source: DCWoRMS/trunk/src/example/localplugin/FCFSBF_RandomClusterPlugin.java @ 574

Revision 574, 2.1 KB checked in by wojtekp, 12 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package example.localplugin;
2
3import gridsim.dcworms.DCWormsTags;
4
5import java.util.List;
6import java.util.Random;
7
8import schedframe.events.scheduling.SchedulingEvent;
9import schedframe.resources.computing.ComputingNode;
10import schedframe.scheduling.manager.resources.ClusterResourceManager;
11import schedframe.scheduling.manager.resources.ResourceManager;
12import schedframe.scheduling.manager.tasks.JobRegistry;
13import schedframe.scheduling.plan.SchedulingPlanInterface;
14import schedframe.scheduling.plan.impl.SchedulingPlan;
15import schedframe.scheduling.plugin.grid.ModuleList;
16import schedframe.scheduling.queue.TaskQueue;
17import schedframe.scheduling.queue.TaskQueueList;
18import schedframe.scheduling.tasks.TaskInterface;
19
20public 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
Note: See TracBrowser for help on using the repository browser.