package schedframe.scheduling.policy.local; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.joda.time.DateTime; import org.joda.time.DateTimeUtilsExt; import org.qcg.broker.schemas.schedulingplan.types.AllocationStatus; import qcg.shared.constants.BrokerConstants; import schedframe.SimulatedEnvironment; import schedframe.events.scheduling.SchedulingEvent; import schedframe.events.scheduling.SchedulingEventType; import schedframe.events.scheduling.StartTaskExecutionEvent; import schedframe.events.scheduling.TaskFinishedEvent; import schedframe.events.scheduling.TaskPausedEvent; import schedframe.events.scheduling.TaskRequestedTimeExpiredEvent; import schedframe.events.scheduling.TaskResumedEvent; import schedframe.exceptions.ResourceException; import schedframe.resources.StandardResourceType; import schedframe.resources.computing.ComputingResource; import schedframe.resources.computing.profiles.energy.ResourceEvent; import schedframe.resources.computing.profiles.energy.ResourceEventType; import schedframe.resources.units.PEUnit; import schedframe.resources.units.ProcessingElements; import schedframe.resources.units.ResourceUnit; import schedframe.resources.units.ResourceUnitName; import schedframe.resources.units.StandardResourceUnitName; import schedframe.scheduling.ExecutionHistoryItem; import schedframe.scheduling.ResourceItem; import schedframe.scheduling.Scheduler; import schedframe.scheduling.TaskList; import schedframe.scheduling.TaskListImpl; import schedframe.scheduling.WorkloadUnitHandler; import schedframe.scheduling.manager.resources.LocalResourceManager; import schedframe.scheduling.manager.resources.ManagedResources; import schedframe.scheduling.manager.resources.ResourceManager; import schedframe.scheduling.plan.AllocationInterface; import schedframe.scheduling.plan.ScheduledTaskInterface; import schedframe.scheduling.plan.SchedulingPlanInterface; import schedframe.scheduling.plugin.ModuleListImpl; import schedframe.scheduling.plugin.SchedulingPlugin; import schedframe.scheduling.plugin.estimation.ExecutionTimeEstimationPlugin; import schedframe.scheduling.policy.AbstractManagementSystem; import schedframe.scheduling.queue.TaskQueueList; import schedframe.scheduling.tasks.AbstractProcesses; import schedframe.scheduling.tasks.Job; import schedframe.scheduling.tasks.JobInterface; import schedframe.scheduling.tasks.Task; import schedframe.scheduling.tasks.TaskInterface; import schedframe.scheduling.tasks.WorkloadUnit; import simulator.DCWormsConstants; import simulator.stats.DCwormsAccumulator; import simulator.utils.DoubleMath; import dcworms.schedframe.scheduling.ExecTask; import dcworms.schedframe.scheduling.Executable; import eduni.simjava.Sim_event; import eduni.simjava.Sim_system; import gridsim.dcworms.DCWormsTags; import gridsim.dcworms.filter.ExecTaskFilter; public class LocalManagementSystem extends AbstractManagementSystem { private Log log = LogFactory.getLog(LocalManagementSystem.class); protected double lastUpdateTime; public LocalManagementSystem(String providerId, String entityName, SchedulingPlugin schedPlugin, ExecutionTimeEstimationPlugin execTimeEstimationPlugin, TaskQueueList queues) throws Exception { super(providerId, entityName, execTimeEstimationPlugin, queues); if (schedPlugin == null) { throw new Exception("Can not create local scheduling plugin instance."); } this.schedulingPlugin = schedPlugin; this.moduleList = new ModuleListImpl(1); } public void init(Scheduler sched, ManagedResources managedResources) { super.init(sched, managedResources); } public void processEvent(Sim_event ev) { updateProcessingProgress(); int tag = ev.get_tag(); SchedulingEvent event; SchedulingPlanInterface decision; switch (tag) { case DCWormsTags.TIMER: event = new SchedulingEvent(SchedulingEventType.TIMER); decision = schedulingPlugin.schedule(event, queues, jobRegistry, getResourceManager(), moduleList); executeSchedulingPlan(decision); sendTimerEvent(); break; case DCWormsTags.TASK_READY_FOR_EXECUTION: ExecTask execTask = (ExecTask) ev.get_data(); try { execTask.setStatus(DCWormsTags.READY); event = new StartTaskExecutionEvent(execTask.getJobId(), execTask.getId()); decision = schedulingPlugin.schedule(event, queues, jobRegistry, getResourceManager(), moduleList); executeSchedulingPlan(decision); } catch (Exception e) { e.printStackTrace(); } break; case DCWormsTags.TASK_EXECUTION_FINISHED: execTask = (ExecTask) ev.get_data(); if (execTask.getStatus() == DCWormsTags.INEXEC) { finalizeExecutable(execTask); sendFinishedWorkloadUnit(execTask); event = new TaskFinishedEvent(execTask.getJobId(), execTask.getId()); decision = schedulingPlugin.schedule(event, queues, jobRegistry, getResourceManager(), moduleList); executeSchedulingPlan(decision); } Job job = jobRegistry.getJob(execTask.getJobId()); if(!job.isFinished()){ getWorkloadUnitHandler().handleJob(job); } //SUPPORTS PRECEDING CONSTRAINST COMING ALSO FROM SWF FILES /*else { try { job.setStatus((int)BrokerConstants.JOB_STATUS_FINISHED); } catch (Exception e) { } for(JobInterface j: jobRegistry.getJobs((int)BrokerConstants.JOB_STATUS_SUBMITTED)){ getWorkloadUnitHandler().handleJob(j); } }*/ break; case DCWormsTags.TASK_REQUESTED_TIME_EXPIRED: execTask = (Executable) ev.get_data(); event = new TaskRequestedTimeExpiredEvent(execTask.getJobId(), execTask.getId()); decision = schedulingPlugin.schedule(event, queues, jobRegistry, getResourceManager(), moduleList); executeSchedulingPlan(decision); break; case DCWormsTags.TASK_PAUSE:{ String[] ids = (String[]) ev.get_data(); execTask = jobRegistry.getTask(ids[0], ids[1]); pauseTask(execTask); event = new TaskPausedEvent(ids[0], ids[1]); decision = schedulingPlugin.schedule(event, queues, jobRegistry, getResourceManager(), moduleList); executeSchedulingPlan(decision); } break; case DCWormsTags.TASK_RESUME:{ String[] ids = (String[]) ev.get_data(); execTask = jobRegistry.getTask(ids[0], ids[1]); resumeTask(execTask, execTask.getAllocatedResources().getLast().getResourceUnits(), true); event = new TaskResumedEvent(ids[0], ids[1]); decision = schedulingPlugin.schedule(event, queues, jobRegistry, getResourceManager(), moduleList); executeSchedulingPlan(decision); } break; case DCWormsTags.TASK_MIGRATE:{ Object[] data = (Object[]) ev.get_data(); execTask = jobRegistry.getTask((String)data[0], (String)data[1]); double migrationTime = execTimeEstimationPlugin.estimateMigrationTime(new StartTaskExecutionEvent((String)data[0], (String)data[1]), execTask, execTask.getAllocatedResources().getLast().getResourceUnits(), (Map)data[2]); scheduler.sendInternal(migrationTime, DCWormsTags.TASK_MOVE, data); } break; case DCWormsTags.TASK_MOVE:{ Object[] data = (Object[]) ev.get_data(); execTask = jobRegistry.getTask((String)data[0], (String)data[1]); moveTask(execTask, (Map)data[2]); event = new StartTaskExecutionEvent((String)data[0], (String)data[1]); decision = schedulingPlugin.schedule(event, queues, jobRegistry, getResourceManager(), moduleList); executeSchedulingPlan(decision); } break; case DCWormsTags.RESOURCE_POWER_STATE_CHANGED: event = new SchedulingEvent(SchedulingEventType.RESOURCE_POWER_STATE_CHANGED); String source; try{ source = ev.get_data().toString(); } catch(Exception e){ source = null; } event.setSource(source); decision = schedulingPlugin.schedule(event, queues, jobRegistry, getResourceManager(), moduleList); executeSchedulingPlan(decision); break; case DCWormsTags.RESOURCE_POWER_LIMIT_EXCEEDED: event = new SchedulingEvent(SchedulingEventType.RESOURCE_POWER_LIMIT_EXCEEDED); try{ source = ev.get_data().toString(); } catch(Exception e){ source = null; } event.setSource(source); decision = schedulingPlugin.schedule(event, queues, jobRegistry, getResourceManager(), moduleList); executeSchedulingPlan(decision); break; case DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED: event = new SchedulingEvent(SchedulingEventType.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED); try{ source = ev.get_data().toString(); } catch(Exception e){ source = null; } event.setSource(source); decision = schedulingPlugin.schedule(event, queues, jobRegistry, getResourceManager(), moduleList); executeSchedulingPlan(decision); break; case DCWormsTags.TASK_EXECUTION_CHANGED: execTask = (ExecTask) ev.get_data(); updateTaskExecutionPhase(execTask); break; case DCWormsTags.UPDATE_PROCESSING: updateProcessingTimes(); break; default: break; } } protected void pauseTask(ExecTask execTask) { if (execTask == null) { return; } else { try { execTask.setStatus(DCWormsTags.PAUSED); Executable exec = (Executable) execTask; Map lastUsed = exec.getAllocatedResources().getLast().getResourceUnits(); getAllocationManager().freeResources(lastUsed, true); saveExecutionHistory(exec, exec.getExecutionProfile().getCompletionPercentage(), exec.getEstimatedDuration()); ExecTaskFilter filter = new ExecTaskFilter(exec.getUniqueId(), -1); scheduler.sim_cancel(filter, null); PEUnit peUnit = (PEUnit)lastUsed.get(StandardResourceUnitName.PE); updateComputingResources(peUnit, ResourceEventType.TASK_FINISHED, exec); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } protected void resumeTask(ExecTask execTask, Map resources, boolean exclusive) { if (execTask == null) { return; } else if (execTask.getStatus() == DCWormsTags.PAUSED) { try { execTask.setStatus(DCWormsTags.RESUMED); Executable exec = (Executable) execTask; boolean status = allocateResources(exec, resources, exclusive); if(status == false){ TaskList newTasks = new TaskListImpl(); newTasks.add(exec); schedulingPlugin.placeTasksInQueues(newTasks, queues, getResourceManager(), moduleList); exec.setStatus(DCWormsTags.READY); } else { runTask(execTask); PEUnit peUnit = (PEUnit)resources.get(StandardResourceUnitName.PE); updateComputingResources(peUnit, ResourceEventType.TASK_STARTED, exec); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } protected void moveTask(ExecTask execTask, Map map) { pauseTask(execTask); resumeTask(execTask, map, false); } public void notifyReturnedWorkloadUnit(WorkloadUnit wu) { SchedulingEvent event = new SchedulingEvent(SchedulingEventType.TASK_FINISHED); SchedulingPlanInterface decision = schedulingPlugin.schedule(event, queues, jobRegistry, getResourceManager(), moduleList); executeSchedulingPlan(decision); //if(scheduler.getParent() != null){ sendFinishedWorkloadUnit(wu); //} } protected void executeSchedulingPlan(SchedulingPlanInterface decision) { ArrayList> taskSchedulingDecisions = decision.getTasks(); for (int i = 0; i < taskSchedulingDecisions.size(); i++) { ScheduledTaskInterface taskDecision = taskSchedulingDecisions.get(i); if (taskDecision.getStatus() == AllocationStatus.REJECTED) { continue; } ArrayList> allocations = taskDecision.getAllocations(); TaskInterface task = taskDecision.getTask(); for (int j = 0; j < allocations.size(); j++) { AllocationInterface allocation = allocations.get(j); if (allocation.getRequestedResources() == null || allocation.getRequestedResources().size() > 0) { ExecTask exec = (ExecTask) task; executeTask(exec, allocation.getRequestedResources()); } else if(resourceManager.getSchedulerName(allocation.getProviderName()) != null){ allocation.setProviderName(resourceManager.getSchedulerName(allocation.getProviderName())); submitTask(task, allocation); } else { ExecTask exec = (ExecTask) task; executeTask(exec, chooseResourcesForExecution(allocation.getProviderName(), exec)); } } } } protected void executeTask(ExecTask task, Map choosenResources) { Executable exec = (Executable)task; boolean allocationStatus = allocateResources(exec, choosenResources, false); if(allocationStatus == false){ log.info("Task " + task.getJobId() + "_" + task.getId() + " requires more resources than is available at this moment."); return; } removeFromQueue(task); log.debug(task.getJobId() + "_" + task.getId() + " starts executing on " + new DateTime()); runTask(exec); PEUnit peUnit = (PEUnit)choosenResources.get(StandardResourceUnitName.PE); updateComputingResources(peUnit, ResourceEventType.UTILIZATION_CHANGED, exec); try { long expectedDuration = exec.getExpectedDuration().getMillis() / 1000; scheduler.sendInternal(expectedDuration, DCWormsTags.TASK_REQUESTED_TIME_EXPIRED, exec); } catch (NoSuchFieldException e) { //double t = exec.getEstimatedDuration(); //scheduler.sendInternal(t, DCWormsTags.TASK_REQUESTED_TIME_EXPIRED, exec); } log.info(DCWormsConstants.USAGE_MEASURE_NAME + ": " + calculateTotalLoad()); } private void runTask(ExecTask execTask){ Executable exec = (Executable) execTask; Map resources = exec.getAllocatedResources().getLast().getResourceUnits(); try { exec.setStatus(DCWormsTags.INEXEC); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } int phaseDuration = Double.valueOf(execTimeEstimationPlugin.execTimeEstimation(new SchedulingEvent(SchedulingEventType.START_TASK_EXECUTION), execTask, resources, exec.getExecutionProfile().getCompletionPercentage())).intValue(); saveExecutionHistory(exec, exec.getExecutionProfile().getCompletionPercentage(), phaseDuration); if(exec.getExecutionProfile().isLast()){ scheduler.sendInternal(phaseDuration, DCWormsTags.TASK_EXECUTION_FINISHED, execTask); } else { scheduler.sendInternal(phaseDuration, DCWormsTags.TASK_EXECUTION_CHANGED, execTask); } PEUnit peUnit = (PEUnit)resources.get(StandardResourceUnitName.PE); updateComputingResources(peUnit, ResourceEventType.TASK_STARTED, exec); } protected void finalizeExecutable(ExecTask execTask){ Executable exec = (Executable)execTask; exec.finalizeExecutable(); ExecTaskFilter filter = new ExecTaskFilter(exec.getUniqueId(), DCWormsTags.TASK_REQUESTED_TIME_EXPIRED); scheduler.sim_cancel(filter, null); Task task; Job job = jobRegistry.getJob(exec.getJobId()); try { task = job.getTask(exec.getTaskId()); } catch (NoSuchFieldException e) { return; } if(exec.getProcessesId() == null){ try { task.setStatus(exec.getStatus()); } catch (Exception e) { e.printStackTrace(); } } else { List processesList = task.getProcesses(); for(int i = 0; i < processesList.size(); i++){ AbstractProcesses processes = processesList.get(i); if(processes.getId().equals(exec.getProcessesId())){ processes.setStatus(exec.getStatus()); break; } } } Map lastUsed = exec.getAllocatedResources().getLast().getResourceUnits(); getAllocationManager().freeResources(lastUsed, true); //TODO calculate the value of completion saveExecutionHistory(exec, 100,0); PEUnit peUnit = (PEUnit)lastUsed.get(StandardResourceUnitName.PE); updateComputingResources(peUnit, ResourceEventType.TASK_FINISHED, exec); log.debug(execTask.getJobId() + "_" + execTask.getId() + " finished execution on " + new DateTime()); log.info(DCWormsConstants.USAGE_MEASURE_NAME + ": " + calculateTotalLoad()); updateComputingResources(peUnit, ResourceEventType.UTILIZATION_CHANGED, exec); } protected void updateProcessingProgress() { double timeSpan = DoubleMath.subtract(Sim_system.clock(), lastUpdateTime); if (timeSpan <= 0.0) { // don't update when nothing changed return; } lastUpdateTime = Sim_system.clock(); Iterator iter = jobRegistry.getRunningTasks().iterator(); while (iter.hasNext()) { ExecTask task = iter.next(); Executable exec = (Executable)task; ExecutionHistoryItem execHistItem = exec.getExecutionHistory().getLast(); //System.out.println("--- upadteProgressX: " + Sim_system.sim_clock() ); //System.out.println("taskId: " + exec.getId() + "; completion percentage: " + exec.getCompletionPercentage() + "; timespan: " + timeSpan + "; estimatedDuration: " + execHistItem.getCompletionPercentage()); exec.getExecutionProfile().setCompletionPercentage(exec.getExecutionProfile().getCompletionPercentage() + 100 * (timeSpan / (execHistItem.getEstimatedDuration()) * (1.0 - execHistItem.getCompletionPercentage()/100.0))); exec.setTotalCompletionPercentage(exec.getTotalCompletionPercentage() + 100 * (timeSpan / execHistItem.getEstimatedDuration()) * exec.getExecutionProfile().getCurrentExecutionPhase().getLenght() / exec.getExecutionProfile().getLength()); //System.out.println("newProgress: " + exec.getCompletionPercentage() ); } } private void updateComputingResources(PEUnit peUnit, ResourceEventType eventType, Object obj){ if(peUnit instanceof ProcessingElements){ /*ProcessingElements pes = (ProcessingElements) peUnit; for (ComputingResource resource : pes) { resource.handleEvent(new ResourceEvent(eventType, obj, scheduler.getFullName())); //DataCenterWorkloadSimulator.getEventManager().sendToResources(resource.getType(), 0, new EnergyEvent(eventType, obj)); }*/ /*try { for (ComputingResource resource : resourceManager.getResourcesOfType(pes.get(0).getType())) { resource.handleEvent(new EnergyEvent(eventType, obj)); } } catch (ResourceException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ ProcessingElements pes = (ProcessingElements) peUnit; ResourceEvent resEvent = new ResourceEvent(eventType, obj, scheduler.getFullName()); try{ Set resourcesToUpdate = new LinkedHashSet(); for (ComputingResource compResource : pes) { resourcesToUpdate.add(compResource); } while(resourcesToUpdate.size() > 0){ Set newSet = new LinkedHashSet(); for(ComputingResource compResource: resourcesToUpdate){ compResource.updateState(resEvent); if(compResource.getParent() != null){ newSet.add(compResource.getParent()); } } resourcesToUpdate = new LinkedHashSet(newSet); } }catch(Exception e){ } } else { ComputingResource resource = null; try { resource = SimulatedEnvironment.getComputingResourceByName(peUnit.getResourceId()); } catch (ResourceException e) { return; } resource.handleEvent(new ResourceEvent(eventType, obj, scheduler.getFullName())); } } protected void updateProcessingTimes() { for (ExecTask execTask: jobRegistry.getRunningTasks()) { Executable exec = (Executable)execTask; Map choosenResources = exec.getAllocatedResources().getLast().getResourceUnits(); int phaseDuration = Double.valueOf(execTimeEstimationPlugin.execTimeEstimation(new SchedulingEvent(SchedulingEventType.RESOURCE_STATE_CHANGED), execTask, choosenResources, exec.getExecutionProfile().getCompletionPercentage())).intValue(); ExecutionHistoryItem execHistItem = exec.getExecutionHistory().getLast(); double lastTimeStamp = execHistItem.getTimeStamp() / 1000; if(DoubleMath.subtract((lastTimeStamp + execHistItem.getEstimatedDuration()), (new DateTime().getMillis() / 1000 + phaseDuration)) == 0.0){ continue; } //System.out.println("=== upadteTIme: " + Sim_system.sim_clock() ); //System.out.println("execId: " + exec.getId() + "; estimatedDuration " + execHistItem.getEstimatedDuration()); //System.out.println("execId: " + exec.getId() + "; difference " + DoubleMath.subtract((lastTimeStamp + execHistItem.getEstimatedDuration()), (new DateTime().getMillis()/1000 + phaseDuration))); //System.out.println("completionPercantage: " + exec.getCompletionPercentage() + "; basic duration: " +exec.getResourceConsumptionProfile().getCurrentResourceConsumption().getDuration() + "; phaseDuration: " + phaseDuration); saveExecutionHistory(exec, exec.getExecutionProfile().getCompletionPercentage(), phaseDuration); if(exec.getExecutionProfile().isLast()){ ExecTaskFilter filter = new ExecTaskFilter(exec.getUniqueId(), DCWormsTags.TASK_EXECUTION_FINISHED); scheduler.sim_cancel(filter, null); scheduler.sendInternal(phaseDuration , DCWormsTags.TASK_EXECUTION_FINISHED, execTask); //PEUnit peUnit = (PEUnit)exec.getUsedResources().getLast().getResourceUnits().get(StandardResourceUnitName.PE); //notifyComputingResources(peUnit, EnergyEventType.RESOURCE_UTILIZATION_CHANGED, exec); } else{ ExecTaskFilter filter = new ExecTaskFilter(exec.getUniqueId(), DCWormsTags.TASK_EXECUTION_CHANGED); scheduler.sim_cancel(filter, null); scheduler.sendInternal(phaseDuration, DCWormsTags.TASK_EXECUTION_CHANGED, execTask); //PEUnit peUnit = (PEUnit)exec.getUsedResources().getLast().getResourceUnits().get(StandardResourceUnitName.PE); //notifyComputingResources(peUnit, EnergyEventType.RESOURCE_UTILIZATION_CHANGED, exec); } } } protected void updateTaskExecutionPhase(ExecTask execTask) { if (execTask.getStatus() == DCWormsTags.INEXEC) { Executable exec = (Executable)execTask; try { exec.setStatus(DCWormsTags.NEW_EXEC_PHASE); } catch (Exception e) { } Map choosenResources = exec.getAllocatedResources().getLast().getResourceUnits(); int phaseDuration = Double.valueOf(execTimeEstimationPlugin.execTimeEstimation(new SchedulingEvent(SchedulingEventType.TASK_EXECUTION_CHANGED), execTask, choosenResources, exec.getExecutionProfile().getCompletionPercentage())).intValue(); saveExecutionHistory(exec, exec.getExecutionProfile().getCompletionPercentage(), phaseDuration); if(exec.getExecutionProfile().isLast()){ scheduler.sendInternal(phaseDuration, DCWormsTags.TASK_EXECUTION_FINISHED, execTask); } else { scheduler.sendInternal(phaseDuration, DCWormsTags.TASK_EXECUTION_CHANGED, execTask); } PEUnit peUnit = (PEUnit)exec.getAllocatedResources().getLast().getResourceUnits().get(StandardResourceUnitName.PE); updateComputingResources(peUnit, ResourceEventType.UTILIZATION_CHANGED, exec); } } protected double calculateTotalLoad() { DCwormsAccumulator loadAcc = new DCwormsAccumulator(); for(ComputingResource compRes: getResourceManager().getResourcesOfType(StandardResourceType.Node)){ loadAcc.add(compRes.getLoadInterface().getRecentUtilization().getValue()); } return loadAcc.getMean(); } private Map chooseResourcesForExecution(String resourceName, ExecTask task) { Map map = new HashMap(); LocalResourceManager resourceManager = getResourceManager(); if(resourceName != null){ ComputingResource resource = resourceManager.getResourceByName(resourceName); if(resource == null){ return null; } resourceManager = new LocalResourceManager(resource); } int cpuRequest; try { cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue(); } catch (NoSuchFieldException e) { cpuRequest = 1; } if (cpuRequest != 0) { List availableUnits = null; try { availableUnits = resourceManager.getPE(); } catch (ResourceException e) { return null; } List choosenPEUnits = new ArrayList(); for (int i = 0; i < availableUnits.size() && cpuRequest > 0; i++) { PEUnit peUnit = (PEUnit) availableUnits.get(i); if(peUnit.getFreeAmount() > 0){ int allocPE = Math.min(peUnit.getFreeAmount(), cpuRequest); cpuRequest = cpuRequest - allocPE; choosenPEUnits.add(peUnit.replicate(allocPE)); } } if(cpuRequest > 0){ return null; } map.put(StandardResourceUnitName.PE, choosenPEUnits.get(0)); } return map; } public void notifySubmittedWorkloadUnit(WorkloadUnit wu) { //250314 //updateProcessingProgress(); if (log.isInfoEnabled()) log.info("Received job " + wu.getId() + " at " + new DateTime(DateTimeUtilsExt.currentTimeMillis())); registerWorkloadUnit(wu); } private void registerWorkloadUnit(WorkloadUnit wu){ if(!wu.isRegistered()){ wu.register(jobRegistry); } wu.accept(getWorkloadUnitHandler()); } class LocalWorkloadUnitHandler implements WorkloadUnitHandler{ public void handleJob(JobInterface job){ if (log.isInfoEnabled()) log.info("Handle " + job.getId() + " at " + new DateTime(DateTimeUtilsExt.currentTimeMillis())); try { if(job.getStatus() == BrokerConstants.JOB_STATUS_UNSUBMITTED) job.setStatus((int)BrokerConstants.JOB_STATUS_SUBMITTED); } catch (Exception e) { e.printStackTrace(); } List> jobsList = new ArrayList>(); jobsList.add(job); TaskListImpl availableTasks = new TaskListImpl(); for(Task task: jobRegistry.getAvailableTasks(jobsList)){ task.setStatus((int)BrokerConstants.TASK_STATUS_QUEUED); availableTasks.add(task); } for(TaskInterface task: availableTasks){ registerWorkloadUnit(task); } } public void handleTask(TaskInterface t){ Task task = (Task)t; List processes = task.getProcesses(); if(processes == null || processes.size() == 0){ Executable exec = new Executable(task); registerWorkloadUnit(exec); } else { for(int j = 0; j < processes.size(); j++){ AbstractProcesses procesesSet = processes.get(j); Executable exec = new Executable(task, procesesSet); registerWorkloadUnit(exec); } } } public void handleExecutable(ExecTask task){ Executable exec = (Executable) task; jobRegistry.addExecTask(exec); exec.setSchedulerName(scheduler.getFullName()); TaskList newTasks = new TaskListImpl(); newTasks.add(exec); schedulingPlugin.placeTasksInQueues(newTasks, queues, getResourceManager(), moduleList); if (exec.getStatus() == DCWormsTags.QUEUED) { sendExecutableReadyEvent(exec); } } } public WorkloadUnitHandler getWorkloadUnitHandler() { return new LocalWorkloadUnitHandler(); } public LocalResourceManager getResourceManager() { if (resourceManager instanceof ResourceManager) return (LocalResourceManager) resourceManager; else return null; } private void saveExecutionHistory(Executable exec, double completionPercentage, double estimatedDuration){ ExecutionHistoryItem execHistoryItem = new ExecutionHistoryItem(new DateTime().getMillis()); execHistoryItem.setCompletionPercentage(completionPercentage); execHistoryItem.setEstimatedDuration(estimatedDuration); execHistoryItem.setResIndex(exec.getAllocatedResources().size() - 1); execHistoryItem.setStatus(exec.getStatus()); exec.addExecHistory(execHistoryItem); } public boolean allocateResources(Executable exec, Map choosenResources, boolean exclusive){ boolean allocationStatus = getAllocationManager().allocateResources(choosenResources, exclusive); if(allocationStatus){ ResourceItem resourceHistoryItem = new ResourceItem(choosenResources); exec.addAllocatedResources(resourceHistoryItem); return true; } return false; } }