Varun Sharma

ONOS-4835 fix

Change-Id: Ic384b39e6cfd111b38c72ade01677831831ec3c0
...@@ -43,6 +43,7 @@ import java.io.InputStream; ...@@ -43,6 +43,7 @@ import java.io.InputStream;
43 import java.net.URI; 43 import java.net.URI;
44 import java.net.URISyntaxException; 44 import java.net.URISyntaxException;
45 45
46 +import org.onlab.util.HexString;
46 import static org.onlab.util.Tools.nullIsNotFound; 47 import static org.onlab.util.Tools.nullIsNotFound;
47 48
48 /** 49 /**
...@@ -110,7 +111,12 @@ public class GroupsWebResource extends AbstractWebResource { ...@@ -110,7 +111,12 @@ public class GroupsWebResource extends AbstractWebResource {
110 public Response getGroupByDeviceIdAndAppCookie(@PathParam("deviceId") String deviceId, 111 public Response getGroupByDeviceIdAndAppCookie(@PathParam("deviceId") String deviceId,
111 @PathParam("appCookie") String appCookie) { 112 @PathParam("appCookie") String appCookie) {
112 final DeviceId deviceIdInstance = DeviceId.deviceId(deviceId); 113 final DeviceId deviceIdInstance = DeviceId.deviceId(deviceId);
113 - final GroupKey appCookieInstance = new DefaultGroupKey(appCookie.getBytes()); 114 +
115 + if (!appCookie.startsWith("0x")) {
116 + throw new IllegalArgumentException("APP_COOKIE must be a hex string starts with 0x");
117 + }
118 + final GroupKey appCookieInstance = new DefaultGroupKey(HexString.fromHexString(
119 + appCookie.split("0x")[1], ""));
114 120
115 Group group = nullIsNotFound(groupService.getGroup(deviceIdInstance, appCookieInstance), 121 Group group = nullIsNotFound(groupService.getGroup(deviceIdInstance, appCookieInstance),
116 GROUP_NOT_FOUND); 122 GROUP_NOT_FOUND);
...@@ -172,7 +178,12 @@ public class GroupsWebResource extends AbstractWebResource { ...@@ -172,7 +178,12 @@ public class GroupsWebResource extends AbstractWebResource {
172 public void deleteGroupByDeviceIdAndAppCookie(@PathParam("deviceId") String deviceId, 178 public void deleteGroupByDeviceIdAndAppCookie(@PathParam("deviceId") String deviceId,
173 @PathParam("appCookie") String appCookie) { 179 @PathParam("appCookie") String appCookie) {
174 DeviceId deviceIdInstance = DeviceId.deviceId(deviceId); 180 DeviceId deviceIdInstance = DeviceId.deviceId(deviceId);
175 - GroupKey appCookieInstance = new DefaultGroupKey(appCookie.getBytes()); 181 +
182 + if (!appCookie.startsWith("0x")) {
183 + throw new IllegalArgumentException("APP_COOKIE must be a hex string starts with 0x");
184 + }
185 + GroupKey appCookieInstance = new DefaultGroupKey(HexString.fromHexString(
186 + appCookie.split("0x")[1], ""));
176 187
177 groupService.removeGroup(deviceIdInstance, appCookieInstance, null); 188 groupService.removeGroup(deviceIdInstance, appCookieInstance, null);
178 } 189 }
......
...@@ -67,6 +67,11 @@ ...@@ -67,6 +67,11 @@
67 "description": "types of the group", 67 "description": "types of the group",
68 "example": "ALL" 68 "example": "ALL"
69 }, 69 },
70 + "deviceId": {
71 + "type": "string",
72 + "description": "device identifier",
73 + "example": "of:0000000000000003"
74 + },
70 "appId": { 75 "appId": {
71 "type": "string", 76 "type": "string",
72 "description": "application identifier", 77 "description": "application identifier",
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
3 "title": "group", 3 "title": "group",
4 "required": [ 4 "required": [
5 "type", 5 "type",
6 - "deviceId",
7 "appCookie", 6 "appCookie",
8 "groupId", 7 "groupId",
9 "buckets" 8 "buckets"
...@@ -13,10 +12,6 @@ ...@@ -13,10 +12,6 @@
13 "type": "string", 12 "type": "string",
14 "example": "ALL" 13 "example": "ALL"
15 }, 14 },
16 - "deviceId": {
17 - "type": "string",
18 - "example": "of:0000000000000001"
19 - },
20 "appCookie": { 15 "appCookie": {
21 "type": "string", 16 "type": "string",
22 "description": "application cookie. Arbitrary length byte array represented in hex string", 17 "description": "application cookie. Arbitrary length byte array represented in hex string",
...@@ -82,4 +77,4 @@ ...@@ -82,4 +77,4 @@
82 } 77 }
83 } 78 }
84 } 79 }
85 -}
...\ No newline at end of file ...\ No newline at end of file
80 +}
......
...@@ -94,14 +94,14 @@ public class GroupsResourceTest extends ResourceTest { ...@@ -94,14 +94,14 @@ public class GroupsResourceTest extends ResourceTest {
94 final Device device2 = new DefaultDevice(null, deviceId2, Device.Type.OTHER, 94 final Device device2 = new DefaultDevice(null, deviceId2, Device.Type.OTHER,
95 "", "", "", "", null); 95 "", "", "", "", null);
96 96
97 - final MockGroup group1 = new MockGroup(deviceId1, 1, "111", 1); 97 + final MockGroup group1 = new MockGroup(deviceId1, 1, "0x111", 1);
98 - final MockGroup group2 = new MockGroup(deviceId1, 2, "222", 2); 98 + final MockGroup group2 = new MockGroup(deviceId1, 2, "0x222", 2);
99 99
100 - final MockGroup group3 = new MockGroup(deviceId2, 3, "333", 3); 100 + final MockGroup group3 = new MockGroup(deviceId2, 3, "0x333", 3);
101 - final MockGroup group4 = new MockGroup(deviceId2, 4, "444", 4); 101 + final MockGroup group4 = new MockGroup(deviceId2, 4, "0x444", 4);
102 102
103 - final MockGroup group5 = new MockGroup(deviceId3, 5, "555", 5); 103 + final MockGroup group5 = new MockGroup(deviceId3, 5, "0x555", 5);
104 - final MockGroup group6 = new MockGroup(deviceId3, 6, "666", 6); 104 + final MockGroup group6 = new MockGroup(deviceId3, 6, "0x666", 6);
105 105
106 public GroupsResourceTest() { 106 public GroupsResourceTest() {
107 super(CoreWebApplication.class); 107 super(CoreWebApplication.class);
...@@ -460,7 +460,7 @@ public class GroupsResourceTest extends ResourceTest { ...@@ -460,7 +460,7 @@ public class GroupsResourceTest extends ResourceTest {
460 .andReturn(group5).anyTimes(); 460 .andReturn(group5).anyTimes();
461 replay(mockGroupService); 461 replay(mockGroupService);
462 final WebResource rs = resource(); 462 final WebResource rs = resource();
463 - final String response = rs.path("groups/" + deviceId3 + "/" + "111").get(String.class); 463 + final String response = rs.path("groups/" + deviceId3 + "/" + "0x111").get(String.class);
464 final JsonObject result = Json.parse(response).asObject(); 464 final JsonObject result = Json.parse(response).asObject();
465 assertThat(result, notNullValue()); 465 assertThat(result, notNullValue());
466 466
...@@ -481,7 +481,7 @@ public class GroupsResourceTest extends ResourceTest { ...@@ -481,7 +481,7 @@ public class GroupsResourceTest extends ResourceTest {
481 .andReturn(null).anyTimes(); 481 .andReturn(null).anyTimes();
482 replay(mockGroupService); 482 replay(mockGroupService);
483 final WebResource rs = resource(); 483 final WebResource rs = resource();
484 - final ClientResponse response = rs.path("groups/" + deviceId3 + "/" + "222").get(ClientResponse.class); 484 + final ClientResponse response = rs.path("groups/" + deviceId3 + "/" + "0x222").get(ClientResponse.class);
485 485
486 assertEquals(404, response.getStatus()); 486 assertEquals(404, response.getStatus());
487 } 487 }
...@@ -517,7 +517,7 @@ public class GroupsResourceTest extends ResourceTest { ...@@ -517,7 +517,7 @@ public class GroupsResourceTest extends ResourceTest {
517 517
518 WebResource rs = resource(); 518 WebResource rs = resource();
519 519
520 - String location = "/groups/1/111"; 520 + String location = "/groups/1/0x111";
521 521
522 ClientResponse deleteResponse = rs.path(location) 522 ClientResponse deleteResponse = rs.path(location)
523 .type(MediaType.APPLICATION_JSON_TYPE) 523 .type(MediaType.APPLICATION_JSON_TYPE)
......