org.apache.karaf.shell.support.completers.StringsCompleter Java Examples

The following examples show how to use org.apache.karaf.shell.support.completers.StringsCompleter. 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: ComponentPropertyNameCompleter.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();

    // Component name is the previous argument.
    String componentName = commandLine.getArguments()[commandLine.getCursorArgumentIndex() - 1];
    ComponentConfigService service = get(ComponentConfigService.class);

    SortedSet<String> strings = delegate.getStrings();
    Set<ConfigProperty> properties =
            service.getProperties(componentName);
    if (properties != null) {
        properties.forEach(property -> strings.add(property.name()));
    }

    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
 
Example #3
Source File: ApplicationIdWithIntentNameCompleter.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 #4
Source File: ReviewApplicationNameCompleter.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();

        ApplicationService service = get(ApplicationService.class);
        Iterator<Application> it = service.getApplications().iterator();
        SortedSet<String> strings = delegate.getStrings();
        while (it.hasNext()) {
            Application app = it.next();
            ApplicationState state = service.getState(app.id());
//            if (previousApps.contains(app.id().name())) {
//                continue;
//            }
            if (state == INSTALLED) {
                strings.add(app.id().name());
            }
        }

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

        for (Bus b : busses) {
            ServerRegistry reg = b.getExtension(ServerRegistry.class);
            List<Server> servers = reg.getServers();

            for (Server serv : servers) {
                if (acceptsFeature(serv)) {
                    String qname = serv.getEndpoint().getEndpointInfo().getName().getLocalPart();
                    delegate.getStrings().add(qname);
                }
            }
        }

    } catch (Exception e) {
        // Ignore
    }
    return delegate.complete(session, commandLine, list);
}
 
Example #6
Source File: KeySpaceCompleter.java    From Karaf-Cassandra with Apache License 2.0 6 votes vote down vote up
public int complete(Session session, CommandLine commandLine,
		List<String> candidates) {
	StringsCompleter delegate = new StringsCompleter();

	com.datastax.driver.core.Session cassandraSession = (com.datastax.driver.core.Session) session
			.get(SessionParameter.CASSANDRA_SESSION);

	if (cassandraSession == null) {
		System.err
				.println("No active session found--run the connect command first");
		return 0;
		// return delegate.complete(session, commandLine, candidates);
	}

	CompleterCommons.completeKeySpace(delegate, cassandraSession);

	return delegate.complete(session, commandLine, candidates);
}
 
Example #7
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 #8
Source File: ClusterIdCompleter.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
    TopologyService service = AbstractShellCommand.get(TopologyService.class);
    Topology topology = service.currentTopology();

    SortedSet<String> strings = delegate.getStrings();
    for (TopologyCluster cluster : service.getClusters(topology)) {
        strings.add(Integer.toString(cluster.id().index()));
    }

    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
 
Example #9
Source File: OpticalConnectPointCompleter.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() && (port.type().equals(Port.Type.OCH) ||
                    port.type().equals(Port.Type.OMS) || port.type().equals(Port.Type.OTU))) {
                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 #10
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 #11
Source File: IntentKeyCompleter.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);
    Iterator<Intent> it = service.getIntents().iterator();
    SortedSet<String> strings = delegate.getStrings();
    while (it.hasNext()) {
        strings.add(it.next().key().toString());
    }

    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
 
Example #12
Source File: LinkDstCompleter.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);

    // Link source the previous argument.
    String srcArg = commandLine.getArguments()[commandLine.getCursorArgumentIndex() - 1];

    // Generate the device ID/port number identifiers
    SortedSet<String> strings = delegate.getStrings();
    try {
        ConnectPoint src = ConnectPoint.deviceConnectPoint(srcArg);
        service.getEgressLinks(src)
                .forEach(link -> strings.add(link.dst().elementId().toString() +
                                                     "/" + link.dst().port()));
    } catch (NumberFormatException e) {
        System.err.println("Invalid connect-point");
    }

    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
 
Example #13
Source File: NetconfOperationCompleter.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();
    SortedSet<String> strings = delegate.getStrings();
    // The available operations are defined in NETCONF protocol (https://tools.ietf.org/html/rfc6241#section-7).
    strings.add("get");
    strings.add("get-config");
    strings.add("edit-config");
    strings.add("copy-config");
    strings.add("delete-config");
    strings.add("lock");
    strings.add("unlock");
    strings.add("close-session");
    strings.add("kill-session");
    return delegate.complete(session, commandLine, candidates);
}
 
Example #14
Source File: DomainIdCompleter.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
    DomainService service = AbstractShellCommand.get(DomainService.class);
    Iterator<DomainId> it = service.getDomainIds().iterator();
    SortedSet<String> strings = delegate.getStrings();
    while (it.hasNext()) {
        strings.add(it.next().id());
    }

    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
 
Example #15
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 #16
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 #17
Source File: IntentKeyImrCompleter.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 -> {
        if (intent instanceof LinkCollectionIntent
                || intent instanceof PointToPointIntent) {
            strings.add(intent.key().toString());
        }
    });

    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
 
Example #18
Source File: ApplicationIdImrCompleter.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(Short.toString(intent.appId().id())));

    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
 
Example #19
Source File: VmIpCompleter.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();

    HostService service = AbstractShellCommand.get(HostService.class);
    Iterator<Host> it = service.getHosts().iterator();
    SortedSet<String> strings = delegate.getStrings();
    while (it.hasNext()) {
        for (IpAddress ip : it.next().ipAddresses()) {
            strings.add(ip.toString() + CIDR);
        }
    }

    return delegate.complete(session, commandLine, candidates);
}
 
Example #20
Source File: VtapIdCompleter.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) {

    OpenstackVtap.Type type = getVtapTypeFromString(VTAP_TYPE);

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

    OpenstackVtapService service = AbstractShellCommand.get(OpenstackVtapService.class);

    service.getVtaps(type).forEach(t -> {
        strings.add(t.id().toString());
    });

    return delegate.complete(session, commandLine, candidates);
}
 
Example #21
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 #22
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 #23
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 #24
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 #25
Source File: DirectPortListCompleter.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<String> set = osNetService.ports().stream()
            .filter(port -> port.getvNicType().equals(DIRECT))
            .map(Port::getId)
            .collect(Collectors.toSet());

    SortedSet<String> strings = delegate.getStrings();
    Iterator<String> it = set.iterator();

    while (it.hasNext()) {
        strings.add(it.next());
    }
    return delegate.complete(session, commandLine, candidates);
}
 
Example #26
Source File: VmDeviceIdCompleter.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<String> set = osNetService.ports().stream().map(Port::getDeviceId)
            .collect(Collectors.toSet());

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

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

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

    return delegate.complete(session, commandLine, candidates);
}
 
Example #27
Source File: VlanIdCompleter.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<VlanId> set = osNetService.externalPeerRouters().stream()
            .map(ExternalPeerRouter::vlanId)
            .collect(Collectors.toSet());
    SortedSet<String> strings = delegate.getStrings();

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

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

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

}
 
Example #28
Source File: VirtualNetworkCompleter.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
    VirtualNetworkAdminService service = AbstractShellCommand.get(VirtualNetworkAdminService.class);

    List<VirtualNetwork> virtualNetworks = new ArrayList<>();

    Set<TenantId> tenantSet = service.getTenantIds();
    tenantSet.forEach(tenantId -> virtualNetworks.addAll(service.getVirtualNetworks(tenantId)));

    Collections.sort(virtualNetworks, Comparators.VIRTUAL_NETWORK_COMPARATOR);

    SortedSet<String> strings = delegate.getStrings();
    virtualNetworks.forEach(virtualNetwork -> strings.add(virtualNetwork.id().toString()));

    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
 
Example #29
Source File: TenantCompleter.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
    VirtualNetworkAdminService service = AbstractShellCommand.get(VirtualNetworkAdminService.class);

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

    for (TenantId tenantId : service.getTenantIds()) {
        strings.add(tenantId.id());
    }

    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
 
Example #30
Source File: PseudowireIdCompleter.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();

    SegmentRoutingService srService =
            AbstractShellCommand.get(SegmentRoutingService.class);


    List<L2Tunnel> tunnels = srService.getL2Tunnels();

    // combine polices and tunnels to pseudowires
    Iterator<String> pseudowires = tunnels.stream()
            .map(l2Tunnel -> Long.toString(l2Tunnel.tunnelId()))
            .collect(Collectors.toList()).iterator();

    SortedSet<String> strings = delegate.getStrings();
    while (pseudowires.hasNext()) {
        strings.add(pseudowires.next());
    }

    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}