1 | package example.localplugin; |
---|
2 | |
---|
3 | import java.util.HashMap; |
---|
4 | import java.util.Map; |
---|
5 | |
---|
6 | import schedframe.Parameters; |
---|
7 | import schedframe.PluginConfiguration; |
---|
8 | import schedframe.events.scheduling.SchedulingEvent; |
---|
9 | import schedframe.events.scheduling.SchedulingEventType; |
---|
10 | import schedframe.events.scheduling.SchedulingResponseType; |
---|
11 | import schedframe.resources.units.ResourceUnit; |
---|
12 | import schedframe.resources.units.ResourceUnitName; |
---|
13 | import schedframe.scheduling.TaskList; |
---|
14 | import schedframe.scheduling.manager.resources.ResourceManager; |
---|
15 | import schedframe.scheduling.manager.tasks.JobRegistry; |
---|
16 | import schedframe.scheduling.plan.impl.Allocation; |
---|
17 | import schedframe.scheduling.plan.impl.ScheduledTask; |
---|
18 | import schedframe.scheduling.plan.impl.SchedulingPlan; |
---|
19 | import schedframe.scheduling.plugin.SchedulingPluginConfiguration; |
---|
20 | import schedframe.scheduling.plugin.grid.ModuleList; |
---|
21 | import schedframe.scheduling.plugin.local.LocalSchedulingPlugin; |
---|
22 | import schedframe.scheduling.queue.TaskQueue; |
---|
23 | import schedframe.scheduling.queue.TaskQueueList; |
---|
24 | import schedframe.scheduling.tasks.TaskInterface; |
---|
25 | import schemas.StringValueWithUnit; |
---|
26 | |
---|
27 | public abstract class BaseLocalSchedulingPlugin implements LocalSchedulingPlugin { |
---|
28 | |
---|
29 | SchedulingPluginConfiguration plugConf; |
---|
30 | |
---|
31 | public PluginConfiguration getConfiguration() { |
---|
32 | return plugConf; |
---|
33 | } |
---|
34 | |
---|
35 | public SchedulingResponseType handleResourceAllocationViolation(SchedulingEvent event, |
---|
36 | TaskQueueList queues, |
---|
37 | JobRegistry jobRegistry, |
---|
38 | ResourceManager resourceManager, ModuleList modules){ |
---|
39 | SchedulingResponseType responeEvent = null; |
---|
40 | switch(event.getType()){ |
---|
41 | case TASK_REQUESTED_TIME_EXPIRED: |
---|
42 | responeEvent = SchedulingResponseType.KILL_TASK; |
---|
43 | break; |
---|
44 | } |
---|
45 | return responeEvent; |
---|
46 | } |
---|
47 | |
---|
48 | public boolean placeTasksInQueues(TaskList newTasks, |
---|
49 | TaskQueueList queues, |
---|
50 | ResourceManager resourceManager, ModuleList moduleList) { |
---|
51 | |
---|
52 | // get the first queue from all available queues. |
---|
53 | TaskQueue queue = queues.get(0); |
---|
54 | |
---|
55 | for(int i = 0; i < newTasks.size(); i++){ |
---|
56 | TaskInterface<?> task = newTasks.get(i); |
---|
57 | queue.add(task); |
---|
58 | } |
---|
59 | |
---|
60 | return true; |
---|
61 | } |
---|
62 | |
---|
63 | public void addToSchedulingPlan(SchedulingPlan plan, TaskInterface<?> task, Map<ResourceUnitName, ResourceUnit> choosenResources ){ |
---|
64 | |
---|
65 | Allocation allocation = new Allocation(); |
---|
66 | allocation.setProcessesCount(1); |
---|
67 | allocation.setRequestedResources(choosenResources); |
---|
68 | |
---|
69 | ScheduledTask scheduledTask = new ScheduledTask(task); |
---|
70 | scheduledTask.setTaskId(task.getId()); |
---|
71 | scheduledTask.setJobId(task.getJobId()); |
---|
72 | scheduledTask.addAllocation(allocation); |
---|
73 | |
---|
74 | plan.addTask(scheduledTask); |
---|
75 | } |
---|
76 | |
---|
77 | public void addToSchedulingPlan(SchedulingPlan plan, TaskInterface<?> task, String providerName){ |
---|
78 | |
---|
79 | Allocation allocation = new Allocation(); |
---|
80 | allocation.setProcessesCount(1); |
---|
81 | allocation.setProviderName(providerName); |
---|
82 | allocation.setRequestedResources(new HashMap<ResourceUnitName, ResourceUnit>()); |
---|
83 | |
---|
84 | ScheduledTask scheduledTask = new ScheduledTask(task); |
---|
85 | scheduledTask.setTaskId(task.getId()); |
---|
86 | scheduledTask.setJobId(task.getJobId()); |
---|
87 | scheduledTask.addAllocation(allocation); |
---|
88 | |
---|
89 | plan.addTask(scheduledTask); |
---|
90 | } |
---|
91 | |
---|
92 | public void addToSchedulingPlan(SchedulingPlan plan, TaskInterface<?> task){ |
---|
93 | |
---|
94 | Allocation allocation = new Allocation(); |
---|
95 | allocation.setProcessesCount(1); |
---|
96 | allocation.setProviderName(null); |
---|
97 | allocation.setRequestedResources(new HashMap<ResourceUnitName, ResourceUnit>()); |
---|
98 | |
---|
99 | ScheduledTask scheduledTask = new ScheduledTask(task); |
---|
100 | scheduledTask.setTaskId(task.getId()); |
---|
101 | scheduledTask.setJobId(task.getJobId()); |
---|
102 | scheduledTask.addAllocation(allocation); |
---|
103 | |
---|
104 | plan.addTask(scheduledTask); |
---|
105 | } |
---|
106 | |
---|
107 | public void init(Parameters parameters) { |
---|
108 | plugConf = new SchedulingPluginConfiguration(); |
---|
109 | try{ |
---|
110 | StringValueWithUnit freq = parameters.get("frequency").get(0); |
---|
111 | plugConf.addServedEvent(SchedulingEventType.TIMER, Double.valueOf(freq.getContent()).intValue()); |
---|
112 | } catch(Exception e){ |
---|
113 | |
---|
114 | } |
---|
115 | } |
---|
116 | |
---|
117 | public String getName() { |
---|
118 | return getClass().getName(); |
---|
119 | } |
---|
120 | |
---|
121 | } |
---|