[104] | 1 | package example.gridplugin; |
---|
| 2 | |
---|
| 3 | import java.util.List; |
---|
| 4 | import java.util.Properties; |
---|
| 5 | import java.util.Random; |
---|
| 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 GridFCFSRandomPlugin extends BaseGlobalPlugin { |
---|
| 26 | |
---|
| 27 | private Random rand; |
---|
| 28 | |
---|
| 29 | public GridFCFSRandomPlugin() { |
---|
| 30 | rand = new Random(5); |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | public SchedulingPlanInterfaceNew schedule(SchedulingEvent event, |
---|
| 34 | QueueList queues, |
---|
| 35 | JobRegistryInterface jobRegistry, |
---|
| 36 | ResourceManagerInterface resourceManager, ModuleList modules) { |
---|
| 37 | |
---|
| 38 | ResourceDiscovery resources = null; |
---|
| 39 | for(int i = 0; i < modules.size(); i++){ |
---|
| 40 | Module m = modules.get(i); |
---|
| 41 | switch(m.getType()){ |
---|
| 42 | case RESOURCE_DISCOVERY: resources = (ResourceDiscovery) m; |
---|
| 43 | break; |
---|
| 44 | } |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | SchedulingPlanNew plan = new SchedulingPlanNew(); |
---|
| 48 | |
---|
| 49 | GSSIMQueue q = queues.get(0); |
---|
| 50 | int size = q.size(); |
---|
| 51 | |
---|
| 52 | // order of the resources on this list is not determined |
---|
| 53 | List<ResourceDescription> availableResources = resources.getResources(null); |
---|
| 54 | int resourceIdx = -1; |
---|
| 55 | |
---|
| 56 | for(int i = 0; i < size; i++) { |
---|
| 57 | GSSIMJobInterface<?> job = q.remove(0); |
---|
| 58 | TaskInterface<?> task = (TaskInterface<?>)job; |
---|
| 59 | |
---|
| 60 | resourceIdx = rand.nextInt(availableResources.size()); |
---|
| 61 | ResourceDescription rd = availableResources.get(resourceIdx); |
---|
| 62 | |
---|
| 63 | AllocationNew allocation = new AllocationNew(); |
---|
| 64 | allocation.setProcessesCount(1); |
---|
| 65 | allocation.setProviderName(rd.getProvider().getProviderId()); |
---|
| 66 | |
---|
| 67 | ScheduledTaskNew scheduledTask = new ScheduledTaskNew(task); |
---|
| 68 | scheduledTask.setTaskId(task.getId()); |
---|
| 69 | scheduledTask.setJobId(task.getJobId()); |
---|
| 70 | scheduledTask.addAllocation(allocation); |
---|
| 71 | |
---|
| 72 | plan.addTask(scheduledTask); |
---|
| 73 | |
---|
| 74 | } |
---|
| 75 | return plan; |
---|
| 76 | |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | public SchedulingPluginConfiguration getConfiguration() { |
---|
| 80 | return DefaultConfiguration.forGridPlugin(); |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | public String getName() { |
---|
| 84 | return getClass().getName(); |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | public void init(Properties properties) { |
---|
| 88 | // no extra initialization is expected. |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | } |
---|