source: DCWoRMS/branches/coolemall/src/test/pausing_resuming/FCFSBF_RandomPluginPausing.java @ 1376

Revision 1376, 5.1 KB checked in by wojtekp, 11 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package test.pausing_resuming;
2
3import dcworms.schedframe.scheduling.ExecTask;
4import dcworms.schedframe.scheduling.Executable;
5import example.localplugin.BaseLocalSchedulingPlugin;
6import gridsim.Gridlet;
7import gridsim.dcworms.DCWormsTags;
8
9import java.util.ArrayList;
10import java.util.HashMap;
11import java.util.List;
12import java.util.Map;
13import java.util.Properties;
14
15import org.joda.time.DateTime;
16
17import schedframe.events.scheduling.SchedulingEvent;
18import schedframe.exceptions.ResourceException;
19import schedframe.resources.ResourceStatus;
20import schedframe.resources.StandardResourceType;
21import schedframe.resources.computing.Node;
22import schedframe.resources.computing.ComputingResource;
23import schedframe.resources.computing.Processor;
24import schedframe.resources.computing.profiles.energy.EnergyEventType;
25import schedframe.resources.units.Memory;
26import schedframe.resources.units.PEUnit;
27import schedframe.resources.units.ProcessingElements;
28import schedframe.resources.units.ResourceUnit;
29import schedframe.resources.units.ResourceUnitName;
30import schedframe.resources.units.StandardResourceUnitName;
31import schedframe.scheduling.manager.resources.ClusterResourceManager;
32import schedframe.scheduling.manager.resources.ResourceManager;
33import schedframe.scheduling.manager.tasks.JobRegistry;
34import schedframe.scheduling.plan.SchedulingPlanInterface;
35import schedframe.scheduling.plan.impl.SchedulingPlan;
36import schedframe.scheduling.plugin.grid.ModuleList;
37import schedframe.scheduling.plugin.local.ResourceAllocation;
38import schedframe.scheduling.queue.TaskQueue;
39import schedframe.scheduling.queue.TaskQueueList;
40import schedframe.scheduling.tasks.TaskInterface;
41import simulator.DataCenterWorkloadSimulator;
42
43public class FCFSBF_RandomPluginPausing extends BaseLocalSchedulingPlugin {
44
45        public SchedulingPlanInterface<?> schedule(SchedulingEvent event, TaskQueueList queues, JobRegistry jobRegistry,
46                        ResourceManager resManager, ModuleList modules) {
47
48                ClusterResourceManager resourceManager = (ClusterResourceManager) resManager;
49                List<Processor> processors = resourceManager.getProcessors();
50                SchedulingPlan plan = new SchedulingPlan();
51                // choose the events types to serve.
52                // Different actions for different events are possible.
53                switch (event.getType()) {
54                case START_TASK_EXECUTION:
55                //case TIMER:
56                        // our tasks are placed only in first queue (see BaseLocalSchedulingPlugin.placeJobsInQueues() method)
57                        TaskQueue q = queues.get(0);
58                        // check all tasks in queue
59
60                        for (int i = 0; i < q.size(); i++) {
61                                TaskInterface<?> task = q.get(i);
62                                // if status of the tasks in READY
63                                if (task.getStatus() == DCWormsTags.READY) {
64
65                                        Map<ResourceUnitName, ResourceUnit> choosenResources = chooseResourcesForExecution(processors, task);
66                                        if (choosenResources != null) {
67                                                addToSchedulingPlan(plan, task, choosenResources);
68                                        } else {
69                                                if(jobRegistry.getRunningTasks().size() > 0) {
70                                                        for(ExecTask exec: jobRegistry.getRunningTasks()){
71                                                                jobRegistry.pauseTask(exec.getJobId(), exec.getId());
72                                                        }
73                                                }
74                                        }
75                                }
76                        }
77
78                        break;
79                case TASK_FINISHED:
80                        for(ExecTask exec: jobRegistry.getTasks(DCWormsTags.PAUSED)){
81                                jobRegistry.resumeTask(exec.getJobId(), exec.getId());
82                        }
83                        q = queues.get(0);
84                        // check all tasks in queue
85
86                        for (int i = 0; i < q.size(); i++) {
87                                TaskInterface<?> task = q.get(i);
88                                // if status of the tasks in READY
89                                if (task.getStatus() == DCWormsTags.READY) {
90                                        Map<ResourceUnitName, ResourceUnit> choosenResources = chooseResourcesForExecution(processors, task);
91                                        if (choosenResources != null) {
92                                                addToSchedulingPlan(plan, task, choosenResources);
93                                        }
94                                }
95                        }
96
97                        break;
98                case TASK_PAUSED:
99                         q = queues.get(0);
100                        // check all tasks in queue
101
102                        for (int i = 0; i < q.size(); i++) {
103                                TaskInterface<?> task = q.get(i);
104                                // if status of the tasks in READY
105                                if (task.getStatus() == DCWormsTags.READY) {
106
107                                        Map<ResourceUnitName, ResourceUnit> choosenResources = chooseResourcesForExecution(processors, task);
108                                        if (choosenResources != null) {
109                                                addToSchedulingPlan(plan, task, choosenResources);
110                                        }
111                                }
112                        }
113
114                }
115               
116                return plan;
117        }
118
119        private Map<ResourceUnitName, ResourceUnit> chooseResourcesForExecution(
120                        List<Processor> processors, TaskInterface<?> task) {
121
122                Map<ResourceUnitName, ResourceUnit> map = new HashMap<ResourceUnitName, ResourceUnit>(1);
123
124                int cpuRequest;
125                try {
126                        cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue();
127                } catch (NoSuchFieldException e) {
128                        cpuRequest = 0;
129                }
130
131                if (cpuRequest != 0) {
132
133                        if (processors.size() < cpuRequest) {
134                                return null;
135                        }
136
137                        List<ComputingResource> choosenResources = new ArrayList<ComputingResource>(cpuRequest);                               
138                        for (int i = 0; i < processors.size() && cpuRequest > 0; i++) {
139                                if (processors.get(i).getStatus() == ResourceStatus.FREE) {
140                                        choosenResources.add(processors.get(i));
141                                        cpuRequest--;
142                                }
143                        }
144                        if (cpuRequest > 0) {
145                                return null;
146                        }
147
148                        ProcessingElements pe = new ProcessingElements();
149                        pe.addAll(choosenResources);
150                        map.put(StandardResourceUnitName.PE, pe);
151                        return map;
152                }
153
154                return null;
155        }
156
157
158
159}
Note: See TracBrowser for help on using the repository browser.