1 | package example.localplugin; |
---|
2 | |
---|
3 | import java.util.HashMap; |
---|
4 | import java.util.List; |
---|
5 | import java.util.Map; |
---|
6 | |
---|
7 | import schedframe.resources.units.ResourceUnit; |
---|
8 | import schedframe.scheduling.TaskInterface; |
---|
9 | import schedframe.scheduling.events.SchedulingEvent; |
---|
10 | import schedframe.scheduling.events.SchedulingResponseType; |
---|
11 | import schedframe.scheduling.plugin.SchedulingPluginConfiguration; |
---|
12 | import schedframe.scheduling.plugin.configuration.DefaultConfiguration; |
---|
13 | import schedframe.scheduling.plugin.grid.ModuleList; |
---|
14 | import schedframe.scheduling.plugin.local.LocalSchedulingPlugin; |
---|
15 | import schedframe.scheduling.utils.ResourceParameterName; |
---|
16 | import test.rewolucja.GSSIMJobInterface; |
---|
17 | import test.rewolucja.resources.ProcessingElements; |
---|
18 | import test.rewolucja.resources.manager.interfaces.ResourceManagerInterface; |
---|
19 | import test.rewolucja.resources.physical.implementation.Processor; |
---|
20 | import test.rewolucja.scheduling.JobRegistry; |
---|
21 | import test.rewolucja.scheduling.plan.AllocationNew; |
---|
22 | import test.rewolucja.scheduling.plan.ScheduledTaskNew; |
---|
23 | import test.rewolucja.scheduling.plan.SchedulingPlanNew; |
---|
24 | import test.rewolucja.scheduling.queue.Queue; |
---|
25 | import test.rewolucja.scheduling.queue.QueueList; |
---|
26 | import test.rewolucja.task.JobList; |
---|
27 | |
---|
28 | /** |
---|
29 | * |
---|
30 | * @author Marcin Krystek |
---|
31 | * |
---|
32 | */ |
---|
33 | public 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 | } |
---|