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.ext.ContextResolver;
import org.codehaus.enunciate.jaxrs.ResponseCode;
import org.codehaus.enunciate.jaxrs.StatusCodes;
import org.opendaylight.controller.northbound.commons.exception.InternalServerErrorException;
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.core.Edge;
public class TopologyNorthboundJAXRS {
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) {
*
* Example:
*
- * RequestURL:
+ * Request URL:
* http://localhost:8080/controller/nb/v2/topology/default
*
- * Response in XML:
+ * Response body in XML:
* <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
* <topology>
* <edgeProperties>
* </edgeProperties>
* </topology>
*
- * Response in JSON:
- * {"edgeProperties":[{"edge":{"tailNodeConnector":{"node":{"id":"00:00:00:00:00:00:00:02","type":"OF"},
- * "id":"2","type":"OF"},"headNodeConnector":{"node":{"id":"00:00:00:00:00:00:00:51","type":"OF"},"id":
- * "2","type":"OF"}},"properties":{"timeStamp":{"value":"1377278961017","name":"creation"}}},
- * {"edge":{"tailNodeConnector":{"node":{"id":"00:00:00:00:00:00:00:51","type":"OF"},"id":
- * "2","type":"OF"}},"headNodeConnector":{"node":{"id":"00:00:00:00:00:00:00:02","type":"OF"},
- * "id":"2","type":"OF"}},"properties":{"timeStamp":{"value":"1377278961018","name":"creation"}}}]}
- *
+ * Response body in JSON:
+ * {
+ * "edgeProperties":[
+ * {
+ * "edge":{
+ * "tailNodeConnector":{
+ * "node":{
+ * "id":"00:00:00:00:00:00:00:02",
+ * "type":"OF"
+ * },
+ * "id":"2",
+ * "type":"OF"
+ * },
+ * "headNodeConnector":{
+ * "node":{
+ * "id":"00:00:00:00:00:00:00:51",
+ * "type":"OF"
+ * },
+ * "id":"2",
+ * "type":"OF"
+ * }
+ * },
+ * "properties":{
+ * "timeStamp": {
+ * "value": 1379527162648,
+ * "name": "creation",
+ * },
+ * "name": {
+ * "value": "s2-eth3"
+ * },
+ * "state": {
+ * "value": 1
+ * },
+ * "config": {
+ * "value": 1
+ * },
+ * "bandwidth": {
+ * "value": 10000000000
+ * }
+ * }
+ * },
+ * {
+ * "edge":{
+ * "tailNodeConnector":{
+ * "node":{
+ * "id":"00:00:00:00:00:00:00:51",
+ * "type":"OF"
+ * },
+ * "id":"2",
+ * "type":"OF"
+ * },
+ * "headNodeConnector":{
+ * "node":{
+ * "id":"00:00:00:00:00:00:00:02",
+ * "type":"OF"
+ * },
+ * "id":"2",
+ * "type":"OF"
+ * }
+ * },
+ * "properties":{
+ * "timeStamp": {
+ * "value": 1379527162648,
+ * "name": "creation",
+ * }
+ * }
+ * }
+ * ]
+ * }
* </pre>
*/
@Path("/{containerName}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@TypeHint(Topology.class)
@StatusCodes({ @ResponseCode(code = 404, condition = "The Container Name was not found") })
- public Topology getTopology(@PathParam("containerName") String containerName) {
+ public Topology getTopology(@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 "
}
Map<Edge, Set<Property>> topo = topologyManager.getEdges();
- if (topo != null) {
- List<EdgeProperties> res = new ArrayList<EdgeProperties>();
- for (Map.Entry<Edge, Set<Property>> entry : topo.entrySet()) {
- EdgeProperties el = new EdgeProperties(entry.getKey(), entry.getValue());
- res.add(el);
- }
- return new Topology(res);
+ if (topo == null) {
+ return null;
+ }
+ List<EdgeProperties> res = new ArrayList<EdgeProperties>();
+ for (Map.Entry<Edge, Set<Property>> entry : topo.entrySet()) {
+ EdgeProperties el = new EdgeProperties(entry.getKey(), entry.getValue());
+ res.add(el);
}
+ Topology result = new Topology(res);
- return null;
+ if (queryString != null) {
+ queryContext.createQuery(queryString, Topology.class)
+ .filter(result, EdgeProperties.class);
+ }
+ return result;
}
/**
*
* Example:
*
- * RequestURL:
+ * Request URL:
* http://localhost:8080/controller/nb/v2/topology/default/userLinks
*
- * Response in XML:
+ * Response body in XML:
* <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
- * <topologyUserLinks>
+ * <list>
* <userLinks>
* <status>Success</status>
* <name>link1</name>
* <srcNodeConnector>OF|2@OF|00:00:00:00:00:00:00:02</srcNodeConnector>
* <dstNodeConnector>OF|2@OF|00:00:00:00:00:00:00:51</dstNodeConnector>
* </userLinks>
- * </topologyUserLinks>
+ * </list>
*
- * Response in JSON:
- * {"userLinks":{"status":"Success","name":"link1","srcNodeConnector":
- * "OF|2@OF|00:00:00:00:00:00:00:02","dstNodeConnector":"OF|2@OF|00:00:00:00:00:00:00:51"}}
+ * Response body in JSON:
+ * {
+ * "userLinks": [
+ * {
+ * "status": "Success",
+ * "name": "link1",
+ * "srcNodeConnector": "OF|2@OF|00:00:00:00:00:00:00:02",
+ * "dstNodeConnector": "OF|5@OF|00:00:00:00:00:00:00:05"
+ * }
+ * ]
+ * }
*
* </pre>
*/
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@TypeHint(TopologyUserLinks.class)
@StatusCodes({ @ResponseCode(code = 404, condition = "The Container Name was not found") })
- public TopologyUserLinks getUserLinks(@PathParam("containerName") String containerName) {
+ public TopologyUserLinks getUserLinks(@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 "
}
ConcurrentMap<String, TopologyUserLinkConfig> userLinks = topologyManager.getUserLinks();
- if ((userLinks != null) && (userLinks.values() != null)) {
- List<TopologyUserLinkConfig> res = new ArrayList<TopologyUserLinkConfig>(userLinks.values());
- return new TopologyUserLinks(res);
+ if ((userLinks == null) || (userLinks.values() == null)) {
+ return null;
}
-
- return null;
+ TopologyUserLinks result = new TopologyUserLinks(
+ new ArrayList<TopologyUserLinkConfig>(userLinks.values()));
+ if (queryString != null) {
+ queryContext.createQuery(queryString, TopologyUserLinks.class)
+ .filter(result, TopologyUserLinkConfig.class);
+ }
+ return result;
}
/**
*
* Example:
*
- * RequestURL:
+ * Request URL:
* http://localhost:8080/controller/nb/v2/topology/default/userLink/link1
*
- * Request in XML:
+ * Request body in XML:
* <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
- * <topologyUserLinks>
+ * <topologyUserLinkConfig>
* <status>Success</status>
* <name>link1</name>
* <srcNodeConnector>OF|2@OF|00:00:00:00:00:00:00:02</srcNodeConnector>
* <dstNodeConnector>OF|2@OF|00:00:00:00:00:00:00:51</dstNodeConnector>
- * </topologyUserLinks>
+ * </topologyUserLinkConfig>
*
- * Request in JSON:
- * {"status":"Success","name":"link1","srcNodeConnector":"OF|2@OF|00:00:00:00:00:00:00:02","dstNodeConnector":"OF|2@OF|00:00:00:00:00:00:00:51"}
+ * Request body in JSON:
+ * {
+ * "status":"Success",
+ * "name":"link1",
+ * "srcNodeConnector":"OF|2@OF|00:00:00:00:00:00:00:02",
+ * "dstNodeConnector":"OF|2@OF|00:00:00:00:00:00:00:51"
+ * }
*
* </pre>
*/
*
* Example:
*
- * RequestURL:
+ * Request URL:
* http://localhost:8080/controller/nb/v2/topology/default/userLink/config1
*
* </pre>