Search in sources :

Example 41 with Step

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;
}
Also used : Step(org.ovirt.engine.core.common.job.Step) Guid(org.ovirt.engine.core.compat.Guid)

Example 42 with Step

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()));
            }
        }
    }
}
Also used : Step(org.ovirt.engine.core.common.job.Step)

Example 43 with Step

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);
    }
}
Also used : Step(org.ovirt.engine.core.common.job.Step)

Example 44 with Step

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);
        }
    }
}
Also used : Step(org.ovirt.engine.core.common.job.Step) Job(org.ovirt.engine.core.common.job.Job)

Example 45 with Step

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();
}
Also used : ExecutionContext(org.ovirt.engine.core.bll.job.ExecutionContext) Step(org.ovirt.engine.core.common.job.Step)

Aggregations

Step (org.ovirt.engine.core.common.job.Step)52 ExecutionContext (org.ovirt.engine.core.bll.job.ExecutionContext)14 Guid (org.ovirt.engine.core.compat.Guid)12 HashMap (java.util.HashMap)8 Job (org.ovirt.engine.core.common.job.Job)8 Date (java.util.Date)7 Test (org.junit.Test)6 CommandContext (org.ovirt.engine.core.bll.context.CommandContext)6 ArrayList (java.util.ArrayList)5 JobExecutionStatus (org.ovirt.engine.core.common.job.JobExecutionStatus)5 List (java.util.List)4 VdcObjectType (org.ovirt.engine.core.common.VdcObjectType)4 GlusterAsyncTask (org.ovirt.engine.core.common.asynctasks.gluster.GlusterAsyncTask)4 StepSubjectEntity (org.ovirt.engine.core.common.job.StepSubjectEntity)4 Map (java.util.Map)3 StepEnum (org.ovirt.engine.core.common.job.StepEnum)3 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Inject (javax.inject.Inject)2