package example.gridplugin; import java.util.List; import java.util.Properties; import java.util.Random; import schedframe.resources.ResourceDescription; import schedframe.scheduling.TaskInterface; import schedframe.scheduling.events.SchedulingEvent; import schedframe.scheduling.plugin.SchedulingPluginConfiguration; import schedframe.scheduling.plugin.configuration.DefaultConfiguration; import schedframe.scheduling.plugin.grid.Module; import schedframe.scheduling.plugin.grid.ModuleList; import schedframe.scheduling.plugin.grid.ResourceDiscovery; import test.rewolucja.GSSIMJobInterface; import test.rewolucja.resources.manager.interfaces.ResourceManagerInterface; import test.rewolucja.scheduling.JobRegistryInterface; import test.rewolucja.scheduling.plan.AllocationNew; import test.rewolucja.scheduling.plan.ScheduledTaskNew; 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 GridFCFSRandomPlugin extends BaseGlobalPlugin { private Random rand; public GridFCFSRandomPlugin() { rand = new Random(5); } public SchedulingPlanInterfaceNew schedule(SchedulingEvent event, QueueList queues, JobRegistryInterface jobRegistry, ResourceManagerInterface resourceManager, ModuleList modules) { ResourceDiscovery resources = null; for(int i = 0; i < modules.size(); i++){ Module m = modules.get(i); switch(m.getType()){ case RESOURCE_DISCOVERY: resources = (ResourceDiscovery) m; break; } } SchedulingPlanNew plan = new SchedulingPlanNew(); Queue q = queues.get(0); int size = q.size(); // order of the resources on this list is not determined List availableResources = resources.getResources(null); int resourceIdx = -1; for(int i = 0; i < size; i++) { GSSIMJobInterface job = q.remove(0); TaskInterface task = (TaskInterface)job; resourceIdx = rand.nextInt(availableResources.size()); ResourceDescription rd = availableResources.get(resourceIdx); AllocationNew allocation = new AllocationNew(); allocation.setProcessesCount(1); allocation.setProviderName(rd.getProvider().getProviderId()); ScheduledTaskNew scheduledTask = new ScheduledTaskNew(task); scheduledTask.setTaskId(task.getId()); scheduledTask.setJobId(task.getJobId()); scheduledTask.addAllocation(allocation); plan.addTask(scheduledTask); } return plan; } public SchedulingPluginConfiguration getConfiguration() { return DefaultConfiguration.forGridPlugin(); } public String getName() { return getClass().getName(); } public void init(Properties properties) { // no extra initialization is expected. } }