[104] | 1 | package example.gridplugin; |
---|
| 2 | |
---|
| 3 | import java.util.LinkedList; |
---|
| 4 | import java.util.List; |
---|
| 5 | import java.util.Properties; |
---|
| 6 | |
---|
| 7 | import schedframe.resources.ResourceDescription; |
---|
| 8 | import schedframe.scheduling.TaskInterface; |
---|
| 9 | import schedframe.scheduling.events.SchedulingEvent; |
---|
| 10 | import schedframe.scheduling.plugin.SchedulingPluginConfiguration; |
---|
| 11 | import schedframe.scheduling.plugin.configuration.DefaultConfiguration; |
---|
| 12 | import schedframe.scheduling.plugin.grid.Module; |
---|
| 13 | import schedframe.scheduling.plugin.grid.ModuleList; |
---|
| 14 | import schedframe.scheduling.plugin.grid.ResourceDiscovery; |
---|
| 15 | import test.rewolucja.GSSIMJobInterface; |
---|
| 16 | import test.rewolucja.resources.manager.interfaces.ResourceManagerInterface; |
---|
| 17 | import test.rewolucja.scheduling.JobRegistryInterface; |
---|
| 18 | import test.rewolucja.scheduling.plan.AllocationNew; |
---|
| 19 | import test.rewolucja.scheduling.plan.ScheduledTaskNew; |
---|
| 20 | import test.rewolucja.scheduling.plan.SchedulingPlanInterfaceNew; |
---|
| 21 | import test.rewolucja.scheduling.plan.SchedulingPlanNew; |
---|
| 22 | import test.rewolucja.scheduling.queue.GSSIMQueue; |
---|
| 23 | import test.rewolucja.scheduling.queue.QueueList; |
---|
| 24 | |
---|
| 25 | public class GridFCFSRoundRobinPlugin extends BaseGlobalPlugin { |
---|
| 26 | |
---|
| 27 | private LinkedList<String> lastUsedResources = new LinkedList<String>(); |
---|
| 28 | |
---|
| 29 | public SchedulingPlanInterfaceNew schedule(SchedulingEvent event, |
---|
| 30 | QueueList queues, |
---|
| 31 | JobRegistryInterface jobRegistry, |
---|
| 32 | ResourceManagerInterface resourceManager, ModuleList modules) { |
---|
| 33 | |
---|
| 34 | ResourceDiscovery resources = null; |
---|
| 35 | for(int i = 0; i < modules.size(); i++){ |
---|
| 36 | Module m = modules.get(i); |
---|
| 37 | switch(m.getType()){ |
---|
| 38 | case RESOURCE_DISCOVERY: resources = (ResourceDiscovery) m; |
---|
| 39 | break; |
---|
| 40 | } |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | SchedulingPlanNew plan = new SchedulingPlanNew(); |
---|
| 44 | |
---|
| 45 | GSSIMQueue q = queues.get(0); |
---|
| 46 | int size = q.size(); |
---|
| 47 | |
---|
| 48 | // order of the resources on this list is not determined |
---|
| 49 | List<ResourceDescription> availableResources = resources.getResources(); |
---|
| 50 | |
---|
| 51 | for(int i = 0; i < size; i++) { |
---|
| 52 | GSSIMJobInterface<?> job = q.remove(0); |
---|
| 53 | TaskInterface<?> task = (TaskInterface<?>)job; |
---|
| 54 | |
---|
| 55 | ResourceDescription rd = availableResources.get(availableResources.size() - 1); |
---|
| 56 | for(ResourceDescription resDesc: availableResources){ |
---|
| 57 | if(!lastUsedResources.contains(resDesc.getProvider().getProviderId())){ |
---|
| 58 | if(lastUsedResources.size() + 1 >= availableResources.size()){ |
---|
| 59 | lastUsedResources.poll(); |
---|
| 60 | } |
---|
| 61 | lastUsedResources.add(resDesc.getProvider().getProviderId()); |
---|
| 62 | rd = resDesc; |
---|
| 63 | break; |
---|
| 64 | } |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | AllocationNew allocation = new AllocationNew(); |
---|
| 68 | allocation.setProcessesCount(1); |
---|
| 69 | allocation.setProviderName(rd.getProvider().getProviderId()); |
---|
| 70 | |
---|
| 71 | ScheduledTaskNew scheduledTask = new ScheduledTaskNew(task); |
---|
| 72 | scheduledTask.setTaskId(task.getId()); |
---|
| 73 | scheduledTask.setJobId(task.getJobId()); |
---|
| 74 | scheduledTask.addAllocation(allocation); |
---|
| 75 | |
---|
| 76 | plan.addTask(scheduledTask); |
---|
| 77 | } |
---|
| 78 | return plan; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | public SchedulingPluginConfiguration getConfiguration() { |
---|
| 83 | return DefaultConfiguration.forGridPlugin(); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | public String getName() { |
---|
| 87 | return getClass().getName(); |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | public void init(Properties properties) { |
---|
| 91 | // no extra initialization is expected. |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | } |
---|