Shireesh Anjal has uploaded a new change for review.

Change subject: gluster: Wrapper method for updating volume status
......................................................................

gluster: Wrapper method for updating volume status

Introduced a new wrapper method GlusterUtils#updateVolumeStatus() for
updating status of a volume. This internally updates status of all the
bricks of that volume as well.

Modified the start/stop gluster volume commands to make use of this new
method. Removed the method GlusterVolumeCommandBase#updateBrickStatus()
as it is not required any more.

Change-Id: Ia5ae4f24e8c70781d7f93f19c935e136ba8b702b
Signed-off-by: Shireesh Anjal <san...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterVolumeCommandBase.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StartGlusterVolumeCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StopGlusterVolumeCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/GlusterUtils.java
4 files changed, 37 insertions(+), 27 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/67/11167/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterVolumeCommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterVolumeCommandBase.java
index b6016bf..625e5df 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterVolumeCommandBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterVolumeCommandBase.java
@@ -7,8 +7,6 @@
 import org.ovirt.engine.core.common.VdcObjectType;
 import org.ovirt.engine.core.common.action.gluster.GlusterVolumeParameters;
 import org.ovirt.engine.core.common.businessentities.VDSGroup;
-import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity;
-import org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus;
 import org.ovirt.engine.core.dal.VdcBllMessages;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
 import org.ovirt.engine.core.dao.gluster.GlusterBrickDao;
@@ -65,11 +63,5 @@
                         getParameters().getVolumeId(),
                         VdcObjectType.GlusterVolume,
                         getActionType().getActionGroup()));
-    }
-
-    protected void updateBrickStatus(GlusterStatus status) {
-        for(GlusterBrickEntity brick : getGlusterVolume().getBricks()) {
-            getGlusterBrickDao().updateBrickStatus(brick.getId(), status);
-        }
     }
 }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StartGlusterVolumeCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StartGlusterVolumeCommand.java
index 3a9b06f..67eab29 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StartGlusterVolumeCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StartGlusterVolumeCommand.java
@@ -2,6 +2,7 @@
 
 import org.ovirt.engine.core.bll.LockIdNameAttribute;
 import org.ovirt.engine.core.bll.NonTransactiveCommandAttribute;
+import org.ovirt.engine.core.bll.utils.GlusterUtils;
 import org.ovirt.engine.core.common.AuditLogType;
 import 
org.ovirt.engine.core.common.action.gluster.GlusterVolumeActionParameters;
 import org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus;
@@ -9,7 +10,6 @@
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 import org.ovirt.engine.core.common.vdscommands.VDSReturnValue;
 import 
org.ovirt.engine.core.common.vdscommands.gluster.GlusterVolumeActionVDSParameters;
-import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dal.VdcBllMessages;
 
 /**
@@ -55,7 +55,7 @@
                                                 getGlusterVolumeName(), 
getParameters().isForceAction()));
         setSucceeded(returnValue.getSucceeded());
         if(getSucceeded()) {
-            updateVolumeStatusInDb(getParameters().getVolumeId());
+            
GlusterUtils.getInstance().updateVolumeStatus(getParameters().getVolumeId(), 
GlusterStatus.UP);
         } else {
             handleVdsError(AuditLogType.GLUSTER_VOLUME_START_FAILED, 
returnValue.getVdsError().getMessage());
             return;
@@ -70,10 +70,4 @@
             return errorType == null ? 
AuditLogType.GLUSTER_VOLUME_START_FAILED : errorType;
         }
     }
-
-    private void updateVolumeStatusInDb(Guid volumeId) {
-        getGlusterVolumeDao().updateVolumeStatus(volumeId, GlusterStatus.UP);
-        updateBrickStatus(GlusterStatus.UP);
-    }
-
 }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StopGlusterVolumeCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StopGlusterVolumeCommand.java
index bd96c98..ef504e7 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StopGlusterVolumeCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StopGlusterVolumeCommand.java
@@ -2,6 +2,7 @@
 
 import org.ovirt.engine.core.bll.LockIdNameAttribute;
 import org.ovirt.engine.core.bll.NonTransactiveCommandAttribute;
+import org.ovirt.engine.core.bll.utils.GlusterUtils;
 import org.ovirt.engine.core.common.AuditLogType;
 import 
org.ovirt.engine.core.common.action.gluster.GlusterVolumeActionParameters;
 import org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus;
@@ -9,7 +10,6 @@
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 import org.ovirt.engine.core.common.vdscommands.VDSReturnValue;
 import 
org.ovirt.engine.core.common.vdscommands.gluster.GlusterVolumeActionVDSParameters;
-import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dal.VdcBllMessages;
 
 /**
@@ -54,8 +54,8 @@
                                         new 
GlusterVolumeActionVDSParameters(upServer.getId(),
                                                 getGlusterVolumeName(), 
getParameters().isForceAction()));
         setSucceeded(returnValue.getSucceeded());
-        if(getSucceeded()) {
-            updateVolumeStatusInDb(getParameters().getVolumeId());
+        if (getSucceeded()) {
+            
GlusterUtils.getInstance().updateVolumeStatus(getParameters().getVolumeId(), 
GlusterStatus.DOWN);
         } else {
             handleVdsError(AuditLogType.GLUSTER_VOLUME_STOP_FAILED, 
returnValue.getVdsError().getMessage());
             return;
@@ -70,10 +70,4 @@
             return errorType == null ? AuditLogType.GLUSTER_VOLUME_STOP_FAILED 
: errorType;
         }
     }
-
-    private void updateVolumeStatusInDb(Guid volumeId) {
-        getGlusterVolumeDao().updateVolumeStatus(volumeId, GlusterStatus.DOWN);
-        updateBrickStatus(GlusterStatus.DOWN);
-    }
-
 }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/GlusterUtils.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/GlusterUtils.java
index 81958e2..14d8bf4 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/GlusterUtils.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/GlusterUtils.java
@@ -1,8 +1,11 @@
 package org.ovirt.engine.core.bll.utils;
 
+import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity;
+import org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
 import org.ovirt.engine.core.dao.gluster.GlusterBrickDao;
+import org.ovirt.engine.core.dao.gluster.GlusterVolumeDao;
 
 public class GlusterUtils {
     private static GlusterUtils instance = new GlusterUtils();
@@ -11,11 +14,38 @@
         return instance;
     }
 
-    public GlusterBrickDao getGlusterBrickDao() {
-        return DbFacade.getInstance().getGlusterBrickDao();
+    private DbFacade getDbFacade() {
+        return DbFacade.getInstance();
+    }
+
+    private GlusterBrickDao getGlusterBrickDao() {
+        return getDbFacade().getGlusterBrickDao();
+    }
+
+    private GlusterVolumeDao getGlusterVolumeDao() {
+        return getDbFacade().getGlusterVolumeDao();
     }
 
     public boolean hasBricks(Guid serverId) {
         return 
(getGlusterBrickDao().getGlusterVolumeBricksByServerId(serverId).size() > 0);
     }
+
+    /**
+     * Update status of all bricks of the given volume to the new status
+     */
+    public void updateBricksStatuses(Guid volumeId, GlusterStatus newStatus) {
+        for (GlusterBrickEntity brick : 
getGlusterBrickDao().getBricksOfVolume(volumeId)) {
+            getGlusterBrickDao().updateBrickStatus(brick.getId(), newStatus);
+        }
+    }
+
+    /**
+     * Update status of the given volume to the new status. This internally 
updates statuses of all bricks of the volume
+     * as well.
+     */
+    public void updateVolumeStatus(Guid volumeId, GlusterStatus newStatus) {
+        getGlusterVolumeDao().updateVolumeStatus(volumeId, newStatus);
+        // When a volume goes UP or DOWN, all it's bricks should also be 
updated with the new status.
+        updateBricksStatuses(volumeId, newStatus);
+    }
 }


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

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

Reply via email to