1 | package example.localplugin; |
---|
2 | |
---|
3 | import gridsim.Gridlet; |
---|
4 | |
---|
5 | import java.util.List; |
---|
6 | import java.util.Properties; |
---|
7 | import java.util.Random; |
---|
8 | |
---|
9 | import schedframe.scheduling.TaskInterface; |
---|
10 | import schedframe.scheduling.events.SchedulingEvent; |
---|
11 | import schedframe.scheduling.plugin.grid.ModuleList; |
---|
12 | import test.rewolucja.GSSIMJobInterface; |
---|
13 | import test.rewolucja.resources.manager.implementation.ClusterResourceManager; |
---|
14 | import test.rewolucja.resources.manager.interfaces.ResourceManagerInterface; |
---|
15 | import test.rewolucja.resources.physical.implementation.ComputingNode; |
---|
16 | import test.rewolucja.scheduling.JobRegistryInterface; |
---|
17 | import test.rewolucja.scheduling.plan.SchedulingPlanInterfaceNew; |
---|
18 | import test.rewolucja.scheduling.plan.SchedulingPlanNew; |
---|
19 | import test.rewolucja.scheduling.queue.GSSIMQueue; |
---|
20 | import test.rewolucja.scheduling.queue.QueueList; |
---|
21 | |
---|
22 | public 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 | |
---|