Search in sources :

Example 16 with ExecutionContext

use of org.ovirt.engine.core.bll.job.ExecutionContext 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 17 with ExecutionContext

use of org.ovirt.engine.core.bll.job.ExecutionContext in project ovirt-engine by oVirt.

the class AddVdsCommand method executeCommand.

@Override
protected void executeCommand() {
    Guid oVirtId = getParameters().getVdsForUniqueId();
    if (oVirtId != null) {
        // if fails to remove deprecated entry, we might attempt to add new oVirt host with an existing unique-id.
        if (!removeDeprecatedOvirtEntry(oVirtId)) {
            log.error("Failed to remove duplicated oVirt entry with id '{}'. Abort adding oVirt Host type", oVirtId);
            throw new EngineException(EngineError.HOST_ALREADY_EXISTS);
        }
    }
    completeOpenstackNetworkProviderId();
    TransactionSupport.executeInNewTransaction(() -> {
        addVdsStaticToDb();
        addVdsDynamicToDb();
        addVdsStatisticsToDb();
        addAffinityLabels();
        getCompensationContext().stateChanged();
        return null;
    });
    if (getParameters().isProvisioned()) {
        HostProviderProxy proxy = providerProxyFactory.create(getHostProvider());
        proxy.provisionHost(getParameters().getvds(), getParameters().getHostGroup(), getParameters().getComputeResource(), getParameters().getHostMac(), getParameters().getDiscoverName(), getParameters().getPassword(), getParameters().getDiscoverIp());
        addCustomValue("HostGroupName", getParameters().getHostGroup().getName());
        auditLogDirector.log(this, AuditLogType.VDS_PROVISION);
    }
    // set vds spm id
    if (getCluster().getStoragePoolId() != null) {
        VdsActionParameters tempVar = new VdsActionParameters(getVdsIdRef());
        tempVar.setSessionId(getParameters().getSessionId());
        tempVar.setCompensationEnabled(true);
        ActionReturnValue addVdsSpmIdReturn = runInternalAction(ActionType.AddVdsSpmId, tempVar, cloneContext().withoutLock().withoutExecutionContext());
        if (!addVdsSpmIdReturn.getSucceeded()) {
            setSucceeded(false);
            getReturnValue().setFault(addVdsSpmIdReturn.getFault());
            return;
        }
    }
    TransactionSupport.executeInNewTransaction(() -> {
        initializeVds(true);
        alertIfPowerManagementNotConfigured(getParameters().getVdsStaticData());
        testVdsPowerManagementStatus(getParameters().getVdsStaticData());
        setSucceeded(true);
        setActionReturnValue(getVdsIdRef());
        // If the installation failed, we don't want to compensate for the failure since it will remove the
        // host, but instead the host should be left in an "install failed" status.
        getCompensationContext().cleanupCompensationDataAfterSuccessfulCommand();
        return null;
    });
    // clients). they are installed as part of the approve process or automatically after provision
    if (Config.<Boolean>getValue(ConfigValues.InstallVds) && !getParameters().isPending() && !getParameters().isProvisioned()) {
        final InstallVdsParameters installVdsParameters = new InstallVdsParameters(getVdsId(), getParameters().getPassword());
        installVdsParameters.setAuthMethod(getParameters().getAuthMethod());
        installVdsParameters.setOverrideFirewall(getParameters().getOverrideFirewall());
        installVdsParameters.setActivateHost(getParameters().getActivateHost());
        installVdsParameters.setNetworkProviderId(getParameters().getVdsStaticData().getOpenstackNetworkProviderId());
        installVdsParameters.setNetworkMappings(getParameters().getNetworkMappings());
        installVdsParameters.setEnableSerialConsole(getParameters().getEnableSerialConsole());
        if (getParameters().getHostedEngineDeployConfiguration() != null) {
            Map<String, String> vdsDeployParams = hostedEngineHelper.createVdsDeployParams(getVdsId(), getParameters().getHostedEngineDeployConfiguration().getDeployAction());
            installVdsParameters.setHostedEngineConfiguration(vdsDeployParams);
        }
        Map<String, String> values = new HashMap<>();
        values.put(VdcObjectType.VDS.name().toLowerCase(), getParameters().getvds().getName());
        Step installStep = executionHandler.addSubStep(getExecutionContext(), getExecutionContext().getJob().getStep(StepEnum.EXECUTING), StepEnum.INSTALLING_HOST, ExecutionMessageDirector.resolveStepMessage(StepEnum.INSTALLING_HOST, values));
        final ExecutionContext installCtx = new ExecutionContext();
        installCtx.setJob(getExecutionContext().getJob());
        installCtx.setStep(installStep);
        installCtx.setMonitored(true);
        installCtx.setShouldEndJob(true);
        ThreadPoolUtil.execute(() -> runInternalAction(ActionType.InstallVdsInternal, installVdsParameters, cloneContextAndDetachFromParent().withExecutionContext(installCtx)));
        ExecutionHandler.setAsyncJob(getExecutionContext(), true);
    }
}
Also used : ExecutionContext(org.ovirt.engine.core.bll.job.ExecutionContext) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) HashMap(java.util.HashMap) InstallVdsParameters(org.ovirt.engine.core.common.action.hostdeploy.InstallVdsParameters) EngineException(org.ovirt.engine.core.common.errors.EngineException) VdsActionParameters(org.ovirt.engine.core.common.action.VdsActionParameters) AddVdsActionParameters(org.ovirt.engine.core.common.action.hostdeploy.AddVdsActionParameters) Guid(org.ovirt.engine.core.compat.Guid) Step(org.ovirt.engine.core.common.job.Step) HostProviderProxy(org.ovirt.engine.core.bll.host.provider.HostProviderProxy)

Example 18 with ExecutionContext

use of org.ovirt.engine.core.bll.job.ExecutionContext in project ovirt-engine by oVirt.

the class GlusterTaskUtils method endStepJob.

public void endStepJob(Step step) {
    jobRepository.updateStep(step);
    ExecutionContext finalContext = executionHandler.createFinalizingContext(step.getId());
    executionHandler.endTaskStepAndJob(finalContext, isTaskSuccess(step.getStatus()));
}
Also used : ExecutionContext(org.ovirt.engine.core.bll.job.ExecutionContext)

Example 19 with ExecutionContext

use of org.ovirt.engine.core.bll.job.ExecutionContext in project ovirt-engine by oVirt.

the class CreateGlusterVolumeCommand method createCommandContext.

/**
 * Creates command context for setting a given option on the given volume
 */
private CommandContext createCommandContext(GlusterVolumeEntity volume, GlusterVolumeOptionEntity option) {
    // Add sub-step for setting given option
    Step setOptionStep = addSubStep(StepEnum.EXECUTING, StepEnum.SETTING_GLUSTER_OPTION, getOptionValues(volume, option));
    // Create execution context for setting option
    ExecutionContext setOptionCtx = new ExecutionContext();
    setOptionCtx.setMonitored(true);
    setOptionCtx.setStep(setOptionStep);
    return cloneContext().withExecutionContext(setOptionCtx).withoutLock();
}
Also used : ExecutionContext(org.ovirt.engine.core.bll.job.ExecutionContext) Step(org.ovirt.engine.core.common.job.Step)

Example 20 with ExecutionContext

use of org.ovirt.engine.core.bll.job.ExecutionContext in project ovirt-engine by oVirt.

the class RunVmCommand method createContextForStatelessSnapshotCreation.

private CommandContext createContextForStatelessSnapshotCreation() {
    Map<String, String> values = getVmValuesForMsgResolving();
    // Creating snapshots as sub step of run stateless
    Step createSnapshotsStep = addSubStep(StepEnum.EXECUTING, StepEnum.CREATING_SNAPSHOTS, values);
    // Add the step as the first step of the new context
    ExecutionContext createSnapshotsCtx = new ExecutionContext();
    createSnapshotsCtx.setMonitored(true);
    createSnapshotsCtx.setStep(createSnapshotsStep);
    getContext().withExecutionContext(createSnapshotsCtx);
    persistCommandIfNeeded();
    return getContext().clone().withoutCompensationContext();
}
Also used : ExecutionContext(org.ovirt.engine.core.bll.job.ExecutionContext) Step(org.ovirt.engine.core.common.job.Step)

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