Search in sources :

Example 6 with ApplicationService

use of org.onosproject.app.ApplicationService in project onos by opennetworkinglab.

the class ApplicationNameCompleter method complete.

@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    // Delegate string completer
    StringsCompleter delegate = new StringsCompleter();
    // Command name is the second argument.
    String cmd = commandLine.getArguments()[1];
    // Fetch our service and feed it's offerings to the string completer
    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 ("uninstall".equals(cmd) || "download".equals(cmd) || ("activate".equals(cmd) && state == INSTALLED) || ("deactivate".equals(cmd) && state == ACTIVE)) {
            strings.add(app.id().name());
        }
    }
    // add unique suffix to candidates, if user has something in buffer
    if (!Strings.isNullOrEmpty(commandLine.getCursorArgument())) {
        List<String> suffixCandidates = strings.stream().map(full -> full.replaceFirst("org\\.onosproject\\.", "")).flatMap(appName -> {
            List<String> suffixes = new ArrayList<>();
            Deque<String> frags = new ArrayDeque<>();
            // a.b.c -> [c, b, a] -> [c, b.c, a.b.c]
            Lists.reverse(asList(appName.split("\\."))).forEach(frag -> {
                frags.addFirst(frag);
                suffixes.add(frags.stream().collect(Collectors.joining(".")));
            });
            return suffixes.stream();
        }).collect(Collectors.groupingBy(e -> e, Collectors.counting())).entrySet().stream().filter(e -> e.getValue() == 1L).map(Entry::getKey).collect(Collectors.toList());
        delegate.getStrings().addAll(suffixCandidates);
    }
    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
Also used : Session(org.apache.karaf.shell.api.console.Session) ApplicationState(org.onosproject.app.ApplicationState) Iterator(java.util.Iterator) SortedSet(java.util.SortedSet) StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter) ApplicationService(org.onosproject.app.ApplicationService) Deque(java.util.Deque) Collectors(java.util.stream.Collectors) AbstractShellCommand.get(org.onosproject.cli.AbstractShellCommand.get) CommandLine(org.apache.karaf.shell.api.console.CommandLine) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) List(java.util.List) AbstractCompleter(org.onosproject.cli.AbstractCompleter) Lists(com.google.common.collect.Lists) ACTIVE(org.onosproject.app.ApplicationState.ACTIVE) Arrays.asList(java.util.Arrays.asList) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Entry(java.util.Map.Entry) INSTALLED(org.onosproject.app.ApplicationState.INSTALLED) ArrayDeque(java.util.ArrayDeque) Application(org.onosproject.core.Application) StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter) ApplicationState(org.onosproject.app.ApplicationState) ArrayList(java.util.ArrayList) Application(org.onosproject.core.Application) ArrayDeque(java.util.ArrayDeque) ApplicationService(org.onosproject.app.ApplicationService)

Example 7 with ApplicationService

use of org.onosproject.app.ApplicationService in project onos by opennetworkinglab.

the class AllApplicationNamesCompleter method choices.

@Override
public List<String> choices() {
    // Fetch the service and return the list of app names
    ApplicationService service = get(ApplicationService.class);
    Iterator<Application> it = service.getApplications().iterator();
    // Add each app name to the list of choices.
    return StreamSupport.stream(Spliterators.spliteratorUnknownSize(it, Spliterator.ORDERED), false).filter(app -> service.getState(app.id()) == INSTALLED).map(app -> app.id().name()).collect(toList());
}
Also used : AbstractChoicesCompleter(org.onosproject.cli.AbstractChoicesCompleter) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Iterator(java.util.Iterator) Spliterators(java.util.Spliterators) Service(org.apache.karaf.shell.api.action.lifecycle.Service) INSTALLED(org.onosproject.app.ApplicationState.INSTALLED) StreamSupport(java.util.stream.StreamSupport) ApplicationService(org.onosproject.app.ApplicationService) Spliterator(java.util.Spliterator) AbstractShellCommand.get(org.onosproject.cli.AbstractShellCommand.get) Application(org.onosproject.core.Application) Application(org.onosproject.core.Application) ApplicationService(org.onosproject.app.ApplicationService)

Example 8 with ApplicationService

use of org.onosproject.app.ApplicationService in project onos by opennetworkinglab.

the class FibInstallerTest method setUp.

@Before
public void setUp() throws Exception {
    sSfibInstaller = new FibInstaller();
    sSfibInstaller.componentConfigService = createNiceMock(ComponentConfigService.class);
    ComponentContext mockContext = createNiceMock(ComponentContext.class);
    routerConfig = new TestRouterConfig();
    interfaceService = createMock(InterfaceService.class);
    networkConfigService = createMock(NetworkConfigService.class);
    networkConfigService.addListener(anyObject(NetworkConfigListener.class));
    expectLastCall().anyTimes();
    networkConfigRegistry = createMock(NetworkConfigRegistry.class);
    flowObjectiveService = createMock(FlowObjectiveService.class);
    applicationService = createNiceMock(ApplicationService.class);
    replay(applicationService);
    deviceService = new TestDeviceService();
    CoreService coreService = createNiceMock(CoreService.class);
    expect(coreService.registerApplication(anyString())).andReturn(APPID).anyTimes();
    replay(coreService);
    sSfibInstaller.networkConfigService = networkConfigService;
    sSfibInstaller.networkConfigRegistry = networkConfigRegistry;
    sSfibInstaller.interfaceService = interfaceService;
    sSfibInstaller.flowObjectiveService = flowObjectiveService;
    sSfibInstaller.applicationService = applicationService;
    sSfibInstaller.coreService = coreService;
    sSfibInstaller.routeService = new TestRouteService();
    sSfibInstaller.deviceService = deviceService;
    setUpNetworkConfigService();
    setUpInterfaceService();
    sSfibInstaller.activate(mockContext);
}
Also used : ComponentConfigService(org.onosproject.cfg.ComponentConfigService) ComponentContext(org.osgi.service.component.ComponentContext) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) CoreService(org.onosproject.core.CoreService) InterfaceService(org.onosproject.net.intf.InterfaceService) NetworkConfigRegistry(org.onosproject.net.config.NetworkConfigRegistry) FlowObjectiveService(org.onosproject.net.flowobjective.FlowObjectiveService) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) ApplicationService(org.onosproject.app.ApplicationService) Before(org.junit.Before)

Example 9 with ApplicationService

use of org.onosproject.app.ApplicationService in project onos by opennetworkinglab.

the class ApplicationsListCommand method doExecute.

@Override
protected void doExecute() {
    ApplicationService service = get(ApplicationService.class);
    List<Application> apps = newArrayList(service.getApplications());
    if (sortByName) {
        apps.sort(Comparator.comparing(app -> app.id().name()));
    } else {
        Collections.sort(apps, Comparators.APP_COMPARATOR);
    }
    if (outputJson()) {
        print("%s", json(service, apps));
    } else {
        for (Application app : apps) {
            boolean isActive = service.getState(app.id()) == ACTIVE;
            if (activeOnly && isActive || !activeOnly) {
                if (shortOnly) {
                    String shortDescription = app.title().equals(app.id().name()) ? app.description().replaceAll("[\\r\\n]", " ").replaceAll(" +", " ") : app.title();
                    print(SHORT_FMT, isActive ? "*" : " ", app.id().id(), app.id().name(), app.version(), shortDescription);
                } else {
                    print(FMT, isActive ? "*" : " ", app.id().id(), app.id().name(), app.version(), app.origin(), app.category(), app.description(), app.features(), app.featuresRepo().map(URI::toString).orElse(""), app.requiredApps(), app.permissions(), app.url());
                }
            }
        }
    }
}
Also used : Comparators(org.onosproject.utils.Comparators) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ApplicationService(org.onosproject.app.ApplicationService) Command(org.apache.karaf.shell.api.action.Command) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ACTIVE(org.onosproject.app.ApplicationState.ACTIVE) Service(org.apache.karaf.shell.api.action.lifecycle.Service) JsonNode(com.fasterxml.jackson.databind.JsonNode) URI(java.net.URI) Comparator(java.util.Comparator) Option(org.apache.karaf.shell.api.action.Option) Collections(java.util.Collections) Application(org.onosproject.core.Application) Application(org.onosproject.core.Application) URI(java.net.URI) ApplicationService(org.onosproject.app.ApplicationService)

Aggregations

ApplicationService (org.onosproject.app.ApplicationService)9 Application (org.onosproject.core.Application)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 List (java.util.List)3 Service (org.apache.karaf.shell.api.action.lifecycle.Service)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Iterator (java.util.Iterator)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 StringsCompleter (org.apache.karaf.shell.support.completers.StringsCompleter)2 Before (org.junit.Before)2 ApplicationState (org.onosproject.app.ApplicationState)2 ACTIVE (org.onosproject.app.ApplicationState.ACTIVE)2 INSTALLED (org.onosproject.app.ApplicationState.INSTALLED)2 AbstractShellCommand.get (org.onosproject.cli.AbstractShellCommand.get)2 ApplicationId (org.onosproject.core.ApplicationId)2 NetworkConfigListener (org.onosproject.net.config.NetworkConfigListener)2 FlowRuleService (org.onosproject.net.flow.FlowRuleService)2 FlowObjectiveService (org.onosproject.net.flowobjective.FlowObjectiveService)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1