Search in sources :

Example 11 with ExecutionContext

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

Example 12 with ExecutionContext

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());
}
Also used : ExecutionContext(org.ovirt.engine.core.bll.job.ExecutionContext)

Example 13 with ExecutionContext

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;
}
Also used : ExecutionContext(org.ovirt.engine.core.bll.job.ExecutionContext) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) StepEnum(org.ovirt.engine.core.common.job.StepEnum) Step(org.ovirt.engine.core.common.job.Step)

Example 14 with ExecutionContext

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);
        }
    }
}
Also used : CommandMultiAsyncTasks(org.ovirt.engine.core.bll.CommandMultiAsyncTasks) ExecutionContext(org.ovirt.engine.core.bll.job.ExecutionContext) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) AsyncTask(org.ovirt.engine.core.common.businessentities.AsyncTask) ArrayList(java.util.ArrayList) EngineException(org.ovirt.engine.core.common.errors.EngineException) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) EndedTaskInfo(org.ovirt.engine.core.common.asynctasks.EndedTaskInfo)

Example 15 with ExecutionContext

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);
}
Also used : ExecutionContext(org.ovirt.engine.core.bll.job.ExecutionContext) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) PersistedCommandContext(org.ovirt.engine.core.common.utils.PersistedCommandContext) EngineContext(org.ovirt.engine.core.bll.context.EngineContext) PersistedCommandContext(org.ovirt.engine.core.common.utils.PersistedCommandContext)

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