Allon Mureinik has uploaded a new change for review.

Change subject: core: Introducing VersionStorageFormatUtil
......................................................................

core: Introducing VersionStorageFormatUtil

Introduced a new utility class, VersionStorageFormatUtil, to handle the
relationship between Version and StorageFormatType.

This patch includes the following:
1. The new VersionStorageFormatUtil class.
2. A test case for this class.
3. Refactoring UpdateStoragePoolCommand to use this new class.

Change-Id: I47fb8b14e5c97b601c8fc0cc296a4ec42a48227a
Signed-off-by: Allon Mureinik <amure...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/UpdateStoragePoolCommand.java
A 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VersionStorageFormatUtil.java
A 
backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/VersionStorageFormatUtilTest.java
3 files changed, 52 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/97/18697/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/UpdateStoragePoolCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/UpdateStoragePoolCommand.java
index 9c1b812..8d7b2ce 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/UpdateStoragePoolCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/UpdateStoragePoolCommand.java
@@ -21,6 +21,7 @@
 import org.ovirt.engine.core.common.errors.VdcBLLException;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
 import org.ovirt.engine.core.common.interfaces.VDSBrokerFrontend;
+import org.ovirt.engine.core.common.utils.VersionStorageFormatUtil;
 import 
org.ovirt.engine.core.common.vdscommands.SetStoragePoolDescriptionVDSCommandParameters;
 import 
org.ovirt.engine.core.common.vdscommands.UpgradeStoragePoolVDSCommandParameters;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
@@ -91,22 +92,12 @@
         final Guid spId = storagePool.getId();
         final Version spVersion = storagePool.getcompatibility_version();
         final Version oldSpVersion = 
_oldStoragePool.getcompatibility_version();
-        final StorageFormatType targetFormat;
 
         if (Version.OpEquality(spVersion, oldSpVersion)) {
             return;
         }
 
-        // TODO: The entire version -> format type scheme should be moved to a 
place
-        // when everyone can utilize it.
-        if (spVersion.compareTo(Version.v3_0) == 0) {
-            targetFormat = StorageFormatType.V2;
-        } else if (spVersion.compareTo(Version.v3_1) >= 0) {
-            targetFormat = StorageFormatType.V3;
-        } else {
-            targetFormat = StorageFormatType.V1;
-        }
-
+        final StorageFormatType targetFormat = 
VersionStorageFormatUtil.getFormatForVersion(spVersion);
         StorageType spType = storagePool.getStorageType();
         if (targetFormat == StorageFormatType.V2 && !spType.isBlockDomain()) {
             // There is no format V2 for domains that aren't ISCSI/FCP
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VersionStorageFormatUtil.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VersionStorageFormatUtil.java
new file mode 100644
index 0000000..d3c32c8
--- /dev/null
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VersionStorageFormatUtil.java
@@ -0,0 +1,26 @@
+package org.ovirt.engine.core.common.utils;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.ovirt.engine.core.common.businessentities.StorageFormatType;
+import org.ovirt.engine.core.compat.Version;
+
+/**
+ * A utility function to match between {@link Version}s and {@link 
StorageFormatType}s
+ */
+public class VersionStorageFormatUtil {
+    private static final Map<Version, StorageFormatType> versionToFormat = new 
HashMap<Version, StorageFormatType>() {
+        {
+            put(Version.v2_2, StorageFormatType.V1);
+            put(Version.v3_0, StorageFormatType.V2);
+            put(Version.v3_1, StorageFormatType.V3);
+            put(Version.v3_2, StorageFormatType.V3);
+            put(Version.v3_3, StorageFormatType.V3);
+        }
+    };
+
+    public static StorageFormatType getFormatForVersion(Version v) {
+        return versionToFormat.get(v);
+    }
+}
diff --git 
a/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/VersionStorageFormatUtilTest.java
 
b/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/VersionStorageFormatUtilTest.java
new file mode 100644
index 0000000..c8096fa
--- /dev/null
+++ 
b/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/VersionStorageFormatUtilTest.java
@@ -0,0 +1,24 @@
+package org.ovirt.engine.core.common.utils;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.experimental.theories.DataPoints;
+import org.junit.experimental.theories.Theories;
+import org.junit.experimental.theories.Theory;
+import org.junit.runner.RunWith;
+import org.ovirt.engine.core.compat.Version;
+
+/**
+ * A test case for {@link VersionStorageFormatUtil}. This test was put in 
place to ensure that no new entries would be
+ * added to {@link Version#ALL} without {@link VersionStorageFormatUtil} being 
updated.
+ */
+@RunWith(Theories.class)
+public class VersionStorageFormatUtilTest {
+    @DataPoints
+    public static final Version[] versions = Version.ALL.toArray(new 
Version[Version.ALL.size()]);
+
+    @Theory
+    public void versionHasMatchingFormat(Version v) {
+        assertNotNull("Missing format for version " + v, 
VersionStorageFormatUtil.getFormatForVersion(v));
+    }
+}


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I47fb8b14e5c97b601c8fc0cc296a4ec42a48227a
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Allon Mureinik <amure...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to