Maor Lipchuk has uploaded a new change for review.

Change subject: restapi : Missing opertions for snapshots in RESTAPI
......................................................................

restapi : Missing opertions for snapshots in RESTAPI

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/867339
Signed-off-by: Maor Lipchuk <[email protected]>
---
M 
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/VmResource.java
M 
backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
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/BackendVmResource.java
M 
backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmResourceTest.java
5 files changed, 130 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/91/25691/1

diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/VmResource.java
 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/VmResource.java
index c010b9c..12ed946 100644
--- 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/VmResource.java
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/VmResource.java
@@ -34,7 +34,7 @@
 @Produces({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, 
ApiMediaType.APPLICATION_X_YAML})
 public interface VmResource extends UpdatableResource<VM>, 
AsynchronouslyCreatedResource, MeasurableResource {
 
-    @Path("{action: 
(start|stop|shutdown|reboot|suspend|detach|migrate|export|move|ticket|cancelmigration)}/{oid}")
+    @Path("{action: 
(start|stop|shutdown|reboot|suspend|detach|migrate|export|move|ticket|cancelmigration|preview_snapshot|commit_snapshot|undo_snapshot)}/{oid}")
     public ActionResource getActionSubresource(@PathParam("action")String 
action, @PathParam("oid")String oid);
 
     @POST
@@ -110,6 +110,27 @@
 
     @POST
     @Formatted
+    @Consumes({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, 
ApiMediaType.APPLICATION_X_YAML})
+    @Actionable
+    @Path("preview_snapshot")
+    public Response previewSnapshot(Action action);
+
+    @POST
+    @Formatted
+    @Consumes({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, 
ApiMediaType.APPLICATION_X_YAML})
+    @Actionable
+    @Path("commit_snapshot")
+    public Response commitSnapshot(Action action);
+
+    @POST
+    @Formatted
+    @Consumes({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, 
ApiMediaType.APPLICATION_X_YAML})
+    @Actionable
+    @Path("undo_snapshot")
+    public Response undoSnapshot(Action action);
+
+    @POST
+    @Formatted
     @Consumes({ ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, 
ApiMediaType.APPLICATION_X_YAML })
     @Actionable
     @Path("cancelmigration")
diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
 
b/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
index 5927a70..c9d890b 100644
--- 
a/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
@@ -167,6 +167,8 @@
       <xs:element name="exclusive" type="xs:boolean" minOccurs="0"/>
       <!-- For VM start -->
       <xs:element ref="vm" minOccurs="0" maxOccurs="1"/>
+      <!-- For VM preview -->
+      <xs:element name="snapshot" type="Snapshot" minOccurs="0" maxOccurs="1"/>
       <!-- For import template -->
       <xs:element ref="template" minOccurs="0" maxOccurs="1"/>
       <!-- For Setup Networks -->
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 688fdee..7f81147 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
@@ -365,6 +365,34 @@
     headers:
       Content-Type: {value: application/xml|json, required: true}
       Correlation-Id: {value: 'any string', required: false}
+- name: /api/vms/{vm:id}/preview_snapshot|rel=preview_snapshot
+  request:
+    body:
+      parameterType: Action
+      signatures:
+      - mandatoryArguments: {action.snapshot.id: 'xs:string'}
+    urlparams: {}
+    headers:
+      Content-Type: {value: application/xml|json, required: true}
+      Correlation-Id: {value: 'any string', required: false}
+- name: /api/vms/{vm:id}/commit_snapshot|rel=commit_snapshot
+  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}/undo_snapshot|rel=undo_snapshot
+  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}/detach|rel=detach
   description: detach a virtual machine in the system identified by the given 
id from the storage domain
   request:
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java
index 54187bd..e420f93 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java
@@ -46,17 +46,20 @@
 import org.ovirt.engine.core.common.action.MigrateVmToServerParameters;
 import org.ovirt.engine.core.common.action.MoveVmParameters;
 import org.ovirt.engine.core.common.action.RemoveVmFromPoolParameters;
+import org.ovirt.engine.core.common.action.RestoreAllSnapshotsParameters;
 import org.ovirt.engine.core.common.action.RunVmOnceParams;
 import org.ovirt.engine.core.common.action.RunVmParams;
 import org.ovirt.engine.core.common.action.SetVmTicketParameters;
 import org.ovirt.engine.core.common.action.ShutdownVmParameters;
 import org.ovirt.engine.core.common.action.StopVmParameters;
 import org.ovirt.engine.core.common.action.StopVmTypeEnum;
+import org.ovirt.engine.core.common.action.TryBackToAllSnapshotsOfVmParameters;
 import org.ovirt.engine.core.common.action.VdcActionParametersBase;
 import org.ovirt.engine.core.common.action.VdcActionType;
 import org.ovirt.engine.core.common.action.VmManagementParametersBase;
 import org.ovirt.engine.core.common.action.VmOperationParameterBase;
 import org.ovirt.engine.core.common.businessentities.InitializationType;
+import org.ovirt.engine.core.common.businessentities.SnapshotActionEnum;
 import org.ovirt.engine.core.common.businessentities.VDS;
 import org.ovirt.engine.core.common.businessentities.VDSGroup;
 import org.ovirt.engine.core.common.businessentities.VmInit;
@@ -234,6 +237,34 @@
     }
 
     @Override
+    public Response undoSnapshot(Action action) {
+        RestoreAllSnapshotsParameters restoreParams = new 
RestoreAllSnapshotsParameters(guid, SnapshotActionEnum.UNDO);
+        Response response = doAction(VdcActionType.RestoreAllSnapshots,
+                restoreParams,
+                action);
+        return response;
+    }
+
+    @Override
+    public Response commitSnapshot(Action action) {
+        RestoreAllSnapshotsParameters restoreParams = new 
RestoreAllSnapshotsParameters(guid, SnapshotActionEnum.COMMIT);
+        Response response = doAction(VdcActionType.RestoreAllSnapshots,
+                restoreParams,
+                action);
+        return response;
+    }
+
+    @Override
+    public Response previewSnapshot(Action action) {
+        TryBackToAllSnapshotsOfVmParameters tryBackParams =
+                new TryBackToAllSnapshotsOfVmParameters(guid, 
asGuid(action.getSnapshot().getId()));
+        Response response = doAction(VdcActionType.TryBackToAllSnapshotsOfVm,
+                tryBackParams,
+                action);
+        return response;
+    }
+
+    @Override
     public Response start(Action action) {
         RunVmParams params;
         VdcActionType actionType;
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmResourceTest.java
 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmResourceTest.java
index e3b2dae..4477ce1 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmResourceTest.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmResourceTest.java
@@ -44,12 +44,14 @@
 import org.ovirt.engine.core.common.action.MigrateVmToServerParameters;
 import org.ovirt.engine.core.common.action.MoveVmParameters;
 import org.ovirt.engine.core.common.action.RemoveVmFromPoolParameters;
+import org.ovirt.engine.core.common.action.RestoreAllSnapshotsParameters;
 import org.ovirt.engine.core.common.action.RunVmOnceParams;
 import org.ovirt.engine.core.common.action.RunVmParams;
 import org.ovirt.engine.core.common.action.SetVmTicketParameters;
 import org.ovirt.engine.core.common.action.ShutdownVmParameters;
 import org.ovirt.engine.core.common.action.StopVmParameters;
 import org.ovirt.engine.core.common.action.StopVmTypeEnum;
+import org.ovirt.engine.core.common.action.TryBackToAllSnapshotsOfVmParameters;
 import org.ovirt.engine.core.common.action.VdcActionParametersBase;
 import org.ovirt.engine.core.common.action.VdcActionType;
 import org.ovirt.engine.core.common.action.VmManagementParametersBase;
@@ -57,6 +59,8 @@
 import org.ovirt.engine.core.common.businessentities.AsyncTaskStatus;
 import org.ovirt.engine.core.common.businessentities.AsyncTaskStatusEnum;
 import org.ovirt.engine.core.common.businessentities.BootSequence;
+import org.ovirt.engine.api.model.Snapshot;
+import org.ovirt.engine.core.common.businessentities.SnapshotActionEnum;
 import org.ovirt.engine.core.common.businessentities.VDS;
 import org.ovirt.engine.core.common.businessentities.VDSGroup;
 import org.ovirt.engine.core.common.businessentities.VmPayload;
@@ -649,6 +653,49 @@
     }
 
     @Test
+    public void testPreviewSnapshot() throws Exception {
+        
setUriInfo(setUpActionExpectations(VdcActionType.TryBackToAllSnapshotsOfVm,
+                                           
TryBackToAllSnapshotsOfVmParameters.class,
+                                           new String[] { "VmId", 
"DstSnapshotId" },
+                                           new Object[] { GUIDS[0], GUIDS[1] 
}));
+        Action action = new Action();
+        Snapshot snapshot = new Snapshot();
+        snapshot.setId(GUIDS[1].toString());
+        action.setSnapshot(snapshot);
+        Response response = resource.previewSnapshot(action);
+        verifyActionResponse(response);
+        Action actionResponse = (Action)response.getEntity();
+        assertTrue(actionResponse.isSetStatus());
+        assertEquals(CreationStatus.COMPLETE.value(), 
actionResponse.getStatus().getState());
+    }
+
+    @Test
+    public void testUndoSnapshot() throws Exception {
+        setUriInfo(setUpActionExpectations(VdcActionType.RestoreAllSnapshots,
+                                           RestoreAllSnapshotsParameters.class,
+                                           new String[] { "VmId", 
"SnapshotAction" },
+                                           new Object[] { GUIDS[0], 
SnapshotActionEnum.UNDO }));
+        Response response = resource.undoSnapshot(new Action());
+        verifyActionResponse(response);
+        Action action = (Action)response.getEntity();
+        assertTrue(action.isSetStatus());
+        assertEquals(CreationStatus.COMPLETE.value(), 
action.getStatus().getState());
+    }
+
+    @Test
+    public void testCommitSnapshot() throws Exception {
+        setUriInfo(setUpActionExpectations(VdcActionType.RestoreAllSnapshots,
+                                           RestoreAllSnapshotsParameters.class,
+                                           new String[] { "VmId", 
"SnapshotAction" },
+                                           new Object[] { GUIDS[0], 
SnapshotActionEnum.COMMIT }));
+        Response response = resource.commitSnapshot(new Action());
+        verifyActionResponse(response);
+        Action action = (Action)response.getEntity();
+        assertTrue(action.isSetStatus());
+        assertEquals(CreationStatus.COMPLETE.value(), 
action.getStatus().getState());
+    }
+
+    @Test
     public void testMigrateWithHostName() throws Exception {
         setUpGetHostIdExpectations(1);
 


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

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

Reply via email to