[750] | 1 | package example.localplugin; |
---|
| 2 | |
---|
| 3 | import gridsim.dcworms.DCWormsTags; |
---|
| 4 | |
---|
| 5 | import java.util.List; |
---|
| 6 | import java.util.Random; |
---|
| 7 | |
---|
| 8 | import schedframe.events.scheduling.SchedulingEvent; |
---|
| 9 | import schedframe.resources.computing.ComputingNode; |
---|
| 10 | import schedframe.resources.computing.profiles.energy.airthroughput.StandardAirThroughputStateName; |
---|
| 11 | import schedframe.scheduling.manager.resources.ClusterResourceManager; |
---|
| 12 | import schedframe.scheduling.manager.resources.ResourceManager; |
---|
| 13 | import schedframe.scheduling.manager.tasks.JobRegistry; |
---|
| 14 | import schedframe.scheduling.plan.SchedulingPlanInterface; |
---|
| 15 | import schedframe.scheduling.plan.impl.SchedulingPlan; |
---|
| 16 | import schedframe.scheduling.plugin.grid.ModuleList; |
---|
| 17 | import schedframe.scheduling.queue.TaskQueue; |
---|
| 18 | import schedframe.scheduling.queue.TaskQueueList; |
---|
| 19 | import schedframe.scheduling.tasks.TaskInterface; |
---|
| 20 | |
---|
| 21 | public class FCFSBF_FanManagementClusterPlugin extends BaseLocalSchedulingPlugin { |
---|
| 22 | |
---|
| 23 | private Random rand; |
---|
| 24 | |
---|
| 25 | public FCFSBF_FanManagementClusterPlugin () { |
---|
| 26 | rand = new Random(5); |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | public SchedulingPlanInterface<?> schedule(SchedulingEvent event, TaskQueueList queues, JobRegistry jobRegistry, |
---|
| 30 | ResourceManager resManager, ModuleList modules) { |
---|
| 31 | |
---|
| 32 | ClusterResourceManager resourceManager = (ClusterResourceManager) resManager; |
---|
| 33 | SchedulingPlan plan = new SchedulingPlan(); |
---|
| 34 | // choose the events types to serve. |
---|
| 35 | // Different actions for different events are possible. |
---|
| 36 | switch (event.getType()) { |
---|
| 37 | case START_TASK_EXECUTION: |
---|
| 38 | case TASK_FINISHED: |
---|
| 39 | //case TIMER: |
---|
| 40 | // our tasks are placed only in first queue (see |
---|
| 41 | // BaseLocalSchedulingPlugin.placeJobsInQueues() method) |
---|
| 42 | TaskQueue q = queues.get(0); |
---|
| 43 | List<ComputingNode> notSelectedNodes = resourceManager.getComputingNodes(); |
---|
| 44 | // check all tasks in queue |
---|
| 45 | for (int i = 0; i < q.size(); i++) { |
---|
| 46 | TaskInterface<?> task = q.get(i); |
---|
| 47 | // if status of the tasks in READY |
---|
| 48 | if (task.getStatus() == DCWormsTags.READY) { |
---|
| 49 | |
---|
| 50 | ComputingNode node = chooseRandomProvider(resourceManager); |
---|
| 51 | if (node != null) { |
---|
| 52 | node.getAirThroughputInterface().setAirThroughputState(StandardAirThroughputStateName.FAN_ON); |
---|
| 53 | notSelectedNodes.remove(node); |
---|
| 54 | addToSchedulingPlan(plan, task, node.getName()); |
---|
| 55 | } |
---|
| 56 | } |
---|
| 57 | } |
---|
| 58 | turnOffIdleNodes(notSelectedNodes); |
---|
| 59 | break; |
---|
| 60 | } |
---|
| 61 | return plan; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | private ComputingNode chooseRandomProvider(ClusterResourceManager resourceManager) { |
---|
| 65 | List<ComputingNode> nodes = resourceManager.getComputingNodes(); |
---|
| 66 | int nodeIdx = rand.nextInt(nodes.size()); |
---|
| 67 | return nodes.get(nodeIdx); |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | private void turnOffIdleNodes(List<ComputingNode> nodes){ |
---|
| 71 | for(ComputingNode node : nodes){ |
---|
| 72 | if(node.getFreeProcessorsNumber() == node.getProcessorsNumber()){ |
---|
| 73 | node.getAirThroughputInterface().setAirThroughputState(StandardAirThroughputStateName.FAN_OFF); |
---|
| 74 | } |
---|
| 75 | } |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | } |
---|