Juan Hernandez has uploaded a new change for review. Change subject: restapi: Move CPU Profile remove from collection to entity ......................................................................
restapi: Move CPU Profile 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: I7e230efbc2cd878d192080c268bc6a7097a76804 Related: https://gerrit.ovirt.org/41783 Signed-off-by: Juan Hernandez <[email protected]> --- M backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/AssignedCpuProfileResource.java M backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/AssignedCpuProfilesResource.java M backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/CpuProfileResource.java M backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/CpuProfilesResource.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCpuProfileResource.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCpuProfilesResource.java M backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCpuProfilesResourceTest.java M backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendAssignedCpuProfileResourceTest.java M backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendCpuProfileResourceTest.java 9 files changed, 201 insertions(+), 104 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/02/41802/1 diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/AssignedCpuProfileResource.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/AssignedCpuProfileResource.java index ab45eb2..a16d95f 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/AssignedCpuProfileResource.java +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/AssignedCpuProfileResource.java @@ -1,13 +1,17 @@ package org.ovirt.engine.api.resource; +import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.Produces; +import javax.ws.rs.core.Response; import org.ovirt.engine.api.model.CpuProfile; @Produces({ ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML }) public interface AssignedCpuProfileResource { - @GET - public CpuProfile get(); + CpuProfile get(); + + @DELETE + Response remove(); } diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/AssignedCpuProfilesResource.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/AssignedCpuProfilesResource.java index 4d9be6a..240cd66 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/AssignedCpuProfilesResource.java +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/AssignedCpuProfilesResource.java @@ -1,7 +1,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; @@ -14,18 +13,13 @@ @Produces({ ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML }) public interface AssignedCpuProfilesResource { - @GET - public CpuProfiles list(); + CpuProfiles list(); @POST @Consumes({ ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML }) - public Response add(CpuProfile cpuProfile); - - @DELETE - @Path("{id}") - public Response remove(@PathParam("id") String id); + Response add(CpuProfile cpuProfile); @Path("{id}") - public AssignedCpuProfileResource getAssignedCpuProfileSubResource(@PathParam("id") String id); + AssignedCpuProfileResource getAssignedCpuProfileSubResource(@PathParam("id") String id); } diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/CpuProfileResource.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/CpuProfileResource.java index dc06e65..00a7da9 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/CpuProfileResource.java +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/CpuProfileResource.java @@ -1,13 +1,17 @@ package org.ovirt.engine.api.resource; +import javax.ws.rs.DELETE; import javax.ws.rs.Path; import javax.ws.rs.Produces; +import javax.ws.rs.core.Response; import org.ovirt.engine.api.model.CpuProfile; @Produces({ ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML }) public interface CpuProfileResource extends UpdatableResource<CpuProfile> { + @DELETE + Response remove(); @Path("permissions") - public AssignedPermissionsResource getPermissionsResource(); + AssignedPermissionsResource getPermissionsResource(); } diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/CpuProfilesResource.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/CpuProfilesResource.java index c231750..2ec1087 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/CpuProfilesResource.java +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/CpuProfilesResource.java @@ -1,7 +1,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; @@ -15,18 +14,13 @@ @Path("/cpuprofiles") @Produces({ ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML }) public interface CpuProfilesResource { - @GET - public CpuProfiles list(); + CpuProfiles list(); @POST @Consumes({ ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML }) - public Response add(CpuProfile cpuProfile); - - @DELETE - @Path("{id}") - public Response remove(@PathParam("id") String id); + Response add(CpuProfile cpuProfile); @Path("{id}") - public CpuProfileResource getCpuProfileSubResource(@PathParam("id") String id); + CpuProfileResource getCpuProfileSubResource(@PathParam("id") String id); } diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCpuProfileResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCpuProfileResource.java index 633d015..bd983af 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCpuProfileResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCpuProfileResource.java @@ -3,9 +3,13 @@ import org.ovirt.engine.api.model.BaseResource; import org.ovirt.engine.api.model.CpuProfile; import org.ovirt.engine.api.model.DataCenter; +import org.ovirt.engine.core.common.action.CpuProfileParameters; +import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.businessentities.qos.QosBase; import org.ovirt.engine.core.common.queries.IdQueryParameters; import org.ovirt.engine.core.common.queries.VdcQueryType; + +import javax.ws.rs.core.Response; public abstract class AbstractBackendCpuProfileResource extends AbstractBackendSubResource<CpuProfile, org.ovirt.engine.core.common.businessentities.profiles.CpuProfile> { @@ -40,4 +44,22 @@ } return super.addLinks(model, suggestedParent, subCollectionMembersToExclude); } + + private org.ovirt.engine.core.common.businessentities.profiles.CpuProfile getCpuProfile(String id) { + return getEntity( + org.ovirt.engine.core.common.businessentities.profiles.CpuProfile.class, + VdcQueryType.GetCpuProfileById, + new IdQueryParameters(asGuidOr404(id)), + "CpuProfiles" + ); + } + + public Response remove() { + get(); + org.ovirt.engine.core.common.businessentities.profiles.CpuProfile cpuProfile = getCpuProfile(id); + return performAction( + VdcActionType.RemoveCpuProfile, + new CpuProfileParameters(cpuProfile, cpuProfile.getId()) + ); + } } diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCpuProfilesResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCpuProfilesResource.java index b99f80f..f2ac47c 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCpuProfilesResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCpuProfilesResource.java @@ -79,21 +79,6 @@ protected abstract void validateParameters(CpuProfile cpuProfile); @Override - protected Response performRemove(String id) { - org.ovirt.engine.core.common.businessentities.profiles.CpuProfile cpuProfile = getCpuProfile(id); - return performAction(VdcActionType.RemoveCpuProfile, - new CpuProfileParameters(cpuProfile, - cpuProfile.getId())); - } - - protected org.ovirt.engine.core.common.businessentities.profiles.CpuProfile getCpuProfile(String id) { - return getEntity(org.ovirt.engine.core.common.businessentities.profiles.CpuProfile.class, - VdcQueryType.GetCpuProfileById, - new IdQueryParameters(asGuidOr404(id)), - "CpuProfiles"); - } - - @Override protected CpuProfile doPopulate(CpuProfile model, org.ovirt.engine.core.common.businessentities.profiles.CpuProfile entity) { return model; diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCpuProfilesResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCpuProfilesResourceTest.java index 54157a0..3daddfe 100644 --- a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCpuProfilesResourceTest.java +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCpuProfilesResourceTest.java @@ -40,74 +40,6 @@ } @Test - public void testRemoveNotFound() throws Exception { - setUpEntityQueryExpectations(1, 0, true); - control.replay(); - try { - collection.remove(GUIDS[0].toString()); - fail("expected WebApplicationException"); - } catch (WebApplicationException wae) { - verifyNotFoundException(wae); - } - } - - @Test - public void testRemove() throws Exception { - setUpEntityQueryExpectations(2, 0, false); - setUriInfo(setUpActionExpectations(VdcActionType.RemoveCpuProfile, - CpuProfileParameters.class, - new String[] {}, - new Object[] {}, - true, - true)); - verifyRemove(collection.remove(GUIDS[0].toString())); - } - - @Test - public void testRemoveNonExistant() throws Exception { - setUpEntityQueryExpectations(VdcQueryType.GetCpuProfileById, - IdQueryParameters.class, - new String[] { "Id" }, - new Object[] { NON_EXISTANT_GUID }, - null); - control.replay(); - try { - collection.remove(NON_EXISTANT_GUID.toString()); - fail("expected WebApplicationException"); - } catch (WebApplicationException wae) { - assertNotNull(wae.getResponse()); - assertEquals(404, wae.getResponse().getStatus()); - } - } - - @Test - public void testRemoveCantDo() throws Exception { - doTestBadRemove(false, true, CANT_DO); - } - - @Test - public void testRemoveFailed() throws Exception { - doTestBadRemove(true, false, FAILURE); - } - - protected void doTestBadRemove(boolean canDo, boolean success, String detail) throws Exception { - setUpEntityQueryExpectations(2, 0, false); - - setUriInfo(setUpActionExpectations(VdcActionType.RemoveCpuProfile, - CpuProfileParameters.class, - new String[] {}, - new Object[] {}, - canDo, - success)); - try { - collection.remove(GUIDS[0].toString()); - fail("expected WebApplicationException"); - } catch (WebApplicationException wae) { - verifyFault(wae, detail); - } - } - - @Test public void testAddCpuProfile() throws Exception { setUriInfo(setUpBasicUriExpectations()); setUpClusterQueryExpectations(); diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendAssignedCpuProfileResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendAssignedCpuProfileResourceTest.java index e76fbf6..edff3e8 100644 --- a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendAssignedCpuProfileResourceTest.java +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendAssignedCpuProfileResourceTest.java @@ -9,6 +9,8 @@ import org.junit.Test; import org.ovirt.engine.api.model.CpuProfile; +import org.ovirt.engine.core.common.action.CpuProfileParameters; +import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.queries.IdQueryParameters; import org.ovirt.engine.core.common.queries.VdcQueryType; @@ -53,6 +55,86 @@ verifyModel(resource.get(), 0); } + @Test + public void testRemoveNotFound() throws Exception { + setUpEntityQueryExpectations(1, 0, true); + control.replay(); + try { + resource.remove(); + fail("expected WebApplicationException"); + } + catch (WebApplicationException wae) { + verifyNotFoundException(wae); + } + } + + @Test + public void testRemove() throws Exception { + setUpEntityQueryExpectations(2, 0, false); + setUriInfo( + setUpActionExpectations( + VdcActionType.RemoveCpuProfile, + CpuProfileParameters.class, + new String[] {}, + new Object[] {}, + true, + true + ) + ); + verifyRemove(resource.remove()); + } + + @Test + public void testRemoveNonExistant() throws Exception { + setUpEntityQueryExpectations( + VdcQueryType.GetCpuProfileById, + IdQueryParameters.class, + new String[] { "Id" }, + new Object[] { GUIDS[0] }, + null + ); + control.replay(); + try { + resource.remove(); + fail("expected WebApplicationException"); + } + catch (WebApplicationException wae) { + assertNotNull(wae.getResponse()); + assertEquals(404, wae.getResponse().getStatus()); + } + } + + @Test + public void testRemoveCantDo() throws Exception { + doTestBadRemove(false, true, CANT_DO); + } + + @Test + public void testRemoveFailed() throws Exception { + doTestBadRemove(true, false, FAILURE); + } + + protected void doTestBadRemove(boolean canDo, boolean success, String detail) throws Exception { + setUpEntityQueryExpectations(2, 0, false); + setUriInfo( + setUpActionExpectations( + VdcActionType.RemoveCpuProfile, + CpuProfileParameters.class, + new String[] {}, + new Object[] {}, + canDo, + success + ) + ); + try { + resource.remove(); + fail("expected WebApplicationException"); + } + catch (WebApplicationException wae) { + verifyFault(wae, detail); + } + } + protected void setUpEntityQueryExpectations(int times, int index, boolean notFound) throws Exception { while (times-- > 0) { setUpEntityQueryExpectations(VdcQueryType.GetCpuProfileById, diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendCpuProfileResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendCpuProfileResourceTest.java index 1e445eb..2a1f46e 100644 --- a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendCpuProfileResourceTest.java +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendCpuProfileResourceTest.java @@ -123,6 +123,86 @@ } } + @Test + public void testRemoveNotFound() throws Exception { + setUpEntityQueryExpectations(1, 0, true); + control.replay(); + try { + resource.remove(); + fail("expected WebApplicationException"); + } + catch (WebApplicationException wae) { + verifyNotFoundException(wae); + } + } + + @Test + public void testRemove() throws Exception { + setUpEntityQueryExpectations(2, 0, false); + setUriInfo( + setUpActionExpectations( + VdcActionType.RemoveCpuProfile, + CpuProfileParameters.class, + new String[] {}, + new Object[] {}, + true, + true + ) + ); + verifyRemove(resource.remove()); + } + + @Test + public void testRemoveNonExistant() throws Exception { + setUpEntityQueryExpectations( + VdcQueryType.GetCpuProfileById, + IdQueryParameters.class, + new String[] { "Id" }, + new Object[] { GUIDS[0] }, + null + ); + control.replay(); + try { + resource.remove(); + fail("expected WebApplicationException"); + } + catch (WebApplicationException wae) { + assertNotNull(wae.getResponse()); + assertEquals(404, wae.getResponse().getStatus()); + } + } + + @Test + public void testRemoveCantDo() throws Exception { + doTestBadRemove(false, true, CANT_DO); + } + + @Test + public void testRemoveFailed() throws Exception { + doTestBadRemove(true, false, FAILURE); + } + + protected void doTestBadRemove(boolean canDo, boolean success, String detail) throws Exception { + setUpEntityQueryExpectations(2, 0, false); + setUriInfo( + setUpActionExpectations( + VdcActionType.RemoveCpuProfile, + CpuProfileParameters.class, + new String[] {}, + new Object[] {}, + canDo, + success + ) + ); + try { + resource.remove(); + fail("expected WebApplicationException"); + } + catch (WebApplicationException wae) { + verifyFault(wae, detail); + } + } + protected void setUpEntityQueryExpectations(int times, int index, boolean notFound) throws Exception { while (times-- > 0) { setUpEntityQueryExpectations(VdcQueryType.GetCpuProfileById, -- To view, visit https://gerrit.ovirt.org/41802 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7e230efbc2cd878d192080c268bc6a7097a76804 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Juan Hernandez <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
