1 | package example.globalplugin; |
---|
2 | |
---|
3 | import java.util.LinkedList; |
---|
4 | import java.util.List; |
---|
5 | |
---|
6 | import schedframe.events.scheduling.SchedulingEvent; |
---|
7 | import schedframe.scheduling.SchedulerDescription; |
---|
8 | import schedframe.scheduling.manager.resources.ResourceManager; |
---|
9 | import schedframe.scheduling.manager.tasks.JobRegistry; |
---|
10 | import schedframe.scheduling.plan.SchedulingPlanInterface; |
---|
11 | import schedframe.scheduling.plan.impl.Allocation; |
---|
12 | import schedframe.scheduling.plan.impl.ScheduledTask; |
---|
13 | import schedframe.scheduling.plan.impl.SchedulingPlan; |
---|
14 | import schedframe.scheduling.plugin.Module; |
---|
15 | import schedframe.scheduling.plugin.ModuleList; |
---|
16 | import schedframe.scheduling.plugin.grid.ResourceDiscovery; |
---|
17 | import schedframe.scheduling.queue.TaskQueue; |
---|
18 | import schedframe.scheduling.queue.TaskQueueList; |
---|
19 | import schedframe.scheduling.tasks.TaskInterface; |
---|
20 | import schedframe.scheduling.tasks.WorkloadUnit; |
---|
21 | |
---|
22 | public class GridFCFSRoundRobinPlugin extends BaseGlobalPlugin { |
---|
23 | |
---|
24 | private LinkedList<String> lastUsedResources = new LinkedList<String>(); |
---|
25 | |
---|
26 | public SchedulingPlanInterface<?> schedule(SchedulingEvent event, |
---|
27 | TaskQueueList queues, |
---|
28 | JobRegistry jobRegistry, |
---|
29 | ResourceManager resourceManager, ModuleList modules) { |
---|
30 | |
---|
31 | ResourceDiscovery resources = null; |
---|
32 | for(int i = 0; i < modules.size(); i++){ |
---|
33 | Module m = modules.get(i); |
---|
34 | switch(m.getType()){ |
---|
35 | case RESOURCE_DISCOVERY: resources = (ResourceDiscovery) m; |
---|
36 | break; |
---|
37 | } |
---|
38 | } |
---|
39 | |
---|
40 | SchedulingPlan plan = new SchedulingPlan(); |
---|
41 | |
---|
42 | TaskQueue q = queues.get(0); |
---|
43 | int size = q.size(); |
---|
44 | |
---|
45 | // order of the resources on this list is not determined |
---|
46 | List<SchedulerDescription> availableResources = resources.getResources(); |
---|
47 | |
---|
48 | for(int i = 0; i < size; i++) { |
---|
49 | WorkloadUnit job = q.remove(0); |
---|
50 | TaskInterface<?> task = (TaskInterface<?>)job; |
---|
51 | |
---|
52 | SchedulerDescription sd = availableResources.get(availableResources.size() - 1); |
---|
53 | for(SchedulerDescription schedDesc: availableResources){ |
---|
54 | if(!lastUsedResources.contains(schedDesc.getProvider().getProviderId())){ |
---|
55 | if(lastUsedResources.size() + 1 >= availableResources.size()){ |
---|
56 | lastUsedResources.poll(); |
---|
57 | } |
---|
58 | lastUsedResources.add(schedDesc.getProvider().getProviderId()); |
---|
59 | sd = schedDesc; |
---|
60 | break; |
---|
61 | } |
---|
62 | } |
---|
63 | |
---|
64 | Allocation allocation = new Allocation(); |
---|
65 | allocation.setProcessesCount(1); |
---|
66 | allocation.setProviderName(sd.getProvider().getProviderId()); |
---|
67 | ScheduledTask scheduledTask = new ScheduledTask(task); |
---|
68 | scheduledTask.setTaskId(task.getId()); |
---|
69 | scheduledTask.setJobId(task.getJobId()); |
---|
70 | scheduledTask.addAllocation(allocation); |
---|
71 | |
---|
72 | plan.addTask(scheduledTask); |
---|
73 | } |
---|
74 | return plan; |
---|
75 | } |
---|
76 | |
---|
77 | } |
---|