source: DCWoRMS/trunk/src/schedframe/scheduling/policy/AbstractManagementSystem.java @ 481

Revision 481, 6.7 KB checked in by wojtekp, 13 years ago (diff)
  • Property svn:mime-type set to text/plain
RevLine 
[477]1package schedframe.scheduling.policy;
2
3import java.util.HashMap;
4import java.util.Map;
5
6import org.apache.commons.logging.Log;
7import org.apache.commons.logging.LogFactory;
8import org.joda.time.DateTimeUtilsExt;
9
10import schedframe.PluginConfiguration;
11import schedframe.events.scheduling.SchedulingEventType;
12import schedframe.scheduling.Scheduler;
13import schedframe.scheduling.WorkloadUnitHandler;
14import schedframe.scheduling.manager.resources.ManagedResources;
15import schedframe.scheduling.manager.resources.ResourceManager;
16import schedframe.scheduling.manager.resources.ResourceManagerFactory;
[481]17import schedframe.scheduling.manager.tasks.JobRegistry;
[477]18import schedframe.scheduling.manager.tasks.JobRegistryImpl;
19import schedframe.scheduling.plan.AllocationInterface;
20import schedframe.scheduling.plan.SchedulingPlanInterface;
21import schedframe.scheduling.plugin.SchedulingPlugin;
22import schedframe.scheduling.plugin.estimation.ExecutionTimeEstimationPlugin;
23import schedframe.scheduling.plugin.grid.ModuleList;
24import schedframe.scheduling.plugin.local.ResourceAllocationInterface;
25import schedframe.scheduling.queue.TaskQueue;
26import schedframe.scheduling.queue.TaskQueueList;
27import schedframe.scheduling.tasks.Job;
[481]28import schedframe.scheduling.tasks.TaskInterface;
[477]29import schedframe.scheduling.tasks.WorkloadUnit;
[481]30import simulator.DCWormsConstants;
[477]31import eduni.simjava.Sim_event;
32import gridsim.GridSim;
33import gridsim.GridSimTags;
34import gridsim.IO_data;
[481]35import gridsim.gssim.DCWormsTags;
[477]36import gssim.schedframe.scheduling.ExecTask;
37import gssim.schedframe.scheduling.Executable;
38import gssim.schedframe.scheduling.queues.AbstractStatsSupportingQueue;
39
40public abstract class AbstractManagementSystem {
41
42        private Log log = LogFactory.getLog(AbstractManagementSystem.class);
43       
44        protected String name;
45
[481]46        protected TaskQueueList queues;
[477]47        protected ResourceManager resourceManager;
[481]48        protected JobRegistryImpl jobRegistry;
49        protected ModuleList moduleList;
50       
[477]51        protected SchedulingPlugin schedulingPlugin;
52        protected ExecutionTimeEstimationPlugin execTimeEstimationPlugin;
53
[481]54        protected Scheduler scheduler;
[477]55       
56
57        public AbstractManagementSystem(String providerId, String entityName,
58                        ExecutionTimeEstimationPlugin execTimeEstPlugin, TaskQueueList queues) {
59               
60                this.name = entityName + "@" + providerId;
61                this.queues = queues;
62                this.jobRegistry = new JobRegistryImpl(name);
63                this.execTimeEstimationPlugin = execTimeEstPlugin;
64        }
65       
[481]66        public void init(Scheduler sched, ManagedResources managedResources) {
67                scheduler = sched;
68                resourceManager = ResourceManagerFactory.createResourceManager(scheduler, managedResources);
69                scheduler.set_stat(DCWormsConstants.getResourcesStatisticsObject(queues.size()));
70                for(int i = 0; i < queues.size(); i++){
71                        TaskQueue q = queues.get(i);
72                        if(q instanceof AbstractStatsSupportingQueue<?>){
73                                AbstractStatsSupportingQueue<?> queue = (AbstractStatsSupportingQueue<?>) q;
74                                queue.setStats(scheduler.get_stat(), DCWormsConstants.TASKS_QUEUE_LENGTH_MEASURE_NAME + "_" + Integer.toString(i));
75                        }
76                }
77        }
78       
[477]79        public void processEvent(Sim_event ev) {
80                processOtherEvent(ev);
81        }
82
83        protected void processOtherEvent(Sim_event ev) {
84                if (ev == null) {
85                        System.out.println(name + ".processOtherEvent(): " + "Error - an event is null.");
86                        return;
87                }
88
89                log.error(name + ".processOtherEvent(): Unable to "
90                                + "handle request from an event with a tag number " + ev.get_tag());
91        }
92       
[481]93       
[477]94        public String getName() {
95                return name;
96        }
97       
98        public ResourceManager getResourceManager() {
99                if (resourceManager instanceof ResourceManager)
100                        return (ResourceManager) resourceManager;
101                else
102                        return null;
103        }
104
105        public ResourceAllocationInterface getAllocationManager() {
106                if (resourceManager instanceof ResourceAllocationInterface)
107                        return (ResourceAllocationInterface) resourceManager;
108                else
109                        return null;
110        }
111
112        protected JobRegistry getJobRegistry(){
113                return jobRegistry;
114        }
[481]115       
116        public Scheduler getScheduler() {
117                return scheduler;
118        }
119       
120        public PluginConfiguration getSchedulingPluginConfiguration() {
121                return schedulingPlugin.getConfiguration();
122        }
[477]123
124        public boolean pluginSupportsEvent(int eventType){
125                return true;
126        }
127
[481]128        public TaskQueueList getQueues(){
129                return queues;
130        }
131       
132        public Map<String, Integer> getQueuesSize() {
133                Map<String, Integer> queue_size = new HashMap<String, Integer>();
134                for (TaskQueue queue : queues) {
135                        queue_size.put(queue.getName(), queue.size());
136                }
137                return queue_size;
138        }
139       
[477]140        //POPRAWIC  (ale co? bo teraz chyba jest ok)
[481]141        protected void submitTask(TaskInterface<?> task, AllocationInterface<?> allocation) {
[477]142                String providerName = allocation.getProviderName();
143                if (providerName == null) {
144                        return;
145                }
146                //Executable exec = (Executable) wu;
[481]147                removeFromQueue(task);
148                scheduler.send(providerName, GridSimTags.SCHEDULE_NOW, GridSimTags.GRIDLET_SUBMIT, task);       
[477]149        }
150
[478]151        protected boolean sendFinishedWorkloadUnit(WorkloadUnit wu) {
[477]152               
153                Executable exec = (Executable) wu;
154                if(scheduler.getParent() == null)
155                {
[480]156                        Job job = jobRegistry.getJob(exec.getJobId());
[477]157
158                        if(job.isFinished()){
159                                scheduler.send(job.getSenderId(), GridSimTags.SCHEDULE_NOW, GridSimTags.GRIDLET_RETURN, job);
160                                return true;
161                        }
162                        else return true;
163                }
164       
165        IO_data obj = new IO_data(exec, 0, /*task.getGridletOutputSize(),*/ GridSim.getEntityId(scheduler.getParent().get_name()));
166        scheduler.send(scheduler.getOutputPort(), 0.0, GridSimTags.GRIDLET_RETURN, obj);
167                return true;
168        }
169
170        protected void sendExecutableReadyEvent(ExecTask exec) {
171
172                long delay = 0;
173                try {
174                        long expectedStartTime = exec.getExecutionStartTime().getMillis() / 1000;
175                        long currentTime = DateTimeUtilsExt.currentTimeMillis() / 1000;
176                        delay = expectedStartTime - currentTime;
177                        if (delay < 0)
178                                delay = 0;
179                } catch (NoSuchFieldException e) {
180                        delay = 0;
181                }
182
[481]183                scheduler.sendInternal(Long.valueOf(delay).doubleValue(), DCWormsTags.TASK_READY_FOR_EXECUTION,
[477]184                                exec);
185        }
186       
187        protected void sendTimerEvent() {
188                PluginConfiguration pluginConfig = schedulingPlugin.getConfiguration();
189                if (pluginConfig != null) {
190                        Map<SchedulingEventType, Object> events = pluginConfig.getServedEvents();
191                        if (events != null) {
192                                Object obj = events.get(SchedulingEventType.TIMER);
193                                if (obj != null) {
194                                        int delay = (Integer) obj;
[481]195                                        scheduler.sendInternal(delay, DCWormsTags.TIMER, null);
[477]196                                }
197                        }
198                }
199        }
200       
[478]201        protected boolean removeFromQueue(WorkloadUnit wu) {
[477]202                for(TaskQueue queue : queues){
203                        if(queue.contains(wu)){
204                                queue.remove(wu);
205                                return true;
206                        }
207                }
208                return false;
209        }
210       
[481]211        public abstract WorkloadUnitHandler getWorkloadUnitHandler();
212       
213        public abstract void notifySubmittedWorkloadUnit(WorkloadUnit wu, boolean ack);
[477]214
[481]215        public abstract void notifyReturnedWorkloadUnit(WorkloadUnit wu);
[477]216
[481]217        protected abstract void executeSchedulingPlan(SchedulingPlanInterface<?> decision);
[477]218
219}
Note: See TracBrowser for help on using the repository browser.