ONOS-4077: REST API's for virtual networks, devices, ports, links: add missing onos.rsModel statements + fix example field in JSON files
Change-Id: I1ae2300143a0a56e5413f8837cea3016d964cb6c
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/VirtualDeviceCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/VirtualDeviceCodec.java
index de40bc0..69f76a1 100644
--- a/core/common/src/main/java/org/onosproject/codec/impl/VirtualDeviceCodec.java
+++ b/core/common/src/main/java/org/onosproject/codec/impl/VirtualDeviceCodec.java
@@ -43,8 +43,8 @@
checkNotNull(vDev, NULL_OBJECT_MSG);
ObjectNode result = context.mapper().createObjectNode()
- .put(ID, vDev.id().toString())
- .put(NETWORK_ID, vDev.networkId().toString());
+ .put(NETWORK_ID, vDev.networkId().toString())
+ .put(ID, vDev.id().toString());
return result;
}
@@ -60,6 +60,13 @@
return new DefaultVirtualDevice(nId, dId);
}
+ /**
+ * Extract member from JSON ObjectNode.
+ *
+ * @param key key for which value is needed
+ * @param json JSON ObjectNode
+ * @return member value
+ */
private String extractMember(String key, ObjectNode json) {
return nullIsIllegal(json.get(key), key + MISSING_MEMBER_MSG).asText();
}
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/VirtualLinkCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/VirtualLinkCodec.java
index 9f6b83a..0fa5ea9 100644
--- a/core/common/src/main/java/org/onosproject/codec/impl/VirtualLinkCodec.java
+++ b/core/common/src/main/java/org/onosproject/codec/impl/VirtualLinkCodec.java
@@ -42,9 +42,11 @@
public ObjectNode encode(VirtualLink vLink, CodecContext context) {
checkNotNull(vLink, NULL_OBJECT_MSG);
+ ObjectNode result = context.mapper().createObjectNode()
+ .put(NETWORK_ID, vLink.networkId().toString());
JsonCodec<Link> codec = context.codec(Link.class);
- ObjectNode result = codec.encode(vLink, context);
- result.put(NETWORK_ID, vLink.networkId().toString());
+ ObjectNode linkResult = codec.encode(vLink, context);
+ result.setAll(linkResult);
return result;
}
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/VirtualNetworkWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/VirtualNetworkWebResource.java
index 81a699b..22078c2 100755
--- a/web/api/src/main/java/org/onosproject/rest/resources/VirtualNetworkWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/VirtualNetworkWebResource.java
@@ -75,6 +75,7 @@
* Returns all virtual networks.
*
* @return 200 OK
+ * @onos.rsModel VirtualNetworks
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@@ -92,6 +93,7 @@
*
* @param tenantId tenant identifier
* @return 200 OK, 404 not found
+ * @onos.rsModel VirtualNetworks
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@@ -106,7 +108,7 @@
/**
* Creates a virtual network from the JSON input stream.
*
- * @param stream TenantId JSON stream
+ * @param stream tenant identifier JSON stream
* @return status of the request - CREATED if the JSON is correct,
* BAD_REQUEST if the JSON is invalid
* @onos.rsModel TenantId
@@ -150,6 +152,7 @@
*
* @param networkId network identifier
* @return 200 OK
+ * @onos.rsModel VirtualDevices
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@@ -164,7 +167,7 @@
* Creates a virtual device from the JSON input stream.
*
* @param networkId network identifier
- * @param stream Virtual device JSON stream
+ * @param stream virtual device JSON stream
* @return status of the request - CREATED if the JSON is correct,
* BAD_REQUEST if the JSON is invalid
* @onos.rsModel VirtualDevice
@@ -220,6 +223,7 @@
* @param networkId network identifier
* @param deviceId virtual device identifier
* @return 200 OK
+ * @onos.rsModel VirtualPorts
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@@ -236,7 +240,7 @@
*
* @param networkId network identifier
* @param virtDeviceId virtual device identifier
- * @param stream Virtual device JSON stream
+ * @param stream virtual port JSON stream
* @return status of the request - CREATED if the JSON is correct,
* BAD_REQUEST if the JSON is invalid
* @onos.rsModel VirtualPort
@@ -309,6 +313,7 @@
*
* @param networkId network identifier
* @return 200 OK
+ * @onos.rsModel VirtualLinks
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@@ -323,7 +328,7 @@
* Creates a virtual network link from the JSON input stream.
*
* @param networkId network identifier
- * @param stream Virtual device JSON stream
+ * @param stream virtual link JSON stream
* @return status of the request - CREATED if the JSON is correct,
* BAD_REQUEST if the JSON is invalid
* @onos.rsModel VirtualLink
@@ -358,7 +363,7 @@
* Removes the virtual network link from the JSON input stream.
*
* @param networkId network identifier
- * @param stream deviceIds JSON stream
+ * @param stream virtual link JSON stream
* @return 200 OK, 404 not found
* @onos.rsModel VirtualLink
*/
diff --git a/web/api/src/main/resources/definitions/TenantId.json b/web/api/src/main/resources/definitions/TenantId.json
index 23981e8..237a9c4 100644
--- a/web/api/src/main/resources/definitions/TenantId.json
+++ b/web/api/src/main/resources/definitions/TenantId.json
@@ -7,7 +7,8 @@
"properties": {
"id": {
"type": "String",
- "example": "Tenant unique identifier"
+ "description": "Tenant identifier",
+ "example": "Tenant123"
}
}
}
diff --git a/web/api/src/main/resources/definitions/TenantIds.json b/web/api/src/main/resources/definitions/TenantIds.json
index 91e104b..f568b9f 100644
--- a/web/api/src/main/resources/definitions/TenantIds.json
+++ b/web/api/src/main/resources/definitions/TenantIds.json
@@ -20,7 +20,8 @@
"properties": {
"id": {
"type": "String",
- "example": "Tenant unique identifier"
+ "description": "Tenant identifier",
+ "example": "Tenant123"
}
}
}
diff --git a/web/api/src/main/resources/definitions/VirtualDevice.json b/web/api/src/main/resources/definitions/VirtualDevice.json
index 858c49d..ada054c 100644
--- a/web/api/src/main/resources/definitions/VirtualDevice.json
+++ b/web/api/src/main/resources/definitions/VirtualDevice.json
@@ -7,12 +7,14 @@
],
"properties": {
"networkId": {
- "type": "String",
- "example": "Network identifier"
+ "type": "int64",
+ "description": "Network identifier",
+ "example": 3
},
"deviceId": {
"type": "String",
- "example": "Device identifier"
+ "description": "Device identifier",
+ "example": "of:0000000000000042"
}
}
}
diff --git a/web/api/src/main/resources/definitions/VirtualDevices.json b/web/api/src/main/resources/definitions/VirtualDevices.json
new file mode 100644
index 0000000..61e4071
--- /dev/null
+++ b/web/api/src/main/resources/definitions/VirtualDevices.json
@@ -0,0 +1,36 @@
+{
+ "type": "object",
+ "title": "VirtualDevices",
+ "required": [
+ "devices"
+ ],
+ "properties": {
+ "devices": {
+ "type": "array",
+ "xml": {
+ "name": "devices",
+ "wrapped": true
+ },
+ "items": {
+ "type": "object",
+ "title": "vdev",
+ "required": [
+ "networkId",
+ "deviceId"
+ ],
+ "properties": {
+ "networkId": {
+ "type": "int64",
+ "description": "Network identifier",
+ "example": 3
+ },
+ "deviceId": {
+ "type": "String",
+ "description": "Device identifier",
+ "example": "of:0000000000000042"
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/web/api/src/main/resources/definitions/VirtualLink.json b/web/api/src/main/resources/definitions/VirtualLink.json
index 6f79e49..8550eb4 100644
--- a/web/api/src/main/resources/definitions/VirtualLink.json
+++ b/web/api/src/main/resources/definitions/VirtualLink.json
@@ -10,8 +10,9 @@
],
"properties": {
"networkId": {
- "type": "String",
- "example": "Network identifier"
+ "type": "int64",
+ "description": "Network identifier",
+ "example": 3
},
"src": {
"type": "object",
@@ -22,8 +23,8 @@
],
"properties": {
"port": {
- "type": "string",
- "example": "3"
+ "type": "int64",
+ "example": 3
},
"device": {
"type": "string",
@@ -40,8 +41,8 @@
],
"properties": {
"port": {
- "type": "string",
- "example": "2"
+ "type": "int64",
+ "example": 2
},
"device": {
"type": "string",
diff --git a/web/api/src/main/resources/definitions/VirtualLinks.json b/web/api/src/main/resources/definitions/VirtualLinks.json
new file mode 100644
index 0000000..8163356
--- /dev/null
+++ b/web/api/src/main/resources/definitions/VirtualLinks.json
@@ -0,0 +1,78 @@
+{
+ "type": "object",
+ "title": "VirtualLinks",
+ "required": [
+ "links"
+ ],
+ "properties": {
+ "links": {
+ "type": "array",
+ "xml": {
+ "name": "links",
+ "wrapped": true
+ },
+ "items": {
+ "type": "object",
+ "title": "vlink",
+ "required": [
+ "networkId",
+ "src",
+ "dst",
+ "type",
+ "state"
+ ],
+ "properties": {
+ "networkId": {
+ "type": "int64",
+ "description": "Network identifier",
+ "example": 3
+ },
+ "src": {
+ "type": "object",
+ "title": "src",
+ "required": [
+ "port",
+ "device"
+ ],
+ "properties": {
+ "port": {
+ "type": "int64",
+ "example": 3
+ },
+ "device": {
+ "type": "string",
+ "example": "of:0000000000000002"
+ }
+ }
+ },
+ "dst": {
+ "type": "object",
+ "title": "dst",
+ "required": [
+ "port",
+ "device"
+ ],
+ "properties": {
+ "port": {
+ "type": "int64",
+ "example": 2
+ },
+ "device": {
+ "type": "string",
+ "example": "of:0000000000000003"
+ }
+ }
+ },
+ "type": {
+ "type": "string",
+ "example": "VIRTUAL"
+ },
+ "state": {
+ "type": "string",
+ "example": "ACTIVE"
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/web/api/src/main/resources/definitions/VirtualNetworks.json b/web/api/src/main/resources/definitions/VirtualNetworks.json
new file mode 100644
index 0000000..6ab1bde
--- /dev/null
+++ b/web/api/src/main/resources/definitions/VirtualNetworks.json
@@ -0,0 +1,36 @@
+{
+ "type": "object",
+ "title": "VirtualNetworks",
+ "required": [
+ "vnets"
+ ],
+ "properties": {
+ "vnets": {
+ "type": "array",
+ "xml": {
+ "name": "vnets",
+ "wrapped": true
+ },
+ "items": {
+ "type": "object",
+ "title": "vnet",
+ "required": [
+ "networkId",
+ "tenantId"
+ ],
+ "properties": {
+ "networkId": {
+ "type": "int64",
+ "description": "Network identifier",
+ "example": 3
+ },
+ "tenantId": {
+ "type": "String",
+ "description": "Tenant identifier",
+ "example": "Tenant123"
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/web/api/src/main/resources/definitions/VirtualPort.json b/web/api/src/main/resources/definitions/VirtualPort.json
index 89cb6c1..d1b8e47 100644
--- a/web/api/src/main/resources/definitions/VirtualPort.json
+++ b/web/api/src/main/resources/definitions/VirtualPort.json
@@ -10,24 +10,29 @@
],
"properties": {
"networkId": {
- "type": "String",
- "example": "Network identifier"
+ "type": "int64",
+ "description": "Network identifier",
+ "example": 3
},
"deviceId": {
"type": "String",
- "example": "Virtual device identifier"
+ "description": "Virtual device identifier",
+ "example": "of:0000000000000042"
},
"portNum": {
- "type": "String",
- "example": "Virtual device port number"
+ "type": "int64",
+ "description": "Virtual device port number",
+ "example": 34
},
"physDeviceId": {
"type": "String",
- "example": "Physical device identifier"
+ "description": "Physical device identifier",
+ "example": "of:0000000000000003"
},
"physPortNum": {
- "type": "String",
- "example": "Physical device port number"
+ "type": "int64",
+ "description": "Physical device port number",
+ "example": 2
}
}
}
diff --git a/web/api/src/main/resources/definitions/VirtualPorts.json b/web/api/src/main/resources/definitions/VirtualPorts.json
new file mode 100644
index 0000000..daa5019
--- /dev/null
+++ b/web/api/src/main/resources/definitions/VirtualPorts.json
@@ -0,0 +1,54 @@
+{
+ "type": "object",
+ "title": "VirtualPorts",
+ "required": [
+ "ports"
+ ],
+ "properties": {
+ "ports": {
+ "type": "array",
+ "xml": {
+ "name": "ports",
+ "wrapped": true
+ },
+ "items": {
+ "type": "object",
+ "title": "vport",
+ "required": [
+ "networkId",
+ "deviceId",
+ "portNum",
+ "physDeviceId",
+ "physPortNum"
+ ],
+ "properties": {
+ "networkId": {
+ "type": "int64",
+ "description": "Network identifier",
+ "example": 3
+ },
+ "deviceId": {
+ "type": "String",
+ "description": "Virtual device identifier",
+ "example": "of:0000000000000042"
+ },
+ "portNum": {
+ "type": "int64",
+ "description": "Virtual device port number",
+ "example": 34
+ },
+ "physDeviceId": {
+ "type": "String",
+ "description": "Physical device identifier",
+ "example": "of:0000000000000003"
+ },
+ "physPortNum": {
+ "type": "int64",
+ "description": "Physical device port number",
+ "example": 2
+ }
+ }
+ }
+ }
+ }
+}