Cherry pick ONOS-4835 fix
Change-Id: I82ecb542dad4430d55af0fc684f8d13d6e45b45e
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/GroupsWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/GroupsWebResource.java
index 5d61c0b..77e6287 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/GroupsWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/GroupsWebResource.java
@@ -44,6 +44,7 @@
import java.io.IOException;
import java.io.InputStream;
+import org.onlab.util.HexString;
import static org.onlab.util.Tools.nullIsNotFound;
/**
@@ -115,7 +116,12 @@
public Response getGroupByDeviceIdAndAppCookie(@PathParam("deviceId") String deviceId,
@PathParam("appCookie") String appCookie) {
final DeviceId deviceIdInstance = DeviceId.deviceId(deviceId);
- final GroupKey appCookieInstance = new DefaultGroupKey(appCookie.getBytes());
+
+ if (!appCookie.startsWith("0x")) {
+ throw new IllegalArgumentException("APP_COOKIE must be a hex string starts with 0x");
+ }
+ final GroupKey appCookieInstance = new DefaultGroupKey(HexString.fromHexString(
+ appCookie.split("0x")[1], ""));
Group group = nullIsNotFound(groupService.getGroup(deviceIdInstance, appCookieInstance),
GROUP_NOT_FOUND);
@@ -179,7 +185,12 @@
public Response deleteGroupByDeviceIdAndAppCookie(@PathParam("deviceId") String deviceId,
@PathParam("appCookie") String appCookie) {
DeviceId deviceIdInstance = DeviceId.deviceId(deviceId);
- GroupKey appCookieInstance = new DefaultGroupKey(appCookie.getBytes());
+
+ if (!appCookie.startsWith("0x")) {
+ throw new IllegalArgumentException("APP_COOKIE must be a hex string starts with 0x");
+ }
+ GroupKey appCookieInstance = new DefaultGroupKey(HexString.fromHexString(
+ appCookie.split("0x")[1], ""));
groupService.removeGroup(deviceIdInstance, appCookieInstance, null);
return Response.noContent().build();
diff --git a/web/api/src/main/resources/definitions/Groups.json b/web/api/src/main/resources/definitions/Groups.json
index 22f36fb..04273e0 100644
--- a/web/api/src/main/resources/definitions/Groups.json
+++ b/web/api/src/main/resources/definitions/Groups.json
@@ -67,6 +67,11 @@
"description": "types of the group",
"example": "ALL"
},
+ "deviceId": {
+ "type": "string",
+ "description": "device identifier",
+ "example": "of:0000000000000003"
+ },
"appId": {
"type": "string",
"description": "application identifier",
@@ -154,4 +159,4 @@
}
}
}
-}
\ No newline at end of file
+}
diff --git a/web/api/src/main/resources/definitions/GroupsPost.json b/web/api/src/main/resources/definitions/GroupsPost.json
index 7ea7b50..203e2e4 100644
--- a/web/api/src/main/resources/definitions/GroupsPost.json
+++ b/web/api/src/main/resources/definitions/GroupsPost.json
@@ -3,7 +3,6 @@
"title": "group",
"required": [
"type",
- "deviceId",
"appCookie",
"groupId",
"buckets"
@@ -13,10 +12,6 @@
"type": "string",
"example": "ALL"
},
- "deviceId": {
- "type": "string",
- "example": "of:0000000000000001"
- },
"appCookie": {
"type": "string",
"description": "application cookie. Arbitrary length byte array represented in hex string",
@@ -82,4 +77,4 @@
}
}
}
-}
\ No newline at end of file
+}