Sahina Bose has uploaded a new change for review.

Change subject: gluster:Use uid check while sync from CLI
......................................................................

gluster:Use uid check while sync from CLI

While syncing gluster servers from gluster CLI
use the gluster host UUID to compare if the
server is present in the engine database or
not.

Change-Id: Id74b47bde915bb0736bce3826e371d8583e1cc6b
Signed-off-by: Sahina Bose <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterJob.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterSyncJob.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GlusterSyncJobTest.java
3 files changed, 75 insertions(+), 22 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/37/15437/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterJob.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterJob.java
index dc34ed3..5bad37e 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterJob.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterJob.java
@@ -26,6 +26,7 @@
 import org.ovirt.engine.core.dao.gluster.GlusterClusterServiceDao;
 import org.ovirt.engine.core.dao.gluster.GlusterHooksDao;
 import org.ovirt.engine.core.dao.gluster.GlusterOptionDao;
+import org.ovirt.engine.core.dao.gluster.GlusterServerDao;
 import org.ovirt.engine.core.dao.gluster.GlusterServerServiceDao;
 import org.ovirt.engine.core.dao.gluster.GlusterServiceDao;
 import org.ovirt.engine.core.dao.gluster.GlusterVolumeDao;
@@ -118,6 +119,10 @@
         return DbFacade.getInstance().getGlusterClusterServiceDao();
     }
 
+    protected GlusterServerDao getGlusterServerDao() {
+        return DbFacade.getInstance().getGlusterServerDao();
+    }
+
     /**
      * Acquires a lock on the cluster with given id and locking group {@link 
LockingGroup#GLUSTER}
      *
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterSyncJob.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterSyncJob.java
index 50b91ac..90a3312 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterSyncJob.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterSyncJob.java
@@ -19,6 +19,7 @@
 import org.ovirt.engine.core.common.businessentities.VDSStatus;
 import org.ovirt.engine.core.common.businessentities.gluster.BrickDetails;
 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.GlusterServerInfo;
 import org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus;
 import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeAdvancedDetails;
@@ -128,6 +129,8 @@
             if (fetchedServers != null) {
                 removeDetachedServers(existingServers, fetchedServers);
             }
+        } catch(Exception e) {
+            log.errorFormat("Error while refreshing server data for cluster 
{0} from database!", cluster.getname(), e);
         } finally {
             releaseLock(cluster.getId());
         }
@@ -192,14 +195,25 @@
      * @return
      */
     private boolean serverDetached(VDS server, List<GlusterServerInfo> 
fetchedServers) {
-        List<String> vdsIps = getVdsIps(server);
-        for (GlusterServerInfo fetchedServer : fetchedServers) {
-            if (fetchedServer.getHostnameOrIp().equals(server.getHostName())
-                    || vdsIps.contains(fetchedServer.getHostnameOrIp())) {
-                return false;
+        if 
(GlusterFeatureSupported.glusterHostUuidSupported(server.getVdsGroupCompatibilityVersion()))
 {
+            // compare gluster host uuid stored in server with the ones 
fetched from list
+            GlusterServer glusterServer = 
getGlusterServerDao().getByServerId(server.getId());
+            for (GlusterServerInfo fetchedServer : fetchedServers) {
+                if 
(fetchedServer.getUuid().equals(glusterServer.getGlusterServerUuid())) {
+                    return false;
+                }
             }
+            return true;
+        } else {
+            List<String> vdsIps = getVdsIps(server);
+            for (GlusterServerInfo fetchedServer : fetchedServers) {
+                if 
(fetchedServer.getHostnameOrIp().equals(server.getHostName())
+                        || vdsIps.contains(fetchedServer.getHostnameOrIp())) {
+                    return false;
+                }
+            }
+            return true;
         }
-        return true;
     }
 
     private List<String> getVdsIps(VDS vds) {
@@ -227,8 +241,7 @@
             // It's possible that the server we are using to get list of 
servers itself has been removed from the
             // cluster, and hence is returning a single server (itself)
             GlusterServerInfo server = fetchedServers.iterator().next();
-            if (server.getHostnameOrIp().equals(upServer.getHostName())
-                    || getVdsIps(upServer).contains(server.getHostnameOrIp())) 
{
+            if (isSameServer(upServer, server)) {
                 // Find a different UP server, and get servers list from it
                 tempServers.remove(upServer);
                 upServer = getNewUpServer(tempServers, upServer);
@@ -251,6 +264,16 @@
         return fetchedServers;
     }
 
+    private boolean isSameServer(VDS upServer, GlusterServerInfo server) {
+        if 
(GlusterFeatureSupported.glusterHostUuidSupported(upServer.getVdsGroupCompatibilityVersion()))
 {
+            GlusterServer glusterUpServer = 
getGlusterServerDao().getByServerId(upServer.getId());
+            return 
glusterUpServer.getGlusterServerUuid().equals(server.getUuid());
+        } else {
+            return server.getHostnameOrIp().equals(upServer.getHostName())
+                || getVdsIps(upServer).contains(server.getHostnameOrIp());
+        }
+    }
+
     /**
      * Fetches list of gluster servers by executing the gluster peer status 
command on the given UP server. If the
      * gluster command fails, tries on other UP servers from the list of 
existing Servers recursively. Returns null if
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GlusterSyncJobTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GlusterSyncJobTest.java
index 67795a9..3ea8b6c 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GlusterSyncJobTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GlusterSyncJobTest.java
@@ -17,7 +17,6 @@
 import java.util.Map;
 
 import org.hamcrest.Matcher;
-import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -39,6 +38,7 @@
 import org.ovirt.engine.core.common.businessentities.gluster.BrickDetails;
 import org.ovirt.engine.core.common.businessentities.gluster.BrickProperties;
 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.GlusterServerInfo;
 import org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus;
 import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeAdvancedDetails;
@@ -63,6 +63,7 @@
 import org.ovirt.engine.core.dao.VdsStatisticsDAO;
 import org.ovirt.engine.core.dao.gluster.GlusterBrickDao;
 import org.ovirt.engine.core.dao.gluster.GlusterOptionDao;
+import org.ovirt.engine.core.dao.gluster.GlusterServerDao;
 import org.ovirt.engine.core.dao.gluster.GlusterVolumeDao;
 import org.ovirt.engine.core.dao.network.InterfaceDao;
 import org.ovirt.engine.core.utils.MockConfigRule;
@@ -83,7 +84,10 @@
             mockConfig(ConfigValues.GlusterRefreshRateLight, 5),
             mockConfig(ConfigValues.GlusterRefreshRateHeavy, 300),
             mockConfig(ConfigValues.GlusterRefreshHeavyWeight, "3.1", false),
-            mockConfig(ConfigValues.GlusterRefreshHeavyWeight, "3.2", true));
+            mockConfig(ConfigValues.GlusterRefreshHeavyWeight, "3.2", true),
+            mockConfig(ConfigValues.GlusterHostUUIDSupport, "3.1", false),
+            mockConfig(ConfigValues.GlusterHostUUIDSupport, "3.2", false),
+            mockConfig(ConfigValues.GlusterHostUUIDSupport, "3.3", true));
 
     @ClassRule
     public static MockEJBStrategyRule ejbRule = new MockEJBStrategyRule();
@@ -100,6 +104,7 @@
     private static final Guid SERVER_ID_1 = new 
Guid("23f6d691-5dfb-472b-86dc-9e1d2d3c18f3");
     private static final Guid SERVER_ID_2 = new 
Guid("2001751e-549b-4e7a-aff6-32d36856c125");
     private static final Guid SERVER_ID_3 = new 
Guid("2001751e-549b-4e7a-aff6-32d36856c126");
+    private static final Guid GLUSTER_SERVER_UUID_1 = new 
Guid("24f4d494-5dfb-472b-86dc-9e1d2d3c18f3");
     private static final String SERVER_NAME_1 = "srvr1";
     private static final String SERVER_NAME_2 = "srvr2";
     private static final String SERVER_NAME_3 = "srvr3";
@@ -135,26 +140,28 @@
     private VdsGroupDAO clusterDao;
     @Mock
     private InterfaceDao interfaceDao;
+    @Mock
+    private GlusterServerDao glusterServerDao;
 
     private VDSGroup existingCluster;
     private VDS existingServer1;
     private VDS existingServer2;
-    private List<VDS> existingServers = new ArrayList<VDS>();
+    private final List<VDS> existingServers = new ArrayList<VDS>();
     private GlusterVolumeEntity existingDistVol;
     private GlusterVolumeEntity existingReplVol;
     private GlusterVolumeEntity newVolume;
-    private List<GlusterVolumeEntity> existingVolumes = new 
ArrayList<GlusterVolumeEntity>();
-    private List<Guid> removedBrickIds = new ArrayList<Guid>();
-    private List<Guid> addedBrickIds = new ArrayList<Guid>();
-    private List<GlusterBrickEntity> bricksWithChangedStatus = new 
ArrayList<GlusterBrickEntity>();
+    private final List<GlusterVolumeEntity> existingVolumes = new 
ArrayList<GlusterVolumeEntity>();
+    private final List<Guid> removedBrickIds = new ArrayList<Guid>();
+    private final List<Guid> addedBrickIds = new ArrayList<Guid>();
+    private final List<GlusterBrickEntity> bricksWithChangedStatus = new 
ArrayList<GlusterBrickEntity>();
 
-    @Before
-    public void createObjects() {
-        existingServer1 = createServer(SERVER_ID_1, SERVER_NAME_1);
-        existingServer2 = createServer(SERVER_ID_2, SERVER_NAME_2);
+
+    private void createObjects(Version version) {
+        existingServer1 = createServer(SERVER_ID_1, SERVER_NAME_1, version);
+        existingServer2 = createServer(SERVER_ID_2, SERVER_NAME_2, version);
         existingServers.add(existingServer1);
         existingServers.add(existingServer2);
-        existingServers.add(createServer(SERVER_ID_3, SERVER_NAME_3));
+        existingServers.add(createServer(SERVER_ID_3, SERVER_NAME_3,version));
 
         existingDistVol = createDistVol(DIST_VOL_NAME, EXISTING_VOL_DIST_ID);
         existingReplVol = createReplVol();
@@ -167,15 +174,18 @@
         existingCluster.setGlusterService(true);
         existingCluster.setVirtService(false);
         existingCluster.setcompatibility_version(version);
+        createObjects(version);
     }
 
-    private VDS createServer(Guid serverId, String hostname) {
+    private VDS createServer(Guid serverId, String hostname, Version version) {
         VdsStatic vdsStatic = new VdsStatic();
         vdsStatic.setId(serverId);
         vdsStatic.setHostName(hostname);
         VdsDynamic vdsDynamic = new VdsDynamic();
         vdsDynamic.setstatus(VDSStatus.Up);
-        return new VDS(vdsStatic, vdsDynamic, new VdsStatistics());
+        VDS vds = new VDS(vdsStatic, vdsDynamic, new VdsStatistics());
+        vds.setVdsGroupCompatibilityVersion(version);
+        return vds;
     }
 
     private GlusterVolumeEntity createDistVol(String volName, Guid volId) {
@@ -209,6 +219,10 @@
 
     private GlusterBrickEntity createBrick(Guid existingVolDistId, VDS server, 
String brickDir) {
         return new GlusterBrickEntity(existingVolDistId, 
server.getStaticData(), brickDir, GlusterStatus.UP);
+    }
+
+    private GlusterServer getGlusterServer() {
+        return new GlusterServer(SERVER_ID_1, GLUSTER_SERVER_UUID_1);
     }
 
     @SuppressWarnings("unchecked")
@@ -334,6 +348,7 @@
         doReturn(vdsDynamicDao).when(glusterManager).getVdsDynamicDao();
         doReturn(clusterDao).when(glusterManager).getClusterDao();
         doReturn(interfaceDao).when(glusterManager).getInterfaceDao();
+        doReturn(glusterServerDao).when(glusterManager).getGlusterServerDao();
 
         
doReturn(Collections.singletonList(existingCluster)).when(clusterDao).getAll();
         doReturn(existingServers).when(vdsDao).getAllForVdsGroup(CLUSTER_ID);
@@ -534,6 +549,16 @@
     }
 
     @Test
+    public void testRefreshLightWeightFor33() throws Exception {
+        createCluster(Version.v3_3);
+        setupMocks();
+        
doReturn(getGlusterServer()).when(glusterServerDao).getByServerId(any(Guid.class));
+
+        glusterManager.refreshLightWeightData();
+        verifyMocksForLightWeight();
+    }
+
+    @Test
     public void testRefreshHeavyWeightFor32() throws Exception {
         createCluster(Version.v3_2);
         setupMocks();


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

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

Reply via email to