X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fnorthbound%2Fsubnets%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsubnets%2Fnorthbound%2FSubnetsNorthbound.java;h=b6274795df9279275e1b1d7e145aa2fa3055914b;hb=5135f2d97f0886632f3ad3b7160a3be54909810f;hp=eb91206bfcdf9bfdf151010e51e54961a43f4f7e;hpb=c7df154d0ab6ab8222e46adefd82aea620b825aa;p=controller.git diff --git a/opendaylight/northbound/subnets/src/main/java/org/opendaylight/controller/subnets/northbound/SubnetsNorthbound.java b/opendaylight/northbound/subnets/src/main/java/org/opendaylight/controller/subnets/northbound/SubnetsNorthbound.java index eb91206bfc..b6274795df 100644 --- a/opendaylight/northbound/subnets/src/main/java/org/opendaylight/controller/subnets/northbound/SubnetsNorthbound.java +++ b/opendaylight/northbound/subnets/src/main/java/org/opendaylight/controller/subnets/northbound/SubnetsNorthbound.java @@ -19,11 +19,13 @@ 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.ws.rs.core.UriInfo; +import javax.ws.rs.ext.ContextResolver; import org.codehaus.enunciate.jaxrs.ResponseCode; import org.codehaus.enunciate.jaxrs.StatusCodes; @@ -35,6 +37,7 @@ import org.opendaylight.controller.northbound.commons.exception.ResourceConflict import org.opendaylight.controller.northbound.commons.exception.ResourceNotFoundException; import org.opendaylight.controller.northbound.commons.exception.ServiceUnavailableException; 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.core.NodeConnector; @@ -63,6 +66,14 @@ public class SubnetsNorthbound { protected static final Logger logger = LoggerFactory.getLogger(SubnetsNorthbound.class); private String username; + private QueryContext queryContext; + + @Context + public void setQueryContext(ContextResolver queryCtxResolver) { + if (queryCtxResolver != null) { + queryContext = queryCtxResolver.getContext(QueryContext.class); + } + } @Context public void setSecurityContext(SecurityContext context) { @@ -112,12 +123,14 @@ public class SubnetsNorthbound { * * @return a List of SubnetConfig * - *
+     * 
      * Example:
      *
-     * Request URL: http://localhost:8080/controller/nb/v2/subnetservice/default/subnets
+     * Request URL:
+     * http://localhost:8080/controller/nb/v2/subnetservice/default/subnets
      *
-     * Response in XML:
+     * Response body in XML:
+     * <list>
      * <subnetConfig>
      *    <name>marketingdepartment</name>
      *    <subnet>30.31.54.254/24</subnet>
@@ -125,20 +138,32 @@ public class SubnetsNorthbound {
      * <subnetConfig>
      *    <name>salesdepartment</name>
      *    <subnet>20.18.1.254/16</subnet>
-     *    <nodeConnectors>0F|11@OF|00:00:00:aa:bb:cc:dd:ee>/nodeConnectors>
-     *    <nodeConnectors>0F|13@OF|00:00:00:aa:bb:cc:dd:ee>/nodeConnectors>
+     *    <nodeConnectors>OF|11@OF|00:00:00:aa:bb:cc:dd:ee</nodeConnectors>
+     *    <nodeConnectors>OF|13@OF|00:00:00:aa:bb:cc:dd:ee</nodeConnectors>
      * </subnetConfig>
-     *
-     * Response in JSON:
+     * </list>
+     * Response body in JSON:
      * {
-     *  "name":"marketingdepartment",
-     *  "subnet":"30.31.54.254/24",
-     * }
-     * {
-     *  "name":"salesdepartment",
-     *  "subnet":"20.18.1.254/16",
-     *  "nodeConnectors":["0F|11@OF|00:00:00:aa:bb:cc:dd:ee", "0F|13@OF|00:00:00:aa:bb:cc:dd:ee"]
+     *   "subnetConfig": [
+     *     {
+     *       "name": "marketingdepartment",
+     *       "subnet": "30.31.54.254/24",
+     *       "nodeConnectors": [
+     *           "OF|04@OF|00:00:00:00:00:00:00:04",
+     *           "OF|07@OF|00:00:00:00:00:00:00:07"
+     *       ]
+     *     },
+     *     {
+     *       "name":"salesdepartment",
+     *       "subnet":"20.18.1.254/16",
+     *       "nodeConnectors": [
+     *            "OF|11@OF|00:00:00:aa:bb:cc:dd:ee",
+     *            "OF|13@OF|00:00:00:aa:bb:cc:dd:ee"
+     *        ]
+     *      }
+     *   ]
      * }
+     *
      * 
*/ @Path("/{containerName}/subnets") @@ -146,9 +171,11 @@ public class SubnetsNorthbound { @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @StatusCodes({ @ResponseCode(code = 401, condition = "User not authorized to perform this operation"), @ResponseCode(code = 404, condition = "The containerName passed was not found"), - @ResponseCode(code = 503, condition = "Service unavailable") }) + @ResponseCode(code = 503, condition = "Service unavailable"), + @ResponseCode(code = 400, condition = "Incorrect query syntex") }) @TypeHint(SubnetConfigs.class) - public SubnetConfigs listSubnets(@PathParam("containerName") String containerName) { + public SubnetConfigs listSubnets(@PathParam("containerName") String containerName, + @QueryParam("_q") String queryString) { handleContainerDoesNotExist(containerName); if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.READ, this)) { @@ -160,7 +187,13 @@ public class SubnetsNorthbound { if (switchManager == null) { throw new ServiceUnavailableException("SwitchManager " + RestMessages.SERVICEUNAVAILABLE.toString()); } - return new SubnetConfigs(switchManager.getSubnetsConfigList()); + List subnets = switchManager.getSubnetsConfigList(); + if (queryString != null) { + subnets = queryContext.createQuery(queryString, SubnetConfig.class) + .find(subnets); + + } + return new SubnetConfigs(subnets); } /** @@ -176,21 +209,25 @@ public class SubnetsNorthbound { *
      * Example:
      *
-     * Request URL: http://localhost:8080/controller/nb/v2/subnetservice/default/subnet/marketingdepartment
+     * Request URL:
+     * http://localhost:8080/controller/nb/v2/subnetservice/default/subnet/marketingdepartment
      *
-     * Response in XML:
+     * Response body in XML:
      * <subnetConfig>
      *    <name>marketingdepartment</name>
      *    <subnet>30.0.0.1/24</subnet>
-     *    <nodeConnectors>0F|1@OF|00:00:11:22:33:44:55:66>/nodePorts>
-     *    <nodeConnectors>0F|3@OF|00:00:11:22:33:44:55:66>/nodePorts>
+     *    <nodeConnectors>OF|1@OF|00:00:00:00:00:00:00:01</nodePorts>
+     *    <nodeConnectors>OF|3@OF|00:00:00:00:00:00:00:03</nodePorts>
      * </subnetConfig>
      *
-     * Response in JSON:
+     * Response body in JSON:
      * {
      *  "name":"marketingdepartment",
      *  "subnet":"30.0.0.1/24",
-     *  "nodeConnectors":["0F|1@OF|00:00:11:22:33:44:55:66", "0F|3@OF|00:00:11:22:33:44:55:66"]
+     *  "nodeConnectors":[
+     *       "OF|1@OF|00:00:00:00:00:00:00:01",
+     *       "OF|3@OF|00:00:00:00:00:00:00:03"
+     *   ]
      * }
      * 
*/ @@ -239,21 +276,25 @@ public class SubnetsNorthbound { *
      * Example:
      *
-     * Request URL: http://localhost:8080/controller/nb/v2/subnetservice/default/subnet/salesdepartment
+     * Request URL:
+     * http://localhost:8080/controller/nb/v2/subnetservice/default/subnet/salesdepartment
      *
-     * Request XML:
+     * Request body in XML:
      *  <subnetConfig>
      *      <name>salesdepartment</name>
      *      <subnet>172.173.174.254/24</subnet>
-     *      <nodeConnectors>0F|22@OF|00:00:11:22:33:44:55:66>/nodeConnectors>
-     *      <nodeConnectors>0F|39@OF|00:00:ab:cd:33:44:55:66>/nodeConnectors>
+     *      <nodeConnectors>OF|22@OF|00:00:11:22:33:44:55:66</nodeConnectors>
+     *      <nodeConnectors>OF|39@OF|00:00:ab:cd:33:44:55:66</nodeConnectors>
      *  </subnetConfig>
      *
-     * Request in JSON:
+     * Request body in JSON:
      * {
      *  "name":"salesdepartment",
-     *  "subnet":"172.173.174.254/24"
-     *  "nodeConnectors":["0F|22@OF|00:00:11:22:33:44:55:66", "0F|39@OF|00:00:ab:cd:33:44:55:66"]
+     *  "subnet":"172.173.174.254/24",
+     *  "nodeConnectors":[
+     *       "OF|22@OF|00:00:11:22:33:44:55:66",
+     *       "OF|39@OF|00:00:ab:cd:33:44:55:66"
+     *       ]
      * }
      * 
*/ @@ -308,9 +349,11 @@ public class SubnetsNorthbound { * name of new subnet to be deleted * @return Response as dictated by the HTTP Response Status code * - *
+     * 
      * Example:
-     *            Request URL: http://localhost:8080/controller/nb/v2/subnetservice/default/subnet/engdepartment
+     *
+     * Request URL:
+     * http://localhost:8080/controller/nb/v2/subnetservice/default/subnet/engdepartment
      *
      * 
*/ @@ -361,21 +404,25 @@ public class SubnetsNorthbound { *
      * Example:
      *
-     * Request URL: http://localhost:8080/controller/nb/v2/subnetservice/default/subnet/salesdepartment
+     * Request URL:
+     * http://localhost:8080/controller/nb/v2/subnetservice/default/subnet/salesdepartment
      *
-     *  Request in XML:
+     *  Request body in XML:
      *  <subnetConfig>
      *      <name>salesdepartment</name>
      *      <subnet>172.173.174.254/24</subnet>
-     *      <nodeConnectors>0F|22@OF|00:00:11:22:33:44:55:66>/nodeConnectors>
-     *      <nodeConnectors>0F|39@OF|00:00:ab:cd:33:44:55:66>/nodeConnectors>
+     *      <nodeConnectors>OF|22@OF|00:00:11:22:33:44:55:66</nodeConnectors>
+     *      <nodeConnectors>OF|39@OF|00:00:ab:cd:33:44:55:66</nodeConnectors>
      *  </subnetConfig>
      *
-     * Request in JSON:
+     * Request body in JSON:
      * {
      *  "name":"salesdepartment",
-     *  "subnet":"172.173.174.254/24"
-     *  "nodeConnectors":["0F|22@OF|00:00:11:22:33:44:55:66", "0F|39@OF|00:00:ab:cd:33:44:55:66"]
+     *  "subnet":"172.173.174.254/24",
+     *  "nodeConnectors":[
+     *      "OF|22@OF|00:00:11:22:33:44:55:66",
+     *      "OF|39@OF|00:00:ab:cd:33:44:55:66"
+     *  ]
      * }
      * 
*/