source: DCWoRMS/trunk/src/test/article/recs/plugins/scheduling/RecsExclusivenessSP.java @ 679

Revision 679, 3.9 KB checked in by wojtekp, 12 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package test.article.recs.plugins.scheduling;
2
3import gridsim.dcworms.DCWormsTags;
4
5import java.util.ArrayList;
6import java.util.HashMap;
7import java.util.List;
8import java.util.Map;
9
10import schedframe.events.scheduling.SchedulingEvent;
11import schedframe.resources.ResourceStatus;
12import schedframe.resources.computing.ComputingNode;
13import schedframe.resources.computing.ComputingResource;
14import schedframe.resources.computing.Core;
15import schedframe.resources.units.ProcessingElements;
16import schedframe.resources.units.ResourceUnit;
17import schedframe.resources.units.ResourceUnitName;
18import schedframe.resources.units.StandardResourceUnitName;
19import schedframe.scheduling.manager.resources.ClusterResourceManager;
20import schedframe.scheduling.manager.resources.ResourceManager;
21import schedframe.scheduling.manager.tasks.JobRegistry;
22import schedframe.scheduling.plan.SchedulingPlanInterface;
23import schedframe.scheduling.plan.impl.SchedulingPlan;
24import schedframe.scheduling.plugin.grid.ModuleList;
25import schedframe.scheduling.queue.TaskQueue;
26import schedframe.scheduling.queue.TaskQueueList;
27import schedframe.scheduling.tasks.TaskInterface;
28
29public class RecsExclusivenessSP extends RecsSP {
30
31        public SchedulingPlanInterface<?> schedule(SchedulingEvent event, TaskQueueList queues, JobRegistry jobRegistry,
32                        ResourceManager resManager, ModuleList modules) {
33
34                ClusterResourceManager resourceManager = (ClusterResourceManager) resManager;
35                SchedulingPlan plan = new SchedulingPlan();
36                // choose the events types to serve.
37                // Different actions for different events are possible.
38                switch (event.getType()) {
39                case START_TASK_EXECUTION:
40                case TASK_FINISHED:
41                //case TIMER:
42                        // our tasks are placed only in first queue (see BaseLocalSchedulingPlugin.placeJobsInQueues() method)
43                        TaskQueue q = queues.get(0);
44                        // check all tasks in queue
45
46                        for (int i = 0; i < q.size(); i++) {
47                                TaskInterface<?> task = q.get(i);
48                                initApplicationType(task);
49                               
50                                // if status of the tasks in READY
51                                if (task.getStatus() == DCWormsTags.READY) {
52                                        Map<ResourceUnitName, ResourceUnit> choosenResources = chooseResourcesForExecution(resourceManager, task);
53                                        if (choosenResources != null) {
54                                                addToSchedulingPlan(plan, task, choosenResources);
55                                        }
56                                }
57                        }
58
59                        break;
60                }
61                return plan;
62        }
63
64        private Map<ResourceUnitName, ResourceUnit> chooseResourcesForExecution(
65                        ClusterResourceManager resourceManager, TaskInterface<?> task) {
66
67                Map<ResourceUnitName, ResourceUnit> map;
68                List<ComputingNode> nodes = resourceManager.getComputingNodes();
69                for (ComputingNode node : nodes) {
70                        int cpuRequest;
71                        try {
72                                cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue();
73                        } catch (NoSuchFieldException e) {
74                                cpuRequest = 0;
75                        }
76
77                        if (cpuRequest != 0) {
78
79                                /*Properties properties = new Properties();
80                                properties.setProperty("type", StandardResourceType.Core.getName());
81                                properties.setProperty("status", ResourceStatus.FREE.toString());
82                                 */
83                                List<Core> cores = node.getProcessors().get(0).getCores();
84                                if (cores.size() < cpuRequest/* || node.getProcessors().get(0).filterDescendants(properties).size() != cores.size()*/) {
85                                        continue;
86                                }
87
88                                int freeCores = 0;
89                                for(Core core: cores){
90                                        if(core.getStatus() == ResourceStatus.FREE)
91                                                freeCores++;
92                                }
93                               
94                                if(freeCores != cores.size())
95                                        continue;
96                                List<ComputingResource> choosenResources = new ArrayList<ComputingResource>();                         
97                                for (int i = 0; i < cores.size() && cpuRequest > 0; i++) {
98                                        if (cores.get(i).getStatus() == ResourceStatus.FREE) {
99                                                choosenResources.add(cores.get(i));
100                                                cpuRequest--;
101                                        }
102                                }
103                                if (cpuRequest > 0) {
104                                        continue;
105                                }
106                                map = new HashMap<ResourceUnitName, ResourceUnit>();
107                                ProcessingElements pe = new ProcessingElements();
108                                pe.addAll(choosenResources);
109                                map.put(StandardResourceUnitName.PE, pe);
110                                return map;
111
112                        }
113                }
114       
115                return null;
116        }
117
118}
Note: See TracBrowser for help on using the repository browser.