use of org.onosproject.net.group.GroupService in project onos by opennetworkinglab.
the class GroupsWebResource method getGroups.
/**
* Returns all groups of all devices.
*
* @return 200 OK with array of all the groups in the system
* @onos.rsModel Groups
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getGroups() {
GroupService groupService = get(GroupService.class);
final Iterable<Device> devices = get(DeviceService.class).getDevices();
devices.forEach(device -> {
final Iterable<Group> groups = groupService.getGroups(device.id());
if (groups != null) {
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 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 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 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.");
}
}
Aggregations