1 | package example.localplugin; |
---|
2 | |
---|
3 | import gridsim.dcworms.DCWormsTags; |
---|
4 | |
---|
5 | import java.util.ArrayList; |
---|
6 | import java.util.List; |
---|
7 | import java.util.Random; |
---|
8 | |
---|
9 | import schedframe.events.scheduling.SchedulingEvent; |
---|
10 | import schedframe.resources.StandardResourceType; |
---|
11 | import schedframe.resources.computing.ComputingNode; |
---|
12 | import schedframe.resources.computing.profiles.energy.airthroughput.StandardAirThroughputStateName; |
---|
13 | import schedframe.resources.computing.profiles.energy.airthroughput.UserAirThroughputStateName; |
---|
14 | import schedframe.resources.devices.Device; |
---|
15 | import schedframe.scheduling.manager.resources.ClusterResourceManager; |
---|
16 | import schedframe.scheduling.manager.resources.ResourceManager; |
---|
17 | import schedframe.scheduling.manager.tasks.JobRegistry; |
---|
18 | import schedframe.scheduling.manager.tasks.JobRegistryImpl; |
---|
19 | import schedframe.scheduling.plan.SchedulingPlanInterface; |
---|
20 | import schedframe.scheduling.plan.impl.SchedulingPlan; |
---|
21 | import schedframe.scheduling.plugin.grid.ModuleList; |
---|
22 | import schedframe.scheduling.queue.TaskQueue; |
---|
23 | import schedframe.scheduling.queue.TaskQueueList; |
---|
24 | import schedframe.scheduling.tasks.TaskInterface; |
---|
25 | |
---|
26 | public class FCFSBF_FanManagementClusterPlugin extends BaseLocalSchedulingPlugin { |
---|
27 | |
---|
28 | private Random rand; |
---|
29 | |
---|
30 | public FCFSBF_FanManagementClusterPlugin () { |
---|
31 | rand = new Random(5); |
---|
32 | } |
---|
33 | |
---|
34 | public SchedulingPlanInterface<?> schedule(SchedulingEvent event, TaskQueueList queues, JobRegistry jobRegistry, |
---|
35 | ResourceManager resManager, ModuleList modules) { |
---|
36 | |
---|
37 | ClusterResourceManager resourceManager = (ClusterResourceManager) resManager; |
---|
38 | SchedulingPlan plan = new SchedulingPlan(); |
---|
39 | // choose the events types to serve. |
---|
40 | // Different actions for different events are possible. |
---|
41 | switch (event.getType()) { |
---|
42 | case START_TASK_EXECUTION: |
---|
43 | case TASK_FINISHED: |
---|
44 | //case TIMER: |
---|
45 | // our tasks are placed only in first queue (see |
---|
46 | // BaseLocalSchedulingPlugin.placeJobsInQueues() method) |
---|
47 | TaskQueue q = queues.get(0); |
---|
48 | List<ComputingNode> notSelectedNodes = resourceManager.getComputingNodes(); |
---|
49 | // check all tasks in queue |
---|
50 | for (int i = 0; i < q.size(); i++) { |
---|
51 | TaskInterface<?> task = q.get(i); |
---|
52 | // if status of the tasks in READY |
---|
53 | if (task.getStatus() == DCWormsTags.READY) { |
---|
54 | |
---|
55 | ComputingNode node = chooseRandomProvider(resourceManager, task); |
---|
56 | if (node != null) { |
---|
57 | //if there are two or more tasks ( running on the given node then |
---|
58 | if(new JobRegistryImpl(node.getFullName()).getRunningTasks().size() > 0){ |
---|
59 | List<Device> devices = node.getResourceCharacteristic().getDevices(); |
---|
60 | for(Device dev : devices){ |
---|
61 | if(dev.getType().equals(StandardResourceType.Fan)){ |
---|
62 | dev.getAirThroughputInterface().setAirThroughputState(new UserAirThroughputStateName("FAN_ON_TURBO")); |
---|
63 | } |
---|
64 | } |
---|
65 | } |
---|
66 | else { |
---|
67 | List<Device> devices = node.getResourceCharacteristic().getDevices(); |
---|
68 | for(Device dev : devices){ |
---|
69 | if(dev.getType().equals(StandardResourceType.Fan)){ |
---|
70 | dev.getAirThroughputInterface().setAirThroughputState(StandardAirThroughputStateName.ON); |
---|
71 | } |
---|
72 | } |
---|
73 | } |
---|
74 | notSelectedNodes.remove(node); |
---|
75 | addToSchedulingPlan(plan, task, node.getFullName()); |
---|
76 | } |
---|
77 | } |
---|
78 | } |
---|
79 | adjustOtherFans(notSelectedNodes); |
---|
80 | break; |
---|
81 | } |
---|
82 | return plan; |
---|
83 | } |
---|
84 | |
---|
85 | private ComputingNode chooseRandomProvider(ClusterResourceManager resourceManager, TaskInterface<?> task) { |
---|
86 | List<ComputingNode> nodes = filterNodes(resourceManager.getComputingNodes(), task); |
---|
87 | return randomNode(nodes); |
---|
88 | } |
---|
89 | |
---|
90 | private List<ComputingNode> filterNodes(List<ComputingNode> nodes, TaskInterface<?> task){ |
---|
91 | List<ComputingNode> filteredNodes = new ArrayList<ComputingNode>(); |
---|
92 | for (ComputingNode node : nodes) { |
---|
93 | int cpuRequest; |
---|
94 | try { |
---|
95 | cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue(); |
---|
96 | } catch (NoSuchFieldException e) { |
---|
97 | cpuRequest = 0; |
---|
98 | } |
---|
99 | if (cpuRequest != 0) { |
---|
100 | if(node.getFreeProcessorsNumber() > cpuRequest) |
---|
101 | filteredNodes.add(node); |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | return filteredNodes; |
---|
106 | } |
---|
107 | |
---|
108 | private ComputingNode randomNode(List<ComputingNode> nodes){ |
---|
109 | return nodes.get(rand.nextInt(nodes.size())); |
---|
110 | } |
---|
111 | |
---|
112 | private void adjustOtherFans(List<ComputingNode> nodes){ |
---|
113 | for(ComputingNode node : nodes){ |
---|
114 | List<Device> devices = node.getResourceCharacteristic().getDevices(); |
---|
115 | if(node.getFreeProcessorsNumber() == node.getProcessorsNumber()){ |
---|
116 | for(Device dev : devices){ |
---|
117 | if(dev.getType().equals(StandardResourceType.Fan)){ |
---|
118 | dev.getAirThroughputInterface().setAirThroughputState(StandardAirThroughputStateName.OFF); |
---|
119 | } |
---|
120 | } |
---|
121 | } else if(new JobRegistryImpl(node.getFullName()).getRunningTasks().size() > 1){ |
---|
122 | for(Device dev : devices){ |
---|
123 | if(dev.getType().equals(StandardResourceType.Fan)){ |
---|
124 | dev.getAirThroughputInterface().setAirThroughputState(new UserAirThroughputStateName("FAN_ON_TURBO")); |
---|
125 | } |
---|
126 | } |
---|
127 | } |
---|
128 | else { |
---|
129 | for(Device dev : devices){ |
---|
130 | if(dev.getType().equals(StandardResourceType.Fan)){ |
---|
131 | dev.getAirThroughputInterface().setAirThroughputState(StandardAirThroughputStateName.ON); |
---|
132 | } |
---|
133 | } |
---|
134 | } |
---|
135 | } |
---|
136 | } |
---|
137 | |
---|
138 | |
---|
139 | } |
---|