Maor Lipchuk has uploaded a new change for review.

Change subject: core: Use storage helper to fetch (related to BZ882825)
......................................................................

core: Use storage helper to fetch (related to BZ882825)

Added engine support for connecting LUN with multiple connections of different
storage types.

Change-Id: Ida526dd9e08bc9881e65a529cb1b00aee0786af1
Signed-off-by: Maor Lipchuk <mlipc...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AbstractDiskVmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/ISCSIStorageHelper.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/StorageHelperBase.java
A 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/storage/StorageHelperBaseTest.java
4 files changed, 127 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/41/10141/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AbstractDiskVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AbstractDiskVmCommand.java
index 1ff1caf..c925ba9 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AbstractDiskVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AbstractDiskVmCommand.java
@@ -4,6 +4,8 @@
 import java.util.List;
 import java.util.Map;
 
+import org.ovirt.engine.core.bll.storage.IStorageHelper;
+import org.ovirt.engine.core.bll.storage.StorageHelperBase;
 import org.ovirt.engine.core.bll.storage.StorageHelperDirector;
 import org.ovirt.engine.core.common.action.VmDiskOperatinParameterBase;
 import org.ovirt.engine.core.common.businessentities.Disk;
@@ -53,13 +55,15 @@
             if (commandType == VDSCommandType.HotPlugDisk) {
                 LUNs lun = lunDisk.getLun();
                 updateLUNConnectionsInfo(lun);
-                if (!StorageHelperDirector.getInstance()
-                        .getItem(getLUNStorageType(lun))
-                        .connectStorageToLunByVdsId(null,
-                                getVm().getRunOnVds().getValue(),
-                                lun,
-                                getVm().getStoragePoolId())) {
-                    throw new 
VdcBLLException(VdcBllErrors.StorageServerConnectionError);
+                Map<StorageType, List<storage_server_connections>> 
lunsByStorageType =
+                        StorageHelperBase.filterLUNsByStorageType(lun);
+                for (StorageType storageType : lunsByStorageType.keySet()) {
+                    if 
(!getStorageHelper(storageType).connectStorageToLunByVdsId(null,
+                            getVm().getRunOnVds().getValue(),
+                            lun,
+                            getVm().getStoragePoolId())) {
+                        throw new 
VdcBLLException(VdcBllErrors.StorageServerConnectionError);
+                    }
                 }
             }
         }
@@ -67,6 +71,10 @@
                 getVm().getId(), disk, vmDevice));
     }
 
+    private IStorageHelper getStorageHelper(StorageType storageType) {
+        return StorageHelperDirector.getInstance().getItem(storageType);
+    }
+
     /**
      * If the LUN has no connections we assume that it is FCP storage type, 
since FCP does not have connections,
      * otherwise, we return the storage type of the first connection
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/ISCSIStorageHelper.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/ISCSIStorageHelper.java
index 36afe34..c48d23a 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/ISCSIStorageHelper.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/ISCSIStorageHelper.java
@@ -21,8 +21,6 @@
 import org.ovirt.engine.core.utils.linq.Function;
 import org.ovirt.engine.core.utils.linq.LinqUtils;
 import org.ovirt.engine.core.utils.linq.Predicate;
-import org.ovirt.engine.core.utils.log.Log;
-import org.ovirt.engine.core.utils.log.LogFactory;
 
 public class ISCSIStorageHelper extends StorageHelperBase {
 
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/StorageHelperBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/StorageHelperBase.java
index d625ab4..56eef91 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/StorageHelperBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/StorageHelperBase.java
@@ -1,6 +1,8 @@
 package org.ovirt.engine.core.bll.storage;
 
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -8,6 +10,7 @@
 import org.ovirt.engine.core.common.AuditLogType;
 import org.ovirt.engine.core.common.action.VdcActionType;
 import org.ovirt.engine.core.common.businessentities.LUNs;
+import org.ovirt.engine.core.common.businessentities.StorageType;
 import org.ovirt.engine.core.common.businessentities.VDS;
 import org.ovirt.engine.core.common.businessentities.storage_domain_static;
 import org.ovirt.engine.core.common.businessentities.storage_domains;
@@ -123,6 +126,19 @@
         return true;
     }
 
+    public static Map<StorageType, List<storage_server_connections>> 
filterLUNsByStorageType(LUNs lun) {
+        Map<StorageType, List<storage_server_connections>> 
storageConnectionsForStorageTypeMap =
+                new HashMap<StorageType, List<storage_server_connections>>();
+        for (storage_server_connections lunConnections : 
lun.getLunConnections()) {
+            StorageType storageType = lunConnections.getstorage_type();
+            if (!storageConnectionsForStorageTypeMap.containsKey(storageType)) 
{
+                storageConnectionsForStorageTypeMap.put(storageType, new 
ArrayList<storage_server_connections>());
+            }
+            
storageConnectionsForStorageTypeMap.get(storageType).add(lunConnections);
+        }
+        return storageConnectionsForStorageTypeMap;
+    }
+
     protected static LunDAO getLunDao() {
         return DbFacade.getInstance().getLunDao();
     }
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/storage/StorageHelperBaseTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/storage/StorageHelperBaseTest.java
new file mode 100644
index 0000000..3336d61
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/storage/StorageHelperBaseTest.java
@@ -0,0 +1,96 @@
+package org.ovirt.engine.core.bll.storage;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+import org.ovirt.engine.core.common.businessentities.LUNs;
+import org.ovirt.engine.core.common.businessentities.StorageType;
+import 
org.ovirt.engine.core.common.businessentities.storage_server_connections;
+
+public class StorageHelperBaseTest {
+
+    @Test
+    public void getLunConnectionsForFC() {
+        LUNs lun = new LUNs();
+        ArrayList<storage_server_connections> connections = new 
ArrayList<storage_server_connections>();
+        lun.setLunConnections(connections);
+        Map<StorageType, List<storage_server_connections>> connectionsByType =
+                StorageHelperBase.filterLUNsByStorageType(lun);
+        assertTrue("Map of storage connections should be empty.", 
connectionsByType.isEmpty());
+    }
+
+    @Test
+    public void getLunConnectionsForISCSI() {
+        LUNs lun = new LUNs();
+        ArrayList<storage_server_connections> connections = new 
ArrayList<storage_server_connections>();
+        connections.add(new storage_server_connections("Some LUN connection",
+                "id",
+                "iqn",
+                "password",
+                StorageType.ISCSI,
+                "Username",
+                "port",
+                "portal"));
+        connections.add(new storage_server_connections("Other LUN connection",
+                "id",
+                "iqn",
+                "password",
+                StorageType.ISCSI,
+                "Username",
+                "port",
+                "portal"));
+
+        lun.setLunConnections(connections);
+        Map<StorageType, List<storage_server_connections>> connectionsByType =
+                StorageHelperBase.filterLUNsByStorageType(lun);
+        assertTrue("Map of ISCSI storage connections should not be empty.", 
!connectionsByType.isEmpty());
+        assertEquals("Map of ISCSI storage connections should have only one 
type of connections.",
+                1,
+                connectionsByType.size());
+        assertEquals("Map of ISCSI storage connections should have only 2 
ISCSI connections.",
+                2,
+                connectionsByType.get(StorageType.ISCSI).size());
+    }
+
+    @Test
+    public void getMixedLunConnections() {
+        LUNs lun = new LUNs();
+        ArrayList<storage_server_connections> connections = new 
ArrayList<storage_server_connections>();
+        connections.add(new storage_server_connections("Some LUN connection",
+                "id",
+                "iqn",
+                "password",
+                StorageType.ISCSI,
+                "Username",
+                "port",
+                "portal"));
+        // Connection for FCP is only for testing, since FCP should not have 
connections.
+        connections.add(new storage_server_connections("Other LUN connection",
+                "id",
+                "iqn",
+                "password",
+                StorageType.FCP,
+                "Username",
+                "port",
+                "portal"));
+
+        lun.setLunConnections(connections);
+        Map<StorageType, List<storage_server_connections>> connectionsByType =
+                StorageHelperBase.filterLUNsByStorageType(lun);
+        assertTrue("Map of storage connections should not be empty.", 
!connectionsByType.isEmpty());
+        assertEquals("Map of storage connections should have only two types of 
connections.",
+                2,
+                connectionsByType.size());
+        assertEquals("Map of ISCSI storage connections should have only 1 
ISCSI connections.",
+                1,
+                connectionsByType.get(StorageType.ISCSI).size());
+        assertEquals("Map of FCP storage connections should have only 1 FCP 
connections.",
+                1,
+                connectionsByType.get(StorageType.FCP).size());
+    }
+}


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

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

Reply via email to