Search in sources :

Example 1 with DisconnectStoragePoolVDSCommandParameters

use of org.ovirt.engine.core.common.vdscommands.DisconnectStoragePoolVDSCommandParameters in project ovirt-engine by oVirt.

the class DeactivateStorageDomainCommand method executeCommand.

@Override
protected void executeCommand() {
    if (isCinderStorageDomain()) {
        deactivateCinderStorageDomain();
        return;
    }
    final StoragePoolIsoMap map = storagePoolIsoMapDao.get(new StoragePoolIsoMapId(getParameters().getStorageDomainId(), getParameters().getStoragePoolId()));
    map.setStatus(StorageDomainStatus.Unknown);
    changeStorageDomainStatusInTransaction(map, getParameters().isInactive() ? StorageDomainStatus.Locked : StorageDomainStatus.PreparingForMaintenance);
    final StorageDomain newMaster;
    if (getStorageDomain().getStorageDomainType() == StorageDomainType.Master) {
        newMaster = electNewMaster();
        isLastMaster = proceedStorageDomainTreatmentByDomainType(newMaster, true);
    } else {
        newMaster = null;
        isLastMaster = false;
    }
    final Guid newMasterId = newMaster != null ? newMaster.getId() : Guid.Empty;
    if (isLastMaster) {
        executeInNewTransaction(() -> {
            getCompensationContext().snapshotEntityStatus(getStoragePool());
            getStoragePool().setStatus(StoragePoolStatus.Maintenance);
            storagePoolDao.updateStatus(getStoragePool().getId(), getStoragePool().getStatus());
            getCompensationContext().stateChanged();
            return null;
        });
        StoragePoolStatusHandler.poolStatusChanged(getStoragePool().getId(), getStoragePool().getStatus());
        getStorageDomain().getStorageDynamicData().setAvailableDiskSize(null);
        getStorageDomain().getStorageDynamicData().setUsedDiskSize(null);
    }
    if (!getParameters().isInactive()) {
        runVdsCommand(VDSCommandType.DeactivateStorageDomain, new DeactivateStorageDomainVDSCommandParameters(getStoragePool().getId(), getStorageDomain().getId(), newMasterId, getStoragePool().getMasterDomainVersion()));
    }
    freeLock();
    VDS spm = null;
    if (getStoragePool().getSpmVdsId() != null) {
        spm = vdsDao.get(getStoragePool().getSpmVdsId());
    }
    if (isLastMaster) {
        if (spm != null) {
            final VDSReturnValue stopSpmReturnValue = runVdsCommand(VDSCommandType.SpmStopOnIrs, new SpmStopOnIrsVDSCommandParameters(getStoragePool().getId()));
            if (!stopSpmReturnValue.getSucceeded()) {
                // no need to continue because DisconnectStoragePool will
                // fail if host is SPM
                log.error("Aborting execution due to failure to stop SPM");
                setSucceeded(false);
                return;
            }
            runVdsCommand(VDSCommandType.DisconnectStoragePool, new DisconnectStoragePoolVDSCommandParameters(spm.getId(), getStoragePool().getId(), spm.getVdsSpmId()));
        }
        runSynchronizeOperation(new DisconnectStoragePoolAsyncOperationFactory());
    }
    if (!getParameters().isInactive()) {
        getEventQueue().submitEventSync(new Event(getParameters().getStoragePoolId(), getParameters().getStorageDomainId(), null, EventType.POOLREFRESH, ""), () -> {
            runSynchronizeOperation(new AfterDeactivateSingleAsyncOperationFactory(), isLastMaster, newMasterId);
            return null;
        });
        if (spm != null) {
            getStorageHelper(getStorageDomain()).disconnectStorageFromDomainByVdsId(getStorageDomain(), spm.getId());
        }
    }
    executeInNewTransaction(() -> {
        if (getParameters().isInactive()) {
            map.setStatus(StorageDomainStatus.Inactive);
        } else if (isLastMaster) {
            map.setStatus(StorageDomainStatus.Maintenance);
        } else {
            log.info("Domain '{}' will remain in '{}' status until deactivated on all hosts", getStorageDomain().getId(), map.getStatus());
        }
        storagePoolIsoMapDao.updateStatus(map.getId(), map.getStatus());
        if (newMaster != null) {
            StoragePoolIsoMap mapOfNewMaster = newMaster.getStoragePoolIsoMapData();
            mapOfNewMaster.setStatus(StorageDomainStatus.Active);
            storagePoolIsoMapDao.updateStatus(mapOfNewMaster.getId(), mapOfNewMaster.getStatus());
        }
        return null;
    });
    if (!getParameters().isSkipChecks()) {
        notifyAsyncTasks();
    }
    setSucceeded(true);
}
Also used : DeactivateStorageDomainVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.DeactivateStorageDomainVDSCommandParameters) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) SpmStopOnIrsVDSCommandParameters(org.ovirt.engine.core.vdsbroker.irsbroker.SpmStopOnIrsVDSCommandParameters) VDS(org.ovirt.engine.core.common.businessentities.VDS) StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap) StoragePoolIsoMapId(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId) DisconnectStoragePoolAsyncOperationFactory(org.ovirt.engine.core.bll.storage.pool.DisconnectStoragePoolAsyncOperationFactory) Event(org.ovirt.engine.core.common.eventqueue.Event) Guid(org.ovirt.engine.core.compat.Guid) DisconnectStoragePoolVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.DisconnectStoragePoolVDSCommandParameters) AfterDeactivateSingleAsyncOperationFactory(org.ovirt.engine.core.bll.storage.pool.AfterDeactivateSingleAsyncOperationFactory) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Example 2 with DisconnectStoragePoolVDSCommandParameters

use of org.ovirt.engine.core.common.vdscommands.DisconnectStoragePoolVDSCommandParameters in project ovirt-engine by oVirt.

the class VdsEventListener method processStorageOnVdsInactive.

private void processStorageOnVdsInactive(final VDS vds) {
    // anymore.
    if (!Guid.Empty.equals(vds.getStoragePoolId())) {
        // when vds is being moved to maintenance, this is the part in which we disconnect it from the pool
        // and the storage server. it should be synced with the host autorecovery mechanism to try to avoid
        // leaving the host with storage/pool connection when it's on maintenance.
        EngineLock lock = new EngineLock(Collections.singletonMap(vds.getId().toString(), new Pair<>(LockingGroup.VDS_POOL_AND_STORAGE_CONNECTIONS.toString(), EngineMessage.ACTION_TYPE_FAILED_OBJECT_LOCKED.toString())), null);
        try {
            lockManager.acquireLockWait(lock);
            clearDomainCache(vds);
            StoragePool storage_pool = storagePoolDao.get(vds.getStoragePoolId());
            if (StoragePoolStatus.Uninitialized != storage_pool.getStatus()) {
                vdsBroker.runVdsCommand(VDSCommandType.DisconnectStoragePool, new DisconnectStoragePoolVDSCommandParameters(vds.getId(), vds.getStoragePoolId(), vds.getVdsSpmId()));
                HostStoragePoolParametersBase params = new HostStoragePoolParametersBase(storage_pool, vds);
                backend.runInternalAction(ActionType.DisconnectHostFromStoragePoolServers, params);
            }
        } finally {
            lockManager.releaseLock(lock);
        }
    }
}
Also used : HostStoragePoolParametersBase(org.ovirt.engine.core.common.action.HostStoragePoolParametersBase) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) DisconnectStoragePoolVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.DisconnectStoragePoolVDSCommandParameters) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 3 with DisconnectStoragePoolVDSCommandParameters

use of org.ovirt.engine.core.common.vdscommands.DisconnectStoragePoolVDSCommandParameters in project ovirt-engine by oVirt.

the class IrsProxy method getHostFromVds.

private String getHostFromVds() {
    String returnValue = null;
    Guid curVdsId = (currentVdsId != null) ? currentVdsId : Guid.Empty;
    StoragePool storagePool = storagePoolDao.get(storagePoolId);
    if (storagePool == null) {
        log.info("hostFromVds::Finished elect spm, storage pool '{}' was removed", storagePoolId);
        return null;
    }
    List<VDS> prioritizedVdsInPool = getPrioritizedVdsInPool();
    currentVdsId = null;
    // If VDS is in initialize status, wait for it to be up (or until
    // configurable timeout is reached)
    waitForVdsIfIsInitializing(curVdsId);
    // update pool status to problematic while selecting spm
    StoragePoolStatus prevStatus = storagePool.getStatus();
    if (prevStatus != StoragePoolStatus.NonResponsive) {
        try {
            getEventListener().storagePoolStatusChange(storagePoolId, StoragePoolStatus.NonResponsive, AuditLogType.SYSTEM_CHANGE_STORAGE_POOL_STATUS_PROBLEMATIC_SEARCHING_NEW_SPM, EngineError.ENGINE, TransactionScopeOption.RequiresNew);
        } catch (RuntimeException ex) {
            throw new IRSStoragePoolStatusException(ex);
        }
    }
    VDS selectedVds = null;
    SpmStatusResult spmStatus = null;
    if (prioritizedVdsInPool != null && prioritizedVdsInPool.size() > 0) {
        selectedVds = prioritizedVdsInPool.get(0);
    } else if (!Guid.Empty.equals(curVdsId) && !getTriedVdssList().contains(curVdsId)) {
        selectedVds = vdsDao.get(curVdsId);
        if (selectedVds.getStatus() != VDSStatus.Up || selectedVds.getVdsSpmPriority() == BusinessEntitiesDefinitions.HOST_MIN_SPM_PRIORITY) {
            selectedVds = null;
        }
    }
    if (selectedVds != null) {
        // Stores origin host id in case and will be needed to disconnect from storage pool
        Guid selectedVdsId = selectedVds.getId();
        Integer selectedVdsSpmId = selectedVds.getVdsSpmId();
        triedVdssList.add(selectedVdsId);
        currentVdsId = selectedVds.getId();
        connectStoragePool(selectedVds, storagePool);
        VDSReturnValue returnValueFromVds = resourceManager.runVdsCommand(VDSCommandType.SpmStatus, new SpmStatusVDSCommandParameters(selectedVds.getId(), storagePoolId));
        spmStatus = (SpmStatusResult) returnValueFromVds.getReturnValue();
        boolean ignoreSpmStatusResult = returnValueFromVds.getVdsError() != null && returnValueFromVds.getVdsError().getCode() == EngineError.InquireNotSupportedError;
        if (spmStatus != null || ignoreSpmStatusResult) {
            boolean performedPoolConnect = false;
            log.info("hostFromVds::selectedVds - '{}', spmStatus '{}', storage pool '{}', storage pool version '{}'", selectedVds.getName(), spmStatus != null ? spmStatus.getSpmStatus() : "unknown", storagePool.getName(), storagePool.getCompatibilityVersion());
            if (ignoreSpmStatusResult) {
                spmStatus = startSpm(storagePool, selectedVds, DEFAULT_PREV_ID, DEFAULT_LVER, DEFAULT_PREV_ID);
            } else {
                if (spmStatus.getSpmStatus() == SpmStatus.Unknown_Pool) {
                    connectStoragePool(selectedVds, storagePool);
                    performedPoolConnect = true;
                    // refresh spmStatus result
                    spmStatus = (SpmStatusResult) resourceManager.runVdsCommand(VDSCommandType.SpmStatus, new SpmStatusVDSCommandParameters(selectedVds.getId(), storagePoolId)).getReturnValue();
                    log.info("hostFromVds::Connected host to pool - selectedVds - {}, spmStatus {}, storage pool {}", selectedVds.getName(), spmStatus.getSpmStatus(), storagePool.getName());
                }
                RefObject<VDS> tempRefObject = new RefObject<>(selectedVds);
                spmStatus = handleSpmStatusResult(curVdsId, prioritizedVdsInPool, storagePool, tempRefObject, spmStatus);
                selectedVds = tempRefObject.argvalue;
            }
            if (selectedVds != null) {
                RefObject<VDS> tempRefObject2 = new RefObject<>(selectedVds);
                RefObject<SpmStatusResult> tempRefObject3 = new RefObject<>(spmStatus);
                returnValue = handleSelectedVdsForSPM(storagePool, tempRefObject2, tempRefObject3, prevStatus);
                selectedVds = tempRefObject2.argvalue;
                spmStatus = tempRefObject3.argvalue;
            } else {
                currentVdsId = null;
            }
            if (performedPoolConnect && selectedVds == null) {
                // if could not start spm on this host and connected to
                // pool here
                // then disconnect
                resourceManager.runVdsCommand(VDSCommandType.DisconnectStoragePool, new DisconnectStoragePoolVDSCommandParameters(selectedVdsId, storagePoolId, selectedVdsSpmId));
            }
        } else {
            log.info("hostFromVds::selectedVds - '{}', spmStatus returned null!", selectedVds.getName());
            if (returnValueFromVds.getExceptionObject() instanceof IRSNoMasterDomainException) {
                throw returnValueFromVds.getExceptionObject();
            }
        }
    }
    return returnValue;
}
Also used : SpmStatusVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.SpmStatusVDSCommandParameters) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) VDS(org.ovirt.engine.core.common.businessentities.VDS) StoragePoolStatus(org.ovirt.engine.core.common.businessentities.StoragePoolStatus) Guid(org.ovirt.engine.core.compat.Guid) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) SpmStatusResult(org.ovirt.engine.core.common.businessentities.SpmStatusResult) RefObject(org.ovirt.engine.core.compat.RefObject) DisconnectStoragePoolVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.DisconnectStoragePoolVDSCommandParameters)

Example 4 with DisconnectStoragePoolVDSCommandParameters

use of org.ovirt.engine.core.common.vdscommands.DisconnectStoragePoolVDSCommandParameters in project ovirt-engine by oVirt.

the class DisconnectStoragePoolAsyncOperation method execute.

@Override
public void execute(int iterationId) {
    try {
        if (getVdss().get(iterationId).getSpmStatus() == VdsSpmStatus.None) {
            log.info("Disconnect storage pool treatment vds '{}', pool '{}'", getVdss().get(iterationId).getName(), getStoragePool().getName());
            resourceManager.runVdsCommand(VDSCommandType.DisconnectStoragePool, new DisconnectStoragePoolVDSCommandParameters(getVdss().get(iterationId).getId(), getStoragePool().getId(), getVdss().get(iterationId).getVdsSpmId()));
        }
    } catch (RuntimeException e) {
        log.error("Failed to DisconnectStoragePool storagePool. Host '{}' from storage pool '{}': {}", getVdss().get(iterationId).getName(), getStoragePool().getName(), e.getMessage());
        log.debug("Exception", e);
    }
}
Also used : DisconnectStoragePoolVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.DisconnectStoragePoolVDSCommandParameters)

Example 5 with DisconnectStoragePoolVDSCommandParameters

use of org.ovirt.engine.core.common.vdscommands.DisconnectStoragePoolVDSCommandParameters in project ovirt-engine by oVirt.

the class ReconstructMasterDomainCommand method reconstructMaster.

protected boolean reconstructMaster() {
    isLastMaster = proceedStorageDomainTreatmentByDomainType(getNewMasterStorageDomain(), false);
    // To issue a reconstructMaster you need to set the domain inactive unless the selected domain is the current master
    if (getParameters().isInactive() && !getStorageDomain().getId().equals(getNewMasterStorageDomainId())) {
        executeInNewTransaction(() -> {
            setStorageDomainStatus(StorageDomainStatus.Inactive, getCompensationContext());
            calcStoragePoolStatusByDomainsStatus();
            getCompensationContext().stateChanged();
            return null;
        });
    }
    if (isLastMaster) {
        return stopSpm();
    }
    boolean commandSucceeded = stopSpm();
    if (commandSucceeded) {
        commandSucceeded = runVdsCommand(VDSCommandType.DisconnectStoragePool, new DisconnectStoragePoolVDSCommandParameters(getVds().getId(), getStoragePool().getId(), getVds().getVdsSpmId())).getSucceeded();
    }
    if (!commandSucceeded) {
        return false;
    }
    List<StoragePoolIsoMap> domains = storagePoolIsoMapDao.getAllForStoragePool(getStoragePool().getId());
    // set to true here in case of failure in executing/getting answer from the reconstruct vds command,
    // unless we know that the command failed we assume that it succeeded (use by RecoveryStoragePool command in
    // order to avoid detaching domain that is already part of the pool in vdsm).
    setActionReturnValue(true);
    return runVdsCommand(VDSCommandType.ReconstructMaster, new ReconstructMasterVDSCommandParameters(getVds().getId(), getVds().getVdsSpmId(), getStoragePool().getId(), getStoragePool().getName(), getNewMasterStorageDomainId(), domains, getStoragePool().getMasterDomainVersion())).getSucceeded();
}
Also used : StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap) ReconstructMasterVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.ReconstructMasterVDSCommandParameters) DisconnectStoragePoolVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.DisconnectStoragePoolVDSCommandParameters)

Aggregations

DisconnectStoragePoolVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.DisconnectStoragePoolVDSCommandParameters)5 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)2 StoragePoolIsoMap (org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap)2 VDS (org.ovirt.engine.core.common.businessentities.VDS)2 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)2 Guid (org.ovirt.engine.core.compat.Guid)2 AfterDeactivateSingleAsyncOperationFactory (org.ovirt.engine.core.bll.storage.pool.AfterDeactivateSingleAsyncOperationFactory)1 DisconnectStoragePoolAsyncOperationFactory (org.ovirt.engine.core.bll.storage.pool.DisconnectStoragePoolAsyncOperationFactory)1 HostStoragePoolParametersBase (org.ovirt.engine.core.common.action.HostStoragePoolParametersBase)1 SpmStatusResult (org.ovirt.engine.core.common.businessentities.SpmStatusResult)1 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)1 StoragePoolIsoMapId (org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId)1 StoragePoolStatus (org.ovirt.engine.core.common.businessentities.StoragePoolStatus)1 Event (org.ovirt.engine.core.common.eventqueue.Event)1 Pair (org.ovirt.engine.core.common.utils.Pair)1 DeactivateStorageDomainVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.DeactivateStorageDomainVDSCommandParameters)1 ReconstructMasterVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.ReconstructMasterVDSCommandParameters)1 SpmStatusVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.SpmStatusVDSCommandParameters)1 RefObject (org.ovirt.engine.core.compat.RefObject)1 EngineLock (org.ovirt.engine.core.utils.lock.EngineLock)1