Thomas Vachuska
Committed by Ray Milkey

Enhanced app CLI.

apps now support -a|--active option to show only activated apps.

app command now takes a list of app ids to allow single command to activate/deactivate/uninstall multiple apps

Deprecated old CLI commands which were already not included in the run-time config.

Consolidated intent & topology metrics to use the same app id since they are bundled into the same app.

Added 'reinstall' and 'reinstall!' option to onos-app tool.

Change-Id: I1406843bf608acf8e7d969a547b929d056e77067
......@@ -88,8 +88,7 @@ public class IntentMetrics implements IntentMetricsService,
@Activate
protected void activate() {
appId =
coreService.registerApplication("org.onosproject.metrics.intent");
appId = coreService.registerApplication("org.onosproject.metrics");
clear();
registerMetrics();
......
......@@ -108,8 +108,7 @@ public class TopologyMetrics implements TopologyMetricsService {
@Activate
protected void activate() {
appId =
coreService.registerApplication("org.onosproject.metrics.topology");
appId = coreService.registerApplication("org.onosproject.metrics");
clear();
registerMetrics();
......
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.cli.app;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onosproject.app.ApplicationAdminService;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.core.ApplicationId;
/**
* Activates an installed application.
*/
@Deprecated
@Command(scope = "onos", name = "app-activate",
description = "Activates an installed application")
public class ApplicationActivateCommand extends AbstractShellCommand {
@Argument(index = 0, name = "name", description = "Application name",
required = true, multiValued = false)
String name = null;
@Override
protected void execute() {
ApplicationAdminService service = get(ApplicationAdminService.class);
ApplicationId appId = service.getId(name);
if (appId != null) {
service.activate(appId);
} else {
print("No such application: %s", name);
}
}
}
......@@ -38,9 +38,9 @@ public class ApplicationCommand extends AbstractShellCommand {
required = true, multiValued = false)
String command = null;
@Argument(index = 1, name = "name", description = "Application name",
required = true, multiValued = false)
String name = null;
@Argument(index = 1, name = "names", description = "Application name(s)",
required = true, multiValued = true)
String[] names = null;
@Override
protected void execute() {
......@@ -49,20 +49,22 @@ public class ApplicationCommand extends AbstractShellCommand {
print("Not supported via CLI yet.");
} else {
ApplicationId appId = service.getId(name);
if (appId == null) {
print("No such application: %s", name);
return;
}
for (String name : names) {
ApplicationId appId = service.getId(name);
if (appId == null) {
print("No such application: %s", name);
return;
}
if (command.equals(UNINSTALL)) {
service.uninstall(appId);
} else if (command.equals(ACTIVATE)) {
service.activate(appId);
} else if (command.equals(DEACTIVATE)) {
service.deactivate(appId);
} else {
print("Unsupported command: %s", command);
if (command.equals(UNINSTALL)) {
service.uninstall(appId);
} else if (command.equals(ACTIVATE)) {
service.activate(appId);
} else if (command.equals(DEACTIVATE)) {
service.deactivate(appId);
} else {
print("Unsupported command: %s", command);
}
}
}
}
......
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.cli.app;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onosproject.app.ApplicationAdminService;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.core.ApplicationId;
/**
* Deactivates an installed application.
*/
@Deprecated
@Command(scope = "onos", name = "app-deactivate",
description = "Deactivates an installed application")
public class ApplicationDeactivateCommand extends AbstractShellCommand {
@Argument(index = 0, name = "name", description = "Application name",
required = true, multiValued = false)
String name = null;
@Override
protected void execute() {
ApplicationAdminService service = get(ApplicationAdminService.class);
ApplicationId appId = service.getId(name);
if (appId != null) {
service.deactivate(appId);
} else {
print("No such application: %s", name);
}
}
}
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.cli.app;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onosproject.app.ApplicationAdminService;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.core.ApplicationId;
/**
* Uninstalls an application.
*/
@Deprecated
@Command(scope = "onos", name = "app-uninstall",
description = "Uninstalls an application")
public class ApplicationUninstallCommand extends AbstractShellCommand {
@Argument(index = 0, name = "name", description = "Application name",
required = true, multiValued = false)
String name = null;
@Override
protected void execute() {
ApplicationAdminService service = get(ApplicationAdminService.class);
ApplicationId appId = service.getId(name);
if (appId != null) {
service.uninstall(appId);
} else {
print("No such application: %s", name);
}
}
}
......@@ -19,6 +19,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.commands.Option;
import org.onosproject.app.ApplicationService;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.cli.Comparators;
......@@ -41,6 +42,11 @@ public class ApplicationsListCommand extends AbstractShellCommand {
"%s id=%d, name=%s, version=%s, origin=%s, description=%s, " +
"features=%s, featuresRepo=%s, permissions=%s";
@Option(name = "-a", aliases = "--active", description = "Show active only",
required = false, multiValued = false)
private boolean activeOnly = false;
@Override
protected void execute() {
ApplicationService service = get(ApplicationService.class);
......@@ -51,11 +57,14 @@ public class ApplicationsListCommand extends AbstractShellCommand {
print("%s", json(service, apps));
} else {
for (Application app : apps) {
print(FMT, service.getState(app.id()) == ACTIVE ? "*" : " ",
app.id().id(), app.id().name(), app.version(), app.origin(),
app.description(), app.features(),
app.featuresRepo().isPresent() ? app.featuresRepo().get().toString() : "",
app.permissions());
boolean isActive = service.getState(app.id()) == ACTIVE;
if (activeOnly && isActive || !activeOnly) {
print(FMT, isActive ? "*" : " ",
app.id().id(), app.id().name(), app.version(), app.origin(),
app.description(), app.features(),
app.featuresRepo().isPresent() ? app.featuresRepo().get().toString() : "",
app.permissions());
}
}
}
}
......@@ -64,7 +73,10 @@ public class ApplicationsListCommand extends AbstractShellCommand {
ObjectMapper mapper = new ObjectMapper();
ArrayNode result = mapper.createArrayNode();
for (Application app : apps) {
result.add(json(service, mapper, app));
boolean isActive = service.getState(app.id()) == ACTIVE;
if (activeOnly && isActive || !activeOnly) {
result.add(json(service, mapper, app));
}
}
return result;
}
......
......@@ -29,7 +29,6 @@
<completers>
<ref component-id="appCommandCompleter"/>
<ref component-id="appNameCompleter"/>
<null/>
</completers>
</command>
......
......@@ -15,10 +15,12 @@ case $cmd in
list) $curl -X GET $URL;;
install) $curl -X POST $HDR $URL --data-binary @$app;;
install!) $curl -X POST $HDR $URL?activate=true --data-binary @$app;;
reinstall) $curl -X DELETE $URL/$app && $curl -X POST $HDR $URL --data-binary @$app;;
reinstall!) $curl -X DELETE $URL/$app && $curl -X POST $HDR $URL?activate=true --data-binary @$app;;
uninstall) $curl -X DELETE $URL/$app;;
activate) $curl -X POST $URL/$app/active;;
deactivate) $curl -X DELETE $URL/$app/active;;
*) echo "usage: onos-app {install|install!} <app-file>" >&2
*) echo "usage: onos-app {install|install!|reinstall|reinstall!} <app-file>" >&2
echo " onos-app {activate|deactivate|uninstall} <app-name>" >&2
exit 1;;
esac
......