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