[104] | 1 | package example.localplugin; |
---|
| 2 | |
---|
| 3 | import gridsim.Gridlet; |
---|
| 4 | import gridsim.gssim.SubmittedTask; |
---|
| 5 | import gssim.schedframe.scheduling.ExecTaskInterface; |
---|
| 6 | |
---|
| 7 | import java.util.ArrayList; |
---|
| 8 | import java.util.HashMap; |
---|
| 9 | import java.util.List; |
---|
| 10 | import java.util.Map; |
---|
| 11 | import java.util.Properties; |
---|
| 12 | |
---|
| 13 | import schedframe.resources.units.Memory; |
---|
| 14 | import schedframe.resources.units.ResourceUnit; |
---|
| 15 | import schedframe.scheduling.TaskInterface; |
---|
| 16 | import schedframe.scheduling.events.SchedulingEvent; |
---|
| 17 | import schedframe.scheduling.plugin.grid.ModuleList; |
---|
| 18 | import schedframe.scheduling.utils.ResourceParameterName; |
---|
| 19 | import test.rewolucja.GSSIMJobInterface; |
---|
| 20 | import test.rewolucja.resources.ProcessingElements; |
---|
| 21 | import test.rewolucja.resources.ResourceStatus; |
---|
| 22 | import test.rewolucja.resources.ResourceType; |
---|
| 23 | import test.rewolucja.resources.manager.implementation.ClusterResourceManager; |
---|
| 24 | import test.rewolucja.resources.manager.interfaces.ResourceManagerInterface; |
---|
| 25 | import test.rewolucja.resources.physical.base.ComputingResource; |
---|
[204] | 26 | import test.rewolucja.resources.physical.implementation.Processor; |
---|
[104] | 27 | import test.rewolucja.resources.physical.implementation.ComputingNode; |
---|
| 28 | import test.rewolucja.scheduling.JobRegistryInterface; |
---|
| 29 | import test.rewolucja.scheduling.plan.SchedulingPlanInterfaceNew; |
---|
| 30 | import test.rewolucja.scheduling.plan.SchedulingPlanNew; |
---|
[163] | 31 | import test.rewolucja.scheduling.queue.Queue; |
---|
[104] | 32 | import test.rewolucja.scheduling.queue.QueueList; |
---|
| 33 | |
---|
| 34 | public class FCFSClusterLocalPlugin extends BaseLocalPlugin { |
---|
| 35 | |
---|
| 36 | public FCFSClusterLocalPlugin() { |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | public SchedulingPlanInterfaceNew schedule(SchedulingEvent event, QueueList queues, JobRegistryInterface jobRegistry, |
---|
| 40 | ResourceManagerInterface resManager, ModuleList modules) { |
---|
| 41 | |
---|
| 42 | ClusterResourceManager resourceManager = (ClusterResourceManager) resManager; |
---|
| 43 | SchedulingPlanNew plan = new SchedulingPlanNew(); |
---|
| 44 | // chose the events types to serve. |
---|
| 45 | // Different actions for different events are possible. |
---|
| 46 | switch (event.getType()) { |
---|
| 47 | case START_TASK_EXECUTION: |
---|
| 48 | case TASK_FINISHED: |
---|
| 49 | case TIMER: |
---|
| 50 | // our tasks are placed only in first queue (see |
---|
[192] | 51 | // BaseLocalPlugin.placeJobsInQueues() method) |
---|
[163] | 52 | Queue q = queues.get(0); |
---|
[104] | 53 | // check all tasks in queue |
---|
| 54 | |
---|
| 55 | for (int i = 0; i < q.size(); i++) { |
---|
| 56 | GSSIMJobInterface<?> job = q.get(i); |
---|
| 57 | TaskInterface<?> task = (TaskInterface<?>) job; |
---|
| 58 | // if status of the tasks in READY |
---|
| 59 | if (task.getStatus() == Gridlet.READY) { |
---|
| 60 | |
---|
| 61 | SubmittedTask subTask = (SubmittedTask) task; |
---|
[129] | 62 | |
---|
| 63 | /****************3 ways to schedule task****************/ |
---|
| 64 | |
---|
[192] | 65 | /****************1. Choosing particular resources to perform execution****************/ |
---|
[129] | 66 | Map<ResourceParameterName, ResourceUnit> choosenResources = chooseResourcesForExecution(resourceManager, subTask); |
---|
[104] | 67 | if (choosenResources != null) { |
---|
| 68 | addToSchedulingPlan(plan, task, choosenResources); |
---|
| 69 | } |
---|
[129] | 70 | |
---|
[192] | 71 | /****************2. Choosing resource scheduler/provider to submit task. If the given resource doesn't contains/isn't |
---|
| 72 | a scheduler, random resources from the given resource will be chosen in order to perform execution****************/ |
---|
[129] | 73 | /*String provName = chooseProviderForExecution(resourceManager); |
---|
| 74 | if (provName != null) { |
---|
| 75 | addToSchedulingPlan(plan, task, provName); |
---|
| 76 | }*/ |
---|
[104] | 77 | |
---|
[192] | 78 | /****************3. Scheduler will choose random resources to perform execution****************/ |
---|
[129] | 79 | //addToSchedulingPlan(plan, task); |
---|
[104] | 80 | } |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | break; |
---|
| 84 | } |
---|
| 85 | return plan; |
---|
| 86 | } |
---|
| 87 | |
---|
[129] | 88 | private HashMap<ResourceParameterName, ResourceUnit> chooseResourcesForExecution( |
---|
[104] | 89 | ClusterResourceManager resourceManager, ExecTaskInterface task) { |
---|
| 90 | |
---|
| 91 | HashMap<ResourceParameterName, ResourceUnit> map = new HashMap<ResourceParameterName, ResourceUnit>(); |
---|
| 92 | |
---|
| 93 | int cpuRequest; |
---|
| 94 | try { |
---|
| 95 | cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue(); |
---|
| 96 | } catch (NoSuchFieldException e) { |
---|
| 97 | cpuRequest = 1; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | if (cpuRequest != 0) { |
---|
| 101 | List<ComputingResource> choosenResources = null; |
---|
[204] | 102 | List<Processor> processors = null; |
---|
[104] | 103 | processors = resourceManager.getProcessors(); |
---|
| 104 | if (processors.size() < cpuRequest) { |
---|
| 105 | // log.warn("Task requires more cpus than is availiable in this resource."); |
---|
| 106 | return null; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | choosenResources = new ArrayList<ComputingResource>(); |
---|
| 110 | |
---|
| 111 | for (int i = 0; i < processors.size() && cpuRequest > 0; i++) { |
---|
| 112 | if (processors.get(i).getStatus() == ResourceStatus.FREE) { |
---|
| 113 | choosenResources.add(processors.get(i)); |
---|
| 114 | cpuRequest--; |
---|
| 115 | } |
---|
| 116 | } |
---|
| 117 | if (cpuRequest > 0) { |
---|
| 118 | // log.info("Task " + task.getJobId() + "_" + task.getId() + |
---|
| 119 | // " requires more cpus than is availiable in this moment."); |
---|
| 120 | return null; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | ProcessingElements result = new ProcessingElements(processors.get(0).getParent().getName()); |
---|
| 124 | result.addAll(choosenResources); |
---|
| 125 | map.put(ResourceParameterName.PROCESSINGELEMENTS, result); |
---|
| 126 | |
---|
| 127 | } |
---|
| 128 | int memoryRequest; |
---|
| 129 | try { |
---|
| 130 | memoryRequest = Double.valueOf(task.getMemoryRequest()).intValue(); |
---|
| 131 | } catch (NoSuchFieldException e) { |
---|
| 132 | memoryRequest = 0; |
---|
| 133 | } |
---|
| 134 | if (memoryRequest != 0) { |
---|
| 135 | List<ComputingNode> nodes = resourceManager.getComputingNodes(); |
---|
| 136 | |
---|
| 137 | Memory memory = null; |
---|
| 138 | for (ComputingNode node : nodes) { |
---|
| 139 | |
---|
| 140 | if (node.getFreeMemory() >= memoryRequest) { |
---|
[192] | 141 | memory = new Memory(node.getMemoryUnit(), memoryRequest, memoryRequest); |
---|
[104] | 142 | } else |
---|
| 143 | return null; |
---|
| 144 | } |
---|
| 145 | map.put(ResourceParameterName.MEMORY, memory); |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | return map; |
---|
| 149 | } |
---|
| 150 | |
---|
[192] | 151 | @SuppressWarnings("unchecked") |
---|
[129] | 152 | private String chooseProviderForExecution(ResourceManagerInterface unitsManager) { |
---|
| 153 | List<ComputingResource> processingElements; |
---|
| 154 | Properties properties = new Properties(); |
---|
| 155 | properties.setProperty("type", ResourceType.COMPUTING_NODE.toString()); |
---|
| 156 | // properties.setProperty("status", ResourceStatus.FREE.toString()); |
---|
| 157 | processingElements = (List<ComputingResource>) unitsManager.filterResources(properties); |
---|
| 158 | return processingElements.get(0).getName(); |
---|
| 159 | } |
---|
| 160 | |
---|
[104] | 161 | public String getName() { |
---|
| 162 | return getClass().getName(); |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | public void init(Properties properties) { |
---|
| 166 | // no extra initialization is expected. |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | } |
---|