[477] | 1 | package example.localplugin; |
---|
| 2 | |
---|
[481] | 3 | import gridsim.gssim.DCWormsTags; |
---|
[477] | 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.scheduling.manager.resources.ClusterResourceManager; |
---|
| 11 | import schedframe.scheduling.manager.resources.ResourceManager; |
---|
| 12 | import schedframe.scheduling.manager.tasks.JobRegistry; |
---|
| 13 | import schedframe.scheduling.plan.SchedulingPlanInterface; |
---|
| 14 | import schedframe.scheduling.plan.impl.SchedulingPlan; |
---|
| 15 | import schedframe.scheduling.plugin.grid.ModuleList; |
---|
| 16 | import schedframe.scheduling.queue.TaskQueue; |
---|
| 17 | import schedframe.scheduling.queue.TaskQueueList; |
---|
| 18 | import schedframe.scheduling.tasks.TaskInterface; |
---|
| 19 | import schedframe.scheduling.tasks.WorkloadUnit; |
---|
| 20 | |
---|
| 21 | public class FCFSRandomClusterLocalPlugin extends BaseLocalSchedulingPlugin { |
---|
| 22 | |
---|
| 23 | private Random rand; |
---|
| 24 | |
---|
| 25 | public FCFSRandomClusterLocalPlugin() { |
---|
| 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 | // chose 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 | // BaseLocalPlugin.placeJobsInQueues() method) |
---|
| 42 | TaskQueue q = queues.get(0); |
---|
| 43 | // check all tasks in queue |
---|
| 44 | |
---|
| 45 | for (int i = 0; i < q.size(); i++) { |
---|
[478] | 46 | WorkloadUnit job = q.get(i); |
---|
[477] | 47 | TaskInterface<?> task = (TaskInterface<?>) job; |
---|
| 48 | // if status of the tasks in READY |
---|
[481] | 49 | if (task.getStatus() == DCWormsTags.READY) { |
---|
[477] | 50 | /*for(ResourceUnitName key:resManager.getSharedResourceUnits().keySet()){ |
---|
| 51 | System.out.println(key.getName()); |
---|
| 52 | }*/ |
---|
| 53 | addToSchedulingPlan(plan, task); |
---|
| 54 | /*String nodeName = chooseRandomProvider(resourceManager); |
---|
| 55 | if (nodeName != null) { |
---|
| 56 | addToSchedulingPlan(plan, task, nodeName); |
---|
| 57 | }*/ |
---|
| 58 | } |
---|
| 59 | } |
---|
| 60 | break; |
---|
| 61 | } |
---|
| 62 | return plan; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | private String chooseRandomProvider(ClusterResourceManager resourceManager) { |
---|
| 66 | List<ComputingNode> nodes = resourceManager.getComputingNodes(); |
---|
| 67 | int nodeIdx = rand.nextInt(nodes.size()); |
---|
| 68 | return nodes.get(nodeIdx).getName(); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | public String getName() { |
---|
| 72 | return getClass().getName(); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | } |
---|
| 77 | |
---|