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;
}
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();
}
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();
}
}
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()));
}
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());
}
Aggregations