org.apache.karaf.shell.api.console.Session Java Examples

The following examples show how to use org.apache.karaf.shell.api.console.Session. 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: 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 #2
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);
}
 
Example #3
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 #4
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 #5
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 #6
Source File: ScopedInstanceCompleter.java    From roboconf-platform with Apache License 2.0 6 votes vote down vote up
@Override
public int complete( Session session, CommandLine commandLine, List<String> candidates ) {

	// Scoped instance path should be the third argument, preceded by an application name.
	String applicationName = null;
	int position = commandLine.getCursorArgumentIndex();
	if( position > 0 )
		applicationName = commandLine.getArguments()[ position - 1 ];

	// Find the instances...
	StringsCompleter delegate = new StringsCompleter( false );
	ManagedApplication ma;
	if( ! Utils.isEmptyOrWhitespaces( applicationName )
			&& ( ma = this.manager.applicationMngr().findManagedApplicationByName( applicationName )) != null ) {

		for( Instance inst : InstanceHelpers.findAllScopedInstances( ma.getApplication()))
			delegate.getStrings().add( InstanceHelpers.computeInstancePath( inst ));
	}

	return delegate.complete( session, commandLine, candidates );
}
 
Example #7
Source File: BusCompleter.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 bus : busses) {
            delegate.getStrings().add(bus.getId());
        }

    } catch (Exception e) {
        // Ignore
    }
    return delegate.complete(session, commandLine, list);
}
 
Example #8
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 #9
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 #10
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 #11
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 #12
Source File: NodeIdCompleter.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
    ClusterService service = AbstractShellCommand.get(ClusterService.class);
    Iterator<ControllerNode> it = service.getNodes().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 #13
Source File: HostIdCompleter.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()) {
        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 #14
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 #15
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 #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: 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 #18
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 #19
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 #20
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 #21
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 #22
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 #23
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 #24
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 #25
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 #26
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 #27
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 #28
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 #29
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 #30
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);


}