Juan Hernandez has uploaded a new change for review. Change subject: restapi: Move Host Nic remove from collection to entity ......................................................................
restapi: Move Host Nic 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: I2e1459061a029c5eeb8eb7417956b9561f965de9 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/HostNicResource.java M backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostNicsResource.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicResource.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResource.java M backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicResourceTest.java M backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResourceTest.java 6 files changed, 96 insertions(+), 90 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/75/42075/1 diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostNicResource.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostNicResource.java index 1e63bdf..0755902 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostNicResource.java +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostNicResource.java @@ -17,6 +17,7 @@ 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; @@ -30,25 +31,27 @@ @Produces({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML}) public interface HostNicResource extends UpdatableResource<HostNIC>, MeasurableResource { - @GET - public HostNIC get(); + HostNIC get(); + + @DELETE + Response remove(); @Path("{action: (attach|detach)}/{oid}") - public ActionResource getActionSubresource(@PathParam("action") String action, @PathParam("oid") String oid); + ActionResource getActionSubresource(@PathParam("action") String action, @PathParam("oid") String oid); @POST @Consumes({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML}) @Actionable @Path("attach") - public Response attach(Action action); + Response attach(Action action); @POST @Consumes({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML}) @Actionable @Path("detach") - public Response detach(Action action); + Response detach(Action action); @Path("labels") - public LabelsResource getLabelsResource(); + LabelsResource getLabelsResource(); } diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostNicsResource.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostNicsResource.java index 1a4087f..da1a844 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostNicsResource.java +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostNicsResource.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.Path; import javax.ws.rs.PathParam; @@ -32,20 +31,15 @@ @Produces({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML}) public interface HostNicsResource { - @Path("{action: (setupnetworks)}") - public ActionResource getActionSubresource(@PathParam("action") String action); + ActionResource getActionSubresource(@PathParam("action") String action); @GET - public HostNics list(); + HostNics list(); @POST @Consumes({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML}) - public Response add(HostNIC nic); - - @DELETE - @Path("{id}") - public Response remove(@PathParam("id") String id); + Response add(HostNIC nic); /** * Sub-resource locator method, returns individual HostNicResource on which the @@ -55,12 +49,11 @@ * @return matching subresource if found */ @Path("{id}") - public HostNicResource getHostNicSubResource(@PathParam("id") String id); + HostNicResource getHostNicSubResource(@PathParam("id") String id); @POST @Consumes({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML}) @Actionable @Path("setupnetworks") - public Response setupNetworks(Action action); - + Response setupNetworks(Action action); } diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicResource.java index 8c6e2d4..61f4786 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicResource.java @@ -17,6 +17,7 @@ import org.ovirt.engine.api.resource.LabelsResource; import org.ovirt.engine.api.resource.StatisticsResource; import org.ovirt.engine.core.common.action.AttachNetworkToVdsParameters; +import org.ovirt.engine.core.common.action.RemoveBondParameters; import org.ovirt.engine.core.common.action.UpdateNetworkToVdsParameters; import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.businessentities.network.NetworkBootProtocol; @@ -203,4 +204,13 @@ public LabelsResource getLabelsResource() { return inject(new BackendHostNicLabelsResource(asGuid(id), parent.getHostId())); } + + @Override + public Response remove() { + // No need to call "get" here, as the call to "lookupInterface" already generates a 404 error if there is no + // such network interface. + Guid hostId = asGuid(parent.getHostId()); + String nicName = parent.lookupInterface(id).getName(); + return performAction(VdcActionType.RemoveBond, new RemoveBondParameters(hostId, nicName)); + } } diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResource.java index 3846a4a..7b75774 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResource.java @@ -26,7 +26,6 @@ import org.ovirt.engine.api.resource.HostNicsResource; import org.ovirt.engine.api.utils.LinkHelper; import org.ovirt.engine.core.common.action.AddBondParameters; -import org.ovirt.engine.core.common.action.RemoveBondParameters; import org.ovirt.engine.core.common.action.SetupNetworksParameters; import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.businessentities.Entities; @@ -84,13 +83,6 @@ lookupNetwork(nic.getNetwork()), lookupSlaves(nic)){{setBondingOptions(map(nic, null).getBondOptions());}}, new HostNicResolver(nic.getName())); - } - - @Override - public Response performRemove(String id) { - return performAction(VdcActionType.RemoveBond, - new RemoveBondParameters(asGuid(hostId), - lookupInterface(id).getName())); } @Override diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicResourceTest.java index 827c05b..a1314cb 100644 --- a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicResourceTest.java +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicResourceTest.java @@ -11,6 +11,7 @@ import java.math.BigDecimal; import java.util.ArrayList; +import java.util.Collections; import java.util.LinkedList; import java.util.List; @@ -25,6 +26,7 @@ import org.ovirt.engine.api.model.Statistic; import org.ovirt.engine.api.restapi.util.RxTxCalculator; import org.ovirt.engine.core.common.action.AttachNetworkToVdsParameters; +import org.ovirt.engine.core.common.action.RemoveBondParameters; import org.ovirt.engine.core.common.action.UpdateNetworkToVdsParameters; import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.businessentities.VDS; @@ -40,6 +42,7 @@ private static final int NIC_IDX = 1; private static final Guid NIC_ID = GUIDS[NIC_IDX]; + private static final String NIC_NAME = NAMES[NIC_IDX]; private static final String[] IPS = new String[]{"10.35.1.1", "10.35.1.2", "10.35.1.3", "10.35.1.4"}; private static final String[] GATEWAYS = new String[]{"10.35.1.254", "10.35.1.126", "10.35.1.254", "10.35.1.126"}; @@ -238,6 +241,73 @@ assertEquals(result.getIp().getGateway(), GATEWAYS[2]); } + @Test + public void testRemove() throws Exception { + setUpEntityQueryExpectations(); + setUriInfo( + setUpActionExpectations( + VdcActionType.RemoveBond, + RemoveBondParameters.class, + new String[] { "VdsId", "BondName" }, + new Object[] { PARENT_GUID, NIC_NAME }, + true, + true + ) + ); + verifyRemove(resource.remove()); + } + + @Test + public void testRemoveNonExistant() throws Exception{ + setUpEntityQueryExpectations( + VdcQueryType.GetVdsInterfacesByVdsId, + IdQueryParameters.class, + new String[] { "Id" }, + new Object[] { PARENT_GUID }, + Collections.emptyList() + ); + 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); + } + + private void doTestBadRemove(boolean canDo, boolean success, String detail) throws Exception { + setUpEntityQueryExpectations(); + setUriInfo( + setUpActionExpectations( + VdcActionType.RemoveBond, + RemoveBondParameters.class, + new String[] { "VdsId", "BondName" }, + new Object[] { PARENT_GUID, NIC_NAME }, + canDo, + success + ) + ); + try { + resource.remove(); + fail("expected WebApplicationException"); + } + catch (WebApplicationException wae) { + verifyFault(wae, detail); + } + } + private void setUpVlanQueryExpectations(VdsNetworkInterface hostNicModel) { List<VdsNetworkInterface> vlans = new LinkedList<VdsNetworkInterface>(); VdsNetworkInterface vlan = new VdsNetworkInterface(); diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResourceTest.java index 8b95cff..00ea785 100644 --- a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResourceTest.java +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResourceTest.java @@ -4,7 +4,6 @@ import java.util.ArrayList; import java.util.Collections; -import java.util.LinkedList; import java.util.List; import javax.ws.rs.WebApplicationException; @@ -23,7 +22,6 @@ import org.ovirt.engine.api.model.Slaves; import org.ovirt.engine.api.resource.HostNicResource; import org.ovirt.engine.core.common.action.AddBondParameters; -import org.ovirt.engine.core.common.action.RemoveBondParameters; import org.ovirt.engine.core.common.action.SetupNetworksParameters; import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.businessentities.VDS; @@ -42,8 +40,8 @@ public static final Guid NETWORK_GUID = new Guid("33333333-3333-3333-3333-333333333333"); public static final String NETWORK_NAME = "skynet"; public static final NetworkBootProtocol BOOT_PROTOCOL = NetworkBootProtocol.STATIC_IP; - private static final Guid MASTER_GUID = new Guid("99999999-9999-9999-9999-999999999999"); - private static final String MASTER_NAME = "master"; + public static final Guid MASTER_GUID = new Guid("99999999-9999-9999-9999-999999999999"); + public static final String MASTER_NAME = "master"; private static final Guid SLAVE_GUID = new Guid("66666666-6666-6666-6666-666666666666"); private static final String SLAVE_NAME = "slave"; private static final int SINGLE_NIC_IDX = GUIDS.length - 2; @@ -189,48 +187,6 @@ } @Test - public void testRemove() throws Exception { - setGetVdsQueryExpectations(1); - setGetNetworksQueryExpectations(1); - setUpEntityQueryExpectations(2); - - setUriInfo(setUpActionExpectations(VdcActionType.RemoveBond, - RemoveBondParameters.class, - new String[] { "VdsId", "BondName" }, - new Object[] { PARENT_GUID, MASTER_NAME }, - true, - true)); - verifyRemove(collection.remove(MASTER_GUID.toString())); - } - - @Test - public void testRemoveNonExistant() throws Exception{ - setUpEntityQueryExpectations(VdcQueryType.GetVdsInterfacesByVdsId, - IdQueryParameters.class, - new String[] { "Id" }, - new Object[] { PARENT_GUID }, - new LinkedList<VdsNetworkInterface>()); - 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); - } - - @Test public void testSetupNetworksNotSyncsNetwork() throws Exception { setUpNetworkQueryExpectations(1); setUpEntityQueryExpectations(1); @@ -302,24 +258,6 @@ assertEquals(list.getActions().getLinks().get(0).getRel(), SETUPNETWORKS_ACTION_REL); } - protected void doTestBadRemove(boolean canDo, boolean success, String detail) throws Exception { - setGetVdsQueryExpectations(1); - setGetNetworksQueryExpectations(1); - setUpEntityQueryExpectations(2); - - setUriInfo(setUpActionExpectations(VdcActionType.RemoveBond, - RemoveBondParameters.class, - new String[] { "VdsId", "BondName" }, - new Object[] { PARENT_GUID, MASTER_NAME }, - canDo, - success)); - try { - collection.remove(MASTER_GUID.toString()); - fail("expected WebApplicationException"); - } catch (WebApplicationException wae) { - verifyFault(wae, detail); - } - } protected void setUpEntityQueryExpectations(int times) throws Exception { setUpEntityQueryExpectations(times, null); -- To view, visit https://gerrit.ovirt.org/42075 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2e1459061a029c5eeb8eb7417956b9561f965de9 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
