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