X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnorthbound%2Fcontainermanager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcontainermanager%2Fnorthbound%2FContainerManagerNorthbound.java;h=754167814d763555ede965c5de8c6ee867f5c9f5;hb=refs%2Fchanges%2F10%2F7610%2F5;hp=e5d2b48d99b98f2b2d9b9a9d8c145c5b485309c1;hpb=8b921f98d7a20185646cb33be6d1fdb0e0874ba3;p=controller.git diff --git a/opendaylight/northbound/containermanager/src/main/java/org/opendaylight/controller/containermanager/northbound/ContainerManagerNorthbound.java b/opendaylight/northbound/containermanager/src/main/java/org/opendaylight/controller/containermanager/northbound/ContainerManagerNorthbound.java index e5d2b48d99..754167814d 100644 --- a/opendaylight/northbound/containermanager/src/main/java/org/opendaylight/controller/containermanager/northbound/ContainerManagerNorthbound.java +++ b/opendaylight/northbound/containermanager/src/main/java/org/opendaylight/controller/containermanager/northbound/ContainerManagerNorthbound.java @@ -9,7 +9,6 @@ package org.opendaylight.controller.containermanager.northbound; -import java.security.Principal; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -18,22 +17,25 @@ import java.util.Set; 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.ws.rs.core.UriInfo; -import javax.xml.bind.JAXBElement; +import javax.ws.rs.ext.ContextResolver; import org.codehaus.enunciate.jaxrs.ResponseCode; import org.codehaus.enunciate.jaxrs.StatusCodes; import org.codehaus.enunciate.jaxrs.TypeHint; +import org.opendaylight.controller.containermanager.ContainerConfig; +import org.opendaylight.controller.containermanager.ContainerFlowConfig; import org.opendaylight.controller.containermanager.IContainerAuthorization; +import org.opendaylight.controller.containermanager.IContainerManager; import org.opendaylight.controller.northbound.commons.RestMessages; import org.opendaylight.controller.northbound.commons.exception.BadRequestException; import org.opendaylight.controller.northbound.commons.exception.InternalServerErrorException; @@ -41,6 +43,7 @@ import org.opendaylight.controller.northbound.commons.exception.ResourceConflict import org.opendaylight.controller.northbound.commons.exception.ResourceForbiddenException; 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.authorization.UserLevel; @@ -49,10 +52,6 @@ import org.opendaylight.controller.sal.utils.ServiceHelper; import org.opendaylight.controller.sal.utils.Status; import org.opendaylight.controller.usermanager.IUserManager; -import org.opendaylight.controller.containermanager.ContainerFlowConfig; -import org.opendaylight.controller.containermanager.IContainerManager; -import org.opendaylight.controller.containermanager.ContainerConfig; - /** * Container Manager Northbound API * @@ -72,12 +71,20 @@ import org.opendaylight.controller.containermanager.ContainerConfig; @Path("/") public class ContainerManagerNorthbound { 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) { - Principal principal; - principal = context.getUserPrincipal(); - username = principal.getName(); + if (context != null && context.getUserPrincipal() != null) { + username = context.getUserPrincipal().getName(); + } } protected String getUserName() { @@ -117,9 +124,9 @@ public class ContainerManagerNorthbound { * Request URL: * http://localhost:8080/controller/nb/v2/containermanager/containers * - * Response Payload in XML: - * <container-config-list> - * <container-config> + * Response body in XML: + * <containerConfig-list> + * <containerConfig> * <container>black</container> * <staticVlan>10</staticVlan> * <nodeConnectors>OF|1@OF|00:00:00:00:00:00:00:01</nodeConnectors> @@ -128,8 +135,8 @@ public class ContainerManagerNorthbound { * <name>tcp</name> * <protocol>TCP</protocol> * </flowSpecs> - * </container-config> - * <container-config> + * </containerConfig> + * <containerConfig> * <container>red</container> * <staticVlan>20</staticVlan> * <nodeConnectors>OF|1@OF|00:00:00:00:00:00:00:01</nodeConnectors> @@ -138,13 +145,35 @@ public class ContainerManagerNorthbound { * <name>udp</name> * <protocol>UDP</protocol> * </flowSpecs> - * </container-config> - * </container-config-list> - * - * Response Payload in JSON: - * { "container-config" : [ { "container" : "black", "nodeConnectors" : ["OF|1@OF|00:00:00:00:00:00:00:01", "OF|23@OF|00:00:00:00:00:00:20:21"], "staticVlan" : "10", "flowSpecs : [{ "name": "udp", "protocol": "UDP" }] } ] } - * { "container-config" : [ { "container" : "red", "nodeConnectors" : ["OF|1@OF|00:00:00:00:00:00:00:01", "OF|23@OF|00:00:00:00:00:00:20:21"], "staticVlan" : "20", "flowSpecs": [{ "name": "tcp", "protocol": "TCP" }] } ] } - * + * </containerConfig> + * </containerConfig-list> + * + * Response body in JSON: + * { "containerConfig" : [ + * { "container" : "black", + * "nodeConnectors" : [ + * "OF|1@OF|00:00:00:00:00:00:00:01", "OF|23@OF|00:00:00:00:00:00:20:21" + * ], + * "staticVlan" : "10", + * "flowSpecs : [ + * { "name": "udp", + * "protocol": "UDP" } + * ] + * }, + * { "container" : "red", + * "nodeConnectors" : [ + * "OF|1@OF|00:00:00:00:00:00:00:01", + * "OF|23@OF|00:00:00:00:00:00:20:21" + * ], + * "staticVlan" : "20", + * "flowSpecs": [ + * { "name": "tcp", + * "protocol": "TCP" + * } + * ] + * } + * ] + * } * */ @Path("/containers") @@ -154,13 +183,18 @@ public class ContainerManagerNorthbound { @StatusCodes({ @ResponseCode(code = 200, condition = "Operation successful"), @ResponseCode(code = 401, condition = "User is not authorized to perform this operation"), @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") }) - public ContainerConfigs viewAllContainers() { + public ContainerConfigs viewAllContainers(@QueryParam("_q") String queryString) { handleNetworkAuthorization(getUserName()); IContainerManager containerManager = getContainerManager(); - - return new ContainerConfigs(containerManager.getContainerConfigList()); + ContainerConfigs result = new ContainerConfigs( + containerManager.getContainerConfigList()); + if (queryString != null) { + queryContext.createQuery(queryString, ContainerConfigs.class) + .filter(result, ContainerConfig.class); + } + return result; } /** @@ -177,17 +211,28 @@ public class ContainerManagerNorthbound { * Request URL: * http://localhost:8080/controller/nb/v2/containermanager/container/blue * - * Response Payload in XML: - * <container-config> + * Response body in XML: + * <containerConfig> * <container>blue</container> * <staticVlan>10</staticVlan> * <nodeConnectors>OF|1@OF|00:00:00:00:00:00:00:01</nodeConnectors> * <nodeConnectors>OF|23@OF|00:00:00:00:00:00:20:21</nodeConnectors> - * </container-config> - * - * Response Payload in JSON: - * { "container" : "blue", "nodeConnectors" : ["OF|1@OF|00:00:00:00:00:00:00:01", "OF|23@OF|00:00:00:00:00:00:20:21"], "staticVlan" : "10" } - * + * </containerConfig> + * + * Response body in JSON: + * { + * "containerConfig": [ + * { + * "container": "yellow", + * "staticVlan": "10", + * "nodeConnectors": [ + * "OF|1@OF|00:00:00:00:00:00:00:01", + * "OF|2@OF|00:00:00:00:00:00:00:02" + * ], + * "flowSpecs": [] + * } + * ] + * } * */ @Path("/container/{container}") @@ -229,15 +274,22 @@ public class ContainerManagerNorthbound { * Request URL: * http://localhost:8080/controller/nb/v2/containermanager/container/yellow * - * Request Payload in XML: - * <container-config> + * Request body in XML: + * <containerConfig> * <container>yellow</container> * <staticVlan>10</staticVlan> * <nodeConnectors></nodeConnectors> - * </container-config> - * - * Request Payload in JSON: - * { "container" : "yellow", "nodeConnectors" : ["OF|1@OF|00:00:00:00:00:00:00:01", "OF|23@OF|00:00:00:00:00:00:20:21"], "staticVlan" : "10"} + * </containerConfig> + * + * Request body in JSON: + * { + * "container" : "yellow", + * "nodeConnectors" : [ + * "OF|1@OF|00:00:00:00:00:00:00:01", + * "OF|23@OF|00:00:00:00:00:00:20:21" + * ], + * "staticVlan" : "10" + * } * * */ @@ -324,18 +376,27 @@ public class ContainerManagerNorthbound { * Request URL: * http://localhost:8080/controller/nb/v2/containermanager/container/green/flowspec/ssh * - * Response Payload in XML: - * <container-flowconfig> + * Response body in XML: + * <flow-spec-config> * <name>ssh</name> + * <dlVlan>52</dlVlan> * <nwSrc>10.0.0.101</nwSrc> * <nwDst>10.0.0.102</nwDst> * <protocol>IPv4</protocol> * <tpSrc>80</tpSrc> * <tpDst>100</tpDst> - * </container-flowconfig> - * - * Response Payload in JSON: - * { "protocol" : "IPv4", "nwDst" : "10.0.0.102", "name" : "ssh", "nwSrc" : "10.0.0.101", "tpSrc" : "80", "tpDst" : "100" } + * </flow-spec-config> + * + * Response body in JSON: + * { + * "protocol" : "IPv4", + * "dlVlan" : "52", + * "nwDst" : "10.0.0.102", + * "name" : "ssh", + * "nwSrc" : "10.0.0.101", + * "tpSrc" : "80", + * "tpDst" : "100" + * } * * */ @@ -381,29 +442,51 @@ public class ContainerManagerNorthbound { * Request URL: * http://localhost:8080/controller/nb/v2/containermanager/container/red/flowspec * - * Response Payload in XML: - * <container-flowconfigs> - * <container-flowconfig> + * Response body in XML: + * <flow-spec-configs> + * <flow-spec-config> * <name>ssh</name> + * <dlVlan>52</dlVlan> * <nwSrc>10.0.0.101</nwSrc> * <nwDst>10.0.0.102</nwDst> * <protocol>IPv4</protocol> * <tpSrc>23</tpSrc> * <tpDst>100</tpDst> - * </container-flowconfig> - * <container-flowconfig> + * </flow-spec-config> + * <flow-spec-config> * <name>http2</name> + * <dlVlan>123</dlVlan> * <nwSrc>10.0.0.201</nwSrc> * <nwDst>10.0.0.202</nwDst> * <protocol></protocol> * <tpSrc>80</tpSrc> * <tpDst>100</tpDst> - * </container-flowconfig> - * </container-flowconfigs> - * - * Response Payload in JSON: - * { "protocol" : "IPv4", "nwDst" : "10.0.0.102", "name" : "ssh" , "nwSrc" : "10.0.0.101", "tpSrc" : "23", "tpDst" : "100" } - * { "protocol" : "", "nwDst" : "10.0.0.202", "name" : "http" , "nwSrc" : "10.0.0.201", "tpSrc" : "80", "tpDst" : "100" } + * </flow-spec-config> + * </flow-spec-configs> + * + * Response body in JSON: + * { + * "flow-spec-config": [ + * { + * "name": "http", + * "dlVlan" : "52", + * "nwSrc": "10.0.0.201", + * "nwDst": "10.0.0.202", + * "protocol": "", + * "tpSrc": "80", + * "tpDst": "100" + * }, + * { + * "name": "ssh", + * "dlVlan" : "123", + * "nwSrc": "10.0.0.101", + * "nwDst": "10.0.0.102", + * "protocol": "IPv4", + * "tpSrc": "23", + * "tpDst": "100" + * } + * ] + * } * * */ @@ -414,7 +497,8 @@ public class ContainerManagerNorthbound { @StatusCodes({ @ResponseCode(code = 200, condition = "Operation successful"), @ResponseCode(code = 404, condition = "The container is not found"), @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") }) - public FlowSpecConfigs viewContainerFlowSpecs(@PathParam(value = "container") String container) { + public FlowSpecConfigs viewContainerFlowSpecs(@PathParam(value = "container") String container, + @QueryParam("_q") String queryString) { handleContainerAuthorization(container, getUserName()); handleForbiddenOnDefault(container); @@ -422,8 +506,13 @@ public class ContainerManagerNorthbound { handleContainerNotExists(container); IContainerManager containerManager = getContainerManager(); - - return new FlowSpecConfigs(containerManager.getContainerFlows(container)); + FlowSpecConfigs result = new FlowSpecConfigs( + containerManager.getContainerFlows(container)); + if (queryString != null) { + queryContext.createQuery(queryString, FlowSpecConfigs.class) + .filter(result, ContainerFlowConfig.class); + } + return result; } /** @@ -446,18 +535,27 @@ public class ContainerManagerNorthbound { * Request URL: * http://localhost:8080/controller/nb/v2/containermanager/container/purple/flowspec/http * - * Request Payload in XML: - * <container-flowconfig> + * Request body in XML: + * <flow-spec-config> * <name>http</name> + * <dlVlan>25</dlVlan> * <nwSrc>10.0.0.101</nwSrc> * <nwDst>10.0.0.102</nwDst> * <protocol></protocol> * <tpSrc>80</tpSrc> * <tpDst>100</tpDst> - * </container-flowconfig> - * - * Request Payload in JSON: - * { "protocol" : "", "nwDst" : "10.0.0.102", "name" : "http", "nwSrc" : "10.0.0.101", "tpSrc" : "80", "tpDst" : "100" } + * </flow-spec-config> + * + * Request body in JSON: + * { + * "name" : "http", + * "dlVlan" : "25", + * "nwSrc" : "10.0.0.101", + * "nwDst" : "10.0.0.102", + * "protocol" : "", + * "tpSrc" : "80", + * "tpDst" : "100" + * } * * */ @@ -554,16 +652,23 @@ public class ContainerManagerNorthbound { * Request URL: * http://localhost:8080/controller/nb/v2/containermanager/container/green/nodeconnector * - * Request Payload in XML: - * <list> + * Request body in XML: + * <nodeConnectors> * <nodeConnectors>OF|1@OF|00:00:00:00:00:00:00:01</nodeConnectors> * <nodeConnectors>OF|2@OF|00:00:00:00:00:00:00:01</nodeConnectors> * <nodeConnectors>OF|3@OF|00:00:00:00:00:00:00:22</nodeConnectors> * <nodeConnectors>OF|4@OF|00:00:00:00:00:00:00:22</nodeConnectors> - * </list> - * - * Request Payload in JSON: - * { "nodeConnectors" : ["OF|1@OF|00:00:00:00:00:00:00:01", "OF|2@OF|00:00:00:00:00:00:00:01", "OF|3@OF|00:00:00:00:00:00:00:22", "OF|4@OF|00:00:00:00:00:00:00:22" } + * </nodeConnectors> + * + * Request body in JSON: + * { + * "nodeConnectors" : [ + * "OF|1@OF|00:00:00:00:00:00:00:01", + * "OF|2@OF|00:00:00:00:00:00:00:01", + * "OF|3@OF|00:00:00:00:00:00:00:22", + * "OF|4@OF|00:00:00:00:00:00:00:22" + * ] + * } * * */ @@ -609,16 +714,23 @@ public class ContainerManagerNorthbound { * Request URL: * http://localhost:8080/controller/nb/v2/containermanager/container/red/nodeconnector * - * Request Payload in XML: - * <list> + * Request body in XML: + * <nodeConnectors> * <nodeConnectors>OF|1@OF|00:00:00:00:00:00:00:01</nodeConnectors> * <nodeConnectors>OF|2@OF|00:00:00:00:00:00:00:01</nodeConnectors> * <nodeConnectors>OF|3@OF|00:00:00:00:00:00:00:22</nodeConnectors> * <nodeConnectors>OF|4@OF|00:00:00:00:00:00:00:22</nodeConnectors> - * </list> - * - * Request Payload in JSON: - * { "nodeConnectors" : ["OF|1@OF|00:00:00:00:00:00:00:01", "OF|2@OF|00:00:00:00:00:00:00:01", "OF|3@OF|00:00:00:00:00:00:00:22", "OF|4@OF|00:00:00:00:00:00:00:22" } + * </nodeConnectors> + * + * Request body in JSON: + * { + * "nodeConnectors" : [ + * "OF|1@OF|00:00:00:00:00:00:00:01", + * "OF|2@OF|00:00:00:00:00:00:00:01", + * "OF|3@OF|00:00:00:00:00:00:00:22", + * "OF|4@OF|00:00:00:00:00:00:00:22" + * ] + * } * * */