From 1decd539316b6d4cfd61ac07409d16d8f1883d7e Mon Sep 17 00:00:00 2001 From: Claudine Chiu Date: Tue, 19 Apr 2016 18:30:01 +0000 Subject: [PATCH] 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 --- .../codec/impl/VirtualDeviceCodec.java | 11 ++- .../codec/impl/VirtualLinkCodec.java | 6 +- .../resources/VirtualNetworkWebResource.java | 15 ++-- .../main/resources/definitions/TenantId.json | 3 +- .../main/resources/definitions/TenantIds.json | 3 +- .../resources/definitions/VirtualDevice.json | 8 +- .../resources/definitions/VirtualDevices.json | 36 +++++++++ .../resources/definitions/VirtualLink.json | 13 ++-- .../resources/definitions/VirtualLinks.json | 78 +++++++++++++++++++ .../definitions/VirtualNetworks.json | 36 +++++++++ .../resources/definitions/VirtualPort.json | 21 +++-- .../resources/definitions/VirtualPorts.json | 54 +++++++++++++ 12 files changed, 256 insertions(+), 28 deletions(-) create mode 100644 web/api/src/main/resources/definitions/VirtualDevices.json create mode 100644 web/api/src/main/resources/definitions/VirtualLinks.json create mode 100644 web/api/src/main/resources/definitions/VirtualNetworks.json create mode 100644 web/api/src/main/resources/definitions/VirtualPorts.json 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 de40bc0be7..69f76a1675 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 @@ public class VirtualDeviceCodec extends JsonCodec { 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 @@ public class VirtualDeviceCodec extends JsonCodec { 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 9f6b83a334..0fa5ea9c8f 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 class VirtualLinkCodec extends JsonCodec { public ObjectNode encode(VirtualLink vLink, CodecContext context) { checkNotNull(vLink, NULL_OBJECT_MSG); + ObjectNode result = context.mapper().createObjectNode() + .put(NETWORK_ID, vLink.networkId().toString()); JsonCodec 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 81a699b561..22078c28a0 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 @@ public class VirtualNetworkWebResource extends AbstractWebResource { * Returns all virtual networks. * * @return 200 OK + * @onos.rsModel VirtualNetworks */ @GET @Produces(MediaType.APPLICATION_JSON) @@ -92,6 +93,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource { * * @param tenantId tenant identifier * @return 200 OK, 404 not found + * @onos.rsModel VirtualNetworks */ @GET @Produces(MediaType.APPLICATION_JSON) @@ -106,7 +108,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource { /** * 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 @@ public class VirtualNetworkWebResource extends AbstractWebResource { * * @param networkId network identifier * @return 200 OK + * @onos.rsModel VirtualDevices */ @GET @Produces(MediaType.APPLICATION_JSON) @@ -164,7 +167,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource { * 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 @@ public class VirtualNetworkWebResource extends AbstractWebResource { * @param networkId network identifier * @param deviceId virtual device identifier * @return 200 OK + * @onos.rsModel VirtualPorts */ @GET @Produces(MediaType.APPLICATION_JSON) @@ -236,7 +240,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource { * * @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 @@ public class VirtualNetworkWebResource extends AbstractWebResource { * * @param networkId network identifier * @return 200 OK + * @onos.rsModel VirtualLinks */ @GET @Produces(MediaType.APPLICATION_JSON) @@ -323,7 +328,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource { * 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 @@ public class VirtualNetworkWebResource extends AbstractWebResource { * 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 23981e8a18..237a9c4949 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 91e104bd3a..f568b9f18f 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 858c49d64c..ada054cc48 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 0000000000..61e4071905 --- /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 6f79e49408..8550eb44c9 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 0000000000..816335678e --- /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 0000000000..6ab1bde6ae --- /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 89cb6c179e..d1b8e47251 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 0000000000..daa50199de --- /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 + } + } + } + } + } +}