Search in sources :

Example 76 with ActionReturnValue

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

the class UpdateVmPoolCommand method updatePoolVms.

private void updatePoolVms(List<VM> vmsInPool) {
    // new latest value
    boolean isUpdatedPoolLatest = getParameters().getVmStaticData().isUseLatestVersion();
    vmTemplateHandler.lockVmTemplateInTransaction(getParameters().getVmStaticData().getVmtGuid(), getCompensationContext());
    for (VM vm : vmsInPool) {
        VmManagementParametersBase updateParams = new VmManagementParametersBase(vm);
        updateParams.getVmStaticData().setUseLatestVersion(isUpdatedPoolLatest);
        if (!isUpdatedPoolLatest) {
            updateParams.getVmStaticData().setVmtGuid(getParameters().getVmStaticData().getVmtGuid());
        }
        ActionReturnValue result = runInternalActionWithTasksContext(ActionType.UpdateVm, updateParams, getLock());
        getTaskIdList().addAll(result.getInternalVdsmTaskIdList());
        setSucceeded(getSucceeded() && result.getSucceeded());
    }
    vmTemplateHandler.unlockVmTemplate(getParameters().getVmStaticData().getVmtGuid());
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) VM(org.ovirt.engine.core.common.businessentities.VM) VmManagementParametersBase(org.ovirt.engine.core.common.action.VmManagementParametersBase)

Example 77 with ActionReturnValue

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

the class UpdateVmVersionCommand method executeVmCommand.

@Override
protected void executeVmCommand() {
    // load vm init from db
    vmHandler.updateVmInitFromDB(getVmTemplate(), false);
    if (!VmHandler.copyData(getVmTemplate(), getVm().getStaticData())) {
        return;
    }
    getParameters().setPreviousDiskOperatorAuthzPrincipalDbId(getIdOfDiskOperator());
    getParameters().setVmStaticData(getVm().getStaticData());
    if (getParameters().getUseLatestVersion() != null) {
        getParameters().getVmStaticData().setUseLatestVersion(getParameters().getUseLatestVersion());
    }
    if (getVm().getVmPoolId() != null) {
        getParameters().setVmPoolId(getVm().getVmPoolId());
        ActionReturnValue result = runInternalActionWithTasksContext(ActionType.RemoveVmFromPool, buildRemoveVmFromPoolParameters(), getLock());
        if (!result.getSucceeded()) {
            log.error("Could not detach vm '{}' ({}) from vm-pool '{}'.", getVm().getName(), getVmId(), getVm().getVmPoolName());
            return;
        }
    }
    ActionReturnValue result = runInternalActionWithTasksContext(ActionType.RemoveVm, buildRemoveVmParameters(), getLock());
    if (result.getSucceeded()) {
        if (result.getHasAsyncTasks()) {
            getReturnValue().getVdsmTaskIdList().addAll(result.getInternalVdsmTaskIdList());
        } else {
            endVmCommand();
        }
        setSucceeded(true);
    }
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue)

Example 78 with ActionReturnValue

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

the class UpdateClusterCommand method updateTemplates.

private boolean updateTemplates() {
    for (VmTemplate template : templatesLockedForUpdate) {
        // the object was loaded in before command execution started and thus the value may be outdated
        template.setClusterCompatibilityVersion(getCluster().getCompatibilityVersion());
        UpdateVmTemplateParameters parameters = new UpdateVmTemplateParameters(template);
        // Locking by UpdateVmTemplate is disabled since templates are already locked in #getExclusiveLocks method.
        parameters.setLockProperties(LockProperties.create(LockProperties.Scope.None));
        parameters.setClusterLevelChangeFromVersion(oldCluster.getCompatibilityVersion());
        updateRngDeviceIfNecessary(template.getId(), template.getCustomCompatibilityVersion(), parameters);
        updateResumeBehavior(template);
        final ActionReturnValue result = runInternalAction(ActionType.UpdateVmTemplate, parameters, cloneContextAndDetachFromParent());
        if (!result.getSucceeded()) {
            List<String> params = new ArrayList<>();
            params.add("$action Update");
            params.add("$type Template");
            params.add(parseErrorMessage(result.getValidationMessages()));
            List<String> messages = Backend.getInstance().getErrorsTranslator().translateErrorText(params);
            failedUpgradeEntities.put(template.getName(), getFailedMessage(messages));
        }
    }
    return true;
}
Also used : VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) UpdateVmTemplateParameters(org.ovirt.engine.core.common.action.UpdateVmTemplateParameters) ArrayList(java.util.ArrayList)

Example 79 with ActionReturnValue

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

the class UpdateClusterCommand method executeCommand.

@Override
protected void executeCommand() {
    Guid newMacPoolId = getNewMacPoolId();
    moveMacs.migrateMacsToAnotherMacPool(oldCluster, newMacPoolId, getContext());
    getCluster().setArchitecture(getArchitecture());
    setDefaultSwitchTypeIfNeeded();
    setDefaultFirewallTypeIfNeeded();
    // TODO: This code should be revisited and proper compensation logic should be introduced here
    checkMaxMemoryOverCommitValue();
    if (!Objects.equals(oldCluster.getCompatibilityVersion(), getParameters().getCluster().getCompatibilityVersion())) {
        String emulatedMachine = null;
        // pick an UP host randomly - all should have latest compat version already if we passed validate.
        for (VDS vds : allForCluster) {
            if (vds.getStatus() == VDSStatus.Up) {
                emulatedMachine = getEmulatedMachineOfHostInCluster(vds);
                break;
            }
        }
        if (emulatedMachine == null) {
            getParameters().getCluster().setDetectEmulatedMachine(true);
        } else {
            getParameters().getCluster().setEmulatedMachine(emulatedMachine);
        }
    } else if (oldCluster.getArchitecture() != getCluster().getArchitecture()) {
        // if architecture was changed, emulated machines must be updated when adding new host.
        // At this point the cluster is empty and have changed CPU name
        getParameters().getCluster().setDetectEmulatedMachine(true);
        getParameters().getCluster().setEmulatedMachine(null);
    }
    if (getParameters().isForceResetEmulatedMachine()) {
        getParameters().getCluster().setDetectEmulatedMachine(true);
    }
    boolean isKsmPolicyChanged = (getCluster().isKsmMergeAcrossNumaNodes() != getPrevCluster().isKsmMergeAcrossNumaNodes()) || (getCluster().isEnableKsm() != getPrevCluster().isEnableKsm());
    clusterDao.update(getParameters().getCluster());
    addOrUpdateAddtionalClusterFeatures();
    if (!oldCluster.supportsGlusterService() && getCluster().supportsGlusterService()) {
        // update gluster parameters on all hosts
        updateGlusterHosts();
    }
    if (isAddedToStoragePool) {
        for (VDS vds : allForCluster) {
            VdsActionParameters parameters = new VdsActionParameters();
            parameters.setVdsId(vds.getId());
            ActionReturnValue addVdsSpmIdReturn = runInternalAction(ActionType.AddVdsSpmId, parameters, cloneContextAndDetachFromParent());
            if (!addVdsSpmIdReturn.getSucceeded()) {
                setSucceeded(false);
                getReturnValue().setFault(addVdsSpmIdReturn.getFault());
                return;
            }
        }
        final NetworkCluster managementNetworkCluster = createManagementNetworkCluster();
        networkClusterDao.save(managementNetworkCluster);
    }
    alertIfFencingDisabled();
    if (isKsmPolicyChanged) {
        momPolicyUpdatedEvent.fire(getCluster());
    }
    updateDefaultNetworkProvider();
    // Call UpdateVmCommand on all VMs in the cluster to update defaults (i.e. DisplayType)
    updateVms();
    updateTemplates();
    if (getCluster().getFirewallType() != getPrevCluster().getFirewallType()) {
        markHostsForReinstall();
    }
    if (!failedUpgradeEntities.isEmpty()) {
        logFailedUpgrades();
        failValidation(Arrays.asList(EngineMessage.CLUSTER_CANNOT_UPDATE_CLUSTER_FAILED_TO_UPDATE_VMS), "$VmList " + StringUtils.join(failedUpgradeEntities.keySet(), ", "));
        getReturnValue().setValid(false);
        setSucceeded(false);
        return;
    }
    if (!Objects.equals(oldCluster.getCompatibilityVersion(), getCluster().getCompatibilityVersion())) {
        vmStaticDao.getAllByCluster(getCluster().getId()).forEach(this::updateClusterVersionInManager);
    }
    setSucceeded(true);
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) VdsActionParameters(org.ovirt.engine.core.common.action.VdsActionParameters) NetworkCluster(org.ovirt.engine.core.common.businessentities.network.NetworkCluster) Guid(org.ovirt.engine.core.compat.Guid)

Example 80 with ActionReturnValue

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

the class RemoveVmPoolCommand method removeVm.

private boolean removeVm(VM vm) {
    RemoveVmFromPoolParameters removeVmFromPoolParameters = new RemoveVmFromPoolParameters(vm.getId(), false, false);
    removeVmFromPoolParameters.setTransactionScopeOption(TransactionScopeOption.Suppress);
    ActionReturnValue result = runInternalActionWithTasksContext(ActionType.RemoveVmFromPool, removeVmFromPoolParameters);
    if (!result.getSucceeded()) {
        return false;
    }
    result = runInternalAction(ActionType.RemoveVm, new RemoveVmParameters(vm.getId(), false), createRemoveVmStepContext(vm));
    if (!result.getSucceeded()) {
        return false;
    }
    vmsRemoved.add(vm.getId());
    return true;
}
Also used : RemoveVmFromPoolParameters(org.ovirt.engine.core.common.action.RemoveVmFromPoolParameters) RemoveVmParameters(org.ovirt.engine.core.common.action.RemoveVmParameters) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue)

Aggregations

ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)293 ArrayList (java.util.ArrayList)57 Guid (org.ovirt.engine.core.compat.Guid)55 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)50 Test (org.junit.Test)37 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)27 ActionType (org.ovirt.engine.core.common.action.ActionType)26 EngineException (org.ovirt.engine.core.common.errors.EngineException)25 VDS (org.ovirt.engine.core.common.businessentities.VDS)23 HashSet (java.util.HashSet)16 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)15 ExecutionException (java.util.concurrent.ExecutionException)13 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)13 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)13 StorageServerConnectionParametersBase (org.ovirt.engine.core.common.action.StorageServerConnectionParametersBase)12 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)12 List (java.util.List)11 ChangeVDSClusterParameters (org.ovirt.engine.core.common.action.ChangeVDSClusterParameters)11 VM (org.ovirt.engine.core.common.businessentities.VM)11 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)11