Ravi Nori has uploaded a new change for review.

Change subject: restapi : undo snapshot preview through restapi commits 
snapshot(#1018554)
......................................................................

restapi : undo snapshot preview through restapi commits snapshot(#1018554)

Attempting to undo a snapshot preview through RESTAPI
commits that snapshot, removing any snapshots that were
taken after the snapshot was originally created, just
like committing the snapshot preview, instead of returning
to the "Active before preview" snapshot and having all
snapshots available.

Change-Id: Icb5b226497664ded1f3c2c99d979a6da9e7a75aa
Bug-Url: https://bugzilla.redhat.com/1018554
Signed-off-by: Ravi Nori <[email protected]>
---
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendSnapshotResource.java
M 
backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendSnapshotResourceTest.java
2 files changed, 43 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/25/20625/1

diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendSnapshotResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendSnapshotResource.java
index 30f5861..ae93bfd 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendSnapshotResource.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendSnapshotResource.java
@@ -1,10 +1,12 @@
 package org.ovirt.engine.api.restapi.resource;
 
+import javax.ws.rs.WebApplicationException;
 import static 
org.ovirt.engine.api.restapi.resource.BackendSnapshotsResource.SUB_COLLECTIONS;
 
 import javax.ws.rs.core.Response;
 
 import org.ovirt.engine.api.model.Action;
+import org.ovirt.engine.api.model.Fault;
 import org.ovirt.engine.api.model.Snapshot;
 import org.ovirt.engine.api.resource.ActionResource;
 import org.ovirt.engine.api.resource.CreationResource;
@@ -15,6 +17,8 @@
 import org.ovirt.engine.core.common.action.RestoreAllSnapshotsParameters;
 import org.ovirt.engine.core.common.action.TryBackToAllSnapshotsOfVmParameters;
 import org.ovirt.engine.core.common.action.VdcActionType;
+import org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotStatus;
+import org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotType;
 import org.ovirt.engine.core.compat.Guid;
 
 public class BackendSnapshotResource extends 
AbstractBackendActionableResource<Snapshot, 
org.ovirt.engine.core.common.businessentities.Snapshot> implements 
SnapshotResource {
@@ -73,6 +77,13 @@
 
     @Override
     public Response undo(Action action) {
+        org.ovirt.engine.core.common.businessentities.Snapshot entity = 
getSnapshot();
+        if (entity.getType()!= SnapshotType.PREVIEW) {
+            Fault f = new Fault();
+            f.setReason("Expected snapshot of type Preview");
+            Response response = 
Response.status(Response.Status.BAD_REQUEST).entity(f).build();
+            throw new WebApplicationException(response);
+        }
         RestoreAllSnapshotsParameters restoreParams = new 
RestoreAllSnapshotsParameters(parentId, guid);
         Response response = doAction(VdcActionType.RestoreAllSnapshots,
                 restoreParams,
@@ -82,6 +93,13 @@
 
     @Override
     public Response commit(Action action) {
+        org.ovirt.engine.core.common.businessentities.Snapshot entity = 
getSnapshot();
+        if (entity.getStatus()!= SnapshotStatus.IN_PREVIEW) {
+            Fault f = new Fault();
+            f.setReason("Expected snapshot in status IN_PREVIEW");
+            Response response = 
Response.status(Response.Status.BAD_REQUEST).entity(f).build();
+            throw new WebApplicationException(response);
+        }
         RestoreAllSnapshotsParameters restoreParams = new 
RestoreAllSnapshotsParameters(parentId, guid);
         Response response = doAction(VdcActionType.RestoreAllSnapshots,
                 restoreParams,
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendSnapshotResourceTest.java
 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendSnapshotResourceTest.java
index 4bb3446..9d7cc75 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendSnapshotResourceTest.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendSnapshotResourceTest.java
@@ -136,12 +136,20 @@
 
     @Test
     public void testUndo() throws Exception {
+
+        String uri = "snapshots/" + GUIDS[0] + "/action";
         setUriInfo(setUpActionExpectations(VdcActionType.RestoreAllSnapshots,
-                                           RestoreAllSnapshotsParameters.class,
-                                           new String[] { "VmId", 
"DstSnapshotId" },
-                                           new Object[] { VM_ID, SNAPSHOT_ID },
-                                           asList(GUIDS[1]),
-                                           asList(new 
AsyncTaskStatus(AsyncTaskStatusEnum.finished))));
+                RestoreAllSnapshotsParameters.class,
+                new String[]{"VmId", "DstSnapshotId"},
+                new Object[]{VM_ID, SNAPSHOT_ID},
+                true, true, null,
+                asList(GUIDS[1]),
+                asList(new AsyncTaskStatus(AsyncTaskStatusEnum.finished)),
+                null, null, uri, false));
+        org.ovirt.engine.core.common.businessentities.Snapshot snapshot = 
getEntity(1);
+        
expect(snapshot.getType()).andReturn(org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotType.PREVIEW).anyTimes();
+        setUpGetEntityExpectations(asList(snapshot));
+        control.replay();
         Response response = resource.undo(new Action());
         verifyActionResponse(response);
         Action action = (Action)response.getEntity();
@@ -151,12 +159,19 @@
 
     @Test
     public void testCommit() throws Exception {
+        String uri = "snapshots/" + GUIDS[0] + "/action";
         setUriInfo(setUpActionExpectations(VdcActionType.RestoreAllSnapshots,
-                                           RestoreAllSnapshotsParameters.class,
-                                           new String[] { "VmId", 
"DstSnapshotId" },
-                                           new Object[] { VM_ID, SNAPSHOT_ID },
-                                           asList(GUIDS[1]),
-                                           asList(new 
AsyncTaskStatus(AsyncTaskStatusEnum.finished))));
+                RestoreAllSnapshotsParameters.class,
+                new String[]{"VmId", "DstSnapshotId"},
+                new Object[]{VM_ID, SNAPSHOT_ID},
+                true, true, null,
+                asList(GUIDS[1]),
+                asList(new AsyncTaskStatus(AsyncTaskStatusEnum.finished)),
+                null, null, uri, false));
+        org.ovirt.engine.core.common.businessentities.Snapshot snapshot = 
getEntity(1);
+        
expect(snapshot.getStatus()).andReturn(org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotStatus.IN_PREVIEW).anyTimes();
+        setUpGetEntityExpectations(asList(snapshot));
+        control.replay();
         Response response = resource.commit(new Action());
         verifyActionResponse(response);
         Action action = (Action)response.getEntity();


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icb5b226497664ded1f3c2c99d979a6da9e7a75aa
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Ravi Nori <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to