Varun Sharma

Cherry pick ONOS-4835 fix

Change-Id: I82ecb542dad4430d55af0fc684f8d13d6e45b45e
...@@ -44,6 +44,7 @@ import javax.ws.rs.core.UriInfo; ...@@ -44,6 +44,7 @@ import javax.ws.rs.core.UriInfo;
44 import java.io.IOException; 44 import java.io.IOException;
45 import java.io.InputStream; 45 import java.io.InputStream;
46 46
47 +import org.onlab.util.HexString;
47 import static org.onlab.util.Tools.nullIsNotFound; 48 import static org.onlab.util.Tools.nullIsNotFound;
48 49
49 /** 50 /**
...@@ -115,7 +116,12 @@ public class GroupsWebResource extends AbstractWebResource { ...@@ -115,7 +116,12 @@ public class GroupsWebResource extends AbstractWebResource {
115 public Response getGroupByDeviceIdAndAppCookie(@PathParam("deviceId") String deviceId, 116 public Response getGroupByDeviceIdAndAppCookie(@PathParam("deviceId") String deviceId,
116 @PathParam("appCookie") String appCookie) { 117 @PathParam("appCookie") String appCookie) {
117 final DeviceId deviceIdInstance = DeviceId.deviceId(deviceId); 118 final DeviceId deviceIdInstance = DeviceId.deviceId(deviceId);
118 - final GroupKey appCookieInstance = new DefaultGroupKey(appCookie.getBytes()); 119 +
120 + if (!appCookie.startsWith("0x")) {
121 + throw new IllegalArgumentException("APP_COOKIE must be a hex string starts with 0x");
122 + }
123 + final GroupKey appCookieInstance = new DefaultGroupKey(HexString.fromHexString(
124 + appCookie.split("0x")[1], ""));
119 125
120 Group group = nullIsNotFound(groupService.getGroup(deviceIdInstance, appCookieInstance), 126 Group group = nullIsNotFound(groupService.getGroup(deviceIdInstance, appCookieInstance),
121 GROUP_NOT_FOUND); 127 GROUP_NOT_FOUND);
...@@ -179,7 +185,12 @@ public class GroupsWebResource extends AbstractWebResource { ...@@ -179,7 +185,12 @@ public class GroupsWebResource extends AbstractWebResource {
179 public Response deleteGroupByDeviceIdAndAppCookie(@PathParam("deviceId") String deviceId, 185 public Response deleteGroupByDeviceIdAndAppCookie(@PathParam("deviceId") String deviceId,
180 @PathParam("appCookie") String appCookie) { 186 @PathParam("appCookie") String appCookie) {
181 DeviceId deviceIdInstance = DeviceId.deviceId(deviceId); 187 DeviceId deviceIdInstance = DeviceId.deviceId(deviceId);
182 - GroupKey appCookieInstance = new DefaultGroupKey(appCookie.getBytes()); 188 +
189 + if (!appCookie.startsWith("0x")) {
190 + throw new IllegalArgumentException("APP_COOKIE must be a hex string starts with 0x");
191 + }
192 + GroupKey appCookieInstance = new DefaultGroupKey(HexString.fromHexString(
193 + appCookie.split("0x")[1], ""));
183 194
184 groupService.removeGroup(deviceIdInstance, appCookieInstance, null); 195 groupService.removeGroup(deviceIdInstance, appCookieInstance, null);
185 return Response.noContent().build(); 196 return Response.noContent().build();
......
...@@ -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",
...@@ -154,4 +159,4 @@ ...@@ -154,4 +159,4 @@
154 } 159 }
155 } 160 }
156 } 161 }
157 -}
...\ No newline at end of file ...\ No newline at end of file
162 +}
......
...@@ -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 +}
......
...@@ -95,14 +95,14 @@ public class GroupsResourceTest extends ResourceTest { ...@@ -95,14 +95,14 @@ public class GroupsResourceTest extends ResourceTest {
95 final Device device2 = new DefaultDevice(null, deviceId2, Device.Type.OTHER, 95 final Device device2 = new DefaultDevice(null, deviceId2, Device.Type.OTHER,
96 "", "", "", "", null); 96 "", "", "", "", null);
97 97
98 - final MockGroup group1 = new MockGroup(deviceId1, 1, "111", 1); 98 + final MockGroup group1 = new MockGroup(deviceId1, 1, "0x111", 1);
99 - final MockGroup group2 = new MockGroup(deviceId1, 2, "222", 2); 99 + final MockGroup group2 = new MockGroup(deviceId1, 2, "0x222", 2);
100 100
101 - final MockGroup group3 = new MockGroup(deviceId2, 3, "333", 3); 101 + final MockGroup group3 = new MockGroup(deviceId2, 3, "0x333", 3);
102 - final MockGroup group4 = new MockGroup(deviceId2, 4, "444", 4); 102 + final MockGroup group4 = new MockGroup(deviceId2, 4, "0x444", 4);
103 103
104 - final MockGroup group5 = new MockGroup(deviceId3, 5, "555", 5); 104 + final MockGroup group5 = new MockGroup(deviceId3, 5, "0x555", 5);
105 - final MockGroup group6 = new MockGroup(deviceId3, 6, "666", 6); 105 + final MockGroup group6 = new MockGroup(deviceId3, 6, "0x666", 6);
106 106
107 /** 107 /**
108 * Mock class for a group. 108 * Mock class for a group.
...@@ -462,7 +462,7 @@ public class GroupsResourceTest extends ResourceTest { ...@@ -462,7 +462,7 @@ public class GroupsResourceTest extends ResourceTest {
462 .andReturn(group5).anyTimes(); 462 .andReturn(group5).anyTimes();
463 replay(mockGroupService); 463 replay(mockGroupService);
464 final WebTarget wt = target(); 464 final WebTarget wt = target();
465 - final String response = wt.path("groups/" + deviceId3 + "/" + "111") 465 + final String response = wt.path("groups/" + deviceId3 + "/" + "0x111")
466 .request().get(String.class); 466 .request().get(String.class);
467 final JsonObject result = Json.parse(response).asObject(); 467 final JsonObject result = Json.parse(response).asObject();
468 assertThat(result, notNullValue()); 468 assertThat(result, notNullValue());
...@@ -484,7 +484,7 @@ public class GroupsResourceTest extends ResourceTest { ...@@ -484,7 +484,7 @@ public class GroupsResourceTest extends ResourceTest {
484 .andReturn(null).anyTimes(); 484 .andReturn(null).anyTimes();
485 replay(mockGroupService); 485 replay(mockGroupService);
486 final WebTarget wt = target(); 486 final WebTarget wt = target();
487 - final Response response = wt.path("groups/" + deviceId3 + "/" + "222").request().get(); 487 + final Response response = wt.path("groups/" + deviceId3 + "/" + "0x222").request().get();
488 488
489 assertEquals(404, response.getStatus()); 489 assertEquals(404, response.getStatus());
490 } 490 }
...@@ -522,7 +522,7 @@ public class GroupsResourceTest extends ResourceTest { ...@@ -522,7 +522,7 @@ public class GroupsResourceTest extends ResourceTest {
522 522
523 WebTarget wt = target(); 523 WebTarget wt = target();
524 524
525 - String location = "/groups/1/111"; 525 + String location = "/groups/1/0x111";
526 526
527 Response deleteResponse = wt.path(location) 527 Response deleteResponse = wt.path(location)
528 .request(MediaType.APPLICATION_JSON_TYPE) 528 .request(MediaType.APPLICATION_JSON_TYPE)
......