[750] | 1 | package example.localplugin; |
---|
| 2 | |
---|
| 3 | import gridsim.dcworms.DCWormsTags; |
---|
| 4 | |
---|
[778] | 5 | import java.util.ArrayList; |
---|
[750] | 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; |
---|
[778] | 12 | import schedframe.resources.computing.profiles.energy.airthroughput.UserAirThroughputStateName; |
---|
[750] | 13 | import schedframe.scheduling.manager.resources.ClusterResourceManager; |
---|
| 14 | import schedframe.scheduling.manager.resources.ResourceManager; |
---|
| 15 | import schedframe.scheduling.manager.tasks.JobRegistry; |
---|
[778] | 16 | import schedframe.scheduling.manager.tasks.JobRegistryImpl; |
---|
[750] | 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 | |
---|
[778] | 53 | ComputingNode node = chooseRandomProvider(resourceManager, task); |
---|
[750] | 54 | if (node != null) { |
---|
[778] | 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); |
---|
[750] | 60 | notSelectedNodes.remove(node); |
---|
| 61 | addToSchedulingPlan(plan, task, node.getName()); |
---|
| 62 | } |
---|
| 63 | } |
---|
| 64 | } |
---|
[778] | 65 | adjustOtherFans(notSelectedNodes); |
---|
[750] | 66 | break; |
---|
| 67 | } |
---|
| 68 | return plan; |
---|
| 69 | } |
---|
| 70 | |
---|
[778] | 71 | private ComputingNode chooseRandomProvider(ClusterResourceManager resourceManager, TaskInterface<?> task) { |
---|
| 72 | List<ComputingNode> nodes = filterNodes(resourceManager.getComputingNodes(), task); |
---|
| 73 | return randomNode(nodes); |
---|
[750] | 74 | } |
---|
| 75 | |
---|
[778] | 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){ |
---|
[750] | 99 | for(ComputingNode node : nodes){ |
---|
| 100 | if(node.getFreeProcessorsNumber() == node.getProcessorsNumber()){ |
---|
| 101 | node.getAirThroughputInterface().setAirThroughputState(StandardAirThroughputStateName.FAN_OFF); |
---|
[778] | 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); |
---|
[750] | 106 | } |
---|
| 107 | } |
---|
| 108 | |
---|
[778] | 109 | |
---|
[750] | 110 | } |
---|