Search in sources :

Example 11 with GroupService

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();
}
Also used : Group(org.onosproject.net.group.Group) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) GroupService(org.onosproject.net.group.GroupService) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 12 with GroupService

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));
    }
}
Also used : Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) List(java.util.List) GroupService(org.onosproject.net.group.GroupService)

Example 13 with GroupService

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;
}
Also used : Comparators(org.onosproject.utils.Comparators) DeviceService(org.onosproject.net.device.DeviceService) GroupBucket(org.onosproject.net.group.GroupBucket) Command(org.apache.karaf.shell.api.action.Command) Group(org.onosproject.net.group.Group) Lists(com.google.common.collect.Lists) GroupState(org.onosproject.net.group.Group.GroupState) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) Device(org.onosproject.net.Device) GroupService(org.onosproject.net.group.GroupService) Argument(org.apache.karaf.shell.api.action.Argument) Collectors(java.util.stream.Collectors) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) List(java.util.List) Stream(java.util.stream.Stream) TreeMap(java.util.TreeMap) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Optional(java.util.Optional) Completion(org.apache.karaf.shell.api.action.Completion) Option(org.apache.karaf.shell.api.action.Option) DeviceId(org.onosproject.net.DeviceId) GroupDescription(org.onosproject.net.group.GroupDescription) Collections(java.util.Collections) SortedMap(java.util.SortedMap) Group(org.onosproject.net.group.Group) Device(org.onosproject.net.Device) List(java.util.List) GroupState(org.onosproject.net.group.Group.GroupState) TreeMap(java.util.TreeMap)

Example 14 with GroupService

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);
}
Also used : NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Group(org.onosproject.net.group.Group) GroupService(org.onosproject.net.group.GroupService)

Example 15 with GroupService

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.");
    }
}
Also used : Group(org.onosproject.net.group.Group) K8sNode(org.onosproject.k8snode.api.K8sNode) K8sNodeService(org.onosproject.k8snode.api.K8sNodeService) CoreService(org.onosproject.core.CoreService) FlowRuleService(org.onosproject.net.flow.FlowRuleService) ApplicationId(org.onosproject.core.ApplicationId) GroupService(org.onosproject.net.group.GroupService)

Aggregations

GroupService (org.onosproject.net.group.GroupService)15 Group (org.onosproject.net.group.Group)9 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 Device (org.onosproject.net.Device)5 DeviceId (org.onosproject.net.DeviceId)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 GET (javax.ws.rs.GET)4 DeviceService (org.onosproject.net.device.DeviceService)4 DefaultGroupKey (org.onosproject.net.group.DefaultGroupKey)4 GroupKey (org.onosproject.net.group.GroupKey)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 List (java.util.List)3 FlowRuleService (org.onosproject.net.flow.FlowRuleService)3 GroupBucket (org.onosproject.net.group.GroupBucket)3 GroupDescription (org.onosproject.net.group.GroupDescription)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Consumes (javax.ws.rs.Consumes)2