use of org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator in project ovirt-engine by oVirt.
the class TransferDiskImageCommand method validateImageTransfer.
@Override
protected boolean validateImageTransfer() {
DiskImage diskImage = getDiskImage();
DiskValidator diskValidator = getDiskValidator(diskImage);
DiskImagesValidator diskImagesValidator = getDiskImagesValidator(diskImage);
StorageDomainValidator storageDomainValidator = getStorageDomainValidator(storageDomainDao.getForStoragePool(diskImage.getStorageIds().get(0), diskImage.getStoragePoolId()));
return validate(diskValidator.isDiskExists()) && validateActiveDiskPluggedToAnyNonDownVm(diskImage, diskValidator) && validate(diskImagesValidator.diskImagesNotIllegal()) && validate(diskImagesValidator.diskImagesNotLocked()) && validate(storageDomainValidator.isDomainExistAndActive());
}
use of org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator 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;
}
use of org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator in project ovirt-engine by oVirt.
the class AmendImageGroupVolumesCommand method validate.
@Override
protected boolean validate() {
DiskValidator diskValidator = createDiskValidator();
if (!validate(diskValidator.isDiskExists())) {
return false;
}
if (!validate(diskValidator.isDiskPluggedToAnyNonDownVm(false))) {
return false;
}
setStoragePoolId(getDiskImage().getStoragePoolId());
if (!validate(new StoragePoolValidator(getStoragePool()).existsAndUp())) {
return false;
}
if (!FeatureSupported.qcowCompatSupported(getStoragePool().getCompatibilityVersion())) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_AMEND_NOT_SUPPORTED_BY_DC_VERSION, String.format("$dataCenterVersion %s", getStoragePool().getCompatibilityVersion().toString()));
}
if (getDiskImage().getVmEntityType().isTemplateType()) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CANT_AMEND_TEMPLATE_DISK);
}
setStorageDomainId(getDiskImage().getStorageIds().get(0));
StorageDomainValidator storageDomainValidator = new StorageDomainValidator(getStorageDomain());
if (!validate(storageDomainValidator.isDomainExistAndActive())) {
return false;
}
DiskImagesValidator diskImagesValidator = new DiskImagesValidator(Collections.singletonList(getDiskImage()));
return validate(diskImagesValidator.diskImagesNotIllegal()) && validate(diskImagesValidator.diskImagesNotLocked());
}
use of org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator in project ovirt-engine by oVirt.
the class ExportVmCommand method validate.
@Override
protected boolean validate() {
if (getVm() == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
}
setDescription(getVmName());
setStoragePoolId(getVm().getStoragePoolId());
// check that target domain exists
StorageDomainValidator targetstorageDomainValidator = new StorageDomainValidator(getStorageDomain());
if (!validate(targetstorageDomainValidator.isDomainExistAndActive())) {
return false;
}
// load the disks of vm from database
vmHandler.updateDisksFromDb(getVm());
List<DiskImage> disksForExport = getDisksBasedOnImage();
DiskImagesValidator diskImagesValidator = new DiskImagesValidator(disksForExport);
if (!validate(diskImagesValidator.diskImagesNotIllegal()) || !validate(diskImagesValidator.diskImagesNotLocked())) {
return false;
}
// update vm snapshots for storage free space check
imagesHandler.fillImagesBySnapshots(getVm());
// check that the target and source domain are in the same storage_pool
if (storagePoolIsoMapDao.get(new StoragePoolIsoMapId(getStorageDomain().getId(), getVm().getStoragePoolId())) == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_POOL_NOT_MATCH);
}
// check if template exists only if asked for
if (getParameters().getTemplateMustExists()) {
if (!checkTemplateInStorageDomain(getVm().getStoragePoolId(), getParameters().getStorageDomainId(), getVm().getVmtGuid(), getContext().getEngineContext())) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_TEMPLATE_NOT_FOUND_ON_EXPORT_DOMAIN, String.format("$TemplateName %1$s", getVm().getVmtName()));
}
}
Map<Guid, ? extends Disk> images = getVm().getDiskMap();
if (getParameters().getCopyCollapse()) {
for (DiskImage img : disksForExport) {
if (images.containsKey(img.getId())) {
// check that no RAW format exists (we are in collapse mode)
if (((DiskImage) images.get(img.getId())).getVolumeFormat() == VolumeFormat.RAW && img.getVolumeFormat() != VolumeFormat.RAW) {
return failValidation(EngineMessage.VM_CANNOT_EXPORT_RAW_FORMAT);
}
}
}
}
// check destination storage is Export domain
if (getStorageDomain().getStorageDomainType() != StorageDomainType.ImportExport) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_SPECIFY_DOMAIN_IS_NOT_EXPORT_DOMAIN, String.format("$storageDomainName %1$s", getStorageDomainName()));
}
// get the snapshots that are going to be exported and have memory
snapshotsWithMemory = getSnapshotsToBeExportedWithMemory();
// check destination storage have free space
if (!handleDestStorageDomain(disksForExport)) {
return false;
}
if (!(checkVmInStorageDomain() && validate(new StoragePoolValidator(getStoragePool()).existsAndUp()) && validate(snapshotsValidator.vmNotDuringSnapshot(getVmId())) && validate(snapshotsValidator.vmNotInPreview(getVmId())) && validate(new VmValidator(getVm()).vmDown()) && validate(new MultipleStorageDomainsValidator(getVm().getStoragePoolId(), ImagesHandler.getAllStorageIdsForImageIds(disksForExport)).allDomainsExistAndActive()))) {
return false;
}
return true;
}
use of org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator in project ovirt-engine by oVirt.
the class ExportVmTemplateCommand method validate.
@Override
protected boolean validate() {
if (getVmTemplate() == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_TEMPLATE_DOES_NOT_EXIST);
}
StorageDomainValidator storageDomainValidator = new StorageDomainValidator(getStorageDomain());
if (!validate(storageDomainValidator.isDomainExistAndActive())) {
return false;
}
// export must be to export domain
if (getStorageDomain().getStorageDomainType() != StorageDomainType.ImportExport) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_SPECIFY_DOMAIN_IS_NOT_EXPORT_DOMAIN);
}
if (getTemplateDisks() != null && !getTemplateDisks().isEmpty()) {
ensureDomainMap(getTemplateDisks(), getParameters().getStorageDomainId());
// check that images are ok
imagesHandler.fillImagesMapBasedOnTemplate(getVmTemplate(), imageFromSourceDomainMap, null);
if (getVmTemplate().getDiskTemplateMap().values().size() != imageFromSourceDomainMap.size()) {
log.error("Can not found any default active domain for one of the disks of template with id '{}'", getVmTemplate().getId());
return failValidation(EngineMessage.ACTION_TYPE_FAILED_MISSED_STORAGES_FOR_SOME_DISKS);
}
if (validate(vmTemplateHandler.isVmTemplateImagesReady(getVmTemplate(), null, true, true, true, false, getTemplateDisks()))) {
setStoragePoolId(getVmTemplate().getStoragePoolId());
StorageDomainValidator sdValidator = createStorageDomainValidator(getStorageDomain());
if (!validate(sdValidator.isDomainExistAndActive()) || !validate(sdValidator.isDomainWithinThresholds()) || !(getParameters().getForceOverride() || (!getParameters().isImagesExistOnTargetStorageDomain() && checkIfDisksExist(getTemplateDisks()))) || !validateFreeSpaceOnDestinationDomain(sdValidator, getTemplateDisks())) {
return false;
}
}
if (storagePoolIsoMapDao.get(new StoragePoolIsoMapId(getStorageDomain().getId(), getVmTemplate().getStoragePoolId())) == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_POOL_NOT_MATCH);
}
}
// check if template (with no override option)
if (!getParameters().getForceOverride()) {
if (ExportVmCommand.checkTemplateInStorageDomain(getVmTemplate().getStoragePoolId(), getParameters().getStorageDomainId(), getVmTemplateId(), getContext().getEngineContext())) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_NAME_ALREADY_USED);
}
}
return true;
}
Aggregations