Dhandapani Gopal has uploaded a new change for review.

Change subject: engine: Fix SHD service not displaying issue (#885592)
......................................................................

engine: Fix SHD service not displaying issue (#885592)

To get the service info, the UI will not pass the volume name, in that case
engine will fetch the volume name in the database.

NFS volume name should be passed to get nfs service details, similarly
REPLICATE/DISTRIBUTED_REPLICATE volume name should be passed as an
argument to get the SHD details.

So to get volume name from database engine will do the following steps.
1. Engine will fetch NFS + REPLICATE/DISTRIBUTED_REPLICATE volume name.
2. If not found first the engine will fetch the nfs volume name and then fetch
   REPLICATE/DISTRIBUTED_REPLICATE volume name.
3. The VDS query will be called twice, one with nfs volume name
   and another with replicate volume name, finally combine the service details.

Change-Id: Id11725f44ab3fdd36f76fe569d7610a411518ee1
Bug-Url: https://bugzilla.redhat.com/885592
Signed-off-by: Dhandapani <[email protected]>
---
M backend/manager/dbscripts/gluster_volumes_sp.sql
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GetGlusterVolumeAdvancedDetailsQuery.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDao.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoDbFacadeImpl.java
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoTest.java
5 files changed, 222 insertions(+), 27 deletions(-)


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

diff --git a/backend/manager/dbscripts/gluster_volumes_sp.sql 
b/backend/manager/dbscripts/gluster_volumes_sp.sql
index 73cbb4a..9751fb5 100644
--- a/backend/manager/dbscripts/gluster_volumes_sp.sql
+++ b/backend/manager/dbscripts/gluster_volumes_sp.sql
@@ -98,6 +98,36 @@
 END; $procedure$
 LANGUAGE plpgsql;
 
+
+Create or replace FUNCTION GetGlusterVolumesByOptionAndVolumeType(v_cluster_id 
UUID,
+        v_status VARCHAR(32),
+        v_option_key VARCHAR(8192),
+        v_option_val VARCHAR(8192),
+        v_vol_type VARCHAR(32))
+RETURNS SETOF gluster_volumes
+AS $procedure$
+BEGIN
+RETURN QUERY SELECT *
+FROM  gluster_volumes
+WHERE cluster_id = v_cluster_id AND status = v_status AND vol_type = v_vol_type
+AND id IN (SELECT volume_id FROM gluster_volume_options
+WHERE option_key=v_option_key AND option_val=v_option_val);
+END; $procedure$
+LANGUAGE plpgsql;
+
+Create or replace FUNCTION GetGlusterVolumesByVolumeType(v_cluster_id UUID,
+        v_status VARCHAR(32),
+        v_vol_type VARCHAR(32))
+RETURNS SETOF gluster_volumes
+AS $procedure$
+BEGIN
+RETURN QUERY SELECT *
+FROM  gluster_volumes
+WHERE cluster_id = v_cluster_id AND status = v_status AND vol_type = 
v_vol_type;
+END; $procedure$
+LANGUAGE plpgsql;
+
+
 Create or replace FUNCTION GetGlusterVolumeById(v_volume_id UUID)
     RETURNS SETOF gluster_volumes
     AS $procedure$
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GetGlusterVolumeAdvancedDetailsQuery.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GetGlusterVolumeAdvancedDetailsQuery.java
index 54d7b47..ceeaded 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GetGlusterVolumeAdvancedDetailsQuery.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GetGlusterVolumeAdvancedDetailsQuery.java
@@ -8,6 +8,7 @@
 import org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus;
 import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeAdvancedDetails;
 import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity;
+import org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeType;
 import org.ovirt.engine.core.common.interfaces.VDSBrokerFrontend;
 import 
org.ovirt.engine.core.common.queries.gluster.GlusterVolumeAdvancedDetailsParameters;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
@@ -16,7 +17,7 @@
 import org.ovirt.engine.core.compat.Guid;
 
 /**
- * Query to get given volume advanced details
+ * Query to get volume advanced details
  */
 public class GetGlusterVolumeAdvancedDetailsQuery<P extends 
GlusterVolumeAdvancedDetailsParameters> extends GlusterQueriesCommandBase<P> {
 
@@ -30,19 +31,67 @@
     @Override
     protected void executeQueryCommand() {
         String volumeName = getParameters().getVolumeName();
-        // To get the service info, the UI will not pass the volume name.
-        // In that case engine will fetch the volume name in the database.
+        /*
+         * To get the service info, the UI will not pass the volume name, in 
that case
+         * engine will fetch the volume name in the database.
+         *
+         * NFS volume name should be passed to get nfs service details, 
similarly
+         * REPLICATE/DISTRIBUTED_REPLICATE volume name should be passed as an
+         * argument to get the SHD details.
+         *
+         * So to get volume name from database engine will do the following 
steps.
+         * 1. First fetch NFS + REPLICATE/DISTRIBUTED_REPLICATE volume name
+         * 2. If not found then fetch the nfs volume name and then fetch
+         *    REPLICATE/DISTRIBUTED_REPLICATE volume name
+         * 3. The VDS query will be called twice, one with nfs volume name
+         *    and another with replicate volume name, finally combine the 
service details.
+         */
         if (!getParameters().isDetailRequired() && 
StringUtils.isEmpty(volumeName)) {
-            volumeName = getVolumeName(getParameters().getClusterId());
-        }
+            VDSReturnValue nfsReturnValue = null;
+            String nfsVolumeName = "";
+            String replicateVolumeName = "";
+            // Get Nfs + Replicated/Distributed Replicate volume name.
+            volumeName = 
getNfsReplicateVolumeName(getParameters().getClusterId());
+            if (StringUtils.isEmpty(volumeName)) {
+                // Get Nfs enabled volume name
+                nfsVolumeName = 
getNfsVolumeName(getParameters().getClusterId());
+                // Get Replicated volume name
+                replicateVolumeName = 
getReplicateVolumeName(getParameters().getClusterId());
 
-        // If there is no volume present in the cluster, then retuen empty 
Volume Advanced Details
-        if (StringUtils.isEmpty(volumeName)) {
-            log.error("No volumes found in the cluster.");
-            getQueryReturnValue().setReturnValue(new 
GlusterVolumeAdvancedDetails());
-            return;
-        }
+                // If there is no volume present in the cluster, then return 
empty Volume Advanced Details
+                if (StringUtils.isEmpty(nfsVolumeName) && 
StringUtils.isEmpty(replicateVolumeName)) {
+                    log.error("To get service details, no Nfs or Replicated 
volumes found in the cluster.");
+                    getQueryReturnValue().setReturnValue(new 
GlusterVolumeAdvancedDetails());
+                    return;
+                }
 
+                if (StringUtils.isNotEmpty(nfsVolumeName)) {
+                    nfsReturnValue = executeCommand(nfsVolumeName);
+                }
+                if (nfsReturnValue != null && 
StringUtils.isNotEmpty(replicateVolumeName)) {
+                    // Get shd status value
+                    VDSReturnValue shdStatusReturnValue = 
executeCommand(replicateVolumeName);
+                    GlusterVolumeAdvancedDetails volumeAdvancedDetailsForNfs =
+                            (GlusterVolumeAdvancedDetails) 
nfsReturnValue.getReturnValue();
+                    GlusterVolumeAdvancedDetails volumeAdvancedDetailsForShd =
+                            (GlusterVolumeAdvancedDetails) 
shdStatusReturnValue.getReturnValue();
+                    // combine the Nfs + Shd status
+                    
volumeAdvancedDetailsForNfs.getServiceInfo().addAll(volumeAdvancedDetailsForShd.getServiceInfo());
+                    
getQueryReturnValue().setReturnValue(volumeAdvancedDetailsForNfs);
+                } else if (nfsReturnValue == null && 
StringUtils.isNotEmpty(replicateVolumeName)) {
+                    VDSReturnValue shdReturnValue = 
executeCommand(replicateVolumeName);
+                    
getQueryReturnValue().setReturnValue(shdReturnValue.getReturnValue());
+                } else if (nfsReturnValue != null && 
StringUtils.isEmpty(replicateVolumeName)) {
+                    
getQueryReturnValue().setReturnValue(nfsReturnValue.getReturnValue());
+                }
+            }
+        } else {
+            VDSReturnValue returnValue = executeCommand(volumeName);
+            getQueryReturnValue().setReturnValue(returnValue.getReturnValue());
+        }
+    }
+
+    private VDSReturnValue executeCommand(String volumeName) {
         VDSReturnValue returnValue =
                 
getBackendResourceManager().RunVdsCommand(VDSCommandType.GetGlusterVolumeAdvancedDetails,
                         new 
GlusterVolumeAdvancedDetailsVDSParameters(getUpServerId(getParameters().getClusterId()),
@@ -50,30 +99,74 @@
                                 volumeName,
                                 getParameters().getBrickName(),
                                 getParameters().isDetailRequired()));
-        getQueryReturnValue().setReturnValue(returnValue.getReturnValue());
+        return returnValue;
     }
 
-    private String getVolumeName(Guid clusterId) {
+    private String getReplicateVolumeName(Guid clusterId) {
         String volumeName = "";
-        List<GlusterVolumeEntity> nfsEnabledvolumesList =
-                getGlusterVolumeDao().getVolumesByOption(clusterId, 
GlusterStatus.UP, OPTION_KEY, OPTION_VALUE);
-
-        if (nfsEnabledvolumesList.size() > 0) {
-            volumeName = nfsEnabledvolumesList.get(0).getName();
+        // First fetch replicate volumes
+        List<GlusterVolumeEntity> replicateVolumes = 
getReplicateVolumes(clusterId, GlusterVolumeType.REPLICATE);
+        if (replicateVolumes.size() > 0) {
+            volumeName = replicateVolumes.get(0).getName();
         } else {
-            // If none of the volume is nfs enabled, then fetch any one of the 
volume
-            List<GlusterVolumeEntity> volumesList =
-                    getGlusterVolumeDao().getByClusterId(clusterId);
-            for (GlusterVolumeEntity volume : volumesList) {
-                if (volume.isOnline()) {
-                    volumeName = volume.getName();
-                    break;
-                }
+            // If not found then fetch distribute replicate volumes
+            List<GlusterVolumeEntity> distributedReplicateVolumes =
+                    getReplicateVolumes(clusterId, 
GlusterVolumeType.DISTRIBUTED_REPLICATE);
+            if (distributedReplicateVolumes.size() > 0) {
+                volumeName = distributedReplicateVolumes.get(0).getName();
             }
         }
         return volumeName;
     }
 
+    private String getNfsVolumeName(Guid clusterId) {
+        String volumeName = "";
+        List<GlusterVolumeEntity> nfsVolumes = getNfsVolumes(clusterId);
+        if (nfsVolumes.size() > 0) {
+            volumeName = nfsVolumes.get(0).getName();
+        }
+        return volumeName;
+    }
+
+    private String getNfsReplicateVolumeName(Guid clusterId) {
+        String volumeName = "";
+        // Get nfs enabled and Replicated volumes
+        List<GlusterVolumeEntity> nfsReplicateVolumes =
+                getReplicateAndNfsVolumes(clusterId, 
GlusterVolumeType.REPLICATE);
+        if (nfsReplicateVolumes.size() > 0) {
+            volumeName = nfsReplicateVolumes.get(0).getName();
+        } else {
+            // If not found get nfs enabled and Distributed Replicated volumes
+            List<GlusterVolumeEntity> nfsDistributedReplicateVolumes =
+                    getReplicateAndNfsVolumes(clusterId, 
GlusterVolumeType.DISTRIBUTED_REPLICATE);
+            if (nfsDistributedReplicateVolumes.size() > 0) {
+                volumeName = nfsDistributedReplicateVolumes.get(0).getName();
+            }
+        }
+        return volumeName;
+    }
+
+    private List<GlusterVolumeEntity> getReplicateAndNfsVolumes(Guid 
clusterId, GlusterVolumeType volumeType) {
+        return getGlusterVolumeDao().getVolumesByOptionAndVolumeType(clusterId,
+                GlusterStatus.UP,
+                OPTION_KEY,
+                OPTION_VALUE,
+                volumeType);
+    }
+
+    private List<GlusterVolumeEntity> getNfsVolumes(Guid clusterId) {
+        return getGlusterVolumeDao().getVolumesByOption(clusterId,
+                GlusterStatus.UP,
+                OPTION_KEY,
+                OPTION_VALUE);
+    }
+
+    private List<GlusterVolumeEntity> getReplicateVolumes(Guid clusterId, 
GlusterVolumeType volumeType) {
+        return getGlusterVolumeDao().getVolumesByVolumeType(clusterId,
+                GlusterStatus.UP,
+                volumeType);
+    }
+
     private Guid getUpServerId(Guid clusterId) {
         VDS vds = getClusterUtils().getUpServer(clusterId);
         if (vds == null) {
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDao.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDao.java
index 536e47d..b2845dd 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDao.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDao.java
@@ -6,6 +6,7 @@
 import org.ovirt.engine.core.common.businessentities.gluster.AccessProtocol;
 import org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus;
 import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity;
+import org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeType;
 import org.ovirt.engine.core.common.businessentities.gluster.TransportType;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dao.DAO;
@@ -30,6 +31,16 @@
             String optionKey,
             String optionValue);
 
+    public List<GlusterVolumeEntity> getVolumesByOptionAndVolumeType(Guid 
clusterId,
+            GlusterStatus status,
+            String optionKey,
+            String optionValue,
+            GlusterVolumeType volumeType);
+
+    public List<GlusterVolumeEntity> getVolumesByVolumeType(Guid clusterId,
+            GlusterStatus status,
+            GlusterVolumeType volumeType);
+
     @Override
     public List<GlusterVolumeEntity> getAllWithQuery(String query);
 
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoDbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoDbFacadeImpl.java
index aaf121b..b613c83 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoDbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoDbFacadeImpl.java
@@ -94,6 +94,40 @@
     }
 
     @Override
+    public List<GlusterVolumeEntity> getVolumesByOptionAndVolumeType(Guid 
clusterId,
+            GlusterStatus status,
+            String optionKey,
+            String optionValue,
+            GlusterVolumeType volumeType) {
+        List<GlusterVolumeEntity> volumes =
+                
getCallsHandler().executeReadList("GetGlusterVolumesByOptionAndVolumeType",
+                        volumeRowMapper,
+                        getCustomMapSqlParameterSource()
+                                .addValue("cluster_id", clusterId)
+                                .addValue("status", 
EnumUtils.nameOrNull(status))
+                                .addValue("option_key", optionKey)
+                                .addValue("option_val", optionValue)
+                                .addValue("vol_type", 
EnumUtils.nameOrNull(volumeType)));
+        fetchRelatedEntities(volumes);
+        return volumes;
+    }
+
+    @Override
+    public List<GlusterVolumeEntity> getVolumesByVolumeType(Guid clusterId,
+            GlusterStatus status,
+            GlusterVolumeType volumeType) {
+        List<GlusterVolumeEntity> volumes =
+                
getCallsHandler().executeReadList("GetGlusterVolumesByVolumeType",
+                        volumeRowMapper,
+                        getCustomMapSqlParameterSource()
+                                .addValue("cluster_id", clusterId)
+                                .addValue("status", 
EnumUtils.nameOrNull(status))
+                                .addValue("vol_type", 
EnumUtils.nameOrNull(volumeType)));
+        fetchRelatedEntities(volumes);
+        return volumes;
+    }
+
+    @Override
     public List<GlusterVolumeEntity> getAllWithQuery(String query) {
         List<GlusterVolumeEntity> volumes = new 
SimpleJdbcTemplate(jdbcTemplate).query(query, volumeRowMapper);
         fetchRelatedEntities(volumes);
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoTest.java
index 1d59051..a45d79a 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoTest.java
@@ -31,6 +31,8 @@
     private static final Guid EXISTING_VOL_REPL_ID = new 
Guid("b2cb2f73-fab3-4a42-93f0-d5e4c069a43e");
     private static final String EXISTING_VOL_REPL_NAME = 
"test-vol-replicate-1";
     private static final String NEW_VOL_NAME = "test-new-vol-1";
+    private static final String NFS_OPTION_KEY = "nfs.disable";
+    private static final String NFS_OPTION_VALUE = "off";
     private GlusterVolumeDao dao;
     private VdsStatic server;
     private GlusterVolumeEntity existingDistVol;
@@ -296,7 +298,7 @@
 
     @Test
     public void testGetVolumesByOption() {
-        List<GlusterVolumeEntity> volumes = dao.getVolumesByOption(CLUSTER_ID, 
GlusterStatus.UP, "nfs.disable", "off");
+        List<GlusterVolumeEntity> volumes = dao.getVolumesByOption(CLUSTER_ID, 
GlusterStatus.UP, NFS_OPTION_KEY, NFS_OPTION_VALUE);
 
         assertTrue(volumes != null);
         assertTrue(volumes.contains(existingReplVol));
@@ -304,6 +306,31 @@
     }
 
     @Test
+    public void testGetVolumesByOptionAndVolumeType() {
+        List<GlusterVolumeEntity> volumes =
+                dao.getVolumesByOptionAndVolumeType(CLUSTER_ID,
+                        GlusterStatus.UP,
+                        NFS_OPTION_KEY,
+                        NFS_OPTION_VALUE,
+                        GlusterVolumeType.DISTRIBUTED_REPLICATE);
+
+        assertTrue(volumes != null);
+        assertTrue(volumes.contains(existingReplVol));
+        assertTrue(volumes.get(0).isNfsEnabled()
+                && volumes.get(0).getVolumeType() == 
GlusterVolumeType.DISTRIBUTED_REPLICATE);
+    }
+
+    @Test
+    public void testGetVolumesByVolumeType() {
+        List<GlusterVolumeEntity> volumes =
+                dao.getVolumesByVolumeType(CLUSTER_ID, GlusterStatus.UP, 
GlusterVolumeType.DISTRIBUTE);
+
+        assertTrue(volumes != null);
+        assertTrue(volumes.contains(existingDistVol));
+        assertTrue(volumes.get(0).getVolumeType() == 
GlusterVolumeType.DISTRIBUTE);
+    }
+
+    @Test
     public void testRemoveTransportTypes() {
         Set<TransportType> transportTypes = 
existingReplVol.getTransportTypes();
         assertEquals(2, transportTypes.size());


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

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

Reply via email to