use of org.ow2.proactive.scheduler.job.InternalJob in project scheduling by ow2-proactive.
the class SchedulerDBManager method loadInternalJobs.
// Executed in a transaction from the caller
private List<InternalJob> loadInternalJobs(boolean fullState, Session session, List<Long> ids) {
Query jobQuery = session.getNamedQuery("loadInternalJobs");
List<InternalJob> result = new ArrayList<>(ids.size());
List<Long> batchLoadIds = new ArrayList<>(RECOVERY_LOAD_JOBS_BATCH_SIZE);
int batchIndex = 1;
for (Long id : ids) {
batchLoadIds.add(id);
if (batchLoadIds.size() == RECOVERY_LOAD_JOBS_BATCH_SIZE) {
logger.info("Loading internal Jobs, batch number " + batchIndex);
batchLoadJobs(session, fullState, jobQuery, batchLoadIds, result);
batchLoadIds.clear();
session.clear();
logger.info("Fetched " + (batchIndex * RECOVERY_LOAD_JOBS_BATCH_SIZE) + " internal Jobs");
batchIndex++;
}
}
if (!batchLoadIds.isEmpty()) {
batchLoadJobs(session, fullState, jobQuery, batchLoadIds, result);
}
logger.info(ALL_REQUIRED_JOBS_HAVE_BEEN_FETCHED);
return result;
}
use of org.ow2.proactive.scheduler.job.InternalJob in project scheduling by ow2-proactive.
the class TaskData method toInternalTask.
InternalTask toInternalTask(InternalJob internalJob, boolean loadFullState) throws InvalidScriptException {
TaskId taskId = createTaskId(internalJob);
InternalTask internalTask;
if (taskType.equals(SCRIPT_TASK)) {
internalTask = new InternalScriptTask(internalJob);
} else if (taskType.equals(FORKED_SCRIPT_TASK)) {
internalTask = new InternalForkedScriptTask(internalJob);
} else {
throw new IllegalStateException("Unexpected stored task type: " + taskType);
}
internalTask.setId(taskId);
internalTask.setDescription(getDescription());
internalTask.setTag(this.getTag());
internalTask.setStatus(getTaskStatus());
internalTask.setJobInfo(internalJob.getJobInfo());
internalTask.setName(getTaskName());
internalTask.setExecutionDuration(getExecutionDuration());
internalTask.setFinishedTime(getFinishedTime());
internalTask.setInErrorTime(getInErrorTime());
internalTask.setStartTime(getStartTime());
internalTask.setScheduledTime(getScheduledTime());
internalTask.setExecutionHostName(getExecutionHostName());
internalTask.setOnTaskError(OnTaskError.getInstance(this.onTaskErrorString));
internalTask.setPreciousLogs(isPreciousLogs());
internalTask.setPreciousResult(isPreciousResult());
internalTask.setRunAsMe(isRunAsMe());
internalTask.setWallTime(getWallTime());
internalTask.setMaxNumberOfExecution(getMaxNumberOfExecution());
internalTask.setNumberOfExecutionLeft(getNumberOfExecutionLeft());
internalTask.setNumberOfExecutionOnFailureLeft(getNumberOfExecutionOnFailureLeft());
internalTask.setRestartTaskOnError(getRestartMode());
internalTask.setFlowBlock(getFlowBlock());
internalTask.setIterationIndex(getIteration());
internalTask.setReplicationIndex(getReplication());
internalTask.setMatchingBlock(getMatchingBlock());
internalTask.setVariables(variablesToTaskVariables());
if (hasAliveTaskLauncher() && getExecuterInformationData() != null) {
internalTask.setExecuterInformation(getExecuterInformationData().toExecuterInformation(loadFullState));
}
ForkEnvironment forkEnv = createForkEnvironment();
internalTask.setForkEnvironment(forkEnv);
return internalTask;
}
use of org.ow2.proactive.scheduler.job.InternalJob in project scheduling by ow2-proactive.
the class StartAtUpdater method updateStartAtAndTasksScheduledTime.
private Set<TaskId> updateStartAtAndTasksScheduledTime(InternalJob job, String startAt, long scheduledTime) {
List<InternalTask> internalTasks = job.getITasks();
Set<TaskId> updatedTasks = new HashSet<>(internalTasks.size());
if (resetJobGenericInformation(job, startAt)) {
for (InternalTask td : internalTasks) {
td.setScheduledTime(scheduledTime);
updatedTasks.add(td.getId());
job.getJobDescriptor().updateTaskScheduledTime(td.getId(), scheduledTime);
}
}
return updatedTasks;
}
use of org.ow2.proactive.scheduler.job.InternalJob in project scheduling by ow2-proactive.
the class TaskResultCreator method getTaskResult.
public TaskResultImpl getTaskResult(SchedulerDBManager dbManager, InternalJob job, InternalTask task, Throwable exception, TaskLogs output) throws UnknownTaskException {
if (task == null) {
throw new UnknownTaskException();
}
JobDescriptor jobDescriptor = job.getJobDescriptor();
EligibleTaskDescriptor eligibleTaskDescriptor = null;
if (jobDescriptor.getPausedTasks().get(task.getId()) != null) {
eligibleTaskDescriptor = (EligibleTaskDescriptor) jobDescriptor.getPausedTasks().get(task.getId());
} else if (jobDescriptor.getRunningTasks().get(task.getId()) != null) {
eligibleTaskDescriptor = (EligibleTaskDescriptor) jobDescriptor.getRunningTasks().get(task.getId());
}
TaskResultImpl taskResult = getEmptyTaskResult(task, exception, output);
taskResult.setPropagatedVariables(getPropagatedVariables(dbManager, eligibleTaskDescriptor, job, task));
return taskResult;
}
use of org.ow2.proactive.scheduler.job.InternalJob 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;
}
Aggregations