X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnorthbound%2Fnetworkconfiguration%2Fneutron%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetworkconfig%2Fneutron%2Fnorthbound%2FNeutronPortsNorthbound.java;h=5451fbf3e129e4be88addabcc7816e308c2cb2b7;hb=0e7b83c0739ac579ca6dbf6a3f7992f70eb3000f;hp=9f24e79ea02ab3fd6fbbd722fe8c86054a3b4470;hpb=4467f6e1ac869d390b607db90cd7e540118a4c6e;p=controller.git diff --git a/opendaylight/northbound/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronPortsNorthbound.java b/opendaylight/northbound/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronPortsNorthbound.java index 9f24e79ea0..5451fbf3e1 100644 --- a/opendaylight/northbound/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronPortsNorthbound.java +++ b/opendaylight/northbound/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronPortsNorthbound.java @@ -15,6 +15,7 @@ import java.util.List; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.PUT; @@ -22,8 +23,10 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; import org.codehaus.enunciate.jaxrs.ResponseCode; import org.codehaus.enunciate.jaxrs.StatusCodes; @@ -69,6 +72,9 @@ public class NeutronPortsNorthbound { return o.extractFields(fields); } + @Context + UriInfo uriInfo; + /** * Returns a list of all Ports */ @@ -92,10 +98,10 @@ public class NeutronPortsNorthbound { @QueryParam("device_id") String queryDeviceID, @QueryParam("device_owner") String queryDeviceOwner, @QueryParam("tenant_id") String queryTenantID, - // pagination - @QueryParam("limit") String limit, + // linkTitle + @QueryParam("limit") Integer limit, @QueryParam("marker") String marker, - @QueryParam("page_reverse") String pageReverse + @DefaultValue("false") @QueryParam("page_reverse") Boolean pageReverse // sorting not supported ) { INeutronPortCRUD portInterface = NeutronCRUDInterfaces.getINeutronPortCRUD(this); @@ -124,7 +130,14 @@ public class NeutronPortsNorthbound { } } } - //TODO: apply pagination to results + + if (limit != null && ans.size() > 1) { + // Return a paginated request + NeutronPortRequest request = (NeutronPortRequest) PaginatedRequestFactory.createRequest(limit, + marker, pageReverse, uriInfo, ans, NeutronPort.class); + return Response.status(200).entity(request).build(); + } + return Response.status(200).entity( new NeutronPortRequest(ans)).build(); } @@ -218,16 +231,6 @@ public class NeutronPortsNorthbound { if (portInterface.macInUse(singleton.getMacAddress())) { throw new ResourceConflictException("MAC Address is in use."); } - Object[] instances = ServiceHelper.getGlobalInstances(INeutronPortAware.class, this, null); - if (instances != null) { - for (Object instance : instances) { - INeutronPortAware service = (INeutronPortAware) instance; - int status = service.canCreatePort(singleton); - if (status < 200 || status > 299) { - return Response.status(status).build(); - } - } - } /* * if fixed IPs are specified, each one has to have an existing subnet ID * that is in the same scoping network as the port. In addition, if an IP @@ -260,6 +263,18 @@ public class NeutronPortsNorthbound { } } + Object[] instances = ServiceHelper.getGlobalInstances(INeutronPortAware.class, this, null); + if (instances != null) { + for (Object instance : instances) { + INeutronPortAware service = (INeutronPortAware) instance; + int status = service.canCreatePort(singleton); + if (status < 200 || status > 299) { + return Response.status(status).build(); + } + } + } + + // add the port to the cache portInterface.addPort(singleton); if (instances != null) { @@ -309,15 +324,7 @@ public class NeutronPortsNorthbound { if (portInterface.macInUse(test.getMacAddress())) { throw new ResourceConflictException("MAC address in use"); } - if (instances != null) { - for (Object instance : instances) { - INeutronPortAware service = (INeutronPortAware) instance; - int status = service.canCreatePort(test); - if (status < 200 || status > 299) { - return Response.status(status).build(); - } - } - } + /* * if fixed IPs are specified, each one has to have an existing subnet ID * that is in the same scoping network as the port. In addition, if an IP @@ -351,6 +358,15 @@ public class NeutronPortsNorthbound { } } } + if (instances != null) { + for (Object instance : instances) { + INeutronPortAware service = (INeutronPortAware) instance; + int status = service.canCreatePort(test); + if (status < 200 || status > 299) { + return Response.status(status).build(); + } + } + } } //once everything has passed, then we can add to the cache