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

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