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