use of org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator in project ovirt-engine by oVirt.
the class AddVmTemplateCommand method validateImages.
protected boolean validateImages() {
// images related checks
if (!images.isEmpty()) {
if (!validateVmNotDuringSnapshot()) {
return false;
}
if (!validate(new StoragePoolValidator(getStoragePool()).existsAndUp())) {
return false;
}
List<CinderDisk> cinderDisks = getCinderDisks();
CinderDisksValidator cinderDisksValidator = new CinderDisksValidator(cinderDisks);
if (!validate(cinderDisksValidator.validateCinderDiskLimits())) {
return false;
}
if (!validate(isPassDiscardSupportedForImagesDestSds())) {
return false;
}
List<DiskImage> diskImagesToCheck = DisksFilter.filterImageDisks(images, ONLY_NOT_SHAREABLE, ONLY_ACTIVE);
diskImagesToCheck.addAll(cinderDisks);
DiskImagesValidator diskImagesValidator = new DiskImagesValidator(diskImagesToCheck);
if (!validate(diskImagesValidator.diskImagesNotIllegal()) || !validate(diskImagesValidator.diskImagesNotLocked())) {
return false;
}
MultipleStorageDomainsValidator storageDomainsValidator = getStorageDomainsValidator(getStoragePoolId(), sourceImageDomainsImageMap.keySet());
if (!validate(storageDomainsValidator.allDomainsExistAndActive())) {
return false;
}
Set<Guid> destImageDomains = getStorageGuidSet();
destImageDomains.removeAll(sourceImageDomainsImageMap.keySet());
for (Guid destImageDomain : destImageDomains) {
StorageDomain storage = storageDomainDao.getForStoragePool(destImageDomain, getVm().getStoragePoolId());
if (storage == null) {
// domain is not in the same storage pool as the vm
if (storageDomainStaticDao.get(destImageDomain) == null) {
addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_NOT_EXIST);
} else {
addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_NOT_IN_STORAGE_POOL);
}
return false;
}
if (storage.getStatus() == null || storage.getStatus() != StorageDomainStatus.Active) {
addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_STATUS_ILLEGAL);
return false;
}
if (storage.getStorageDomainType().isIsoOrImportExportDomain()) {
addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_TYPE_ILLEGAL);
return false;
}
}
return validateSpaceRequirements();
}
return true;
}
use of org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator in project ovirt-engine by oVirt.
the class CommonVmPoolCommand method validate.
@Override
protected boolean validate() {
if (getCluster() == null) {
return failValidation(EngineMessage.VDS_CLUSTER_IS_NOT_VALID);
}
// A Pool cannot be added in a cluster without a defined architecture
if (getCluster().getArchitecture() == ArchitectureType.undefined) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_UNDEFINED_ARCHITECTURE);
}
VmPool pool = vmPoolDao.getByName(getParameters().getVmPool().getName());
if (pool != null && (getActionType() == ActionType.AddVmPool || !pool.getVmPoolId().equals(getParameters().getVmPoolId()))) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_NAME_ALREADY_USED);
}
setStoragePoolId(getCluster().getStoragePoolId());
if (!validate(new StoragePoolValidator(getStoragePool()).existsAndUp())) {
return false;
}
ensureDestinationImageMap();
// check if the selected template is compatible with Cluster architecture.
if (!getVmTemplate().getId().equals(VmTemplateHandler.BLANK_VM_TEMPLATE_ID) && getCluster().getArchitecture() != getVmTemplate().getClusterArch()) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_TEMPLATE_IS_INCOMPATIBLE);
}
final int nicsCount = getParameters().getVmsCount() * vmNicDao.getAllForTemplate(getVmTemplateId()).size();
if (!validate(vmHandler.verifyMacPool(nicsCount, getMacPool()))) {
return false;
}
final int priority = getParameters().getVmStaticData().getPriority();
if (!validate(vmHandler.isVmPriorityValueLegal(priority))) {
return false;
}
if (getVmTemplate().getDiskTemplateMap().values().size() != diskInfoDestinationMap.size()) {
log.error("Can not found any default active domain for one of the disks of template with id '{}'", getVmTemplate().getId());
addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_MISSED_STORAGES_FOR_SOME_DISKS);
return false;
}
List<Guid> storageIds = new ArrayList<>();
for (DiskImage diskImage : diskInfoDestinationMap.values()) {
Guid storageId = diskImage.getStorageIds().get(0);
if (!storageIds.contains(storageId) && !areTemplateImagesInStorageReady(storageId)) {
return false;
}
storageIds.add(storageId);
}
if (getActionType() == ActionType.AddVmPool && getParameters().getVmsCount() < 1) {
return failValidation(EngineMessage.VM_POOL_CANNOT_CREATE_WITH_NO_VMS);
}
if (getParameters().getVmPool().getPrestartedVms() > getParameters().getVmPool().getAssignedVmsCount() + getParameters().getVmsCount()) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_PRESTARTED_VMS_CANNOT_EXCEED_VMS_COUNT);
}
if (!setAndValidateDiskProfiles()) {
return false;
}
if (!setAndValidateCpuProfile()) {
return false;
}
return checkDestDomains();
}
Aggregations