source: DCWoRMS/branches/coolemall/src/schedframe/scheduling/policy/local/LocalManagementSystem.java @ 1162

Revision 1162, 21.4 KB checked in by wojtekp, 12 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package schedframe.scheduling.policy.local;
2
3import dcworms.schedframe.scheduling.ExecTask;
4import dcworms.schedframe.scheduling.Executable;
5import eduni.simjava.Sim_event;
6import eduni.simjava.Sim_system;
7import gridsim.Accumulator;
8import gridsim.ResourceCalendar;
9import gridsim.dcworms.DCWormsTags;
10import gridsim.dcworms.filter.ExecTaskFilter;
11
12import java.util.ArrayList;
13import java.util.HashMap;
14import java.util.Iterator;
15import java.util.List;
16import java.util.Map;
17
18import org.apache.commons.lang.ArrayUtils;
19import org.apache.commons.logging.Log;
20import org.apache.commons.logging.LogFactory;
21import org.joda.time.DateTime;
22import org.joda.time.DateTimeUtilsExt;
23import org.qcg.broker.schemas.schedulingplan.types.AllocationStatus;
24
25import qcg.shared.constants.BrokerConstants;
26import schedframe.ResourceController;
27import schedframe.events.scheduling.SchedulingEvent;
28import schedframe.events.scheduling.SchedulingEventType;
29import schedframe.events.scheduling.StartTaskExecutionEvent;
30import schedframe.events.scheduling.TaskFinishedEvent;
31import schedframe.events.scheduling.TaskRequestedTimeExpiredEvent;
32import schedframe.exceptions.ResourceException;
33import schedframe.resources.computing.ComputingResource;
34import schedframe.resources.computing.profiles.energy.EnergyEvent;
35import schedframe.resources.computing.profiles.energy.EnergyEventType;
36import schedframe.resources.units.PEUnit;
37import schedframe.resources.units.ProcessingElements;
38import schedframe.resources.units.ResourceUnit;
39import schedframe.resources.units.ResourceUnitName;
40import schedframe.resources.units.StandardResourceUnitName;
41import schedframe.scheduling.ResourceHistoryItem;
42import schedframe.scheduling.Scheduler;
43import schedframe.scheduling.TaskList;
44import schedframe.scheduling.TaskListImpl;
45import schedframe.scheduling.UsedResourcesList;
46import schedframe.scheduling.WorkloadUnitHandler;
47import schedframe.scheduling.manager.resources.LocalResourceManager;
48import schedframe.scheduling.manager.resources.ManagedResources;
49import schedframe.scheduling.manager.resources.ResourceManager;
50import schedframe.scheduling.plan.AllocationInterface;
51import schedframe.scheduling.plan.ScheduledTaskInterface;
52import schedframe.scheduling.plan.SchedulingPlanInterface;
53import schedframe.scheduling.plugin.SchedulingPlugin;
54import schedframe.scheduling.plugin.estimation.ExecutionTimeEstimationPlugin;
55import schedframe.scheduling.plugin.grid.ModuleListImpl;
56import schedframe.scheduling.plugin.grid.ModuleType;
57import schedframe.scheduling.policy.AbstractManagementSystem;
58import schedframe.scheduling.queue.TaskQueueList;
59import schedframe.scheduling.tasks.AbstractProcesses;
60import schedframe.scheduling.tasks.Job;
61import schedframe.scheduling.tasks.JobInterface;
62import schedframe.scheduling.tasks.Task;
63import schedframe.scheduling.tasks.TaskInterface;
64import schedframe.scheduling.tasks.WorkloadUnit;
65import simulator.DCWormsConstants;
66import simulator.utils.DoubleMath;
67
68public class LocalManagementSystem extends AbstractManagementSystem {
69
70        private Log log = LogFactory.getLog(LocalManagementSystem.class);
71
72        protected double lastUpdateTime;
73
74        protected Accumulator accTotalLoad;
75
76        public LocalManagementSystem(String providerId, String entityName, SchedulingPlugin schedPlugin,
77                        ExecutionTimeEstimationPlugin execTimeEstimationPlugin, TaskQueueList queues)
78                        throws Exception {
79
80                super(providerId, entityName, execTimeEstimationPlugin, queues);
81               
82                if (schedPlugin == null) {
83                        throw new Exception("Can not create local scheduling plugin instance.");
84                }
85                this.schedulingPlugin =  schedPlugin;
86                this.moduleList = new ModuleListImpl(1);
87               
88                this.accTotalLoad = new Accumulator();
89        }
90
91        public void init(Scheduler sched, ManagedResources managedResources) {
92                super.init(sched, managedResources);
93                double load = 0;
94                accTotalLoad.add(load);
95        }
96
97        public void processEvent(Sim_event ev) {
98
99                updateProcessingProgress();
100
101                int tag = ev.get_tag();
102
103                switch (tag) {
104
105                case DCWormsTags.TIMER:
106                        if (pluginSupportsEvent(tag)) {
107                                SchedulingEvent event = new SchedulingEvent(SchedulingEventType.TIMER);
108                                SchedulingPlanInterface<?> decision =  schedulingPlugin.schedule(event,
109                                                queues,  getJobRegistry(), getResourceManager(), moduleList);
110                                executeSchedulingPlan(decision);
111                        }
112                        sendTimerEvent();
113                        break;
114
115                case DCWormsTags.TASK_READY_FOR_EXECUTION:
116                        ExecTask execTask = (ExecTask) ev.get_data();
117                        try {
118                                execTask.setStatus(DCWormsTags.READY);
119                                if (pluginSupportsEvent(tag)) {
120                                        SchedulingEvent event = new StartTaskExecutionEvent(execTask.getJobId(), execTask.getId());
121                                        SchedulingPlanInterface<?> decision =  schedulingPlugin.schedule(event,
122                                                        queues,  getJobRegistry(), getResourceManager(), moduleList);
123                                        executeSchedulingPlan(decision);
124                                }
125                        } catch (Exception e) {
126                                e.printStackTrace();
127                        }
128                        break;
129
130                case DCWormsTags.TASK_EXECUTION_FINISHED:
131                        execTask = (ExecTask) ev.get_data();
132                        if (execTask.getStatus() == DCWormsTags.INEXEC) {
133                               
134                                finalizeExecutable(execTask);
135                                sendFinishedWorkloadUnit(execTask);
136                                log.debug(execTask.getJobId() + "_" + execTask.getId() + " finished execution on " + new DateTime());
137                                log.info(DCWormsConstants.USAGE_MEASURE_NAME + ": " + calculateTotalLoad(jobRegistry.getRunningTasks().size()));
138                                if (pluginSupportsEvent(tag)) {
139                                        SchedulingEvent event = new TaskFinishedEvent(execTask.getJobId(), execTask.getId());
140                                        SchedulingPlanInterface<?> decision = schedulingPlugin.schedule(event,
141                                                        queues, getJobRegistry(), getResourceManager(), moduleList);
142                                        executeSchedulingPlan(decision);
143                                }
144                        }
145
146                        Job job = jobRegistry.getJob(execTask.getJobId());
147                        if(!job.isFinished()){
148                                getWorkloadUnitHandler().handleJob(job);
149                        }
150                        //SUPPORTS PRECEDING CONSTRAINST COMING BOTH FROM SWF FILES
151                        /*else {
152                                try {
153                                        job.setStatus((int)BrokerConstants.JOB_STATUS_FINISHED);
154                                } catch (Exception e) {
155
156                                }
157                                for(JobInterface<?> j: jobRegistry.getJobs((int)BrokerConstants.JOB_STATUS_SUBMITTED)){
158                                        getWorkloadUnitHandler().handleJob(j); 
159                                }
160                        }*/
161                        break;
162                       
163                case DCWormsTags.TASK_REQUESTED_TIME_EXPIRED:
164                        execTask = (Executable) ev.get_data();
165                        if (pluginSupportsEvent(tag)) {
166                                SchedulingEvent event = new TaskRequestedTimeExpiredEvent(execTask.getJobId(), execTask.getId());
167                                SchedulingPlanInterface<?> decision = schedulingPlugin.schedule(event,
168                                                queues, getJobRegistry(), getResourceManager(), moduleList);
169                                executeSchedulingPlan(decision);
170                        }
171                        break;
172                       
173                case DCWormsTags.UPDATE_PROCESSING:
174                        updateProcessingTimes(ev);
175                        break;
176                       
177                case DCWormsTags.TASK_EXECUTION_CHANGED:
178                        execTask = (ExecTask) ev.get_data();
179                        updateTaskExecution(execTask, SchedulingEventType.RESOURCE_STATE_CHANGED);
180                        break;
181                }
182        }
183
184        public void notifyReturnedWorkloadUnit(WorkloadUnit wu) {
185                if (pluginSupportsEvent(DCWormsTags.TASK_EXECUTION_FINISHED)) {
186                        SchedulingEvent event = new SchedulingEvent(SchedulingEventType.TASK_FINISHED);
187                        SchedulingPlanInterface<?> decision =  schedulingPlugin.schedule(event,
188                                        queues, getJobRegistry(), getResourceManager(), moduleList);
189                        executeSchedulingPlan(decision);
190                }
191                //if(scheduler.getParent() != null){
192                        sendFinishedWorkloadUnit(wu);
193                //}
194        }
195       
196        protected void executeSchedulingPlan(SchedulingPlanInterface<?> decision) {
197
198                ArrayList<ScheduledTaskInterface<?>> taskSchedulingDecisions = decision.getTasks();
199                for (int i = 0; i < taskSchedulingDecisions.size(); i++) {
200                        ScheduledTaskInterface<?> taskDecision = taskSchedulingDecisions.get(i);
201
202                        if (taskDecision.getStatus() == AllocationStatus.REJECTED) {
203                                continue;
204                        }
205
206                        ArrayList<AllocationInterface<?>> allocations = taskDecision.getAllocations();
207
208                        TaskInterface<?> task = taskDecision.getTask();
209                        for (int j = 0; j < allocations.size(); j++) {
210
211                                AllocationInterface<?> allocation = allocations.get(j);
212                                if (allocation.getRequestedResources() == null || allocation.getRequestedResources().size() > 0) {
213                                        ExecTask exec = (ExecTask) task;                                       
214                                        executeTask(exec, allocation.getRequestedResources());
215                                } else if(resourceManager.getSchedulerName(allocation.getProviderName()) != null){
216                                        allocation.setProviderName(resourceManager.getSchedulerName(allocation.getProviderName()));
217                                        submitTask(task, allocation);
218                                } else {
219                                        ExecTask exec = (ExecTask) task;
220                                        executeTask(exec, chooseResourcesForExecution(allocation.getProviderName(), exec));
221                                }
222                        }
223                }
224        }
225
226        protected void executeTask(ExecTask task, Map<ResourceUnitName, ResourceUnit> choosenResources) {
227
228                Executable exec = (Executable)task;
229                boolean allocationStatus = getAllocationManager().allocateResources(choosenResources);
230                if(allocationStatus == false){
231                        log.info("Task " + task.getJobId() + "_" + task.getId() + " requires more resources than is available at this moment.");
232                        return;
233                }
234
235                removeFromQueue(task);
236
237                log.debug(task.getJobId() + "_" + task.getId() + " starts executing on " + new DateTime());
238
239                //if (phaseDuration < 0.0)
240                //      return;
241
242                //exec.setEstimatedDuration(exec.getEstimatedDuration() + phaseDuration);
243                DateTime currentTime = new DateTime();
244                ResourceHistoryItem resHistItem = new ResourceHistoryItem(choosenResources, currentTime);
245                exec.addUsedResources(resHistItem);
246               
247                try {
248                        exec.setStatus(DCWormsTags.INEXEC);
249                } catch (Exception e) {
250                        // TODO Auto-generated catch block
251                        e.printStackTrace();
252                }
253               
254                updateTaskExecution(exec, SchedulingEventType.START_TASK_EXECUTION);
255                //scheduler.sendInternal(time, DCWormsTags.TASK_EXECUTION_FINISHED, exec);
256
257                try {
258                        long expectedDuration = exec.getExpectedDuration().getMillis() / 1000;
259                        scheduler.sendInternal(expectedDuration, DCWormsTags.TASK_REQUESTED_TIME_EXPIRED, exec);
260                } catch (NoSuchFieldException e) {
261                        //double t = exec.getEstimatedDuration();
262                        //scheduler.sendInternal(t, DCWormsTags.TASK_REQUESTED_TIME_EXPIRED, exec);
263                }
264
265                log.info(DCWormsConstants.USAGE_MEASURE_NAME + ": " + calculateTotalLoad(jobRegistry.getRunningTasks().size()));
266               
267                PEUnit peUnit = (PEUnit)choosenResources.get(StandardResourceUnitName.PE);
268               
269                notifyComputingResources(peUnit, EnergyEventType.TASK_STARTED, exec);
270               
271        }
272       
273        protected void finalizeExecutable(ExecTask execTask){
274               
275                Executable exec = (Executable)execTask;
276                exec.finalizeExecutable();
277               
278                ExecTaskFilter filter = new ExecTaskFilter(exec.getUniqueId(), DCWormsTags.TASK_REQUESTED_TIME_EXPIRED);
279                scheduler.sim_cancel(filter, null);
280               
281                Task task;
282                Job job = jobRegistry.getJob(exec.getJobId());
283                try {
284                        task = job.getTask(exec.getTaskId());
285                } catch (NoSuchFieldException e) {
286                        return;
287                }
288                if(exec.getProcessesId() == null){
289                        try {
290                                task.setStatus(exec.getStatus());
291                        } catch (Exception e) {
292                                e.printStackTrace();
293                        }
294                } else {
295                        List<AbstractProcesses> processesList = task.getProcesses();
296                        for(int i = 0; i < processesList.size(); i++){
297                                AbstractProcesses processes = processesList.get(i);
298                                if(processes.getId().equals(exec.getProcessesId())){
299                                        processes.setStatus(exec.getStatus());
300                                        break;
301                                }
302                        }
303                }
304               
305                UsedResourcesList lastUsedList = exec.getUsedResources();
306                Map<ResourceUnitName, ResourceUnit> lastUsed = lastUsedList.getLast()
307                                .getResourceUnits();
308                getAllocationManager().freeResources(lastUsed);
309               
310                PEUnit peUnit = (PEUnit)lastUsed.get(StandardResourceUnitName.PE);
311                notifyComputingResources(peUnit, EnergyEventType.TASK_FINISHED, exec);
312        }
313       
314        protected void updateProcessingProgress() {
315                double timeSpan = DoubleMath.subtract(Sim_system.clock(), lastUpdateTime);
316                if (timeSpan <= 0.0) {
317                        // don't update when nothing changed
318                        return;
319                }
320                lastUpdateTime = Sim_system.clock();
321                Iterator<ExecTask> iter = jobRegistry.getRunningTasks().iterator();
322                while (iter.hasNext()) {
323                        ExecTask task = iter.next();
324                        Executable exec = (Executable)task;
325                        //exec.setCompletionPercentage(exec.getCompletionPercentage() + 100 * timeSpan/exec.getEstimatedDuration());
326                        exec.setCompletionPercentage(exec.getCompletionPercentage() + 100 * (timeSpan / exec.getEstimatedDuration()));
327                        UsedResourcesList usedResourcesList = exec.getUsedResources();
328                        PEUnit peUnit = (PEUnit)usedResourcesList.getLast().getResourceUnits()
329                                        .get(StandardResourceUnitName.PE);
330                        double load = getMIShare(timeSpan, peUnit);
331                        addTotalLoad(load);
332                }
333        }
334       
335        private void notifyComputingResources(PEUnit peUnit, EnergyEventType eventType, Object obj){
336                if(peUnit instanceof ProcessingElements){
337                        ProcessingElements pes = (ProcessingElements) peUnit;
338                        for (ComputingResource resource : pes) {
339                                resource.handleEvent(new EnergyEvent(eventType, obj));
340                        }
341                        /*try {
342                                for (ComputingResource resource : resourceManager.getResourcesOfType(pes.get(0).getType())) {
343                                        resource.handleEvent(new EnergyEvent(eventType, obj));
344                                }
345                        } catch (ResourceException e) {
346                                // TODO Auto-generated catch block
347                                e.printStackTrace();
348                        }*/
349                } else {
350                        ComputingResource resource = null;
351                        try {
352                                resource = ResourceController.getComputingResourceByName(peUnit.getResourceId());
353                        } catch (ResourceException e) {
354                                return;
355                        }
356                        resource.handleEvent(new EnergyEvent(eventType, obj));
357                }
358        }
359       
360        private double getMIShare(double timeSpan, PEUnit pes) {
361                double localLoad;
362                ResourceCalendar resCalendar = (ResourceCalendar) moduleList.getModule(ModuleType.RESOURCE_CALENDAR);
363                if (resCalendar == null)
364                        localLoad = 0;
365                else
366                        // 1 - localLoad_ = available MI share percentage
367                        localLoad = resCalendar.getCurrentLoad();
368
369                int speed = pes.getSpeed();
370                int cnt = pes.getAmount();
371
372                double totalMI = speed * cnt * timeSpan * (1 - localLoad);
373                return totalMI;
374        }
375
376        protected void updateProcessingTimes(Sim_event ev) {
377                updateProcessingProgress();
378                for (ExecTask execTask : jobRegistry.getRunningTasks()) {
379                        Executable exec = (Executable)execTask;
380
381                        Map<ResourceUnitName, ResourceUnit> choosenResources = exec.getUsedResources().getLast().getResourceUnits();
382                        double lastTimeStamp = exec.getUsedResources().getLast().getTimeStamp().getMillis()/1000;
383                        int phaseDuration = Double.valueOf(execTimeEstimationPlugin.execTimeEstimation(new SchedulingEvent(SchedulingEventType.RESOURCE_STATE_CHANGED),
384                                        execTask, choosenResources, exec.getCompletionPercentage())).intValue();
385
386                        if(DoubleMath.subtract((lastTimeStamp + exec.getEstimatedDuration()), (new DateTime().getMillis()/1000 + phaseDuration)) == 0.0){
387                                return;
388                        }
389
390                        exec.setEstimatedDuration(phaseDuration);
391                        DateTime currentTime = new DateTime();
392                        ResourceHistoryItem resHistItem = new ResourceHistoryItem(choosenResources, currentTime);
393                        exec.addUsedResources(resHistItem);
394                       
395                        if(exec.getResourceConsumptionProfile().getCurrentResourceConsumption() == exec.getResourceConsumptionProfile().getResourceConsumptionList().getLast()){
396                                ExecTaskFilter filter = new ExecTaskFilter(exec.getUniqueId(), DCWormsTags.TASK_EXECUTION_FINISHED);
397                                scheduler.sim_cancel(filter, null);
398                                scheduler.sendInternal(phaseDuration , DCWormsTags.TASK_EXECUTION_FINISHED, execTask);
399                                PEUnit peUnit = (PEUnit)exec.getUsedResources().getLast().getResourceUnits().get(StandardResourceUnitName.PE);
400                                notifyComputingResources(peUnit, EnergyEventType.RESOURCE_UTILIZATION_CHANGED, exec);
401                        } else{
402                                ExecTaskFilter filter = new ExecTaskFilter(exec.getUniqueId(), DCWormsTags.TASK_EXECUTION_CHANGED);
403                                scheduler.sim_cancel(filter, null);
404                                scheduler.sendInternal(phaseDuration, DCWormsTags.TASK_EXECUTION_CHANGED, execTask);
405                                PEUnit peUnit = (PEUnit)exec.getUsedResources().getLast().getResourceUnits().get(StandardResourceUnitName.PE);
406                                notifyComputingResources(peUnit, EnergyEventType.RESOURCE_UTILIZATION_CHANGED, exec);
407                        }
408                }
409        }       
410
411        protected void updateTaskExecution(ExecTask execTask, SchedulingEventType schedEvType) {
412
413                if (execTask.getStatus() == DCWormsTags.INEXEC) {
414                        Executable exec = (Executable)execTask;
415                       
416                        try {
417                                exec.setStatus(DCWormsTags.NEW_EXEC_PHASE);
418                        } catch (Exception e) {
419                        }
420                       
421                        Map<ResourceUnitName, ResourceUnit> choosenResources = exec.getUsedResources().getLast().getResourceUnits();
422
423                        int phaseDuration = Double.valueOf(execTimeEstimationPlugin.execTimeEstimation(new SchedulingEvent(schedEvType),
424                                        execTask, choosenResources, exec.getCompletionPercentage())).intValue();
425
426                        exec.setEstimatedDuration(phaseDuration);
427                       
428                        if(exec.getResourceConsumptionProfile().getCurrentResourceConsumption() == exec.getResourceConsumptionProfile().getResourceConsumptionList().getLast()){
429                                scheduler.sendInternal(phaseDuration, DCWormsTags.TASK_EXECUTION_FINISHED, execTask);
430                        } else {
431                                scheduler.sendInternal(phaseDuration, DCWormsTags.TASK_EXECUTION_CHANGED, execTask);
432                        }
433                }
434        }       
435
436        public double calculateTotalLoad(int size) {
437                // background load, defined during initialization
438                double load;
439                ResourceCalendar resCalendar = (ResourceCalendar) moduleList.getModule(ModuleType.RESOURCE_CALENDAR);
440                if (resCalendar == null)
441                        load = 0;
442                else
443                        load = resCalendar.getCurrentLoad();
444
445                int numberOfPE = 0;
446                try {
447                        for(ResourceUnit resUnit : getResourceManager().getPE()){
448                                numberOfPE = numberOfPE + resUnit.getAmount();
449                        }
450                } catch (Exception e) {
451                        numberOfPE = 1;
452                }
453                double tasksPerPE = (double) size / numberOfPE;
454                load += Math.min(1.0 - load, tasksPerPE);
455
456                return load;
457        }
458
459        public Accumulator getTotalLoad() {
460                return accTotalLoad;
461        }
462
463        protected void addTotalLoad(double load) {
464                accTotalLoad.add(load);
465        }
466       
467        private Map<ResourceUnitName, ResourceUnit> chooseResourcesForExecution(String resourceName,
468                        ExecTask task) {
469
470                Map<ResourceUnitName, ResourceUnit> map = new HashMap<ResourceUnitName, ResourceUnit>();
471                LocalResourceManager resourceManager = getResourceManager();
472                if(resourceName != null){
473                        ComputingResource resource = null;
474                        try {
475                                resource = resourceManager.getResourceByName(resourceName);
476                        } catch (ResourceException e) {
477                                return null;
478                        }
479                        resourceManager = new LocalResourceManager(resource);
480                }
481
482                int cpuRequest;
483                try {
484                        cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue();
485                } catch (NoSuchFieldException e) {
486                        cpuRequest = 1;
487                }
488
489                if (cpuRequest != 0) {
490                       
491                        List<ResourceUnit> availableUnits = null;
492                        try {
493                                availableUnits = resourceManager.getPE();
494                        } catch (ResourceException e) {
495                                return null;
496                        }
497                       
498                        List<ResourceUnit> choosenPEUnits = new ArrayList<ResourceUnit>();
499                        for (int i = 0; i < availableUnits.size() && cpuRequest > 0; i++) {
500                                PEUnit peUnit = (PEUnit) availableUnits.get(i);
501                                if(peUnit.getFreeAmount() > 0){
502                                        int allocPE = Math.min(peUnit.getFreeAmount(), cpuRequest);
503                                        cpuRequest = cpuRequest - allocPE;
504                                        choosenPEUnits.add(peUnit.replicate(allocPE)); 
505                                }       
506                        }
507                       
508                        if(cpuRequest > 0){
509                                return null;
510                        }
511                        map.put(StandardResourceUnitName.PE, choosenPEUnits.get(0));
512                }
513
514                return  map;
515        }
516       
517        public void notifySubmittedWorkloadUnit(WorkloadUnit wu, boolean ack) {
518                updateProcessingProgress();
519                if (log.isInfoEnabled())
520                        log.info("Received job " + wu.getId() + " at " + new DateTime(DateTimeUtilsExt.currentTimeMillis()));
521                registerWorkloadUnit(wu);
522        }
523
524        private void registerWorkloadUnit(WorkloadUnit wu){
525                if(!wu.isRegistered()){
526                        wu.register(jobRegistry);
527                }
528                wu.accept(getWorkloadUnitHandler());
529        }
530       
531        class LocalWorkloadUnitHandler implements WorkloadUnitHandler{
532               
533                public void handleJob(JobInterface<?> job){
534
535                        if (log.isInfoEnabled())
536                                log.info("Handle " + job.getId() + " at " + new DateTime(DateTimeUtilsExt.currentTimeMillis()));
537                       
538                        try {
539                                if(job.getStatus() == BrokerConstants.JOB_STATUS_UNSUBMITTED)
540                                        job.setStatus((int)BrokerConstants.JOB_STATUS_SUBMITTED);
541                        } catch (Exception e) {
542                                // TODO Auto-generated catch block
543                                e.printStackTrace();
544                        }
545                        List<JobInterface<?>> jobsList = new ArrayList<JobInterface<?>>();
546                        jobsList.add(job);
547                        TaskListImpl availableTasks = new TaskListImpl();
548                        for(Task task: jobRegistry.getAvailableTasks(jobsList)){
549                                task.setStatus((int)BrokerConstants.TASK_STATUS_QUEUED);
550                                availableTasks.add(task);
551                        }
552
553                        for(TaskInterface<?> task: availableTasks){     
554                                registerWorkloadUnit(task);
555                        }
556                }
557               
558                public void handleTask(TaskInterface<?> t){
559                        Task task = (Task)t;
560                        List<AbstractProcesses> processes = task.getProcesses();
561
562                        if(processes == null || processes.size() == 0){
563                                Executable exec = new Executable(task);
564                                registerWorkloadUnit(exec);
565                        } else {
566                                for(int j = 0; j < processes.size(); j++){
567                                        AbstractProcesses procesesSet = processes.get(j);
568                                        Executable exec = new Executable(task, procesesSet);
569                                        registerWorkloadUnit(exec);
570                                }
571                        }
572                }
573               
574                public void handleExecutable(ExecTask task){
575                       
576                        Executable exec = (Executable) task;
577                        jobRegistry.addExecTask(exec);
578                       
579                        exec.trackResource(scheduler.get_name());
580                        Scheduler parentScheduler = scheduler.getParent();
581                        List<String> visitedResource = exec.getVisitedResources();
582                        String [] visitedResourcesArray = visitedResource.toArray(new String[visitedResource.size()]);
583                        while (parentScheduler != null && !ArrayUtils.contains(visitedResourcesArray, parentScheduler.get_name())) {
584                                exec.trackResource(parentScheduler.get_name());
585                                parentScheduler = parentScheduler.getParent();
586                        }
587                        exec.setSchedulerName(scheduler.get_id());
588                       
589                        TaskList newTasks = new TaskListImpl();
590                        newTasks.add(exec);
591               
592                        schedulingPlugin.placeTasksInQueues(newTasks, queues, getResourceManager(), moduleList);
593
594                        if (exec.getStatus() == DCWormsTags.QUEUED) {
595                                sendExecutableReadyEvent(exec);
596                        }
597                }
598        }
599
600        public WorkloadUnitHandler getWorkloadUnitHandler() {
601                return new LocalWorkloadUnitHandler();
602        }
603       
604       
605        public LocalResourceManager getResourceManager() {
606                if (resourceManager instanceof ResourceManager)
607                        return (LocalResourceManager) resourceManager;
608                else
609                        return null;
610        }
611       
612}
Note: See TracBrowser for help on using the repository browser.