use of org.ovirt.engine.core.bll.ValidationResult in project ovirt-engine by oVirt.
the class ImportVmCommandBase method validate.
@Override
protected boolean validate() {
if (getVm() == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
}
if (getCluster() == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_CAN_NOT_BE_EMPTY);
}
if (getParameters().getStoragePoolId() != null && !getParameters().getStoragePoolId().equals(getCluster().getStoragePoolId())) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_IS_NOT_VALID);
}
macPool = getMacPool();
List<VmNetworkInterface> nicsUnableToBeImported = getVm().getInterfaces().stream().filter(this::ifaceMacCannotBeAddedToMacPool).collect(Collectors.toList());
if (!nicsUnableToBeImported.isEmpty()) {
EngineMessage engineMessage = EngineMessage.ACTION_TYPE_FAILED_CANNOT_ADD_IFACE_DUE_TO_MAC_DUPLICATES;
Collection<String> replacements = ReplacementUtils.getListVariableAssignmentString(engineMessage, nicsUnableToBeImported);
return validate(new ValidationResult(engineMessage, replacements));
}
List<EngineMessage> msgs = openStackMetadataAdapter.validate(getVm().getVmInit());
if (!CollectionUtils.isEmpty(msgs)) {
return failValidation(msgs);
}
return true;
}
use of org.ovirt.engine.core.bll.ValidationResult 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.ValidationResult in project ovirt-engine by oVirt.
the class CinderProviderValidator method validateAttachStorageDomain.
private ValidationResult validateAttachStorageDomain() {
StoragePoolValidator spValidator = new StoragePoolValidator(getStoragePool());
ValidationResult result;
result = spValidator.isAnyDomainInProcess();
if (!result.isValid()) {
return result;
}
result = spValidator.isInStatus(StoragePoolStatus.Up);
if (!result.isValid()) {
return result;
}
return ValidationResult.VALID;
}
use of org.ovirt.engine.core.bll.ValidationResult in project ovirt-engine by oVirt.
the class CpuProfileHelper method setAndValidateCpuProfile.
public ValidationResult setAndValidateCpuProfile(VmBase vmBase, Guid userId) {
if (vmBase.getCpuProfileId() == null) {
return assignFirstCpuProfile(vmBase, userId);
}
Guid clusterId = vmBase.getClusterId();
if (clusterId == null) {
return new ValidationResult(EngineMessage.ACTION_TYPE_CPU_PROFILE_CLUSTER_NOT_PROVIDED);
}
CpuProfile fetchedCpuProfile = cpuProfileDao.get(vmBase.getCpuProfileId());
if (fetchedCpuProfile == null) {
return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_CPU_PROFILE_NOT_FOUND);
}
if (!clusterId.equals(fetchedCpuProfile.getClusterId())) {
return new ValidationResult(EngineMessage.ACTION_TYPE_CPU_PROFILE_NOT_MATCH_CLUSTER);
}
if (!checkPermissions(vmBase.getCpuProfileId(), userId)) {
return new ValidationResult(EngineMessage.ACTION_TYPE_NO_PERMISSION_TO_ASSIGN_CPU_PROFILE, String.format("$cpuProfileId %s", vmBase.getCpuProfileId()), String.format("$cpuProfileName %s", fetchedCpuProfile.getName()));
}
return ValidationResult.VALID;
}
use of org.ovirt.engine.core.bll.ValidationResult in project ovirt-engine by oVirt.
the class DiskProfileValidator method validateUnattachedDisks.
private ValidationResult validateUnattachedDisks() {
List<DiskImage> entities = diskImageDao.getAllForDiskProfiles(Collections.singletonList(getProfile().getId()));
if (entities.isEmpty()) {
return ValidationResult.VALID;
}
List<Object> nameList = new ArrayList<>();
for (DiskImage diskImage : entities) {
nameList.add(diskImage.getDiskAlias());
}
Collection<String> replacements = ReplacementUtils.replaceWith("ENTITIES_USING_PROFILE", nameList);
replacements.add(EngineMessage.VAR__ENTITIES__DISKS.name());
return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_PROFILE_IN_USE, replacements);
}
Aggregations