source: DCWoRMS/branches/coolemall/src/experiments/e2dc2013/recs/plugins/scheduling/exp2/RecsLeft2RightSP.java @ 1499

Revision 1499, 6.7 KB checked in by wojtekp, 10 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package experiments.e2dc2013.recs.plugins.scheduling.exp2;
2
3import experiments.e2dc2013.recs.plugins.scheduling.RecsSP;
4import gridsim.dcworms.DCWormsTags;
5
6import java.io.FileNotFoundException;
7import java.io.IOException;
8import java.util.ArrayList;
9import java.util.Collections;
10import java.util.Comparator;
11import java.util.HashMap;
12import java.util.List;
13import java.util.Map;
14import java.util.MissingResourceException;
15
16import schedframe.events.scheduling.SchedulingEvent;
17import schedframe.resources.ResourceStatus;
18import schedframe.resources.StandardResourceType;
19import schedframe.resources.computing.Node;
20import schedframe.resources.computing.ComputingResource;
21import schedframe.resources.computing.Core;
22import schedframe.resources.computing.profiles.energy.airthroughput.CustomAirflowStateName;
23import schedframe.resources.computing.profiles.energy.airthroughput.StandardAirflowStateName;
24import schedframe.resources.devices.Device;
25import schedframe.resources.devices.Fan;
26import schedframe.resources.units.ProcessingElements;
27import schedframe.resources.units.ResourceUnit;
28import schedframe.resources.units.ResourceUnitName;
29import schedframe.resources.units.StandardResourceUnitName;
30import schedframe.scheduling.manager.resources.ClusterResourceManager;
31import schedframe.scheduling.manager.resources.ResourceManager;
32import schedframe.scheduling.manager.tasks.JobRegistry;
33import schedframe.scheduling.plan.SchedulingPlanInterface;
34import schedframe.scheduling.plan.impl.SchedulingPlan;
35import schedframe.scheduling.plugin.ModuleList;
36import schedframe.scheduling.queue.TaskQueue;
37import schedframe.scheduling.queue.TaskQueueList;
38import schedframe.scheduling.tasks.TaskInterface;
39
40public class RecsLeft2RightSP extends RecsSP {
41
42        private static int START_ID = 0;
43        private static int END_ID = 17;
44
45        public SchedulingPlanInterface<?> schedule(SchedulingEvent event, TaskQueueList queues, JobRegistry jobRegistry,
46                        ResourceManager resManager, ModuleList modules) {
47
48                ClusterResourceManager resourceManager = (ClusterResourceManager) resManager;
49                SchedulingPlan plan = new SchedulingPlan();
50                // choose the events types to serve.
51                // Different actions for different events are possible.
52                switch (event.getType()) {
53                case START_TASK_EXECUTION:
54                case TASK_FINISHED:
55                        // case TIMER:
56                        // our tasks are placed only in first queue (see
57                        // BaseLocalSchedulingPlugin.placeJobsInQueues() method)
58                        TaskQueue q = queues.get(0);
59
60                        List<Node> notSelectedNodes = resourceManager.getNodes();
61                        // check all tasks in queue
62                        for (int i = 0; i < q.size(); i++) {
63                                TaskInterface<?> task = q.get(i);
64                                // if status of the tasks in READY
65                                if (task.getStatus() == DCWormsTags.READY) {
66                                        Node node = chooseProvider(resourceManager, task);
67                                        if (node != null) {
68                                                for(Device device: node.getParent().getResourceCharacteristic().getDevices()){
69                                                       
70                                                        if(device.getType().equals(StandardResourceType.Fan)){
71                                                                Fan fan = (Fan) device;
72
73                                                                if(fan.getChilledResources().contains(node.getFullName())){
74                                                                        fan.getAirflowInterface().setAirflowState(StandardAirflowStateName.ON);
75                                                                }
76                                                        }
77                                                }
78                                                //node.getAirflowInterface().setAirflowState(StandardAirflowStateName.ON);
79                                                notSelectedNodes.remove(node);
80                                                addToSchedulingPlan(plan, task, chooseResourcesForExecution(node, task));
81                                        }
82                                }
83                        }
84                        adjustOtherFans(notSelectedNodes);
85                        break;
86                }
87                return plan;
88        }
89
90        private Node chooseProvider(ClusterResourceManager resourceManager, TaskInterface<?> task) {
91                List<Node> nodes = filterNodes(resourceManager.getNodes(), task);
92                Collections.sort(nodes, new ResourceIdComparator());
93                for (Node node : nodes) {
94                        Integer id = Integer.parseInt(node.getName().split("_")[1]);
95                        if ((id >= START_ID && id <= END_ID)) {
96                                return node;
97                        }
98
99                }
100
101                return null;
102        }
103
104        private Map<ResourceUnitName, ResourceUnit> chooseResourcesForExecution(Node node, TaskInterface<?> task) {
105
106                Map<ResourceUnitName, ResourceUnit> map = new HashMap<ResourceUnitName, ResourceUnit>();
107
108                int cpuRequest;
109                try {
110                        cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue();
111                } catch (NoSuchFieldException e) {
112                        cpuRequest = 0;
113                }
114
115                if (cpuRequest != 0) {
116
117                        List<Core> cores = node.getProcessors().get(0).getCores();
118
119                        List<ComputingResource> choosenResources = new ArrayList<ComputingResource>();
120                        for (int i = 0; i < cores.size(); i++) {
121                                if (cores.get(i).getStatus() == ResourceStatus.FREE) {
122                                        // choosenResources.add(cores.get(i));
123                                        cpuRequest--;
124                                }
125                        }
126                        if (cpuRequest > 0) {
127                                // return null;
128                        }
129                        choosenResources.add(node.getProcessors().get(0));
130                        ProcessingElements pe = new ProcessingElements();
131                        pe.addAll(choosenResources);
132                        map.put(StandardResourceUnitName.PE, pe);
133                        return map;
134                }
135                return null;
136        }
137
138        private List<Node> filterNodes(List<Node> nodes, TaskInterface<?> task) {
139                List<Node> filteredNodes = new ArrayList<Node>();
140                for (Node node : nodes) {
141                        int cpuRequest;
142                        try {
143                                cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue();
144                        } catch (NoSuchFieldException e) {
145                                cpuRequest = 0;
146                        }
147
148                        if (cpuRequest != 0) {
149
150                                List<Core> cores = node.getProcessors().get(0).getCores();
151                                if (cores.size() < cpuRequest) {
152                                        continue;
153                                }
154
155                                int freeCores = 0;
156                                for (Core core : cores) {
157                                        if (core.getStatus() == ResourceStatus.FREE)
158                                                freeCores++;
159                                }
160
161                                if (freeCores != cores.size())
162                                        continue;
163
164                                try {
165                                        if (!getExecutiveness(createExecutivenessQuery(task, node)))
166                                                continue;
167                                } catch (FileNotFoundException e) {
168                                        continue;
169                                } catch (IOException e) {
170                                        continue;
171                                } catch (MissingResourceException e) {
172                                        continue;
173                                }
174                                filteredNodes.add(node);
175                        }
176                }
177
178                return filteredNodes;
179        }
180
181        private void adjustOtherFans(List<Node> nodes) {
182                for (Node node : nodes) {
183                        if (node.getFreeProcessorsNumber() == node.getProcessorsNumber()) {
184                                // node.getAirThroughputInterface().setAirThroughputState(StandardAirThroughputStateName.FAN_OFF);
185                        } else {
186                                for(Device device: node.getParent().getResourceCharacteristic().getDevices()){
187                                       
188                                        if(device.getType().equals(StandardResourceType.Fan)){
189                                                Fan fan = (Fan) device;
190
191                                                if(fan.getChilledResources().contains(node.getFullName())){
192                                                        fan.getAirflowInterface().setAirflowState(StandardAirflowStateName.ON);
193                                                }
194                                        }
195                                }
196                                //node.getAirflowInterface().setAirflowState(StandardAirflowStateName.ON);
197                        }
198                }
199        }
200
201        class ResourceIdComparator implements Comparator<Node> {
202
203                public int compare(Node node1, Node node2) {
204                        Integer id1 = Integer.parseInt(node1.getName().split("_")[1]);
205                        Integer id2 = Integer.parseInt(node2.getName().split("_")[1]);
206                        if (id1 % 9 > id2 % 9)
207                                return 1;
208                        else if (id1 % 9 < id2 % 9)
209                                return -1;
210                        else
211                                return 0;
212
213                }
214        }
215
216}
217
Note: See TracBrowser for help on using the repository browser.