use of org.ovirt.engine.core.common.job.Step in project ovirt-engine by oVirt.
the class RunVmCommand method createContextForStatelessSnapshotCreation.
private CommandContext createContextForStatelessSnapshotCreation() {
Map<String, String> values = getVmValuesForMsgResolving();
// Creating snapshots as sub step of run stateless
Step createSnapshotsStep = addSubStep(StepEnum.EXECUTING, StepEnum.CREATING_SNAPSHOTS, values);
// Add the step as the first step of the new context
ExecutionContext createSnapshotsCtx = new ExecutionContext();
createSnapshotsCtx.setMonitored(true);
createSnapshotsCtx.setStep(createSnapshotsStep);
getContext().withExecutionContext(createSnapshotsCtx);
persistCommandIfNeeded();
return getContext().clone().withoutCompensationContext();
}
use of org.ovirt.engine.core.common.job.Step in project ovirt-engine by oVirt.
the class MaintenanceNumberOfVdssCommand method validateNoRunningJobs.
private boolean validateNoRunningJobs(VDS vds) {
List<Step> steps = stepDao.getStartedStepsByStepSubjectEntity(new SubjectEntity(VdcObjectType.EXECUTION_HOST, vds.getId()));
if (!steps.isEmpty()) {
List<String> replacements = new ArrayList<>(2);
replacements.add(ReplacementUtils.createSetVariableString("host", vds.getName()));
replacements.addAll(ReplacementUtils.replaceWith("jobs", steps.stream().map(s -> s.getDescription()).collect(Collectors.toList())));
return failValidation(EngineMessage.VDS_CANNOT_MAINTENANCE_HOST_WITH_RUNNING_OPERATIONS, replacements);
}
return true;
}
use of org.ovirt.engine.core.common.job.Step in project ovirt-engine by oVirt.
the class MaintenanceVdsCommand method createMigrateVmContext.
protected CommandContext createMigrateVmContext(ExecutionContext parentContext, VM vm) {
ExecutionContext ctx = new ExecutionContext();
try {
Map<String, String> values = new HashMap<>();
values.put(VdcObjectType.VM.name().toLowerCase(), vm.getName());
values.put(VdcObjectType.VDS.name().toLowerCase(), vm.getRunOnVdsName());
Step step = executionHandler.addSubStep(getExecutionContext(), parentContext.getJob().getStep(StepEnum.EXECUTING), StepEnum.MIGRATE_VM, ExecutionMessageDirector.resolveStepMessage(StepEnum.MIGRATE_VM, values));
ctx.setJob(parentContext.getJob());
ctx.setStep(step);
ctx.setMonitored(true);
} catch (RuntimeException e) {
log.error("Failed to create ExecutionContext for MigrateVmCommand", e);
}
return cloneContextAndDetachFromParent().withExecutionContext(ctx);
}
use of org.ovirt.engine.core.common.job.Step in project ovirt-engine by oVirt.
the class AddUnmanagedVmsCommand method createAddExternalVmContext.
protected CommandContext createAddExternalVmContext(VmStatic vmStatic) {
ExecutionContext ctx = new ExecutionContext();
try {
Step step = executionHandler.addSubStep(getExecutionContext(), getExecutionContext().getJob().getStep(StepEnum.EXECUTING), StepEnum.ADD_VM, ExecutionMessageDirector.resolveStepMessage(StepEnum.ADD_VM, Collections.singletonMap(VdcObjectType.VM.name().toLowerCase(), vmStatic.getName())));
ctx.setJob(getExecutionContext().getJob());
ctx.setStep(step);
ctx.setMonitored(true);
} catch (RuntimeException e) {
log.error("Failed to create ExecutionContext for AddVmFromScratch", e);
}
return cloneContextAndDetachFromParent().withExecutionContext(ctx);
}
use of org.ovirt.engine.core.common.job.Step in project ovirt-engine by oVirt.
the class CommandBase method executeAction.
public ActionReturnValue executeAction() {
getSessionDataContainer().updateSessionLastActiveTime(getParameters().getSessionId());
determineExecutionReason();
actionState = CommandActionState.EXECUTE;
String tempVar = getDescription();
getReturnValue().setDescription((tempVar != null) ? tempVar : getReturnValue().getDescription());
setActionMessageParameters();
Step validatingStep = null;
boolean actionAllowed;
boolean isExternal = this.getParameters().getJobId() != null || this.getParameters().getStepId() != null;
if (!isExternal) {
validatingStep = executionHandler.addStep(getExecutionContext(), StepEnum.VALIDATING, null);
}
try {
if (parentHasCallback()) {
persistCommand(getParameters().getParentCommand());
}
actionAllowed = getReturnValue().isValid() || internalValidate();
if (!isExternal) {
executionHandler.endStep(getExecutionContext(), validatingStep, actionAllowed);
}
if (actionAllowed) {
execute();
} else {
getReturnValue().setValid(false);
}
} finally {
updateCommandIfNeeded();
freeLockExecute();
clearAsyncTasksWithOutVdsmId();
}
return getReturnValue();
}
Aggregations