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