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

Revision 656, 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 java.util.ArrayList;
4import java.util.HashMap;
5import java.util.List;
6import java.util.Map;
7
8import schedframe.events.scheduling.SchedulingEvent;
9import schedframe.resources.ResourceStatus;
10import schedframe.resources.computing.ComputingNode;
11import schedframe.resources.computing.ComputingResource;
12import schedframe.resources.computing.Core;
13import schedframe.resources.units.ProcessingElements;
14import schedframe.resources.units.ResourceUnit;
15import schedframe.resources.units.ResourceUnitName;
16import schedframe.resources.units.StandardResourceUnitName;
17import schedframe.scheduling.manager.resources.ClusterResourceManager;
18import schedframe.scheduling.manager.resources.ResourceManager;
19import schedframe.scheduling.manager.tasks.JobRegistry;
20import schedframe.scheduling.plan.SchedulingPlanInterface;
21import schedframe.scheduling.plan.impl.SchedulingPlan;
22import schedframe.scheduling.plugin.grid.ModuleList;
23import schedframe.scheduling.queue.TaskQueue;
24import schedframe.scheduling.queue.TaskQueueList;
25import schedframe.scheduling.tasks.TaskInterface;
26import example.localplugin.BaseLocalSchedulingPlugin;
27import gridsim.dcworms.DCWormsTags;
28
29public class RecsExclusivenessSP extends BaseLocalSchedulingPlugin {
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                                // if status of the tasks in READY
49                                if (task.getStatus() == DCWormsTags.READY) {
50                                        Map<ResourceUnitName, ResourceUnit> choosenResources = chooseResourcesForExecution(resourceManager, task);
51                                        if (choosenResources != null) {
52                                                addToSchedulingPlan(plan, task, choosenResources);
53                                        }
54                                }
55                        }
56
57                        break;
58                }
59                return plan;
60        }
61
62        private Map<ResourceUnitName, ResourceUnit> chooseResourcesForExecution(
63                        ClusterResourceManager resourceManager, TaskInterface<?> task) {
64
65                Map<ResourceUnitName, ResourceUnit> map;
66                List<ComputingNode> nodes = resourceManager.getComputingNodes();
67                for (ComputingNode node : nodes) {
68                        int cpuRequest;
69                        try {
70                                cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue();
71                        } catch (NoSuchFieldException e) {
72                                cpuRequest = 0;
73                        }
74
75                        if (cpuRequest != 0) {
76
77                                /*Properties properties = new Properties();
78                                properties.setProperty("type", StandardResourceType.Core.getName());
79                                properties.setProperty("status", ResourceStatus.FREE.toString());
80                                 */
81                                List<Core> cores = node.getProcessors().get(0).getCores();
82                                if (cores.size() < cpuRequest/* || node.getProcessors().get(0).filterDescendants(properties).size() != cores.size()*/) {
83                                        continue;
84                                }
85
86                                int freeCores = 0;
87                                for(Core core: cores){
88                                        if(core.getStatus() == ResourceStatus.FREE)
89                                                freeCores++;
90                                }
91                               
92                                if(freeCores != cores.size())
93                                        continue;
94                                List<ComputingResource> choosenResources = new ArrayList<ComputingResource>();                         
95                                for (int i = 0; i < cores.size() && cpuRequest > 0; i++) {
96                                        if (cores.get(i).getStatus() == ResourceStatus.FREE) {
97                                                choosenResources.add(cores.get(i));
98                                                cpuRequest--;
99                                        }
100                                }
101                                if (cpuRequest > 0) {
102                                        continue;
103                                }
104                                map = new HashMap<ResourceUnitName, ResourceUnit>();
105                                ProcessingElements pe = new ProcessingElements();
106                                pe.addAll(choosenResources);
107                                map.put(StandardResourceUnitName.PE, pe);
108                                return map;
109
110                        }
111                }
112       
113                return null;
114        }
115
116}
Note: See TracBrowser for help on using the repository browser.