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
This commit is contained in:
Thomas Vachuska 2015-03-25 18:48:59 -07:00 committed by Ray Milkey
parent db49800f19
commit fba2857430
9 changed files with 41 additions and 169 deletions

View File

@ -88,8 +88,7 @@ public class IntentMetrics implements IntentMetricsService,
@Activate @Activate
protected void activate() { protected void activate() {
appId = appId = coreService.registerApplication("org.onosproject.metrics");
coreService.registerApplication("org.onosproject.metrics.intent");
clear(); clear();
registerMetrics(); registerMetrics();

View File

@ -108,8 +108,7 @@ public class TopologyMetrics implements TopologyMetricsService {
@Activate @Activate
protected void activate() { protected void activate() {
appId = appId = coreService.registerApplication("org.onosproject.metrics");
coreService.registerApplication("org.onosproject.metrics.topology");
clear(); clear();
registerMetrics(); registerMetrics();

View File

@ -1,47 +0,0 @@
/*
* 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);
}
}
}

View File

@ -38,9 +38,9 @@ public class ApplicationCommand extends AbstractShellCommand {
required = true, multiValued = false) required = true, multiValued = false)
String command = null; String command = null;
@Argument(index = 1, name = "name", description = "Application name", @Argument(index = 1, name = "names", description = "Application name(s)",
required = true, multiValued = false) required = true, multiValued = true)
String name = null; String[] names = null;
@Override @Override
protected void execute() { protected void execute() {
@ -49,20 +49,22 @@ public class ApplicationCommand extends AbstractShellCommand {
print("Not supported via CLI yet."); print("Not supported via CLI yet.");
} else { } else {
ApplicationId appId = service.getId(name); for (String name : names) {
if (appId == null) { ApplicationId appId = service.getId(name);
print("No such application: %s", name); if (appId == null) {
return; print("No such application: %s", name);
} return;
}
if (command.equals(UNINSTALL)) { if (command.equals(UNINSTALL)) {
service.uninstall(appId); service.uninstall(appId);
} else if (command.equals(ACTIVATE)) { } else if (command.equals(ACTIVATE)) {
service.activate(appId); service.activate(appId);
} else if (command.equals(DEACTIVATE)) { } else if (command.equals(DEACTIVATE)) {
service.deactivate(appId); service.deactivate(appId);
} else { } else {
print("Unsupported command: %s", command); print("Unsupported command: %s", command);
}
} }
} }
} }

View File

@ -1,47 +0,0 @@
/*
* 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);
}
}
}

View File

@ -1,47 +0,0 @@
/*
* 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);
}
}
}

View File

@ -19,6 +19,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ArrayNode;
import org.apache.karaf.shell.commands.Command; import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.commands.Option;
import org.onosproject.app.ApplicationService; import org.onosproject.app.ApplicationService;
import org.onosproject.cli.AbstractShellCommand; import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.cli.Comparators; 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, " + "%s id=%d, name=%s, version=%s, origin=%s, description=%s, " +
"features=%s, featuresRepo=%s, permissions=%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 @Override
protected void execute() { protected void execute() {
ApplicationService service = get(ApplicationService.class); ApplicationService service = get(ApplicationService.class);
@ -51,11 +57,14 @@ public class ApplicationsListCommand extends AbstractShellCommand {
print("%s", json(service, apps)); print("%s", json(service, apps));
} else { } else {
for (Application app : apps) { for (Application app : apps) {
print(FMT, service.getState(app.id()) == ACTIVE ? "*" : " ", boolean isActive = service.getState(app.id()) == ACTIVE;
app.id().id(), app.id().name(), app.version(), app.origin(), if (activeOnly && isActive || !activeOnly) {
app.description(), app.features(), print(FMT, isActive ? "*" : " ",
app.featuresRepo().isPresent() ? app.featuresRepo().get().toString() : "", app.id().id(), app.id().name(), app.version(), app.origin(),
app.permissions()); 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(); ObjectMapper mapper = new ObjectMapper();
ArrayNode result = mapper.createArrayNode(); ArrayNode result = mapper.createArrayNode();
for (Application app : apps) { 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; return result;
} }

View File

@ -29,7 +29,6 @@
<completers> <completers>
<ref component-id="appCommandCompleter"/> <ref component-id="appCommandCompleter"/>
<ref component-id="appNameCompleter"/> <ref component-id="appNameCompleter"/>
<null/>
</completers> </completers>
</command> </command>

View File

@ -15,10 +15,12 @@ case $cmd in
list) $curl -X GET $URL;; list) $curl -X GET $URL;;
install) $curl -X POST $HDR $URL --data-binary @$app;; install) $curl -X POST $HDR $URL --data-binary @$app;;
install!) $curl -X POST $HDR $URL?activate=true --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;; uninstall) $curl -X DELETE $URL/$app;;
activate) $curl -X POST $URL/$app/active;; activate) $curl -X POST $URL/$app/active;;
deactivate) $curl -X DELETE $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 echo " onos-app {activate|deactivate|uninstall} <app-name>" >&2
exit 1;; exit 1;;
esac esac