source: xssim/trunk/src/example/localplugin/FCFSEnergyAwareClusterLocalPlugin.java @ 192

Revision 192, 3.3 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.ArrayList;
6import java.util.Collections;
7import java.util.Comparator;
8import java.util.List;
9import java.util.Properties;
10
11import schedframe.scheduling.TaskInterface;
12import schedframe.scheduling.events.SchedulingEvent;
13import schedframe.scheduling.plugin.grid.ModuleList;
14import test.rewolucja.GSSIMJobInterface;
15import test.rewolucja.resources.manager.implementation.ClusterResourceManager;
16import test.rewolucja.resources.manager.interfaces.ResourceManagerInterface;
17import test.rewolucja.resources.physical.implementation.ComputingNode;
18import test.rewolucja.scheduling.JobRegistryInterface;
19import test.rewolucja.scheduling.plan.SchedulingPlanInterfaceNew;
20import test.rewolucja.scheduling.plan.SchedulingPlanNew;
21import test.rewolucja.scheduling.queue.Queue;
22import test.rewolucja.scheduling.queue.QueueList;
23
24public class FCFSEnergyAwareClusterLocalPlugin extends BaseLocalPlugin {
25
26        public FCFSEnergyAwareClusterLocalPlugin () {
27        }
28
29        public SchedulingPlanInterfaceNew schedule(SchedulingEvent event, QueueList queues, JobRegistryInterface jobRegistry,
30                        ResourceManagerInterface resManager, ModuleList modules) {
31
32                ClusterResourceManager resourceManager = (ClusterResourceManager) resManager;
33                SchedulingPlanNew plan = new SchedulingPlanNew();
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                        // our tasks are placed only in first queue (see
40                        // BaseLocalPlugin.placeJobsInQueues() method)
41                        Queue q = queues.get(0);
42                        // check all tasks in queue
43
44                        for (int i = 0; i < q.size(); i++) {
45                                GSSIMJobInterface<?> job = q.get(i);
46                                TaskInterface<?> task = (TaskInterface<?>) job;
47                                // if status of the tasks in READY
48                                if (task.getStatus() == Gridlet.READY) {
49
50                                        String nodeName = chooseProviderForExecution(resourceManager, task);
51                                        if (nodeName != null) {
52                                                addToSchedulingPlan(plan, task, nodeName);
53                                        }
54                                }
55                        }
56
57                        break;
58                }
59                return plan;
60        }
61
62        private String chooseProviderForExecution(ClusterResourceManager resourceManager, TaskInterface<?> task) {
63                int cpuRequest;
64                try {
65                        cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue();
66                } catch (NoSuchFieldException e) {
67                        cpuRequest = 1;
68                }
69                List<ComputingNode> nodes = resourceManager.getComputingNodes();
70                nodes = findSuitableNodes(cpuRequest, nodes);
71                Collections.sort(nodes, new Comparator<ComputingNode>(){
72                         
73                    public int compare(ComputingNode node1, ComputingNode node2){   
74                        return node1.getCategory().getName().compareTo(node2.getCategory().getName());
75                   
76                    }
77                });
78
79                return nodes.size() == 0 ? null : nodes.get(0).getName();
80        }
81       
82        private List<ComputingNode> findSuitableNodes(int cpuRequest, List<ComputingNode> nodes){
83                List<ComputingNode> avNodes = new ArrayList<ComputingNode>();
84                for(ComputingNode node: nodes){
85                        if(node.getFreeProcessorsNumber() >= cpuRequest){
86                                avNodes.add(node);
87                        }
88                }
89                return avNodes;
90        }
91       
92        public String getName() {
93                return getClass().getName();
94        }
95
96        public void init(Properties properties) {
97                // no extra initialization is expected.
98        }
99
100        class CategoryComparator implements Comparator<String>{
101                 
102            public int compare(String cat1, String cat2){   
103                return cat1.compareTo(cat2);
104           
105            }
106        }
107}
108
Note: See TracBrowser for help on using the repository browser.