source: DCWoRMS/branches/coolemall/build/classes/example/localplugin/BaseLocalPlugin.java @ 477

Revision 477, 3.7 KB checked in by wojtekp, 13 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package example.localplugin;
2
3import java.util.Map;
4
5import schedframe.Parameters;
6import schedframe.PluginConfiguration;
7import schedframe.events.scheduling.SchedulingEvent;
8import schedframe.events.scheduling.SchedulingEventType;
9import schedframe.events.scheduling.SchedulingResponseType;
10import schedframe.resources.units.ResourceUnit;
11import schedframe.resources.units.ResourceUnitName;
12import schedframe.scheduling.WorkloadUnitListImpl;
13import schedframe.scheduling.manager.resources.ResourceManager;
14import schedframe.scheduling.manager.tasks.JobRegistryImpl;
15import schedframe.scheduling.plan.impl.Allocation;
16import schedframe.scheduling.plan.impl.ScheduledTask;
17import schedframe.scheduling.plan.impl.SchedulingPlan;
18import schedframe.scheduling.plugin.SchedulingPluginConfiguration;
19import schedframe.scheduling.plugin.grid.ModuleList;
20import schedframe.scheduling.plugin.local.LocalSchedulingPlugin;
21import schedframe.scheduling.queue.TaskQueue;
22import schedframe.scheduling.queue.TaskQueueList;
23import schedframe.scheduling.tasks.TaskInterface;
24import schedframe.scheduling.tasks.WorkloadUnit;
25import schemas.StringValueWithUnit;
26
27public abstract class BaseLocalPlugin 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                        JobRegistryImpl jobRegistry,
38                                        ResourceManager resourceManager, ModuleList modules){
39                SchedulingResponseType timeEvent = null;
40                switch(event.getType()){
41                        case TASK_REQUESTED_TIME_EXPIRED:
42                                timeEvent = SchedulingResponseType.KILL_TASK;
43                                break;
44                }
45                return timeEvent;
46        }
47       
48        public int placeJobsInQueues(WorkloadUnitListImpl newJobs,
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 < newJobs.size(); i++){
56                        WorkloadUnit<?> task = newJobs.get(i);
57                        queue.add(task);
58                }
59               
60                return 0;
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.setSpecificResources(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               
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 addToSchedulingPlan(SchedulingPlan plan, TaskInterface<?> task){
92               
93                Allocation allocation = new Allocation();
94                allocation.setProcessesCount(1);
95                allocation.setProviderName(null);
96               
97                ScheduledTask scheduledTask = new ScheduledTask(task);
98                scheduledTask.setTaskId(task.getId());
99                scheduledTask.setJobId(task.getJobId());
100                scheduledTask.addAllocation(allocation);               
101               
102                plan.addTask(scheduledTask);
103        }
104
105        public void init(Parameters parameters) {
106                plugConf = new SchedulingPluginConfiguration();
107                try{
108                        StringValueWithUnit freq = parameters.get("frequency").get(0);
109                        plugConf.addServedEvent(SchedulingEventType.TIMER, Double.valueOf(freq.getContent()).intValue());
110                } catch(Exception e){
111                       
112                }
113        }
114}
Note: See TracBrowser for help on using the repository browser.