source: xssim/branches/tpiontek/src/example/localplugin/BaseLocalPlugin.java @ 256

Revision 256, 3.9 KB checked in by piontek, 13 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package example.localplugin;
2
3import java.util.HashMap;
4import java.util.List;
5import java.util.Map;
6
7import schedframe.resources.units.ResourceUnit;
8import schedframe.scheduling.TaskInterface;
9import schedframe.scheduling.events.SchedulingEvent;
10import schedframe.scheduling.events.SchedulingResponseType;
11import schedframe.scheduling.plugin.SchedulingPluginConfiguration;
12import schedframe.scheduling.plugin.configuration.DefaultConfiguration;
13import schedframe.scheduling.plugin.grid.ModuleList;
14import schedframe.scheduling.plugin.local.LocalSchedulingPlugin;
15import schedframe.scheduling.utils.ResourceParameterName;
16import test.rewolucja.GSSIMJobInterface;
17import test.rewolucja.resources.ProcessingElements;
18import test.rewolucja.resources.manager.interfaces.ResourceManagerInterface;
19import test.rewolucja.resources.physical.implementation.Processor;
20import test.rewolucja.scheduling.JobRegistry;
21import test.rewolucja.scheduling.plan.AllocationNew;
22import test.rewolucja.scheduling.plan.ScheduledTaskNew;
23import test.rewolucja.scheduling.plan.SchedulingPlanNew;
24import test.rewolucja.scheduling.queue.Queue;
25import test.rewolucja.scheduling.queue.QueueList;
26import test.rewolucja.task.JobList;
27
28/**
29 *
30 * @author Marcin Krystek
31 *
32 */
33public abstract class BaseLocalPlugin implements LocalSchedulingPlugin {
34
35        public SchedulingPluginConfiguration getConfiguration() {
36                return DefaultConfiguration.forLocalPlugin();
37        }
38       
39        public SchedulingResponseType handleResourceAllocationViolation(SchedulingEvent event,
40                        QueueList queues,
41                        JobRegistry jobRegistry,
42                                        ResourceManagerInterface resourceManager, ModuleList modules){
43                SchedulingResponseType timeEvent = null;
44                switch(event.getType()){
45                        case TASK_REQUESTED_TIME_EXPIRED:
46                                timeEvent = SchedulingResponseType.KILL_TASK;
47                                break;
48                }
49                return timeEvent;
50        }
51       
52        public int placeJobsInQueues(JobList newJobs,
53                        QueueList queues,
54                        ResourceManagerInterface resourceManager, ModuleList moduleList) {
55               
56                // get the first queue from all available queues.
57                Queue queue = queues.get(0);
58
59                for(int i = 0; i < newJobs.size(); i++){
60                        GSSIMJobInterface<?> task = newJobs.get(i);
61                        queue.add(task);
62                }
63               
64                return 0;
65        }
66       
67        public void addToSchedulingPlan(SchedulingPlanNew plan, TaskInterface<?> task,  List<Processor> cpus){
68               
69                Map<ResourceParameterName, ResourceUnit> map = new HashMap<ResourceParameterName, ResourceUnit>();
70               
71                ProcessingElements result = new ProcessingElements();
72                result.addAll( cpus);
73                map.put(ResourceParameterName.PROCESSINGELEMENTS, result);
74               
75                addToSchedulingPlan(plan, task, map);
76        }
77       
78        public void addToSchedulingPlan(SchedulingPlanNew plan, TaskInterface<?> task, Map<ResourceParameterName, ResourceUnit> choosenResources ){
79               
80                AllocationNew allocation = new AllocationNew();
81                allocation.setProcessesCount(1);
82                allocation.setSpecificResources(choosenResources);
83               
84                ScheduledTaskNew scheduledTask = new ScheduledTaskNew(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(SchedulingPlanNew plan, TaskInterface<?> task, String providerName){
93               
94                AllocationNew allocation = new AllocationNew();
95                allocation.setProcessesCount(1);
96                allocation.setProviderName(providerName);
97               
98                ScheduledTaskNew scheduledTask = new ScheduledTaskNew(task);
99                scheduledTask.setTaskId(task.getId());
100                scheduledTask.setJobId(task.getJobId());
101                scheduledTask.addAllocation(allocation);               
102               
103                plan.addTask(scheduledTask);
104        }
105       
106        public void addToSchedulingPlan(SchedulingPlanNew plan, TaskInterface<?> task){
107               
108                AllocationNew allocation = new AllocationNew();
109                allocation.setProcessesCount(1);
110                allocation.setProviderName(null);
111               
112                ScheduledTaskNew scheduledTask = new ScheduledTaskNew(task);
113                scheduledTask.setTaskId(task.getId());
114                scheduledTask.setJobId(task.getJobId());
115                scheduledTask.addAllocation(allocation);               
116               
117                plan.addTask(scheduledTask);
118        }
119
120}
Note: See TracBrowser for help on using the repository browser.