Daniel Erez has uploaded a new change for review. Change subject: resapi: adding support for moving a VM disk ......................................................................
resapi: adding support for moving a VM disk * Added move action to VmDiskResource interface. * Added the implementation in BackendVmDiskResource. * Added tests to BackendVmDiskResourceTest (similar to the tests of copy disk in BackendTemplateDiskResourceTest). * Updated rsdl yaml accordingly (similar to copy disk). Change-Id: I1c864a81463388f8ac82eba6f909c5a4359efab6 Bug-Url: https://bugzilla.redhat.com/883871 Signed-off-by: Daniel Erez <[email protected]> --- M backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/VmDiskResource.java M backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata_v-3.1.yaml M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmDiskResource.java M backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmDiskResourceTest.java 4 files changed, 123 insertions(+), 1 deletion(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/76/10676/1 diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/VmDiskResource.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/VmDiskResource.java index 33fc194..aac3fc0 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/VmDiskResource.java +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/VmDiskResource.java @@ -33,7 +33,7 @@ @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_X_YAML}) public interface VmDiskResource extends DiskResource, DeviceResource<Disk> { - @Path("{action: (activate|deactivate)}/{oid}") + @Path("{action: (activate|deactivate|move)}/{oid}") public ActionResource getActionSubresource(@PathParam("action") String action, @PathParam("oid") String oid); @POST @@ -50,6 +50,13 @@ @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_X_YAML}) public Response deactivate(Action action); + @POST + @Formatted + @Actionable + @Path("move") + @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_X_YAML}) + public Response move(Action action); + @PUT @Formatted @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_X_YAML }) diff --git a/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata_v-3.1.yaml b/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata_v-3.1.yaml index 8ba7b3a..8502a4a 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata_v-3.1.yaml +++ b/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata_v-3.1.yaml @@ -362,6 +362,18 @@ headers: Content-Type: {value: application/xml|json, required: true} Correlation-Id: {value: 'any string', required: false} +- name: /api/vms/{vm:id}/disks/{disk:id}/move|rel=move + request: + body: + parameterType: Action + signatures: + - mandatoryArguments: {storagedomain.host.id|name: 'xs:string'} + optionalArguments: {action.async: 'xs:boolean'} + urlparams: {} + headers: + Content-Type: {value: application/xml|json, required: true} + Correlation-Id: {value: 'any string', required: false} + Filter: {value: true|false, required: false} - name: /api/vms/{vm:id}/nics|rel=get request: body: diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmDiskResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmDiskResource.java index 8daf29c..06f40cc 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmDiskResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmDiskResource.java @@ -1,5 +1,7 @@ package org.ovirt.engine.api.restapi.resource; +import java.util.Collections; + import javax.ws.rs.core.Response; import org.ovirt.engine.api.model.Action; @@ -9,6 +11,8 @@ import org.ovirt.engine.api.resource.StatisticsResource; import org.ovirt.engine.api.resource.VmDiskResource; import org.ovirt.engine.core.common.action.HotPlugDiskToVmParameters; +import org.ovirt.engine.core.common.action.MoveDiskParameters; +import org.ovirt.engine.core.common.action.MoveDisksParameters; import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.compat.Guid; @@ -73,6 +77,17 @@ } @Override + public Response move(Action action) { + validateParameters(action, "storageDomain.id|name"); + MoveDisksParameters params = + new MoveDisksParameters(Collections.singletonList(new MoveDiskParameters( + asGuid(get().getImageId()), + Guid.Empty, + getStorageDomainId(action)))); + return doAction(VdcActionType.MoveDisks, params, action); + } + + @Override public Disk get() { return super.get();//explicit call solves REST-Easy confusion } diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmDiskResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmDiskResourceTest.java index 362af5a..7bfbc6f 100644 --- a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmDiskResourceTest.java +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmDiskResourceTest.java @@ -2,9 +2,11 @@ import java.math.BigDecimal; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; import org.junit.Test; @@ -12,12 +14,21 @@ import org.ovirt.engine.api.model.Disk; import org.ovirt.engine.api.model.Disks; import org.ovirt.engine.api.model.Statistic; +import org.ovirt.engine.api.model.StorageDomain; import org.ovirt.engine.api.resource.VmDiskResource; import org.ovirt.engine.core.common.action.HotPlugDiskToVmParameters; +import org.ovirt.engine.core.common.action.MoveDiskParameters; +import org.ovirt.engine.core.common.action.MoveDisksParameters; import org.ovirt.engine.core.common.action.UpdateVmDiskParameters; +import org.ovirt.engine.core.common.action.VdcActionParametersBase; import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.businessentities.DiskImage; import org.ovirt.engine.core.common.businessentities.Disk.DiskStorageType; +import org.ovirt.engine.core.common.businessentities.StorageDomainStatus; +import org.ovirt.engine.core.common.businessentities.StorageDomainType; +import org.ovirt.engine.core.common.businessentities.StorageType; +import org.ovirt.engine.core.common.businessentities.storage_domains; +import org.ovirt.engine.core.common.interfaces.SearchType; import org.ovirt.engine.core.common.queries.GetAllDisksByVmIdParameters; import org.ovirt.engine.core.common.queries.VdcQueryType; import org.ovirt.engine.core.compat.Guid; @@ -237,4 +248,81 @@ } } + @Test + public void testMoveBySdId() throws Exception { + setUpEntityQueryExpectations(1); + setUriInfo(setUpActionExpectations(VdcActionType.MoveDisks, + MoveDisksParameters.class, + new String[] { "ParametersList" }, + new Object[] { Collections.singletonList(new MoveDiskParameters(GUIDS[1], Guid.Empty, GUIDS[3])) })); + + verifyActionResponse(((VmDiskResource) resource).move(setUpMoveParams(false))); + } + + @Test + public void testMoveBySdName() throws Exception { + setUpEntityQueryExpectations(1); + setUpGetEntityExpectations("Storage: name=" + NAMES[2], + SearchType.StorageDomain, + getStorageDomainEntity(0)); + setUriInfo(setUpActionExpectations(VdcActionType.MoveDisks, + MoveDisksParameters.class, + new String[] { "ParametersList" }, + new Object[] { Collections.singletonList(new MoveDiskParameters(GUIDS[1], Guid.Empty, GUIDS[3])) })); + + verifyActionResponse(((VmDiskResource) resource).move(setUpMoveParams(true))); + } + + @Test + public void testIncompleteMove() throws Exception { + setUriInfo(setUpBasicUriExpectations()); + try { + control.replay(); + ((VmDiskResource) resource).move(new Action()); + fail("expected WebApplicationException on incomplete parameters"); + } catch (WebApplicationException wae) { + verifyIncompleteException(wae, "Action", "move", "storageDomain.id|name"); + } + } + + private void verifyActionResponse(Response r) throws Exception { + verifyActionResponse(r, "vms/" + PARENT_ID + "/disks/" + PARENT_ID, false); + } + + protected storage_domains getStorageDomainEntity(int index) { + storage_domains entity = control.createMock(storage_domains.class); + return setUpStorageDomainEntityExpectations(entity, index, StorageType.NFS); + } + + static storage_domains setUpStorageDomainEntityExpectations(storage_domains entity, + int index, + StorageType storageType) { + expect(entity.getId()).andReturn(GUIDS[3]).anyTimes(); + expect(entity.getstorage_name()).andReturn(NAMES[2]).anyTimes(); + expect(entity.getstatus()).andReturn(StorageDomainStatus.Active).anyTimes(); + expect(entity.getstorage_domain_type()).andReturn(StorageDomainType.Master).anyTimes(); + expect(entity.getstorage_type()).andReturn(storageType).anyTimes(); + expect(entity.getstorage()).andReturn(GUIDS[0].toString()).anyTimes(); + return entity; + } + + private Action setUpMoveParams(boolean byName) { + Action action = new Action(); + StorageDomain sd = new StorageDomain(); + if (byName) { + sd.setName(NAMES[2]); + } else { + sd.setId(GUIDS[3].toString()); + } + action.setStorageDomain(sd); + return action; + } + + protected UriInfo setUpActionExpectations(VdcActionType task, + Class<? extends VdcActionParametersBase> clz, + String[] names, + Object[] values) { + return setUpActionExpectations(task, clz, names, values, true, true, null, null, true); + } + } -- To view, visit http://gerrit.ovirt.org/10676 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1c864a81463388f8ac82eba6f909c5a4359efab6 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Daniel Erez <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
