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