use of org.ovirt.engine.core.common.job.Step in project ovirt-engine by oVirt.
the class ExecutionHandler method createFinalizingContext.
/**
* Creates {@code ExecutionContext} which defines the context for executing the finalizing step of the job. If the
* step exists, it must be part of a job, therefore the {@code Job} entity is being set as part of the context.
*
* @param stepId
* The unique identifier of the step. Must not be {@code null}.
* @return The context for monitoring the finalizing step of the job, or {@code null} if no such step.
*/
public ExecutionContext createFinalizingContext(Guid stepId) {
ExecutionContext context = null;
try {
Step step = jobRepository.getStep(stepId, false);
if (step != null && step.getParentStepId() != null) {
context = new ExecutionContext();
Step executionStep = jobRepository.getStep(step.getParentStepId(), false);
// indicates if a step is monitored at Job level or as an inner step
Guid parentStepId = executionStep.getParentStepId();
if (parentStepId == null) {
context.setExecutionMethod(ExecutionMethod.AsJob);
context.setJob(jobRepository.getJobWithSteps(step.getJobId()));
} else {
context.setExecutionMethod(ExecutionMethod.AsStep);
Step parentStep = jobRepository.getStep(parentStepId, false);
parentStep.setSteps(stepDao.getStepsByParentStepId(parentStep.getId()));
context.setStep(parentStep);
}
context.setMonitored(true);
}
} catch (Exception e) {
log.error("Exception", e);
}
return context;
}
use of org.ovirt.engine.core.common.job.Step in project ovirt-engine by oVirt.
the class ExecutionHandler method endTaskJobIfNeeded.
/**
* Finalizes Job with VDSM tasks, as this case requires verification that no other steps are running in order to
* close the entire Job
*
* @param context
* The context of the execution which defines how the job should be ended
* @param exitStatus
* Indicates if the execution described by the job ended successfully or not.
*/
public void endTaskJobIfNeeded(ExecutionContext context, boolean exitStatus) {
if (context == null) {
return;
}
if (context.getExecutionMethod() == ExecutionMethod.AsJob && context.getJob() != null) {
endJob(context, exitStatus);
} else {
Step parentStep = context.getStep();
if (context.getExecutionMethod() == ExecutionMethod.AsStep && parentStep != null) {
List<Step> steps = stepDao.getStepsByJobId(parentStep.getJobId());
boolean hasChildStepsRunning = false;
for (Step step : steps) {
if (step.getStatus() == JobExecutionStatus.STARTED && step.getParentStepId() != null) {
hasChildStepsRunning = true;
break;
}
}
if (!hasChildStepsRunning) {
endJob(exitStatus, jobRepository.getJob(parentStep.getJobId()));
}
}
}
}
use of org.ovirt.engine.core.common.job.Step in project ovirt-engine by oVirt.
the class ExecutionHandler method endTaskStep.
/**
* Finalizes a {@code Step} execution which represents a VDSM task. In case of a failure status, the job will not be
* marked as failed at this stage, but via executing the {@code CommandBase.endAction} with the proper status by
* {@code the AsyncTaskManager}.
*
* @param stepId
* A unique identifier of the step to finalize.
* @param exitStatus
* The status which the step should be ended with.
*/
public void endTaskStep(Guid stepId, JobExecutionStatus exitStatus) {
try {
if (stepId != null) {
Step step = jobRepository.getStep(stepId, false);
if (step != null) {
step.markStepEnded(exitStatus);
jobRepository.updateStep(step);
}
}
} catch (Exception e) {
log.error("Failed to terminate step '{}' with status '{}': {}", stepId, exitStatus, e.getMessage());
log.debug("Exception", e);
}
}
use of org.ovirt.engine.core.common.job.Step in project ovirt-engine by oVirt.
the class ExecutionHandler method endStep.
/**
* Finalizes a {@code Step} execution by a given context in which the step was performed and by the exit status of
* the step.
*
* @param context
* The context in which the {@code Step} was executed.
* @param step
* The step to finalize.
* @param exitStatus
* Indicates if the execution described by the step ended successfully or not.
*/
public void endStep(ExecutionContext context, Step step, boolean exitStatus) {
if (context == null) {
return;
}
if (context.isMonitored()) {
Job job = context.getJob();
try {
if (step != null) {
step.markStepEnded(exitStatus);
jobRepository.updateStep(step);
}
if (context.getExecutionMethod() == ExecutionMethod.AsJob && job != null && !exitStatus) {
// step failure will cause the job to be marked as failed
context.setCompleted(true);
job.markJobEnded(false);
jobRepository.updateCompletedJobAndSteps(job);
} else {
Step parentStep = context.getStep();
if (context.getExecutionMethod() == ExecutionMethod.AsStep && parentStep != null) {
context.setCompleted(true);
if (job != null && !exitStatus) {
job.markJobEnded(false);
jobRepository.updateCompletedJobAndSteps(job);
}
}
}
} catch (Exception e) {
log.error("Exception", e);
}
}
}
use of org.ovirt.engine.core.common.job.Step in project ovirt-engine by oVirt.
the class CreateGlusterVolumeCommand method createCommandContext.
/**
* Creates command context for setting a given option on the given volume
*/
private CommandContext createCommandContext(GlusterVolumeEntity volume, GlusterVolumeOptionEntity option) {
// Add sub-step for setting given option
Step setOptionStep = addSubStep(StepEnum.EXECUTING, StepEnum.SETTING_GLUSTER_OPTION, getOptionValues(volume, option));
// Create execution context for setting option
ExecutionContext setOptionCtx = new ExecutionContext();
setOptionCtx.setMonitored(true);
setOptionCtx.setStep(setOptionStep);
return cloneContext().withExecutionContext(setOptionCtx).withoutLock();
}
Aggregations