Search in sources :

Example 16 with StoragePoolValidator

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

the class RemoveDiskCommand method canRemoveVmImageDisk.

private boolean canRemoveVmImageDisk() {
    if (!listVms.isEmpty()) {
        Guid storagePoolId = listVms.get(0).getStoragePoolId();
        StoragePool sp = storagePoolDao.get(storagePoolId);
        if (!validate(new StoragePoolValidator(sp).existsAndUp())) {
            return false;
        }
        List<DiskImage> diskList = DisksFilter.filterImageDisks(Collections.singletonList(getDisk()), ONLY_NOT_SHAREABLE, ONLY_ACTIVE);
        DiskImagesValidator diskImagesValidator = new DiskImagesValidator(diskList);
        if (!validate(diskImagesValidator.diskImagesNotLocked())) {
            return false;
        }
    }
    for (VM vm : listVms) {
        if (!validate(snapshotsValidator.vmNotDuringSnapshot(vm.getId())) || !validate(snapshotsValidator.vmNotInPreview(vm.getId()))) {
            return false;
        }
    }
    return true;
}
Also used : StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) VM(org.ovirt.engine.core.common.businessentities.VM) Guid(org.ovirt.engine.core.compat.Guid) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 17 with StoragePoolValidator

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

the class RemoveDiskSnapshotsCommand method validate.

@Override
protected boolean validate() {
    if (getVm() == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
    }
    DiskSnapshotsValidator diskSnapshotsValidator = createDiskSnapshotsValidator(getImages());
    if (!validate(diskSnapshotsValidator.diskSnapshotsNotExist(getParameters().getImageIds())) || !validate(diskSnapshotsValidator.diskImagesBelongToSameImageGroup()) || !validate(diskSnapshotsValidator.imagesAreSnapshots())) {
        return false;
    }
    // Validate all chain of images in the disk
    if (!validateAllDiskImages()) {
        return false;
    }
    DiskImagesValidator diskImagesValidator = createDiskImageValidator(getImages());
    if (!validate(diskImagesValidator.diskImagesSnapshotsNotAttachedToOtherVms(false))) {
        return false;
    }
    if (!canRunActionOnNonManagedVm()) {
        return false;
    }
    if (isDiskPlugged()) {
        VmValidator vmValidator = createVmValidator(getVm());
        if (!validate(vmValidator.vmQualifiedForSnapshotMerge())) {
            return false;
        }
    }
    if (!validate(new StoragePoolValidator(getStoragePool()).existsAndUp()) || !validateVmNotDuringSnapshot() || !validateVmNotInPreview() || !validateSnapshotExists() || !validateSnapshotType() || !validateStorageDomainActive()) {
        return false;
    }
    if (!validateStorageDomainAvailableSpace()) {
        return false;
    }
    return true;
}
Also used : StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) DiskSnapshotsValidator(org.ovirt.engine.core.bll.validator.storage.DiskSnapshotsValidator) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator)

Example 18 with StoragePoolValidator

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

the class TryBackToAllSnapshotsOfVmCommand method validate.

@Override
protected boolean validate() {
    if (Guid.Empty.equals(getParameters().getDstSnapshotId())) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_CORRUPTED_VM_SNAPSHOT_ID);
    }
    // verify that the destination lease domain ID belongs to one of the VM's snapshots
    if (getParameters().getDstLeaseDomainId() != null) {
        if (!validate(snapshotsValidator.isLeaseDomainIdBelongsToSnapshot(getVmId(), getParameters().getDstLeaseDomainId())) && !getParameters().getDstLeaseDomainId().equals(getVm().getLeaseStorageDomainId())) {
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_LEASE_DOMAIN_ID_IS_NOT_VALID);
        }
    }
    VmValidator vmValidator = new VmValidator(getVm());
    if (!validate(vmValidator.isVmExists()) || !validate(vmValidator.vmDown()) || !validate(snapshotsValidator.snapshotExists(getVmId(), getParameters().getDstSnapshotId())) || !validate(snapshotsValidator.vmNotDuringSnapshot(getVmId())) || !validate(snapshotsValidator.vmNotInPreview(getVmId())) || !validate(snapshotsValidator.snapshotVmConfigurationBroken(getDstSnapshot(), getVmName()))) {
        return false;
    }
    updateVmDisksFromDb();
    List<DiskImage> diskImages = DisksFilter.filterImageDisks(getVm().getDiskMap().values(), ONLY_NOT_SHAREABLE, ONLY_SNAPABLE, ONLY_ACTIVE);
    diskImages.addAll(DisksFilter.filterCinderDisks(getVm().getDiskMap().values(), ONLY_PLUGGED));
    if (!diskImages.isEmpty()) {
        if (!validate(new StoragePoolValidator(getStoragePool()).existsAndUp())) {
            return false;
        }
        DiskImagesValidator diskImagesValidator = new DiskImagesValidator(diskImages);
        if (!validate(diskImagesValidator.diskImagesNotIllegal()) || !validate(diskImagesValidator.diskImagesNotLocked())) {
            return false;
        }
        List<DiskImage> images = getImagesToPreview();
        DiskImagesValidator diskImagesToPreviewValidator = new DiskImagesValidator(images);
        if (!validate(diskImagesToPreviewValidator.noDuplicatedIds()) || !validate(diskImagesToPreviewValidator.diskImagesSnapshotsAttachedToVm(getVmId())) || !validate(diskImagesToPreviewValidator.diskImagesNotIllegal()) || !validate(diskImagesToPreviewValidator.diskImagesNotLocked())) {
            return false;
        }
        Set<Guid> storageIds = ImagesHandler.getAllStorageIdsForImageIds(diskImages);
        // verify lease storage domain status
        if (getParameters().getDstLeaseDomainId() != null) {
            storageIds.add(getParameters().getDstLeaseDomainId());
        } else if (getDstSnapshot().getVmConfiguration() != null) {
            Guid leaseDomainId = OvfUtils.fetchLeaseDomainId(getDstSnapshot().getVmConfiguration());
            if (leaseDomainId != null) {
                storageIds.add(leaseDomainId);
            }
        }
        MultipleStorageDomainsValidator storageValidator = new MultipleStorageDomainsValidator(getVm().getStoragePoolId(), storageIds);
        if (!validate(storageValidator.allDomainsExistAndActive()) || !validate(storageValidator.allDomainsWithinThresholds()) || !validateCinder()) {
            return false;
        }
    }
    DiskSnapshotsValidator diskSnapshotsValidator = new DiskSnapshotsValidator(getParameters().getDisks());
    if (!validate(diskSnapshotsValidator.canDiskSnapshotsBePreviewed(getParameters().getDstSnapshotId()))) {
        return false;
    }
    if (isRestoreMemory() && !validateMemoryTakenInSupportedVersion()) {
        return false;
    }
    if (!canRestoreVmConfigFromSnapshot()) {
        return failValidation(EngineMessage.MAC_POOL_NOT_ENOUGH_MAC_ADDRESSES);
    }
    return true;
}
Also used : StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) DiskSnapshotsValidator(org.ovirt.engine.core.bll.validator.storage.DiskSnapshotsValidator) Guid(org.ovirt.engine.core.compat.Guid) MultipleStorageDomainsValidator(org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator)

Example 19 with StoragePoolValidator

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

the class ActivateStorageDomainCommand method validate.

@Override
protected boolean validate() {
    StoragePoolValidator validator = createStoragePoolValidator();
    boolean returnValue = validate(validator.exists()) && validate(validator.isNotInStatus(StoragePoolStatus.Uninitialized)) && checkStorageDomain() && storageDomainStatusIsValid() && (getStorageDomain().getStorageDomainType() == StorageDomainType.Master || checkMasterDomainIsUp()) && checkForActiveVds() != null;
    return returnValue;
}
Also used : StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator)

Example 20 with StoragePoolValidator

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

the class ImageSpmCommand method validate.

@Override
protected boolean validate() {
    if (getPoolSpmId() == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_NO_SPM);
    }
    setStoragePool(null);
    StoragePoolValidator spValidator = new StoragePoolValidator(getStoragePool());
    if (!validate(spValidator.exists())) {
        return false;
    }
    if (!getPoolSpmId().equals(getStoragePool().getSpmVdsId())) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_SPM_CHANGED);
    }
    VdsDynamic vdsDynamic = vdsDynamicDao.get(getPoolSpmId());
    if (vdsDynamic == null || vdsDynamic.getStatus() != VDSStatus.Up) {
        addValidationMessage(EngineMessage.VAR__HOST_STATUS__UP);
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_VDS_STATUS_ILLEGAL);
    }
    setVdsId(vdsDynamic.getId());
    if (!commandSpecificValidate()) {
        return false;
    }
    return true;
}
Also used : StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) VdsDynamic(org.ovirt.engine.core.common.businessentities.VdsDynamic)

Aggregations

StoragePoolValidator (org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator)27 Guid (org.ovirt.engine.core.compat.Guid)11 VmValidator (org.ovirt.engine.core.bll.validator.VmValidator)9 DiskImagesValidator (org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator)9 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)9 StorageDomainValidator (org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator)7 MultipleStorageDomainsValidator (org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator)6 ArrayList (java.util.ArrayList)5 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)5 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)4 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)4 CinderDisksValidator (org.ovirt.engine.core.bll.validator.storage.CinderDisksValidator)3 VM (org.ovirt.engine.core.common.businessentities.VM)3 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)3 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)3 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)2