use of org.ow2.proactive.scheduler.common.TaskDescriptor in project scheduling by ow2-proactive.
the class SchedulingServiceTest9 method startTask.
private JobDescriptor startTask(int expectedTasks) throws Exception {
Map<JobId, JobDescriptor> jobsMap;
JobDescriptor jobDesc;
jobsMap = service.lockJobsToSchedule();
assertEquals(1, jobsMap.size());
jobDesc = jobsMap.values().iterator().next();
Assert.assertEquals(expectedTasks, jobDesc.getEligibleTasks().size());
for (TaskDescriptor taskDesc : jobDesc.getEligibleTasks()) {
taskStarted(jobDesc, (EligibleTaskDescriptor) taskDesc);
}
service.unlockJobsToSchedule(jobsMap.values());
return jobDesc;
}
use of org.ow2.proactive.scheduler.common.TaskDescriptor in project scheduling by ow2-proactive.
the class ExtendedSchedulerPolicy method getOrderedTasks.
/*
* Utilize 'startAt' generic info and filter any tasks that should not be scheduled for current
* execution cycle.
*/
@Override
public LinkedList<EligibleTaskDescriptor> getOrderedTasks(List<JobDescriptor> jobDescList) {
Date now = new Date();
LinkedList<EligibleTaskDescriptor> executionCycleTasks = new LinkedList<>();
Collections.sort(jobDescList, FIFO_BY_PRIORITY_COMPARATOR);
for (JobDescriptor jobDesc : jobDescList) {
Collection<TaskDescriptor> tasks = jobDesc.getEligibleTasks();
Collection<EligibleTaskDescriptor> eligibleTasks = (Collection) tasks;
for (EligibleTaskDescriptor candidate : eligibleTasks) {
String startAt = getStartAtValue(jobDesc, candidate);
if (startAt == null) {
executionCycleTasks.add(candidate);
} else {
try {
if (now.after(ISO8601DateUtil.toDate(startAt))) {
executionCycleTasks.add(candidate);
} else {
if (logger.isTraceEnabled()) {
logger.trace(String.format("Task [jobId:\"%s\", taskId:\"%s\"] is scheduled to be executed at %s." + " It will not be scheduled for this execution cycle at %s.", jobDesc.getJobId(), candidate.getTaskId(), startAt, ISO8601DateUtil.parse(now)));
}
}
} catch (IllegalArgumentException e) {
logger.error(String.format("An error occurred while processing 'startAt' generic info.%n" + "Task ([job-id:\"%s\", task-id:\"%s\"]) will be scheduled immediately for execution.", jobDesc.getJobId().toString(), candidate.getTaskId().toString()), e);
executionCycleTasks.add(candidate);
}
}
}
}
return executionCycleTasks;
}
use of org.ow2.proactive.scheduler.common.TaskDescriptor in project scheduling by ow2-proactive.
the class JobDescriptorImpl method doReplicate.
/**
* Complete REPLICATE action on JobDescriptor side
*
* @param initiator Task initiating the REPLICATE action
* @param tree InternalTask tree of replicated tasks
* @param target Target task of the REPLICATE action: first task of the block
* @param oldEnd End task of the replicated block ; original version
* @param newEnd End task of the replicated block ; dup version
*/
public void doReplicate(TaskId initiator, Map<TaskId, InternalTask> tree, InternalTask target, TaskId oldEnd, TaskId newEnd) {
Map<TaskId, EligibleTaskDescriptorImpl> acc = new HashMap<>();
// create new EligibleTasks and accumulate it
for (Entry<TaskId, InternalTask> it : tree.entrySet()) {
TaskId itId = it.getValue().getTaskInfo().getTaskId();
EligibleTaskDescriptorImpl td = new EligibleTaskDescriptorImpl(it.getValue());
acc.put(itId, td);
}
// recreate the dependencies
for (Entry<TaskId, InternalTask> it : tree.entrySet()) {
TaskId itId = it.getValue().getTaskInfo().getTaskId();
EligibleTaskDescriptorImpl down = acc.get(itId);
List<InternalTask> ideps = new ArrayList<>();
int deptype = 0;
if (it.getValue().hasDependences()) {
ideps.addAll(it.getValue().getIDependences());
} else if (it.getValue().getIfBranch() != null) {
deptype = 1;
ideps.add(it.getValue().getIfBranch());
} else if (it.getValue().getJoinedBranches() != null) {
deptype = 2;
ideps.addAll(it.getValue().getJoinedBranches());
}
if (ideps != null && !target.equals(itId)) {
for (InternalTask parent : ideps) {
if (parent == null) {
continue;
}
EligibleTaskDescriptorImpl up = acc.get(parent.getId());
if (up == null) {
continue;
}
switch(deptype) {
case 0:
up.addChild(down);
down.addParent(up);
break;
case 1:
case 2:
branchTasks.put(down.getTaskId(), down);
break;
}
}
}
}
EligibleTaskDescriptorImpl oldTask = (EligibleTaskDescriptorImpl) runningTasks.get(initiator);
EligibleTaskDescriptorImpl newTask = acc.get(target.getId());
if (oldTask == null) {
oldTask = (EligibleTaskDescriptorImpl) eligibleTasks.get(initiator);
}
HashSet<TaskId> excl = new HashSet<>();
EligibleTaskDescriptorImpl endTask = (EligibleTaskDescriptorImpl) findTask(oldTask, oldEnd, excl);
if (endTask == null) {
// findTask cannot walk weak dependencies (IF/ELSE) down, lets walk these branches ourselves
for (TaskDescriptor branch : branchTasks.values()) {
endTask = (EligibleTaskDescriptorImpl) findTask(branch, oldEnd, excl);
if (endTask != null) {
break;
}
}
}
EligibleTaskDescriptorImpl end = acc.get(newEnd);
for (TaskDescriptor t : endTask.getChildren()) {
end.addChild(t);
((EligibleTaskDescriptorImpl) t).addParent(end);
}
newTask.addParent(oldTask);
oldTask.addChild(newTask);
eligibleTasks.put(target.getId(), newTask);
}
use of org.ow2.proactive.scheduler.common.TaskDescriptor in project scheduling by ow2-proactive.
the class JobDescriptorImpl method makeTree.
/**
* Make a dependences tree of the job's tasks according to the dependence list
* stored in taskDescriptor.
* This list represents the ordered TaskDescriptor list of its parent tasks.
*/
private void makeTree(InternalJob job) {
// create task descriptor list
for (InternalTask td : job.getITasks()) {
// if this task is a first task, put it in eligible tasks list
EligibleTaskDescriptor lt = new EligibleTaskDescriptorImpl(td);
if (isEntryPoint(td, job.getITasks())) {
eligibleTasks.put(td.getId(), lt);
}
if (td.getJoinedBranches() != null || td.getIfBranch() != null) {
branchTasks.put(td.getId(), lt);
}
allTasksWithTheirChildren.put(td, lt);
}
// now for each taskDescriptor, set the parents and children list
for (InternalTask td : job.getITasks()) {
if (td.getDependences() != null) {
TaskDescriptor taskDescriptor = allTasksWithTheirChildren.get(td);
for (InternalTask depends : td.getIDependences()) {
((EligibleTaskDescriptorImpl) taskDescriptor).addParent(allTasksWithTheirChildren.get(depends));
}
for (TaskDescriptor lt : taskDescriptor.getParents()) {
((EligibleTaskDescriptorImpl) lt).addChild(taskDescriptor);
hasChildren.add(lt.getTaskId());
}
}
}
}
use of org.ow2.proactive.scheduler.common.TaskDescriptor in project scheduling by ow2-proactive.
the class TestTaskIdGeneration method test.
@Test
public void test() throws Exception {
TaskFlowJob jobDef = new TaskFlowJob();
jobDef.addTask(createDefaultTask("task1"));
jobDef.addTask(createDefaultTask("task2"));
jobDef.addTask(createDefaultTask("task3"));
InternalJob job = InternalJobFactory.createJob(jobDef, getDefaultCredentials());
job.setOwner(DEFAULT_USER_NAME);
dbManager.newJobSubmitted(job);
for (InternalTask task : job.getITasks()) {
Assert.assertSame(task, job.getIHMTasks().get(task.getId()));
}
for (TaskDescriptor task : job.getJobDescriptor().getEligibleTasks()) {
Assert.assertNotNull(job.getIHMTasks().get(task.getTaskId()));
}
checkIds(job);
SchedulerStateRecoverHelper recoverHelper = new SchedulerStateRecoverHelper(dbManager);
RecoveredSchedulerState state = recoverHelper.recover(-1);
Collection<InternalJob> jobs = state.getPendingJobs();
Assert.assertEquals(1, jobs.size());
job = jobs.iterator().next();
checkIds(job);
JobState jobState = state.getSchedulerState().getPendingJobs().iterator().next();
checkIds(jobState);
}
Aggregations