X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnorthbound%2Fhosttracker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fhosttracker%2Fnorthbound%2FHostTrackerNorthbound.java;h=d7579c82e10bdd378dd603bfee9c4fde1d0ad414;hp=836bfa2d60fdd59b62e14d8d8a2c2d9fd247e898;hb=80aa861b74f7b0b3574f0962cdb45740ff71946c;hpb=171c283d513bc07c4422a37120b203b4bcc53e43 diff --git a/opendaylight/northbound/hosttracker/src/main/java/org/opendaylight/controller/hosttracker/northbound/HostTrackerNorthbound.java b/opendaylight/northbound/hosttracker/src/main/java/org/opendaylight/controller/hosttracker/northbound/HostTrackerNorthbound.java index 836bfa2d60..d7579c82e1 100644 --- a/opendaylight/northbound/hosttracker/src/main/java/org/opendaylight/controller/hosttracker/northbound/HostTrackerNorthbound.java +++ b/opendaylight/northbound/hosttracker/src/main/java/org/opendaylight/controller/hosttracker/northbound/HostTrackerNorthbound.java @@ -21,12 +21,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.xml.bind.JAXBElement; +import javax.ws.rs.ext.ContextResolver; import org.codehaus.enunciate.jaxrs.ResponseCode; import org.codehaus.enunciate.jaxrs.StatusCodes; @@ -40,6 +41,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; @@ -70,6 +72,14 @@ import org.opendaylight.controller.switchmanager.ISwitchManager; public class HostTrackerNorthbound { 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) { @@ -108,7 +118,7 @@ public class HostTrackerNorthbound { return hostTracker; } - private Hosts convertHosts(Set hostNodeConnectors) { + private Set convertHosts(Set hostNodeConnectors) { if(hostNodeConnectors == null) { return null; } @@ -116,7 +126,7 @@ public class HostTrackerNorthbound { for(HostNodeConnector hnc : hostNodeConnectors) { hosts.add(HostConfig.convert(hnc)); } - return new Hosts(hosts); + return hosts; } /** @@ -131,11 +141,10 @@ public class HostTrackerNorthbound { * * Example: * - * RequestURL: - * + * Request URL: * http://localhost:8080/controller/nb/v2/hosttracker/default/hosts/active * - * Response in XML + * Response body in XML * * <list> * <hostConfig> @@ -160,7 +169,7 @@ public class HostTrackerNorthbound { * </hostConfig> * </list> * - * Response in JSON: + * Response body in JSON: * * { * "hostConfig":[ @@ -196,14 +205,20 @@ public class HostTrackerNorthbound { @ResponseCode(code = 200, condition = "Operation successful"), @ResponseCode(code = 404, condition = "The containerName is not found"), @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") }) - public Hosts getActiveHosts(@PathParam("containerName") String containerName) { + public Hosts getActiveHosts(@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 " + containerName); } IfIptoHost hostTracker = getIfIpToHostService(containerName); - return convertHosts(hostTracker.getAllHosts()); + Hosts hosts = new Hosts(convertHosts(hostTracker.getAllHosts())); + if (queryString != null) { + queryContext.createQuery(queryString, Hosts.class) + .filter(hosts, HostConfig.class); + } + return hosts; } /** @@ -218,11 +233,10 @@ public class HostTrackerNorthbound { * * Example: * - * RequestURL: - * + * Request URL: * http://localhost:8080/controller/nb/v2/hosttracker/default/hosts/inactive * - * Response in XML + * Response body in XML * * <list> * <hostConfig> @@ -247,7 +261,7 @@ public class HostTrackerNorthbound { * </hostConfig> * </list> * - * Response in JSON: + * Response body in JSON: * * { * "hostConfig":[ @@ -284,13 +298,19 @@ public class HostTrackerNorthbound { @ResponseCode(code = 404, condition = "The containerName is not found"), @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") }) public Hosts getInactiveHosts( - @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 " + containerName); } IfIptoHost hostTracker = getIfIpToHostService(containerName); - return convertHosts(hostTracker.getInactiveStaticHosts()); + Hosts hosts = new Hosts(convertHosts(hostTracker.getInactiveStaticHosts())); + if (queryString != null) { + queryContext.createQuery(queryString, Hosts.class) + .filter(hosts, HostConfig.class); + } + return hosts; } /** @@ -306,11 +326,10 @@ public class HostTrackerNorthbound { * * Example: * - * RequestURL: - * + * Request URL: * http://localhost:8080/controller/nb/v2/hosttracker/default/address/1.1.1.1 * - * Response in XML + * Response body in XML * * <hostConfig> * <dataLayerAddress>00:00:00:00:01:01</dataLayerAddress> @@ -323,7 +342,7 @@ public class HostTrackerNorthbound { * <staticHost>false</staticHost> * </hostConfig> * - * Response in JSON: + * Response body in JSON: * * { * "dataLayerAddress":"00:00:00:00:01:01", @@ -386,11 +405,10 @@ public class HostTrackerNorthbound { * * Example: * - * RequestURL: - * + * Request URL: * http://localhost:8080/controller/nb/v2/hosttracker/default/address/1.1.1.1 * - * Request in XML + * Request body in XML * * <hostConfig> * <dataLayerAddress>00:00:00:00:01:01</dataLayerAddress> @@ -399,11 +417,11 @@ public class HostTrackerNorthbound { * <nodeId>00:00:00:00:00:00:00:01</nodeId> * <nodeConnectorType>OF</nodeConnectorType> * <nodeConnectorId>9</nodeConnectorId> - * <vlan>0</vlan> - * <staticHost>false</staticHost> + * <vlan>1</vlan> + * <staticHost>true</staticHost> * </hostConfig> * - * Request in JSON: + * Request body in JSON: * * { * "dataLayerAddress":"00:00:00:00:01:01", @@ -411,8 +429,8 @@ public class HostTrackerNorthbound { * "nodeId":"00:00:00:00:00:00:00:01", * "nodeConnectorType":"OF", * "nodeConnectorId":"9", - * "vlan":"0", - * "staticHost":"false", + * "vlan":"1", + * "staticHost":"true", * "networkAddress":"1.1.1.1" * } * @@ -472,6 +490,12 @@ public class HostTrackerNorthbound { * @param networkAddress * IP Address * @return Response as dictated by the HTTP Response code. + * + * Example: + * + * Request URL: + * http://localhost:8080/controller/nb/v2/hosttracker/default/address/1.1.1.1 + * */ @Path("/{containerName}/address/{networkAddress}")