Search in sources :

Example 16 with Step

use of org.ovirt.engine.core.common.job.Step in project ovirt-engine by oVirt.

the class ExportOvaCommand method createOvaCreationStepContext.

protected CommandContext createOvaCreationStepContext() {
    CommandContext commandCtx = null;
    StepEnum step = StepEnum.CREATING_OVA;
    try {
        Step ovaCreationStep = executionHandler.addSubStep(getExecutionContext(), getExecutionContext().getJob().getStep(StepEnum.EXECUTING), step, ExecutionMessageDirector.resolveStepMessage(step, Collections.emptyMap()));
        ExecutionContext ctx = new ExecutionContext();
        ctx.setStep(ovaCreationStep);
        ctx.setMonitored(true);
        commandCtx = cloneContext().withoutCompensationContext().withExecutionContext(ctx).withoutLock();
    } catch (RuntimeException e) {
        log.error("Failed to create command context of creating OVA '{}': {}", getVmName(), e.getMessage());
        log.debug("Exception", e);
    }
    return commandCtx;
}
Also used : ExecutionContext(org.ovirt.engine.core.bll.job.ExecutionContext) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) StepEnum(org.ovirt.engine.core.common.job.StepEnum) Step(org.ovirt.engine.core.common.job.Step)

Example 17 with Step

use of org.ovirt.engine.core.common.job.Step in project ovirt-engine by oVirt.

the class VdsCommandsHelper method updateStepMessage.

private void updateStepMessage(CommandBase<?> cmd, Guid vdsForExecution) {
    // As an HSM job can run on any host, we want to display the host running the job when it is
    // chosen. To do so, we look for a corresponding command step with an "_ON_HOST" suffix that
    // is supposed to contain a "vds" placeholder.
    StepEnum stepEnum = null;
    try {
        stepEnum = StepEnum.valueOf(getStepWithHostname(cmd));
    } catch (IllegalArgumentException e) {
        // Ignore this exception and do nothing as no corresponding step_ON_HOST found.
        log.debug("No StepEnum found for " + getStepWithHostname(cmd));
        return;
    }
    Step step = cmd.getExecutionContext().getStep();
    Map<String, String> jobProperties = cmd.getJobMessageProperties();
    jobProperties.put(VdcObjectType.VDS.name().toLowerCase(), vdsDao.get(vdsForExecution).getName());
    step.setDescription(ExecutionMessageDirector.resolveStepMessage(stepEnum, jobProperties));
    stepDao.update(step);
    // Add an audit log entry if a corresponding AuditLogType exists. Note that we expect an AuditLogType
    // with name equals to Step_Enum to exist. If an AuditLogType exists, the arguments in the audit
    // message must match these in the StepEnum message.
    AuditLogType logType = null;
    try {
        logType = AuditLogType.valueOf(getAuditLogType(cmd));
    } catch (IllegalArgumentException e) {
        // Ignore this exception and do nothing as no corresponding AuditLogType found.
        log.debug("No AuditLogType found for " + getAuditLogType(cmd));
        return;
    }
    jobProperties.entrySet().stream().forEach(entry -> cmd.addCustomValue(entry.getKey(), entry.getValue()));
    Injector.get(AuditLogDirector.class).log(cmd, logType);
}
Also used : AuditLogType(org.ovirt.engine.core.common.AuditLogType) StepEnum(org.ovirt.engine.core.common.job.StepEnum) Step(org.ovirt.engine.core.common.job.Step) AuditLogDirector(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector)

Example 18 with Step

use of org.ovirt.engine.core.common.job.Step in project ovirt-engine by oVirt.

the class ExecutionHandler method endFinalizingStepAndCurrentStep.

/**
 * If the provided {@link ExecutionContext} execution method is as Step the current step will
 * be ended with the appropriate exitStatus and so is the FINALIZING {@link Step} if present.
 *
 * @param context
 *            The context of the execution
 * @param exitStatus
 *            Indicates if the execution ended successfully or not.
 */
public void endFinalizingStepAndCurrentStep(ExecutionContext context, boolean exitStatus) {
    if (context == null) {
        return;
    }
    try {
        Step parentStep = context.getStep();
        if (context.getExecutionMethod() == ExecutionMethod.AsStep && parentStep != null) {
            Step finalizingStep = parentStep.getStep(StepEnum.FINALIZING);
            if (finalizingStep != null) {
                finalizingStep.markStepEnded(exitStatus);
                jobRepository.updateStep(finalizingStep);
            }
            parentStep.markStepEnded(exitStatus);
            jobRepository.updateStep(parentStep);
        }
    } catch (RuntimeException e) {
        log.error("Exception", e);
    }
}
Also used : Step(org.ovirt.engine.core.common.job.Step)

Example 19 with Step

use of org.ovirt.engine.core.common.job.Step in project ovirt-engine by oVirt.

the class ExecutionHandler method addSubStep.

/**
 * Adds a {@link Step} entity by the provided context as a child step of a given parent step. A {@link Step} will
 * not be created if {@code ExecutionContext.isMonitored()} returns false.
 *
 * @param context
 *            The context of the execution which defines visibility and execution method.
 * @param parentStep
 *            The parent step which the new step will be added as its child.
 * @param newStepName
 *            The name of the step.
 * @param description
 *            A presentation name for the step. If not provided, the presentation name is resolved by the
 *            {@code stepName}.
 * @param isExternal
 *        Indicates if the step is invoked by a plug-in
 */
public Step addSubStep(ExecutionContext context, Step parentStep, StepEnum newStepName, String description, boolean isExternal) {
    Step step = null;
    if (context == null || parentStep == null) {
        return null;
    }
    try {
        if (context.isMonitored()) {
            if (description == null) {
                description = ExecutionMessageDirector.getInstance().getStepMessage(newStepName);
            }
            if (context.getExecutionMethod() == ExecutionMethod.AsJob) {
                if (stepDao.exists(parentStep.getId())) {
                    if (parentStep.getJobId().equals(context.getJob().getId())) {
                        step = parentStep.addStep(newStepName, description);
                    }
                }
            } else if (context.getExecutionMethod() == ExecutionMethod.AsStep) {
                step = parentStep.addStep(newStepName, description);
            }
        }
        if (step != null) {
            step.setExternal(isExternal);
            jobRepository.saveStep(step);
        }
    } catch (Exception e) {
        log.error("Exception", e);
    }
    return step;
}
Also used : Step(org.ovirt.engine.core.common.job.Step)

Example 20 with Step

use of org.ovirt.engine.core.common.job.Step in project ovirt-engine by oVirt.

the class ExecutionHandler method createDefaultContextForTasksImpl.

private static ExecutionContext createDefaultContextForTasksImpl(ExecutionContext parentExecutionContext) {
    ExecutionContext executionContext = new ExecutionContext();
    if (parentExecutionContext != null) {
        if (parentExecutionContext.getJob() != null) {
            Step parentStep = parentExecutionContext.getParentTasksStep();
            if (parentStep != null) {
                executionContext.setParentTasksStep(parentStep);
            }
        } else {
            executionContext.setParentTasksStep(parentExecutionContext.getParentTasksStep());
        }
        executionContext.setStep(parentExecutionContext.getStep());
        executionContext.setStepsList(parentExecutionContext.getStepsList());
        executionContext.setJob(parentExecutionContext.getJob());
    }
    return executionContext;
}
Also used : 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