package example.localplugin; import gridsim.Gridlet; import java.util.List; import java.util.Properties; import java.util.Random; import schedframe.scheduling.TaskInterface; import schedframe.scheduling.events.SchedulingEvent; import schedframe.scheduling.plugin.grid.ModuleList; import test.rewolucja.GSSIMJobInterface; import test.rewolucja.resources.manager.implementation.ClusterResourceManager; import test.rewolucja.resources.manager.interfaces.ResourceManagerInterface; import test.rewolucja.resources.physical.implementation.ComputingNode; import test.rewolucja.scheduling.JobRegistryInterface; import test.rewolucja.scheduling.plan.SchedulingPlanInterfaceNew; import test.rewolucja.scheduling.plan.SchedulingPlanNew; import test.rewolucja.scheduling.queue.Queue; import test.rewolucja.scheduling.queue.QueueList; public class FCFSRandomClusterLocalPlugin extends BaseLocalPlugin { private Random rand; public FCFSRandomClusterLocalPlugin() { rand = new Random(5); } public SchedulingPlanInterfaceNew schedule(SchedulingEvent event, QueueList queues, JobRegistryInterface jobRegistry, ResourceManagerInterface resManager, ModuleList modules) { ClusterResourceManager resourceManager = (ClusterResourceManager) resManager; SchedulingPlanNew plan = new SchedulingPlanNew(); // chose the events types to serve. // Different actions for different events are possible. switch (event.getType()) { case START_TASK_EXECUTION: case TASK_FINISHED: // our tasks are placed only in first queue (see // BaseLocalPlugin.placeJobsInQueues() method) Queue q = queues.get(0); // check all tasks in queue for (int i = 0; i < q.size(); i++) { GSSIMJobInterface job = q.get(i); TaskInterface task = (TaskInterface) job; // if status of the tasks in READY if (task.getStatus() == Gridlet.READY) { String nodeName = chooseRandomProvider(resourceManager); if (nodeName != null) { addToSchedulingPlan(plan, task, nodeName); } } } break; } return plan; } private String chooseRandomProvider(ClusterResourceManager resourceManager) { List nodes = resourceManager.getComputingNodes(); int nodeIdx = rand.nextInt(nodes.size()); return nodes.get(nodeIdx).getName(); } public String getName() { return getClass().getName(); } public void init(Properties properties) { // no extra initialization is expected. } }