use of org.onosproject.core.Application in project onos by opennetworkinglab.
the class ApplicationCommand method manageApp.
// Manages the specified application.
private boolean manageApp(ApplicationAdminService service, String name) {
ApplicationId appId = service.getId(name);
if (appId == null) {
List<Application> matches = service.getApplications().stream().filter(app -> app.id().name().matches(".*\\." + name + "$")).collect(Collectors.toList());
if (matches.size() == 1) {
// Found match
appId = matches.iterator().next().id();
} else if (!matches.isEmpty()) {
print("Did you mean one of: %s", matches.stream().map(Application::id).map(ApplicationId::name).collect(Collectors.toList()));
return false;
}
}
if (appId == null) {
print("No such application: %s", name);
return false;
}
String action;
if (command.equals(UNINSTALL)) {
service.uninstall(appId);
action = "Uninstalled";
} else if (command.equals(ACTIVATE)) {
service.activate(appId);
action = "Activated";
} else if (command.equals(DEACTIVATE)) {
service.deactivate(appId);
action = "Deactivated";
} else {
print("Unsupported command: %s", command);
return false;
}
print("%s %s", action, appId.name());
return true;
}
use of org.onosproject.core.Application 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);
}
use of org.onosproject.core.Application 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());
}
use of org.onosproject.core.Application in project onos by opennetworkinglab.
the class ReviewApplicationNameCompleter method complete.
@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 (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);
}
use of org.onosproject.core.Application in project onos by opennetworkinglab.
the class ApplicationEventTest method withoutTime.
@Test
public void withoutTime() {
Application app = createApp();
ApplicationEvent event = new ApplicationEvent(APP_ACTIVATED, app, 123L);
validateEvent(event, APP_ACTIVATED, app, 123L);
}
Aggregations