HostTracker REST APIs compliance of new guidelines 09/1009/6
authorAsad Ahmed <asaahmed@cisco.com>
Tue, 27 Aug 2013 18:19:40 +0000 (11:19 -0700)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 28 Aug 2013 14:59:22 +0000 (14:59 +0000)
Change-Id: I8d33f9970bc4585120316f4cc96f8f32669df4ed
Signed-off-by: Asad Ahmed <asaahmed@cisco.com>
opendaylight/northbound/hosttracker/pom.xml
opendaylight/northbound/hosttracker/src/main/java/org/opendaylight/controller/hosttracker/northbound/HostConfig.java [new file with mode: 0644]
opendaylight/northbound/hosttracker/src/main/java/org/opendaylight/controller/hosttracker/northbound/HostTrackerNorthbound.java
opendaylight/northbound/hosttracker/src/main/java/org/opendaylight/controller/hosttracker/northbound/Hosts.java
opendaylight/northbound/hosttracker/src/test/java/org/opendaylight/controller/hosttracker/northbound/HostTrackerNorthboundTest.java
opendaylight/northbound/integrationtest/src/test/java/org/opendaylight/controller/northbound/integrationtest/NorthboundIT.java

index ae6900766ca283e660a209894811608b2353b23b..74e33863b55eb32691e11e1c0c801a0a2f4afc91 100644 (file)
@@ -51,6 +51,7 @@
               org.opendaylight.controller.northbound.commons.exception,
               org.opendaylight.controller.northbound.commons.utils,
               org.opendaylight.controller.sal.authorization,
+              org.opendaylight.controller.sal.packet.address,
               javax.ws.rs,
               javax.ws.rs.core,
               javax.xml.bind.annotation,
diff --git a/opendaylight/northbound/hosttracker/src/main/java/org/opendaylight/controller/hosttracker/northbound/HostConfig.java b/opendaylight/northbound/hosttracker/src/main/java/org/opendaylight/controller/hosttracker/northbound/HostConfig.java
new file mode 100644 (file)
index 0000000..b66da34
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.hosttracker.northbound;
+
+import java.io.Serializable;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.opendaylight.controller.hosttracker.hostAware.HostNodeConnector;
+import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.controller.sal.core.NodeConnector;
+import org.opendaylight.controller.sal.packet.address.DataLinkAddress;
+import org.opendaylight.controller.sal.packet.address.EthernetAddress;
+
+/**
+ * Configuration Java Object which represents a Host configuration information
+ * for HostTracker.
+ */
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.NONE)
+public class HostConfig implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    @XmlElement
+    public String dataLayerAddress;
+    @XmlElement
+    private String nodeType;
+    @XmlElement
+    private String nodeId;
+    @XmlElement
+    private String nodeConnectorType;
+    @XmlElement
+    private String nodeConnectorId;
+    @XmlElement
+    private String vlan;
+    @XmlElement
+    private boolean staticHost;
+    @XmlElement
+    private String networkAddress;
+
+    public HostConfig() {
+
+    }
+
+    protected String getDataLayerAddress() {
+        return this.dataLayerAddress;
+    }
+
+    protected String getNodeType() {
+        return this.nodeType;
+    }
+
+    protected String getNodeId() {
+        return this.nodeId;
+    }
+
+    protected String getNodeConnectorType() {
+        return this.nodeConnectorType;
+    }
+
+    protected String getNodeConnectorId() {
+        return this.nodeConnectorId;
+    }
+
+    protected String getVlan() {
+        return this.vlan;
+    }
+
+    protected boolean isStaticHost() {
+        return staticHost;
+    }
+
+    protected String getNetworkAddress() {
+        return networkAddress;
+    }
+
+    public static HostConfig convert(HostNodeConnector hnc) {
+        if(hnc == null) {
+            return null;
+        }
+        HostConfig hc = new HostConfig();
+        DataLinkAddress dl = hnc.getDataLayerAddress();
+        if(dl instanceof EthernetAddress) {
+            EthernetAddress et = (EthernetAddress) dl;
+            hc.dataLayerAddress = et.getMacAddress();
+        } else {
+            hc.dataLayerAddress = dl.getName();
+        }
+        NodeConnector nc = hnc.getnodeConnector();
+        if(nc != null) {
+            hc.nodeConnectorType = nc.getType();
+            hc.nodeConnectorId = nc.getNodeConnectorIDString();
+            Node n = hnc.getnodeconnectorNode();
+            if(n != null) {
+                hc.nodeType = n.getType();
+                hc.nodeId = n.getNodeIDString();
+            }
+        }
+        hc.vlan = String.valueOf(hnc.getVlan());
+        hc.staticHost = hnc.isStaticHost();
+        hc.networkAddress = hnc.getNetworkAddressAsString();
+        return hc;
+    }
+}
index 285967522caa4d99c85515f4a491eafec66f23b8..2530d78416bf691dc2ea34bded2c8014fc574905 100644 (file)
@@ -10,21 +10,22 @@ package org.opendaylight.controller.hosttracker.northbound;
 
 import java.net.InetAddress;
 import java.net.UnknownHostException;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
-import javax.ws.rs.DefaultValue;
 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.xml.bind.JAXBElement;
 
 import org.codehaus.enunciate.jaxrs.ResponseCode;
 import org.codehaus.enunciate.jaxrs.StatusCodes;
@@ -116,6 +117,17 @@ public class HostTrackerNorthbound {
         return hostTracker;
     }
 
+    private Hosts convertHosts(Set<HostNodeConnector> hostNodeConnectors) {
+        if(hostNodeConnectors == null) {
+            return null;
+        }
+        Set<HostConfig> hosts = new HashSet<HostConfig>();
+        for(HostNodeConnector hnc : hostNodeConnectors) {
+            hosts.add(HostConfig.convert(hnc));
+        }
+        return new Hosts(hosts);
+    }
+
     /**
      * Returns a list of all Hosts : both configured via PUT API and dynamically
      * learnt on the network.
@@ -124,6 +136,66 @@ public class HostTrackerNorthbound {
      *            Name of the Container. The Container name for the base
      *            controller is "default".
      * @return List of Active Hosts.
+     * <pre>
+     *
+     * Example:
+     *
+     * RequestURL:
+     *
+     * http://localhost:8080/controller/nb/v2/host/default
+     *
+     * Response in XML
+     *
+     * &lt;list&gt;
+     * &#x20;&lt;hostConfig&gt;
+     * &#x20;&#x20;&lt;dataLayerAddress&gt;00:00:00:00:01:01&lt;/dataLayerAddress&gt;
+     * &#x20;&#x20;&lt;networkAddress&gt;1.1.1.1&lt;/networkAddress&gt;
+     * &#x20;&#x20;&lt;nodeType&gt;OF&lt;/nodeType&gt;
+     * &#x20;&#x20;&lt;nodeId&gt;00:00:00:00:00:00:00:01&lt;/nodeId&gt;
+     * &#x20;&#x20;&lt;nodeConnectorType&gt;OF&lt;/nodeConnectorType&gt;
+     * &#x20;&#x20;&lt;nodeConnectorId&gt;9&lt;/nodeConnectorId&gt;
+     * &#x20;&#x20;&lt;vlan&gt;0&lt;/vlan&gt;
+     * &#x20;&#x20;&lt;staticHost&gt;false&lt;/staticHost&gt;
+     * &#x20;&lt;/hostConfig&gt;
+     * &#x20;&lt;hostConfig&gt;
+     * &#x20;&#x20;&lt;dataLayerAddress&gt;00:00:00:00:02:02&lt;/dataLayerAddress&gt;
+     * &#x20;&#x20;&lt;networkAddress&gt;2.2.2.2&lt;/networkAddress&gt;
+     * &#x20;&#x20;&lt;nodeType&gt;OF&lt;/nodeType&gt;
+     * &#x20;&#x20;&lt;nodeId&gt;00:00:00:00:00:00:00:02&lt;/nodeId&gt;
+     * &#x20;&#x20;&lt;nodeConnectorType&gt;OF&lt;/nodeConnectorType&gt;
+     * &#x20;&#x20;&lt;nodeConnectorId&gt;5&lt;/nodeConnectorId&gt;
+     * &#x20;&#x20;&lt;vlan&gt;0&lt;/vlan&gt;
+     * &#x20;&#x20;&lt;staticHost&gt;false&lt;/staticHost&gt;
+     * &#x20;&lt;/hostConfig&gt;
+     * &lt;/list&gt;
+     *
+     * Response in JSON:
+     *
+     * {
+     * &#x20;"hostConfig":[
+     * &#x20;&#x20;{
+     * &#x20;&#x20;&#x20;"dataLayerAddress":"00:00:00:00:01:01",
+     * &#x20;&#x20;&#x20;"nodeType":"OF",
+     * &#x20;&#x20;&#x20;"nodeId":"00:00:00:00:00:00:00:01",
+     * &#x20;&#x20;&#x20;"nodeConnectorType":"OF",
+     * &#x20;&#x20;&#x20;"nodeConnectorId":"9",
+     * &#x20;&#x20;&#x20;"vlan":"0",
+     * &#x20;&#x20;&#x20;"staticHost":"false",
+     * &#x20;&#x20;&#x20;"networkAddress":"1.1.1.1"
+     * &#x20;&#x20;},
+     * &#x20;&#x20;{
+     * &#x20;&#x20;&#x20;"dataLayerAddress":"00:00:00:00:02:02",
+     * &#x20;&#x20;&#x20;"nodeType":"OF",
+     * &#x20;&#x20;&#x20;"nodeId":"00:00:00:00:00:00:00:02",
+     * &#x20;&#x20;&#x20;"nodeConnectorType":"OF",
+     * &#x20;&#x20;&#x20;"nodeConnectorId":"5",
+     * &#x20;&#x20;&#x20;"vlan":"0",
+     * &#x20;&#x20;&#x20;"staticHost":"false",
+     * &#x20;&#x20;&#x20;"networkAddress":"2.2.2.2"
+     * &#x20;&#x20;}
+     * &#x20;]
+     * }
+     * </pre>
      */
     @Path("/{containerName}")
     @GET
@@ -146,8 +218,7 @@ public class HostTrackerNorthbound {
             throw new ServiceUnavailableException("Host Tracker "
                     + RestMessages.SERVICEUNAVAILABLE.toString());
         }
-
-        return new Hosts(hostTracker.getAllHosts());
+        return convertHosts(hostTracker.getAllHosts());
     }
 
     /**
@@ -158,6 +229,66 @@ public class HostTrackerNorthbound {
      *            Name of the Container. The Container name for the base
      *            controller is "default".
      * @return List of inactive Hosts.
+     * <pre>
+     *
+     * Example:
+     *
+     * RequestURL:
+     *
+     * http://localhost:8080/controller/nb/v2/host/default/inactive
+     *
+     * Response in XML
+     *
+     * &lt;list&gt;
+     * &#x20;&lt;hostConfig&gt;
+     * &#x20;&#x20;&lt;dataLayerAddress&gt;00:00:00:00:01:01&lt;/dataLayerAddress&gt;
+     * &#x20;&#x20;&lt;networkAddress&gt;1.1.1.1&lt;/networkAddress&gt;
+     * &#x20;&#x20;&lt;nodeType&gt;OF&lt;/nodeType&gt;
+     * &#x20;&#x20;&lt;nodeId&gt;00:00:00:00:00:00:00:01&lt;/nodeId&gt;
+     * &#x20;&#x20;&lt;nodeConnectorType&gt;OF&lt;/nodeConnectorType&gt;
+     * &#x20;&#x20;&lt;nodeConnectorId&gt;9&lt;/nodeConnectorId&gt;
+     * &#x20;&#x20;&lt;vlan&gt;0&lt;/vlan&gt;
+     * &#x20;&#x20;&lt;staticHost&gt;false&lt;/staticHost&gt;
+     * &#x20;&lt;/hostConfig&gt;
+     * &#x20;&lt;hostConfig&gt;
+     * &#x20;&#x20;&lt;dataLayerAddress&gt;00:00:00:00:02:02&lt;/dataLayerAddress&gt;
+     * &#x20;&#x20;&lt;networkAddress&gt;2.2.2.2&lt;/networkAddress&gt;
+     * &#x20;&#x20;&lt;nodeType&gt;OF&lt;/nodeType&gt;
+     * &#x20;&#x20;&lt;nodeId&gt;00:00:00:00:00:00:00:02&lt;/nodeId&gt;
+     * &#x20;&#x20;&lt;nodeConnectorType&gt;OF&lt;/nodeConnectorType&gt;
+     * &#x20;&#x20;&lt;nodeConnectorId&gt;5&lt;/nodeConnectorId&gt;
+     * &#x20;&#x20;&lt;vlan&gt;0&lt;/vlan&gt;
+     * &#x20;&#x20;&lt;staticHost&gt;false&lt;/staticHost&gt;
+     * &#x20;&lt;/hostConfig&gt;
+     * &lt;/list&gt;
+     *
+     * Response in JSON:
+     *
+     * {
+     * &#x20;"hostConfig":[
+     * &#x20;&#x20;{
+     * &#x20;&#x20;&#x20;"dataLayerAddress":"00:00:00:00:01:01",
+     * &#x20;&#x20;&#x20;"nodeType":"OF",
+     * &#x20;&#x20;&#x20;"nodeId":"00:00:00:00:00:00:00:01",
+     * &#x20;&#x20;&#x20;"nodeConnectorType":"OF",
+     * &#x20;&#x20;&#x20;"nodeConnectorId":"9",
+     * &#x20;&#x20;&#x20;"vlan":"0",
+     * &#x20;&#x20;&#x20;"staticHost":"false",
+     * &#x20;&#x20;&#x20;"networkAddress":"1.1.1.1"
+     * &#x20;&#x20;},
+     * &#x20;&#x20;{
+     * &#x20;&#x20;&#x20;"dataLayerAddress":"00:00:00:00:02:02",
+     * &#x20;&#x20;&#x20;"nodeType":"OF",
+     * &#x20;&#x20;&#x20;"nodeId":"00:00:00:00:00:00:00:02",
+     * &#x20;&#x20;&#x20;"nodeConnectorType":"OF",
+     * &#x20;&#x20;&#x20;"nodeConnectorId":"5",
+     * &#x20;&#x20;&#x20;"vlan":"0",
+     * &#x20;&#x20;&#x20;"staticHost":"false",
+     * &#x20;&#x20;&#x20;"networkAddress":"2.2.2.2"
+     * &#x20;&#x20;}
+     * &#x20;]
+     * }
+     * </pre>
      */
     @Path("/{containerName}/inactive")
     @GET
@@ -180,8 +311,7 @@ public class HostTrackerNorthbound {
             throw new ServiceUnavailableException("Host Tracker "
                     + RestMessages.SERVICEUNAVAILABLE.toString());
         }
-
-        return new Hosts(hostTracker.getInactiveStaticHosts());
+        return convertHosts(hostTracker.getInactiveStaticHosts());
     }
 
     /**
@@ -193,17 +323,51 @@ public class HostTrackerNorthbound {
      * @param networkAddress
      *            IP Address being looked up
      * @return host that matches the IP Address
+     * <pre>
+     *
+     * Example:
+     *
+     * RequestURL:
+     *
+     * http://localhost:8080/controller/nb/v2/host/default/1.1.1.1
+     *
+     * Response in XML
+     *
+     * &lt;hostConfig&gt;
+     * &#x20;&lt;dataLayerAddress&gt;00:00:00:00:01:01&lt;/dataLayerAddress&gt;
+     * &#x20;&lt;networkAddress&gt;1.1.1.1&lt;/networkAddress&gt;
+     * &#x20;&lt;nodeType&gt;OF&lt;/nodeType&gt;
+     * &#x20;&lt;nodeId&gt;00:00:00:00:00:00:00:01&lt;/nodeId&gt;
+     * &#x20;&lt;nodeConnectorType&gt;OF&lt;/nodeConnectorType&gt;
+     * &#x20;&lt;nodeConnectorId&gt;9&lt;/nodeConnectorId&gt;
+     * &#x20;&lt;vlan&gt;0&lt;/vlan&gt;
+     * &#x20;&lt;staticHost&gt;false&lt;/staticHost&gt;
+     * &lt;/hostConfig&gt;
+     *
+     * Response in JSON:
+     *
+     * {
+     * &#x20;"dataLayerAddress":"00:00:00:00:01:01",
+     * &#x20;"nodeType":"OF",
+     * &#x20;"nodeId":"00:00:00:00:00:00:00:01",
+     * &#x20;"nodeConnectorType":"OF",
+     * &#x20;"nodeConnectorId":"9",
+     * &#x20;"vlan":"0",
+     * &#x20;"staticHost":"false",
+     * &#x20;"networkAddress":"1.1.1.1"
+     * }
+     * </pre>
      */
     @Path("/{containerName}/{networkAddress}")
     @GET
     @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
-    @TypeHint(HostNodeConnector.class)
+    @TypeHint(HostConfig.class)
     @StatusCodes({
             @ResponseCode(code = 200, condition = "Operation successful"),
             @ResponseCode(code = 404, condition = "The containerName is not found"),
             @ResponseCode(code = 415, condition = "Invalid IP Address passed in networkAddress parameter"),
             @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
-    public HostNodeConnector getHostDetails(
+    public HostConfig getHostDetails(
             @PathParam("containerName") String containerName,
             @PathParam("networkAddress") String networkAddress) {
         if (!NorthboundUtils.isAuthorized(
@@ -227,7 +391,7 @@ public class HostTrackerNorthbound {
         }
         for (HostNodeConnector host : hostTracker.getAllHosts()) {
             if (host.getNetworkAddress().equals(ip)) {
-                return host;
+                return HostConfig.convert(host);
             }
         }
         throw new ResourceNotFoundException(RestMessages.NOHOST.toString());
@@ -241,23 +405,48 @@ public class HostTrackerNorthbound {
      *            controller is "default".
      * @param networkAddress
      *            Host IP Address
-     * @param dataLayerAddress
-     *            Host L2 data-layer address.
-     * @param nodeType
-     *            Node Type as specifid by Node class
-     * @param nodeId
-     *            Node Identifier as specifid by Node class
-     * @param nodeConnectorType
-     *            Port Type as specified by NodeConnector class
-     * @param nodeConnectorId
-     *            Port Identifier as specified by NodeConnector class
-     * @param vlan
-     *            Vlan number
+     * @param hostConfig
+     *            Host Config Details
      * @return Response as dictated by the HTTP Response Status code
+     *
+     * <pre>
+     *
+     * Example:
+     *
+     * RequestURL:
+     *
+     * http://localhost:8080/controller/nb/v2/host/default/1.1.1.1
+     *
+     * Request in XML
+     *
+     * &lt;hostConfig&gt;
+     * &#x20;&lt;dataLayerAddress&gt;00:00:00:00:01:01&lt;/dataLayerAddress&gt;
+     * &#x20;&lt;networkAddress&gt;1.1.1.1&lt;/networkAddress&gt;
+     * &#x20;&lt;nodeType&gt;OF&lt;/nodeType&gt;
+     * &#x20;&lt;nodeId&gt;00:00:00:00:00:00:00:01&lt;/nodeId&gt;
+     * &#x20;&lt;nodeConnectorType&gt;OF&lt;/nodeConnectorType&gt;
+     * &#x20;&lt;nodeConnectorId&gt;9&lt;/nodeConnectorId&gt;
+     * &#x20;&lt;vlan&gt;0&lt;/vlan&gt;
+     * &#x20;&lt;staticHost&gt;false&lt;/staticHost&gt;
+     * &lt;/hostConfig&gt;
+     *
+     * Request in JSON:
+     *
+     * {
+     * &#x20;"dataLayerAddress":"00:00:00:00:01:01",
+     * &#x20;"nodeType":"OF",
+     * &#x20;"nodeId":"00:00:00:00:00:00:00:01",
+     * &#x20;"nodeConnectorType":"OF",
+     * &#x20;"nodeConnectorId":"9",
+     * &#x20;"vlan":"0",
+     * &#x20;"staticHost":"false",
+     * &#x20;"networkAddress":"1.1.1.1"
+     * }
+     * </pre>
      */
 
     @Path("/{containerName}/{networkAddress}")
-    @POST
+    @PUT
     @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
     @StatusCodes({
             @ResponseCode(code = 201, condition = "Static host created successfully"),
@@ -268,12 +457,7 @@ public class HostTrackerNorthbound {
             @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
     public Response addHost(@PathParam("containerName") String containerName,
             @PathParam("networkAddress") String networkAddress,
-            @QueryParam("dataLayerAddress") String dataLayerAddress,
-            @QueryParam("nodeType") String nodeType,
-            @QueryParam("nodeId") String nodeId,
-            @QueryParam("nodeConnectorType") String nodeConnectorType,
-            @QueryParam("nodeConnectorId") String nodeConnectorId,
-            @DefaultValue("0") @QueryParam("vlan") String vlan) {
+            @TypeHint(HostConfig.class) JAXBElement<HostConfig> hostConfig) {
 
         if (!NorthboundUtils.isAuthorized(
                 getUserName(), containerName, Privilege.WRITE, this)) {
@@ -289,7 +473,8 @@ public class HostTrackerNorthbound {
                     + RestMessages.SERVICEUNAVAILABLE.toString());
         }
 
-        Node node = handleNodeAvailability(containerName, nodeType, nodeId);
+        HostConfig hc = hostConfig.getValue();
+        Node node = handleNodeAvailability(containerName, hc.getNodeType(), hc.getNodeId());
         if (node == null) {
             throw new InternalServerErrorException(
                     RestMessages.NONODE.toString());
@@ -301,14 +486,20 @@ public class HostTrackerNorthbound {
             throw new UnsupportedMediaTypeException(networkAddress + " "
                     + RestMessages.INVALIDADDRESS.toString());
         }
-        NodeConnector nc = NodeConnector.fromStringNoNode(nodeConnectorType,
-                nodeConnectorId, node);
+        if(!networkAddress.equals(hc.getNetworkAddress())) {
+            throw new UnsupportedMediaTypeException(networkAddress + " is not the same as "
+                    + hc.getNetworkAddress());
+        }
+        if(!hc.isStaticHost()) {
+            throw new UnsupportedMediaTypeException("StaticHost flag must be true");
+        }
+        NodeConnector nc = NodeConnector.fromStringNoNode(hc.getNodeConnectorType(), hc.getNodeConnectorId(), node);
         if (nc == null) {
-            throw new ResourceNotFoundException(nodeConnectorType + "|"
-                    + nodeConnectorId + " : " + RestMessages.NONODE.toString());
+            throw new ResourceNotFoundException(hc.getNodeConnectorType() + "|"
+                    + hc.getNodeConnectorId() + " : " + RestMessages.NONODE.toString());
         }
         Status status = hostTracker.addStaticHost(networkAddress,
-                dataLayerAddress, nc, vlan);
+                hc.getDataLayerAddress(), nc, hc.getVlan());
         if (status.isSuccess()) {
             NorthboundUtils.auditlog("Static Host", username, "added", networkAddress, containerName);
             return Response.status(Response.Status.CREATED).build();
index c9ada2aeedd528e615b756a562aa32e47b5e25fb..dec5a354986477ffbd8bfaeb9b26e4e143513d87 100644 (file)
@@ -15,24 +15,22 @@ import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 
-import org.opendaylight.controller.hosttracker.hostAware.HostNodeConnector;
-
-@XmlRootElement
+@XmlRootElement(name="list")
 @XmlAccessorType(XmlAccessType.NONE)
 
 public class Hosts {
-        @XmlElement (name="host")
-        Set<HostNodeConnector> hostNodeConnector;
+        @XmlElement
+        Set<HostConfig> hostConfig;
 
         public Hosts() {
         }
-        public Hosts (Set<HostNodeConnector> hostNodeConnector) {
-                this.hostNodeConnector = hostNodeConnector;
+        public Hosts (Set<HostConfig> hostConfig) {
+                this.hostConfig = hostConfig;
         }
-        public Set<HostNodeConnector> getHostNodeConnector() {
-                return hostNodeConnector;
+        public Set<HostConfig> getHostConfig() {
+                return hostConfig;
         }
-        public void setHostNodeConnector(Set<HostNodeConnector> hostNodeConnector) {
-                this.hostNodeConnector = hostNodeConnector;
+        public void setHostConfig(Set<HostConfig> hostConfig) {
+                this.hostConfig = hostConfig;
         }
 }
index cd5e5a91d66880f6f7c3f40307922c1d4079bf7f..c11312375a97e9e3f20ccdca3562e9e65369942c 100644 (file)
@@ -15,22 +15,22 @@ public class HostTrackerNorthboundTest {
     @Test
     public void testHosts() throws UnknownHostException, ConstructionException {
         Hosts h1 = new Hosts();
-        Assert.assertNull(h1.getHostNodeConnector());
+        Assert.assertNull(h1.getHostConfig());
 
         Hosts h2 = new Hosts(null);
-        Assert.assertNull(h2.getHostNodeConnector());
+        Assert.assertNull(h2.getHostConfig());
 
-        Set<HostNodeConnector> conn = new HashSet<HostNodeConnector>();
+        Set<HostConfig> conn = new HashSet<HostConfig>();
         InetAddress addr = InetAddress.getByName("10.1.1.1");
         HostNodeConnector c1 = new HostNodeConnector(addr);
-        conn.add(c1);
-        h1.setHostNodeConnector(conn);
-        Assert.assertTrue(h1.getHostNodeConnector().equals(conn));
+        conn.add(HostConfig.convert(c1));
+        h1.setHostConfig(conn);
+        Assert.assertTrue(h1.getHostConfig().equals(conn));
 
         Hosts h3 = new Hosts(conn);
-        Assert.assertTrue(h3.getHostNodeConnector().equals(conn));
-        h3.setHostNodeConnector(null);
-        Assert.assertNull(h3.getHostNodeConnector());
+        Assert.assertTrue(h3.getHostConfig().equals(conn));
+        h3.setHostConfig(null);
+        Assert.assertNull(h3.getHostConfig());
 
     }
 }
index 85b77b2f4de000f37b2ebe487623a6aa5fc0df8a..a39249d4115437a667b2e62708cabf00e8363cb5 100644 (file)
@@ -868,21 +868,31 @@ public class NorthboundIT {
 
         String baseURL = "http://127.0.0.1:8080/controller/nb/v2/host/default";
 
-        // test POST method: addHost()
-        String queryParameter = new QueryParameter("dataLayerAddress", dataLayerAddress_1).add("nodeType", nodeType_1)
-                .add("nodeId", nodeId_1.toString()).add("nodeConnectorType", nodeConnectorType_1)
-                .add("nodeConnectorId", nodeConnectorId_1.toString()).add("vlan", vlan_1).getString();
-
-        String result = getJsonResult(baseURL + "/" + networkAddress_1 + queryParameter, "POST");
+        // test PUT method: addHost()
+        JSONObject fc_json = new JSONObject();
+        fc_json.put("dataLayerAddress", dataLayerAddress_1);
+        fc_json.put("nodeType", nodeType_1);
+        fc_json.put("nodeId", nodeId_1);
+        fc_json.put("nodeConnectorType", nodeType_1);
+        fc_json.put("nodeConnectorId", nodeConnectorId_1.toString());
+        fc_json.put("vlan", vlan_1);
+        fc_json.put("staticHost", "true");
+        fc_json.put("networkAddress", networkAddress_1);
+
+        String result = getJsonResult(baseURL + "/" + networkAddress_1, "PUT", fc_json.toString());
         Assert.assertTrue(httpResponseCode == 201);
 
-        // vlan is not passed through query parameter but should be
-        // defaulted to "0"
-        queryParameter = new QueryParameter("dataLayerAddress", dataLayerAddress_2).add("nodeType", nodeType_2)
-                .add("nodeId", nodeId_2.toString()).add("nodeConnectorType", nodeConnectorType_2)
-                .add("nodeConnectorId", nodeConnectorId_2.toString()).getString();
-
-        result = getJsonResult(baseURL + "/" + networkAddress_2 + queryParameter, "POST");
+        fc_json = new JSONObject();
+        fc_json.put("dataLayerAddress", dataLayerAddress_2);
+        fc_json.put("nodeType", nodeType_2);
+        fc_json.put("nodeId", nodeId_2);
+        fc_json.put("nodeConnectorType", nodeType_2);
+        fc_json.put("nodeConnectorId", nodeConnectorId_2.toString());
+        fc_json.put("vlan", vlan_2);
+        fc_json.put("staticHost", "true");
+        fc_json.put("networkAddress", networkAddress_2);
+
+        result = getJsonResult(baseURL + "/" + networkAddress_2 , "PUT", fc_json.toString());
         Assert.assertTrue(httpResponseCode == 201);
 
         // define variables for decoding returned strings
@@ -897,32 +907,30 @@ public class NorthboundIT {
         JSONTokener jt = new JSONTokener(result);
         JSONObject json = new JSONObject(jt);
         // there should be at least two hosts in the DB
-        Assert.assertTrue(json.get("host") instanceof JSONArray);
-        JSONArray ja = json.getJSONArray("host");
+        Assert.assertTrue(json.get("hostConfig") instanceof JSONArray);
+        JSONArray ja = json.getJSONArray("hostConfig");
         Integer count = ja.length();
         Assert.assertTrue(count == 2);
 
         for (int i = 0; i < count; i++) {
             host_jo = ja.getJSONObject(i);
-            dl_jo = host_jo.getJSONObject("dataLayerAddress");
-            nc_jo = host_jo.getJSONObject("nodeConnector");
-            node_jo = nc_jo.getJSONObject("node");
-
             networkAddress = host_jo.getString("networkAddress");
             if (networkAddress.equalsIgnoreCase(networkAddress_1)) {
-                Assert.assertTrue(dl_jo.getString("macAddress").equalsIgnoreCase(dataLayerAddress_1));
-                Assert.assertTrue(nc_jo.getString("@type").equalsIgnoreCase(nodeConnectorType_1));
-                Assert.assertTrue(nc_jo.getInt("@id") == nodeConnectorId_1);
-                Assert.assertTrue(node_jo.getString("@type").equalsIgnoreCase(nodeType_1));
-                Assert.assertTrue(node_jo.getInt("@id") == nodeId_1);
+                Assert.assertTrue(host_jo.getString("dataLayerAddress").equalsIgnoreCase(dataLayerAddress_1));
+                Assert.assertTrue(host_jo.getString("nodeConnectorType").equalsIgnoreCase(nodeConnectorType_1));
+                Assert.assertTrue(host_jo.getInt("nodeConnectorId") == nodeConnectorId_1);
+                Assert.assertTrue(host_jo.getString("nodeType").equalsIgnoreCase(nodeType_1));
+                Assert.assertTrue(host_jo.getInt("nodeId") == nodeId_1);
                 Assert.assertTrue(host_jo.getString("vlan").equalsIgnoreCase(vlan_1));
+                Assert.assertTrue(host_jo.getBoolean("staticHost"));
             } else if (networkAddress.equalsIgnoreCase(networkAddress_2)) {
-                Assert.assertTrue(dl_jo.getString("macAddress").equalsIgnoreCase(dataLayerAddress_2));
-                Assert.assertTrue(nc_jo.getString("@type").equalsIgnoreCase(nodeConnectorType_2));
-                Assert.assertTrue(nc_jo.getInt("@id") == nodeConnectorId_2);
-                Assert.assertTrue(node_jo.getString("@type").equalsIgnoreCase(nodeType_2));
-                Assert.assertTrue(node_jo.getInt("@id") == nodeId_2);
+                Assert.assertTrue(host_jo.getString("dataLayerAddress").equalsIgnoreCase(dataLayerAddress_2));
+                Assert.assertTrue(host_jo.getString("nodeConnectorType").equalsIgnoreCase(nodeConnectorType_2));
+                Assert.assertTrue(host_jo.getInt("nodeConnectorId") == nodeConnectorId_2);
+                Assert.assertTrue(host_jo.getString("nodeType").equalsIgnoreCase(nodeType_2));
+                Assert.assertTrue(host_jo.getInt("nodeId") == nodeId_2);
                 Assert.assertTrue(host_jo.getString("vlan").equalsIgnoreCase(vlan_2));
+                Assert.assertTrue(host_jo.getBoolean("staticHost"));
             } else {
                 Assert.assertTrue(false);
             }
@@ -969,17 +977,13 @@ public class NorthboundIT {
 
         Assert.assertFalse(json.length() == 0);
 
-        dl_jo = json.getJSONObject("dataLayerAddress");
-        nc_jo = json.getJSONObject("nodeConnector");
-        node_jo = nc_jo.getJSONObject("node");
-
-        Assert.assertTrue(json.getString("networkAddress").equalsIgnoreCase(networkAddress_1));
-        Assert.assertTrue(dl_jo.getString("macAddress").equalsIgnoreCase(dataLayerAddress_1));
-        Assert.assertTrue(nc_jo.getString("@type").equalsIgnoreCase(nodeConnectorType_1));
-        Assert.assertTrue(Integer.parseInt(nc_jo.getString("@id")) == nodeConnectorId_1);
-        Assert.assertTrue(node_jo.getString("@type").equalsIgnoreCase(nodeType_1));
-        Assert.assertTrue(Integer.parseInt(node_jo.getString("@id")) == nodeId_1);
+        Assert.assertTrue(json.getString("dataLayerAddress").equalsIgnoreCase(dataLayerAddress_1));
+        Assert.assertTrue(json.getString("nodeConnectorType").equalsIgnoreCase(nodeConnectorType_1));
+        Assert.assertTrue(json.getInt("nodeConnectorId") == nodeConnectorId_1);
+        Assert.assertTrue(json.getString("nodeType").equalsIgnoreCase(nodeType_1));
+        Assert.assertTrue(json.getInt("nodeId") == nodeId_1);
         Assert.assertTrue(json.getString("vlan").equalsIgnoreCase(vlan_1));
+        Assert.assertTrue(json.getBoolean("staticHost"));
 
         // test DELETE method for deleteFlow()
 
@@ -1004,8 +1008,8 @@ public class NorthboundIT {
         if (json.length() == 0) {
             return false;
         }
-        if (json.get("host") instanceof JSONArray) {
-            JSONArray ja = json.getJSONArray("host");
+        if (json.get("hostConfig") instanceof JSONArray) {
+            JSONArray ja = json.getJSONArray("hostConfig");
             for (int i = 0; i < ja.length(); i++) {
                 String na = ja.getJSONObject(i).getString("networkAddress");
                 if (na.equalsIgnoreCase(hostIp))
@@ -1013,7 +1017,8 @@ public class NorthboundIT {
             }
             return false;
         } else {
-            String na = json.getJSONObject("host").getString("networkAddress");
+            JSONObject ja = json.getJSONObject("hostConfig");
+            String na = ja.getString("networkAddress");
             return (na.equalsIgnoreCase(hostIp)) ? true : false;
         }
     }