Search in sources :

Example 1 with Guid

use of org.ovirt.engine.core.compat.Guid in project ovirt-engine by oVirt.

the class IrsBrokerCommand method startReconstruct.

private void startReconstruct() {
    StorageDomainStatic masterDomain = null;
    List<StorageDomainStatic> storageDomainStaticList = DbFacade.getInstance().getStorageDomainStaticDao().getAllForStoragePool(getParameters().getStoragePoolId());
    for (StorageDomainStatic storageDomainStatic : storageDomainStaticList) {
        if (storageDomainStatic.getStorageDomainType() == StorageDomainType.Master) {
            masterDomain = storageDomainStatic;
            break;
        }
    }
    if (masterDomain != null) {
        final Guid masterDomainId = masterDomain.getId();
        eventQueue.submitEventAsync(new Event(getParameters().getStoragePoolId(), masterDomainId, null, EventType.RECONSTRUCT, "IrsBrokerCommand.startReconstruct()"), () -> eventListener.masterDomainNotOperational(masterDomainId, getParameters().getStoragePoolId(), true, getVDSReturnValue().getVdsError() != null && getVDSReturnValue().getVdsError().getCode() == EngineError.StoragePoolWrongMaster));
    } else {
        log.error("IrsBroker::IRSNoMasterDomainException:: Could not find master domain for pool '{}'", getParameters().getStoragePoolId());
    }
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) Event(org.ovirt.engine.core.common.eventqueue.Event) Guid(org.ovirt.engine.core.compat.Guid)

Example 2 with Guid

use of org.ovirt.engine.core.compat.Guid in project ovirt-engine by oVirt.

the class IrsProxy method updateMaintenanceVdsData.

private void updateMaintenanceVdsData(final Guid vdsId, final String vdsName, Set<Guid> domainsInMaintenance) {
    for (Guid domainId : domainsInMaintenance) {
        Set<Guid> vdsSet = _domainsInMaintenance.get(domainId);
        if (vdsSet == null) {
            log.info("Adding domain '{}' to the domains in maintenance cache", domainId);
            _domainsInMaintenance.put(domainId, new HashSet<>(Arrays.asList(vdsId)));
        } else {
            vdsSet.add(vdsId);
        }
    }
    Set<Guid> maintenanceDomainsByHost = new HashSet<>(_domainsInMaintenance.keySet());
    maintenanceDomainsByHost.removeAll(domainsInMaintenance);
    for (Guid domainId : maintenanceDomainsByHost) {
        Set<Guid> vdsForDomain = _domainsInMaintenance.get(domainId);
        if (vdsForDomain != null && vdsForDomain.contains(vdsId)) {
            vdsForDomain.remove(vdsId);
            if (vdsForDomain.isEmpty()) {
                log.info("Removing domain '{}' from the domains in maintenance cache", domainId);
                _domainsInMaintenance.remove(domainId);
            }
        }
    }
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) HashSet(java.util.HashSet)

Example 3 with Guid

use of org.ovirt.engine.core.compat.Guid in project ovirt-engine by oVirt.

the class IrsProxy method getPrioritizedVdsInPool.

private List<VDS> getPrioritizedVdsInPool() {
    Guid curVdsId = (currentVdsId != null) ? currentVdsId : Guid.Empty;
    // Gets a list of the hosts in the storagePool, that are "UP", ordered
    // by vds_spm_priority (not including -1) and secondly ordered by RANDOM(), to
    // deal with the case that there are several hosts with the same priority.
    List<VDS> allVds = vdsDao.getListForSpmSelection(storagePoolId);
    List<VDS> vdsRelevantForSpmSelection = new ArrayList<>();
    Guid preferredHost = getIrsProxyManager().getProxy(storagePoolId).getPreferredHostId();
    getIrsProxyManager().getProxy(storagePoolId).setPreferredHostId(null);
    for (VDS vds : allVds) {
        if (!triedVdssList.contains(vds.getId()) && !vds.getId().equals(curVdsId)) {
            if (vds.getId().equals(preferredHost)) {
                vdsRelevantForSpmSelection.add(0, vds);
            } else {
                vdsRelevantForSpmSelection.add(vds);
            }
        }
    }
    return vdsRelevantForSpmSelection;
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid)

Example 4 with Guid

use of org.ovirt.engine.core.compat.Guid in project ovirt-engine by oVirt.

the class IrsProxy method hostsStorageConnectionsAndPoolMetadataRefresh.

@OnTimerMethodAnnotation("hostsStorageConnectionsAndPoolMetadataRefresh")
public void hostsStorageConnectionsAndPoolMetadataRefresh() {
    Map<Guid, Guid> reportsToHandle = procceedReportsThreatmenet();
    if (reportsToHandle.isEmpty()) {
        return;
    }
    List<Callable<Void>> connectStorageTasks = new ArrayList<>();
    final List<Callable<Void>> refreshStoragePoolTasks = new ArrayList<>();
    final StoragePool storagePool = storagePoolDao.get(storagePoolId);
    final Guid masterDomainId = storageDomainDao.getMasterStorageDomainIdForPool(storagePoolId);
    final List<StoragePoolIsoMap> storagePoolIsoMap = storagePoolIsoMapDao.getAllForStoragePool(storagePoolId);
    Map<String, Pair<String, String>> acquiredLocks = new HashMap<>();
    try {
        for (Map.Entry<Guid, Guid> entry : reportsToHandle.entrySet()) {
            Guid vdsId = entry.getKey();
            Guid currentReportId = entry.getValue();
            vdsHandeledReportsOnUnseenDomains.put(vdsId, currentReportId);
            Map<String, Pair<String, String>> lockMap = Collections.singletonMap(vdsId.toString(), new Pair<>(LockingGroup.VDS_POOL_AND_STORAGE_CONNECTIONS.toString(), EngineMessage.ACTION_TYPE_FAILED_OBJECT_LOCKED.toString()));
            EngineLock engineLock = new EngineLock(lockMap, null);
            if (!lockManager.acquireLock(engineLock).getFirst()) {
                log.info("Failed to acquire lock to refresh storage connection and pool metadata for host '{}', skipping it", vdsId);
                continue;
            }
            final VDS vds = vdsDao.get(entry.getKey());
            if (vds.getStatus() != VDSStatus.Up) {
                log.info("Skipping storage connection and pool metadata information for host '{}' as it's no longer in status UP", vdsId);
                lockManager.releaseLock(engineLock);
                continue;
            }
            acquiredLocks.putAll(lockMap);
            connectStorageTasks.add(() -> {
                getEventListener().connectHostToDomainsInActiveOrUnknownStatus(vds);
                return null;
            });
            refreshStoragePoolTasks.add(() -> {
                storagePoolDomainHelper.refreshHostPoolMetadata(vds, storagePool, masterDomainId, storagePoolIsoMap);
                return null;
            });
        }
        final Set<String> handledHosts = acquiredLocks.keySet();
        log.info("Running storage connections refresh for hosts '{}'", handledHosts);
        ThreadPoolUtil.invokeAll(connectStorageTasks);
        log.info("Submitting to the event queue pool refresh for hosts '{}'", handledHosts);
        getEventQueue().submitEventSync(new Event(storagePoolId, null, null, EventType.POOLREFRESH, ""), () -> {
            log.info("Running storage pool metadata refresh for hosts '{}'", handledHosts);
            ThreadPoolUtil.invokeAll(refreshStoragePoolTasks);
            return new EventResult(true, EventType.POOLREFRESH);
        });
    } finally {
        if (!acquiredLocks.isEmpty()) {
            lockManager.releaseLock(new EngineLock(acquiredLocks, null));
        }
    }
}
Also used : StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) VDS(org.ovirt.engine.core.common.businessentities.VDS) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) Callable(java.util.concurrent.Callable) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) EventResult(org.ovirt.engine.core.common.eventqueue.EventResult) Event(org.ovirt.engine.core.common.eventqueue.Event) VdsSpmIdMap(org.ovirt.engine.core.common.businessentities.VdsSpmIdMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap) Pair(org.ovirt.engine.core.common.utils.Pair) OnTimerMethodAnnotation(org.ovirt.engine.core.utils.timer.OnTimerMethodAnnotation)

Example 5 with Guid

use of org.ovirt.engine.core.compat.Guid in project ovirt-engine by oVirt.

the class IrsProxy method proceedStoragePoolStats.

@SuppressWarnings("unchecked")
private void proceedStoragePoolStats(StoragePool storagePool) {
    // ugly patch because vdsm doesnt check if host is spm on spm
    // operations
    VDSReturnValue result = null;
    Guid curVdsId = currentVdsId;
    if (curVdsId != null) {
        result = resourceManager.runVdsCommand(VDSCommandType.SpmStatus, new SpmStatusVDSCommandParameters(curVdsId, storagePoolId));
    }
    if (result == null || !result.getSucceeded() || (result.getSucceeded() && ((SpmStatusResult) result.getReturnValue()).getSpmStatus() != SpmStatus.SPM)) {
        // update pool status to problematic until fence will happen
        if (storagePool.getStatus() != StoragePoolStatus.NonResponsive && storagePool.getStatus() != StoragePoolStatus.NotOperational) {
            if (result != null && result.getVdsError() != null) {
                updateStoragePoolStatus(storagePoolId, StoragePoolStatus.NonResponsive, AuditLogType.SYSTEM_CHANGE_STORAGE_POOL_STATUS_PROBLEMATIC_WITH_ERROR, result.getVdsError().getCode());
            } else {
                updateStoragePoolStatus(storagePoolId, StoragePoolStatus.NonResponsive, AuditLogType.SYSTEM_CHANGE_STORAGE_POOL_STATUS_PROBLEMATIC, EngineError.ENGINE);
            }
        }
        // then cause failover with attempts
        if (result != null && !(result.getExceptionObject() instanceof VDSNetworkException)) {
            HashMap<Guid, AsyncTaskStatus> tasksList = (HashMap<Guid, AsyncTaskStatus>) resourceManager.runVdsCommand(VDSCommandType.HSMGetAllTasksStatuses, new VdsIdVDSCommandParametersBase(curVdsId)).getReturnValue();
            boolean allTasksFinished = true;
            if (tasksList != null) {
                for (AsyncTaskStatus taskStatus : tasksList.values()) {
                    if (AsyncTaskStatusEnum.finished != taskStatus.getStatus()) {
                        allTasksFinished = false;
                        break;
                    }
                }
            }
            if ((tasksList == null) || allTasksFinished) {
                nullifyInternalProxies();
            } else {
                if (_errorAttempts < Config.<Integer>getValue(ConfigValues.SPMFailOverAttempts)) {
                    _errorAttempts++;
                    log.warn("failed getting spm status for pool '{}' ({}), attempt number: {}", storagePoolId, storagePool.getName(), _errorAttempts);
                } else {
                    nullifyInternalProxies();
                    _errorAttempts = 0;
                }
            }
        }
    } else if (result.getSucceeded() && ((SpmStatusResult) result.getReturnValue()).getSpmStatus() == SpmStatus.SPM && (storagePool.getStatus() == StoragePoolStatus.NonResponsive || storagePool.getStatus() == StoragePoolStatus.Contend)) {
        // if recovered from network exception set back to up
        storagePoolDao.updateStatus(storagePool.getId(), StoragePoolStatus.Up);
        storagePool.setStatus(StoragePoolStatus.Up);
        getEventListener().storagePoolStatusChanged(storagePool.getId(), storagePool.getStatus());
    }
    List<StorageDomain> domainsInDb = storageDomainDao.getAllForStoragePool(storagePoolId);
    GetStoragePoolInfoVDSCommandParameters tempVar = new GetStoragePoolInfoVDSCommandParameters(storagePoolId);
    tempVar.setIgnoreFailoverLimit(true);
    VDSReturnValue storagePoolInfoResult = resourceManager.runVdsCommand(VDSCommandType.GetStoragePoolInfo, tempVar);
    if (storagePoolInfoResult.getSucceeded()) {
        KeyValuePairCompat<StoragePool, List<StorageDomain>> data = (KeyValuePairCompat<StoragePool, List<StorageDomain>>) storagePoolInfoResult.getReturnValue();
        int masterVersion = data.getKey().getMasterDomainVersion();
        HashSet<Guid> domainsInVds = new HashSet<>();
        List<StorageDomain> storageDomainsToSync = data.getValue().stream().peek(storageDomain -> domainsInVds.add(storageDomain.getId())).filter(storageDomain -> proceedStorageDomain(storageDomain, masterVersion, storagePool)).collect(Collectors.toList());
        if (!storageDomainsToSync.isEmpty()) {
            getEventListener().syncStorageDomainsLuns(getCurrentVdsId(), storageDomainsToSync.stream().map(StorageDomain::getId).collect(Collectors.toList()));
        }
        for (final StorageDomain domainInDb : domainsInDb) {
            if (domainInDb.getStorageDomainType() != StorageDomainType.Master && domainInDb.getStatus() != StorageDomainStatus.Locked && !domainInDb.getStorageType().isCinderDomain() && !domainsInVds.contains(domainInDb.getId())) {
                // domain not attached to pool anymore
                storagePoolIsoMapDao.remove(new StoragePoolIsoMapId(domainInDb.getId(), storagePoolId));
            }
        }
    }
    domainsInMaintenanceCheck(domainsInDb, storagePool);
}
Also used : SpmStatusVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.SpmStatusVDSCommandParameters) VdsIdVDSCommandParametersBase(org.ovirt.engine.core.common.vdscommands.VdsIdVDSCommandParametersBase) StoragePoolDomainHelper(org.ovirt.engine.core.vdsbroker.storage.StoragePoolDomainHelper) VdsSpmIdMap(org.ovirt.engine.core.common.businessentities.VdsSpmIdMap) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) StorageDomainDynamicDao(org.ovirt.engine.core.dao.StorageDomainDynamicDao) ScheduledFuture(java.util.concurrent.ScheduledFuture) LoggerFactory(org.slf4j.LoggerFactory) NonOperationalReason(org.ovirt.engine.core.common.businessentities.NonOperationalReason) EventType(org.ovirt.engine.core.common.eventqueue.EventType) ConnectStoragePoolVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.ConnectStoragePoolVDSCommandParameters) OnTimerMethodAnnotation(org.ovirt.engine.core.utils.timer.OnTimerMethodAnnotation) VdsDao(org.ovirt.engine.core.dao.VdsDao) KeyValuePairCompat(org.ovirt.engine.core.compat.KeyValuePairCompat) Map(java.util.Map) Event(org.ovirt.engine.core.common.eventqueue.Event) StoragePoolDao(org.ovirt.engine.core.dao.StoragePoolDao) SpmStartVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.SpmStartVDSCommandParameters) ThreadPoolUtil(org.ovirt.engine.core.utils.threadpool.ThreadPoolUtil) AuditLogableImpl(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableImpl) EnumSet(java.util.EnumSet) ManagedScheduledExecutorService(javax.enterprise.concurrent.ManagedScheduledExecutorService) Instance(javax.enterprise.inject.Instance) GetStoragePoolInfoVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.GetStoragePoolInfoVDSCommandParameters) RefObject(org.ovirt.engine.core.compat.RefObject) StoragePoolIsoMapId(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId) Collection(java.util.Collection) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) StorageConstants(org.ovirt.engine.core.common.constants.StorageConstants) Set(java.util.Set) EventQueue(org.ovirt.engine.core.common.eventqueue.EventQueue) BusinessEntitiesDefinitions(org.ovirt.engine.core.common.businessentities.BusinessEntitiesDefinitions) Collectors(java.util.stream.Collectors) AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus) VdsStaticDao(org.ovirt.engine.core.dao.VdsStaticDao) VdsDynamicDao(org.ovirt.engine.core.dao.VdsDynamicDao) VDSNetworkException(org.ovirt.engine.core.vdsbroker.vdsbroker.VDSNetworkException) List(java.util.List) VDSStatus(org.ovirt.engine.core.common.businessentities.VDSStatus) VDSDomainsData(org.ovirt.engine.core.common.businessentities.VDSDomainsData) IVdsEventListener(org.ovirt.engine.core.common.businessentities.IVdsEventListener) PostConstruct(javax.annotation.PostConstruct) AuditLogType(org.ovirt.engine.core.common.AuditLogType) SpmStatusVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.SpmStatusVDSCommandParameters) DisconnectStoragePoolVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.DisconnectStoragePoolVDSCommandParameters) SpmStatusResult(org.ovirt.engine.core.common.businessentities.SpmStatusResult) SpmStopVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.SpmStopVDSCommandParameters) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) TransportFactory(org.ovirt.engine.core.vdsbroker.TransportFactory) ResourceManager(org.ovirt.engine.core.vdsbroker.ResourceManager) Guid(org.ovirt.engine.core.compat.Guid) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) StorageDomainStatus(org.ovirt.engine.core.common.businessentities.StorageDomainStatus) ThreadPools(org.ovirt.engine.core.utils.threadpool.ThreadPools) TransactionSupport(org.ovirt.engine.core.utils.transaction.TransactionSupport) StoragePoolIsoMapDao(org.ovirt.engine.core.dao.StoragePoolIsoMapDao) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) LinkedList(java.util.LinkedList) StorageDomainStaticDao(org.ovirt.engine.core.dao.StorageDomainStaticDao) Pair(org.ovirt.engine.core.common.utils.Pair) VdsSpmIdMapDao(org.ovirt.engine.core.dao.VdsSpmIdMapDao) Config(org.ovirt.engine.core.common.config.Config) VdsIdVDSCommandParametersBase(org.ovirt.engine.core.common.vdscommands.VdsIdVDSCommandParametersBase) StoragePoolStatus(org.ovirt.engine.core.common.businessentities.StoragePoolStatus) LockingGroup(org.ovirt.engine.core.common.locks.LockingGroup) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) ReentrantLock(java.util.concurrent.locks.ReentrantLock) AuditLogDirector(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) ExceptionUtils(org.apache.commons.lang.exception.ExceptionUtils) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) ConfigValues(org.ovirt.engine.core.common.config.ConfigValues) SpmStatus(org.ovirt.engine.core.common.businessentities.SpmStatus) LockManager(org.ovirt.engine.core.utils.lock.LockManager) EventResult(org.ovirt.engine.core.common.eventqueue.EventResult) EngineError(org.ovirt.engine.core.common.errors.EngineError) TransactionScopeOption(org.ovirt.engine.core.compat.TransactionScopeOption) AuditLogable(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogable) TimeUnit(java.util.concurrent.TimeUnit) VDSCommandType(org.ovirt.engine.core.common.vdscommands.VDSCommandType) StorageDomainType(org.ovirt.engine.core.common.businessentities.StorageDomainType) StorageDomainDao(org.ovirt.engine.core.dao.StorageDomainDao) Collections(java.util.Collections) VDS(org.ovirt.engine.core.common.businessentities.VDS) AsyncTaskStatusEnum(org.ovirt.engine.core.common.businessentities.AsyncTaskStatusEnum) StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) KeyValuePairCompat(org.ovirt.engine.core.compat.KeyValuePairCompat) StoragePoolIsoMapId(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId) VDSNetworkException(org.ovirt.engine.core.vdsbroker.vdsbroker.VDSNetworkException) Guid(org.ovirt.engine.core.compat.Guid) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) GetStoragePoolInfoVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.GetStoragePoolInfoVDSCommandParameters) SpmStatusResult(org.ovirt.engine.core.common.businessentities.SpmStatusResult) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Aggregations

Guid (org.ovirt.engine.core.compat.Guid)1431 ArrayList (java.util.ArrayList)330 Test (org.junit.Test)322 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)219 HashMap (java.util.HashMap)211 List (java.util.List)167 VM (org.ovirt.engine.core.common.businessentities.VM)144 Map (java.util.Map)118 VDS (org.ovirt.engine.core.common.businessentities.VDS)117 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)106 HashSet (java.util.HashSet)102 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)89 Pair (org.ovirt.engine.core.common.utils.Pair)79 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)77 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)72 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)70 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)69 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)57 ActionType (org.ovirt.engine.core.common.action.ActionType)56 Set (java.util.Set)52