Search in sources :

Example 1 with InstallVdsParameters

use of org.ovirt.engine.core.common.action.hostdeploy.InstallVdsParameters 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 2 with InstallVdsParameters

use of org.ovirt.engine.core.common.action.hostdeploy.InstallVdsParameters in project ovirt-engine by oVirt.

the class UpdateVdsCommand method executeCommand.

@Override
protected void executeCommand() {
    getParameters().getVdsStaticData().setReinstallRequired(shouldVdsBeReinstalled());
    updateVdsData();
    if (needToUpdateVdsBroker()) {
        initializeVds();
    }
    if (getParameters().isInstallHost()) {
        InstallVdsParameters tempVar = new InstallVdsParameters(getVdsId(), getParameters().getPassword());
        tempVar.setIsReinstallOrUpgrade(getParameters().isReinstallOrUpgrade());
        tempVar.setoVirtIsoFile(getParameters().getoVirtIsoFile());
        if (vdsDynamicDao.get(getVdsId()).getStatus() == VDSStatus.InstallingOS) {
            // TODO: remove hack when reinstall api will provider override-firewall parameter.
            // https://bugzilla.redhat.com/show_bug.cgi?id=1177126 - for now we override firewall
            // configurations on each deploy for provisioned host to avoid wrong deployment.
            tempVar.setOverrideFirewall(true);
        } else {
            tempVar.setOverrideFirewall(getParameters().getOverrideFirewall());
        }
        tempVar.setOverrideFirewall(getParameters().getOverrideFirewall());
        tempVar.setActivateHost(getParameters().getActivateHost());
        tempVar.setNetworkProviderId(getParameters().getVdsStaticData().getOpenstackNetworkProviderId());
        tempVar.setNetworkMappings(getParameters().getNetworkMappings());
        tempVar.setAuthMethod(getParameters().getAuthMethod());
        if (getParameters().getHostedEngineDeployConfiguration() != null) {
            tempVar.setHostedEngineConfiguration(hostedEngineHelper.createVdsDeployParams(getVdsId(), getParameters().getHostedEngineDeployConfiguration().getDeployAction()));
        }
        List<ActionReturnValue> resultList = runInternalMultipleActions(actionType, new ArrayList<>(Arrays.asList(tempVar)), ExecutionHandler.createInternalJobContext().getExecutionContext());
        // status, therefore needed to fail the command to revert the status.
        if (!resultList.isEmpty()) {
            ActionReturnValue actionReturnValue = resultList.get(0);
            if (actionReturnValue != null && !actionReturnValue.isValid()) {
                List<String> validationMessages = actionReturnValue.getValidationMessages();
                if (!validationMessages.isEmpty()) {
                    // add can do action messages to return value so error messages
                    // are returned back to the client
                    getReturnValue().getValidationMessages().addAll(validationMessages);
                    log.error("Installation/upgrade of Host '{}', '{}' failed: {}", getVdsId(), getVdsName(), StringUtils.join(Backend.getInstance().getErrorsTranslator().translateErrorText(validationMessages), ","));
                }
                // set can do action to false so can do action messages are
                // returned back to client
                getReturnValue().setValid(false);
                setSucceeded(false);
                // add old vds dynamic data to compensation context. This
                // way the status will revert back to what it was before
                // starting installation process
                getCompensationContext().snapshotEntityStatus(oldHost.getDynamicData());
                getCompensationContext().stateChanged();
                return;
            }
        }
    }
    // set clusters network to be operational (if needed)
    if (oldHost.getStatus() == VDSStatus.Up) {
        List<Network> networks = networkDao.getAllForCluster(oldHost.getClusterId());
        networkClusterHelper.setStatus(oldHost.getClusterId(), networks);
    }
    alertIfPowerManagementNotConfigured(getParameters().getVdsStaticData());
    testVdsPowerManagementStatus(getParameters().getVdsStaticData());
    checkKdumpIntegrationStatus();
    updateAffinityLabels();
    setSucceeded(true);
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) InstallVdsParameters(org.ovirt.engine.core.common.action.hostdeploy.InstallVdsParameters) Network(org.ovirt.engine.core.common.businessentities.network.Network)

Example 3 with InstallVdsParameters

use of org.ovirt.engine.core.common.action.hostdeploy.InstallVdsParameters in project ovirt-engine by oVirt.

the class UpgradeHostInternalCommand method executeCommand.

@Override
protected void executeCommand() {
    getCompensationContext().snapshotEntityStatus(getVds().getDynamicData(), getParameters().getInitialStatus());
    getCompensationContext().stateChanged();
    VDSType vdsType = getVds().getVdsType();
    if (vdsType == VDSType.VDS || vdsType == VDSType.oVirtNode) {
        try {
            setVdsStatus(VDSStatus.Installing);
            upgradeManager.update(getVds());
            if (vdsType == VDSType.oVirtNode || getParameters().isReboot()) {
                VdsActionParameters params = new VdsActionParameters(getVds().getId());
                params.setPrevVdsStatus(getParameters().getInitialStatus());
                ActionReturnValue returnValue = runInternalAction(ActionType.SshHostReboot, params, ExecutionHandler.createInternalJobContext());
                if (!returnValue.getSucceeded()) {
                    setVdsStatus(VDSStatus.InstallFailed);
                    log.error("Engine failed to restart via ssh host '{}' ('{}') after upgrade", getVds().getName(), getVds().getId());
                    return;
                }
            } else {
                // letting the host a chance to recover from restarting the VDSM service after the upgrade
                if (!new HostConnectivityChecker().check(getVds())) {
                    log.warn("Engine failed to communicate with VDSM agent on host '{}' with address '{}' ('{}') " + "after upgrade", getVds().getName(), getVds().getHostName(), getVds().getId());
                }
            }
        } catch (Exception e) {
            setVdsStatus(VDSStatus.InstallFailed);
            return;
        }
    } else if (getVds().isOvirtVintageNode()) {
        InstallVdsParameters parameters = new InstallVdsParameters(getVdsId());
        parameters.setIsReinstallOrUpgrade(true);
        parameters.setoVirtIsoFile(getParameters().getoVirtIsoFile());
        parameters.setActivateHost(getParameters().getInitialStatus() == VDSStatus.Up);
        ActionReturnValue result = runInternalAction(ActionType.UpgradeOvirtNodeInternal, parameters);
        if (!result.getSucceeded()) {
            setVdsStatus(VDSStatus.InstallFailed);
            propagateFailure(result);
            return;
        }
    }
    try {
        updateHostStatusAfterSuccessfulUpgrade();
        setSucceeded(true);
    } catch (Exception e) {
        log.error("Failed to set new status for host '{}' after upgrade has ended.", getVdsName());
        log.error("Exception", e);
        setVdsStatus(VDSStatus.InstallFailed);
    }
}
Also used : VDSType(org.ovirt.engine.core.common.businessentities.VDSType) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) InstallVdsParameters(org.ovirt.engine.core.common.action.hostdeploy.InstallVdsParameters) HostConnectivityChecker(org.ovirt.engine.core.bll.host.HostConnectivityChecker) VdsActionParameters(org.ovirt.engine.core.common.action.VdsActionParameters)

Example 4 with InstallVdsParameters

use of org.ovirt.engine.core.common.action.hostdeploy.InstallVdsParameters in project ovirt-engine by oVirt.

the class UpgradeOvirtNodeInternalCommandTest method createParameters.

private static InstallVdsParameters createParameters() {
    InstallVdsParameters param = new InstallVdsParameters(Guid.newGuid());
    param.setIsReinstallOrUpgrade(true);
    return param;
}
Also used : InstallVdsParameters(org.ovirt.engine.core.common.action.hostdeploy.InstallVdsParameters)

Example 5 with InstallVdsParameters

use of org.ovirt.engine.core.common.action.hostdeploy.InstallVdsParameters in project ovirt-engine by oVirt.

the class InstallVdsInternalCommandTest method createParameters.

private static InstallVdsParameters createParameters() {
    InstallVdsParameters param = new InstallVdsParameters(Guid.newGuid());
    param.setIsReinstallOrUpgrade(true);
    return param;
}
Also used : InstallVdsParameters(org.ovirt.engine.core.common.action.hostdeploy.InstallVdsParameters)

Aggregations

InstallVdsParameters (org.ovirt.engine.core.common.action.hostdeploy.InstallVdsParameters)5 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)3 VdsActionParameters (org.ovirt.engine.core.common.action.VdsActionParameters)2 HashMap (java.util.HashMap)1 HostConnectivityChecker (org.ovirt.engine.core.bll.host.HostConnectivityChecker)1 HostProviderProxy (org.ovirt.engine.core.bll.host.provider.HostProviderProxy)1 ExecutionContext (org.ovirt.engine.core.bll.job.ExecutionContext)1 AddVdsActionParameters (org.ovirt.engine.core.common.action.hostdeploy.AddVdsActionParameters)1 VDSType (org.ovirt.engine.core.common.businessentities.VDSType)1 Network (org.ovirt.engine.core.common.businessentities.network.Network)1 EngineException (org.ovirt.engine.core.common.errors.EngineException)1 Step (org.ovirt.engine.core.common.job.Step)1 Guid (org.ovirt.engine.core.compat.Guid)1