Moti Asayag has uploaded a new change for review. Change subject: engine: Add VnicProfileValidator ......................................................................
engine: Add VnicProfileValidator The patch adds a validator class for constrains required by the vnic profile command. Change-Id: I6af74a398d1d7ffb97a1802305c56ad536acb346 Signed-off-by: Moti Asayag <masa...@redhat.com> --- A backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VnicProfileValidator.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java M backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties M frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java M frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties M frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties 6 files changed, 125 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/87/16887/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VnicProfileValidator.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VnicProfileValidator.java new file mode 100644 index 0000000..c570979 --- /dev/null +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VnicProfileValidator.java @@ -0,0 +1,104 @@ +package org.ovirt.engine.core.bll.validator; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.apache.commons.lang.ObjectUtils; +import org.ovirt.engine.core.bll.ValidationResult; +import org.ovirt.engine.core.common.businessentities.VM; +import org.ovirt.engine.core.common.businessentities.VMStatus; +import org.ovirt.engine.core.common.businessentities.network.Network; +import org.ovirt.engine.core.common.businessentities.network.VnicProfile; +import org.ovirt.engine.core.common.errors.VdcBllMessages; +import org.ovirt.engine.core.dal.dbbroker.DbFacade; +import org.ovirt.engine.core.utils.ReplacementUtils; + +public class VnicProfileValidator { + + private VnicProfile vnicProfile; + private VnicProfile oldVnicProfile; + private Network network; + private List<VnicProfile> vnicProfiles; + + public VnicProfileValidator(VnicProfile vnicProfile) { + this.vnicProfile = vnicProfile; + } + + protected DbFacade getDbFacade() { + return DbFacade.getInstance(); + } + + public ValidationResult vnicProfileIsSet() { + return vnicProfile == null + ? new ValidationResult(VdcBllMessages.NETWORK_NOT_EXISTS) + : ValidationResult.VALID; + } + + public ValidationResult vnicProfileExists() { + return getOldVnicProfile() == null + ? new ValidationResult(VdcBllMessages.VNIC_PROFILE_NOT_EXISTS) + : ValidationResult.VALID; + } + + public ValidationResult networkExists() { + return getNetwork() == null + ? new ValidationResult(VdcBllMessages.NETWORK_NOT_EXISTS) + : ValidationResult.VALID; + } + + public ValidationResult vnicProfileNameNotUsed() { + for (VnicProfile profile : getVnicProfiles()) { + if (profile.getName().equals(vnicProfile.getName())) { + return new ValidationResult(VdcBllMessages.VNIC_PROFILE_NAME_IN_USE); + } + } + + return ValidationResult.VALID; + } + + public ValidationResult changingNetworkAllowed() { + if (!ObjectUtils.equals(vnicProfile.getNetworkId(), getOldVnicProfile().getNetworkId())) { + List<VM> vms = getDbFacade().getVmDao().getAllForVnicProfile(vnicProfile.getId()); + List<VM> vmUsingProfile = new ArrayList<>(); + for (VM vm : vms) { + if (vm.getStatus() != VMStatus.Down) { + vmUsingProfile.add(vm); + } + } + + if (!vmUsingProfile.isEmpty()) { + Collection<String> replacements = + ReplacementUtils.replaceWithNameable("ENTITIES_USING_VNIC_PROFILE", vmUsingProfile); + replacements.add(VdcBllMessages.VAR__ENTITIES__VMS.name()); + return new ValidationResult(VdcBllMessages.VNIC_PROFILE_IN_USE, replacements); + } + } + + return ValidationResult.VALID; + } + + protected Network getNetwork() { + if (network == null) { + network = getDbFacade().getNetworkDao().get(vnicProfile.getNetworkId()); + } + + return network; + } + + protected List<VnicProfile> getVnicProfiles() { + if (vnicProfiles == null) { + vnicProfiles = getDbFacade().getVnicProfileDao().getAllForNetwork(vnicProfile.getNetworkId()); + } + + return vnicProfiles; + } + + protected VnicProfile getOldVnicProfile() { + if (oldVnicProfile == null) { + oldVnicProfile = getDbFacade().getVnicProfileDao().get(vnicProfile.getId()); + } + return oldVnicProfile; + } + +} diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java index 367b3a6..cafa37d 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java @@ -420,6 +420,9 @@ NETWORK_MTU_OVERRIDE_NOT_SUPPORTED(ErrorType.CONFLICT), EXTERNAL_NETWORK_CANNOT_BE_PROVISIONED(ErrorType.NOT_SUPPORTED), ILLEGAL_VNIC_PROFILE_NAME(ErrorType.BAD_PARAMETERS), + VNIC_PROFILE_NOT_EXISTS(ErrorType.BAD_PARAMETERS), + VNIC_PROFILE_NAME_IN_USE(ErrorType.CONFLICT), + VNIC_PROFILE_IN_USE(ErrorType.CONFLICT), ACTION_TYPE_FAILED_MIGRATION_NETWORK_IS_NOT_SUPPORTED(ErrorType.NOT_SUPPORTED), ACTION_TYPE_FAILED_PROVIDER_DOESNT_EXIST(ErrorType.BAD_PARAMETERS), ACTION_TYPE_FAILED_MANAGEMENT_NETWORK_REQUIRED(ErrorType.BAD_PARAMETERS), diff --git a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties index 95f9c33..d9dc1c5 100644 --- a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties +++ b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties @@ -356,6 +356,9 @@ VDS_GROUP_CPU_TYPE_CANNOT_BE_NULL=Cannot add Cluster. CPU type must be specified VDS_GROUP_CANNOT_DO_ACTION_NAME_IN_USE=Cannot ${action} Cluster. Cluster name is already in use. NETWORK_NAME_ALREADY_EXISTS=Cannot ${action} ${type}. Network name already exists. +VNIC_PROFILE_NOT_EXISTS=The specified VM network interface profile doesn't exist. +VNIC_PROFILE_NAME_IN_USE=Cannot ${action} ${type}. The VM network interface profile's name is already used by an existing profile in the same data-center.\n-Please choose a different name. +VNIC_PROFILE_IN_USE=Cannot ${action} ${type}. Several ${entities} (${ENTITIES_USING_VNIC_PROFILE_COUNTER}) are using this VM network interface profile:\n${ENTITIES_USING_VNIC_PROFILE}\n - Please remove it from all ${entities} that are using it and try again. ACTION_TYPE_FAILED_NAME_ALREADY_USED=Cannot ${action} ${type}. The ${type} name is already in use, please choose a unique name and try again. ACTION_TYPE_FAILED_URL_INVALID=Cannot ${action} ${type}. The URL is not valid, please enter a valid URL and try again. ACTION_TYPE_FAILED_STORAGE_CONNECTION_NOT_EXIST=Cannot ${action} ${type}. Storage connection doesn't exist. diff --git a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java index e57f60b..ec158bc 100644 --- a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java +++ b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java @@ -1132,6 +1132,15 @@ @DefaultStringValue("The specified Logical Network doesn't exist.") String NETWORK_NOT_EXISTS(); + @DefaultStringValue("The specified VM network interface profile doesn't exist.") + String VNIC_PROFILE_NOT_EXISTS(); + + @DefaultStringValue("Cannot ${action} ${type}. The VM network interface profile's name is already used by an existing profile in the same data-center.\n-Please choose a different name.") + String VNIC_PROFILE_NAME_IN_USE(); + + @DefaultStringValue("Cannot ${action} ${type}. Several ${entities} (${ENTITIES_USING_VNIC_PROFILE_COUNTER}) are using this VM network interface profile:\n${ENTITIES_USING_VNIC_PROFILE}\n - Please remove it from all ${entities} that are using it and try again.") + String VNIC_PROFILE_IN_USE(); + @DefaultStringValue("The specified external network cannot be configured on the host's interface.") String EXTERNAL_NETWORK_CANNOT_BE_PROVISIONED(); diff --git a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties index 56a511f..78aadae 100644 --- a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties +++ b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties @@ -398,6 +398,9 @@ NETWORK_INTERFACE_ALREADY_HAVE_NETWORK=The Network Interface is already attached to a Logical Network. NETWORK_ALREAY_ATTACH_TO_INTERFACE=Logical Network is already attached to a Network Interface. NETWORK_NOT_EXISTS=The specified Logical Network doesn't exist. +VNIC_PROFILE_NOT_EXISTS=The specified VM network interface profile doesn't exist. +VNIC_PROFILE_NAME_IN_USE=Cannot ${action} ${type}. The VM network interface profile's name is already used by an existing profile in the same data-center.\n-Please choose a different name. +VNIC_PROFILE_IN_USE=Cannot ${action} ${type}. Several ${entities} (${ENTITIES_USING_VNIC_PROFILE_COUNTER}) are using this VM network interface profile:\n${ENTITIES_USING_VNIC_PROFILE}\n - Please remove it from all ${entities} that are using it and try again. EXTERNAL_NETWORK_CANNOT_BE_PROVISIONED=The specified external network cannot be configured on the host's interface. ILLEGAL_VNIC_PROFILE_NAME=Virtual machine network interface profile name must be 1-50 long and can contain only 'A-Z', 'a-z', '0-9', '_' characters. ERROR_CANNOT_RECOVERY_STORAGE_POOL_THERE_IS_ACTIVE_DATA_DOMAINS=Cannot recover Data Center with active Data Storage Domain in Data Center. diff --git a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties index 5c8aeac..6dc2978 100644 --- a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties +++ b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties @@ -361,6 +361,9 @@ VDS_GROUP_CPU_TYPE_CANNOT_BE_NULL=Cannot add Cluster. CPU type must be specified. VDS_GROUP_CANNOT_DO_ACTION_NAME_IN_USE=Cannot ${action} Cluster. Cluster name is already in use. NETWORK_NAME_ALREADY_EXISTS=Cannot ${action} ${type}. Network name already exists. +VNIC_PROFILE_NOT_EXISTS=The specified VM network interface profile doesn't exist. +VNIC_PROFILE_NAME_IN_USE=Cannot ${action} ${type}. The VM network interface profile's name is already used by an existing profile in the same data-center.\n-Please choose a different name. +VNIC_PROFILE_IN_USE=Cannot ${action} ${type}. Several ${entities} (${ENTITIES_USING_VNIC_PROFILE_COUNTER}) are using this VM network interface profile:\n${ENTITIES_USING_VNIC_PROFILE}\n - Please remove it from all ${entities} that are using it and try again. ACTION_TYPE_FAILED_NAME_ALREADY_USED=Cannot ${action} ${type}. The ${type} name is already in use, please choose a unique name and try again. VALIDATION_VDS_CONSOLEADDRESSS_HOSTNAME_OR_IP=Console address must be a FQDN or a valid IP address ACTION_TYPE_FAILED_URL_INVALID=Cannot ${action} ${type}. The URL is not valid, please enter a valid URL and try again. -- To view, visit http://gerrit.ovirt.org/16887 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6af74a398d1d7ffb97a1802305c56ad536acb346 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Moti Asayag <masa...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches