mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-18 10:51:04 +02:00
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:
parent
db49800f19
commit
fba2857430
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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,6 +49,7 @@ public class ApplicationCommand extends AbstractShellCommand {
|
||||
print("Not supported via CLI yet.");
|
||||
|
||||
} else {
|
||||
for (String name : names) {
|
||||
ApplicationId appId = service.getId(name);
|
||||
if (appId == null) {
|
||||
print("No such application: %s", name);
|
||||
@ -66,5 +67,6 @@ public class ApplicationCommand extends AbstractShellCommand {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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,7 +57,9 @@ public class ApplicationsListCommand extends AbstractShellCommand {
|
||||
print("%s", json(service, apps));
|
||||
} else {
|
||||
for (Application app : apps) {
|
||||
print(FMT, service.getState(app.id()) == ACTIVE ? "*" : " ",
|
||||
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() : "",
|
||||
@ -59,13 +67,17 @@ public class ApplicationsListCommand extends AbstractShellCommand {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private JsonNode json(ApplicationService service, List<Application> apps) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
ArrayNode result = mapper.createArrayNode();
|
||||
for (Application app : apps) {
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user