X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnorthbound%2Fstaticrouting%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fforwarding%2Fstaticrouting%2Fnorthbound%2FStaticRoutingNorthbound.java;h=20f6cb40a56cb812fa5370a5dd01cc6bf2ef85e8;hb=refs%2Fchanges%2F10%2F7610%2F5;hp=3deb8dfa7b59766fab862b6151e3b2f00e4fc6d3;hpb=b497dc0e387e4aa025e9cbe19d94b1406cc56fc2;p=controller.git diff --git a/opendaylight/northbound/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/northbound/StaticRoutingNorthbound.java b/opendaylight/northbound/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/northbound/StaticRoutingNorthbound.java index 3deb8dfa7b..20f6cb40a5 100644 --- a/opendaylight/northbound/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/northbound/StaticRoutingNorthbound.java +++ b/opendaylight/northbound/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/northbound/StaticRoutingNorthbound.java @@ -15,15 +15,17 @@ import java.util.List; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; -import javax.ws.rs.POST; +import javax.ws.rs.PUT; 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.SecurityContext; -import javax.xml.bind.JAXBElement; +import javax.ws.rs.core.UriInfo; +import javax.ws.rs.ext.ContextResolver; import org.codehaus.enunciate.jaxrs.ResponseCode; import org.codehaus.enunciate.jaxrs.StatusCodes; @@ -37,6 +39,7 @@ import org.opendaylight.controller.northbound.commons.exception.NotAcceptableExc import org.opendaylight.controller.northbound.commons.exception.ResourceConflictException; import org.opendaylight.controller.northbound.commons.exception.ResourceNotFoundException; import org.opendaylight.controller.northbound.commons.exception.UnauthorizedException; +import org.opendaylight.controller.northbound.commons.query.QueryContext; import org.opendaylight.controller.northbound.commons.utils.NorthboundUtils; import org.opendaylight.controller.sal.authorization.Privilege; import org.opendaylight.controller.sal.utils.GlobalConstants; @@ -44,25 +47,48 @@ import org.opendaylight.controller.sal.utils.ServiceHelper; import org.opendaylight.controller.sal.utils.Status; /** - * Static Routing Northbound APIs + *
Static Routing Northbound API allows for the management of the static + * routes.
+ * + * An example request/response for retrieving the static routes may look like this: + *+ * GET http://localhost:8080/controller/nb/v2/staticroute/default HTTP/1.1 + * Accept: application/json + * + * HTTP/1.1 200 OK + * Content-Type: application/json + * + * { "staticRoute":[ + * "name":"route-1", + * "prefix":"10.10.1.0/24", + * "nextHop":"1.1.1.1" + * ] + * } + * + ** *
+ * Example: + * + * Request URL: + * http://localhost:8080/controller/nb/v2/staticroute/default/routes + * + * Response body in XML: + * <list> + * <staticRoute> + * <name>route-1</name> + * <prefix>10.10.1.0/24</prefix> + * <nextHop>1.1.1.1</nextHop> + * </staticRoute> + * </list> + * + * Response body in JSON: + * { + * "staticRoute": [ + * { + * "name": "route-1", + * "prefix": "10.10.1.0/24", + * "nextHop": "1.1.1.1" + * } + * ] + * } + **/ - @Path("/{containerName}") + @Path("/{containerName}/routes") @GET @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @TypeHint(StaticRoutes.class) @@ -106,7 +159,8 @@ public class StaticRoutingNorthbound { @ResponseCode(code = 200, condition = "Operation successful"), @ResponseCode(code = 404, condition = "The containerName passed was not found") }) public StaticRoutes getStaticRoutes( - @PathParam("containerName") String containerName) { + @PathParam("containerName") String containerName, + @QueryParam("_q") String queryString) { if(!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.WRITE, this)){ @@ -114,17 +168,45 @@ public class StaticRoutingNorthbound { UnauthorizedException("User is not authorized to perform this operation on container " + containerName); } - return new StaticRoutes(getStaticRoutesInternal(containerName)); + StaticRoutes result = new StaticRoutes(getStaticRoutesInternal(containerName)); + if (queryString != null) { + queryContext.createQuery(queryString, StaticRoutes.class) + .filter(result, StaticRoute.class); + } + return result; } /** * Returns the static route for the provided configuration name on a given container * * @param containerName Name of the Container. The Container name for the base controller is "default". - * @param name Name of the Static Route configuration + * @param route Name of the Static Route configuration * @return Static route configured with the supplied Name. + * + *
+ * Example: + * + * Request URL: + * http://localhost:8080/controller/nb/v2/staticroute/default/route/route-1 + * + * Response body in XML: + * + * <staticRoute> + * <name>route-1</name> + * <prefix>10.10.1.0/24</prefix> + * <nextHop>1.1.1.1</nextHop> + * </staticRoute> + * + * Response body in JSON: + * { + * "name":"route-1", + * "prefix":"10.10.1.0/24", + * "nextHop":"1.1.1.1" + * } + * + **/ - @Path("/{containerName}/{name}") + @Path("/{containerName}/route/{route}") @GET @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @TypeHint(StaticRoute.class) @@ -133,7 +215,7 @@ public class StaticRoutingNorthbound { @ResponseCode(code = 404, condition = "The Container Name or Static Route Configuration name passed was not found") }) public StaticRoute getStaticRoute( @PathParam("containerName") String containerName, - @PathParam("name") String name) { + @PathParam("route") String route) { if(!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.WRITE, this)){ @@ -142,9 +224,9 @@ public class StaticRoutingNorthbound { + containerName); } List
+ * Example: + * + * Request URL: + * http://localhost:8080/controller/nb/v2/staticroute/default/route/route-1 + * + * Request body in XML: + * <staticRoute> + * <name>route-1</name> + * <prefix>10.10.1.0/24</prefix> + * <nextHop>1.1.1.1</nextHop> + * </staticRoute> + * Request body in JSON: + * { + * "name":"route-1", + * "prefix":"10.10.1.0/24", + * "nextHop":"1.1.1.1" + * } + **/ - @Path("/{containerName}/{name}") - @POST + @Path("/{containerName}/route/{route}") + @PUT @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @StatusCodes( { @ResponseCode(code = 201, condition = "Created Static Route successfully"), @@ -169,9 +272,10 @@ public class StaticRoutingNorthbound { @ResponseCode(code = 406, condition = "Cannot operate on Default Container when other Containers are active"), @ResponseCode(code = 409, condition = "Failed to create Static Route entry due to Conflicting Name or Prefix."), }) public Response addStaticRoute( + @Context UriInfo uriInfo, @PathParam(value = "containerName") String containerName, - @PathParam(value = "name") String name, - @TypeHint(StaticRoute.class) JAXBElement
+ * Example: + * + * Request URL: + * DELETE http://localhost:8080/controller/nb/v2/staticroute/default/route/route-1 + * + **/ - - @Path("/{containerName}/{name}") + @Path("/{containerName}/route/{route}") @DELETE @StatusCodes( { - @ResponseCode(code = 200, condition = "Operation successful"), + @ResponseCode(code = 204, condition = "Static route removed successfully"), @ResponseCode(code = 404, condition = "Container Name or Configuration Name not found"), @ResponseCode(code = 406, condition = "Cannot operate on Default Container when other Containers are active") }) public Response removeStaticRoute( @PathParam(value = "containerName") String containerName, - @PathParam(value = "name") String name) { + @PathParam(value = "route") String route) { if(!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.WRITE, this)){ @@ -239,12 +350,12 @@ public class StaticRoutingNorthbound { .toString()); } - Status status = staticRouting.removeStaticRoute(name); + Status status = staticRouting.removeStaticRoute(route); if (status.isSuccess()) { - NorthboundUtils.auditlog("Static Route", username, "removed", name, containerName); - return Response.ok().build(); + NorthboundUtils.auditlog("Static Route", username, "removed", route, containerName); + return Response.noContent().build(); } - throw new ResourceNotFoundException(status.getDescription()); + return NorthboundUtils.getResponse(status); } private void handleDefaultDisabled(String containerName) {