Sahina Bose has uploaded a new change for review.

Change subject: bll: base class for geo-rep session commands
......................................................................

bll: base class for geo-rep session commands

Base class to be used by geo-rep session
commands

Change-Id: Id9611320c93c48080bf7f908a61bbdeb2f899513
Bug-Url: https://bugzilla.redhat.com/1125845
Signed-off-by: Sahina Bose <[email protected]>
---
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GeoRepSessionCommandBase.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterCommandBase.java
A 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GeoRepSessionCommandTest.java
A 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/gluster/GlusterVolumeGeoRepSessionParameters.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/locks/LockingGroup.java
M backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
M 
frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
M 
frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
9 files changed, 222 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/80/39580/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GeoRepSessionCommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GeoRepSessionCommandBase.java
new file mode 100644
index 0000000..4ccc823
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GeoRepSessionCommandBase.java
@@ -0,0 +1,71 @@
+package org.ovirt.engine.core.bll.gluster;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.ovirt.engine.core.bll.LockMessagesMatchUtil;
+import 
org.ovirt.engine.core.common.action.gluster.GlusterVolumeGeoRepSessionParameters;
+import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSession;
+import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity;
+import org.ovirt.engine.core.common.errors.VdcBllMessages;
+import org.ovirt.engine.core.common.locks.LockingGroup;
+import org.ovirt.engine.core.common.utils.Pair;
+import org.ovirt.engine.core.dao.gluster.GlusterGeoRepDao;
+
+public abstract class GeoRepSessionCommandBase<T extends 
GlusterVolumeGeoRepSessionParameters> extends GlusterVolumeCommandBase<T> {
+    private GlusterGeoRepSession geoRepSession = null;
+
+    public GeoRepSessionCommandBase(T params) {
+        super(params);
+    }
+
+    @Override
+    protected void setActionMessageParameters() {
+        
addCanDoActionMessage(VdcBllMessages.VAR__TYPE__GLUSTER_GEOREP_SESSION);
+        addCanDoActionMessageVariable("volumeName", getGlusterVolumeName());
+        addCanDoActionMessageVariable("vdsGroup", getVdsGroupName());
+    }
+
+    @Override
+    protected boolean canDoAction() {
+        if (!super.canDoAction()) {
+            return false;
+        }
+
+        if (getGeoRepSession() == null) {
+            
addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_GEOREP_SESSION_INVALID);
+            return false;
+        }
+
+        GlusterVolumeEntity volume = getGlusterVolume();
+        if (!volume.isOnline()) {
+            
addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_GLUSTER_VOLUME_IS_DOWN);
+            addCanDoActionMessageVariable("volumeName", volume.getName());
+            return false;
+        }
+
+        return true;
+    }
+
+    protected GlusterGeoRepSession getGeoRepSession() {
+        if (geoRepSession == null) {
+            geoRepSession = 
getGlusterGeoRepDao().getById(getParameters().getGeoRepSessionId());
+        }
+        return geoRepSession;
+    }
+
+    @Override
+    protected Map<String, Pair<String, String>> getExclusiveLocks() {
+        if (!isInternalExecution()) {
+            return 
Collections.singletonMap(getGeoRepSession().getId().toString(),
+                    
LockMessagesMatchUtil.makeLockingPair(LockingGroup.GLUSTER_GEOREP,
+                            
VdcBllMessages.ACTION_TYPE_FAILED_GEOREP_SESSION_LOCKED));
+        }
+        return null;
+    }
+
+    protected GlusterGeoRepDao getGlusterGeoRepDao() {
+        return getDbFacade().getGlusterGeoRepDao();
+    }
+
+}
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterCommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterCommandBase.java
index ac5bb23..d0e153f 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterCommandBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterCommandBase.java
@@ -54,7 +54,7 @@
     protected Map<String, Pair<String, String>> getExclusiveLocks() {
         if (!isInternalExecution()) {
             return Collections.singletonMap(getVdsGroupId().toString(),
-                    
LockMessagesMatchUtil.makeLockingPair(LockingGroup.GLUSTER, 
VdcBllMessages.ACTION_TYPE_FAILED_OBJECT_LOCKED));
+                    
LockMessagesMatchUtil.makeLockingPair(LockingGroup.GLUSTER, 
VdcBllMessages.ACTION_TYPE_FAILED_GLUSTER_OPERATION_INPROGRESS));
         }
         return super.getExclusiveLocks();
     }
@@ -185,4 +185,5 @@
     protected GlusterBrickDao getGlusterBrickDao() {
         return getDbFacade().getGlusterBrickDao();
     }
+
 }
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GeoRepSessionCommandTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GeoRepSessionCommandTest.java
new file mode 100644
index 0000000..4910b72
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GeoRepSessionCommandTest.java
@@ -0,0 +1,70 @@
+package org.ovirt.engine.core.bll.gluster;
+
+import static org.mockito.Mockito.doReturn;
+
+import org.mockito.Mock;
+import org.ovirt.engine.core.common.businessentities.VDS;
+import org.ovirt.engine.core.common.businessentities.VDSStatus;
+import 
org.ovirt.engine.core.common.businessentities.gluster.GeoRepSessionStatus;
+import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSession;
+import org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus;
+import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity;
+import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dao.gluster.GlusterGeoRepDao;
+import org.ovirt.engine.core.dao.gluster.GlusterVolumeDao;
+
+public class GeoRepSessionCommandTest {
+
+    @Mock
+    GlusterGeoRepDao geoRepDao;
+    @Mock
+    GlusterVolumeDao volumeDao;
+    protected final Guid stoppedVolumeId = new 
Guid("8bc6f108-c0ef-43ab-ba20-ec41107220f5");
+    protected final Guid startedVolumeId = new 
Guid("b2cb2f73-fab3-4a42-93f0-d5e4c069a43e");
+    protected final Guid geoRepSessionId = new 
Guid("bbcb2f73-fab3-4a42-93f0-d5e4c069a43e");
+    private final Guid CLUSTER_ID = new 
Guid("b399944a-81ab-4ec5-8266-e19ba7c3c9d1");
+
+    public GeoRepSessionCommandTest() {
+        super();
+    }
+
+    protected <T extends GeoRepSessionCommandBase> void prepareMocks(T 
command) {
+        doReturn(geoRepDao).when(command).getGlusterGeoRepDao();
+        doReturn(volumeDao).when(command).getGlusterVolumeDao();
+        doReturn(getVds(VDSStatus.Up)).when(command).getUpServer();
+        
doReturn(getGeoRepSession(geoRepSessionId)).when(geoRepDao).getById(geoRepSessionId);
+        
doReturn(getGlusterVolume(startedVolumeId)).when(volumeDao).getById(startedVolumeId);
+        
doReturn(getGlusterVolume(stoppedVolumeId)).when(volumeDao).getById(stoppedVolumeId);
+        doReturn(null).when(geoRepDao).getById(null);
+    }
+
+    private VDS getVds(VDSStatus status) {
+        VDS vds = new VDS();
+        vds.setId(Guid.newGuid());
+        vds.setVdsName("gfs1");
+        vds.setVdsGroupId(CLUSTER_ID);
+        vds.setStatus(status);
+        return vds;
+    }
+
+    private GlusterGeoRepSession getGeoRepSession(Guid gSessionId) {
+        return getGeoRepSession(gSessionId, GeoRepSessionStatus.ACTIVE);
+    }
+
+    protected GlusterGeoRepSession getGeoRepSession(Guid gSessionId, 
GeoRepSessionStatus status) {
+        GlusterGeoRepSession session = new GlusterGeoRepSession();
+        session.setStatus(status);
+        session.setId(gSessionId);
+        return session;
+    }
+
+    private GlusterVolumeEntity getGlusterVolume(Guid volumeId) {
+        GlusterVolumeEntity volumeEntity = new GlusterVolumeEntity();
+        volumeEntity.setId(volumeId);
+        volumeEntity.setName("test-vol");
+        volumeEntity.setStatus((volumeId.equals(startedVolumeId)) ? 
GlusterStatus.UP : GlusterStatus.DOWN);
+        volumeEntity.setClusterId(CLUSTER_ID);
+        return volumeEntity;
+    }
+
+}
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/gluster/GlusterVolumeGeoRepSessionParameters.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/gluster/GlusterVolumeGeoRepSessionParameters.java
new file mode 100644
index 0000000..92ab2c8
--- /dev/null
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/gluster/GlusterVolumeGeoRepSessionParameters.java
@@ -0,0 +1,61 @@
+package org.ovirt.engine.core.common.action.gluster;
+
+import org.ovirt.engine.core.compat.Guid;
+
+public class GlusterVolumeGeoRepSessionParameters extends 
GlusterVolumeParameters{
+
+    private static final long serialVersionUID = -881348048838907389L;
+
+    private Guid geoRepSessionId;
+    private String slaveVolumeName;
+    private String slaveHost;
+    private boolean force;
+
+    public GlusterVolumeGeoRepSessionParameters() {
+        super();
+    }
+
+    public GlusterVolumeGeoRepSessionParameters(Guid volumeId, Guid 
geoRepSessionId) {
+        super(volumeId);
+        this.geoRepSessionId = geoRepSessionId;
+    }
+
+    public GlusterVolumeGeoRepSessionParameters(Guid volumeId, String 
slaveVolumeName, String slaveHost) {
+        super(volumeId);
+        this.slaveVolumeName = slaveVolumeName;
+        this.slaveHost = slaveHost;
+    }
+
+    public String getSlaveVolumeName() {
+        return slaveVolumeName;
+    }
+
+    public void setSlaveVolumeName(String slaveVolumeName) {
+        this.slaveVolumeName = slaveVolumeName;
+    }
+
+    public String getSlaveHost() {
+        return slaveHost;
+    }
+
+    public void setSlaveHost(String slaveHost) {
+        this.slaveHost = slaveHost;
+    }
+
+    public boolean isForce() {
+        return force;
+    }
+
+    public void setForce(boolean force) {
+        this.force = force;
+    }
+
+    public Guid getGeoRepSessionId() {
+        return geoRepSessionId;
+    }
+
+    public void setGeoRepSessionId(Guid geoRepSessionId) {
+        this.geoRepSessionId = geoRepSessionId;
+    }
+
+}
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
index 12c8485..9231029 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
@@ -48,6 +48,7 @@
     VAR__TYPE__GLUSTER_SERVER,
     VAR__TYPE__GLUSTER_HOOK,
     VAR__TYPE__GLUSTER_SERVICE,
+    VAR__TYPE__GLUSTER_GEOREP_SESSION,
 
     // External Event
     VAR__TYPE__EXTERNAL_EVENT,
@@ -929,6 +930,9 @@
     ACTION_TYPE_FAILED_NO_SERVERS_FOR_CLUSTER(ErrorType.BAD_PARAMETERS),
     ACTION_TYPE_FAILED_VOLUME_OPERATION_IN_PROGRESS(ErrorType.CONFLICT),
     ACTION_TYPE_FAILED_GLUSTER_OPERATION_INPROGRESS(ErrorType.CONFLICT),
+    ACTION_TYPE_FAILED_GEOREP_SESSION_INVALID(ErrorType.BAD_PARAMETERS),
+    ACTION_TYPE_FAILED_GEOREP_SESSION_LOCKED(ErrorType.CONFLICT),
+
     // OpenStack Glance
     ACTION_TYPE_FAILED_IMAGE_DOWNLOAD_ERROR(ErrorType.BAD_PARAMETERS),
     ACTION_TYPE_FAILED_IMAGE_NOT_SUPPORTED(ErrorType.BAD_PARAMETERS),
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/locks/LockingGroup.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/locks/LockingGroup.java
index 83801a6..6a9fadf 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/locks/LockingGroup.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/locks/LockingGroup.java
@@ -17,6 +17,8 @@
     REGISTER_VDS,
     VM_SNAPSHOTS,
     GLUSTER,
+    /** this group is used to lock geo-replication session */
+    GLUSTER_GEOREP,
     USER_VM_POOL,
     /** This group is used to lock template which is in export domain */
     REMOTE_TEMPLATE,
diff --git 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
index bbffa8b..2155bb9 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
@@ -1134,6 +1134,9 @@
 ACTION_TYPE_FAILED_GLUSTER_VOLUME_CANNOT_STOP_REBALANCE_IN_PROGRESS= Cannot 
${action} ${type}. Rebalance is running on the volume ${volumeName} in cluster 
${vdsGroup}.
 ACTION_TYPE_FAILED_GLUSTER_VOLUME_CANNOT_STOP_REMOVE_BRICK_IN_PROGRESS= Cannot 
${action} ${type}. Remove brick operation is running on the volume 
${volumeName} in cluster ${vdsGroup}.
 ACTION_TYPE_FAILED_GLUSTER_OPERATION_INPROGRESS=Cannot ${action} ${type}. 
Gluster operation is in progress in cluster. Please try again.
+ACTION_TYPE_FAILED_GEOREP_SESSION_INVALID=Cannot ${action} ${type}. 
Geo-replication session not found.
+ACTION_TYPE_FAILED_GEOREP_SESSION_LOCKED=Cannot ${action} ${type}. Another 
operation is in progress on this geo-replication session. Please try again.
+
 ACTION_TYPE_FAILED_TAG_ID_REQUIRED=Cannot ${action} ${type}. Tag ID is 
required.
 
 ACTION_TYPE_FAILED_QOS_OUT_OF_RANGE_VALUES=Cannot ${action} ${type}. Values 
are out of range.
diff --git 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
index b34e6aa..73a988f 100644
--- 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
+++ 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
@@ -3066,6 +3066,12 @@
     @DefaultStringValue("Cannot ${action} ${type}. Gluster operation is in 
progress in cluster. Please try again.")
     String ACTION_TYPE_FAILED_GLUSTER_OPERATION_INPROGRESS();
 
+    @DefaultStringValue("Cannot ${action} ${type}. Geo-replication session not 
found.")
+    String ACTION_TYPE_FAILED_GEOREP_SESSION_INVALID();
+
+    @DefaultStringValue("Cannot ${action} ${type}. Another operation is in 
progress on this geo-replication session. Please try again.")
+    String ACTION_TYPE_FAILED_GEOREP_SESSION_LOCKED();
+
     @DefaultStringValue("Cannot ${action} ${type}. All three values are needed 
in order to define QoS on each network directions.")
     String ACTION_TYPE_FAILED_NETWORK_QOS_MISSING_VALUES();
 
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
index 65cf3f6..9dc1003 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
+++ 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
@@ -1103,6 +1103,9 @@
 ACTION_TYPE_FAILED_GLUSTER_VOLUME_CANNOT_STOP_REBALANCE_IN_PROGRESS= Cannot 
${action} ${type}. Rebalance is running on the volume ${volumeName} in cluster 
${vdsGroup}.
 ACTION_TYPE_FAILED_GLUSTER_VOLUME_CANNOT_STOP_REMOVE_BRICK_IN_PROGRESS= Cannot 
${action} ${type}. Remove brick operation is running on the volume 
${volumeName} in cluster ${vdsGroup}.
 ACTION_TYPE_FAILED_GLUSTER_OPERATION_INPROGRESS=Cannot ${action} ${type}. 
Gluster operation is in progress in cluster. Please try again.
+ACTION_TYPE_FAILED_GEOREP_SESSION_INVALID=Cannot ${action} ${type}. 
Geo-replication session not found.
+ACTION_TYPE_FAILED_GEOREP_SESSION_LOCKED=Cannot ${action} ${type}. Another 
operation is in progress on this geo-replication session. Please try again.
+
 ACTION_TYPE_FAILED_TAG_ID_REQUIRED=Cannot ${action} ${type}. Tag ID is 
required.
 
 ACTION_TYPE_FAILED_QOS_OUT_OF_RANGE_VALUES=Cannot ${action} ${type}. Values 
are out of range.


-- 
To view, visit https://gerrit.ovirt.org/39580
To unsubscribe, visit https://gerrit.ovirt.org/settings

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

Reply via email to