use of org.onosproject.net.group.GroupService in project onos by opennetworkinglab.
the class GroupsWebResource method createGroup.
/**
* Create new group rule. Creates and installs a new group rule for the
* specified device.
*
* @param deviceId device identifier
* @param stream group rule JSON
* @return status of the request - CREATED if the JSON is correct,
* BAD_REQUEST if the JSON is invalid
* @onos.rsModel GroupsPost
*/
@POST
@Path("{deviceId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createGroup(@PathParam("deviceId") String deviceId, InputStream stream) {
GroupService groupService = get(GroupService.class);
try {
ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
JsonNode specifiedDeviceId = jsonTree.get("deviceId");
if (specifiedDeviceId != null && !specifiedDeviceId.asText().equals(deviceId)) {
throw new IllegalArgumentException(DEVICE_INVALID);
}
jsonTree.put("deviceId", deviceId);
Group group = codec(Group.class).decode(jsonTree, this);
GroupDescription description = new DefaultGroupDescription(group.deviceId(), group.type(), group.buckets(), group.appCookie(), group.id().id(), group.appId());
groupService.addGroup(description);
UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path("groups").path(deviceId).path(Long.toString(group.id().id()));
return Response.created(locationBuilder.build()).build();
} catch (IOException ex) {
throw new IllegalArgumentException(ex);
}
}
use of org.onosproject.net.group.GroupService in project onos by opennetworkinglab.
the class GroupsWebResource method getGroupByDeviceIdAndAppCookie.
/**
* Returns a group with the given deviceId and appCookie.
*
* @param deviceId device identifier
* @param appCookie group key
* @return 200 OK with a group entry in the system
* @onos.rsModel Group
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{deviceId}/{appCookie}")
public Response getGroupByDeviceIdAndAppCookie(@PathParam("deviceId") String deviceId, @PathParam("appCookie") String appCookie) {
GroupService groupService = get(GroupService.class);
final DeviceId deviceIdInstance = DeviceId.deviceId(deviceId);
final GroupKey appCookieInstance = createKey(appCookie);
Group group = nullIsNotFound(groupService.getGroup(deviceIdInstance, appCookieInstance), GROUP_NOT_FOUND);
groupsNode.add(codec(Group.class).encode(group, this));
return ok(root).build();
}
use of org.onosproject.net.group.GroupService in project onos by opennetworkinglab.
the class GroupsWebResource method getGroupsByDeviceId.
/**
* Returns all groups associated with the given device.
*
* @param deviceId device identifier
* @return 200 OK with array of all the groups in the system
* @onos.rsModel Groups
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{deviceId}")
public Response getGroupsByDeviceId(@PathParam("deviceId") String deviceId) {
GroupService groupService = get(GroupService.class);
final Iterable<Group> groups = groupService.getGroups(DeviceId.deviceId(deviceId));
groups.forEach(group -> groupsNode.add(codec(Group.class).encode(group, this)));
return ok(root).build();
}
use of org.onosproject.net.group.GroupService in project onos by opennetworkinglab.
the class GroupsWebResource method deleteGroupByDeviceIdAndAppCookie.
/**
* Removes the specified group.
*
* @param deviceId device identifier
* @param appCookie application cookie to be used for lookup
* @return 204 NO CONTENT
*/
@DELETE
@Path("{deviceId}/{appCookie}")
public Response deleteGroupByDeviceIdAndAppCookie(@PathParam("deviceId") String deviceId, @PathParam("appCookie") String appCookie) {
GroupService groupService = get(GroupService.class);
DeviceId deviceIdInstance = DeviceId.deviceId(deviceId);
final GroupKey appCookieInstance = createKey(appCookie);
groupService.removeGroup(deviceIdInstance, appCookieInstance, null);
return Response.noContent().build();
}
use of org.onosproject.net.group.GroupService in project onos by opennetworkinglab.
the class GroupsWebResource method updateGroupBuckets.
/**
* Adds buckets to a group using the group service.
*
* @param deviceIdString device Id
* @param appCookieString application cookie
* @param stream JSON stream
*/
private void updateGroupBuckets(String deviceIdString, String appCookieString, InputStream stream) throws IOException {
GroupService groupService = get(GroupService.class);
DeviceId deviceId = DeviceId.deviceId(deviceIdString);
final GroupKey groupKey = createKey(appCookieString);
Group group = nullIsNotFound(groupService.getGroup(deviceId, groupKey), GROUP_NOT_FOUND);
ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
GroupBuckets buckets = null;
List<GroupBucket> groupBucketList = new ArrayList<>();
JsonNode bucketsJson = jsonTree.get("buckets");
final JsonCodec<GroupBucket> groupBucketCodec = codec(GroupBucket.class);
if (bucketsJson != null) {
IntStream.range(0, bucketsJson.size()).forEach(i -> {
ObjectNode bucketJson = (ObjectNode) bucketsJson.get(i);
groupBucketList.add(groupBucketCodec.decode(bucketJson, this));
});
buckets = new GroupBuckets(groupBucketList);
}
groupService.addBucketsToGroup(deviceId, groupKey, buckets, groupKey, group.appId());
}
Aggregations