Maor Lipchuk has uploaded a new change for review.

Change subject: restapi : Missing opertions for snapshots in RESTAPI(#867339)
......................................................................

restapi : Missing opertions for snapshots in RESTAPI(#867339)

In RESTAPI some opertions for snapshot are missing which are
available in webadmin.

This patch adds preview, commit and undo operations to the
snapshot resource.

Change-Id: If8c6d25daf7e716a7c857295b6ceb1741cbaf7f7
Bug-Url: https://bugzilla.redhat.com/970115
Signed-off-by: Maor Lipchuk <mlipc...@redhat.com>
---
M 
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/SnapshotResource.java
M 
backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
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
4 files changed, 141 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/56/24056/1

diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/SnapshotResource.java
 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/SnapshotResource.java
index ddf4eb0..910f934 100644
--- 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/SnapshotResource.java
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/SnapshotResource.java
@@ -37,7 +37,7 @@
     @Formatted
     public Snapshot get();
 
-    @Path("{action: (restore)}/{oid}")
+    @Path("{action: (restore|preview|commit|undo)}/{oid}")
     public ActionResource getActionSubresource(@PathParam("action") String 
action, @PathParam("oid") String oid);
 
     @POST
@@ -47,6 +47,27 @@
     @Path("restore")
     public Response restore(Action action);
 
+    @POST
+    @Formatted
+    @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, 
MediaType.APPLICATION_X_YAML})
+    @Actionable
+    @Path("preview")
+    public Response preview(Action action);
+
+    @POST
+    @Formatted
+    @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, 
MediaType.APPLICATION_X_YAML})
+    @Actionable
+    @Path("commit")
+    public Response commit(Action action);
+
+    @POST
+    @Formatted
+    @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, 
MediaType.APPLICATION_X_YAML})
+    @Actionable
+    @Path("undo")
+    public Response undo(Action action);
+
     @Path("cdroms")
     public SnapshotCdRomsResource getSnapshotCdRomsResource();
 
diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
 
b/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
index cca493e..82c84ec 100644
--- 
a/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
@@ -874,6 +874,33 @@
     headers:
       Content-Type: {value: application/xml|json, required: true}
       Correlation-Id: {value: 'any string', required: false}
+- name: /api/vms/{vm:id}/snapshots/{snapshot:id}/preview|rel=preview
+  request:
+    body:
+      parameterType: Action
+      signatures: []
+    urlparams: {}
+    headers:
+      Content-Type: {value: application/xml|json, required: true}
+      Correlation-Id: {value: 'any string', required: false}
+- name: /api/vms/{vm:id}/snapshots/{snapshot:id}/commit|rel=commit
+  request:
+    body:
+      parameterType: Action
+      signatures: []
+    urlparams: {}
+    headers:
+      Content-Type: {value: application/xml|json, required: true}
+      Correlation-Id: {value: 'any string', required: false}
+- name: /api/vms/{vm:id}/snapshots/{snapshot:id}/undo|rel=undo
+  request:
+    body:
+      parameterType: Action
+      signatures: []
+    urlparams: {}
+    headers:
+      Content-Type: {value: application/xml|json, required: true}
+      Correlation-Id: {value: 'any string', required: false}
 - name: /vms/{vm:id}/snapshots/{snapshot:id}/cdroms|rel=get
   description: get the list of cdroms attached to the virtual machine at the 
time the snapshot was created
   request:
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 9469d3f..b261692 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
@@ -6,6 +6,7 @@
 
 import org.ovirt.engine.api.model.Action;
 import org.ovirt.engine.api.model.Snapshot;
+import org.ovirt.engine.api.model.SnapshotStatus;
 import org.ovirt.engine.api.resource.ActionResource;
 import org.ovirt.engine.api.resource.CreationResource;
 import org.ovirt.engine.api.resource.SnapshotCdRomsResource;
@@ -76,6 +77,33 @@
     }
 
     @Override
+    public Response undo(Action action) {
+        RestoreAllSnapshotsParameters restoreParams = new 
RestoreAllSnapshotsParameters(parentId, SnapshotAction.UNDO);
+        Response response = doAction(VdcActionType.RestoreAllSnapshots,
+                restoreParams,
+                action);
+        return response;
+    }
+
+    @Override
+    public Response commit(Action action) {
+        RestoreAllSnapshotsParameters restoreParams = new 
RestoreAllSnapshotsParameters(parentId, SnapshotAction.COMMIT);
+        Response response = doAction(VdcActionType.RestoreAllSnapshots,
+                restoreParams,
+                action);
+        return response;
+    }
+
+    @Override
+    public Response preview(Action action) {
+        TryBackToAllSnapshotsOfVmParameters tryBackParams = new 
TryBackToAllSnapshotsOfVmParameters(parentId, guid);
+        Response response = doAction(VdcActionType.TryBackToAllSnapshotsOfVm,
+                tryBackParams,
+                action);
+        return response;
+    }
+
+    @Override
     public CreationResource getCreationSubresource(String ids) {
         return inject(new BackendCreationResource(ids));
     }
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 fcefeb5..5a16b1f 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
@@ -5,6 +5,7 @@
 import java.util.List;
 
 import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 
 import org.junit.Before;
@@ -21,6 +22,10 @@
 import org.ovirt.engine.core.common.queries.VdcQueryType;
 import org.ovirt.engine.core.compat.Guid;
 import static org.easymock.EasyMock.expect;
+import org.ovirt.engine.api.model.CreationStatus;
+import org.ovirt.engine.core.common.action.VdcActionParametersBase;
+import org.ovirt.engine.core.common.businessentities.AsyncTaskStatus;
+import org.ovirt.engine.core.common.businessentities.AsyncTaskStatusEnum;
 
 public class BackendSnapshotResourceTest extends 
AbstractBackendSubResourceTest<Snapshot, 
org.ovirt.engine.core.common.businessentities.Snapshot, 
BackendSnapshotResource> {
 
@@ -115,6 +120,65 @@
         resource.restore(new Action());
     }
 
+    @Test
+    public void testPreview() throws Exception {
+        
setUriInfo(setUpActionExpectations(VdcActionType.TryBackToAllSnapshotsOfVm,
+                                           
TryBackToAllSnapshotsOfVmParameters.class,
+                                           new String[] { "VmId", 
"DstSnapshotId" },
+                                           new Object[] { VM_ID, SNAPSHOT_ID },
+                                           asList(GUIDS[1]),
+                                           asList(new 
AsyncTaskStatus(AsyncTaskStatusEnum.finished))));
+        Response response = resource.preview(new Action());
+        verifyActionResponse(response);
+        Action action = (Action)response.getEntity();
+        assertTrue(action.isSetStatus());
+        assertEquals(CreationStatus.COMPLETE.value(), 
action.getStatus().getState());
+    }
+
+    @Test
+    public void testUndo() throws Exception {
+        setUriInfo(setUpActionExpectations(VdcActionType.RestoreAllSnapshots,
+                                           RestoreAllSnapshotsParameters.class,
+                                           new String[] { "VmId", 
"DstSnapshotId" },
+                                           new Object[] { VM_ID, SNAPSHOT_ID },
+                                           asList(GUIDS[1]),
+                                           asList(new 
AsyncTaskStatus(AsyncTaskStatusEnum.finished))));
+        Response response = resource.undo(new Action());
+        verifyActionResponse(response);
+        Action action = (Action)response.getEntity();
+        assertTrue(action.isSetStatus());
+        assertEquals(CreationStatus.COMPLETE.value(), 
action.getStatus().getState());
+    }
+
+    @Test
+    public void testCommit() throws Exception {
+        setUriInfo(setUpActionExpectations(VdcActionType.RestoreAllSnapshots,
+                                           RestoreAllSnapshotsParameters.class,
+                                           new String[] { "VmId", 
"DstSnapshotId" },
+                                           new Object[] { VM_ID, SNAPSHOT_ID },
+                                           asList(GUIDS[1]),
+                                           asList(new 
AsyncTaskStatus(AsyncTaskStatusEnum.finished))));
+        Response response = resource.commit(new Action());
+        verifyActionResponse(response);
+        Action action = (Action)response.getEntity();
+        assertTrue(action.isSetStatus());
+        assertEquals(CreationStatus.COMPLETE.value(), 
action.getStatus().getState());
+    }
+
+    protected UriInfo setUpActionExpectations(VdcActionType task,
+                                              Class<? extends 
VdcActionParametersBase> clz,
+                                              String[] names,
+                                              Object[] values,
+                                              ArrayList<Guid> asyncTasks,
+                                              ArrayList<AsyncTaskStatus> 
asyncStatuses) {
+        String uri = "snapshots/" + GUIDS[0] + "/action";
+        return setUpActionExpectations(task, clz, names, values, true, true, 
null, asyncTasks, asyncStatuses, null, null, uri, true);
+    }
+
+    private void verifyActionResponse(Response r) throws Exception {
+        verifyActionResponse(r, "snapshots/" + GUIDS[0], true);
+    }
+
     protected UriInfo setUpTryBackExpectations() {
         return setUpActionExpectations(
                 VdcActionType.TryBackToAllSnapshotsOfVm,


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

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

Reply via email to