package example.gridplugin; import java.util.LinkedList; import java.util.List; import java.util.Properties; 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.GSSIMQueue; import test.rewolucja.scheduling.queue.QueueList; public class GridFCFSRoundRobinPlugin extends BaseGlobalPlugin { private LinkedList lastUsedResources = new LinkedList(); 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(); GSSIMQueue q = queues.get(0); int size = q.size(); // order of the resources on this list is not determined List availableResources = resources.getResources(); for(int i = 0; i < size; i++) { GSSIMJobInterface job = q.remove(0); TaskInterface task = (TaskInterface)job; ResourceDescription rd = availableResources.get(availableResources.size() - 1); for(ResourceDescription resDesc: availableResources){ if(!lastUsedResources.contains(resDesc.getProvider().getProviderId())){ if(lastUsedResources.size() + 1 >= availableResources.size()){ lastUsedResources.poll(); } lastUsedResources.add(resDesc.getProvider().getProviderId()); rd = resDesc; break; } } 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. } }