Shubhendu Tripathi has uploaded a new change for review.

Change subject: gluster: Remove bricks from DB after commit completion
......................................................................

gluster: Remove bricks from DB after commit completion

Added logic to remove the bricks from DB after the commit is performed.

Change-Id: Ie0a21f013833833710abc219c1a066a2250bc5fb
Signed-off-by: Shubhendu Tripathi <shtri...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/CommitRemoveGlusterVolumeBricksCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterVolumeRemoveBricksCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StopRemoveGlusterVolumeBricksCommand.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/CommitRemoveGlusterVolumeBricksCommandTest.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/StopRemoveGlusterVolumeBricksCommandTest.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterDBUtils.java
6 files changed, 85 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/09/20109/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/CommitRemoveGlusterVolumeBricksCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/CommitRemoveGlusterVolumeBricksCommand.java
index b73c311..f84ecb1 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/CommitRemoveGlusterVolumeBricksCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/CommitRemoveGlusterVolumeBricksCommand.java
@@ -16,6 +16,7 @@
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 import org.ovirt.engine.core.common.vdscommands.VDSReturnValue;
 import 
org.ovirt.engine.core.common.vdscommands.gluster.GlusterVolumeRemoveBricksVDSParameters;
+import org.ovirt.engine.core.dao.gluster.GlusterDBUtils;
 
 /**
  * BLL command to commit bricks removal asynchronous task started on a gluster 
volume
@@ -41,6 +42,10 @@
 
         if (!super.canDoAction()) {
             return false;
+        }
+
+        if (getParameters().getBricks().isEmpty()) {
+            return 
failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_BRICKS_REQUIRED);
         }
 
         if (!(GlusterTaskUtils.isTaskOfType(volume, 
GlusterTaskType.REMOVE_BRICK))
@@ -73,11 +78,14 @@
 
         endStepJobCommitted();
         releaseVolumeLock();
+        getDbUtils().removeBricksFromVolumeInDb(volume,
+                getParameters().getBricks(),
+                getParameters().getReplicaCount());
         getReturnValue().setActionReturnValue(returnValue.getReturnValue());
     }
 
     protected void endStepJobCommitted() {
-        endStepJob(JobExecutionStatus.FINISHED, 
getStepMessageMap(JobExecutionStatus.FINISHED),true);
+        endStepJob(JobExecutionStatus.FINISHED, 
getStepMessageMap(JobExecutionStatus.FINISHED), true);
     }
 
     @Override
@@ -100,4 +108,8 @@
     public BackendInternal getBackend() {
         return super.getBackend();
     }
+
+    public GlusterDBUtils getDbUtils() {
+        return GlusterDBUtils.getInstance();
+    }
 }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterVolumeRemoveBricksCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterVolumeRemoveBricksCommand.java
index bb4a034..6e7f575 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterVolumeRemoveBricksCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterVolumeRemoveBricksCommand.java
@@ -16,6 +16,7 @@
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 import org.ovirt.engine.core.common.vdscommands.VDSReturnValue;
 import 
org.ovirt.engine.core.common.vdscommands.gluster.GlusterVolumeRemoveBricksVDSParameters;
+import org.ovirt.engine.core.dao.gluster.GlusterDBUtils;
 
 /**
  * BLL command to Remove Bricks from Gluster volume
@@ -49,7 +50,9 @@
         }
 
         GlusterBrickValidator brickValidator = new GlusterBrickValidator();
-        return 
validate(brickValidator.validateBricks(getParameters().getBricks(), 
getGlusterVolume(), getParameters().getReplicaCount()));
+        return 
validate(brickValidator.validateBricks(getParameters().getBricks(),
+                getGlusterVolume(),
+                getParameters().getReplicaCount()));
     }
 
     @Override
@@ -66,7 +69,9 @@
                                 getGlusterVolumeName(), 
getParameters().getBricks(), replicaCount, true));
         setSucceeded(returnValue.getSucceeded());
         if (getSucceeded()) {
-            removeBricksFromVolumeInDb(getParameters().getBricks());
+            
GlusterDBUtils.getInstance().removeBricksFromVolumeInDb(getGlusterVolume(),
+                    getParameters().getBricks(),
+                    getParameters().getReplicaCount());
         } else {
             handleVdsError(AuditLogType.GLUSTER_VOLUME_REMOVE_BRICKS_FAILED, 
returnValue.getVdsError().getMessage());
             return;
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StopRemoveGlusterVolumeBricksCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StopRemoveGlusterVolumeBricksCommand.java
index b1c39be..e5ddf97 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StopRemoveGlusterVolumeBricksCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StopRemoveGlusterVolumeBricksCommand.java
@@ -39,6 +39,10 @@
             return false;
         }
 
+        if (getParameters().getBricks().isEmpty()) {
+            return 
failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_BRICKS_REQUIRED);
+        }
+
         if (!(GlusterTaskUtils.isTaskOfType(volume, 
GlusterTaskType.REMOVE_BRICK))
                 || !(GlusterTaskUtils.isTaskStatus(volume, 
JobExecutionStatus.STARTED))) {
             return 
failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_GLUSTER_VOLUME_REMOVE_BRICKS_NOT_STARTED);
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/CommitRemoveGlusterVolumeBricksCommandTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/CommitRemoveGlusterVolumeBricksCommandTest.java
index caf0d31..e90f60e 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/CommitRemoveGlusterVolumeBricksCommandTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/CommitRemoveGlusterVolumeBricksCommandTest.java
@@ -43,17 +43,23 @@
 import org.ovirt.engine.core.common.vdscommands.VDSReturnValue;
 import 
org.ovirt.engine.core.common.vdscommands.gluster.GlusterVolumeVDSParameters;
 import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dao.gluster.GlusterBrickDao;
+import org.ovirt.engine.core.dao.gluster.GlusterDBUtils;
 import org.ovirt.engine.core.dao.gluster.GlusterVolumeDao;
 
 @RunWith(MockitoJUnitRunner.class)
 public class CommitRemoveGlusterVolumeBricksCommandTest {
 
     @Mock
-    GlusterVolumeDao volumeDao;
+    protected GlusterVolumeDao volumeDao;
+    @Mock
+    protected GlusterBrickDao brickDao;
     @Mock
     protected BackendInternal backend;
     @Mock
     protected VDSBrokerFrontend vdsBrokerFrontend;
+    @Mock
+    protected GlusterDBUtils dbUtils;
 
     private final Guid volumeWithRemoveBricksTask = new 
Guid("8bc6f108-c0ef-43ab-ba20-ec41107220f5");
     private final Guid volumeWithRemoveBricksTaskNotFinished = new 
Guid("b2cb2f73-fab3-4a42-93f0-d5e4c069a43e");
@@ -69,6 +75,8 @@
 
     private void prepareMocks(CommitRemoveGlusterVolumeBricksCommand command) {
         doReturn(volumeDao).when(command).getGlusterVolumeDao();
+        doReturn(brickDao).when(command).getGlusterBrickDao();
+        doReturn(dbUtils).when(command).getDbUtils();
         doReturn(getVds(VDSStatus.Up)).when(command).getUpServer();
         
doReturn(getVolumeWithRemoveBricksTask(volumeWithRemoveBricksTask)).when(volumeDao)
                 .getById(volumeWithRemoveBricksTask);
@@ -250,4 +258,13 @@
         prepareMocks(cmd);
         assertFalse(cmd.canDoAction());
     }
+
+    @Test
+    public void canDoActionFailsWithEmptyBricksList() {
+        cmd =
+                spy(new CommitRemoveGlusterVolumeBricksCommand(new 
GlusterVolumeRemoveBricksParameters(volumeWithoutRemoveBricksTask,
+                        new ArrayList<GlusterBrickEntity>())));
+        prepareMocks(cmd);
+        assertFalse(cmd.canDoAction());
+    }
 }
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/StopRemoveGlusterVolumeBricksCommandTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/StopRemoveGlusterVolumeBricksCommandTest.java
index 31ad44d..ea51849 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/StopRemoveGlusterVolumeBricksCommandTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/StopRemoveGlusterVolumeBricksCommandTest.java
@@ -248,4 +248,13 @@
         prepareMocks(cmd);
         assertFalse(cmd.canDoAction());
     }
+
+    @Test
+    public void canDoActionFailsWithEmptyBricksList() {
+        cmd =
+                spy(new StopRemoveGlusterVolumeBricksCommand(new 
GlusterVolumeRemoveBricksParameters(volumeWithoutRemoveBricksTask,
+                        new ArrayList<GlusterBrickEntity>())));
+        prepareMocks(cmd);
+        assertFalse(cmd.canDoAction());
+    }
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterDBUtils.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterDBUtils.java
index 9edceea..b5539c3 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterDBUtils.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterDBUtils.java
@@ -7,6 +7,8 @@
 import org.ovirt.engine.core.common.businessentities.VdsStatic;
 import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity;
 import org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus;
+import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity;
+import org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeType;
 import 
org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
@@ -99,4 +101,36 @@
             throw new RuntimeException(e);
         }
     }
+
+    public void removeBricksFromVolumeInDb(GlusterVolumeEntity volume,
+            List<GlusterBrickEntity> brickList,
+            int volumeReplicaCount) {
+        getGlusterBrickDao().removeAllInBatch(brickList);
+
+        // Update volume type and replica/stripe count
+        if (volume.getVolumeType() == GlusterVolumeType.DISTRIBUTED_REPLICATE
+                && volume.getReplicaCount() == (volume.getBricks().size() - 
brickList.size())) {
+            volume.setVolumeType(GlusterVolumeType.REPLICATE);
+        }
+        if (volume.getVolumeType().isReplicatedType()) {
+            int replicaCount =
+                    (volumeReplicaCount == 0)
+                            ? volume.getReplicaCount()
+                            : volumeReplicaCount;
+            volume.setReplicaCount(replicaCount);
+            getGlusterVolumeDao().updateGlusterVolume(volume);
+        }
+
+        if (volume.getVolumeType() == GlusterVolumeType.DISTRIBUTED_STRIPE
+                && volume.getStripeCount() == (volume.getBricks().size() - 
brickList.size())) {
+            volume.setVolumeType(GlusterVolumeType.STRIPE);
+            getGlusterVolumeDao().updateGlusterVolume(volume);
+        }
+
+        if (volume.getVolumeType() == 
GlusterVolumeType.DISTRIBUTED_STRIPED_REPLICATE
+                && (volume.getStripeCount() * volume.getReplicaCount()) == 
(volume.getBricks().size() - brickList.size())) {
+            volume.setVolumeType(GlusterVolumeType.STRIPED_REPLICATE);
+            getGlusterVolumeDao().updateGlusterVolume(volume);
+        }
+    }
 }


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

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

Reply via email to