Search in sources :

Example 6 with SpmStatusResult

use of org.ovirt.engine.core.common.businessentities.SpmStatusResult 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 7 with SpmStatusResult

use of org.ovirt.engine.core.common.businessentities.SpmStatusResult in project ovirt-engine by oVirt.

the class IrsProxy method handleSpmStatusResult.

private SpmStatusResult handleSpmStatusResult(Guid curVdsId, List<VDS> vdsByPool, final StoragePool storagePool, RefObject<VDS> selectedVds, SpmStatusResult spmStatus) {
    if (spmStatus.getSpmStatus() == SpmStatus.Free) {
        int vdsSpmIdToFence = -1;
        boolean startSpm = true;
        if (spmStatus.getSpmId() != -1 && !wasVdsManuallyFenced(spmStatus.getSpmId())) {
            int spmId = spmStatus.getSpmId();
            Guid spmVdsId = Guid.Empty;
            VDS spmVds = null;
            if (selectedVds.argvalue.getVdsSpmId() == spmId) {
                spmVdsId = selectedVds.argvalue.getId();
            } else {
                for (VDS tempVds : vdsByPool) {
                    if (tempVds.getVdsSpmId() == spmId) {
                        log.info("Found spm host '{}', host name: '{}', according to spmId: '{}'.", tempVds.getId(), tempVds.getName(), spmId);
                        spmVds = tempVds;
                        break;
                    }
                }
                // non operational we want to find it as well
                if (spmVds == null) {
                    List<VDS> nonOperationalVds = vdsDao.getAllForStoragePoolAndStatus(storagePoolId, VDSStatus.NonOperational);
                    for (VDS tempVds : nonOperationalVds) {
                        if (tempVds.getVdsSpmId() == spmId) {
                            spmVds = tempVds;
                            break;
                        }
                    }
                }
                if (spmVds != null) {
                    spmVdsId = spmVds.getId();
                } else if (!curVdsId.equals(Guid.Empty)) {
                    VDS currentVds = vdsDao.get(curVdsId);
                    if (currentVds != null && currentVds.getStatus() == VDSStatus.Up && currentVds.getVdsSpmId() != null && currentVds.getVdsSpmId().equals(spmId)) {
                        spmVdsId = curVdsId;
                        spmVds = currentVds;
                    }
                }
            }
            try {
                if (!spmVdsId.equals(Guid.Empty)) {
                    SpmStatusResult destSpmStatus = (SpmStatusResult) resourceManager.runVdsCommand(VDSCommandType.SpmStatus, new SpmStatusVDSCommandParameters(spmVdsId, storagePoolId)).getReturnValue();
                    log.info("SpmStatus on vds '{}': '{}'", spmVdsId, destSpmStatus == null ? "NULL" : destSpmStatus.getSpmStatus());
                    // intentionally unreachable code
                    if (destSpmStatus != null && destSpmStatus.getSpmStatus() == SpmStatus.SPM) {
                        if (!spmVdsId.equals(selectedVds.argvalue.getId()) && spmVds != null && spmVds.getStatus() == VDSStatus.Up) {
                            selectedVds.argvalue = spmVds;
                            startSpm = false;
                            log.info("Using old spm server: '{}', no start needed", spmVds.getName());
                            return destSpmStatus;
                        } else // VDS is non-operational and SPM
                        {
                            log.warn("Host reports to be SPM '{}', but is not up.", spmVdsId);
                            vdsSpmIdToFence = spmStatus.getSpmId();
                        }
                    } else // it is not SPM and continue.
                    if (destSpmStatus == null || (destSpmStatus.getSpmStatus() != SpmStatus.Free && destSpmStatus.getSpmStatus() != SpmStatus.Unknown_Pool)) {
                        vdsSpmIdToFence = spmStatus.getSpmId();
                    }
                } else {
                    log.error("SPM Init: could not find reported vds or not up - pool: '{}' vds_spm_id: '{}'", storagePool.getName(), spmStatus.getSpmId());
                    vdsSpmIdToFence = spmStatus.getSpmId();
                }
            } catch (Exception ex) {
                vdsSpmIdToFence = spmStatus.getSpmId();
            }
        }
        if (startSpm) {
            VdsSpmIdMap map = vdsSpmIdMapDao.get(storagePoolId, vdsSpmIdToFence);
            if (map != null) {
                VDS vdsToFenceObject = vdsDao.get(map.getId());
                if (vdsToFenceObject != null) {
                    log.info("SPM selection - vds seems as spm '{}'", vdsToFenceObject.getName());
                    if (vdsToFenceObject.getStatus() == VDSStatus.NonResponsive) {
                        log.warn("spm vds is non responsive, stopping spm selection.");
                        selectedVds.argvalue = null;
                        return spmStatus;
                    } else {
                        // try to stop spm
                        VDSReturnValue spmStopReturnValue = resourceManager.runVdsCommand(VDSCommandType.SpmStop, new SpmStopVDSCommandParameters(vdsToFenceObject.getId(), storagePoolId));
                        // continue with spm selection
                        if (spmStopReturnValue != null && spmStopReturnValue.getSucceeded()) {
                            log.info("spm stop succeeded, continuing with spm selection");
                        } else // if spm stop failed for any reason we stop spm
                        // selection
                        {
                            log.warn("spm stop on spm failed, stopping spm selection!");
                            selectedVds.argvalue = null;
                            return spmStatus;
                        }
                    }
                }
            }
            spmStatus = startSpm(storagePool, selectedVds.argvalue, spmStatus.getSpmId(), spmStatus.getSpmLVER(), vdsSpmIdToFence);
        }
    }
    return spmStatus;
}
Also used : SpmStatusVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.SpmStatusVDSCommandParameters) SpmStatusResult(org.ovirt.engine.core.common.businessentities.SpmStatusResult) VDS(org.ovirt.engine.core.common.businessentities.VDS) VdsSpmIdMap(org.ovirt.engine.core.common.businessentities.VdsSpmIdMap) SpmStopVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.SpmStopVDSCommandParameters) Guid(org.ovirt.engine.core.compat.Guid) VDSNetworkException(org.ovirt.engine.core.vdsbroker.vdsbroker.VDSNetworkException) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Aggregations

SpmStatusResult (org.ovirt.engine.core.common.businessentities.SpmStatusResult)7 SpmStatusVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.SpmStatusVDSCommandParameters)5 Guid (org.ovirt.engine.core.compat.Guid)5 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)3 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)3 AsyncTaskStatus (org.ovirt.engine.core.common.businessentities.AsyncTaskStatus)2 VDS (org.ovirt.engine.core.common.businessentities.VDS)2 SpmStartVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.SpmStartVDSCommandParameters)2 SpmStopVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.SpmStopVDSCommandParameters)2 VDSNetworkException (org.ovirt.engine.core.vdsbroker.vdsbroker.VDSNetworkException)2 MessageFormat (java.text.MessageFormat)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 EnumSet (java.util.EnumSet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1