Mike Kolesnik has uploaded a new change for review.

Change subject: engine: Add validator for NetworkCluster
......................................................................

engine: Add validator for NetworkCluster

This validator will hold checks that are necessary to perform on this
entity, such as making sure the management network attachment is valid.

Change-Id: Iba58dfbd9950176ba26790ff6a50244d554fd9b3
Signed-off-by: Mike Kolesnik <[email protected]>
---
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/cluster/NetworkClusterValidator.java
A 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/network/cluster/NetworkClusterValidatorTest.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/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
7 files changed, 74 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/36/11836/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/cluster/NetworkClusterValidator.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/cluster/NetworkClusterValidator.java
new file mode 100644
index 0000000..c028c74
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/cluster/NetworkClusterValidator.java
@@ -0,0 +1,30 @@
+package org.ovirt.engine.core.bll.network.cluster;
+
+import org.ovirt.engine.core.bll.ValidationResult;
+import org.ovirt.engine.core.common.businessentities.network.NetworkCluster;
+import org.ovirt.engine.core.dal.VdcBllMessages;
+
+/**
+ * Validator class for {@link NetworkCluster} instances.
+ */
+public class NetworkClusterValidator {
+    protected static final String NETWORK_NAME_REPLACEMENT = "$NetworkName %s";
+    private NetworkCluster networkCluster;
+
+    public NetworkClusterValidator(NetworkCluster networkCluster) {
+        this.networkCluster = networkCluster;
+    }
+
+    /**
+     * Make sure the management network attachment is valid: The network must 
be required.
+     *
+     * @param networkName
+     *            The network's name.
+     * @return Error iff the management network attachment is not valid.
+     */
+    public ValidationResult managementNetworkAttachment(String networkName) {
+        return networkCluster.isRequired() ? ValidationResult.VALID
+                : new 
ValidationResult(VdcBllMessages.ACTION_TYPE_FAILED_MANAGEMENT_NETWORK_REQUIRED,
+                        String.format(NETWORK_NAME_REPLACEMENT, networkName));
+    }
+}
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/network/cluster/NetworkClusterValidatorTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/network/cluster/NetworkClusterValidatorTest.java
new file mode 100644
index 0000000..c0942cf
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/network/cluster/NetworkClusterValidatorTest.java
@@ -0,0 +1,37 @@
+package org.ovirt.engine.core.bll.network.cluster;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.ovirt.engine.core.bll.ValidationResult;
+import org.ovirt.engine.core.common.businessentities.network.NetworkCluster;
+import org.ovirt.engine.core.dal.VdcBllMessages;
+import org.ovirt.engine.core.utils.RandomUtils;
+
+public class NetworkClusterValidatorTest {
+
+    private static final String NETWORK_NAME = 
RandomUtils.instance().nextString(
+            RandomUtils.instance().nextInt(1, 10));
+
+    private static final String NETWORK_NAME_REPLACEMENT = String.format(
+            NetworkClusterValidator.NETWORK_NAME_REPLACEMENT, NETWORK_NAME);
+
+    private NetworkCluster networkCluster = new NetworkCluster();
+
+    private NetworkClusterValidator validator = new 
NetworkClusterValidator(networkCluster);
+
+    @Test
+    public void managementNetworkAttachmentValid() throws Exception {
+        networkCluster.setRequired(true);
+
+        assertEquals(ValidationResult.VALID, 
validator.managementNetworkAttachment(NETWORK_NAME));
+    }
+
+    @Test
+    public void managementNetworkAttachmentInvalid() throws Exception {
+        networkCluster.setRequired(false);
+
+        assertEquals(new 
ValidationResult(VdcBllMessages.ACTION_TYPE_FAILED_MANAGEMENT_NETWORK_REQUIRED, 
NETWORK_NAME_REPLACEMENT),
+                validator.managementNetworkAttachment(NETWORK_NAME));
+    }
+}
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
index 60dbad8..53dc3be 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
@@ -435,6 +435,7 @@
     NON_VM_NETWORK_CANNOT_SUPPORT_STP,
     NETWORK_MTU_DIFFERENCES,
     NETWORK_MTU_OVERRIDE_NOT_SUPPORTED,
+    ACTION_TYPE_FAILED_MANAGEMENT_NETWORK_REQUIRED,
     ACTION_TYPE_FAILED_STORAGE_DOMAIN_NOT_IN_STORAGE_POOL,
     ACTION_TYPE_FAILED_STORAGE_POOL_NOT_EXIST,
     ACTION_TYPE_FAILED_STORAGE_DOMAIN_NOT_EXIST,
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 e5c93bb..642d551 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
@@ -458,6 +458,7 @@
 NON_VM_NETWORK_CANNOT_SUPPORT_STP=Cannot ${action} ${type}. STP can only be 
enabled on VM Networks.
 NETWORK_MTU_DIFFERENCES=Cannot ${action} ${type}. The following Logical 
Networks don't have the same MTU value: ${NETWORK_MTU_DIFFERENCES_LIST}.
 NETWORK_MTU_OVERRIDE_NOT_SUPPORTED=Cannot ${action} ${type}. Overriding MTU is 
not supported for this Data Center's compatibility version.
+ACTION_TYPE_FAILED_MANAGEMENT_NETWORK_REQUIRED=Cannot ${action} ${type}. The 
management network '${NetworkName}' must be required, please change the network 
to be required and try again.
 CANNOT_PREIEW_CURRENT_IMAGE=The currently used VM Snapshot Image cannot be 
used in Preview command.
 CONFIG_UNKNOWN_KEY=Illegal configuration entry.\n\
        -Please check configuration entry name.
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 d32d2b5..ab208fa 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
@@ -1233,6 +1233,9 @@
     @DefaultStringValue("Cannot ${action} ${type}. Overriding MTU is not 
supported for this Data Center's compatibility version.")
     String NETWORK_MTU_OVERRIDE_NOT_SUPPORTED();
 
+    @DefaultStringValue("Cannot ${action} ${type}. The management network 
'${NetworkName}' must be required, please change the network to be required and 
try again.")
+    String ACTION_TYPE_FAILED_MANAGEMENT_NETWORK_REQUIRED();
+
     @DefaultStringValue("The currently used VM Snapshot Image cannot be used 
in Preview command.")
     String CANNOT_PREIEW_CURRENT_IMAGE();
 
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 b51afad..6d41d1b 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
@@ -454,6 +454,7 @@
 NON_VM_NETWORK_CANNOT_SUPPORT_STP=Cannot ${action} ${type}. STP can only be 
enabled on VM Networks.
 NETWORK_MTU_DIFFERENCES=Cannot ${action} ${type}. The following Logical 
Networks don't have the same MTU value: ${NETWORK_MTU_DIFFERENCES_LIST}.
 NETWORK_MTU_OVERRIDE_NOT_SUPPORTED=Cannot ${action} ${type}. Overriding MTU is 
not supported for this Data Center's compatibility version.
+ACTION_TYPE_FAILED_MANAGEMENT_NETWORK_REQUIRED=Cannot ${action} ${type}. The 
management network '${NetworkName}' must be required, please change the network 
to be required and try again.
 CANNOT_PREIEW_CURRENT_IMAGE=The currently used VM Snapshot Image cannot be 
used in Preview command.
 CONFIG_UNKNOWN_KEY=Illegal configuration entry.\n\
        -Please check configuration entry name.
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 b768016..9764589 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
@@ -452,6 +452,7 @@
 NON_VM_NETWORK_CANNOT_SUPPORT_STP=Cannot ${action} ${type}. STP can only be 
enabled on VM Networks.
 NETWORK_MTU_DIFFERENCES=Cannot ${action} ${type}. The following Logical 
Networks don't have the same MTU value: ${NETWORK_MTU_DIFFERENCES_LIST}.
 NETWORK_MTU_OVERRIDE_NOT_SUPPORTED=Cannot ${action} ${type}. Overriding MTU is 
not supported for this Data Center's compatibility version.
+ACTION_TYPE_FAILED_MANAGEMENT_NETWORK_REQUIRED=Cannot ${action} ${type}. The 
management network '${NetworkName}' must be required, please change the network 
to be required and try again.
 CANNOT_PREIEW_CURRENT_IMAGE=The currently used VM Snapshot Image cannot be 
used in Preview command.
 CONFIG_UNKNOWN_KEY=Illegal configuration entry.\n\
        -Please check configuration entry name.


--
To view, visit http://gerrit.ovirt.org/11836
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iba58dfbd9950176ba26790ff6a50244d554fd9b3
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Mike Kolesnik <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to