source: DCWoRMS/trunk/src/example/localplugin/FCFSBF_DFSClusterPlugin.java @ 569

Revision 569, 3.9 KB checked in by wojtekp, 12 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package example.localplugin;
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.ComputingResource;
13import schedframe.resources.computing.Processor;
14import schedframe.resources.units.ProcessingElements;
15import schedframe.resources.units.ResourceUnit;
16import schedframe.resources.units.ResourceUnitName;
17import schedframe.resources.units.StandardResourceUnitName;
18import schedframe.scheduling.manager.resources.ClusterResourceManager;
19import schedframe.scheduling.manager.resources.ResourceManager;
20import schedframe.scheduling.manager.tasks.JobRegistry;
21import schedframe.scheduling.plan.SchedulingPlanInterface;
22import schedframe.scheduling.plan.impl.SchedulingPlan;
23import schedframe.scheduling.plugin.grid.ModuleList;
24import schedframe.scheduling.queue.TaskQueue;
25import schedframe.scheduling.queue.TaskQueueList;
26import schedframe.scheduling.tasks.TaskInterface;
27
28public class FCFSBF_DFSClusterPlugin extends BaseLocalSchedulingPlugin {
29
30        public SchedulingPlanInterface<?> schedule(SchedulingEvent event, TaskQueueList queues, JobRegistry jobRegistry,
31                        ResourceManager resManager, ModuleList modules) {
32
33                ClusterResourceManager resourceManager = (ClusterResourceManager) resManager;
34                SchedulingPlan plan = new SchedulingPlan();
35                // our tasks are placed only in first queue (see
36                // BaseLocalSchedulingPlugin.placeJobsInQueues() method)
37                TaskQueue q = queues.get(0);
38                // chose the events types to serve.
39                // Different actions for different events are possible.
40                switch (event.getType()) {
41               
42                case START_TASK_EXECUTION:
43                case TASK_FINISHED:
44                        // check all tasks in queue
45                        for (int i = 0; i < q.size(); i++) {
46                                TaskInterface<?> task = q.get(i);
47                                // if status of the tasks in READY
48                                if (task.getStatus() == DCWormsTags.READY) {
49
50                                        Map<ResourceUnitName, ResourceUnit> choosenResources = chooseResourcesForExecution(resourceManager, task);
51                                        if (choosenResources  != null) {
52                                                addToSchedulingPlan(plan, task, choosenResources);
53                                        }
54                                }
55                        }
56                        adjustFrequency(resourceManager.getProcessors());
57                }
58                return plan;
59        }
60       
61        private Map<ResourceUnitName, ResourceUnit> chooseResourcesForExecution(
62                        ClusterResourceManager resourceManager, TaskInterface<?> task) {
63
64                Map<ResourceUnitName, ResourceUnit> map = new HashMap<ResourceUnitName, ResourceUnit>();
65
66                int cpuRequest;
67                try {
68                        cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue();
69                } catch (NoSuchFieldException e) {
70                        cpuRequest = 0;
71                }
72
73                if (cpuRequest != 0) {
74                        List<ComputingResource> choosenResources = null;
75                        List<Processor> processors = resourceManager.getProcessors();
76                        if (processors.size() < cpuRequest) {
77                                // log.warn("Task requires more cpus than is availiable in this resource.");
78                                return null;
79                        }
80
81                        choosenResources = new ArrayList<ComputingResource>();
82
83                        for (int i = 0; i < processors.size() && cpuRequest > 0; i++) {
84                                if (processors.get(i).getStatus() == ResourceStatus.FREE) {
85                                        choosenResources.add(processors.get(i));
86                                        cpuRequest--;
87                                }
88                        }
89                        if (cpuRequest > 0) {
90                                // log.info("Task " + task.getJobId() + "_" + task.getId() +
91                                // " requires more cpus than is availiable in this moment.");
92                                return null;
93                        }
94
95                        ProcessingElements pe = new ProcessingElements();
96                        pe.addAll(choosenResources);
97                        map.put(StandardResourceUnitName.PE, pe);
98                }
99                return map;
100        }
101       
102        private void adjustFrequency(List<Processor> processors){
103
104                for(Processor cpu: processors){
105                        if(cpu.getStatus() == ResourceStatus.FREE) {
106                                if(cpu.getPowerInterface().getSupportedPStates().containsKey("P3"))
107                                        cpu.getPowerInterface().setPState("P3");
108                        }
109                        else{
110                                if(cpu.getPowerInterface().getSupportedPStates().containsKey("P0"))
111                                        cpu.getPowerInterface().setPState("P0");
112                        }
113                }
114        }
115
116}
Note: See TracBrowser for help on using the repository browser.