Add new rest api to get ports for all devices

Currently, the onos provides a rest api to get port status.
But if we want to get port status for all devices, we need to call rest api with each device ids.

So, this changes provides a rest api to get ports for all devices.

Change-Id: Iaa123ab341890684b7f0991d8cc75d73cd76c9cb
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/DevicesWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/DevicesWebResource.java
index 05390344..c544a11 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/DevicesWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/DevicesWebResource.java
@@ -17,6 +17,7 @@
 
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.collect.Lists;
 import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.Device;
 import org.onosproject.net.DeviceId;
@@ -38,6 +39,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.List;
+import java.util.Optional;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 import static org.onlab.util.Tools.nullIsNotFound;
@@ -106,6 +108,26 @@
     }
 
     /**
+      * Gets ports of all infrastructure devices.
+      * Returns port details of all infrastructure devices.
+      *
+      * @onos.rsModel DevicesGetPorts
+      * @return 200 OK with a collection of ports for all devices
+      */
+    @GET
+    @Path("ports")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response getDevicesPorts() {
+        DeviceService service = get(DeviceService.class);
+        List<Port> result = Lists.newArrayList();
+        service.getDevices().forEach(device -> {
+                Optional<List<Port>> list = Optional.ofNullable(service.getPorts(device.id()));
+                list.ifPresent(ports -> result.addAll(ports));
+        });
+        return ok(encodeArray(Port.class, "ports", result)).build();
+    }
+
+    /**
      * Gets ports of infrastructure device.
      * Returns details of the specified infrastructure device.
      *
diff --git a/web/api/src/main/resources/definitions/DevicesGetPorts.json b/web/api/src/main/resources/definitions/DevicesGetPorts.json
new file mode 100644
index 0000000..453c91a
--- /dev/null
+++ b/web/api/src/main/resources/definitions/DevicesGetPorts.json
@@ -0,0 +1,64 @@
+{
+  "type": "object",
+  "title": "device",
+  "required": [
+    "ports"
+  ],
+  "properties": {
+    "ports": {
+      "type": "array",
+      "xml": {
+        "name": "ports",
+        "wrapped": true
+      },
+      "items": {
+        "type": "object",
+        "title": "port",
+        "required": [
+          "element",
+          "port",
+          "isEnabled",
+          "type",
+          "portSpeed",
+          "annotations"
+        ],
+        "properties": {
+          "element": {
+            "type": "string",
+            "example": "of:0000000000000001"
+          },
+          "port": {
+            "type": "string",
+            "example": "2"
+          },
+          "isEnabled": {
+            "type": "boolean",
+            "example": true
+          },
+          "type": {
+            "type": "string",
+            "example": "copper"
+          },
+          "portSpeed": {
+            "type": "integer",
+            "format": "int64",
+            "example": 0
+          },
+          "annotations": {
+            "type": "object",
+            "title": "annotations",
+            "required": [
+              "portName"
+            ],
+            "properties": {
+              "portName": {
+                "type": "string",
+                "example": "s1"
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+}