1 | package example.localplugin.recs; |
---|
2 | |
---|
3 | import example.localplugin.BaseLocalSchedulingPlugin; |
---|
4 | import gridsim.dcworms.DCWormsTags; |
---|
5 | |
---|
6 | import java.util.List; |
---|
7 | import java.util.Random; |
---|
8 | |
---|
9 | import schedframe.events.scheduling.SchedulingEvent; |
---|
10 | import schedframe.exceptions.ResourceException; |
---|
11 | import schedframe.resources.UserResourceType; |
---|
12 | import schedframe.resources.computing.ComputingResource; |
---|
13 | import schedframe.scheduling.manager.resources.ClusterResourceManager; |
---|
14 | import schedframe.scheduling.manager.resources.ResourceManager; |
---|
15 | import schedframe.scheduling.manager.tasks.JobRegistry; |
---|
16 | import schedframe.scheduling.plan.SchedulingPlanInterface; |
---|
17 | import schedframe.scheduling.plan.impl.SchedulingPlan; |
---|
18 | import schedframe.scheduling.plugin.grid.ModuleList; |
---|
19 | import schedframe.scheduling.queue.TaskQueue; |
---|
20 | import schedframe.scheduling.queue.TaskQueueList; |
---|
21 | import schedframe.scheduling.tasks.TaskInterface; |
---|
22 | |
---|
23 | public class FCFSBF_RECS_SP extends BaseLocalSchedulingPlugin { |
---|
24 | |
---|
25 | private Random rand; |
---|
26 | |
---|
27 | public FCFSBF_RECS_SP () { |
---|
28 | rand = new Random(47); |
---|
29 | } |
---|
30 | |
---|
31 | public SchedulingPlanInterface<?> schedule(SchedulingEvent event, TaskQueueList queues, JobRegistry jobRegistry, |
---|
32 | ResourceManager resManager, ModuleList modules) { |
---|
33 | |
---|
34 | ClusterResourceManager resourceManager = (ClusterResourceManager) resManager; |
---|
35 | SchedulingPlan plan = new SchedulingPlan(); |
---|
36 | // choose the events types to serve. |
---|
37 | // Different actions for different events are possible. |
---|
38 | switch (event.getType()) { |
---|
39 | case START_TASK_EXECUTION: |
---|
40 | case TASK_FINISHED: |
---|
41 | //case TIMER: |
---|
42 | // our tasks are placed only in first queue (see |
---|
43 | // BaseLocalSchedulingPlugin.placeJobsInQueues() method) |
---|
44 | TaskQueue q = queues.get(0); |
---|
45 | |
---|
46 | // check all tasks in queue |
---|
47 | for (int i = 0; i < q.size(); i++) { |
---|
48 | TaskInterface<?> task = q.get(i); |
---|
49 | // if status of the tasks in READY |
---|
50 | if (task.getStatus() == DCWormsTags.READY) { |
---|
51 | |
---|
52 | String nodeName = chooseRandomProvider(resourceManager); |
---|
53 | if (nodeName != null) { |
---|
54 | addToSchedulingPlan(plan, task, nodeName); |
---|
55 | } |
---|
56 | } |
---|
57 | } |
---|
58 | break; |
---|
59 | } |
---|
60 | return plan; |
---|
61 | } |
---|
62 | |
---|
63 | @SuppressWarnings("unchecked") |
---|
64 | private String chooseRandomProvider(ClusterResourceManager resourceManager) { |
---|
65 | List<ComputingResource> nodes = null; |
---|
66 | try { |
---|
67 | nodes = (List<ComputingResource>) resourceManager.getResourcesOfType(new UserResourceType("Node")); |
---|
68 | } catch (ResourceException e) { |
---|
69 | // TODO Auto-generated catch block |
---|
70 | e.printStackTrace(); |
---|
71 | } |
---|
72 | int nodeIdx = rand.nextInt(nodes.size()); |
---|
73 | return nodes.get(nodeIdx).getName(); |
---|
74 | } |
---|
75 | |
---|
76 | } |
---|
77 | |
---|