Java Code Examples for org.apache.karaf.shell.support.completers.StringsCompleter#getStrings()

The following examples show how to use org.apache.karaf.shell.support.completers.StringsCompleter#getStrings() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApplicationNameImrCompleter.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    // Delegate string completer
    StringsCompleter delegate = new StringsCompleter();

    // Fetch our service and feed it's offerings to the string completer
    IntentService service = AbstractShellCommand.get(IntentService.class);
    SortedSet<String> strings = delegate.getStrings();

    service.getIntents()
            .forEach(intent ->
                             strings.add(intent.appId().name()));

    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
 
Example 2
Source File: InstanceIpAddressCompleter.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    StringsCompleter delegate = new StringsCompleter();
    InstancePortService instancePortService =
            AbstractShellCommand.get(InstancePortService.class);

    Set<IpAddress> set = instancePortService.instancePorts().stream()
            .map(InstancePort::ipAddress)
            .collect(Collectors.toSet());
    set.add(IpAddress.valueOf(EXTERNAL_IP));

    SortedSet<String> strings = delegate.getStrings();

    Iterator<IpAddress> it = set.iterator();

    while (it.hasNext()) {
        strings.add(it.next().toString());
    }

    return delegate.complete(session, commandLine, candidates);


}
 
Example 3
Source File: DeviceIdCompleter.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    // Delegate string completer
    StringsCompleter delegate = new StringsCompleter();

    // Fetch our service and feed it's offerings to the string completer
    DeviceService service = AbstractShellCommand.get(DeviceService.class);
    Iterator<Device> it = service.getDevices().iterator();
    SortedSet<String> strings = delegate.getStrings();
    while (it.hasNext()) {
        strings.add(it.next().id().toString());
    }

    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
 
Example 4
Source File: LinkSrcCompleter.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    // Delegate string completer
    StringsCompleter delegate = new StringsCompleter();

    // Fetch our service and feed it's offerings to the string completer
    LinkService service = AbstractShellCommand.get(LinkService.class);

    // Generate the device ID/port number identifiers
    SortedSet<String> strings = delegate.getStrings();
    service.getLinks()
            .forEach(link -> strings.add(link.src().elementId().toString() +
                                                 "/" + link.src().port()));

    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
 
Example 5
Source File: ConnectPointCompleter.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    // Delegate string completer
    StringsCompleter delegate = new StringsCompleter();

    // Fetch our service and feed it's offerings to the string completer
    DeviceService service = AbstractShellCommand.get(DeviceService.class);

    // Generate the device ID/port number identifiers
    for (Device device : service.getDevices()) {
        SortedSet<String> strings = delegate.getStrings();
        for (Port port : service.getPorts(device.id())) {
            if (!port.number().isLogical()) {
                strings.add(device.id().toString() + "/" + port.number());
            }
        }
    }

    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
 
Example 6
Source File: CfmDeviceIdCompleter.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    // Delegate string completer
    StringsCompleter delegate = new StringsCompleter();

    // Fetch our service and feed it's offerings to the string completer
    DeviceService service = AbstractShellCommand.get(DeviceService.class);
    Iterator<Device> it = service.getDevices().iterator();
    SortedSet<String> strings = delegate.getStrings();
    while (it.hasNext()) {
        Device device = it.next();
        if (device.is(CfmMepProgrammable.class)) {
            strings.add(device.id().toString());
        }
    }

    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
 
Example 7
Source File: IpAddressCompleter.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    StringsCompleter delegate = new StringsCompleter();
    OpenstackNetworkService osNetService = get(OpenstackNetworkService.class);
    Set<IpAddress> set = osNetService.externalPeerRouters().stream()
            .map(ExternalPeerRouter::ipAddress)
            .collect(Collectors.toSet());
    SortedSet<String> strings = delegate.getStrings();

    Iterator<IpAddress> it = set.iterator();

    while (it.hasNext()) {
        strings.add(it.next().toString());
    }

    return delegate.complete(session, commandLine, candidates);

}
 
Example 8
Source File: MacAddressCompleter.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
    public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    StringsCompleter delegate = new StringsCompleter();
    OpenstackNetworkService osNetService = get(OpenstackNetworkService.class);
    Set<MacAddress> set = osNetService.externalPeerRouters().stream()
            .map(ExternalPeerRouter::macAddress)
            .collect(Collectors.toSet());
    SortedSet<String> strings = delegate.getStrings();

    Iterator<MacAddress> it = set.iterator();

    while (it.hasNext()) {
        strings.add(it.next().toString());
    }

    return delegate.complete(session, commandLine, candidates);

}
 
Example 9
Source File: Srv6SidCompleter.java    From onos-p4-tutorial with Apache License 2.0 6 votes vote down vote up
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    DeviceService deviceService = AbstractShellCommand.get(DeviceService.class);
    NetworkConfigService netCfgService = AbstractShellCommand.get(NetworkConfigService.class);

    // Delegate string completer
    StringsCompleter delegate = new StringsCompleter();
    SortedSet<String> strings = delegate.getStrings();

    stream(deviceService.getDevices())
            .map(d -> netCfgService.getConfig(d.id(), Srv6DeviceConfig.class))
            .filter(Objects::nonNull)
            .map(Srv6DeviceConfig::mySid)
            .filter(Objects::nonNull)
            .forEach(sid -> strings.add(sid.toString()));

    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
 
Example 10
Source File: K8sNetworkIdCompleter.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    StringsCompleter delegate = new StringsCompleter();
    K8sNetworkService networkService = get(K8sNetworkService.class);

    Set<String> netNames = networkService.networks().stream().map(K8sNetwork::name)
            .collect(Collectors.toSet());
    SortedSet<String> strings = delegate.getStrings();

    strings.addAll(netNames);

    return delegate.complete(session, commandLine, candidates);
}
 
Example 11
Source File: ExtHeaderCompleter.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    // Delegate string completer
    StringsCompleter delegate = new StringsCompleter();
    SortedSet<String> strings = delegate.getStrings();

    for (ExtHeader extHeader : ExtHeader.values()) {
        strings.add(extHeader.toString());
    }

    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
 
Example 12
Source File: PlaceholderCompleter.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    // Populate a string completer with what the user has typed so far
    StringsCompleter delegate = new StringsCompleter();
    SortedSet<String> strings = delegate.getStrings();
    if (commandLine.getCursorArgument() != null) {
        strings.add(commandLine.getCursorArgument());
    }
    return delegate.complete(session, commandLine, candidates);
}
 
Example 13
Source File: CfmMaNameTypeCompleter.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    // Delegate string completer
    StringsCompleter delegate = new StringsCompleter();
    SortedSet<String> strings = delegate.getStrings();

    for (MaIdShort.MaIdType nameType : MaIdShort.MaIdType.values()) {
        strings.add(nameType.toString());
    }

    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
 
Example 14
Source File: ComponentNameCompleter.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    // Delegate string completer
    StringsCompleter delegate = new StringsCompleter();

    // Fetch our service and feed it's offerings to the string completer
    ComponentConfigService service = AbstractShellCommand.get(ComponentConfigService.class);
    SortedSet<String> strings = delegate.getStrings();
    service.getComponentNames().forEach(strings::add);

    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
 
Example 15
Source File: ActiveFloatingIpCompleter.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    StringsCompleter delegate = new StringsCompleter();
    InstancePortService service = AbstractShellCommand.get(InstancePortService.class);
    Set<String> set = service.instancePorts().stream()
            .filter(p -> p.state() == InstancePort.State.ACTIVE)
            .filter(p -> service.floatingIp(p.portId()) != null)
            .map(p -> service.floatingIp(p.portId()).toString())
            .collect(Collectors.toSet());

    SortedSet<String> strings = delegate.getStrings();
    strings.addAll(set);

    return delegate.complete(session, commandLine, candidates);
}
 
Example 16
Source File: OpenstackHostnameCompleter.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    StringsCompleter delegate = new StringsCompleter();
    OpenstackNodeService osNodeService = get(OpenstackNodeService.class);

    Set<String> hostnames = osNodeService.nodes().stream()
                                .map(OpenstackNode::hostname)
                                .collect(Collectors.toSet());
    SortedSet<String> strings = delegate.getStrings();

    strings.addAll(hostnames);

    return delegate.complete(session, commandLine, candidates);
}
 
Example 17
Source File: FreeIpCompleter.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    // Delegate string completer
    StringsCompleter delegate = new StringsCompleter();
    DhcpService dhcpService = AbstractShellCommand.get(DhcpService.class);
    Iterator<Ip4Address> it = dhcpService.getAvailableIPs().iterator();
    SortedSet<String> strings = delegate.getStrings();

    while (it.hasNext()) {
        strings.add(it.next().toString());
    }

    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
 
Example 18
Source File: RoleCompleter.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    // Delegate string completer
    StringsCompleter delegate = new StringsCompleter();
    SortedSet<String> strings = delegate.getStrings();
    strings.add(MastershipRole.MASTER.toString().toLowerCase());
    strings.add(MastershipRole.STANDBY.toString().toLowerCase());
    strings.add(MastershipRole.NONE.toString().toLowerCase());

    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
 
Example 19
Source File: FlowRuleStatusCompleter.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    // Delegate string completer
    StringsCompleter delegate = new StringsCompleter();

    FlowEntryState[] states = FlowEntryState.values();
    SortedSet<String> strings = delegate.getStrings();
    for (int i = 0; i < states.length; i++) {
        strings.add(states[i].toString().toLowerCase());
    }
    strings.add(FlowsListCommand.ANY);

    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
 
Example 20
Source File: ResourceNameCompleter.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    // delegate string completer
    StringsCompleter delegate = new StringsCompleter();

    // Resource type is the second argument.
    String nodeId = commandLine.getArguments()[1];
    String type = commandLine.getArguments()[2];

    if (resourceTypes.contains(type)) {
        ControlPlaneMonitorService monitorService =
                AbstractShellCommand.get(ControlPlaneMonitorService.class);

        Set<String> set = Sets.newHashSet();
        switch (type) {
            case NETWORK:
                set = monitorService.availableResourcesSync(NodeId.nodeId(nodeId),
                        ControlResource.Type.NETWORK);
                break;
            case DISK:
                set = monitorService.availableResourcesSync(NodeId.nodeId(nodeId),
                        ControlResource.Type.DISK);
                break;
            case CONTROL_MESSAGE:
                set = monitorService.availableResourcesSync(NodeId.nodeId(nodeId),
                        ControlResource.Type.CONTROL_MESSAGE);
                break;
            default:
                log.warn(INVALID_MSG);
                break;
        }

        SortedSet<String> strings = delegate.getStrings();

        if (!set.isEmpty()) {
            set.forEach(strings::add);
        }
    }

    return delegate.complete(session, commandLine, candidates);
}