Sahina Bose has uploaded a new change for review.

Change subject: engine: [WIP] Monitoring of geo-rep status and statistics
......................................................................

engine: [WIP] Monitoring of geo-rep status and statistics

Change-Id: I67e857ab2ce993cded966fb60b361f6962b9a665
Bug-Url: https://bugzilla.redhat.com/1138116
Signed-off-by: Sahina Bose <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterGeoRepSyncJob.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterJobsManager.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllErrors.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/gluster/GetGlusterVolumeGeoRepStatusDetailVDSCommand.java
5 files changed, 117 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/52/34552/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterGeoRepSyncJob.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterGeoRepSyncJob.java
index 951d9fa..292b38b 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterGeoRepSyncJob.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterGeoRepSyncJob.java
@@ -5,6 +5,7 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.Callable;
 
 import org.apache.commons.lang.ArrayUtils;
 import org.ovirt.engine.core.common.AuditLogType;
@@ -15,11 +16,14 @@
 import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSessionDetails;
 import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity;
 import org.ovirt.engine.core.common.constants.gluster.GlusterConstants;
+import org.ovirt.engine.core.common.errors.VdcBLLException;
+import org.ovirt.engine.core.common.errors.VdcBllErrors;
 import org.ovirt.engine.core.common.gluster.GlusterFeatureSupported;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 import org.ovirt.engine.core.common.vdscommands.VDSReturnValue;
 import 
org.ovirt.engine.core.common.vdscommands.gluster.GlusterVolumeGeoRepSessionVDSParameters;
 import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.utils.threadpool.ThreadPoolUtil;
 import org.ovirt.engine.core.utils.timer.OnTimerMethodAnnotation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -47,22 +51,91 @@
         List<VDSGroup> clusters = getClusterDao().getAll();
         // for every cluster that supports geo-rep monitoring
         for (VDSGroup cluster : clusters) {
-            refreshGeoRepDataInCluster(cluster);
+            discoverGeoRepDataInCluster(cluster);
         }
 
     }
 
-    public void refreshGeoRepDataInCluster(VDSGroup cluster) {
+    @OnTimerMethodAnnotation("gluster_georepstatus_poll_event")
+    public void refreshGeoRepSessionStatus() {
+        // get all clusters
+        List<VDSGroup> clusters = getClusterDao().getAll();
+        // for every cluster that supports geo-rep monitoring
+        for (VDSGroup cluster : clusters) {
+            refreshGeoRepSessionStatusInCluster(cluster);
+        }
+    }
+
+    private void refreshGeoRepSessionStatusInCluster(final VDSGroup cluster) {
+        List<GlusterGeoRepSession> geoRepSessions = 
getGeoRepDao().getGeoRepSessionsInCluster(cluster.getId());
+        refreshGeoRepSessionStatus(cluster, geoRepSessions);
+    }
+
+    public void refreshGeoRepDataForVolume(final GlusterVolumeEntity volume) {
+        VDSGroup cluster = getClusterDao().get(volume.getClusterId());
+        discoverGeoRepDataForVolume(cluster, volume);
+        List<GlusterGeoRepSession> geoRepSessions = 
getGeoRepDao().getGeoRepSessions(volume.getId());
+        refreshGeoRepSessionStatus(cluster, geoRepSessions);
+    }
+
+    private void refreshGeoRepSessionStatus(final VDSGroup cluster, 
List<GlusterGeoRepSession> geoRepSessions) {
+        List<Callable<GlusterGeoRepSession>> geoRepSessionCalls = new 
ArrayList<>();
+        for (final GlusterGeoRepSession geoRepSession: geoRepSessions) {
+            geoRepSessionCalls.add(new Callable<GlusterGeoRepSession>() {
+
+                @Override
+                public GlusterGeoRepSession call() throws Exception {
+                    geoRepSession.setSessionDetails((ArrayList) 
getSessionDetailFromCLI(cluster, geoRepSession));
+                    return geoRepSession;
+                }
+
+            });
+        }
+
+        List<GlusterGeoRepSession> updatedSessions = 
ThreadPoolUtil.invokeAll(geoRepSessionCalls);
+        for (GlusterGeoRepSession updatedSession : updatedSessions) {
+            GlusterVolumeEntity masterVolume = 
getVolumeDao().getById(updatedSession.getMasterVolumeId());
+            updateGeoRepStatus(masterVolume, updatedSession);
+            getGeoRepDao().updateSession(updatedSession);
+            updateSessionDetailsInDB(updatedSession);
+        }
+    }
+
+    public void discoverGeoRepDataInCluster(VDSGroup cluster) {
         if (!supportsGlusterGeoRepFeature(cluster)) {
             return;
         }
 
-        Map<String, GlusterGeoRepSession> sessionsMap = 
getSessionsForCluster(cluster);
+        Map<String, GlusterGeoRepSession> sessionsMap = 
getSessionsFromCLI(cluster, null);
         if (sessionsMap == null) {
             log.debug("Error in retrieving sessions for cluster: {} from CLI, 
nothing to do", cluster.getName());
             return;
         }
 
+        refreshDiscoveredSessions(cluster, sessionsMap);
+    }
+
+    private void discoverGeoRepDataForVolume(VDSGroup cluster, 
GlusterVolumeEntity volume) {
+        if (!supportsGlusterGeoRepFeature(cluster)) {
+            return;
+        }
+
+        if (volume == null) {
+            throw new 
VdcBLLException(VdcBllErrors.GlusterVolumeGeoRepSyncFailed, "No volume 
information");
+        }
+
+        Map<String, GlusterGeoRepSession> sessionsMap = 
getSessionsFromCLI(cluster, volume.getName());
+        if (sessionsMap == null) {
+            log.debug("Error in retrieving sessions for cluster: {} from CLI, 
nothing to do", cluster.getName());
+            return;
+        }
+
+        refreshDiscoveredSessions(cluster, sessionsMap);
+    }
+
+
+
+    private void refreshDiscoveredSessions(VDSGroup cluster, Map<String, 
GlusterGeoRepSession> sessionsMap) {
         removeDeletedSessions(cluster.getId(), sessionsMap);
 
         // for each geo-rep session, find session in database and update 
details.
@@ -94,13 +167,16 @@
                 session.setId(sessionInDb.getId());
                 getGeoRepDao().updateSession(session);
             }
-            //update the session details object with session id.
-            for (GlusterGeoRepSessionDetails sessDetails : 
session.getSessionDetails()) {
-                sessDetails.setSessionId(session.getId());
-            }
-            
getGeoRepDao().saveOrUpdateDetailsInBatch(session.getSessionDetails());
+            updateSessionDetailsInDB(session);
         }
+    }
 
+    private void updateSessionDetailsInDB(GlusterGeoRepSession session) {
+        // update the session details object with session id.
+        for (GlusterGeoRepSessionDetails sessDetails : 
session.getSessionDetails()) {
+            sessDetails.setSessionId(session.getId());
+        }
+        getGeoRepDao().saveOrUpdateDetailsInBatch(session.getSessionDetails());
     }
 
     private void removeDeletedSessions(Guid clusterId, final Map<String, 
GlusterGeoRepSession> sessionsMap) {
@@ -196,7 +272,7 @@
         return GeoRepSessionStatus.UNKNOWN;
     }
 
-    private Map<String, GlusterGeoRepSession> getSessionsForCluster(VDSGroup 
cluster) {
+    private Map<String, GlusterGeoRepSession> getSessionsFromCLI(VDSGroup 
cluster, String volumeName) {
         VDS upServer = getClusterUtils().getRandomUpServer(cluster.getId());
         if (upServer == null) {
             log.debug("No UP server found in cluster: {} for geo-rep 
monitoring", cluster.getName());
@@ -204,7 +280,7 @@
         }
         // get details of geo-rep sessions in cluster
         VDSReturnValue returnValue = 
runVdsCommand(VDSCommandType.GetGlusterVolumeGeoRepStatus,
-                new GlusterVolumeGeoRepSessionVDSParameters(upServer.getId(), 
null));
+                new GlusterVolumeGeoRepSessionVDSParameters(upServer.getId(), 
volumeName));
         if (returnValue.getSucceeded()) {
             List<GlusterGeoRepSession> sessions = (List<GlusterGeoRepSession>) 
returnValue.getReturnValue();
             HashMap<String, GlusterGeoRepSession> sessionsMap = new 
HashMap<>();
@@ -223,6 +299,24 @@
 
     }
 
+    private List<GlusterGeoRepSessionDetails> getSessionDetailFromCLI(VDSGroup 
cluster, GlusterGeoRepSession session) {
+        VDS upServer = getClusterUtils().getRandomUpServer(cluster.getId());
+        if (upServer == null) {
+            log.debug("No UP server found in cluster: {} for geo-rep 
monitoring", cluster.getName());
+            return null;
+        }
+        VDSReturnValue returnValue = 
runVdsCommand(VDSCommandType.GetGlusterVolumeGeoRepStatusDetail,
+                new GlusterVolumeGeoRepSessionVDSParameters(upServer.getId(),
+                        session.getMasterVolumeName(), 
session.getSlaveHostName(), session.getSlaveVolumeName()));
+        if (returnValue.getSucceeded()) {
+            return (List<GlusterGeoRepSessionDetails>) 
returnValue.getReturnValue();
+        } else {
+            log.error("VDS error {}", returnValue.getVdsError().getMessage());
+            log.debug("VDS error", returnValue.getVdsError());
+            return null;
+        }
+    }
+
     private GlusterVolumeEntity getVolume(VDSGroup cluster, String 
masterVolumeName) {
         return getVolumeDao().getByName(cluster.getId(), masterVolumeName);
     }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterJobsManager.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterJobsManager.java
index 96e19aa..f0fce81 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterJobsManager.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterJobsManager.java
@@ -72,6 +72,13 @@
                 getRefreshRate(ConfigValues.GlusterRefreshRateGeoRepDiscovery),
                 TimeUnit.SECONDS);
 
+        scheduler.scheduleAFixedDelayJob(GlusterGeoRepSyncJob.getInstance(),
+                "gluster_georepstatus_poll_event",
+                new Class[0],
+                new Class[0],
+                getRefreshRate(ConfigValues.GlusterRefreshRateGeoRepStatus),
+                getRefreshRate(ConfigValues.GlusterRefreshRateGeoRepStatus),
+                TimeUnit.SECONDS);
     }
 
     private static boolean glusterModeSupported() {
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
index b14d095..5e97220 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
@@ -1401,6 +1401,10 @@
     @DefaultValueAttribute("3600")
     GlusterRefreshRateGeoRepDiscovery,
 
+    @TypeConverterAttribute(Integer.class)
+    @DefaultValueAttribute("300")
+    GlusterRefreshRateGeoRepStatus,
+
     @TypeConverterAttribute(String.class)
     @DefaultValueAttribute("AttestationService/resources/PollHosts")
     PollUri,
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllErrors.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllErrors.java
index 18aab1c..6fc5549 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllErrors.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllErrors.java
@@ -405,6 +405,7 @@
     GlusterVolumeGeoRepStopFailedException(4596),
     GlusterVolumeGeoRepStatusFailed(4599),
     GlusterVolumeGeoRepStatusDetailFailed(4600),
+    GlusterVolumeGeoRepSyncFailed(4601),
 
     UnicodeArgumentException(4900),
 
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/gluster/GetGlusterVolumeGeoRepStatusDetailVDSCommand.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/gluster/GetGlusterVolumeGeoRepStatusDetailVDSCommand.java
index a770d6a..5357ba7 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/gluster/GetGlusterVolumeGeoRepStatusDetailVDSCommand.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/gluster/GetGlusterVolumeGeoRepStatusDetailVDSCommand.java
@@ -21,7 +21,7 @@
         result = 
getBroker().glusterVolumeGeoRepStatusDetail(parameter.getVolumeName(), 
parameter.getSlaveHost(), parameter.getSlaveVolume());
         proceedProxyReturnValue();
         if (getVDSReturnValue().getSucceeded()) {
-            setReturnValue(result.getGeoRepSessions());
+            setReturnValue(result.getGeoRepDetails());
         }
     }
 


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I67e857ab2ce993cded966fb60b361f6962b9a665
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