Juan Hernandez has uploaded a new change for review. Change subject: restapi: Move Host remove from collection to entity ......................................................................
restapi: Move Host remove from collection to entity This patch moves the method that implements the DELETE operation from the collection interface to the entity interface. This is needed to avoid issues with newer versions of Resteasy. Change-Id: I0a2fed67c0edc8c73e96543dc1d8008523d46abe Related: https://gerrit.ovirt.org/41783 Signed-off-by: Juan Hernandez <juan.hernan...@redhat.com> --- M backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostResource.java M backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostsResource.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostResource.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostsResource.java M backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostResourceTest.java M backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostsResourceTest.java 6 files changed, 133 insertions(+), 115 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/23/41823/1 diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostResource.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostResource.java index 84aa938..987f2a8 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostResource.java +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostResource.java @@ -16,6 +16,8 @@ package org.ovirt.engine.api.resource; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; @@ -29,6 +31,12 @@ @Produces({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML}) public interface HostResource extends UpdatableResource<Host>, MeasurableResource { + @DELETE + Response remove(); + + @DELETE + @Consumes({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML}) + Response remove(Action actio); @Path("{action: (approve|install|upgrade|fence|activate|deactivate|commitnetconfig|iscsidiscover|iscsilogin|forceselectspm)}/{oid}") public ActionResource getActionSubresource(@PathParam("action")String action, @PathParam("oid")String oid); diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostsResource.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostsResource.java index 1aec7cd..b6b89199 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostsResource.java +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostsResource.java @@ -17,7 +17,6 @@ package org.ovirt.engine.api.resource; import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; @@ -25,16 +24,14 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.Response; -import org.ovirt.engine.api.model.Action; import org.ovirt.engine.api.model.Host; import org.ovirt.engine.api.model.Hosts; @Path("/hosts") @Produces({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML}) public interface HostsResource { - @GET - public Hosts list(); + Hosts list(); /** * Creates a new host and adds it to the database. The host is @@ -49,17 +46,7 @@ */ @POST @Consumes({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML}) - public Response add(Host host); - - @DELETE - @Path("{id}") - public Response remove(@PathParam("id") String id); - - @DELETE - @Consumes({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML}) - @Path("{id}") - public Response remove(@PathParam("id") String id, Action action); - + Response add(Host host); /** * Sub-resource locator method, returns individual HostResource on which the @@ -69,5 +56,5 @@ * @return matching subresource if found */ @Path("{id}") - public HostResource getHostSubResource(@PathParam("id") String id); + HostResource getHostSubResource(@PathParam("id") String id); } diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostResource.java index 3d85dd4..de29a46 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostResource.java @@ -43,6 +43,7 @@ import org.ovirt.engine.core.common.action.FenceVdsManualyParameters; import org.ovirt.engine.core.common.action.ForceSelectSPMParameters; import org.ovirt.engine.core.common.action.MaintenanceNumberOfVdssParameters; +import org.ovirt.engine.core.common.action.RemoveVdsParameters; import org.ovirt.engine.core.common.action.StorageServerConnectionParametersBase; import org.ovirt.engine.core.common.action.VdcActionParametersBase; import org.ovirt.engine.core.common.action.VdcActionType; @@ -552,6 +553,23 @@ return model; } + + @Override + public Response remove() { + get(); + return performAction(VdcActionType.RemoveVds, new RemoveVdsParameters(guid)); + } + + @Override + public Response remove(Action action) { + get(); + boolean force = false; + if (action != null && action.isSetForce()) { + force = action.isForce(); + } + return performAction(VdcActionType.RemoveVds, new RemoveVdsParameters(guid, force)); + } + public BackendHostsResource getParent() { return this.parent; } diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostsResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostsResource.java index 558a269..4c65afc 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostsResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostsResource.java @@ -7,7 +7,6 @@ import javax.ws.rs.core.Response; import org.ovirt.engine.api.common.util.DetailHelper; -import org.ovirt.engine.api.model.Action; import org.ovirt.engine.api.model.Agent; import org.ovirt.engine.api.model.Certificate; import org.ovirt.engine.api.model.Cluster; @@ -20,7 +19,6 @@ import org.ovirt.engine.api.resource.HostsResource; import org.ovirt.engine.api.restapi.types.FenceAgentMapper; import org.ovirt.engine.api.utils.LinkHelper; -import org.ovirt.engine.core.common.action.RemoveVdsParameters; import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.action.VdsOperationActionParameters; import org.ovirt.engine.core.common.action.hostdeploy.AddVdsActionParameters; @@ -114,18 +112,6 @@ return performCreate(VdcActionType.AddVds, addParams, new QueryIdResolver<Guid>(VdcQueryType.GetVdsByVdsId, IdQueryParameters.class)); - } - - @Override - public Response performRemove(String id) { - return performAction(VdcActionType.RemoveVds, new RemoveVdsParameters(asGuid(id))); - } - - @Override - public Response remove(String id, Action action) { - getEntity(id); //verifies that entity exists, returns 404 otherwise. - return performAction(VdcActionType.RemoveVds, - new RemoveVdsParameters(asGuid(id), action != null && action.isSetForce() ? action.isForce() : false)); } @Override diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostResourceTest.java index 7e1a8c4..fb604cd 100644 --- a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostResourceTest.java +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostResourceTest.java @@ -32,6 +32,7 @@ import org.ovirt.engine.core.common.action.FenceVdsManualyParameters; import org.ovirt.engine.core.common.action.ForceSelectSPMParameters; import org.ovirt.engine.core.common.action.MaintenanceNumberOfVdssParameters; +import org.ovirt.engine.core.common.action.RemoveVdsParameters; import org.ovirt.engine.core.common.action.StorageServerConnectionParametersBase; import org.ovirt.engine.core.common.action.VdcActionParametersBase; import org.ovirt.engine.core.common.action.VdcActionType; @@ -606,6 +607,109 @@ assertEquals(actionReturned.getFault().getReason(), "some_error"); } + @Test + public void testRemove() throws Exception { + setUpGetEntityExpectations(1); + setUriInfo( + setUpActionExpectations( + VdcActionType.RemoveVds, + RemoveVdsParameters.class, + new String[] { "VdsId" }, + new Object[] { GUIDS[0] }, + true, + true + ) + ); + verifyRemove(resource.remove()); + } + + @Test + public void testRemoveNonExistant() throws Exception { + setUpGetEntityExpectations( + VdcQueryType.GetVdsByVdsId, + IdQueryParameters.class, + new String[] { "Id" }, + new Object[] { GUIDS[0] }, + null + ); + setUriInfo(setUpGetMatrixConstraintsExpectations(BackendHostResource.FORCE_CONSTRAINT, false, null)); + try { + resource.remove(); + fail("expected WebApplicationException"); + } + catch (WebApplicationException wae) { + assertNotNull(wae.getResponse()); + assertEquals(404, wae.getResponse().getStatus()); + } + } + + @Test + public void testRemoveForced() throws Exception { + setUpGetEntityExpectations(1); + setUriInfo( + setUpActionExpectations( + VdcActionType.RemoveVds, + RemoveVdsParameters.class, + new String[] { "VdsId", "ForceAction" }, + new Object[] { GUIDS[0], Boolean.TRUE }, + true, + true + ) + ); + Action action = new Action(); + action.setForce(true); + verifyRemove(resource.remove(action)); + } + + @Test + public void testRemoveForcedIncomplete() throws Exception { + setUpGetEntityExpectations(1); + setUriInfo( + setUpActionExpectations( + VdcActionType.RemoveVds, + RemoveVdsParameters.class, + new String[] { "VdsId", "ForceAction" }, + new Object[] { GUIDS[0], Boolean.FALSE }, + true, + true + ) + ); + Action action = new Action(); + verifyRemove(resource.remove(action)); + } + + @Test + public void testRemoveCantDo() throws Exception { + setUpGetEntityExpectations(1); + doTestBadRemove(false, true, CANT_DO); + } + + @Test + public void testRemoveFailed() throws Exception { + setUpGetEntityExpectations(1); + doTestBadRemove(true, false, FAILURE); + } + + protected void doTestBadRemove(boolean canDo, boolean success, String detail) throws Exception { + setUriInfo( + setUpActionExpectations( + VdcActionType.RemoveVds, + RemoveVdsParameters.class, + new String[] { "VdsId" }, + new Object[] { GUIDS[0] }, + canDo, + success + ) + ); + try { + resource.remove(); + fail("expected WebApplicationException"); + } + catch (WebApplicationException wae) { + verifyFault(wae, detail); + } + } + protected VDS setUpStatisticalExpectations() throws Exception { VdsStatistics stats = control.createMock(VdsStatistics.class); VDS entity = control.createMock(VDS.class); diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostsResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostsResourceTest.java index 497c09d..8742ecb 100644 --- a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostsResourceTest.java +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostsResourceTest.java @@ -9,11 +9,9 @@ import javax.ws.rs.core.UriInfo; import org.junit.Test; -import org.ovirt.engine.api.model.Action; import org.ovirt.engine.api.model.Cluster; import org.ovirt.engine.api.model.Host; import org.ovirt.engine.api.model.HostStatus; -import org.ovirt.engine.core.common.action.RemoveVdsParameters; import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.action.hostdeploy.AddVdsActionParameters; import org.ovirt.engine.core.common.businessentities.VDS; @@ -76,61 +74,6 @@ } } - @Test - public void testRemove() throws Exception { - setUpGetEntityExpectations(); - setUriInfo(setUpActionExpectations(VdcActionType.RemoveVds, - RemoveVdsParameters.class, - new String[] { "VdsId" }, - new Object[] { GUIDS[0] }, - true, - true)); - verifyRemove(collection.remove(GUIDS[0].toString())); - } - - @Test - public void testRemoveNonExistant() throws Exception { - setUpGetEntityExpectations(VdcQueryType.GetVdsByVdsId, - IdQueryParameters.class, - new String[] { "Id" }, - new Object[] { NON_EXISTANT_GUID }, - null); - setUriInfo(setUpGetMatrixConstraintsExpectations(BackendHostResource.FORCE_CONSTRAINT, false, null)); - try { - collection.remove(NON_EXISTANT_GUID.toString()); - fail("expected WebApplicationException"); - } catch (WebApplicationException wae) { - assertNotNull(wae.getResponse()); - assertEquals(404, wae.getResponse().getStatus()); - } - } - - @Test - public void testRemoveForced() throws Exception { - setUpGetEntityExpectations(); - setUriInfo(setUpActionExpectations(VdcActionType.RemoveVds, - RemoveVdsParameters.class, - new String[] { "VdsId", "ForceAction" }, - new Object[] { GUIDS[0], Boolean.TRUE }, - true, - true)); - Action action = new Action(); - action.setForce(true); - verifyRemove(collection.remove(GUIDS[0].toString(), action)); - } - - @Test - public void testRemoveForcedIncomplete() throws Exception { - setUpGetEntityExpectations(); - setUriInfo(setUpActionExpectations(VdcActionType.RemoveVds, - RemoveVdsParameters.class, - new String[] { "VdsId", "ForceAction" }, - new Object[] { GUIDS[0], Boolean.FALSE }, - true, - true)); - verifyRemove(collection.remove(GUIDS[0].toString(), new Action(){{}})); - } - private void setUpGetEntityExpectations() throws Exception { VDS vds = new VDS(); vds.setId(GUIDS[0]); @@ -140,34 +83,6 @@ new Object[] { GUIDS[0] }, vds); } - - @Test - public void testRemoveCantDo() throws Exception { - setUpGetEntityExpectations(); - doTestBadRemove(false, true, CANT_DO); - } - - @Test - public void testRemoveFailed() throws Exception { - setUpGetEntityExpectations(); - doTestBadRemove(true, false, FAILURE); - } - - protected void doTestBadRemove(boolean canDo, boolean success, String detail) throws Exception { - setUriInfo(setUpActionExpectations(VdcActionType.RemoveVds, - RemoveVdsParameters.class, - new String[] { "VdsId" }, - new Object[] { GUIDS[0] }, - canDo, - success)); - try { - collection.remove(GUIDS[0].toString()); - fail("expected WebApplicationException"); - } catch (WebApplicationException wae) { - verifyFault(wae, detail); - } - } - @Test public void testAddHost() throws Exception { setUriInfo(setUpBasicUriExpectations()); -- To view, visit https://gerrit.ovirt.org/41823 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0a2fed67c0edc8c73e96543dc1d8008523d46abe Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Juan Hernandez <juan.hernan...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches