use of org.ovirt.engine.core.bll.job.ExecutionContext in project ovirt-engine by oVirt.
the class CommonVmPoolCommand method createAddVmStepContext.
private CommandContext createAddVmStepContext(String currentVmName) {
CommandContext commandCtx = null;
try {
Map<String, String> values = new HashMap<>();
values.put(VdcObjectType.VM.name().toLowerCase(), currentVmName);
Step addVmStep = executionHandler.addSubStep(getExecutionContext(), getExecutionContext().getJob().getStep(StepEnum.EXECUTING), StepEnum.ADD_VM_TO_POOL, ExecutionMessageDirector.resolveStepMessage(StepEnum.ADD_VM_TO_POOL, values));
ExecutionContext ctx = new ExecutionContext();
ctx.setStep(addVmStep);
ctx.setMonitored(true);
commandCtx = cloneContextAndDetachFromParent().withExecutionContext(ctx);
} catch (RuntimeException e) {
log.error("Failed to create command context of adding VM '{}' to Pool '{}': {}", currentVmName, getParameters().getVmPool().getName(), 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 CommandBase method initCommandBase.
/**
* Initializes CommandBase instance when parameters are passed in constructor (non compensation
* context instance creation)
*/
private void initCommandBase() {
initUser();
ExecutionContext executionContext = context.getExecutionContext();
if (executionContext.getJob() != null) {
setJobId(executionContext.getJob().getId());
} else if (executionContext.getStep() != null) {
setJobId(executionContext.getStep().getJobId());
}
setCorrelationId(parameters.getCorrelationId());
}
use of org.ovirt.engine.core.bll.job.ExecutionContext 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;
}
use of org.ovirt.engine.core.bll.job.ExecutionContext in project ovirt-engine by oVirt.
the class CommandAsyncTask method endCommandAction.
private void endCommandAction() {
CommandMultiAsyncTasks entityInfo = getCommandMultiAsyncTasks();
ActionReturnValue actionReturnValue = null;
ExecutionContext context = null;
boolean endActionRuntimeException = false;
AsyncTask dbAsyncTask = getParameters().getDbAsyncTask();
ArrayList<ActionParametersBase> imagesParameters = new ArrayList<>();
for (EndedTaskInfo taskInfo : entityInfo.getEndedTasksInfo().getTasksInfo()) {
ActionParametersBase childTaskParameters = taskInfo.getTaskParameters().getDbAsyncTask().getTaskParameters();
boolean childTaskGroupSuccess = childTaskParameters.getTaskGroupSuccess() && taskInfo.getTaskStatus().getTaskEndedSuccessfully();
childTaskParameters.setTaskGroupSuccess(childTaskGroupSuccess);
if (!childTaskParameters.equals(dbAsyncTask.getActionParameters())) {
imagesParameters.add(childTaskParameters);
}
}
dbAsyncTask.getActionParameters().setImagesParameters(imagesParameters);
try {
log.info("CommandAsyncTask::endCommandAction [within thread] context: Attempting to endAction '{}',", dbAsyncTask.getActionParameters().getCommandType());
try {
actionReturnValue = coco.endAction(this);
} catch (EngineException ex) {
log.error("{}: {}", getErrorMessage(), ex.getMessage());
log.debug("Exception", ex);
} catch (RuntimeException ex) {
log.error(getErrorMessage(), ex);
endActionRuntimeException = true;
}
} catch (RuntimeException Ex2) {
log.error("CommandAsyncTask::endCommandAction [within thread]: An exception has been thrown (not" + " related to 'endAction' itself)", Ex2);
endActionRuntimeException = true;
} finally {
// if a RuntimeExcpetion occurs we clear the task from db and perform no other action
if (endActionRuntimeException) {
handleEndActionRuntimeException(entityInfo, dbAsyncTask);
} else {
boolean isTaskGroupSuccess = dbAsyncTask.getActionParameters().getTaskGroupSuccess();
handleEndActionResult(entityInfo, actionReturnValue, context, isTaskGroupSuccess);
}
}
}
use of org.ovirt.engine.core.bll.job.ExecutionContext in project ovirt-engine by oVirt.
the class CommandContextsCacheImpl method buildCommandContext.
private CommandContext buildCommandContext(CommandEntity cmdEntity) {
ExecutionContext executionContext = new ExecutionContext();
PersistedCommandContext persistedCommandContext = cmdEntity.getCommandContext();
if (!Guid.isNullOrEmpty(persistedCommandContext.getJobId())) {
executionContext.setJob(jobRepository.getJobWithSteps(persistedCommandContext.getJobId()));
} else if (!Guid.isNullOrEmpty(persistedCommandContext.getStepId())) {
executionContext.setStep(jobRepository.getStep(persistedCommandContext.getStepId(), false));
}
executionContext.setExecutionMethod(persistedCommandContext.getExecutionMethod());
executionContext.setCompleted(persistedCommandContext.isCompleted());
executionContext.setJobRequired(persistedCommandContext.isJobRequired());
executionContext.setMonitored(persistedCommandContext.isMonitored());
executionContext.setShouldEndJob(persistedCommandContext.shouldEndJob());
executionContext.setTasksMonitored(persistedCommandContext.isTasksMonitored());
return new CommandContext(new EngineContext()).withExecutionContext(executionContext);
}
Aggregations