Search in sources :

Example 16 with StorageDomain

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

the class ProcessOvfUpdateForStoragePoolCommand method proccessDomainsForOvfUpdate.

protected void proccessDomainsForOvfUpdate(StoragePool pool) {
    List<StorageDomain> domainsInPool = storageDomainDao.getAllForStoragePool(pool.getId());
    for (StorageDomain domain : domainsInPool) {
        if (!domain.getStorageDomainType().isDataDomain() || (domain.getStatus() != StorageDomainStatus.Active && getParameters().getStorageDomainId() != null && !domain.getId().equals(getParameters().getStorageDomainId()))) {
            continue;
        }
        activeDataDomainsIds.add(domain.getId());
        Integer ovfStoresCountForDomain = Config.<Integer>getValue(ConfigValues.StorageDomainOvfStoreCount);
        List<StorageDomainOvfInfo> storageDomainOvfInfos = storageDomainOvfInfoDao.getAllForDomain(domain.getId());
        if (storageDomainOvfInfos.size() < ovfStoresCountForDomain) {
            proccessedDomains.add(domain.getId());
            continue;
        }
        for (StorageDomainOvfInfo storageDomainOvfInfo : storageDomainOvfInfos) {
            if (storageDomainOvfInfo.getStatus() == StorageDomainOvfInfoStatus.OUTDATED) {
                proccessedDomains.add(storageDomainOvfInfo.getStorageDomainId());
                break;
            }
        }
    }
}
Also used : StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StorageDomainOvfInfo(org.ovirt.engine.core.common.businessentities.StorageDomainOvfInfo)

Example 17 with StorageDomain

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

the class RemoveStorageDomainCommand method validate.

@Override
protected boolean validate() {
    if (!super.validate()) {
        return false;
    }
    StorageDomain dom = getStorageDomain();
    if (dom == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_NOT_EXIST);
    }
    VDS vds = getVds();
    boolean localFs = isLocalFs(dom);
    if (vds == null) {
        if (localFs) {
            if (!initializeVds()) {
                return false;
            }
        } else {
            return failValidation(EngineMessage.CANNOT_REMOVE_STORAGE_DOMAIN_INVALID_HOST_ID);
        }
    } else if (vds.getStatus() != VDSStatus.Up) {
        return failValidation(EngineMessage.CANNOT_REMOVE_STORAGE_DOMAIN_HOST_NOT_UP, String.format("$%1$s %2$s", "hostName", vds.getName()));
    }
    StorageDomainToPoolRelationValidator domainPoolValidator = createDomainToPoolValidator(dom);
    if (!checkStorageDomain()) {
        return false;
    }
    if (!localFs && !validate(domainPoolValidator.isStorageDomainNotInAnyPool())) {
        return false;
    }
    if (localFs && isDomainAttached(dom) && !canDetachDomain(getParameters().getDestroyingPool())) {
        return false;
    }
    if (getParameters().getDoFormat() && !localFs && isStorageDomainAttached(dom)) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_FORMAT_STORAGE_DOMAIN_WITH_ATTACHED_DATA_DOMAIN);
    }
    if (dom.getStorageType().isOpenStackDomain()) {
        return failValidation(EngineMessage.ERROR_CANNOT_MANAGE_STORAGE_DOMAIN);
    }
    return true;
}
Also used : StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) VDS(org.ovirt.engine.core.common.businessentities.VDS) StorageDomainToPoolRelationValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainToPoolRelationValidator)

Example 18 with StorageDomain

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

the class StorageDomainCommandBase method updateStorageDomainDynamicFromIrs.

protected void updateStorageDomainDynamicFromIrs() {
    final StorageDomain sd = (StorageDomain) runVdsCommand(VDSCommandType.GetStorageDomainStats, new GetStorageDomainStatsVDSCommandParameters(getVds().getId(), getStorageDomain().getId())).getReturnValue();
    TransactionSupport.executeInNewTransaction(() -> {
        getCompensationContext().snapshotEntity(getStorageDomain().getStorageDynamicData());
        storageDomainDynamicDao.update(sd.getStorageDynamicData());
        getCompensationContext().stateChanged();
        return null;
    });
}
Also used : StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) GetStorageDomainStatsVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.GetStorageDomainStatsVDSCommandParameters)

Example 19 with StorageDomain

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

the class AddStoragePoolWithStoragesCommand method executeCommand.

@Override
protected void executeCommand() {
    if (updateStorageDomainsInDb()) {
        // setting storage pool status to maintenance
        StoragePool storagePool = getStoragePool();
        getCompensationContext().snapshotEntity(storagePool);
        TransactionSupport.executeInNewTransaction(() -> {
            getStoragePool().setStatus(StoragePoolStatus.Maintenance);
            getStoragePool().setStoragePoolFormatType(masterStorageDomain.getStorageFormat());
            storagePoolDao.update(getStoragePool());
            getCompensationContext().stateChanged();
            StoragePoolStatusHandler.poolStatusChanged(getStoragePool().getId(), getStoragePool().getStatus());
            return null;
        });
        // Following code performs only read operations, therefore no need for new transaction
        boolean result = false;
        // Once we create a storage pool with multiple hosts, the engine should connect all
        // the hosts in the storage pool,
        // since the engine picks a random host to fetch all the unregistered disks.
        boolean isStoragePoolCreated = false;
        retVal = null;
        for (VDS vds : getAllRunningVdssInPool()) {
            setVds(vds);
            for (Guid storageDomainId : getParameters().getStorages()) {
                // now the domain should have the mapping
                // with the pool in db
                StorageDomain storageDomain = storageDomainDao.getForStoragePool(storageDomainId, getStoragePool().getId());
                storageHelperDirector.getItem(storageDomain.getStorageType()).connectStorageToDomainByVdsId(storageDomain, getVds().getId());
            }
            if (!isStoragePoolCreated) {
                // but didn't throw exception
                if (!cleanDirtyMetaDataIfNeeded()) {
                    result = false;
                } else {
                    retVal = addStoragePoolInIrs();
                    if (!retVal.getSucceeded() && retVal.getVdsError().getCode() == EngineError.StorageDomainAccessError) {
                        log.warn("Error creating storage pool on vds '{}' - continuing", vds.getName());
                        continue;
                    }
                    result = retVal.getSucceeded();
                }
                isStoragePoolCreated = true;
            }
        }
        setSucceeded(result);
        if (!result) {
            if (retVal != null && retVal.getVdsError().getCode() != null) {
                throw new EngineException(retVal.getVdsError().getCode(), retVal.getVdsError().getMessage());
            } else {
                // command
                throw new EngineException(EngineError.ENGINE_ERROR_CREATING_STORAGE_POOL);
            }
        }
        registerOvfStoreDisks();
    }
    // Create pool phase completed, no rollback is needed here, so compensation information needs to be cleared!
    TransactionSupport.executeInNewTransaction(() -> {
        getCompensationContext().cleanupCompensationDataAfterSuccessfulCommand();
        return null;
    });
    freeLock();
    // if create succeeded activate
    if (getSucceeded()) {
        activateStorageDomains();
    }
}
Also used : StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) VDS(org.ovirt.engine.core.common.businessentities.VDS) EngineException(org.ovirt.engine.core.common.errors.EngineException) Guid(org.ovirt.engine.core.compat.Guid)

Example 20 with StorageDomain

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

Aggregations

StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)345 ArrayList (java.util.ArrayList)108 Guid (org.ovirt.engine.core.compat.Guid)103 Test (org.junit.Test)91 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)75 List (java.util.List)58 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)58 StorageDomainStatic (org.ovirt.engine.core.common.businessentities.StorageDomainStatic)49 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)47 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)46 QueryType (org.ovirt.engine.core.common.queries.QueryType)43 StorageServerConnections (org.ovirt.engine.core.common.businessentities.StorageServerConnections)42 AsyncDataProvider (org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider)41 ConstantsManager (org.ovirt.engine.ui.uicompat.ConstantsManager)41 ConfirmationModel (org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)40 VDS (org.ovirt.engine.core.common.businessentities.VDS)39 Frontend (org.ovirt.engine.ui.frontend.Frontend)39 HelpTag (org.ovirt.engine.ui.uicommonweb.help.HelpTag)36 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)36 StorageType (org.ovirt.engine.core.common.businessentities.storage.StorageType)35