use of org.ovirt.engine.core.common.errors.EngineMessage in project ovirt-engine by oVirt.
the class AddVmCommand method validate.
@Override
protected boolean validate() {
if (getCluster() == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_CAN_NOT_BE_EMPTY);
}
if (getVmTemplate() == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_TEMPLATE_DOES_NOT_EXIST);
}
if (getVmTemplate().isDisabled()) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_TEMPLATE_IS_DISABLED);
}
StoragePoolValidator spValidator = new StoragePoolValidator(getStoragePool());
if (!validate(spValidator.exists())) {
return false;
}
if (!isExternalVM() && !validate(spValidator.isInStatus(StoragePoolStatus.Up))) {
return false;
}
if (!isTemplateInValidDc()) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_TEMPLATE_NOT_EXISTS_IN_CURRENT_DC);
}
if (!isDisksVolumeFormatValid()) {
return false;
}
Version customCompatibilityVersionFromParams = getParameters().getVmStaticData().getCustomCompatibilityVersion();
if (customCompatibilityVersionFromParams != null && !isCompatibilityVersionSupportedByCluster(customCompatibilityVersionFromParams)) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CUSTOM_COMPATIBILITY_VERSION_NOT_SUPPORTED, String.format("$Ccv %s", customCompatibilityVersionFromParams));
}
// A VM cannot be added in a cluster without a defined architecture
if (getCluster().getArchitecture() == ArchitectureType.undefined) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_UNDEFINED_ARCHITECTURE);
}
if (verifySourceDomains() && buildAndCheckDestStorageDomains()) {
chooseDisksSourceDomains();
} else {
return false;
}
if (getParameters().getVmStaticData().getVmType() == VmType.HighPerformance && !FeatureSupported.isHighPerformanceTypeSupported(getEffectiveCompatibilityVersion())) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_HIGH_PERFORMANCE_IS_NOT_SUPPORTED, String.format("$Version %s", getEffectiveCompatibilityVersion()));
}
if (isBalloonEnabled() && !osRepository.isBalloonEnabled(getParameters().getVmStaticData().getOsId(), getEffectiveCompatibilityVersion())) {
addValidationMessageVariable("clusterArch", getCluster().getArchitecture());
return failValidation(EngineMessage.BALLOON_REQUESTED_ON_NOT_SUPPORTED_ARCH);
}
if (isSoundDeviceEnabled() && !osRepository.isSoundDeviceEnabled(getParameters().getVmStaticData().getOsId(), getEffectiveCompatibilityVersion())) {
addValidationMessageVariable("clusterArch", getCluster().getArchitecture());
return failValidation(EngineMessage.SOUND_DEVICE_REQUESTED_ON_NOT_SUPPORTED_ARCH);
}
if (!validateQuota(getParameters().getVmStaticData().getQuotaId())) {
return false;
}
// otherwise..
storageToDisksMap = ImagesHandler.buildStorageToDiskMap(getImagesToCheckDestinationStorageDomains(), diskInfoDestinationMap);
if (!validateAddVmCommand()) {
return false;
}
VM vmFromParams = getParameters().getVm();
// 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);
}
if (StringUtils.isEmpty(vmFromParams.getName())) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_NAME_MAY_NOT_BE_EMPTY);
}
// check that VM name is not too long
if (!isVmNameValidLength(vmFromParams)) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_NAME_LENGTH_IS_TOO_LONG);
}
// check for Vm Payload
if (getParameters().getVmPayload() != null) {
if (!checkPayload(getParameters().getVmPayload())) {
return false;
}
// otherwise, we save the content in base64 string
for (Map.Entry<String, String> entry : getParameters().getVmPayload().getFiles().entrySet()) {
entry.setValue(new String(BASE_64.encode(entry.getValue().getBytes()), StandardCharsets.UTF_8));
}
}
// check for Vm Watchdog Model
if (getParameters().getWatchdog() != null) {
if (!validate(new VmWatchdogValidator(vmFromParams.getOs(), getParameters().getWatchdog(), getEffectiveCompatibilityVersion()).isValid())) {
return false;
}
}
// check if the OS type is supported
if (!validate(vmHandler.isOsTypeSupported(vmFromParams.getOs(), getCluster().getArchitecture()))) {
return false;
}
if (!validate(vmHandler.isCpuSupported(vmFromParams.getVmOsId(), getEffectiveCompatibilityVersion(), getCluster().getCpuName()))) {
return false;
}
// Check if the graphics and display from parameters are supported
if (!validate(vmHandler.isGraphicsAndDisplaySupported(getParameters().getVmStaticData().getOsId(), vmHandler.getResultingVmGraphics(getVmDeviceUtils().getGraphicsTypesOfEntity(getVmTemplateId()), getParameters().getGraphicsDevices()), vmFromParams.getDefaultDisplayType(), getEffectiveCompatibilityVersion()))) {
return false;
}
if (!validate(vmHandler.validateSmartCardDevice(getParameters().getVmStaticData()))) {
return false;
}
if (!FeatureSupported.isMigrationSupported(getCluster().getArchitecture(), getEffectiveCompatibilityVersion()) && vmFromParams.getMigrationSupport() != MigrationSupport.PINNED_TO_HOST) {
return failValidation(EngineMessage.VM_MIGRATION_IS_NOT_SUPPORTED);
}
// check cpuPinning if the check haven't failed yet
if (!validate(isCpuPinningValid(vmFromParams.getCpuPinning(), vmFromParams.getStaticData()))) {
return false;
}
if (vmFromParams.isUseHostCpuFlags() && vmFromParams.getMigrationSupport() != MigrationSupport.PINNED_TO_HOST) {
return failValidation(EngineMessage.VM_HOSTCPU_MUST_BE_PINNED_TO_HOST);
}
if (vmFromParams.isUseHostCpuFlags() && (ArchitectureType.ppc == getCluster().getArchitecture().getFamily())) {
return failValidation(EngineMessage.USE_HOST_CPU_REQUESTED_ON_UNSUPPORTED_ARCH);
}
if (!validateMemoryAlignment(getParameters().getVmStaticData())) {
return false;
}
if (getInstanceTypeId() != null && getInstanceType() == null) {
// invalid instance type
return failValidation(EngineMessage.ACTION_TYPE_FAILED_INSTANCE_TYPE_DOES_NOT_EXIST);
}
if (imageTypeId != null && getImageType() == null) {
// invalid image type
return failValidation(EngineMessage.ACTION_TYPE_FAILED_IMAGE_TYPE_DOES_NOT_EXIST);
}
if (!validate(VmValidator.validateCpuSockets(getParameters().getVmStaticData(), getEffectiveCompatibilityVersion()))) {
return false;
}
if (!isCpuSharesValid(vmFromParams)) {
return failValidation(EngineMessage.QOS_CPU_SHARES_OUT_OF_RANGE);
}
if (!VmCpuCountHelper.validateCpuCounts(vmFromParams)) {
return failValidation(EngineMessage.TOO_MANY_CPU_COMPONENTS);
}
if (Boolean.TRUE.equals(getParameters().isVirtioScsiEnabled())) {
// Verify OS compatibility
if (!validate(vmHandler.isOsTypeSupportedForVirtioScsi(vmFromParams.getOs(), getEffectiveCompatibilityVersion()))) {
return false;
}
}
if (vmFromParams.getMinAllocatedMem() > vmFromParams.getMemSizeMb()) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_MIN_MEMORY_CANNOT_EXCEED_MEMORY_SIZE);
}
if (!setAndValidateDiskProfiles()) {
return false;
}
if (!setAndValidateCpuProfile()) {
return false;
}
if (getVmId() != null && vmStaticDao.get(getVmId()) != null) {
return failValidation(EngineMessage.VM_ID_EXISTS);
}
List<CinderDisk> cinderDisks = DisksFilter.filterCinderDisks(diskInfoDestinationMap.values());
CinderDisksValidator cinderDisksValidator = new CinderDisksValidator(cinderDisks);
if (!validate(cinderDisksValidator.validateCinderDiskLimits())) {
return false;
}
if (getParameters().getVmLargeIcon() != null && !validate(IconValidator.validate(IconValidator.DimensionsType.LARGE_CUSTOM_ICON, getParameters().getVmLargeIcon()))) {
return false;
}
if (getSmallIconId() != null && // icon id is ignored if large icon is sent
getParameters().getVmLargeIcon() == null && !validate(IconValidator.validateIconId(getSmallIconId(), "Small"))) {
return false;
}
if (getLargeIconId() != null && // icon id is ignored if large icon is sent
getParameters().getVmLargeIcon() == null && !validate(IconValidator.validateIconId(getLargeIconId(), "Large"))) {
return false;
}
if (!validate(getNumaValidator().checkVmNumaNodesIntegrity(getParameters().getVm(), getParameters().getVm().getvNumaNodeList()))) {
return false;
}
if (getCluster().isInUpgradeMode()) {
getParameters().getVm().setClusterCompatibilityVersion(getCluster().getCompatibilityVersion());
if (!validate(getClusterUpgradeValidator().isVmReadyForUpgrade(getParameters().getVm()))) {
return false;
}
}
if (!validate(vmHandler.validateMaxMemorySize(getParameters().getVmStaticData(), getEffectiveCompatibilityVersion()))) {
return false;
}
if (shouldAddLease(getParameters().getVmStaticData()) && !canAddLease()) {
return false;
}
List<EngineMessage> msgs = openStackMetadataAdapter.validate(getParameters().getVmStaticData().getVmInit());
if (!CollectionUtils.isEmpty(msgs)) {
return failValidation(msgs);
}
return true;
}
use of org.ovirt.engine.core.common.errors.EngineMessage 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.common.errors.EngineMessage in project ovirt-engine by oVirt.
the class ImportVmTemplateCommand method validate.
@Override
protected boolean validate() {
if (getVmTemplate() == 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 (!getCluster().getStoragePoolId().equals(getStoragePoolId())) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_IS_NOT_VALID);
}
setDescription(getVmTemplateName());
// check that the storage pool is valid
if (!validate(createStoragePoolValidator().existsAndUp()) || !validateTemplateArchitecture() || !isClusterCompatible()) {
return false;
}
// set the source domain and check that it is ImportExport type and active
setSourceDomainId(getParameters().getSourceDomainId());
StorageDomainValidator sourceDomainValidator = new StorageDomainValidator(getSourceDomain());
if (!validate(sourceDomainValidator.isDomainExistAndActive())) {
return false;
}
if ((getSourceDomain().getStorageDomainType() != StorageDomainType.ImportExport) && !getParameters().isImagesExistOnTargetStorageDomain()) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_TYPE_ILLEGAL);
}
if (!getParameters().isImagesExistOnTargetStorageDomain()) {
// Set the template images from the Export domain and change each image id storage is to the import domain
GetAllFromExportDomainQueryParameters tempVar = new GetAllFromExportDomainQueryParameters(getParameters().getStoragePoolId(), getParameters().getSourceDomainId());
QueryReturnValue qretVal = runInternalQuery(QueryType.GetTemplatesFromExportDomain, tempVar);
if (!qretVal.getSucceeded()) {
return false;
}
Map<VmTemplate, List<DiskImage>> templates = qretVal.getReturnValue();
ArrayList<DiskImage> images = new ArrayList<>();
for (Map.Entry<VmTemplate, List<DiskImage>> entry : templates.entrySet()) {
if (entry.getKey().getId().equals(getVmTemplate().getId())) {
images = new ArrayList<>(entry.getValue());
getVmTemplate().setInterfaces(entry.getKey().getInterfaces());
getVmTemplate().setOvfVersion(entry.getKey().getOvfVersion());
break;
}
}
getParameters().setImages(images);
getVmTemplate().setImages(images);
ensureDomainMap(getImages(), getParameters().getDestDomainId());
HashMap<Guid, DiskImage> imageMap = new HashMap<>();
for (DiskImage image : images) {
if (Guid.Empty.equals(image.getVmSnapshotId())) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CORRUPTED_VM_SNAPSHOT_ID);
}
StorageDomain storageDomain = getStorageDomain(imageToDestinationDomainMap.get(image.getId()));
StorageDomainValidator validator = new StorageDomainValidator(storageDomain);
if (!validate(validator.isDomainExistAndActive()) || !validate(validator.domainIsValidDestination())) {
return false;
}
StorageDomainStatic targetDomain = storageDomain.getStorageStaticData();
changeRawToCowIfSparseOnBlockDevice(targetDomain.getStorageType(), image);
if (!ImagesHandler.checkImageConfiguration(targetDomain, image, getReturnValue().getValidationMessages())) {
return false;
}
image.setStoragePoolId(getParameters().getStoragePoolId());
image.setStorageIds(new ArrayList<>(Collections.singletonList(storageDomain.getId())));
imageMap.put(image.getImageId(), image);
}
getVmTemplate().setDiskImageMap(imageMap);
}
sourceTemplateId = getVmTemplateId();
if (getParameters().isImportAsNewEntity()) {
initImportClonedTemplate();
}
VmTemplate duplicateTemplate = vmTemplateDao.get(getParameters().getVmTemplate().getId());
// check that the template does not exists in the target domain
if (duplicateTemplate != null) {
return failValidation(EngineMessage.VMT_CANNOT_IMPORT_TEMPLATE_EXISTS, String.format("$TemplateName %1$s", duplicateTemplate.getName()));
}
if (getVmTemplate().isBaseTemplate() && isVmTemplateWithSameNameExist()) {
return failValidation(EngineMessage.VM_CANNOT_IMPORT_TEMPLATE_NAME_EXISTS);
}
if (!validateNoDuplicateDiskImages(getImages())) {
return false;
}
if (getImages() != null && !getImages().isEmpty() && !getParameters().isImagesExistOnTargetStorageDomain()) {
if (!validateSpaceRequirements(getImages())) {
return false;
}
}
List<VmNetworkInterface> vmNetworkInterfaces = getVmTemplate().getInterfaces();
vmNicMacsUtils.replaceInvalidEmptyStringMacAddressesWithNull(vmNetworkInterfaces);
if (!validate(vmNicMacsUtils.validateMacAddress(vmNetworkInterfaces))) {
return false;
}
// if this is a template version, check base template exist
if (!getVmTemplate().isBaseTemplate()) {
VmTemplate baseTemplate = vmTemplateDao.get(getVmTemplate().getBaseTemplateId());
if (baseTemplate == null) {
return failValidation(EngineMessage.VMT_CANNOT_IMPORT_TEMPLATE_VERSION_MISSING_BASE);
}
}
if (!setAndValidateDiskProfiles()) {
return false;
}
if (!setAndValidateCpuProfile()) {
return false;
}
if (!validate(vmHandler.validateMaxMemorySize(getVmTemplate(), getEffectiveCompatibilityVersion()))) {
return false;
}
List<EngineMessage> msgs = openStackMetadataAdapter.validate(getVmTemplate().getVmInit());
if (!CollectionUtils.isEmpty(msgs)) {
return failValidation(msgs);
}
return true;
}
use of org.ovirt.engine.core.common.errors.EngineMessage in project ovirt-engine by oVirt.
the class MoveMacsTest method canMigrateMacsToAnotherMacPoolWithMultipleClusters.
@Test
public void canMigrateMacsToAnotherMacPoolWithMultipleClusters() {
// we are testing 4 clusters at once, their macs to be moved has to be merged and processed at once.
// cluster 2 and 4 will be ignored, because migration targetMacPoolId->targetMacPoolId will be skipped.
// therefore we are actually migrating only 2 cluster, among them there's duplicate mac1 to be migrated, which
// should be blocked, since targetMacPoolId disallows duplicates.
List<Cluster> clusters = Arrays.asList(createClusterAndMockMacs(sourceMacPoolId, Collections.singletonList("mac1")), createClusterAndMockMacs(targetMacPoolId, Collections.singletonList("mac2")), createClusterAndMockMacs(sourceMacPoolId, Collections.singletonList("mac1")), createClusterAndMockMacs(targetMacPoolId, Collections.singletonList("mac2")));
EngineMessage engineMessage = ACTION_TYPE_FAILED_CANNOT_MIGRATE_MACS_DUE_TO_DUPLICATES;
Collection<String> replacements = ReplacementUtils.getListVariableAssignmentString(engineMessage, Collections.singleton("mac1"));
assertThat(underTest.canMigrateMacsToAnotherMacPool(clusters, targetMacPoolId), ValidationResultMatchers.failsWith(engineMessage, replacements));
}
use of org.ovirt.engine.core.common.errors.EngineMessage in project ovirt-engine by oVirt.
the class NetworkAttachmentValidatorTest method testNetworkExistWhenOnlyNetworkNameIsSet.
@Test
public void testNetworkExistWhenOnlyNetworkNameIsSet() {
NetworkAttachment networkAttachment = new NetworkAttachment();
networkAttachment.setNetworkName(NETWORK_NAME);
NetworkAttachmentValidator validator = createNetworkAttachmentValidator(networkAttachment);
EngineMessage engineMessage = EngineMessage.NETWORK_HAVING_NAME_NOT_EXISTS;
assertThat(validator.networkExists(), failsWith(engineMessage, ReplacementUtils.getVariableAssignmentString(engineMessage, NETWORK_NAME)));
}
Aggregations