Sahina Bose has uploaded a new change for review.

Change subject: engine: Refactoring GlusterManager
......................................................................

engine: Refactoring GlusterManager

Renamed GlusterManager to GlusterSyncManager.

Created a class GlusterJobsManager that's responsible
for scheduling gluster jobs.

Change-Id: I61d851928f18da22b352b7be9d6ccaf4382e7930
Signed-off-by: Sahina Bose <sab...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InitBackendServicesOnStartupBean.java
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterJobsManager.java
R 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterSyncManager.java
R 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GlusterSyncManagerTest.java
4 files changed, 149 insertions(+), 122 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/44/13944/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InitBackendServicesOnStartupBean.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InitBackendServicesOnStartupBean.java
index 789cf38..22c0feb 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InitBackendServicesOnStartupBean.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InitBackendServicesOnStartupBean.java
@@ -6,7 +6,7 @@
 import javax.ejb.Singleton;
 import javax.ejb.Startup;
 
-import org.ovirt.engine.core.bll.gluster.GlusterManager;
+import org.ovirt.engine.core.bll.gluster.GlusterJobsManager;
 import org.ovirt.engine.core.bll.network.MacPoolManager;
 import org.ovirt.engine.core.bll.storage.StoragePoolStatusHandler;
 import org.ovirt.engine.core.common.config.Config;
@@ -53,7 +53,8 @@
         });
         StoragePoolStatusHandler.Init();
 
-        GlusterManager.getInstance().init();
+        GlusterJobsManager.init();
+
         try {
             log.info("Init VM custom properties utilities");
             VmPropertiesUtils.getInstance().init();
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
new file mode 100644
index 0000000..eb9f32b
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterJobsManager.java
@@ -0,0 +1,138 @@
+package org.ovirt.engine.core.bll.gluster;
+
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import org.ovirt.engine.core.bll.Backend;
+import org.ovirt.engine.core.bll.utils.ClusterUtils;
+import org.ovirt.engine.core.common.businessentities.VDS;
+import org.ovirt.engine.core.common.businessentities.gluster.GlusterServerInfo;
+import org.ovirt.engine.core.common.config.Config;
+import org.ovirt.engine.core.common.config.ConfigValues;
+import org.ovirt.engine.core.common.mode.ApplicationMode;
+import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
+import org.ovirt.engine.core.common.vdscommands.VDSParametersBase;
+import org.ovirt.engine.core.common.vdscommands.VDSReturnValue;
+import org.ovirt.engine.core.common.vdscommands.VdsIdVDSCommandParametersBase;
+import org.ovirt.engine.core.dal.dbbroker.DbFacade;
+import org.ovirt.engine.core.dao.VdsDAO;
+import org.ovirt.engine.core.dao.VdsDynamicDAO;
+import org.ovirt.engine.core.dao.VdsGroupDAO;
+import org.ovirt.engine.core.dao.VdsStaticDAO;
+import org.ovirt.engine.core.dao.VdsStatisticsDAO;
+import org.ovirt.engine.core.dao.gluster.GlusterBrickDao;
+import org.ovirt.engine.core.dao.gluster.GlusterHooksDao;
+import org.ovirt.engine.core.dao.gluster.GlusterOptionDao;
+import org.ovirt.engine.core.dao.gluster.GlusterVolumeDao;
+import org.ovirt.engine.core.dao.network.InterfaceDao;
+import org.ovirt.engine.core.utils.log.Log;
+import org.ovirt.engine.core.utils.log.LogFactory;
+import org.ovirt.engine.core.utils.timer.SchedulerUtil;
+import org.ovirt.engine.core.utils.timer.SchedulerUtilQuartzImpl;
+
+public class GlusterJobsManager {
+
+    private static final Log log = LogFactory.getLog(GlusterJobsManager.class);
+
+    public static void init() {
+        if (!glusterModeSupported()) {
+            log.debug("Gluster mode not supported. Will not schedule jobs for 
refreshing Gluster data.");
+            return;
+        }
+
+        log.debug("Initializing Gluster Jobs Manager");
+
+        SchedulerUtil scheduler = SchedulerUtilQuartzImpl.getInstance();
+
+        scheduler.scheduleAFixedDelayJob(GlusterSyncManager.getInstance(),
+                "refreshLightWeightData",
+                new Class[0],
+                new Object[0],
+                getGlusterRefreshRateLight(),
+                getGlusterRefreshRateLight(),
+                TimeUnit.SECONDS);
+
+        scheduler.scheduleAFixedDelayJob(GlusterSyncManager.getInstance(),
+                "refreshHeavyWeightData",
+                new Class[0],
+                new Object[0],
+                getGlusterRefreshRateHeavy(),
+                getGlusterRefreshRateHeavy(),
+                TimeUnit.SECONDS);
+
+   }
+
+    private static boolean glusterModeSupported() {
+        Integer appMode = Config.<Integer> 
GetValue(ConfigValues.ApplicationMode);
+        return ((appMode & ApplicationMode.GlusterOnly.getValue()) > 0);
+    }
+
+    private static int getGlusterRefreshRateLight() {
+        return Config.<Integer> GetValue(ConfigValues.GlusterRefreshRateLight);
+    }
+
+    private static int getGlusterRefreshRateHeavy() {
+        return Config.<Integer> GetValue(ConfigValues.GlusterRefreshRateHeavy);
+    }
+
+
+    @SuppressWarnings("unchecked")
+    protected List<GlusterServerInfo> fetchServers(VDS upServer) {
+        VDSReturnValue result =
+                Backend.getInstance()
+                        .getResourceManager()
+                        .RunVdsCommand(VDSCommandType.GlusterServersList,
+                                new 
VdsIdVDSCommandParametersBase(upServer.getId()));
+
+        return result.getSucceeded() ? (List<GlusterServerInfo>) 
result.getReturnValue() : null;
+    }
+
+    protected VDSReturnValue runVdsCommand(VDSCommandType commandType, 
VDSParametersBase params) {
+        return 
Backend.getInstance().getResourceManager().RunVdsCommand(commandType, params);
+    }
+
+    protected ClusterUtils getClusterUtils() {
+        return ClusterUtils.getInstance();
+    }
+
+    protected VdsStatisticsDAO getVdsStatisticsDao() {
+        return DbFacade.getInstance().getVdsStatisticsDao();
+    }
+
+    protected VdsStaticDAO getVdsStaticDao() {
+        return DbFacade.getInstance().getVdsStaticDao();
+    }
+
+    protected VdsDynamicDAO getVdsDynamicDao() {
+        return DbFacade.getInstance().getVdsDynamicDao();
+    }
+
+    protected InterfaceDao getInterfaceDao() {
+        return DbFacade.getInstance().getInterfaceDao();
+    }
+
+    protected VdsGroupDAO getClusterDao() {
+        return DbFacade.getInstance().getVdsGroupDao();
+    }
+
+    protected VdsDAO getVdsDao() {
+        return DbFacade.getInstance().getVdsDao();
+    }
+
+    protected GlusterVolumeDao getVolumeDao() {
+        return DbFacade.getInstance().getGlusterVolumeDao();
+    }
+
+    protected GlusterOptionDao getOptionDao() {
+        return DbFacade.getInstance().getGlusterOptionDao();
+    }
+
+    protected GlusterBrickDao getBrickDao() {
+        return DbFacade.getInstance().getGlusterBrickDao();
+    }
+
+    protected GlusterHooksDao getHooksDao() {
+        return DbFacade.getInstance().getGlusterHooksDao();
+    }
+
+}
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterManager.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterSyncManager.java
similarity index 89%
rename from 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterManager.java
rename to 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterSyncManager.java
index a6924c0..db4cc53 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterManager.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterSyncManager.java
@@ -8,12 +8,10 @@
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
-import java.util.concurrent.TimeUnit;
 
 import org.ovirt.engine.core.bll.Backend;
 import org.ovirt.engine.core.bll.LockMessagesMatchUtil;
 import org.ovirt.engine.core.bll.job.ExecutionHandler;
-import org.ovirt.engine.core.bll.utils.ClusterUtils;
 import org.ovirt.engine.core.common.AuditLogType;
 import org.ovirt.engine.core.common.action.SetNonOperationalVdsParameters;
 import org.ovirt.engine.core.common.action.VdcActionType;
@@ -30,43 +28,26 @@
 import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeOptionEntity;
 import org.ovirt.engine.core.common.businessentities.gluster.TransportType;
 import 
org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface;
-import org.ovirt.engine.core.common.config.Config;
-import org.ovirt.engine.core.common.config.ConfigValues;
 import org.ovirt.engine.core.common.constants.gluster.GlusterConstants;
 import org.ovirt.engine.core.common.locks.LockingGroup;
-import org.ovirt.engine.core.common.mode.ApplicationMode;
 import org.ovirt.engine.core.common.utils.ListUtils;
 import org.ovirt.engine.core.common.utils.ObjectUtils;
 import org.ovirt.engine.core.common.utils.gluster.GlusterCoreUtil;
 import org.ovirt.engine.core.common.vdscommands.RemoveVdsVDSCommandParameters;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
-import org.ovirt.engine.core.common.vdscommands.VDSParametersBase;
 import org.ovirt.engine.core.common.vdscommands.VDSReturnValue;
-import org.ovirt.engine.core.common.vdscommands.VdsIdVDSCommandParametersBase;
 import 
org.ovirt.engine.core.common.vdscommands.gluster.GlusterVolumeAdvancedDetailsVDSParameters;
 import 
org.ovirt.engine.core.common.vdscommands.gluster.GlusterVolumesListVDSParameters;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dal.VdcBllMessages;
-import org.ovirt.engine.core.dal.dbbroker.DbFacade;
 import 
org.ovirt.engine.core.dal.dbbroker.auditloghandling.gluster.GlusterAuditLogUtil;
-import org.ovirt.engine.core.dao.VdsDAO;
-import org.ovirt.engine.core.dao.VdsDynamicDAO;
-import org.ovirt.engine.core.dao.VdsGroupDAO;
-import org.ovirt.engine.core.dao.VdsStaticDAO;
-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.GlusterDBUtils;
-import org.ovirt.engine.core.dao.gluster.GlusterVolumeDao;
-import org.ovirt.engine.core.dao.network.InterfaceDao;
 import org.ovirt.engine.core.utils.lock.EngineLock;
 import org.ovirt.engine.core.utils.lock.LockManager;
 import org.ovirt.engine.core.utils.lock.LockManagerFactory;
 import org.ovirt.engine.core.utils.log.Log;
 import org.ovirt.engine.core.utils.log.LogFactory;
 import org.ovirt.engine.core.utils.timer.OnTimerMethodAnnotation;
-import org.ovirt.engine.core.utils.timer.SchedulerUtil;
-import org.ovirt.engine.core.utils.timer.SchedulerUtilQuartzImpl;
 import org.ovirt.engine.core.utils.transaction.TransactionMethod;
 import org.ovirt.engine.core.utils.transaction.TransactionSupport;
 
@@ -75,16 +56,16 @@
  * GlusterFS. This helps to make sure that any changes done on Gluster servers 
using the Gluster CLI are propagated to
  * engine as well.
  */
-public class GlusterManager {
-    private final Log log = LogFactory.getLog(GlusterManager.class);
+public class GlusterSyncManager extends GlusterJobsManager {
+    private final Log log = LogFactory.getLog(GlusterSyncManager.class);
     private final LockManager lockManager = 
LockManagerFactory.getLockManager();
     private GlusterAuditLogUtil logUtil = GlusterAuditLogUtil.getInstance();
-    private static final GlusterManager instance = new GlusterManager();
+    private static final GlusterSyncManager instance = new 
GlusterSyncManager();
 
-    private GlusterManager() {
+    private GlusterSyncManager() {
     }
 
-    public static GlusterManager getInstance() {
+    public static GlusterSyncManager getInstance() {
         return instance;
     }
 
@@ -95,37 +76,6 @@
         this.logUtil = logUtil;
     }
 
-    public void init() {
-        if (!glusterModeSupported()) {
-            log.debug("Gluster mode not supported. Will not schedule jobs for 
refreshing Gluster data.");
-            return;
-        }
-
-        log.debug("Initializing Gluster Manager");
-
-        SchedulerUtil scheduler = SchedulerUtilQuartzImpl.getInstance();
-
-        scheduler.scheduleAFixedDelayJob(this,
-                "refreshLightWeightData",
-                new Class[0],
-                new Object[0],
-                getGlusterRefreshRateLight(),
-                getGlusterRefreshRateLight(),
-                TimeUnit.SECONDS);
-
-        scheduler.scheduleAFixedDelayJob(this,
-                "refreshHeavyWeightData",
-                new Class[0],
-                new Object[0],
-                getGlusterRefreshRateHeavy(),
-                getGlusterRefreshRateHeavy(),
-                TimeUnit.SECONDS);
-    }
-
-    private boolean glusterModeSupported() {
-        Integer appMode = Config.<Integer> 
GetValue(ConfigValues.ApplicationMode);
-        return ((appMode & ApplicationMode.GlusterOnly.getValue()) > 0);
-    }
 
     /**
      * Acquires a lock on the cluster with given id and locking group {@link 
LockingGroup#GLUSTER}
@@ -263,10 +213,6 @@
         });
     }
 
-    protected VDSReturnValue runVdsCommand(VDSCommandType commandType, 
VDSParametersBase params) {
-        return 
Backend.getInstance().getResourceManager().RunVdsCommand(commandType, params);
-    }
-
     /**
      * We need to be particularly careful about what servers we remove from 
the DB. A newly added (bootstrapped) server
      * gets peer probed after it's first reboot, and we don't want to 
accidentally remove such legitimate servers just
@@ -384,17 +330,6 @@
         
Backend.getInstance().runInternalAction(VdcActionType.SetNonOperationalVds,
                 nonOpParams,
                 ExecutionHandler.createInternalJobContext());
-    }
-
-    @SuppressWarnings("unchecked")
-    protected List<GlusterServerInfo> fetchServers(VDS upServer) {
-        VDSReturnValue result =
-                Backend.getInstance()
-                        .getResourceManager()
-                        .RunVdsCommand(VDSCommandType.GlusterServersList,
-                                new 
VdsIdVDSCommandParametersBase(upServer.getId()));
-
-        return result.getSucceeded() ? (List<GlusterServerInfo>) 
result.getReturnValue() : null;
     }
 
     /**
@@ -878,51 +813,4 @@
         getVdsDynamicDao().remove(server.getId());
     }
 
-    protected ClusterUtils getClusterUtils() {
-        return ClusterUtils.getInstance();
-    }
-
-    protected VdsStatisticsDAO getVdsStatisticsDao() {
-        return DbFacade.getInstance().getVdsStatisticsDao();
-    }
-
-    protected VdsStaticDAO getVdsStaticDao() {
-        return DbFacade.getInstance().getVdsStaticDao();
-    }
-
-    protected VdsDynamicDAO getVdsDynamicDao() {
-        return DbFacade.getInstance().getVdsDynamicDao();
-    }
-
-    protected InterfaceDao getInterfaceDao() {
-        return DbFacade.getInstance().getInterfaceDao();
-    }
-
-    protected VdsGroupDAO getClusterDao() {
-        return DbFacade.getInstance().getVdsGroupDao();
-    }
-
-    protected VdsDAO getVdsDao() {
-        return DbFacade.getInstance().getVdsDao();
-    }
-
-    protected GlusterVolumeDao getVolumeDao() {
-        return DbFacade.getInstance().getGlusterVolumeDao();
-    }
-
-    protected GlusterOptionDao getOptionDao() {
-        return DbFacade.getInstance().getGlusterOptionDao();
-    }
-
-    protected GlusterBrickDao getBrickDao() {
-        return DbFacade.getInstance().getGlusterBrickDao();
-    }
-
-    private int getGlusterRefreshRateLight() {
-        return Config.<Integer> GetValue(ConfigValues.GlusterRefreshRateLight);
-    }
-
-    private int getGlusterRefreshRateHeavy() {
-        return Config.<Integer> GetValue(ConfigValues.GlusterRefreshRateHeavy);
-    }
 }
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GlusterManagerTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GlusterSyncManagerTest.java
similarity index 99%
rename from 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GlusterManagerTest.java
rename to 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GlusterSyncManagerTest.java
index fde740b..d5521d0 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GlusterManagerTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GlusterSyncManagerTest.java
@@ -67,7 +67,7 @@
 import org.ovirt.engine.core.utils.MockEJBStrategyRule;
 
 @RunWith(MockitoJUnitRunner.class)
-public class GlusterManagerTest {
+public class GlusterSyncManagerTest {
 
     private static final String REPL_VOL_NAME = "repl-vol";
 
@@ -84,7 +84,7 @@
     @ClassRule
     public static MockEJBStrategyRule ejbRule = new MockEJBStrategyRule();
 
-    private GlusterManager glusterManager;
+    private GlusterSyncManager glusterManager;
     private GlusterAuditLogUtil logUtil;
 
     private static final String OPTION_AUTH_ALLOW = "auth.allow";
@@ -211,7 +211,7 @@
     @SuppressWarnings("unchecked")
     private void setupMocks() throws Exception {
         logUtil = Mockito.spy(GlusterAuditLogUtil.getInstance());
-        glusterManager = Mockito.spy(GlusterManager.getInstance());
+        glusterManager = Mockito.spy(GlusterSyncManager.getInstance());
         glusterManager.setLogUtil(logUtil);
         mockDaos();
 


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

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

Reply via email to