Search in sources :

Example 1 with StorageFormatType

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

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

the class UploadImageModel method validate.

public boolean validate() {
    boolean uploadImageIsValid;
    setIsValid(true);
    getInvalidityReasons().clear();
    getImageInfoModel().getInvalidityReasons().clear();
    if (getImageSourceLocalEnabled().getEntity()) {
        getImagePath().validateEntity(new IValidation[] { value -> {
            ValidationResult result = new ValidationResult();
            if (value == null || StringHelper.isNullOrEmpty((String) value)) {
                result.setSuccess(false);
                result.getReasons().add(constants.emptyImagePath());
            }
            return result;
        } });
        StorageFormatType storageFormatType = getDiskModel().getStorageDomain().getSelectedItem().getStorageFormat();
        uploadImageIsValid = getImagePath().getIsValid() && getImageInfoModel().validate(storageFormatType, getImageSize());
        getInvalidityReasons().addAll(getImagePath().getInvalidityReasons());
        getInvalidityReasons().addAll(getImageInfoModel().getInvalidityReasons());
    } else {
        // TODO remote/download
        uploadImageIsValid = false;
    }
    return uploadImageIsValid && diskModel.validate();
}
Also used : StorageFormatType(org.ovirt.engine.core.common.businessentities.StorageFormatType) ValidationResult(org.ovirt.engine.ui.uicommonweb.validation.ValidationResult)

Example 3 with StorageFormatType

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

the class DataCenterListModel method onSave.

public void onSave() {
    final DataCenterModel dcModel = (DataCenterModel) getWindow();
    if (!dcModel.validate()) {
        return;
    }
    if ((dcModel.getIsNew() || dcModel.getEntity() == null) && dcModel.getQuotaEnforceTypeListModel().getSelectedItem() == QuotaEnforcementTypeEnum.HARD_ENFORCEMENT) {
        promptNoQuotaInDCMessage();
    } else if (!dcModel.getIsNew() && getSelectedItem() != null && !dcModel.getVersion().getSelectedItem().equals(getSelectedItem().getCompatibilityVersion())) {
        final ConfirmationModel confirmModel = new ConfirmationModel();
        setConfirmWindow(confirmModel);
        confirmModel.setTitle(ConstantsManager.getInstance().getConstants().changeDataCenterCompatibilityVersionTitle());
        confirmModel.setHelpTag(HelpTag.change_data_center_compatibility_version);
        // $NON-NLS-1$
        confirmModel.setHashName("change_data_center_compatibility_version");
        final StoragePool sp = getSelectedItem();
        startProgress();
        IdQueryParameters params = new IdQueryParameters(sp.getId());
        Frontend.getInstance().runQuery(QueryType.GetStorageDomainsByStoragePoolId, params, new AsyncQuery<QueryReturnValue>(returnValue -> {
            List<StorageDomain> storages = returnValue.getReturnValue();
            StorageDomain storage = null;
            for (StorageDomain sd : storages) {
                if (sd.getStorageDomainType().isDataDomain()) {
                    storage = sd;
                }
            }
            StorageFormatType newFormat = null;
            StorageFormatType oldFormat = null;
            if (storage != null) {
                newFormat = VersionStorageFormatUtil.getForVersion(dcModel.getVersion().getSelectedItem());
                oldFormat = VersionStorageFormatUtil.getForVersion(sp.getCompatibilityVersion());
            }
            if (newFormat == oldFormat) {
                confirmModel.setMessage(ConstantsManager.getInstance().getConstants().youAreAboutChangeDcCompatibilityVersionMsg());
            } else {
                Version v = VersionStorageFormatUtil.getEarliestVersionSupported(newFormat);
                confirmModel.setMessage(ConstantsManager.getInstance().getMessages().youAreAboutChangeDcCompatibilityVersionWithUpgradeMsg(v.getValue()));
            }
            stopProgress();
        }));
        // $NON-NLS-1$
        UICommand tempVar = UICommand.createDefaultOkUiCommand("OnSaveInternal", this);
        confirmModel.getCommands().add(tempVar);
        // $NON-NLS-1$
        UICommand tempVar2 = UICommand.createCancelUiCommand("CancelConfirmation", this);
        confirmModel.getCommands().add(tempVar2);
    } else if (getSelectedItem() != null && getSelectedItem().getQuotaEnforcementType() != QuotaEnforcementTypeEnum.HARD_ENFORCEMENT && dcModel.getQuotaEnforceTypeListModel().getSelectedItem() == QuotaEnforcementTypeEnum.HARD_ENFORCEMENT) {
        checkForQuotaInDC(dcModel.getEntity(), this);
    } else if (dcModel.getIsNew()) {
        // New data center, check for name uniqueness.
        validateDataCenterName(dcModel);
    } else {
        onSaveInternal();
    }
}
Also used : StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) Version(org.ovirt.engine.core.compat.Version) StorageFormatType(org.ovirt.engine.core.common.businessentities.StorageFormatType) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) ConfirmationModel(org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)

Example 4 with StorageFormatType

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

the class StorageDomainValidator method isStorageFormatCompatibleWithDomain.

public ValidationResult isStorageFormatCompatibleWithDomain() {
    StorageFormatType storageFormat = storageDomain.getStorageFormat();
    StorageType storageType = storageDomain.getStorageType();
    StorageDomainType storageDomainFunction = storageDomain.getStorageDomainType();
    boolean validationSucceeded = true;
    if (storageFormat == null) {
        validationSucceeded = false;
    }
    // V2 is applicable only for block data storage domains
    if (validationSucceeded && storageFormat == StorageFormatType.V2) {
        if (!(storageDomainFunction.isDataDomain() && storageType.isBlockDomain())) {
            validationSucceeded = false;
        }
    }
    if (validationSucceeded && storageFormat.compareTo(StorageFormatType.V3) >= 0) {
        // Above V3 is applicable only for data storage domains
        if (!storageDomainFunction.isDataDomain()) {
            validationSucceeded = false;
        }
    }
    return validationSucceeded ? ValidationResult.VALID : new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_FORMAT_ILLEGAL_HOST, String.format("$storageFormat %1$s", storageDomain.getStorageFormat()));
}
Also used : StorageDomainType(org.ovirt.engine.core.common.businessentities.StorageDomainType) StorageType(org.ovirt.engine.core.common.businessentities.storage.StorageType) StorageFormatType(org.ovirt.engine.core.common.businessentities.StorageFormatType) ValidationResult(org.ovirt.engine.core.bll.ValidationResult)

Example 5 with StorageFormatType

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

the class AddStorageDomainCommonTest method validateSucceedsInitFormatDataDomain.

@Test
public void validateSucceedsInitFormatDataDomain() {
    sd.setStorageFormat(null);
    ValidateTestUtils.runAndAssertValidateSuccess(cmd);
    StorageFormatType targetStorageFormatType = StorageFormatType.values()[StorageFormatType.values().length - 1];
    assertEquals("Format not initialized correctly", targetStorageFormatType, sd.getStorageFormat());
}
Also used : StorageFormatType(org.ovirt.engine.core.common.businessentities.StorageFormatType) Test(org.junit.Test) BaseCommandTest(org.ovirt.engine.core.bll.BaseCommandTest)

Aggregations

StorageFormatType (org.ovirt.engine.core.common.businessentities.StorageFormatType)12 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)4 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)3 Guid (org.ovirt.engine.core.compat.Guid)3 Version (org.ovirt.engine.core.compat.Version)3 Test (org.junit.Test)2 StorageDomainStatic (org.ovirt.engine.core.common.businessentities.StorageDomainStatic)2 StorageDomainType (org.ovirt.engine.core.common.businessentities.StorageDomainType)2 ArrayList (java.util.ArrayList)1 Theory (org.junit.experimental.theories.Theory)1 StorageFormat (org.ovirt.engine.api.model.StorageFormat)1 BaseCommandTest (org.ovirt.engine.core.bll.BaseCommandTest)1 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)1 StorageDomainToPoolRelationValidator (org.ovirt.engine.core.bll.validator.storage.StorageDomainToPoolRelationValidator)1 StoragePoolIsoMap (org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap)1 StoragePoolIsoMapId (org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId)1 StorageType (org.ovirt.engine.core.common.businessentities.storage.StorageType)1 EngineException (org.ovirt.engine.core.common.errors.EngineException)1 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)1 UpgradeStoragePoolVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.UpgradeStoragePoolVDSCommandParameters)1