source: DCWoRMS/trunk/src/example/localplugin/BaseLocalSchedulingPlugin.java @ 481

Revision 481, 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.TaskListImpl;
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 schemas.StringValueWithUnit;
25
26public abstract class BaseLocalSchedulingPlugin implements LocalSchedulingPlugin {
27
28        SchedulingPluginConfiguration plugConf;
29       
30        public PluginConfiguration getConfiguration() {
31                return plugConf;
32        }
33       
34        public SchedulingResponseType handleResourceAllocationViolation(SchedulingEvent event,
35                        TaskQueueList queues,
36                        JobRegistryImpl jobRegistry,
37                                        ResourceManager resourceManager, ModuleList modules){
38                SchedulingResponseType responeEvent = null;
39                switch(event.getType()){
40                        case TASK_REQUESTED_TIME_EXPIRED:
41                                responeEvent = SchedulingResponseType.KILL_TASK;
42                                break;
43                }
44                return responeEvent;
45        }
46       
47        public int placeTasksInQueues(TaskListImpl newTasks,
48                        TaskQueueList queues,
49                        ResourceManager resourceManager, ModuleList moduleList) {
50               
51                // get the first queue from all available queues.
52                TaskQueue queue = queues.get(0);
53
54                for(int i = 0; i < newTasks.size(); i++){
55                        TaskInterface<?> task = newTasks.get(i);
56                        queue.add(task);
57                }
58               
59                return 0;
60        }
61       
62        public void addToSchedulingPlan(SchedulingPlan plan, TaskInterface<?> task, Map<ResourceUnitName, ResourceUnit> choosenResources ){
63               
64                Allocation allocation = new Allocation();
65                allocation.setProcessesCount(1);
66                allocation.setSpecificResources(choosenResources);
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, String providerName){
77               
78                Allocation allocation = new Allocation();
79                allocation.setProcessesCount(1);
80                allocation.setProviderName(providerName);
81               
82                ScheduledTask scheduledTask = new ScheduledTask(task);
83                scheduledTask.setTaskId(task.getId());
84                scheduledTask.setJobId(task.getJobId());
85                scheduledTask.addAllocation(allocation);               
86               
87                plan.addTask(scheduledTask);
88        }
89       
90        public void addToSchedulingPlan(SchedulingPlan plan, TaskInterface<?> task){
91               
92                Allocation allocation = new Allocation();
93                allocation.setProcessesCount(1);
94                allocation.setProviderName(null);
95               
96                ScheduledTask scheduledTask = new ScheduledTask(task);
97                scheduledTask.setTaskId(task.getId());
98                scheduledTask.setJobId(task.getJobId());
99                scheduledTask.addAllocation(allocation);               
100               
101                plan.addTask(scheduledTask);
102        }
103
104        public void init(Parameters parameters) {
105                plugConf = new SchedulingPluginConfiguration();
106                try{
107                        StringValueWithUnit freq = parameters.get("frequency").get(0);
108                        plugConf.addServedEvent(SchedulingEventType.TIMER, Double.valueOf(freq.getContent()).intValue());
109                } catch(Exception e){
110                       
111                }
112        }
113
114        public String getName() {
115                return getClass().getName();
116        }
117
118}
Note: See TracBrowser for help on using the repository browser.