Shubhendu Tripathi has uploaded a new change for review.

Change subject: gluster: During import check host existence by UUID
......................................................................

gluster: During import check host existence by UUID

Modified to check the existence of hosts in the cluster by UUID, while
impporting the hosts into console which got added from CLI.
This makes sure no self entries get listed because of virbr0 bridge and
also resolves the hanging issue while importing the hosts added from
CLI.

Also added logic to discard a host ifrom the list if there is no fingerprint
available for the same.

Change-Id: I60f5fdf16c6b2cf717a041b34f9e62e0ac6b78f3
Bug-Url: https://bugzilla.redhat.com/1021773
Signed-off-by: Shubhendu Tripathi <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQuery.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQueryTest.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterDBUtils.java
3 files changed, 59 insertions(+), 6 deletions(-)


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

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQuery.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQuery.java
index aac25a6..4ecff74 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQuery.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQuery.java
@@ -1,6 +1,7 @@
 package org.ovirt.engine.core.bll.gluster;
 
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -9,6 +10,7 @@
 import org.ovirt.engine.core.bll.interfaces.BackendInternal;
 import org.ovirt.engine.core.bll.utils.ClusterUtils;
 import org.ovirt.engine.core.common.businessentities.VDS;
+import org.ovirt.engine.core.common.businessentities.VDSGroup;
 import org.ovirt.engine.core.common.businessentities.gluster.GlusterServerInfo;
 import org.ovirt.engine.core.common.businessentities.gluster.PeerStatus;
 import org.ovirt.engine.core.common.interfaces.VDSBrokerFrontend;
@@ -19,6 +21,9 @@
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 import org.ovirt.engine.core.common.vdscommands.VDSReturnValue;
 import org.ovirt.engine.core.common.vdscommands.VdsIdVDSCommandParametersBase;
+import org.ovirt.engine.core.compat.Version;
+import org.ovirt.engine.core.dal.dbbroker.DbFacade;
+import org.ovirt.engine.core.dao.VdsGroupDAO;
 import org.ovirt.engine.core.dao.gluster.GlusterDBUtils;
 
 /**
@@ -40,6 +45,16 @@
                             new 
VdsIdVDSCommandParametersBase(upServer.getId()));
             glusterServers = getAddedGlusterServers((List<GlusterServerInfo>) 
returnValue.getReturnValue());
         }
+
+        // Keep server details in the map only for the servers which are 
reachable
+        Iterator<Map.Entry<String, String>> iterator = 
glusterServers.entrySet().iterator();
+        while (iterator.hasNext()) {
+            Map.Entry<String, String> entry = iterator.next();
+            if (entry.getValue() == null) {
+                iterator.remove();
+            }
+        }
+
         getQueryReturnValue().setReturnValue(glusterServers);
     }
 
@@ -54,7 +69,7 @@
                     returnValue = getBackendInstance().
                             
runInternalQuery(VdcQueryType.GetServerSSHKeyFingerprint,
                                              new 
ServerParameters(server.getHostnameOrIp()));
-                    if (returnValue != null && returnValue.getSucceeded()) {
+                    if (returnValue != null && returnValue.getSucceeded() && 
returnValue.getReturnValue() != null) {
                         fingerprint = returnValue.getReturnValue().toString();
                     }
                 }
@@ -72,7 +87,12 @@
     }
 
     private boolean serverExists(GlusterServerInfo glusterServer) {
-        return getDbUtils().serverExists(getParameters().getClusterId(), 
glusterServer.getHostnameOrIp());
+        VDSGroup vdsGroup = 
getVdsGroupDao().get(getParameters().getClusterId());
+        if (vdsGroup.getcompatibility_version().compareTo(Version.v3_3) >= 0) {
+            return getDbUtils().serverExists(glusterServer.getUuid());
+        } else {
+            return getDbUtils().serverExists(getParameters().getClusterId(), 
glusterServer.getHostnameOrIp());
+        }
     }
 
     public ClusterUtils getClusterUtils() {
@@ -87,4 +107,8 @@
     public BackendInternal getBackendInstance() {
         return Backend.getInstance();
     }
+
+    public VdsGroupDAO getVdsGroupDao() {
+        return DbFacade.getInstance().getVdsGroupDao();
+    }
 }
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQueryTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQueryTest.java
index a76ff5d..c21559e 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQueryTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQueryTest.java
@@ -20,6 +20,7 @@
 import org.ovirt.engine.core.bll.interfaces.BackendInternal;
 import org.ovirt.engine.core.bll.utils.ClusterUtils;
 import org.ovirt.engine.core.common.businessentities.VDS;
+import org.ovirt.engine.core.common.businessentities.VDSGroup;
 import org.ovirt.engine.core.common.businessentities.VDSStatus;
 import org.ovirt.engine.core.common.businessentities.gluster.GlusterServerInfo;
 import org.ovirt.engine.core.common.businessentities.gluster.PeerStatus;
@@ -29,7 +30,9 @@
 import org.ovirt.engine.core.common.vdscommands.VDSParametersBase;
 import org.ovirt.engine.core.common.vdscommands.VDSReturnValue;
 import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.compat.Version;
 import org.ovirt.engine.core.dao.VdsDAO;
+import org.ovirt.engine.core.dao.VdsGroupDAO;
 import org.ovirt.engine.core.dao.gluster.GlusterDBUtils;
 
 public class GetAddedGlusterServersQueryTest extends 
AbstractQueryTest<AddedGlusterServersParameters, 
GetAddedGlusterServersQuery<AddedGlusterServersParameters>> {
@@ -39,6 +42,7 @@
     private VDSBrokerFrontend vdsBrokerFrontend;
     private BackendInternal backendInternal;
     private VdsDAO vdsDaoMock;
+    private VdsGroupDAO vdsGroupDaoMock;
     private GlusterDBUtils dbUtils;
     private ClusterUtils clusterUtils;
 
@@ -51,6 +55,14 @@
     private static final Guid server_id2 = new 
Guid("6a697a38-cc82-4399-a6fb-0ec79c0ff1d5");
     private static final Guid server_id3 = new 
Guid("7a797a38-cb32-4399-b6fb-21c79c03a1d6");
     private static final String serverKeyFingerprint = "";
+
+    private VDSGroup getVdsGroup() {
+        VDSGroup vdsGroup = new VDSGroup();
+        vdsGroup.setId(CLUSTER_ID);
+        vdsGroup.setcompatibility_version(Version.v3_3);
+
+        return vdsGroup;
+    }
 
     private VDS getVds(VDSStatus status) {
         VDS vds = new VDS();
@@ -87,10 +99,6 @@
     private void setupExpectedGlusterServersInfo() {
         expectedServers = new ArrayList<GlusterServerInfo>();
         GlusterServerInfo server = new GlusterServerInfo();
-        server.setUuid(server_id1);
-        server.setHostnameOrIp(TEST_SERVER1);
-        server.setStatus(PeerStatus.CONNECTED);
-        expectedServers.add(server);
         server = new GlusterServerInfo();
         server.setUuid(server_id3);
         server.setHostnameOrIp(TEST_SERVER3);
@@ -102,6 +110,7 @@
         vdsBrokerFrontend = mock(VDSBrokerFrontend.class);
         clusterUtils = mock(ClusterUtils.class);
         vdsDaoMock = mock(VdsDAO.class);
+        vdsGroupDaoMock = mock(VdsGroupDAO.class);
         dbUtils = mock(GlusterDBUtils.class);
 
         doReturn(vdsBrokerFrontend).when(getQuery()).getResourceManager();
@@ -112,10 +121,12 @@
         VDSReturnValue returnValue = getVDSReturnValue();
         
when(vdsBrokerFrontend.RunVdsCommand(eq(VDSCommandType.GlusterServersList),
                 any(VDSParametersBase.class))).thenReturn(returnValue);
+        when(vdsGroupDaoMock.get(any(Guid.class))).thenReturn(getVdsGroup());
         
doReturn(params.getClusterId()).when(getQueryParameters()).getClusterId();
         
doReturn(true).when(getQueryParameters()).isServerKeyFingerprintRequired();
 
         doReturn(vdsDaoMock).when(clusterUtils).getVdsDao();
+        doReturn(vdsGroupDaoMock).when(getQuery()).getVdsGroupDao();
         doReturn(serversList).when(vdsDaoMock).getAllForVdsGroup(CLUSTER_ID);
         doReturn(true).when(dbUtils).serverExists(any(Guid.class), 
eq(TEST_SERVER1));
         doReturn(false).when(dbUtils).serverExists(any(Guid.class), 
eq(TEST_SERVER3));
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterDBUtils.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterDBUtils.java
index b5539c3..7af763b 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterDBUtils.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterDBUtils.java
@@ -6,6 +6,7 @@
 
 import org.ovirt.engine.core.common.businessentities.VdsStatic;
 import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity;
+import org.ovirt.engine.core.common.businessentities.gluster.GlusterServer;
 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;
@@ -32,6 +33,10 @@
 
     private GlusterVolumeDao getGlusterVolumeDao() {
         return getDbFacade().getGlusterVolumeDao();
+    }
+
+    private GlusterServerDao getGlusterServerDao() {
+        return getDbFacade().getGlusterServerDao();
     }
 
     public boolean hasBricks(Guid serverId) {
@@ -69,6 +74,19 @@
         return getServer(clusterId, hostnameOrIp) != null;
     }
 
+    public boolean serverExists(Guid uuid) {
+        return getServerByUuid(uuid) != null;
+    }
+
+    /**
+     * Returns a server from the given cluster, having given UUID
+     *
+     * @return VDS object for the said server if found, else null
+     */
+    public GlusterServer getServerByUuid(Guid uuid) {
+        return getGlusterServerDao().getByGlusterServerUuid(uuid);
+    }
+
     /**
      * Returns a server from the given cluster, having give host name or IP 
address.
      *


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

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

Reply via email to