Search in sources :

Example 1 with StorageDomainToPoolRelationValidator

use of org.ovirt.engine.core.bll.validator.storage.StorageDomainToPoolRelationValidator 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 2 with StorageDomainToPoolRelationValidator

use of org.ovirt.engine.core.bll.validator.storage.StorageDomainToPoolRelationValidator in project ovirt-engine by oVirt.

the class RemoveStorageDomainCommandTest method setUp.

@Before
public void setUp() {
    Guid storageDomainID = command.getStorageDomainId();
    storageDomain = new StorageDomain();
    storageDomain.setId(storageDomainID);
    storageDomain.setStatus(StorageDomainStatus.Maintenance);
    Guid vdsID = Guid.newGuid();
    VDS vds = new VDS();
    vds.setId(vdsID);
    command.setVdsId(vdsID);
    command.getParameters().setVdsId(vdsID);
    command.getParameters().setDoFormat(true);
    command.init();
    doReturn(storageDomain).when(storageDomainDaoMock).get(storageDomainID);
    doReturn(Collections.singletonList(storageDomain)).when(storageDomainDaoMock).getAllForStorageDomain(storageDomainID);
    doReturn(vds).when(vdsDaoMock).get(vdsID);
    StorageDomainToPoolRelationValidator domainToPoolValidator = spy(new StorageDomainToPoolRelationValidator(storageDomain.getStorageStaticData(), null));
    doReturn(ValidationResult.VALID).when(domainToPoolValidator).isStorageDomainNotInAnyPool();
    doReturn(domainToPoolValidator).when(command).createDomainToPoolValidator(storageDomain);
    doReturn(Boolean.FALSE).when(command).isStorageDomainAttached(storageDomain);
}
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) Guid(org.ovirt.engine.core.compat.Guid) Before(org.junit.Before)

Example 3 with StorageDomainToPoolRelationValidator

use of org.ovirt.engine.core.bll.validator.storage.StorageDomainToPoolRelationValidator in project ovirt-engine by oVirt.

the class AttachStorageDomainToPoolCommand method validate.

@Override
protected boolean validate() {
    StoragePoolValidator spValidator = createStoragePoolValidator();
    if (!validate(spValidator.exists()) || !initializeVds() || !checkStorageDomain()) {
        return false;
    }
    StorageDomainToPoolRelationValidator storageDomainToPoolRelationValidator = new StorageDomainToPoolRelationValidator(getStorageDomain().getStorageStaticData(), getStoragePool());
    if (!validate(storageDomainToPoolRelationValidator.validateDomainCanBeAttachedToPool())) {
        return false;
    }
    if (!spValidator.isNotInStatus(StoragePoolStatus.Uninitialized).isValid() && getStorageDomain().getStorageDomainType() != StorageDomainType.Data) {
        return failValidation(EngineMessage.ERROR_CANNOT_ADD_STORAGE_POOL_WITHOUT_DATA_DOMAIN);
    }
    StorageDomainValidator storageDomainValidator = new StorageDomainValidator(getStorageDomain());
    if (!validate(storageDomainValidator.isDiscardAfterDeleteSupportedByDcVersion(getStoragePool().getCompatibilityVersion()))) {
        return false;
    }
    if (spValidator.isNotInStatus(StoragePoolStatus.Uninitialized).isValid()) {
        return checkMasterDomainIsUp();
    }
    return true;
}
Also used : StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) StorageDomainToPoolRelationValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainToPoolRelationValidator)

Example 4 with StorageDomainToPoolRelationValidator

use of org.ovirt.engine.core.bll.validator.storage.StorageDomainToPoolRelationValidator in project ovirt-engine by oVirt.

the class AddStoragePoolWithStoragesCommand method checkStorageDomainsInPool.

private boolean checkStorageDomainsInPool() {
    if (!getParameters().getIsInternal()) {
        boolean hasData = false;
        StorageFormatType storageFormat = null;
        for (Guid storageDomainId : getParameters().getStorages()) {
            StorageDomain domain = storageDomainDao.get(storageDomainId);
            StorageDomainToPoolRelationValidator storageDomainToPoolRelationValidator = new StorageDomainToPoolRelationValidator(domain.getStorageStaticData(), getStoragePool());
            if (isStorageDomainNotNull(domain) && validate(storageDomainToPoolRelationValidator.validateDomainCanBeAttachedToPool())) {
                if (domain.getStorageDomainType() == StorageDomainType.Data) {
                    hasData = true;
                    if (storageFormat == null) {
                        storageFormat = domain.getStorageFormat();
                    } else if (storageFormat != domain.getStorageFormat()) {
                        addValidationMessage(EngineMessage.ERROR_CANNOT_ADD_STORAGE_POOL_WITH_DIFFERENT_STORAGE_FORMAT);
                        return false;
                    }
                }
            } else {
                return false;
            }
        }
        if (!hasData) {
            addValidationMessage(EngineMessage.ERROR_CANNOT_ADD_STORAGE_POOL_WITHOUT_DATA_AND_ISO_DOMAINS);
            return false;
        }
    }
    return true;
}
Also used : StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StorageFormatType(org.ovirt.engine.core.common.businessentities.StorageFormatType) StorageDomainToPoolRelationValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainToPoolRelationValidator) Guid(org.ovirt.engine.core.compat.Guid)

Aggregations

StorageDomainToPoolRelationValidator (org.ovirt.engine.core.bll.validator.storage.StorageDomainToPoolRelationValidator)4 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)3 VDS (org.ovirt.engine.core.common.businessentities.VDS)2 Guid (org.ovirt.engine.core.compat.Guid)2 Before (org.junit.Before)1 StorageDomainValidator (org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator)1 StoragePoolValidator (org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator)1 StorageFormatType (org.ovirt.engine.core.common.businessentities.StorageFormatType)1