Search in sources :

Example 1 with CommandContext

use of org.ovirt.engine.core.bll.context.CommandContext in project ovirt-engine by oVirt.

the class ImportVmFromExternalProviderCommand method createConversionStepContext.

protected CommandContext createConversionStepContext(StepEnum step) {
    CommandContext commandCtx = null;
    try {
        Map<String, String> values = Collections.singletonMap(VdcObjectType.VM.name().toLowerCase(), getVmName());
        Step conversionStep = executionHandler.addSubStep(getExecutionContext(), getExecutionContext().getJob().getStep(StepEnum.EXECUTING), step, ExecutionMessageDirector.resolveStepMessage(step, values));
        ExecutionContext ctx = new ExecutionContext();
        ctx.setStep(conversionStep);
        ctx.setMonitored(true);
        commandCtx = cloneContext().withoutCompensationContext().withExecutionContext(ctx).withoutLock();
    } catch (RuntimeException e) {
        log.error("Failed to create command context of converting VM '{}': {}", 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) Step(org.ovirt.engine.core.common.job.Step)

Example 2 with CommandContext

use of org.ovirt.engine.core.bll.context.CommandContext in project ovirt-engine by oVirt.

the class VdsNotRespondingTreatmentCommand method setStoragePoolNonOperational.

private void setStoragePoolNonOperational() {
    log.info("Fence failed on vds '{}' which is spm of pool '{}' - moving pool to non operational", getVds().getName(), getVds().getStoragePoolId());
    CommandContext commandContext = getContext().clone();
    // CommandContext clone is 'shallow' and does not clone the internal ExecutionContext.
    // So ExecutionContext is cloned here manually to prevent a bug (BZ1145099).
    commandContext.withExecutionContext(new ExecutionContext(commandContext.getExecutionContext()));
    runInternalAction(ActionType.SetStoragePoolStatus, new SetStoragePoolStatusParameters(getVds().getStoragePoolId(), StoragePoolStatus.NotOperational, AuditLogType.SYSTEM_CHANGE_STORAGE_POOL_STATUS_NO_HOST_FOR_SPM), commandContext);
}
Also used : SetStoragePoolStatusParameters(org.ovirt.engine.core.common.action.SetStoragePoolStatusParameters) ExecutionContext(org.ovirt.engine.core.bll.job.ExecutionContext) CommandContext(org.ovirt.engine.core.bll.context.CommandContext)

Example 3 with CommandContext

use of org.ovirt.engine.core.bll.context.CommandContext in project ovirt-engine by oVirt.

the class LiveMigrateDiskCommand method createStepsContext.

private CommandContext createStepsContext(StepEnum step) {
    Step addedStep = executionHandler.addSubStep(getExecutionContext(), getExecutionContext().getJob().getStep(StepEnum.EXECUTING), step, ExecutionMessageDirector.resolveStepMessage(step, Collections.emptyMap()));
    ExecutionContext ctx = new ExecutionContext();
    ctx.setStep(addedStep);
    ctx.setMonitored(true);
    CommandContext commandCtx = ExecutionHandler.createDefaultContextForTasks(getContext(), null).withExecutionContext(ctx);
    return commandCtx;
}
Also used : ExecutionContext(org.ovirt.engine.core.bll.job.ExecutionContext) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) Step(org.ovirt.engine.core.common.job.Step)

Example 4 with CommandContext

use of org.ovirt.engine.core.bll.context.CommandContext 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;
}
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) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 5 with CommandContext

use of org.ovirt.engine.core.bll.context.CommandContext 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)

Aggregations

CommandContext (org.ovirt.engine.core.bll.context.CommandContext)15 ExecutionContext (org.ovirt.engine.core.bll.job.ExecutionContext)9 EngineContext (org.ovirt.engine.core.bll.context.EngineContext)5 Step (org.ovirt.engine.core.common.job.Step)5 HashMap (java.util.HashMap)3 EngineLock (org.ovirt.engine.core.utils.lock.EngineLock)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 CompensationContext (org.ovirt.engine.core.bll.context.CompensationContext)1 ManageNetworksParametersBuilder (org.ovirt.engine.core.bll.network.ManageNetworksParametersBuilder)1 ManageNetworksParametersBuilderFactory (org.ovirt.engine.core.bll.network.ManageNetworksParametersBuilderFactory)1 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)1