1 | package example.localplugin; |
---|
2 | |
---|
3 | import java.util.Map; |
---|
4 | |
---|
5 | import schedframe.resources.units.ResourceUnit; |
---|
6 | import schedframe.scheduling.TaskInterface; |
---|
7 | import schedframe.scheduling.events.SchedulingEvent; |
---|
8 | import schedframe.scheduling.events.SchedulingResponseType; |
---|
9 | import schedframe.scheduling.plugin.SchedulingPluginConfiguration; |
---|
10 | import schedframe.scheduling.plugin.configuration.DefaultConfiguration; |
---|
11 | import schedframe.scheduling.plugin.grid.ModuleList; |
---|
12 | import schedframe.scheduling.plugin.local.LocalSchedulingPlugin; |
---|
13 | import schedframe.scheduling.utils.ResourceParameterName; |
---|
14 | import test.rewolucja.GSSIMJobInterface; |
---|
15 | import test.rewolucja.resources.manager.interfaces.ResourceManagerInterface; |
---|
16 | import test.rewolucja.scheduling.JobRegistry; |
---|
17 | import test.rewolucja.scheduling.plan.AllocationNew; |
---|
18 | import test.rewolucja.scheduling.plan.ScheduledTaskNew; |
---|
19 | import test.rewolucja.scheduling.plan.SchedulingPlanNew; |
---|
20 | import test.rewolucja.scheduling.queue.GSSIMQueue; |
---|
21 | import test.rewolucja.scheduling.queue.QueueList; |
---|
22 | import test.rewolucja.task.JobList; |
---|
23 | |
---|
24 | /** |
---|
25 | * |
---|
26 | * @author Marcin Krystek |
---|
27 | * |
---|
28 | */ |
---|
29 | public abstract class BaseLocalPlugin implements LocalSchedulingPlugin { |
---|
30 | |
---|
31 | public SchedulingPluginConfiguration getConfiguration() { |
---|
32 | return DefaultConfiguration.forLocalPlugin(); |
---|
33 | } |
---|
34 | |
---|
35 | public SchedulingResponseType handleResourceAllocationViolation(SchedulingEvent event, |
---|
36 | QueueList queues, |
---|
37 | JobRegistry jobRegistry, |
---|
38 | ResourceManagerInterface 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(JobList newJobs, |
---|
49 | QueueList queues, |
---|
50 | ResourceManagerInterface resourceManager, ModuleList moduleList) { |
---|
51 | |
---|
52 | // get the first queue from all available queues. |
---|
53 | GSSIMQueue queue = queues.get(0); |
---|
54 | |
---|
55 | for(int i = 0; i < newJobs.size(); i++){ |
---|
56 | GSSIMJobInterface<?> task = newJobs.get(i); |
---|
57 | queue.add(task); |
---|
58 | } |
---|
59 | |
---|
60 | return 0; |
---|
61 | } |
---|
62 | |
---|
63 | public void addToSchedulingPlan(SchedulingPlanNew plan, TaskInterface<?> task, Map<ResourceParameterName, ResourceUnit> choosenResources ){ |
---|
64 | |
---|
65 | AllocationNew allocation = new AllocationNew(); |
---|
66 | allocation.setProcessesCount(1); |
---|
67 | allocation.setSpecificResources(choosenResources); |
---|
68 | |
---|
69 | ScheduledTaskNew scheduledTask = new ScheduledTaskNew(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(SchedulingPlanNew plan, TaskInterface<?> task, String providerName){ |
---|
78 | |
---|
79 | AllocationNew allocation = new AllocationNew(); |
---|
80 | allocation.setProcessesCount(1); |
---|
81 | allocation.setProviderName(providerName); |
---|
82 | |
---|
83 | ScheduledTaskNew scheduledTask = new ScheduledTaskNew(task); |
---|
84 | scheduledTask.setTaskId(task.getId()); |
---|
85 | scheduledTask.setJobId(task.getJobId()); |
---|
86 | scheduledTask.addAllocation(allocation); |
---|
87 | |
---|
88 | plan.addTask(scheduledTask); |
---|
89 | } |
---|
90 | |
---|
91 | |
---|
92 | } |
---|