Search in sources :

Example 1 with StoragePoolIsoMap

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

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

the class IrsProxy method proceedStorageDomain.

private boolean proceedStorageDomain(StorageDomain domainFromVdsm, int dataMasterVersion, StoragePool storagePool) {
    StorageDomain storage_domain = storageDomainDao.getForStoragePool(domainFromVdsm.getId(), storagePoolId);
    if (storage_domain != null) {
        StorageDomainStatic domainFromDb = storage_domain.getStorageStaticData();
        StoragePoolIsoMap domainPoolMapFromDb = storage_domain.getStoragePoolIsoMapData();
        // If the domain is master in the DB
        if (domainFromDb.getStorageDomainType() == StorageDomainType.Master && domainPoolMapFromDb != null && domainPoolMapFromDb.getStatus() != StorageDomainStatus.Locked) {
            // and the domain is not master in the VDSM
            if (!((domainFromVdsm.getStorageDomainType() == StorageDomainType.Master) || (domainFromVdsm.getStorageDomainType() == StorageDomainType.Unknown))) {
                reconstructMasterDomainNotInSync(domainFromVdsm.getStoragePoolId(), domainFromDb, "Mismatch between master in DB and VDSM", MessageFormat.format("Master domain is not in sync between DB and VDSM. " + "Domain {0} marked as master in DB and not in the storage", domainFromDb.getStorageName()));
            } else // mismatch
            if (dataMasterVersion != storagePool.getMasterDomainVersion()) {
                reconstructMasterDomainNotInSync(domainFromVdsm.getStoragePoolId(), domainFromDb, "Mismatch between master version in DB and VDSM", MessageFormat.format("Master domain version is not in sync between DB and VDSM. " + "Domain {0} marked as master, but the version in DB: {1} and in VDSM: {2}", domainFromDb.getStorageName(), storagePool.getMasterDomainVersion(), dataMasterVersion));
            }
        }
        boolean statusChanged = false;
        if (domainPoolMapFromDb == null) {
            domainFromVdsm.setStoragePoolId(storagePoolId);
            storagePoolIsoMapDao.save(domainFromVdsm.getStoragePoolIsoMapData());
            statusChanged = true;
        } else if (!domainPoolMapFromDb.getStatus().isStorageDomainInProcess() && domainPoolMapFromDb.getStatus() != domainFromVdsm.getStatus()) {
            if (domainPoolMapFromDb.getStatus() != StorageDomainStatus.Inactive && domainFromVdsm.getStatus() != StorageDomainStatus.Inactive) {
                storagePoolIsoMapDao.update(domainFromVdsm.getStoragePoolIsoMapData());
                statusChanged = true;
            }
            if (domainFromVdsm.getStatus() != null && domainFromVdsm.getStatus() == StorageDomainStatus.Inactive && domainFromDb.getStorageDomainType() == StorageDomainType.Master) {
                StoragePool pool = storagePoolDao.get(domainPoolMapFromDb.getStoragePoolId());
                if (pool != null) {
                    storagePoolDao.updateStatus(pool.getId(), StoragePoolStatus.Maintenance);
                    pool.setStatus(StoragePoolStatus.Maintenance);
                    getEventListener().storagePoolStatusChanged(pool.getId(), StoragePoolStatus.Maintenance);
                }
            }
        }
        // update dynamic data
        if (statusChanged || (domainPoolMapFromDb.getStatus() != StorageDomainStatus.Inactive && domainFromVdsm.getStatus() == StorageDomainStatus.Active)) {
            storageDomainDynamicDao.update(domainFromVdsm.getStorageDynamicData());
            if (domainFromVdsm.getAvailableDiskSize() != null && domainFromVdsm.getUsedDiskSize() != null) {
                double freePercent = domainFromVdsm.getStorageDynamicData().getfreeDiskPercent();
                AuditLogType type = AuditLogType.UNASSIGNED;
                Integer freeDiskInGB = domainFromVdsm.getStorageDynamicData().getAvailableDiskSize();
                if (freeDiskInGB != null) {
                    if (freePercent < domainFromDb.getWarningLowSpaceIndicator()) {
                        type = AuditLogType.IRS_DISK_SPACE_LOW;
                    }
                    if (freeDiskInGB < domainFromDb.getCriticalSpaceActionBlocker()) {
                        // Note, if both conditions are met, only IRS_DISK_SPACE_LOW_ERROR will be shown
                        type = AuditLogType.IRS_DISK_SPACE_LOW_ERROR;
                    }
                }
                if (type != AuditLogType.UNASSIGNED) {
                    AuditLogable logable = new AuditLogableImpl();
                    logable.setStorageDomainName(domainFromDb.getStorageName());
                    logable.addCustomValue("DiskSpace", domainFromVdsm.getAvailableDiskSize().toString());
                    domainFromVdsm.setStorageName(domainFromDb.getStorageName());
                    auditLogDirector.log(logable, type);
                }
            }
            Set<EngineError> alerts = domainFromVdsm.getAlerts();
            if (alerts != null && !alerts.isEmpty()) {
                AuditLogable logable = new AuditLogableImpl();
                logable.setStorageDomainName(domainFromDb.getStorageName());
                domainFromVdsm.setStorageName(domainFromDb.getStorageName());
                for (EngineError alert : alerts) {
                    switch(alert) {
                        case VG_METADATA_CRITICALLY_FULL:
                            auditLogDirector.log(logable, AuditLogType.STORAGE_ALERT_VG_METADATA_CRITICALLY_FULL);
                            break;
                        case SMALL_VG_METADATA:
                            auditLogDirector.log(logable, AuditLogType.STORAGE_ALERT_SMALL_VG_METADATA);
                            break;
                        default:
                            log.error("Unrecognized alert for domain {}(id = {}): {}", domainFromVdsm.getStorageName(), domainFromVdsm.getId(), alert);
                            break;
                    }
                }
            }
        }
        // Block domains should have their LUNs synchronized and updated in the DB.
        if (statusChanged && domainFromVdsm.getStatus() == StorageDomainStatus.Active && storage_domain.getStorageType().isBlockDomain()) {
            return true;
        }
    } else {
        log.debug("The domain with id '{}' was not found in DB", domainFromVdsm.getId());
    }
    return false;
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) AuditLogType(org.ovirt.engine.core.common.AuditLogType) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) AuditLogable(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogable) StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap) EngineError(org.ovirt.engine.core.common.errors.EngineError) AuditLogableImpl(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableImpl)

Example 3 with StoragePoolIsoMap

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

the class StoragePoolDomainHelper method updateApplicablePoolDomainsStatuses.

public void updateApplicablePoolDomainsStatuses(Guid storagePoolId, Set<StorageDomainStatus> applicableStatusesForUpdate, StorageDomainStatus newStatus, String reason) {
    List<StoragePoolIsoMap> storagesStatusInPool = storagePoolIsoMapDao.getAllForStoragePool(storagePoolId);
    for (StoragePoolIsoMap storageStatusInPool : storagesStatusInPool) {
        if (storageStatusInPool.getStatus() != null && storageStatusInPool.getStatus() != newStatus && applicableStatusesForUpdate.contains(storageStatusInPool.getStatus())) {
            log.info("Storage Pool '{}' - Updating Storage Domain '{}' status from '{}' to '{}', reason: {}", storagePoolId, storageStatusInPool.getStorageId(), storageStatusInPool.getStatus().name(), newStatus.name(), reason);
            storageStatusInPool.setStatus(newStatus);
            storagePoolIsoMapDao.updateStatus(storageStatusInPool.getId(), storageStatusInPool.getStatus());
        }
    }
}
Also used : StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap)

Example 4 with StoragePoolIsoMap

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

the class AddStoragePoolWithStoragesCommand method updateStorageDomainsInDb.

private boolean updateStorageDomainsInDb() {
    boolean result = TransactionSupport.executeInNewTransaction(() -> {
        for (Guid storageDomainId : getParameters().getStorages()) {
            StorageDomain storageDomain = storageDomainDao.get(storageDomainId);
            if (storageDomain != null) {
                StoragePoolIsoMap mapFromDB = storagePoolIsoMapDao.get(new StoragePoolIsoMapId(storageDomain.getId(), getStoragePool().getId()));
                boolean existingInDb = mapFromDB != null;
                if (existingInDb) {
                    getCompensationContext().snapshotEntity(mapFromDB);
                }
                final StorageDomainStatic staticDomain = storageDomain.getStorageStaticData();
                boolean staticDomainChanged = false;
                StorageFormatType requiredFormatType = VersionStorageFormatUtil.getForVersion(getStoragePool().getCompatibilityVersion());
                if (staticDomain.getStorageFormat().compareTo(requiredFormatType) < 0) {
                    if (!staticDomainChanged) {
                        getCompensationContext().snapshotEntity(staticDomain);
                    }
                    staticDomain.setStorageFormat(requiredFormatType);
                    staticDomainChanged = true;
                }
                storageDomain.setStoragePoolId(getStoragePool().getId());
                if (masterStorageDomain == null && storageDomain.getStorageDomainType() == StorageDomainType.Data) {
                    if (!staticDomainChanged) {
                        getCompensationContext().snapshotEntity(staticDomain);
                    }
                    storageDomain.setStorageDomainType(StorageDomainType.Master);
                    staticDomainChanged = true;
                    masterStorageDomain = storageDomain;
                    // The update of storage pool should be without compensation,
                    // this is why we run it in a different SUPRESS transaction.
                    updateStoragePoolMasterDomainVersionInDiffTransaction();
                }
                if (staticDomainChanged) {
                    storageDomainStaticDao.update(staticDomain);
                }
                storageDomain.setStatus(StorageDomainStatus.Locked);
                if (existingInDb) {
                    storagePoolIsoMapDao.update(storageDomain.getStoragePoolIsoMapData());
                } else {
                    storagePoolIsoMapDao.save(storageDomain.getStoragePoolIsoMapData());
                    getCompensationContext().snapshotNewEntity(storageDomain.getStoragePoolIsoMapData());
                }
            } else {
                return false;
            }
        }
        getCompensationContext().stateChanged();
        return true;
    });
    return result && masterStorageDomain != null;
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap) StorageFormatType(org.ovirt.engine.core.common.businessentities.StorageFormatType) StoragePoolIsoMapId(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId) Guid(org.ovirt.engine.core.compat.Guid)

Example 5 with StoragePoolIsoMap

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

the class ReconstructMasterDomainCommand method connectAndRefreshAllUpHosts.

private void connectAndRefreshAllUpHosts(final boolean commandSucceeded) {
    if (isLastMaster || !commandSucceeded) {
        log.warn("skipping connect and refresh for all hosts, last master '{}', command status '{}'", isLastMaster, commandSucceeded);
        return;
    }
    List<Callable<Void>> tasks = new ArrayList<>();
    for (final VDS vds : getAllRunningVdssInPool()) {
        tasks.add(() -> {
            try {
                if (!connectVdsToNewMaster(vds)) {
                    log.warn("failed to connect vds '{}' to the new master '{}'", vds.getId(), getNewMasterStorageDomainId());
                    return null;
                }
                List<StoragePoolIsoMap> storagePoolIsoMap = storagePoolIsoMapDao.getAllForStoragePool(getStoragePool().getId());
                try {
                    runVdsCommand(VDSCommandType.ConnectStoragePool, new ConnectStoragePoolVDSCommandParameters(vds, getStoragePool(), getNewMasterStorageDomainId(), storagePoolIsoMap, true));
                } catch (EngineException ex) {
                    if (EngineError.StoragePoolUnknown == ex.getVdsError().getCode()) {
                        VDSReturnValue returnVal = runVdsCommand(VDSCommandType.ConnectStoragePool, new ConnectStoragePoolVDSCommandParameters(vds, getStoragePool(), getNewMasterStorageDomainId(), storagePoolIsoMap));
                        if (!returnVal.getSucceeded()) {
                            log.error("Post reconstruct actions (connectPool) did not complete on host '{}' in the pool. error {}", vds.getId(), returnVal.getVdsError().getMessage());
                        }
                    } else {
                        log.error("Post reconstruct actions (refreshPool)" + " did not complete on host '{}' in the pool. error {}", vds.getId(), ex.getMessage());
                    }
                }
            } catch (Exception e) {
                log.error("Post reconstruct actions (connectPool,refreshPool,disconnect storage)" + " did not complete on host '{}' in the pool: {}", vds.getId(), e.getMessage());
                log.debug("Exception", e);
            }
            return null;
        });
    }
    ThreadPoolUtil.invokeAll(tasks);
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap) ArrayList(java.util.ArrayList) EngineException(org.ovirt.engine.core.common.errors.EngineException) ConnectStoragePoolVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.ConnectStoragePoolVDSCommandParameters) Callable(java.util.concurrent.Callable) EngineException(org.ovirt.engine.core.common.errors.EngineException) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Aggregations

StoragePoolIsoMap (org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap)40 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)15 Guid (org.ovirt.engine.core.compat.Guid)14 StoragePoolIsoMapId (org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId)9 Test (org.junit.Test)8 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)8 ArrayList (java.util.ArrayList)6 StorageServerConnections (org.ovirt.engine.core.common.businessentities.StorageServerConnections)6 StorageDomainStatic (org.ovirt.engine.core.common.businessentities.StorageDomainStatic)4 EngineException (org.ovirt.engine.core.common.errors.EngineException)4 Pair (org.ovirt.engine.core.common.utils.Pair)4 HashMap (java.util.HashMap)3 List (java.util.List)3 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)3 StorageDomainDynamic (org.ovirt.engine.core.common.businessentities.StorageDomainDynamic)3 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)3 VDS (org.ovirt.engine.core.common.businessentities.VDS)3 Event (org.ovirt.engine.core.common.eventqueue.Event)3 EventResult (org.ovirt.engine.core.common.eventqueue.EventResult)3 ConnectStoragePoolVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.ConnectStoragePoolVDSCommandParameters)3