source: xssim/src/example/localplugin/FCFSRandomClusterLocalPlugin.java @ 104

Revision 104, 2.4 KB checked in by wojtekp, 13 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package example.localplugin;
2
3import gridsim.Gridlet;
4
5import java.util.List;
6import java.util.Properties;
7import java.util.Random;
8
9import schedframe.scheduling.TaskInterface;
10import schedframe.scheduling.events.SchedulingEvent;
11import schedframe.scheduling.plugin.grid.ModuleList;
12import test.rewolucja.GSSIMJobInterface;
13import test.rewolucja.resources.manager.implementation.ClusterResourceManager;
14import test.rewolucja.resources.manager.interfaces.ResourceManagerInterface;
15import test.rewolucja.resources.physical.implementation.ComputingNode;
16import test.rewolucja.scheduling.JobRegistryInterface;
17import test.rewolucja.scheduling.plan.SchedulingPlanInterfaceNew;
18import test.rewolucja.scheduling.plan.SchedulingPlanNew;
19import test.rewolucja.scheduling.queue.GSSIMQueue;
20import test.rewolucja.scheduling.queue.QueueList;
21
22public class FCFSRandomClusterLocalPlugin extends BaseLocalPlugin {
23
24        private Random rand;
25       
26        public FCFSRandomClusterLocalPlugin() {
27                rand = new Random(5);
28        }
29
30        public SchedulingPlanInterfaceNew schedule(SchedulingEvent event, QueueList queues, JobRegistryInterface jobRegistry,
31                         ResourceManagerInterface resManager, ModuleList modules) {
32
33                ClusterResourceManager resourceManager = (ClusterResourceManager) resManager;
34                SchedulingPlanNew plan = new SchedulingPlanNew();
35                // chose the events types to serve.
36                // Different actions for different events are possible.
37                switch (event.getType()) {
38                case START_TASK_EXECUTION:
39                case TASK_FINISHED:
40                        // our tasks are placed only in first queue (see
41                        // BaseLocalPlugin.placeTasksInQueues() method)
42                        GSSIMQueue q = queues.get(0);
43                        // check all tasks in queue
44
45                        for (int i = 0; i < q.size(); i++) {
46                                GSSIMJobInterface<?> job = q.get(i);
47                                TaskInterface<?> task = (TaskInterface<?>) job;
48                                // if status of the tasks in READY
49                                if (task.getStatus() == Gridlet.READY) {
50                                        String nodeName = chooseRandomProvider(resourceManager);
51                                        if (nodeName != null) {
52                                                addToSchedulingPlan(plan, task, nodeName);
53                                        }
54                                }
55                        }
56                        break;
57                }
58                return plan;
59        }
60
61        private String chooseRandomProvider(ClusterResourceManager resourceManager) {
62                List<ComputingNode> nodes = resourceManager.getComputingNodes();
63                int nodeIdx = rand.nextInt(nodes.size());
64                return nodes.get(nodeIdx).getName();
65        }
66       
67        public String getName() {
68                return getClass().getName();
69        }
70
71        public void init(Properties properties) {
72                // no extra initialization is expected.
73        }
74
75}
76
Note: See TracBrowser for help on using the repository browser.