use of org.onosproject.net.group.GroupService in project onos by opennetworkinglab.
the class GroupsListCommand method doExecute.
@Override
protected void doExecute() {
DeviceService deviceService = get(DeviceService.class);
GroupService groupService = get(GroupService.class);
SortedMap<Device, List<Group>> sortedGroups = getSortedGroups(deviceService, groupService);
if (referencedOnly && unreferencedOnly) {
print("Options -r and -u cannot be used at the same time");
return;
}
if (outputJson()) {
print("%s", json(sortedGroups));
} else {
sortedGroups.forEach((device, groups) -> printGroups(device.id(), groups));
}
}
use of org.onosproject.net.group.GroupService in project onos by opennetworkinglab.
the class GroupsListCommand method getSortedGroups.
/**
* Returns the list of devices sorted using the device ID URIs.
*
* @param deviceService device service
* @param groupService group service
* @return sorted device list
*/
protected SortedMap<Device, List<Group>> getSortedGroups(DeviceService deviceService, GroupService groupService) {
final GroupState groupsState = (this.state != null && !"any".equals(this.state)) ? GroupState.valueOf(this.state.toUpperCase()) : null;
final Iterable<Device> devices = Optional.ofNullable(uri).map(DeviceId::deviceId).map(deviceService::getDevice).map(dev -> (Iterable<Device>) Collections.singletonList(dev)).orElse(deviceService.getDevices());
SortedMap<Device, List<Group>> sortedGroups = new TreeMap<>(Comparators.ELEMENT_COMPARATOR);
for (Device d : devices) {
Stream<Group> groupStream = Lists.newArrayList(groupService.getGroups(d.id())).stream();
if (groupsState != null) {
groupStream = groupStream.filter(g -> g.state().equals(groupsState));
}
if (referencedOnly) {
groupStream = groupStream.filter(g -> g.referenceCount() != 0);
}
if (type != null && !"any".equals(type)) {
groupStream = groupStream.filter(g -> g.type().equals(GroupDescription.Type.valueOf(type.toUpperCase())));
}
if (unreferencedOnly) {
groupStream = groupStream.filter(g -> g.referenceCount() == 0);
}
sortedGroups.put(d, groupStream.sorted(Comparators.GROUP_COMPARATOR).collect(Collectors.toList()));
}
return sortedGroups;
}
use of org.onosproject.net.group.GroupService in project onos by opennetworkinglab.
the class K8sPurgeRulesCommand method doExecute.
@Override
protected void doExecute() {
FlowRuleService flowRuleService = get(FlowRuleService.class);
GroupService groupService = get(GroupService.class);
CoreService coreService = get(CoreService.class);
K8sNodeService k8sNodeService = get(K8sNodeService.class);
ApplicationId appId = coreService.getAppId(K8S_NETWORKING_APP_ID);
if (appId == null) {
error("Failed to purge kubernetes networking flow rules.");
return;
}
flowRuleService.removeFlowRulesById(appId);
print("Successfully purged flow rules installed by kubernetes networking app.");
boolean result = true;
long timeoutExpiredMs = System.currentTimeMillis() + TIMEOUT_MS;
// we make sure all flow rules are removed from the store
while (stream(flowRuleService.getFlowEntriesById(appId).spliterator(), false).count() > 0) {
long waitMs = timeoutExpiredMs - System.currentTimeMillis();
try {
sleep(SLEEP_MS);
} catch (InterruptedException e) {
log.error("Exception caused during rule purging...");
}
if (stream(flowRuleService.getFlowEntriesById(appId).spliterator(), false).count() == 0) {
break;
} else {
flowRuleService.removeFlowRulesById(appId);
print("Failed to purging flow rules, retrying rule purging...");
}
if (waitMs <= 0) {
result = false;
break;
}
}
for (K8sNode node : k8sNodeService.completeNodes()) {
for (Group group : groupService.getGroups(node.intgBridge(), appId)) {
groupService.removeGroup(node.intgBridge(), group.appCookie(), appId);
}
}
if (result) {
print("Successfully purged flow rules!");
} else {
error("Failed to purge flow rules.");
}
}
use of org.onosproject.net.group.GroupService in project onos by opennetworkinglab.
the class OFSwitchManager method getGroups.
@Override
public List<Group> getGroups(NetworkId networkId, DeviceId deviceId) {
GroupService groupService = virtualNetService.get(networkId, GroupService.class);
Iterable<Group> entries = groupService.getGroups(deviceId);
return Lists.newArrayList(entries);
}
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