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);
}
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;
}
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);
}
}
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;
}
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;
}
Aggregations