Search in sources :

Example 6 with CommandContext

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

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

the class VdsEventListener method vdsUpEvent.

@Override
public boolean vdsUpEvent(final VDS vds) {
    HostStoragePoolParametersBase params = new HostStoragePoolParametersBase(vds);
    CommandContext commandContext = new CommandContext(new EngineContext()).withoutExecutionContext();
    commandContext.getExecutionContext().setJobRequired(true);
    boolean isSucceeded = backend.runInternalAction(ActionType.InitVdsOnUp, params, commandContext).getSucceeded();
    if (isSucceeded) {
        ThreadPoolUtil.execute(() -> {
            try {
                // migrate vms that its their default vds and failback
                // is on
                List<VmStatic> vmsToMigrate = vmStaticDao.getAllWithFailbackByVds(vds.getId());
                if (!vmsToMigrate.isEmpty()) {
                    CommandContext ctx = new CommandContext(new EngineContext());
                    ctx.getExecutionContext().setMonitored(true);
                    backend.runInternalMultipleActions(ActionType.MigrateVmToServer, new ArrayList<>(createMigrateVmToServerParametersList(vmsToMigrate, vds, null)), ctx);
                }
            } catch (RuntimeException e) {
                log.error("Failed to initialize Vds on up: {}", e.getMessage());
                log.error("Exception", e);
            }
        });
    }
    return isSucceeded;
}
Also used : HostStoragePoolParametersBase(org.ovirt.engine.core.common.action.HostStoragePoolParametersBase) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) EngineContext(org.ovirt.engine.core.bll.context.EngineContext) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic)

Example 8 with CommandContext

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

Example 9 with CommandContext

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

the class CommandsRepository method retrieveCommand.

private CommandBase<?> retrieveCommand(CommandEntity cmdEntity, CommandContext cmdContext) {
    CommandBase<?> command = null;
    if (cmdEntity != null) {
        if (cmdContext == null) {
            cmdContext = new CommandContext(new EngineContext()).withExecutionContext(new ExecutionContext());
        }
        command = CommandsFactory.createCommand(cmdEntity.getCommandType(), cmdEntity.getCommandParameters(), cmdContext);
        if (command != null) {
            command.setCommandStatus(cmdEntity.getCommandStatus(), false);
            command.setCommandData(cmdEntity.getData());
            command.setReturnValue(cmdEntity.getReturnValue());
            if (!Guid.isNullOrEmpty(cmdEntity.getParentCommandId()) && !cmdEntity.getParentCommandId().equals(cmdEntity.getId()) && command.getParameters().getParentParameters() == null) {
                CommandBase<?> parentCommand = retrieveCommand(cmdEntity.getParentCommandId());
                if (parentCommand != null) {
                    command.getParameters().setParentParameters(parentCommand.getParameters());
                }
            }
        }
    }
    return command;
}
Also used : ExecutionContext(org.ovirt.engine.core.bll.job.ExecutionContext) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) EngineContext(org.ovirt.engine.core.bll.context.EngineContext)

Example 10 with CommandContext

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

the class InitVdsOnUpCommand method initializeStorage.

private boolean initializeStorage() {
    boolean returnValue = false;
    // connect any storage
    if (getStoragePool() == null || StoragePoolStatus.Uninitialized == getStoragePool().getStatus() || StoragePoolStatus.Maintenance == getStoragePool().getStatus()) {
        returnValue = true;
        connectPoolSucceeded = true;
    } else {
        ConnectHostToStoragePoolServersParameters params = new ConnectHostToStoragePoolServersParameters(getStoragePool(), getVds());
        CommandContext ctx = cloneContext();
        ctx.getExecutionContext().setJobRequired(false);
        runInternalAction(ActionType.ConnectHostToStoragePoolServers, params, ctx);
        EventResult connectResult = connectHostToPool();
        if (connectResult != null) {
            returnValue = connectResult.isSuccess();
            problematicDomains = (List<StorageDomainStatic>) connectResult.getResultData();
        }
        connectPoolSucceeded = returnValue;
    }
    return returnValue;
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) ConnectHostToStoragePoolServersParameters(org.ovirt.engine.core.common.action.ConnectHostToStoragePoolServersParameters) EventResult(org.ovirt.engine.core.common.eventqueue.EventResult) CommandContext(org.ovirt.engine.core.bll.context.CommandContext)

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