source: DCWoRMS/trunk/src/test/article/recs/plugins/scheduling/old/RecsExclusivenessFirstSP.java @ 709

Revision 709, 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.old;
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;
28import test.article.recs.plugins.scheduling.RecsSP;
29
30public class RecsExclusivenessFirstSP extends RecsSP {
31
32        public SchedulingPlanInterface<?> schedule(SchedulingEvent event, TaskQueueList queues, JobRegistry jobRegistry,
33                        ResourceManager resManager, ModuleList modules) {
34
35                ClusterResourceManager resourceManager = (ClusterResourceManager) resManager;
36                SchedulingPlan plan = new SchedulingPlan();
37                // choose the events types to serve.
38                // Different actions for different events are possible.
39                switch (event.getType()) {
40                case START_TASK_EXECUTION:
41                case TASK_FINISHED:
42                //case TIMER:
43                        // our tasks are placed only in first queue (see BaseLocalSchedulingPlugin.placeJobsInQueues() method)
44                        TaskQueue q = queues.get(0);
45                        // check all tasks in queue
46
47                        for (int i = 0; i < q.size(); i++) {
48                                TaskInterface<?> task = q.get(i);
49                                initApplicationType(task);
50                               
51                                // if status of the tasks in READY
52                                if (task.getStatus() == DCWormsTags.READY) {
53                                        Map<ResourceUnitName, ResourceUnit> choosenResources = chooseResourcesForExecution(resourceManager, task);
54                                        if (choosenResources != null) {
55                                                addToSchedulingPlan(plan, task, choosenResources);
56                                        }
57                                }
58                        }
59
60                        break;
61                }
62                return plan;
63        }
64
65        private Map<ResourceUnitName, ResourceUnit> chooseResourcesForExecution(
66                        ClusterResourceManager resourceManager, TaskInterface<?> task) {
67
68                Map<ResourceUnitName, ResourceUnit> map;
69                List<ComputingNode> nodes = resourceManager.getComputingNodes();
70                for (ComputingNode node : nodes) {
71                        int cpuRequest;
72                        try {
73                                cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue();
74                        } catch (NoSuchFieldException e) {
75                                cpuRequest = 0;
76                        }
77
78                        if (cpuRequest != 0) {
79
80                                /*Properties properties = new Properties();
81                                properties.setProperty("type", StandardResourceType.Core.getName());
82                                properties.setProperty("status", ResourceStatus.FREE.toString());
83                                 */
84                                List<Core> cores = node.getProcessors().get(0).getCores();
85                                if (cores.size() < cpuRequest/* || node.getProcessors().get(0).filterDescendants(properties).size() != cores.size()*/) {
86                                        continue;
87                                }
88
89                                int freeCores = 0;
90                                for(Core core: cores){
91                                        if(core.getStatus() == ResourceStatus.FREE)
92                                                freeCores++;
93                                }
94                               
95                                if(freeCores != cores.size())
96                                        continue;
97                                List<ComputingResource> choosenResources = new ArrayList<ComputingResource>();                         
98                                for (int i = 0; i < cores.size() && cpuRequest > 0; i++) {
99                                        if (cores.get(i).getStatus() == ResourceStatus.FREE) {
100                                                choosenResources.add(cores.get(i));
101                                                cpuRequest--;
102                                        }
103                                }
104                                if (cpuRequest > 0) {
105                                        continue;
106                                }
107                                map = new HashMap<ResourceUnitName, ResourceUnit>();
108                                ProcessingElements pe = new ProcessingElements();
109                                pe.addAll(choosenResources);
110                                map.put(StandardResourceUnitName.PE, pe);
111                                return map;
112
113                        }
114                }
115       
116                return null;
117        }
118
119}
Note: See TracBrowser for help on using the repository browser.