source: DCWoRMS/branches/coolemall/src/example/localplugin/BaseLocalSchedulingPlugin.java @ 1415

Revision 1415, 3.3 KB checked in by wojtekp, 11 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package example.localplugin;
2
3import java.util.HashMap;
4import java.util.Map;
5
6import schedframe.Parameters;
7import schedframe.PluginConfiguration;
8import schedframe.events.scheduling.SchedulingEventType;
9import schedframe.resources.units.ResourceUnit;
10import schedframe.resources.units.ResourceUnitName;
11import schedframe.scheduling.TaskList;
12import schedframe.scheduling.manager.resources.ResourceManager;
13import schedframe.scheduling.plan.impl.Allocation;
14import schedframe.scheduling.plan.impl.ScheduledTask;
15import schedframe.scheduling.plan.impl.SchedulingPlan;
16import schedframe.scheduling.plugin.ModuleList;
17import schedframe.scheduling.plugin.SchedulingPluginConfiguration;
18import schedframe.scheduling.plugin.local.LocalSchedulingPlugin;
19import schedframe.scheduling.queue.TaskQueue;
20import schedframe.scheduling.queue.TaskQueueList;
21import schedframe.scheduling.tasks.TaskInterface;
22import schemas.StringValueWithUnit;
23
24public 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}
Note: See TracBrowser for help on using the repository browser.