source: DCWoRMS/branches/coolemall/src/example/localplugin/FCFSBF_FanManagementClusterPlugin.java @ 1207

Revision 1207, 4.9 KB checked in by wojtekp, 11 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.List;
7import java.util.Random;
8
9import schedframe.events.scheduling.SchedulingEvent;
10import schedframe.resources.StandardResourceType;
11import schedframe.resources.computing.ComputingNode;
12import schedframe.resources.computing.profiles.energy.airthroughput.StandardAirThroughputStateName;
13import schedframe.resources.computing.profiles.energy.airthroughput.UserAirThroughputStateName;
14import schedframe.resources.devices.Device;
15import schedframe.scheduling.manager.resources.ClusterResourceManager;
16import schedframe.scheduling.manager.resources.ResourceManager;
17import schedframe.scheduling.manager.tasks.JobRegistry;
18import schedframe.scheduling.manager.tasks.JobRegistryImpl;
19import schedframe.scheduling.plan.SchedulingPlanInterface;
20import schedframe.scheduling.plan.impl.SchedulingPlan;
21import schedframe.scheduling.plugin.grid.ModuleList;
22import schedframe.scheduling.queue.TaskQueue;
23import schedframe.scheduling.queue.TaskQueueList;
24import schedframe.scheduling.tasks.TaskInterface;
25
26public class FCFSBF_FanManagementClusterPlugin extends BaseLocalSchedulingPlugin {
27
28        private Random rand;
29       
30        public FCFSBF_FanManagementClusterPlugin () {
31                rand = new Random(5);
32        }
33
34        public SchedulingPlanInterface<?> schedule(SchedulingEvent event, TaskQueueList queues, JobRegistry jobRegistry,
35                         ResourceManager resManager, ModuleList modules) {
36
37                ClusterResourceManager resourceManager = (ClusterResourceManager) resManager;
38                SchedulingPlan plan = new SchedulingPlan();
39                // choose the events types to serve.
40                // Different actions for different events are possible.
41                switch (event.getType()) {
42                case START_TASK_EXECUTION:
43                case TASK_FINISHED:
44                //case TIMER:
45                        // our tasks are placed only in first queue (see
46                        // BaseLocalSchedulingPlugin.placeJobsInQueues() method)
47                        TaskQueue q = queues.get(0);
48                        List<ComputingNode> notSelectedNodes = resourceManager.getComputingNodes();
49                        // check all tasks in queue
50                        for (int i = 0; i < q.size(); i++) {
51                                TaskInterface<?> task = q.get(i);
52                                // if status of the tasks in READY
53                                if (task.getStatus() == DCWormsTags.READY) {
54
55                                        ComputingNode node = chooseRandomProvider(resourceManager, task);
56                                        if (node != null) {
57                                                //if there are two or more tasks ( running on the given node then
58                                                if(new JobRegistryImpl(node.getFullName()).getRunningTasks().size() > 0){
59                                                        List<Device> devices = node.getResourceCharacteristic().getDevices();
60                                                        for(Device dev : devices){
61                                                                if(dev.getType().equals(StandardResourceType.Fan)){
62                                                                        dev.getAirThroughputInterface().setAirThroughputState(new UserAirThroughputStateName("FAN_ON_TURBO"));
63                                                                }
64                                                        }
65                                                }
66                                                else {
67                                                        List<Device> devices = node.getResourceCharacteristic().getDevices();
68                                                        for(Device dev : devices){
69                                                                if(dev.getType().equals(StandardResourceType.Fan)){
70                                                                        dev.getAirThroughputInterface().setAirThroughputState(StandardAirThroughputStateName.ON);       
71                                                                }
72                                                        }
73                                                }
74                                                notSelectedNodes.remove(node);
75                                                addToSchedulingPlan(plan, task, node.getFullName());
76                                        }
77                                }
78                        }
79                        adjustOtherFans(notSelectedNodes);
80                        break;
81                }
82                return plan;
83        }
84
85        private ComputingNode chooseRandomProvider(ClusterResourceManager resourceManager, TaskInterface<?> task) {
86                List<ComputingNode> nodes = filterNodes(resourceManager.getComputingNodes(), task);
87                return randomNode(nodes);
88        }
89       
90        private List<ComputingNode> filterNodes(List<ComputingNode> nodes, TaskInterface<?> task){
91                List<ComputingNode> filteredNodes = new ArrayList<ComputingNode>();
92                for (ComputingNode node : nodes) {
93                        int cpuRequest;
94                        try {
95                                cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue();
96                        } catch (NoSuchFieldException e) {
97                                cpuRequest = 0;
98                        }
99                        if (cpuRequest != 0) {
100                                if(node.getFreeProcessorsNumber() > cpuRequest)
101                                        filteredNodes.add(node);
102                        }
103                }
104               
105                return filteredNodes;
106        }
107       
108        private ComputingNode randomNode(List<ComputingNode> nodes){
109                return nodes.get(rand.nextInt(nodes.size()));
110        }
111       
112        private void adjustOtherFans(List<ComputingNode> nodes){
113                for(ComputingNode node : nodes){
114                        List<Device> devices = node.getResourceCharacteristic().getDevices();
115                        if(node.getFreeProcessorsNumber() == node.getProcessorsNumber()){
116                                for(Device dev : devices){
117                                        if(dev.getType().equals(StandardResourceType.Fan)){
118                                                dev.getAirThroughputInterface().setAirThroughputState(StandardAirThroughputStateName.OFF);
119                                        }
120                                }
121                        } else if(new JobRegistryImpl(node.getFullName()).getRunningTasks().size() > 1){
122                                for(Device dev : devices){
123                                        if(dev.getType().equals(StandardResourceType.Fan)){
124                                                dev.getAirThroughputInterface().setAirThroughputState(new UserAirThroughputStateName("FAN_ON_TURBO"));
125                                        }
126                                }
127                        }
128                        else {
129                                for(Device dev : devices){
130                                        if(dev.getType().equals(StandardResourceType.Fan)){
131                                                dev.getAirThroughputInterface().setAirThroughputState(StandardAirThroughputStateName.ON);
132                                        }
133                                }
134                        }
135                }
136        }
137
138       
139}
Note: See TracBrowser for help on using the repository browser.