[477] | 1 | package example.localplugin; |
---|
| 2 | |
---|
[493] | 3 | import gridsim.dcworms.DCWormsTags; |
---|
[477] | 4 | import schedframe.events.scheduling.SchedulingEvent; |
---|
| 5 | import schedframe.scheduling.manager.resources.ClusterResourceManager; |
---|
| 6 | import schedframe.scheduling.manager.resources.ResourceManager; |
---|
| 7 | import schedframe.scheduling.manager.tasks.JobRegistry; |
---|
| 8 | import schedframe.scheduling.plan.SchedulingPlanInterface; |
---|
| 9 | import schedframe.scheduling.plan.impl.SchedulingPlan; |
---|
| 10 | import schedframe.scheduling.plugin.grid.ModuleList; |
---|
| 11 | import schedframe.scheduling.queue.TaskQueue; |
---|
| 12 | import schedframe.scheduling.queue.TaskQueueList; |
---|
| 13 | import schedframe.scheduling.tasks.TaskInterface; |
---|
| 14 | import schedframe.scheduling.tasks.WorkloadUnit; |
---|
| 15 | |
---|
| 16 | public class RackLocalPlugin extends BaseLocalSchedulingPlugin { |
---|
| 17 | |
---|
| 18 | public RackLocalPlugin() { |
---|
| 19 | } |
---|
| 20 | |
---|
[481] | 21 | public SchedulingPlanInterface<?> schedule(SchedulingEvent event, TaskQueueList queues, JobRegistry jobRegistry, |
---|
[477] | 22 | ResourceManager resManager, ModuleList modules) { |
---|
| 23 | |
---|
| 24 | ClusterResourceManager resourceManager = (ClusterResourceManager) resManager; |
---|
| 25 | SchedulingPlan plan = new SchedulingPlan(); |
---|
| 26 | // chose the events types to serve. |
---|
| 27 | // Different actions for different events are possible. |
---|
| 28 | switch (event.getType()) { |
---|
| 29 | case START_TASK_EXECUTION: |
---|
| 30 | case TASK_FINISHED: |
---|
| 31 | //case TIMER: |
---|
| 32 | // our tasks are placed only in first queue (see |
---|
| 33 | // BaseLocalPlugin.placeJobsInQueues() method) |
---|
| 34 | TaskQueue q = queues.get(0); |
---|
| 35 | // check all tasks in queue |
---|
| 36 | |
---|
| 37 | for (int i = 0; i < q.size(); i++) { |
---|
[478] | 38 | WorkloadUnit job = q.get(i); |
---|
[477] | 39 | TaskInterface<?> task = (TaskInterface<?>) job; |
---|
| 40 | // if status of the tasks in READY |
---|
[481] | 41 | if (task.getStatus() == DCWormsTags.READY) { |
---|
[477] | 42 | System.out.println(resourceManager.getSchedulers().get(0).get_name()); |
---|
| 43 | String nodeName = resourceManager.getSchedulers().get(0).get_name(); |
---|
| 44 | if (nodeName != null) { |
---|
| 45 | addToSchedulingPlan(plan, task, nodeName); |
---|
| 46 | } |
---|
| 47 | } |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | break; |
---|
| 51 | } |
---|
| 52 | return plan; |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | public String getName() { |
---|
| 57 | return getClass().getName(); |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | } |
---|