source: DCWoRMS/trunk/src/example/localplugin/FCFSRandomClusterLocalPlugin.java @ 497

Revision 497, 2.2 KB checked in by wojtekp, 13 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;
19import schedframe.scheduling.tasks.WorkloadUnit;
20
21public class FCFSRandomClusterLocalPlugin extends BaseLocalSchedulingPlugin {
22
23        private Random rand;
24       
25        public FCFSRandomClusterLocalPlugin() {
26                rand = new Random(5);
27        }
28
29        public SchedulingPlanInterface<?> schedule(SchedulingEvent event, TaskQueueList queues, JobRegistry jobRegistry,
30                         ResourceManager resManager, ModuleList modules) {
31
32                ClusterResourceManager resourceManager = (ClusterResourceManager) resManager;
33                SchedulingPlan plan = new SchedulingPlan();
34                // chose the events types to serve.
35                // Different actions for different events are possible.
36                switch (event.getType()) {
37                case START_TASK_EXECUTION:
38                case TASK_FINISHED:
39                //case TIMER:
40                        // our tasks are placed only in first queue (see
41                        // BaseLocalPlugin.placeJobsInQueues() method)
42                        TaskQueue q = queues.get(0);
43                       
44                        // check all tasks in queue
45                        for (int i = 0; i < q.size(); i++) {
46                                WorkloadUnit job = q.get(i);
47                                TaskInterface<?> task = (TaskInterface<?>) job;
48                                // if status of the tasks in READY
49                                if (task.getStatus() == DCWormsTags.READY) {
50
51                                        String nodeName = chooseRandomProvider(resourceManager);
52                                        if (nodeName != null) {
53                                                addToSchedulingPlan(plan, task, nodeName);
54                                        }
55                                }
56                        }
57                        break;
58                }
59                return plan;
60        }
61
62        private String chooseRandomProvider(ClusterResourceManager resourceManager) {
63                List<ComputingNode> nodes = resourceManager.getComputingNodes();
64                int nodeIdx = rand.nextInt(nodes.size());
65                return nodes.get(nodeIdx).getName();
66        }
67
68}
69
Note: See TracBrowser for help on using the repository browser.