use of org.ow2.proactive.scheduler.common.task.TaskId in project scheduling by ow2-proactive.
the class InternalJob method displayAllTasks.
private String displayAllTasks() {
String nl = System.lineSeparator();
String answer = "{" + nl;
for (TaskId tid : tasks.keySet()) {
answer += tasks.get(tid).display() + nl + nl;
}
answer += "}";
return answer;
}
use of org.ow2.proactive.scheduler.common.task.TaskId in project scheduling by ow2-proactive.
the class InternalJob method replicateForNextLoopIteration.
public boolean replicateForNextLoopIteration(InternalTask initiator, InternalTask target, ChangedTasksInfo changesInfo, SchedulerStateUpdate frontend, FlowAction action) {
LOGGER.info("LOOP (init:" + initiator.getId() + "; target:" + target.getId() + ")");
// accumulates the tasks between the initiator and the target
Map<TaskId, InternalTask> dup = new HashMap<>();
// replicate the tasks between the initiator and the target
try {
initiator.replicateTree(dup, target.getId(), true, initiator.getReplicationIndex(), initiator.getIterationIndex());
} catch (ExecutableCreationException e) {
LOGGER.error("", e);
return false;
}
((JobInfoImpl) this.getJobInfo()).setNumberOfPendingTasks(this.getJobInfo().getNumberOfPendingTasks() + dup.size());
// time-consuming but safe
for (InternalTask nt : dup.values()) {
boolean ok;
do {
ok = true;
for (InternalTask task : tasks.values()) {
if (nt.getName().equals(task.getName())) {
nt.setIterationIndex(nt.getIterationIndex() + 1);
ok = false;
}
}
} while (!ok);
}
// configure the new tasks
InternalTask newTarget = null;
InternalTask newInit = null;
for (Entry<TaskId, InternalTask> it : dup.entrySet()) {
InternalTask nt = it.getValue();
if (target.getId().equals(it.getKey())) {
newTarget = nt;
}
if (initiator.getId().equals(it.getKey())) {
newInit = nt;
}
nt.setJobInfo(getJobInfo());
this.addTask(nt);
assignReplicationTag(nt, initiator, true, action);
}
changesInfo.newTasksAdded(dup.values());
// connect replicated tree
newTarget.addDependence(initiator);
changesInfo.taskUpdated(newTarget);
// connect mergers
List<InternalTask> mergers = new ArrayList<>();
for (InternalTask t : this.tasks.values()) {
if (t.getIDependences() != null) {
for (InternalTask p : t.getIDependences()) {
if (p.getId().equals(initiator.getId())) {
if (!t.equals(newTarget)) {
mergers.add(t);
}
}
}
}
}
for (InternalTask t : mergers) {
t.getIDependences().remove(initiator);
t.addDependence(newInit);
changesInfo.taskUpdated(t);
}
// propagate the changes in the job descriptor
getJobDescriptor().doLoop(initiator.getId(), dup, newTarget, newInit);
this.jobInfo.setTasksChanges(changesInfo, this);
// notify frontend that tasks were added and modified
frontend.jobStateUpdated(this.getOwner(), new NotificationData<JobInfo>(SchedulerEvent.TASK_REPLICATED, new JobInfoImpl(jobInfo)));
frontend.jobUpdatedFullData(this);
this.jobInfo.clearTasksChanges();
return true;
}
use of org.ow2.proactive.scheduler.common.task.TaskId in project scheduling by ow2-proactive.
the class InternalJob method failed.
/**
* Failed this job due to the given task failure or job has been killed
*
* @param taskId the task that has been the cause to failure. Can be null if
* the job has been killed
* @param jobStatus type of the failure on this job. (failed/canceled/killed)
*/
public Set<TaskId> failed(TaskId taskId, JobStatus jobStatus) {
if (jobStatus != JobStatus.KILLED) {
InternalTask descriptor = tasks.get(taskId);
if (descriptor.getStartTime() > 0) {
descriptor.setFinishedTime(System.currentTimeMillis());
setNumberOfFinishedTasks(getNumberOfFinishedTasks() + 1);
if (descriptor.getExecutionDuration() < 0) {
descriptor.setExecutionDuration(descriptor.getFinishedTime() - descriptor.getStartTime());
}
}
descriptor.setStatus((jobStatus == JobStatus.FAILED) ? TaskStatus.FAILED : TaskStatus.FAULTY);
// terminate this job descriptor
getJobDescriptor().failed();
}
// set the new status of the job
setFinishedTime(System.currentTimeMillis());
setNumberOfPendingTasks(0);
setNumberOfRunningTasks(0);
setStatus(jobStatus);
// creating list of status
Set<TaskId> updatedTasks = new HashSet<>();
for (InternalTask td : tasks.values()) {
if (!td.getId().equals(taskId)) {
if (td.getStatus() == TaskStatus.RUNNING) {
td.setStatus(TaskStatus.ABORTED);
td.setFinishedTime(System.currentTimeMillis());
if (td.getStartTime() > 0 && td.getExecutionDuration() < 0) {
td.setExecutionDuration(td.getFinishedTime() - td.getStartTime());
}
updatedTasks.add(td.getId());
} else if (td.getStatus() == TaskStatus.WAITING_ON_ERROR || td.getStatus() == TaskStatus.WAITING_ON_FAILURE) {
td.setStatus(TaskStatus.NOT_RESTARTED);
updatedTasks.add(td.getId());
} else if (td.getStatus() != TaskStatus.FINISHED && td.getStatus() != TaskStatus.FAILED && td.getStatus() != TaskStatus.FAULTY && td.getStatus() != TaskStatus.SKIPPED) {
td.setStatus(TaskStatus.NOT_STARTED);
updatedTasks.add(td.getId());
}
}
}
terminateTaskDataSpaceApplications();
return updatedTasks;
}
use of org.ow2.proactive.scheduler.common.task.TaskId in project scheduling by ow2-proactive.
the class InternalJob method terminateTask.
/**
* Terminate a task, change status, managing dependencies
* <p>
* Also, apply a Control Flow Action if provided. This may alter the number
* of tasks in the job, events have to be sent accordingly.
*
* @param errorOccurred has an error occurred for this termination
* @param taskId the task to terminate.
* @param frontend Used to notify all listeners of the replication of tasks,
* triggered by the FlowAction
* @param action a Control Flow Action that will potentially create new tasks
* inside the job
* @return the taskDescriptor that has just been terminated.
*/
public ChangedTasksInfo terminateTask(boolean errorOccurred, TaskId taskId, SchedulerStateUpdate frontend, FlowAction action, TaskResultImpl result, boolean taskIsPaused) {
final InternalTask descriptor = tasks.get(taskId);
if (!errorOccurred) {
decreaseNumberOfFaultyTasks(taskId);
}
descriptor.setFinishedTime(System.currentTimeMillis());
descriptor.setStatus(errorOccurred ? TaskStatus.FAULTY : TaskStatus.FINISHED);
descriptor.setExecutionDuration(result.getTaskDuration());
if (taskIsPaused) {
setNumberOfInErrorTasks(getNumberOfInErrorTasks() - 1);
} else {
setNumberOfRunningTasks(getNumberOfRunningTasks() - 1);
}
setNumberOfFinishedTasks(getNumberOfFinishedTasks() + 1);
if ((getStatus() == JobStatus.RUNNING) && (getNumberOfRunningTasks() == 0) && !taskIsPaused) {
setStatus(JobStatus.STALLED);
}
ChangedTasksInfo changesInfo = new ChangedTasksInfo();
changesInfo.taskUpdated(descriptor);
boolean didAction = false;
if (action != null) {
InternalTask initiator = tasks.get(taskId);
switch(action.getType()) {
/*
* LOOP action
*/
case LOOP:
{
didAction = terminateLoopHandler.terminateLoopTask(action, initiator, changesInfo, frontend);
break;
}
/*
* IF action
*/
case IF:
{
didAction = terminateIfTaskHandler.terminateIfTask(action, initiator, changesInfo, frontend, descriptor, taskId);
break;
}
/*
* REPLICATE action
*/
case REPLICATE:
{
didAction = terminateReplicateTaskHandler.terminateReplicateTask(action, initiator, changesInfo, frontend, taskId);
break;
}
/*
* CONTINUE action : - continue taskflow as if no action was provided
*/
case CONTINUE:
LOGGER.debug("Task flow Action CONTINUE on task " + initiator.getId().getReadableName());
break;
default:
LOGGER.warn("There are inconsistency between InternalJob and FlowActionType classes.");
break;
}
/**
* System.out.println("******** task dump ** " +
* this.getJobInfo().getJobId() + " " + initiator.getName() +
* " does " + action.getType() + " " + ((action.getTarget() == null)
* ? "." : action.getTarget()) + " " + ((action.getTargetElse() ==
* null) ? "." : action.getTargetElse()) + " " +
* ((action.getTargetJoin() == null) ? "." :
* action.getTargetJoin())); for (InternalTask it :
* this.tasks.values()) { System.out.print(it.getName() + " "); if
* (it.getIDependences() != null) { System.out.print("deps "); for
* (InternalTask parent : it.getIDependences()) {
* System.out.print(parent.getName() + " "); } } if
* (it.getIfBranch() != null) { System.out.print("if " +
* it.getIfBranch().getName() + " "); } if (it.getJoinedBranches()
* != null && it.getJoinedBranches().size() == 2) {
* System.out.print("join " +
* it.getJoinedBranches().get(0).getName() + " " +
* it.getJoinedBranches().get(1).getName()); } System.out.println();
* } System.out.println("******** task dump ** " +
* this.getJobInfo().getJobId()); System.out.println();
*/
}
// terminate this task
if (!didAction) {
getJobDescriptor().terminate(taskId, taskIsPaused);
}
return changesInfo;
}
use of org.ow2.proactive.scheduler.common.task.TaskId in project scheduling by ow2-proactive.
the class InternalJob method update.
@Override
public synchronized void update(JobInfo info) {
if (!getId().equals(info.getJobId())) {
throw new IllegalArgumentException("This job info is not applicable for this job. (expected id is '" + getId() + "' but was '" + info.getJobId() + "'");
}
// update job info
this.jobInfo = (JobInfoImpl) info;
// update skipped tasks
if (this.jobInfo.getTasksSkipped() != null) {
for (TaskId id : tasks.keySet()) {
if (this.jobInfo.getTasksSkipped().contains(id)) {
TaskInfoImpl taskInfo = (TaskInfoImpl) tasks.get(id).getTaskInfo();
taskInfo.setStatus(TaskStatus.SKIPPED);
}
}
}
}
Aggregations