Claudine Chiu
Committed by Gerrit Code Review

ONOS-4077: REST API's for virtual networks, devices, ports, links: add missing o…

…nos.rsModel statements + fix example field in JSON files

Change-Id: I1ae2300143a0a56e5413f8837cea3016d964cb6c
...@@ -43,8 +43,8 @@ public class VirtualDeviceCodec extends JsonCodec<VirtualDevice> { ...@@ -43,8 +43,8 @@ public class VirtualDeviceCodec extends JsonCodec<VirtualDevice> {
43 checkNotNull(vDev, NULL_OBJECT_MSG); 43 checkNotNull(vDev, NULL_OBJECT_MSG);
44 44
45 ObjectNode result = context.mapper().createObjectNode() 45 ObjectNode result = context.mapper().createObjectNode()
46 - .put(ID, vDev.id().toString()) 46 + .put(NETWORK_ID, vDev.networkId().toString())
47 - .put(NETWORK_ID, vDev.networkId().toString()); 47 + .put(ID, vDev.id().toString());
48 48
49 return result; 49 return result;
50 } 50 }
...@@ -60,6 +60,13 @@ public class VirtualDeviceCodec extends JsonCodec<VirtualDevice> { ...@@ -60,6 +60,13 @@ public class VirtualDeviceCodec extends JsonCodec<VirtualDevice> {
60 return new DefaultVirtualDevice(nId, dId); 60 return new DefaultVirtualDevice(nId, dId);
61 } 61 }
62 62
63 + /**
64 + * Extract member from JSON ObjectNode.
65 + *
66 + * @param key key for which value is needed
67 + * @param json JSON ObjectNode
68 + * @return member value
69 + */
63 private String extractMember(String key, ObjectNode json) { 70 private String extractMember(String key, ObjectNode json) {
64 return nullIsIllegal(json.get(key), key + MISSING_MEMBER_MSG).asText(); 71 return nullIsIllegal(json.get(key), key + MISSING_MEMBER_MSG).asText();
65 } 72 }
......
...@@ -42,9 +42,11 @@ public class VirtualLinkCodec extends JsonCodec<VirtualLink> { ...@@ -42,9 +42,11 @@ public class VirtualLinkCodec extends JsonCodec<VirtualLink> {
42 public ObjectNode encode(VirtualLink vLink, CodecContext context) { 42 public ObjectNode encode(VirtualLink vLink, CodecContext context) {
43 checkNotNull(vLink, NULL_OBJECT_MSG); 43 checkNotNull(vLink, NULL_OBJECT_MSG);
44 44
45 + ObjectNode result = context.mapper().createObjectNode()
46 + .put(NETWORK_ID, vLink.networkId().toString());
45 JsonCodec<Link> codec = context.codec(Link.class); 47 JsonCodec<Link> codec = context.codec(Link.class);
46 - ObjectNode result = codec.encode(vLink, context); 48 + ObjectNode linkResult = codec.encode(vLink, context);
47 - result.put(NETWORK_ID, vLink.networkId().toString()); 49 + result.setAll(linkResult);
48 return result; 50 return result;
49 } 51 }
50 52
......
...@@ -75,6 +75,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource { ...@@ -75,6 +75,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource {
75 * Returns all virtual networks. 75 * Returns all virtual networks.
76 * 76 *
77 * @return 200 OK 77 * @return 200 OK
78 + * @onos.rsModel VirtualNetworks
78 */ 79 */
79 @GET 80 @GET
80 @Produces(MediaType.APPLICATION_JSON) 81 @Produces(MediaType.APPLICATION_JSON)
...@@ -92,6 +93,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource { ...@@ -92,6 +93,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource {
92 * 93 *
93 * @param tenantId tenant identifier 94 * @param tenantId tenant identifier
94 * @return 200 OK, 404 not found 95 * @return 200 OK, 404 not found
96 + * @onos.rsModel VirtualNetworks
95 */ 97 */
96 @GET 98 @GET
97 @Produces(MediaType.APPLICATION_JSON) 99 @Produces(MediaType.APPLICATION_JSON)
...@@ -106,7 +108,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource { ...@@ -106,7 +108,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource {
106 /** 108 /**
107 * Creates a virtual network from the JSON input stream. 109 * Creates a virtual network from the JSON input stream.
108 * 110 *
109 - * @param stream TenantId JSON stream 111 + * @param stream tenant identifier JSON stream
110 * @return status of the request - CREATED if the JSON is correct, 112 * @return status of the request - CREATED if the JSON is correct,
111 * BAD_REQUEST if the JSON is invalid 113 * BAD_REQUEST if the JSON is invalid
112 * @onos.rsModel TenantId 114 * @onos.rsModel TenantId
...@@ -150,6 +152,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource { ...@@ -150,6 +152,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource {
150 * 152 *
151 * @param networkId network identifier 153 * @param networkId network identifier
152 * @return 200 OK 154 * @return 200 OK
155 + * @onos.rsModel VirtualDevices
153 */ 156 */
154 @GET 157 @GET
155 @Produces(MediaType.APPLICATION_JSON) 158 @Produces(MediaType.APPLICATION_JSON)
...@@ -164,7 +167,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource { ...@@ -164,7 +167,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource {
164 * Creates a virtual device from the JSON input stream. 167 * Creates a virtual device from the JSON input stream.
165 * 168 *
166 * @param networkId network identifier 169 * @param networkId network identifier
167 - * @param stream Virtual device JSON stream 170 + * @param stream virtual device JSON stream
168 * @return status of the request - CREATED if the JSON is correct, 171 * @return status of the request - CREATED if the JSON is correct,
169 * BAD_REQUEST if the JSON is invalid 172 * BAD_REQUEST if the JSON is invalid
170 * @onos.rsModel VirtualDevice 173 * @onos.rsModel VirtualDevice
...@@ -220,6 +223,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource { ...@@ -220,6 +223,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource {
220 * @param networkId network identifier 223 * @param networkId network identifier
221 * @param deviceId virtual device identifier 224 * @param deviceId virtual device identifier
222 * @return 200 OK 225 * @return 200 OK
226 + * @onos.rsModel VirtualPorts
223 */ 227 */
224 @GET 228 @GET
225 @Produces(MediaType.APPLICATION_JSON) 229 @Produces(MediaType.APPLICATION_JSON)
...@@ -236,7 +240,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource { ...@@ -236,7 +240,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource {
236 * 240 *
237 * @param networkId network identifier 241 * @param networkId network identifier
238 * @param virtDeviceId virtual device identifier 242 * @param virtDeviceId virtual device identifier
239 - * @param stream Virtual device JSON stream 243 + * @param stream virtual port JSON stream
240 * @return status of the request - CREATED if the JSON is correct, 244 * @return status of the request - CREATED if the JSON is correct,
241 * BAD_REQUEST if the JSON is invalid 245 * BAD_REQUEST if the JSON is invalid
242 * @onos.rsModel VirtualPort 246 * @onos.rsModel VirtualPort
...@@ -309,6 +313,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource { ...@@ -309,6 +313,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource {
309 * 313 *
310 * @param networkId network identifier 314 * @param networkId network identifier
311 * @return 200 OK 315 * @return 200 OK
316 + * @onos.rsModel VirtualLinks
312 */ 317 */
313 @GET 318 @GET
314 @Produces(MediaType.APPLICATION_JSON) 319 @Produces(MediaType.APPLICATION_JSON)
...@@ -323,7 +328,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource { ...@@ -323,7 +328,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource {
323 * Creates a virtual network link from the JSON input stream. 328 * Creates a virtual network link from the JSON input stream.
324 * 329 *
325 * @param networkId network identifier 330 * @param networkId network identifier
326 - * @param stream Virtual device JSON stream 331 + * @param stream virtual link JSON stream
327 * @return status of the request - CREATED if the JSON is correct, 332 * @return status of the request - CREATED if the JSON is correct,
328 * BAD_REQUEST if the JSON is invalid 333 * BAD_REQUEST if the JSON is invalid
329 * @onos.rsModel VirtualLink 334 * @onos.rsModel VirtualLink
...@@ -358,7 +363,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource { ...@@ -358,7 +363,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource {
358 * Removes the virtual network link from the JSON input stream. 363 * Removes the virtual network link from the JSON input stream.
359 * 364 *
360 * @param networkId network identifier 365 * @param networkId network identifier
361 - * @param stream deviceIds JSON stream 366 + * @param stream virtual link JSON stream
362 * @return 200 OK, 404 not found 367 * @return 200 OK, 404 not found
363 * @onos.rsModel VirtualLink 368 * @onos.rsModel VirtualLink
364 */ 369 */
......
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
7 "properties": { 7 "properties": {
8 "id": { 8 "id": {
9 "type": "String", 9 "type": "String",
10 - "example": "Tenant unique identifier" 10 + "description": "Tenant identifier",
11 + "example": "Tenant123"
11 } 12 }
12 } 13 }
13 } 14 }
......
...@@ -20,7 +20,8 @@ ...@@ -20,7 +20,8 @@
20 "properties": { 20 "properties": {
21 "id": { 21 "id": {
22 "type": "String", 22 "type": "String",
23 - "example": "Tenant unique identifier" 23 + "description": "Tenant identifier",
24 + "example": "Tenant123"
24 } 25 }
25 } 26 }
26 } 27 }
......
...@@ -7,12 +7,14 @@ ...@@ -7,12 +7,14 @@
7 ], 7 ],
8 "properties": { 8 "properties": {
9 "networkId": { 9 "networkId": {
10 - "type": "String", 10 + "type": "int64",
11 - "example": "Network identifier" 11 + "description": "Network identifier",
12 + "example": 3
12 }, 13 },
13 "deviceId": { 14 "deviceId": {
14 "type": "String", 15 "type": "String",
15 - "example": "Device identifier" 16 + "description": "Device identifier",
17 + "example": "of:0000000000000042"
16 } 18 }
17 } 19 }
18 } 20 }
......
1 +{
2 + "type": "object",
3 + "title": "VirtualDevices",
4 + "required": [
5 + "devices"
6 + ],
7 + "properties": {
8 + "devices": {
9 + "type": "array",
10 + "xml": {
11 + "name": "devices",
12 + "wrapped": true
13 + },
14 + "items": {
15 + "type": "object",
16 + "title": "vdev",
17 + "required": [
18 + "networkId",
19 + "deviceId"
20 + ],
21 + "properties": {
22 + "networkId": {
23 + "type": "int64",
24 + "description": "Network identifier",
25 + "example": 3
26 + },
27 + "deviceId": {
28 + "type": "String",
29 + "description": "Device identifier",
30 + "example": "of:0000000000000042"
31 + }
32 + }
33 + }
34 + }
35 + }
36 +}
...@@ -10,8 +10,9 @@ ...@@ -10,8 +10,9 @@
10 ], 10 ],
11 "properties": { 11 "properties": {
12 "networkId": { 12 "networkId": {
13 - "type": "String", 13 + "type": "int64",
14 - "example": "Network identifier" 14 + "description": "Network identifier",
15 + "example": 3
15 }, 16 },
16 "src": { 17 "src": {
17 "type": "object", 18 "type": "object",
...@@ -22,8 +23,8 @@ ...@@ -22,8 +23,8 @@
22 ], 23 ],
23 "properties": { 24 "properties": {
24 "port": { 25 "port": {
25 - "type": "string", 26 + "type": "int64",
26 - "example": "3" 27 + "example": 3
27 }, 28 },
28 "device": { 29 "device": {
29 "type": "string", 30 "type": "string",
...@@ -40,8 +41,8 @@ ...@@ -40,8 +41,8 @@
40 ], 41 ],
41 "properties": { 42 "properties": {
42 "port": { 43 "port": {
43 - "type": "string", 44 + "type": "int64",
44 - "example": "2" 45 + "example": 2
45 }, 46 },
46 "device": { 47 "device": {
47 "type": "string", 48 "type": "string",
......
1 +{
2 + "type": "object",
3 + "title": "VirtualLinks",
4 + "required": [
5 + "links"
6 + ],
7 + "properties": {
8 + "links": {
9 + "type": "array",
10 + "xml": {
11 + "name": "links",
12 + "wrapped": true
13 + },
14 + "items": {
15 + "type": "object",
16 + "title": "vlink",
17 + "required": [
18 + "networkId",
19 + "src",
20 + "dst",
21 + "type",
22 + "state"
23 + ],
24 + "properties": {
25 + "networkId": {
26 + "type": "int64",
27 + "description": "Network identifier",
28 + "example": 3
29 + },
30 + "src": {
31 + "type": "object",
32 + "title": "src",
33 + "required": [
34 + "port",
35 + "device"
36 + ],
37 + "properties": {
38 + "port": {
39 + "type": "int64",
40 + "example": 3
41 + },
42 + "device": {
43 + "type": "string",
44 + "example": "of:0000000000000002"
45 + }
46 + }
47 + },
48 + "dst": {
49 + "type": "object",
50 + "title": "dst",
51 + "required": [
52 + "port",
53 + "device"
54 + ],
55 + "properties": {
56 + "port": {
57 + "type": "int64",
58 + "example": 2
59 + },
60 + "device": {
61 + "type": "string",
62 + "example": "of:0000000000000003"
63 + }
64 + }
65 + },
66 + "type": {
67 + "type": "string",
68 + "example": "VIRTUAL"
69 + },
70 + "state": {
71 + "type": "string",
72 + "example": "ACTIVE"
73 + }
74 + }
75 + }
76 + }
77 + }
78 +}
1 +{
2 + "type": "object",
3 + "title": "VirtualNetworks",
4 + "required": [
5 + "vnets"
6 + ],
7 + "properties": {
8 + "vnets": {
9 + "type": "array",
10 + "xml": {
11 + "name": "vnets",
12 + "wrapped": true
13 + },
14 + "items": {
15 + "type": "object",
16 + "title": "vnet",
17 + "required": [
18 + "networkId",
19 + "tenantId"
20 + ],
21 + "properties": {
22 + "networkId": {
23 + "type": "int64",
24 + "description": "Network identifier",
25 + "example": 3
26 + },
27 + "tenantId": {
28 + "type": "String",
29 + "description": "Tenant identifier",
30 + "example": "Tenant123"
31 + }
32 + }
33 + }
34 + }
35 + }
36 +}
...@@ -10,24 +10,29 @@ ...@@ -10,24 +10,29 @@
10 ], 10 ],
11 "properties": { 11 "properties": {
12 "networkId": { 12 "networkId": {
13 - "type": "String", 13 + "type": "int64",
14 - "example": "Network identifier" 14 + "description": "Network identifier",
15 + "example": 3
15 }, 16 },
16 "deviceId": { 17 "deviceId": {
17 "type": "String", 18 "type": "String",
18 - "example": "Virtual device identifier" 19 + "description": "Virtual device identifier",
20 + "example": "of:0000000000000042"
19 }, 21 },
20 "portNum": { 22 "portNum": {
21 - "type": "String", 23 + "type": "int64",
22 - "example": "Virtual device port number" 24 + "description": "Virtual device port number",
25 + "example": 34
23 }, 26 },
24 "physDeviceId": { 27 "physDeviceId": {
25 "type": "String", 28 "type": "String",
26 - "example": "Physical device identifier" 29 + "description": "Physical device identifier",
30 + "example": "of:0000000000000003"
27 }, 31 },
28 "physPortNum": { 32 "physPortNum": {
29 - "type": "String", 33 + "type": "int64",
30 - "example": "Physical device port number" 34 + "description": "Physical device port number",
35 + "example": 2
31 } 36 }
32 } 37 }
33 } 38 }
......
1 +{
2 + "type": "object",
3 + "title": "VirtualPorts",
4 + "required": [
5 + "ports"
6 + ],
7 + "properties": {
8 + "ports": {
9 + "type": "array",
10 + "xml": {
11 + "name": "ports",
12 + "wrapped": true
13 + },
14 + "items": {
15 + "type": "object",
16 + "title": "vport",
17 + "required": [
18 + "networkId",
19 + "deviceId",
20 + "portNum",
21 + "physDeviceId",
22 + "physPortNum"
23 + ],
24 + "properties": {
25 + "networkId": {
26 + "type": "int64",
27 + "description": "Network identifier",
28 + "example": 3
29 + },
30 + "deviceId": {
31 + "type": "String",
32 + "description": "Virtual device identifier",
33 + "example": "of:0000000000000042"
34 + },
35 + "portNum": {
36 + "type": "int64",
37 + "description": "Virtual device port number",
38 + "example": 34
39 + },
40 + "physDeviceId": {
41 + "type": "String",
42 + "description": "Physical device identifier",
43 + "example": "of:0000000000000003"
44 + },
45 + "physPortNum": {
46 + "type": "int64",
47 + "description": "Physical device port number",
48 + "example": 2
49 + }
50 + }
51 + }
52 + }
53 + }
54 +}