use of org.ovirt.engine.core.bll.validator.ImportValidator in project ovirt-engine by oVirt.
the class ImportVmTemplateFromConfigurationCommand method validateUnregisteredEntity.
private boolean validateUnregisteredEntity(VmTemplate entityFromConfiguration, OvfEntityData ovfEntityData) {
if (ovfEntityData == null && !getParameters().isImportAsNewEntity()) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_UNSUPPORTED_OVF);
}
if (entityFromConfiguration == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_OVF_CONFIGURATION_NOT_SUPPORTED);
}
ImportValidator importValidator = new ImportValidator(getParameters());
if (!validate(importValidator.validateDiskNotAlreadyExistOnDB(getImages(), getParameters().isAllowPartialImport(), imageToDestinationDomainMap, failedDisksToImportForAuditLog))) {
return false;
}
for (DiskImage image : new ArrayList<>(getImages())) {
DiskImage fromIrs = null;
Guid storageDomainId = image.getStorageIds().get(0);
Guid imageGroupId = image.getId() != null ? image.getId() : Guid.Empty;
try {
fromIrs = (DiskImage) runVdsCommand(VDSCommandType.GetImageInfo, new GetImageInfoVDSCommandParameters(getStoragePool().getId(), storageDomainId, imageGroupId, image.getImageId())).getReturnValue();
} catch (Exception e) {
log.debug("Unable to get image info from storage", e);
}
if (fromIrs == null) {
if (!getParameters().isAllowPartialImport()) {
return failValidation(EngineMessage.TEMPLATE_IMAGE_NOT_EXIST);
}
log.warn("Disk image '{}/{}' doesn't exist on storage domain '{}'. Ignoring since force flag in on", imageGroupId, image.getImageId(), storageDomainId);
getImages().remove(image);
failedDisksToImportForAuditLog.putIfAbsent(image.getId(), image.getDiskAlias());
}
}
for (DiskImage image : getImages()) {
StorageDomain sd = storageDomainDao.getForStoragePool(image.getStorageIds().get(0), getStoragePool().getId());
ValidationResult result = new StorageDomainValidator(sd).isDomainExistAndActive();
if (!result.isValid()) {
if (!getParameters().isAllowPartialImport()) {
return validate(result);
} else {
log.warn("storage domain '{}' does not exists. Ignoring since force flag in on", image.getStorageIds().get(0));
getImages().remove(image);
failedDisksToImportForAuditLog.putIfAbsent(image.getId(), image.getDiskAlias());
}
}
}
if (!getStorageDomain().getStorageDomainType().isDataDomain()) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_TYPE_UNSUPPORTED, String.format("$domainId %1$s", getParameters().getStorageDomainId()), String.format("$domainType %1$s", getStorageDomain().getStorageDomainType()));
}
return true;
}
use of org.ovirt.engine.core.bll.validator.ImportValidator in project ovirt-engine by oVirt.
the class ImportVmCommandTest method setupDiskSpaceTest.
private void setupDiskSpaceTest() {
final ImportValidator validator = spy(new ImportValidator(cmd.getParameters()));
doReturn(validator).when(cmd).getImportValidator();
cmd.init();
cmd.getParameters().setCopyCollapse(true);
doReturn(true).when(cmd).validateNoDuplicateVm();
doReturn(true).when(cmd).validateVdsCluster();
doReturn(true).when(cmd).validateUniqueVmName();
doReturn(true).when(cmd).checkTemplateInStorageDomain();
doReturn(true).when(cmd).checkImagesGUIDsLegal();
doReturn(true).when(cmd).setAndValidateDiskProfiles();
doReturn(true).when(cmd).setAndValidateCpuProfile();
doReturn(true).when(cmd).validateNoDuplicateDiskImages(any());
doReturn(createSourceDomain()).when(cmd).getSourceDomain();
doReturn(createStorageDomain()).when(cmd).getStorageDomain(any());
doReturn(cmd.getParameters().getVm()).when(cmd).getVmFromExportDomain(any());
doReturn(new VmTemplate()).when(cmd).getVmTemplate();
StoragePool sp = new StoragePool();
sp.setStatus(StoragePoolStatus.Up);
doReturn(sp).when(cmd).getStoragePool();
Cluster cluster = new Cluster();
cluster.setStoragePoolId(cmd.getParameters().getStoragePoolId());
cluster.setClusterId(cmd.getParameters().getClusterId());
doReturn(cluster).when(cmd).getCluster();
doReturn(macPool).when(cmd).getMacPool();
when(poolPerCluster.getMacPoolForCluster(any())).thenReturn(macPool);
ArrayList<Guid> sdIds = new ArrayList<>(Collections.singletonList(Guid.newGuid()));
for (DiskImage image : cmd.getParameters().getVm().getImages()) {
image.setStorageIds(sdIds);
}
doReturn(Collections.emptyList()).when(cmd).createDiskDummiesForSpaceValidations(any());
}
use of org.ovirt.engine.core.bll.validator.ImportValidator in project ovirt-engine by oVirt.
the class ImportVmFromConfigurationCommand method validateEntityPropertiesWhenImagesOnTarget.
private boolean validateEntityPropertiesWhenImagesOnTarget() {
ImportValidator importValidator = getImportValidator();
if (isImagesAlreadyOnTarget()) {
if (!validate(importValidator.validateUnregisteredEntity(ovfEntityData))) {
return false;
}
removeInvalidAffinityGroups(importValidator);
removeInvalidAffinityLabels(importValidator);
removeInavlidUsers(importValidator);
removeInavlidRoles(importValidator);
setImagesWithStoragePoolId(getParameters().getStoragePoolId(), getVm().getImages());
}
return true;
}
Aggregations