1 | package test.pausing_resuming; |
---|
2 | |
---|
3 | import dcworms.schedframe.scheduling.ExecTask; |
---|
4 | import dcworms.schedframe.scheduling.Executable; |
---|
5 | import example.localplugin.BaseLocalSchedulingPlugin; |
---|
6 | import gridsim.Gridlet; |
---|
7 | import gridsim.dcworms.DCWormsTags; |
---|
8 | |
---|
9 | import java.util.ArrayList; |
---|
10 | import java.util.HashMap; |
---|
11 | import java.util.List; |
---|
12 | import java.util.Map; |
---|
13 | import java.util.Properties; |
---|
14 | |
---|
15 | import org.joda.time.DateTime; |
---|
16 | |
---|
17 | import schedframe.events.scheduling.SchedulingEvent; |
---|
18 | import schedframe.exceptions.ResourceException; |
---|
19 | import schedframe.resources.ResourceStatus; |
---|
20 | import schedframe.resources.StandardResourceType; |
---|
21 | import schedframe.resources.computing.Node; |
---|
22 | import schedframe.resources.computing.ComputingResource; |
---|
23 | import schedframe.resources.computing.Processor; |
---|
24 | import schedframe.resources.computing.profiles.energy.EnergyEventType; |
---|
25 | import schedframe.resources.units.Memory; |
---|
26 | import schedframe.resources.units.PEUnit; |
---|
27 | import schedframe.resources.units.ProcessingElements; |
---|
28 | import schedframe.resources.units.ResourceUnit; |
---|
29 | import schedframe.resources.units.ResourceUnitName; |
---|
30 | import schedframe.resources.units.StandardResourceUnitName; |
---|
31 | import schedframe.scheduling.manager.resources.ClusterResourceManager; |
---|
32 | import schedframe.scheduling.manager.resources.ResourceManager; |
---|
33 | import schedframe.scheduling.manager.tasks.JobRegistry; |
---|
34 | import schedframe.scheduling.plan.SchedulingPlanInterface; |
---|
35 | import schedframe.scheduling.plan.impl.SchedulingPlan; |
---|
36 | import schedframe.scheduling.plugin.grid.ModuleList; |
---|
37 | import schedframe.scheduling.plugin.local.ResourceAllocation; |
---|
38 | import schedframe.scheduling.queue.TaskQueue; |
---|
39 | import schedframe.scheduling.queue.TaskQueueList; |
---|
40 | import schedframe.scheduling.tasks.TaskInterface; |
---|
41 | import simulator.DataCenterWorkloadSimulator; |
---|
42 | |
---|
43 | public class FCFSBF_RandomPluginPausing extends BaseLocalSchedulingPlugin { |
---|
44 | |
---|
45 | public SchedulingPlanInterface<?> schedule(SchedulingEvent event, TaskQueueList queues, JobRegistry jobRegistry, |
---|
46 | ResourceManager resManager, ModuleList modules) { |
---|
47 | |
---|
48 | ClusterResourceManager resourceManager = (ClusterResourceManager) resManager; |
---|
49 | List<Processor> processors = resourceManager.getProcessors(); |
---|
50 | SchedulingPlan plan = new SchedulingPlan(); |
---|
51 | // choose the events types to serve. |
---|
52 | // Different actions for different events are possible. |
---|
53 | switch (event.getType()) { |
---|
54 | case START_TASK_EXECUTION: |
---|
55 | //case TIMER: |
---|
56 | // our tasks are placed only in first queue (see BaseLocalSchedulingPlugin.placeJobsInQueues() method) |
---|
57 | TaskQueue q = queues.get(0); |
---|
58 | // check all tasks in queue |
---|
59 | |
---|
60 | for (int i = 0; i < q.size(); i++) { |
---|
61 | TaskInterface<?> task = q.get(i); |
---|
62 | // if status of the tasks in READY |
---|
63 | if (task.getStatus() == DCWormsTags.READY) { |
---|
64 | |
---|
65 | Map<ResourceUnitName, ResourceUnit> choosenResources = chooseResourcesForExecution(processors, task); |
---|
66 | if (choosenResources != null) { |
---|
67 | addToSchedulingPlan(plan, task, choosenResources); |
---|
68 | } else { |
---|
69 | if(jobRegistry.getRunningTasks().size() > 0) { |
---|
70 | for(ExecTask exec: jobRegistry.getRunningTasks()){ |
---|
71 | jobRegistry.pauseTask(exec.getJobId(), exec.getId()); |
---|
72 | } |
---|
73 | } |
---|
74 | } |
---|
75 | } |
---|
76 | } |
---|
77 | |
---|
78 | break; |
---|
79 | case TASK_FINISHED: |
---|
80 | for(ExecTask exec: jobRegistry.getTasks(DCWormsTags.PAUSED)){ |
---|
81 | jobRegistry.resumeTask(exec.getJobId(), exec.getId()); |
---|
82 | } |
---|
83 | q = queues.get(0); |
---|
84 | // check all tasks in queue |
---|
85 | |
---|
86 | for (int i = 0; i < q.size(); i++) { |
---|
87 | TaskInterface<?> task = q.get(i); |
---|
88 | // if status of the tasks in READY |
---|
89 | if (task.getStatus() == DCWormsTags.READY) { |
---|
90 | Map<ResourceUnitName, ResourceUnit> choosenResources = chooseResourcesForExecution(processors, task); |
---|
91 | if (choosenResources != null) { |
---|
92 | addToSchedulingPlan(plan, task, choosenResources); |
---|
93 | } |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|
97 | break; |
---|
98 | case TASK_PAUSED: |
---|
99 | q = queues.get(0); |
---|
100 | // check all tasks in queue |
---|
101 | |
---|
102 | for (int i = 0; i < q.size(); i++) { |
---|
103 | TaskInterface<?> task = q.get(i); |
---|
104 | // if status of the tasks in READY |
---|
105 | if (task.getStatus() == DCWormsTags.READY) { |
---|
106 | |
---|
107 | Map<ResourceUnitName, ResourceUnit> choosenResources = chooseResourcesForExecution(processors, task); |
---|
108 | if (choosenResources != null) { |
---|
109 | addToSchedulingPlan(plan, task, choosenResources); |
---|
110 | } |
---|
111 | } |
---|
112 | } |
---|
113 | |
---|
114 | } |
---|
115 | |
---|
116 | return plan; |
---|
117 | } |
---|
118 | |
---|
119 | private Map<ResourceUnitName, ResourceUnit> chooseResourcesForExecution( |
---|
120 | List<Processor> processors, TaskInterface<?> task) { |
---|
121 | |
---|
122 | Map<ResourceUnitName, ResourceUnit> map = new HashMap<ResourceUnitName, ResourceUnit>(1); |
---|
123 | |
---|
124 | int cpuRequest; |
---|
125 | try { |
---|
126 | cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue(); |
---|
127 | } catch (NoSuchFieldException e) { |
---|
128 | cpuRequest = 0; |
---|
129 | } |
---|
130 | |
---|
131 | if (cpuRequest != 0) { |
---|
132 | |
---|
133 | if (processors.size() < cpuRequest) { |
---|
134 | return null; |
---|
135 | } |
---|
136 | |
---|
137 | List<ComputingResource> choosenResources = new ArrayList<ComputingResource>(cpuRequest); |
---|
138 | for (int i = 0; i < processors.size() && cpuRequest > 0; i++) { |
---|
139 | if (processors.get(i).getStatus() == ResourceStatus.FREE) { |
---|
140 | choosenResources.add(processors.get(i)); |
---|
141 | cpuRequest--; |
---|
142 | } |
---|
143 | } |
---|
144 | if (cpuRequest > 0) { |
---|
145 | return null; |
---|
146 | } |
---|
147 | |
---|
148 | ProcessingElements pe = new ProcessingElements(); |
---|
149 | pe.addAll(choosenResources); |
---|
150 | map.put(StandardResourceUnitName.PE, pe); |
---|
151 | return map; |
---|
152 | } |
---|
153 | |
---|
154 | return null; |
---|
155 | } |
---|
156 | |
---|
157 | |
---|
158 | |
---|
159 | } |
---|