Merge "Re-added config.version to config-module-archetype."
[controller.git] / opendaylight / northbound / statistics / src / main / java / org / opendaylight / controller / statistics / northbound / StatisticsNorthbound.java
index a47bfa70b77e9fa2d0657529df2e676f8ab98f2a..4175f1e3c49984c7d90ac03b2207df946c9f7e3a 100644 (file)
@@ -15,9 +15,11 @@ import javax.ws.rs.GET;
 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.SecurityContext;
+import javax.ws.rs.ext.ContextResolver;
 
 import org.codehaus.enunciate.jaxrs.ResponseCode;
 import org.codehaus.enunciate.jaxrs.StatusCodes;
@@ -29,6 +31,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.Node;
@@ -57,7 +60,14 @@ import org.opendaylight.controller.switchmanager.ISwitchManager;
 public class StatisticsNorthbound {
 
     private String username;
+    private QueryContext queryContext;
 
+    @Context
+    public void setQueryContext(ContextResolver<QueryContext> queryCtxResolver) {
+      if (queryCtxResolver != null) {
+        queryContext = queryCtxResolver.getContext(QueryContext.class);
+      }
+    }
     @Context
     public void setSecurityContext(SecurityContext context) {
         if (context != null && context.getUserPrincipal() != null) username = context.getUserPrincipal().getName();
@@ -114,7 +124,7 @@ public class StatisticsNorthbound {
      * Request URL:
      * http://localhost:8080/controller/nb/v2/statistics/default/flow
      *
-     * Response in JSON:
+     * Response body in JSON:
      * {
      *     "flowStatistics": [
      *         {
@@ -171,7 +181,7 @@ public class StatisticsNorthbound {
      *     ]
      * }
      *
-     * Response in XML:
+     * Response body in XML:
      * &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;
      * &lt;list&gt;
      *     &lt;flowStatistics&gt;
@@ -234,7 +244,8 @@ public class StatisticsNorthbound {
         @ResponseCode(code = 404, condition = "The containerName is not found"),
         @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
     public AllFlowStatistics getFlowStatistics(
-            @PathParam("containerName") String containerName) {
+            @PathParam("containerName") String containerName,
+            @QueryParam("_q") String queryString) {
         if (!NorthboundUtils.isAuthorized(
                 getUserName(), containerName, Privilege.READ, this)) {
             throw new UnauthorizedException(
@@ -265,7 +276,12 @@ public class StatisticsNorthbound {
             FlowStatistics stat = new FlowStatistics(node, flowStats);
             statistics.add(stat);
         }
-        return new AllFlowStatistics(statistics);
+        AllFlowStatistics result = new AllFlowStatistics(statistics);
+        if (queryString != null) {
+            queryContext.createQuery(queryString, AllFlowStatistics.class)
+                .filter(result, FlowStatistics.class);
+        }
+        return result;
     }
 
     /**
@@ -287,7 +303,7 @@ public class StatisticsNorthbound {
      * Request URL:
      * http://localhost:8080/controller/nb/v2/statistics/default/flow/node/OF/00:00:00:00:00:00:00:01
      *
-     * Response in JSON:
+     * Response body in JSON:
      * {
      *     "node": {
      *         "id":"00:00:00:00:00:00:00:01",
@@ -340,7 +356,7 @@ public class StatisticsNorthbound {
      *     ]
      * }
      *
-     * Response in XML:
+     * Response body in XML:
      * &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;
      *     &lt;nodeFlowStatistics&gt;
      *         &lt;node&gt;
@@ -474,7 +490,7 @@ public class StatisticsNorthbound {
      * Request URL:
      * http://localhost:8080/controller/nb/v2/statistics/default/port
      *
-     * Response in JSON:
+     * Response body in JSON:
      * {
      *     "portStatistics": [
      *         {
@@ -544,7 +560,7 @@ public class StatisticsNorthbound {
      *     ]
      * }
      *
-     * Response in XML:
+     * Response body in XML:
      * &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;
      * &lt;list&gt;
      *     &lt;portStatistics&gt;
@@ -610,7 +626,8 @@ public class StatisticsNorthbound {
         @ResponseCode(code = 404, condition = "The containerName is not found"),
         @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
     public AllPortStatistics getPortStatistics(
-            @PathParam("containerName") String containerName) {
+            @PathParam("containerName") String containerName,
+            @QueryParam("_q") String queryString) {
 
         if (!NorthboundUtils.isAuthorized(
                 getUserName(), containerName, Privilege.READ, this)) {
@@ -638,7 +655,13 @@ public class StatisticsNorthbound {
             PortStatistics portStat = new PortStatistics(node, stat);
             statistics.add(portStat);
         }
-        return new AllPortStatistics(statistics);
+
+        AllPortStatistics result = new AllPortStatistics(statistics);
+        if (queryString != null) {
+            queryContext.createQuery(queryString, AllPortStatistics.class)
+                .filter(result, PortStatistics.class);
+        }
+        return result;
     }
 
     /**
@@ -662,7 +685,7 @@ public class StatisticsNorthbound {
      * Request URL:
      * http://localhost:8080/controller/nb/v2/statistics/default/port/node/OF/00:00:00:00:00:00:00:01
      *
-     * Response in JSON:
+     * Response body in JSON:
      * {
      *     "node": {
      *         "id":"00:00:00:00:00:00:00:01",
@@ -716,7 +739,7 @@ public class StatisticsNorthbound {
      *     ]
      * }
      *
-     * Response in XML:
+     * Response body in XML:
      * &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;
      * &lt;nodePortStatistics&gt;
      *     &lt;node&gt;
@@ -825,7 +848,7 @@ public class StatisticsNorthbound {
      * Request URL:
      * http://localhost:8080/controller/nb/v2/statistics/default/table
      *
-     * Response in JSON:
+     * Response body in JSON:
      * {
      *     "tableStatistics": [
      *         {
@@ -844,7 +867,8 @@ public class StatisticsNorthbound {
      *                     },
      *                     "activeCount": "11",
      *                     "lookupCount": "816",
-     *                     "matchedCount": "220"
+     *                     "matchedCount": "220",
+     *                     "maximumEntries": "1000"
      *                 },
      *                 {
      *                     ...another table
@@ -857,7 +881,7 @@ public class StatisticsNorthbound {
      *     ]
      * }
      *
-     *  Response in XML:
+     *  Response body in XML:
      *  &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;
      *  &lt;list&gt;
      *  &lt;tableStatistics&gt;
@@ -876,6 +900,7 @@ public class StatisticsNorthbound {
      *          &lt;activeCount&gt;12&lt;/activeCount&gt;
      *          &lt;lookupCount&gt;10935&lt;/lookupCount&gt;
      *          &lt;matchedCount&gt;10084&lt;/matchedCount&gt;
+     *          &lt;maximumEntries&gt;1000&lt;/maximumEntries&gt;
      *      &lt;/tableStatistic&gt;
      *      &lt;tableStatistic&gt;
      *          &lt;nodeTable&gt;
@@ -888,6 +913,7 @@ public class StatisticsNorthbound {
      *          &lt;activeCount&gt;0&lt;/activeCount&gt;
      *          &lt;lookupCount&gt;0&lt;/lookupCount&gt;
      *          &lt;matchedCount&gt;0&lt;/matchedCount&gt;
+     *          &lt;maximumEntries&gt;0&lt;/maximumEntries&gt;
      *      &lt;/tableStatistic&gt;
      *      &lt;tableStatistic&gt;
      *          &lt;nodeTable&gt;
@@ -900,6 +926,7 @@ public class StatisticsNorthbound {
      *          &lt;activeCount&gt;0&lt;/activeCount&gt;
      *          &lt;lookupCount&gt;0&lt;/lookupCount&gt;
      *          &lt;matchedCount&gt;0&lt;/matchedCount&gt;
+     *          &lt;maximumEntries&gt;0&lt;/maximumEntries&gt;
      *      &lt;/tableStatistic&gt;
      *  &lt;/tableStatistics&gt;
      *  &lt;tableStatistics&gt;
@@ -920,7 +947,8 @@ public class StatisticsNorthbound {
         @ResponseCode(code = 404, condition = "The containerName is not found"),
         @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
     public AllTableStatistics getTableStatistics(
-            @PathParam("containerName") String containerName) {
+            @PathParam("containerName") String containerName,
+            @QueryParam("_q") String queryString) {
 
         if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.READ, this)) {
             throw new UnauthorizedException("User is not authorized to perform this operation on container "
@@ -948,7 +976,12 @@ public class StatisticsNorthbound {
             TableStatistics tableStat = new TableStatistics(node, stat);
             statistics.add(tableStat);
         }
-        return new AllTableStatistics(statistics);
+        AllTableStatistics allstats = new AllTableStatistics(statistics);
+        if (queryString != null) {
+            queryContext.createQuery(queryString, AllTableStatistics.class)
+                .filter(allstats, TableStatistics.class);
+        }
+        return allstats;
     }
 
     /**
@@ -970,7 +1003,7 @@ public class StatisticsNorthbound {
      * Request URL:
      * http://localhost:8080/controller/nb/v2/statistics/default/table/node/OF/00:00:00:00:00:00:00:01
      *
-     * Response in JSON:
+     * Response body in JSON:
      * {
      *     "node": {
      *         "id":"00:00:00:00:00:00:00:01",
@@ -987,7 +1020,8 @@ public class StatisticsNorthbound {
      *             },
      *             "activeCount": "12",
      *             "lookupCount": "11382",
-     *             "matchedCount": "10524"
+     *             "matchedCount": "10524",
+     *             "maximumEntries": "1000"
      *         },
      *         {
      *             "nodeTable": {
@@ -999,12 +1033,13 @@ public class StatisticsNorthbound {
      *             },
      *             "activeCount": "0",
      *             "lookupCount": "0",
-     *             "matchedCount": "0"
+     *             "matchedCount": "0",
+     *             "maximumEntries": "0"
      *         }
      *    ]
      * }
      *
-     * Response in XML:
+     * Response body in XML:
      * &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;
      * &lt;nodeTableStatistics&gt;
      *     &lt;node&gt;
@@ -1022,6 +1057,7 @@ public class StatisticsNorthbound {
      *         &lt;activeCount&gt;12&lt;/activeCount&gt;
      *         &lt;lookupCount&gt;10935&lt;/lookupCount&gt;
      *         &lt;matchedCount&gt;10084&lt;/matchedCount&gt;
+     *         &lt;maximumEntries&gt;1000&lt;/maximumEntries&gt;
      *     &lt;/tableStatistic&gt;
      *     &lt;tableStatistic&gt;
      *         &lt;nodeTable&gt;
@@ -1034,6 +1070,7 @@ public class StatisticsNorthbound {
      *         &lt;activeCount&gt;0&lt;/activeCount&gt;
      *         &lt;lookupCount&gt;0&lt;/lookupCount&gt;
      *         &lt;matchedCount&gt;0&lt;/matchedCount&gt;
+     *         &lt;maximumEntries&gt;0&lt;/maximumEntries&gt;
      *     &lt;/tableStatistic&gt;
      *     &lt;tableStatistic&gt;
      *         &lt;nodeTable&gt;
@@ -1046,6 +1083,7 @@ public class StatisticsNorthbound {
      *         &lt;activeCount&gt;0&lt;/activeCount&gt;
      *         &lt;lookupCount&gt;0&lt;/lookupCount&gt;
      *         &lt;matchedCount&gt;0&lt;/matchedCount&gt;
+     *         &lt;maximumEntries&gt;0&lt;/maximumEntries&gt;
      *     &lt;/tableStatistic&gt;
      * &lt;/nodeTableStatistics&gt;
      *