Search in sources :

Example 6 with ExecutionContext

use of org.ovirt.engine.core.bll.job.ExecutionContext in project ovirt-engine by oVirt.

the class RunVmCommand method createContextForRunStatelessVm.

private CommandContext createContextForRunStatelessVm() {
    Step step = getExecutionContext().getStep();
    if (step == null) {
        return cloneContextAndDetachFromParent();
    }
    // Retrieve the job object and its steps as this the endSuccessfully stage of command execution -
    // at this is a new instance of the command is used
    // (comparing with the execution state) so all information on the job and steps should be retrieved.
    Job job = jobRepository.getJobWithSteps(step.getJobId());
    Step executingStep = job.getDirectStep(StepEnum.EXECUTING);
    // We would like to to set the run stateless step as substep of executing step
    setInternalExecution(true);
    ExecutionContext runStatelessVmCtx = new ExecutionContext();
    // The internal command should be monitored for tasks
    runStatelessVmCtx.setMonitored(true);
    Step runStatelessStep = executionHandler.addSubStep(getExecutionContext(), executingStep, StepEnum.RUN_STATELESS_VM, ExecutionMessageDirector.resolveStepMessage(StepEnum.RUN_STATELESS_VM, getVmValuesForMsgResolving()));
    // This is needed in order to end the job upon execution of the steps of the child command
    runStatelessVmCtx.setShouldEndJob(true);
    runStatelessVmCtx.setJob(job);
    // Since run stateless step involves invocation of command, we should set the run stateless vm step as
    // the "beginning step" of the child command.
    runStatelessVmCtx.setStep(runStatelessStep);
    return cloneContextAndDetachFromParent().withExecutionContext(runStatelessVmCtx);
}
Also used : ExecutionContext(org.ovirt.engine.core.bll.job.ExecutionContext) Step(org.ovirt.engine.core.common.job.Step) Job(org.ovirt.engine.core.common.job.Job)

Example 7 with ExecutionContext

use of org.ovirt.engine.core.bll.job.ExecutionContext in project ovirt-engine by oVirt.

the class RemoveVmPoolCommand method createRemoveVmStepContext.

private CommandContext createRemoveVmStepContext(VM vm) {
    CommandContext commandCtx = null;
    try {
        Map<String, String> values = Collections.singletonMap(VdcObjectType.VM.name().toLowerCase(), vm.getName());
        Step removeVmStep = executionHandler.addSubStep(getExecutionContext(), getExecutionContext().getJob().getStep(StepEnum.EXECUTING), StepEnum.REMOVING_VM, ExecutionMessageDirector.resolveStepMessage(StepEnum.REMOVING_VM, values));
        ExecutionContext ctx = new ExecutionContext();
        ctx.setStep(removeVmStep);
        ctx.setMonitored(true);
        Map<String, Pair<String, String>> locks = new HashMap<>();
        addVmLocks(vm, locks);
        EngineLock engineLock = new EngineLock(locks, null);
        commandCtx = cloneContext().withoutCompensationContext().withExecutionContext(ctx).withLock(engineLock);
    } catch (RuntimeException e) {
        log.error("Failed to create command context of removing VM '{}' that was in Pool '{}': {}", vm.getName(), getVmPoolName(), 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) HashMap(java.util.HashMap) Step(org.ovirt.engine.core.common.job.Step) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 8 with ExecutionContext

use of org.ovirt.engine.core.bll.job.ExecutionContext in project ovirt-engine by oVirt.

the class AddStepCommand method executeCommand.

@Override
protected void executeCommand() {
    ExecutionContext context = new ExecutionContext();
    context.setMonitored(true);
    if (parentStep == null) {
        // A step that is directly under a job
        context.setJob(job);
        context.setExecutionMethod(ExecutionMethod.AsJob);
        jobRepository.loadJobSteps(job);
        Step step = executionHandler.addStep(context, getParameters().getStepType(), getParameters().getDescription(), true);
        setActionReturnValue(step.getId());
        setSucceeded(true);
    } else {
        // this is a sub-step
        context.setStep(parentStep);
        context.setExecutionMethod(ExecutionMethod.AsStep);
        jobRepository.loadParentStepSteps(parentStep);
        Step step = executionHandler.addSubStep(context, parentStep, getParameters().getStepType(), getParameters().getDescription(), true);
        setActionReturnValue(step.getId());
        setSucceeded(true);
    }
}
Also used : ExecutionContext(org.ovirt.engine.core.bll.job.ExecutionContext) Step(org.ovirt.engine.core.common.job.Step)

Example 9 with ExecutionContext

use of org.ovirt.engine.core.bll.job.ExecutionContext in project ovirt-engine by oVirt.

the class AttachUserToVmFromPoolAndRunCommand method runVm.

private ActionReturnValue runVm() {
    RunVmParams runVmParams = new RunVmParams(getVmId());
    runVmParams.setSessionId(getParameters().getSessionId());
    runVmParams.setEntityInfo(new EntityInfo(VdcObjectType.VM, getVmId()));
    runVmParams.setParentCommand(getActionType());
    runVmParams.setParentParameters(getParameters());
    runVmParams.setEndProcedure(EndProcedure.COMMAND_MANAGED);
    runVmParams.setRunAsStateless(!getVmPool().isStateful());
    ExecutionContext runVmContext = createRunVmContext();
    ActionReturnValue actionReturnValue = runInternalAction(ActionType.RunVm, runVmParams, cloneContext().withExecutionContext(runVmContext).withCompensationContext(null));
    getTaskIdList().addAll(actionReturnValue.getInternalVdsmTaskIdList());
    return actionReturnValue;
}
Also used : ExecutionContext(org.ovirt.engine.core.bll.job.ExecutionContext) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) EntityInfo(org.ovirt.engine.core.common.asynctasks.EntityInfo) RunVmParams(org.ovirt.engine.core.common.action.RunVmParams)

Example 10 with ExecutionContext

use of org.ovirt.engine.core.bll.job.ExecutionContext in project ovirt-engine by oVirt.

the class AttachUserToVmFromPoolAndRunCommand method createRunVmContext.

private ExecutionContext createRunVmContext() {
    ExecutionContext ctx = new ExecutionContext();
    try {
        Step step = executionHandler.addSubStep(getExecutionContext(), getExecutionContext().getJob().getStep(StepEnum.EXECUTING), StepEnum.TAKING_VM_FROM_POOL, ExecutionMessageDirector.resolveStepMessage(StepEnum.TAKING_VM_FROM_POOL, Collections.singletonMap(VdcObjectType.VM.name().toLowerCase(), getVmName())));
        ctx.setStep(step);
        ctx.setMonitored(true);
        ctx.setShouldEndJob(true);
    } catch (RuntimeException e) {
        log.error("Error when creating executing context for running stateless VM", e);
    }
    return ctx;
}
Also used : ExecutionContext(org.ovirt.engine.core.bll.job.ExecutionContext) Step(org.ovirt.engine.core.common.job.Step)

Aggregations

ExecutionContext (org.ovirt.engine.core.bll.job.ExecutionContext)27 Step (org.ovirt.engine.core.common.job.Step)14 CommandContext (org.ovirt.engine.core.bll.context.CommandContext)9 HashMap (java.util.HashMap)4 EngineContext (org.ovirt.engine.core.bll.context.EngineContext)3 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)3 EngineException (org.ovirt.engine.core.common.errors.EngineException)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 CommandMultiAsyncTasks (org.ovirt.engine.core.bll.CommandMultiAsyncTasks)1 HostProviderProxy (org.ovirt.engine.core.bll.host.provider.HostProviderProxy)1 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)1 RunVmParams (org.ovirt.engine.core.common.action.RunVmParams)1 SetStoragePoolStatusParameters (org.ovirt.engine.core.common.action.SetStoragePoolStatusParameters)1 VdsActionParameters (org.ovirt.engine.core.common.action.VdsActionParameters)1 AddVdsActionParameters (org.ovirt.engine.core.common.action.hostdeploy.AddVdsActionParameters)1 InstallVdsParameters (org.ovirt.engine.core.common.action.hostdeploy.InstallVdsParameters)1 EndedTaskInfo (org.ovirt.engine.core.common.asynctasks.EndedTaskInfo)1 EntityInfo (org.ovirt.engine.core.common.asynctasks.EntityInfo)1 GlusterAsyncTask (org.ovirt.engine.core.common.asynctasks.gluster.GlusterAsyncTask)1