Search in sources :

Example 6 with StorageDomainType

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

the class AttachStorageDomainToPoolCommand method executeCommand.

@Override
protected void executeCommand() {
    if (isCinderStorageDomain()) {
        handleCinderDomain();
        return;
    }
    if (getStoragePool().getStatus() == StoragePoolStatus.Uninitialized) {
        StoragePoolWithStoragesParameter parameters = new StoragePoolWithStoragesParameter(getStoragePool(), Collections.singletonList(getStorageDomain().getId()), getParameters().getSessionId());
        parameters.setIsInternal(true);
        parameters.setTransactionScopeOption(TransactionScopeOption.Suppress);
        ActionReturnValue returnValue = runInternalAction(ActionType.AddStoragePoolWithStorages, parameters, getContext().clone().withoutCompensationContext());
        setSucceeded(returnValue.getSucceeded());
        if (!returnValue.getSucceeded()) {
            getReturnValue().setFault(returnValue.getFault());
        }
    } else {
        map = storagePoolIsoMapDao.get(new StoragePoolIsoMapId(getStorageDomain().getId(), getParameters().getStoragePoolId()));
        if (map == null) {
            executeInNewTransaction(() -> {
                map = new StoragePoolIsoMap(getStorageDomain().getId(), getParameters().getStoragePoolId(), StorageDomainStatus.Locked);
                storagePoolIsoMapDao.save(map);
                getCompensationContext().snapshotNewEntity(map);
                getCompensationContext().stateChanged();
                return null;
            });
            List<Pair<Guid, Boolean>> hostsConnectionResults = connectHostsInUpToDomainStorageServer();
            if (isAllHostConnectionFailed(hostsConnectionResults)) {
                log.error("Cannot connect storage connection server, aborting attach storage domain operation.");
                setSucceeded(false);
                return;
            }
            // Forcibly detach only data storage domains.
            if (getStorageDomain().getStorageDomainType() == StorageDomainType.Data) {
                @SuppressWarnings("unchecked") Pair<StorageDomainStatic, Guid> domainFromIrs = (Pair<StorageDomainStatic, Guid>) runVdsCommand(VDSCommandType.HSMGetStorageDomainInfo, new HSMGetStorageDomainInfoVDSCommandParameters(getVdsId(), getParameters().getStorageDomainId())).getReturnValue();
                // If the storage domain is already related to another Storage Pool, detach it by force.
                Guid storagePoolId = domainFromIrs.getSecond();
                if (storagePoolId != null) {
                    // Master domain version is not relevant since force remove at
                    // DetachStorageDomainVdsCommand does not use it.
                    // Storage pool id can be empty
                    DetachStorageDomainVDSCommandParameters detachParams = new DetachStorageDomainVDSCommandParameters(getStoragePoolIdFromVds(), getParameters().getStorageDomainId(), Guid.Empty, 0);
                    detachParams.setForce(true);
                    detachParams.setDetachFromOldStoragePool(true);
                    try {
                        runVdsCommand(VDSCommandType.DetachStorageDomain, detachParams);
                    } catch (EngineException e) {
                        log.warn("Detaching Storage Domain '{}' from it's previous storage pool '{}'" + " has failed. The meta data of the Storage Domain might still" + " indicate that it is attached to a different Storage Pool.", getParameters().getStorageDomainId(), Guid.Empty, 0);
                        throw e;
                    }
                }
                if (diskProfileDao.getAllForStorageDomain(getStorageDomain().getId()).isEmpty()) {
                    createDefaultDiskProfile();
                }
            }
            runVdsCommand(VDSCommandType.AttachStorageDomain, new AttachStorageDomainVDSCommandParameters(getParameters().getStoragePoolId(), getParameters().getStorageDomainId()));
            final List<OvfEntityData> unregisteredEntitiesFromOvfDisk = new ArrayList<>();
            if (getStorageDomain().getStorageDomainType().isDataDomain()) {
                List<OvfEntityData> returnValueFromStorageOvfDisk = getEntitiesFromStorageOvfDisk(getParameters().getStorageDomainId(), getStoragePoolIdFromVds());
                unregisteredEntitiesFromOvfDisk.addAll(returnValueFromStorageOvfDisk);
            }
            List<DiskImage> ovfStoreDiskImages = getAllOVFDisks(getParameters().getStorageDomainId(), getStoragePoolIdFromVds());
            executeInNewTransaction(() -> {
                final StorageDomainType sdType = getStorageDomain().getStorageDomainType();
                map.setStatus(StorageDomainStatus.Maintenance);
                storagePoolIsoMapDao.updateStatus(map.getId(), map.getStatus());
                if (sdType == StorageDomainType.Master) {
                    calcStoragePoolStatusByDomainsStatus();
                }
                if (getStorageDomain().getStorageDomainType().isDataDomain()) {
                    registerAllOvfDisks(ovfStoreDiskImages, getParameters().getStorageDomainId());
                    // Update unregistered entities
                    for (OvfEntityData ovf : unregisteredEntitiesFromOvfDisk) {
                        unregisteredOVFDataDao.removeEntity(ovf.getEntityId(), getParameters().getStorageDomainId());
                        unregisteredOVFDataDao.saveOVFData(ovf);
                        log.info("Adding OVF data of entity id '{}' and entity name '{}'", ovf.getEntityId(), ovf.getEntityName());
                    }
                    initUnregisteredDisksToDB(getParameters().getStorageDomainId());
                }
                // upgrade the domain format to the storage pool format
                updateStorageDomainFormatIfNeeded(getStorageDomain());
                return null;
            });
            if (getParameters().getActivate()) {
                attemptToActivateDomain();
            }
            setSucceeded(true);
        }
    }
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) StorageDomainType(org.ovirt.engine.core.common.businessentities.StorageDomainType) AttachStorageDomainVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.AttachStorageDomainVDSCommandParameters) DetachStorageDomainVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.DetachStorageDomainVDSCommandParameters) StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap) EngineException(org.ovirt.engine.core.common.errors.EngineException) ArrayList(java.util.ArrayList) StoragePoolIsoMapId(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId) HSMGetStorageDomainInfoVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.HSMGetStorageDomainInfoVDSCommandParameters) Guid(org.ovirt.engine.core.compat.Guid) StoragePoolWithStoragesParameter(org.ovirt.engine.core.common.action.StoragePoolWithStoragesParameter) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) OvfEntityData(org.ovirt.engine.core.common.businessentities.OvfEntityData) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 7 with StorageDomainType

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

the class StorageHandlingCommandBase method updateStorageDomainFormatIfNeeded.

protected void updateStorageDomainFormatIfNeeded(StorageDomain domain) {
    final StorageDomainType sdType = domain.getStorageDomainType();
    if (!sdType.isDataDomain()) {
        log.debug("Skipping format update for domain '{}' (type '{}')", getStorageDomain().getId(), sdType);
        return;
    }
    final StorageDomainStatic storageStaticData = domain.getStorageStaticData();
    final StorageFormatType targetFormat = getStoragePool().getStoragePoolFormatType();
    if (storageStaticData.getStorageFormat() != targetFormat) {
        log.info("Updating storage domain '{}' (type '{}') to format '{}'", getStorageDomain().getId(), sdType, targetFormat);
        storageStaticData.setStorageFormat(targetFormat);
        storageDomainStaticDao.update(storageStaticData);
    } else {
        log.debug("Skipping format update for domain '{}' format is '{}'", getStorageDomain().getId(), storageStaticData.getStorageFormat());
    }
}
Also used : StorageDomainType(org.ovirt.engine.core.common.businessentities.StorageDomainType) StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) StorageFormatType(org.ovirt.engine.core.common.businessentities.StorageFormatType)

Example 8 with StorageDomainType

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

the class StorageDomainToPoolRelationValidatorTest method testCanAttachMultipleISOOrExport.

@Test
public void testCanAttachMultipleISOOrExport() {
    for (StorageDomainType type : Arrays.asList(StorageDomainType.ISO, StorageDomainType.ImportExport)) {
        storageDomain.setStorageDomainType(type);
        // Make the pool to have already a domain with the same type of the domain we want to attach.
        StorageDomain domainWithSameType = new StorageDomain();
        domainWithSameType.setStorageDomainType(type);
        when(storageDomainDao.getAllForStoragePool(storagePool.getId())).thenReturn(Collections.singletonList(domainWithSameType));
        ValidationResult attachMultipleISOOrExportResult = validator.validateDomainCanBeAttachedToPool();
        assertThat("Attaching domain of type " + type + " succeeded though another domain of the same type already exists in the pool", attachMultipleISOOrExportResult, failsWith(type == StorageDomainType.ISO ? EngineMessage.ERROR_CANNOT_ATTACH_MORE_THAN_ONE_ISO_DOMAIN : EngineMessage.ERROR_CANNOT_ATTACH_MORE_THAN_ONE_EXPORT_DOMAIN));
    }
}
Also used : StorageDomainType(org.ovirt.engine.core.common.businessentities.StorageDomainType) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) Test(org.junit.Test)

Example 9 with StorageDomainType

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

the class StorageDomainToPoolRelationValidatorTest method testCanAttachSingleISOOrExport.

/**
 * Tests attaching an ISO/Export domain to a pool first to a pool without an ISO/Export domain attached (should succeed)
 * then to a pool with an ISO/Export domain attached (should fail)
 */
@Test
public void testCanAttachSingleISOOrExport() {
    for (StorageDomainType type : Arrays.asList(StorageDomainType.ISO, StorageDomainType.ImportExport)) {
        storageDomain.setStorageDomainType(type);
        assertThat(validator.validateDomainCanBeAttachedToPool(), isValid());
    }
}
Also used : StorageDomainType(org.ovirt.engine.core.common.businessentities.StorageDomainType) Test(org.junit.Test)

Example 10 with StorageDomainType

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

the class UpdateStoragePoolCommand method updateMemberDomainsFormat.

private void updateMemberDomainsFormat(StorageFormatType targetFormat) {
    Guid spId = getStoragePool().getId();
    List<StorageDomainStatic> domains = storageDomainStaticDao.getAllForStoragePool(spId);
    for (StorageDomainStatic domain : domains) {
        StorageDomainType sdType = domain.getStorageDomainType();
        if (sdType == StorageDomainType.Data || sdType == StorageDomainType.Master) {
            log.info("Setting storage domain '{}' (type '{}') to format '{}'", domain.getId(), sdType, targetFormat);
            domain.setStorageFormat(targetFormat);
            storageDomainStaticDao.update(domain);
        }
    }
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) StorageDomainType(org.ovirt.engine.core.common.businessentities.StorageDomainType) Guid(org.ovirt.engine.core.compat.Guid)

Aggregations

StorageDomainType (org.ovirt.engine.core.common.businessentities.StorageDomainType)13 StorageDomainStatic (org.ovirt.engine.core.common.businessentities.StorageDomainStatic)4 StorageType (org.ovirt.engine.core.common.businessentities.storage.StorageType)4 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)3 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)3 StorageDomainSharedStatus (org.ovirt.engine.core.common.businessentities.StorageDomainSharedStatus)3 StorageFormatType (org.ovirt.engine.core.common.businessentities.StorageFormatType)3 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)3 HorizontalPanel (com.google.gwt.user.client.ui.HorizontalPanel)2 Image (com.google.gwt.user.client.ui.Image)2 TreeItem (com.google.gwt.user.client.ui.TreeItem)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Guid (org.ovirt.engine.core.compat.Guid)2 StringValueLabel (org.ovirt.engine.ui.common.widget.label.StringValueLabel)2 Collection (java.util.Collection)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 ActionUtils (org.ovirt.engine.core.common.ActionUtils)1 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)1