[663] | 1 | package test.article.recs.plugins.scheduling; |
---|
| 2 | |
---|
[679] | 3 | import gridsim.dcworms.DCWormsTags; |
---|
| 4 | |
---|
[708] | 5 | import java.io.FileNotFoundException; |
---|
| 6 | import java.io.IOException; |
---|
[663] | 7 | import java.util.ArrayList; |
---|
| 8 | import java.util.HashMap; |
---|
| 9 | import java.util.List; |
---|
| 10 | import java.util.Map; |
---|
[708] | 11 | import java.util.MissingResourceException; |
---|
[663] | 12 | import java.util.Random; |
---|
| 13 | |
---|
| 14 | import schedframe.events.scheduling.SchedulingEvent; |
---|
| 15 | import schedframe.resources.ResourceStatus; |
---|
| 16 | import schedframe.resources.computing.ComputingNode; |
---|
| 17 | import schedframe.resources.computing.ComputingResource; |
---|
| 18 | import schedframe.resources.computing.Core; |
---|
| 19 | import schedframe.resources.computing.Processor; |
---|
| 20 | import schedframe.resources.units.ProcessingElements; |
---|
| 21 | import schedframe.resources.units.ResourceUnit; |
---|
| 22 | import schedframe.resources.units.ResourceUnitName; |
---|
| 23 | import schedframe.resources.units.StandardResourceUnitName; |
---|
| 24 | import schedframe.scheduling.manager.resources.ClusterResourceManager; |
---|
| 25 | import schedframe.scheduling.manager.resources.ResourceManager; |
---|
| 26 | import schedframe.scheduling.manager.tasks.JobRegistry; |
---|
| 27 | import schedframe.scheduling.plan.SchedulingPlanInterface; |
---|
| 28 | import schedframe.scheduling.plan.impl.SchedulingPlan; |
---|
| 29 | import schedframe.scheduling.plugin.grid.ModuleList; |
---|
| 30 | import schedframe.scheduling.queue.TaskQueue; |
---|
| 31 | import schedframe.scheduling.queue.TaskQueueList; |
---|
| 32 | import schedframe.scheduling.tasks.TaskInterface; |
---|
| 33 | import test.article.recs.utils.RecsProcessorPowerInterface; |
---|
| 34 | |
---|
[679] | 35 | public class RecsExclusivenessDFSSP extends RecsSP { |
---|
[663] | 36 | |
---|
| 37 | private Random rand = new Random(5); |
---|
| 38 | |
---|
| 39 | public SchedulingPlanInterface<?> schedule(SchedulingEvent event, TaskQueueList queues, JobRegistry jobRegistry, |
---|
| 40 | ResourceManager resManager, ModuleList modules) { |
---|
| 41 | |
---|
| 42 | ClusterResourceManager resourceManager = (ClusterResourceManager) resManager; |
---|
| 43 | SchedulingPlan plan = new SchedulingPlan(); |
---|
| 44 | // our tasks are placed only in first queue (see |
---|
| 45 | // BaseLocalSchedulingPlugin.placeJobsInQueues() method) |
---|
| 46 | TaskQueue q = queues.get(0); |
---|
| 47 | // choose the events types to serve. |
---|
| 48 | // Different actions for different events are possible. |
---|
| 49 | switch (event.getType()) { |
---|
| 50 | |
---|
| 51 | case START_TASK_EXECUTION: |
---|
| 52 | case TASK_FINISHED: |
---|
| 53 | // check all tasks in queue |
---|
| 54 | for (int i = 0; i < q.size(); i++) { |
---|
| 55 | TaskInterface<?> task = q.get(i); |
---|
[679] | 56 | initApplicationType(task); |
---|
| 57 | |
---|
[663] | 58 | // if status of the tasks in READY |
---|
| 59 | if (task.getStatus() == DCWormsTags.READY) { |
---|
| 60 | |
---|
| 61 | Map<ResourceUnitName, ResourceUnit> choosenResources = chooseResourcesForExecution(resourceManager, task); |
---|
| 62 | if (choosenResources != null) { |
---|
| 63 | addToSchedulingPlan(plan, task, choosenResources); |
---|
| 64 | } |
---|
| 65 | } |
---|
| 66 | } |
---|
| 67 | adjustFrequency(resourceManager.getProcessors()); |
---|
| 68 | } |
---|
| 69 | return plan; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | private Map<ResourceUnitName, ResourceUnit> chooseResourcesForExecution( |
---|
| 73 | ClusterResourceManager resourceManager, TaskInterface<?> task) { |
---|
| 74 | |
---|
| 75 | Map<ResourceUnitName, ResourceUnit> map = new HashMap<ResourceUnitName, ResourceUnit>(); |
---|
| 76 | |
---|
| 77 | List<ComputingNode> nodes = resourceManager.getComputingNodes(); |
---|
| 78 | List<ComputingNode> avNodes = filterNodes(nodes, task); |
---|
| 79 | if(avNodes.size() == 0) |
---|
| 80 | return null; |
---|
| 81 | ComputingNode node = randomNode(avNodes); |
---|
| 82 | |
---|
| 83 | int cpuRequest; |
---|
| 84 | try { |
---|
| 85 | cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue(); |
---|
| 86 | } catch (NoSuchFieldException e) { |
---|
| 87 | cpuRequest = 0; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | if (cpuRequest != 0) { |
---|
| 91 | |
---|
| 92 | List<Core> cores = node.getProcessors().get(0).getCores(); |
---|
| 93 | |
---|
| 94 | List<ComputingResource> choosenResources = new ArrayList<ComputingResource>(); |
---|
[734] | 95 | for (int i = 0; i < cores.size(); i++) { |
---|
[663] | 96 | if (cores.get(i).getStatus() == ResourceStatus.FREE) { |
---|
[734] | 97 | //choosenResources.add(cores.get(i)); |
---|
[663] | 98 | cpuRequest--; |
---|
| 99 | } |
---|
| 100 | } |
---|
[734] | 101 | choosenResources.add(node); |
---|
[663] | 102 | if (cpuRequest > 0) { |
---|
[734] | 103 | //return null; |
---|
[663] | 104 | } |
---|
| 105 | ProcessingElements pe = new ProcessingElements(); |
---|
| 106 | pe.addAll(choosenResources); |
---|
| 107 | map.put(StandardResourceUnitName.PE, pe); |
---|
| 108 | return map; |
---|
| 109 | } |
---|
| 110 | return null; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | private List<ComputingNode> filterNodes(List<ComputingNode> nodes, TaskInterface<?> task){ |
---|
| 114 | List<ComputingNode> filteredNodes = new ArrayList<ComputingNode>(); |
---|
| 115 | for (ComputingNode node : nodes) { |
---|
| 116 | int cpuRequest; |
---|
| 117 | try { |
---|
| 118 | cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue(); |
---|
| 119 | } catch (NoSuchFieldException e) { |
---|
| 120 | cpuRequest = 0; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | if (cpuRequest != 0) { |
---|
| 124 | |
---|
| 125 | List<Core> cores = node.getProcessors().get(0).getCores(); |
---|
| 126 | if (cores.size() < cpuRequest) { |
---|
| 127 | continue; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | int freeCores = 0; |
---|
| 131 | for(Core core: cores){ |
---|
| 132 | if(core.getStatus() == ResourceStatus.FREE) |
---|
| 133 | freeCores++; |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | if(freeCores != cores.size()) |
---|
| 137 | continue; |
---|
[708] | 138 | try { |
---|
| 139 | if(!getExecutiveness(createExecutivenessQuery(task, node))) |
---|
| 140 | continue; |
---|
| 141 | } catch (FileNotFoundException e) { |
---|
| 142 | continue; |
---|
| 143 | } catch (IOException e) { |
---|
| 144 | continue; |
---|
| 145 | } catch (MissingResourceException e){ |
---|
| 146 | continue; |
---|
| 147 | } |
---|
[663] | 148 | |
---|
| 149 | filteredNodes.add(node); |
---|
| 150 | } |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | return filteredNodes; |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | private ComputingNode randomNode(List<ComputingNode> nodes){ |
---|
| 157 | return nodes.get(rand.nextInt(nodes.size())); |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | |
---|
| 161 | private void adjustFrequency(List<Processor> processors){ |
---|
| 162 | |
---|
| 163 | for(Processor cpu: processors){ |
---|
| 164 | RecsProcessorPowerInterface rppi = (RecsProcessorPowerInterface) cpu.getPowerInterface(); |
---|
| 165 | int freeCores = 0; |
---|
| 166 | |
---|
| 167 | for(Core core: cpu.getCores()){ |
---|
| 168 | if(core.getStatus() == ResourceStatus.FREE) |
---|
| 169 | freeCores++; |
---|
| 170 | } |
---|
| 171 | if(freeCores == cpu.getCores().size()) |
---|
| 172 | rppi.setPState(rppi.getHighestPState().getName()); |
---|
| 173 | else |
---|
[708] | 174 | rppi.setPState(rppi.getHighestPState().getName()); |
---|
[663] | 175 | |
---|
| 176 | } |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | } |
---|