Shubhendu Tripathi has uploaded a new change for review.

Change subject: restapi: Execute commit remove brick if delete without force
......................................................................

restapi: Execute commit remove brick if delete without force

Introduced a DELETE action which takes set of bricks and force
parameters and deletes the bricks from the volume. If force parameter is
set to true, the deletion of brick happens without any data migration.
If force option is not passed or set to false, it deletes the brick if
data migration has already happened on the brick.

Change-Id: I7830749bb84f61dd1a80281d3abe6dc113150fd1
Signed-off-by: Shubhendu Tripathi <shtri...@redhat.com>
---
M 
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/gluster/GlusterBricksResource.java
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/gluster/BackendGlusterBricksResource.java
M 
backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/gluster/BackendGlusterBricksResourceTest.java
3 files changed, 57 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/43/21043/1

diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/gluster/GlusterBricksResource.java
 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/gluster/GlusterBricksResource.java
index 6efa9b0..e2f1b13 100644
--- 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/gluster/GlusterBricksResource.java
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/gluster/GlusterBricksResource.java
@@ -55,9 +55,19 @@
      */
     @DELETE
     @RsdlIgnore //TODO: remove this when we have support for delete at 
collection level in yaml metadata
+    @Deprecated
     public Response remove(GlusterBricks bricks);
 
     /**
+     * Removes the given bricks set from the volume and deletes it from the 
database.<br>
+     * If force option is passed as part of parameters, the delete bricks is 
forceful without any data migration
+     * and if without force option is selected, the delete is meant with 
migration of data
+     */
+    @DELETE
+    @Consumes({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, 
ApiMediaType.APPLICATION_X_YAML})
+    public Response remove(Action action);
+
+    /**
      * Removes the given brick from the volume and deletes it from the 
database.
      *
      * @param id
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/gluster/BackendGlusterBricksResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/gluster/BackendGlusterBricksResource.java
index 7e2ff0c..512a2d0 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/gluster/BackendGlusterBricksResource.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/gluster/BackendGlusterBricksResource.java
@@ -146,16 +146,32 @@
 
     @Override
     public Response remove(GlusterBricks bricks) {
+        return performForceRemove(bricks, null);
+    }
+
+    private Response performForceRemove(GlusterBricks bricks, 
GlusterVolumeRemoveBricksParameters params) {
         if (bricks.getGlusterBricks().size() > 0) {
             for (GlusterBrick brick : bricks.getGlusterBricks()) {
-                validateParameters(brick, "id");
+                validateParameters(brick, "id|name");
             }
         }
+
         int replicaCount = bricks.isSetReplicaCount() ? 
bricks.getReplicaCount() : 0;
-        return performAction(VdcActionType.GlusterVolumeRemoveBricks,
-                new GlusterVolumeRemoveBricksParameters(asGuid(getVolumeId()),
-                        mapBricks(asGuid(getVolumeId()), bricks),
-                        replicaCount));
+        if (params == null) {
+            params = new 
GlusterVolumeRemoveBricksParameters(asGuid(getVolumeId()), 
mapBricks(asGuid(getVolumeId()), bricks), replicaCount);
+        }
+
+        return performAction(VdcActionType.GlusterVolumeRemoveBricks, params);
+    }
+
+    @Override
+    public Response remove(Action action) {
+        boolean forceRemove = action.isSetForce() ? true : false;
+        validateParameters(action, "bricks");
+        validateBrickNames(action);
+        GlusterVolumeRemoveBricksParameters params = toParameters(action);
+        return forceRemove ? performForceRemove(action.getBricks(), params) : 
performAction(VdcActionType.CommitRemoveGlusterVolumeBricks,
+                params);
     }
 
     @Override
@@ -217,7 +233,7 @@
             entity.setBrickDirectory(brick.getBrickDir());
             entity.setVolumeId(new Guid(getVolumeId()));
             if (brick.getName() != null) {
-                String [] arr = brick.getName().split("\\:");
+                String[] arr = brick.getName().split("\\:");
                 if (arr.length > 1) {
                     entity.setServerName(arr[0]);
                     entity.setBrickDirectory(arr[1]);
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/gluster/BackendGlusterBricksResourceTest.java
 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/gluster/BackendGlusterBricksResourceTest.java
index 161ff10..9b13866 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/gluster/BackendGlusterBricksResourceTest.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/gluster/BackendGlusterBricksResourceTest.java
@@ -42,7 +42,8 @@
     private static final String serverName = "testServer";
     private BackendGlusterVolumeResource parentMock;
     private GlusterTestHelper helper;
-    private static final String MIGRATE_BRICKS_ACTION_BASE_URL = "/clusters/" 
+ clusterId + "/glustervolumes/" + volumeId;
+    private static final String MIGRATE_BRICKS_ACTION_BASE_URL = "/clusters/" 
+ clusterId + "/glustervolumes/"
+            + volumeId;
 
     public BackendGlusterBricksResourceTest() {
         super(new BackendGlusterBricksResource(),
@@ -186,6 +187,28 @@
     }
 
     @Test
+    public void testRemoveWithAction() throws Exception {
+        GlusterBrick brick = new GlusterBrick();
+        GlusterVolume volume = new GlusterVolume();
+        brick.setName(serverName + ":" + brickDir);
+        volume.setId(volumeId.toString());
+        brick.setGlusterVolume(volume);
+
+        GlusterBricks bricks = control.createMock(GlusterBricks.class);
+        
expect(bricks.getGlusterBricks()).andReturn(Collections.singletonList(brick)).anyTimes();
+
+        
setUriInfo(setUpActionExpectations(VdcActionType.CommitRemoveGlusterVolumeBricks,
+                GlusterVolumeRemoveBricksParameters.class,
+                new String [] {},
+                new Object [] {},
+                true,
+                true));
+        Action action = new Action();
+        action.setBricks(bricks);
+        collection.remove(action);
+    }
+
+    @Test
     public void testMigrate() throws Exception {
         GlusterBrick brick = new GlusterBrick();
         GlusterVolume volume = new GlusterVolume();
@@ -198,7 +221,7 @@
 
         
setUriInfo(setUpActionExpectations(VdcActionType.StartRemoveGlusterVolumeBricks,
                 GlusterVolumeRemoveBricksParameters.class,
-                new String [] {},
+                new String[] {},
                 new Object[] {},
                 true,
                 true));


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

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