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
Showing
9 changed files
with
23 additions
and
151 deletions
| ... | @@ -88,8 +88,7 @@ public class IntentMetrics implements IntentMetricsService, | ... | @@ -88,8 +88,7 @@ public class IntentMetrics implements IntentMetricsService, |
| 88 | 88 | ||
| 89 | @Activate | 89 | @Activate |
| 90 | protected void activate() { | 90 | protected void activate() { |
| 91 | - appId = | 91 | + appId = coreService.registerApplication("org.onosproject.metrics"); |
| 92 | - coreService.registerApplication("org.onosproject.metrics.intent"); | ||
| 93 | 92 | ||
| 94 | clear(); | 93 | clear(); |
| 95 | registerMetrics(); | 94 | registerMetrics(); | ... | ... |
| ... | @@ -108,8 +108,7 @@ public class TopologyMetrics implements TopologyMetricsService { | ... | @@ -108,8 +108,7 @@ public class TopologyMetrics implements TopologyMetricsService { |
| 108 | 108 | ||
| 109 | @Activate | 109 | @Activate |
| 110 | protected void activate() { | 110 | protected void activate() { |
| 111 | - appId = | 111 | + appId = coreService.registerApplication("org.onosproject.metrics"); |
| 112 | - coreService.registerApplication("org.onosproject.metrics.topology"); | ||
| 113 | 112 | ||
| 114 | clear(); | 113 | clear(); |
| 115 | registerMetrics(); | 114 | registerMetrics(); | ... | ... |
| 1 | -/* | ||
| 2 | - * Copyright 2015 Open Networking Laboratory | ||
| 3 | - * | ||
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | - * you may not use this file except in compliance with the License. | ||
| 6 | - * You may obtain a copy of the License at | ||
| 7 | - * | ||
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | - * | ||
| 10 | - * Unless required by applicable law or agreed to in writing, software | ||
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | - * See the License for the specific language governing permissions and | ||
| 14 | - * limitations under the License. | ||
| 15 | - */ | ||
| 16 | -package org.onosproject.cli.app; | ||
| 17 | - | ||
| 18 | -import org.apache.karaf.shell.commands.Argument; | ||
| 19 | -import org.apache.karaf.shell.commands.Command; | ||
| 20 | -import org.onosproject.app.ApplicationAdminService; | ||
| 21 | -import org.onosproject.cli.AbstractShellCommand; | ||
| 22 | -import org.onosproject.core.ApplicationId; | ||
| 23 | - | ||
| 24 | -/** | ||
| 25 | - * Activates an installed application. | ||
| 26 | - */ | ||
| 27 | -@Deprecated | ||
| 28 | -@Command(scope = "onos", name = "app-activate", | ||
| 29 | - description = "Activates an installed application") | ||
| 30 | -public class ApplicationActivateCommand extends AbstractShellCommand { | ||
| 31 | - | ||
| 32 | - @Argument(index = 0, name = "name", description = "Application name", | ||
| 33 | - required = true, multiValued = false) | ||
| 34 | - String name = null; | ||
| 35 | - | ||
| 36 | - @Override | ||
| 37 | - protected void execute() { | ||
| 38 | - ApplicationAdminService service = get(ApplicationAdminService.class); | ||
| 39 | - ApplicationId appId = service.getId(name); | ||
| 40 | - if (appId != null) { | ||
| 41 | - service.activate(appId); | ||
| 42 | - } else { | ||
| 43 | - print("No such application: %s", name); | ||
| 44 | - } | ||
| 45 | - } | ||
| 46 | - | ||
| 47 | -} |
| ... | @@ -38,9 +38,9 @@ public class ApplicationCommand extends AbstractShellCommand { | ... | @@ -38,9 +38,9 @@ public class ApplicationCommand extends AbstractShellCommand { |
| 38 | required = true, multiValued = false) | 38 | required = true, multiValued = false) |
| 39 | String command = null; | 39 | String command = null; |
| 40 | 40 | ||
| 41 | - @Argument(index = 1, name = "name", description = "Application name", | 41 | + @Argument(index = 1, name = "names", description = "Application name(s)", |
| 42 | - required = true, multiValued = false) | 42 | + required = true, multiValued = true) |
| 43 | - String name = null; | 43 | + String[] names = null; |
| 44 | 44 | ||
| 45 | @Override | 45 | @Override |
| 46 | protected void execute() { | 46 | protected void execute() { |
| ... | @@ -49,6 +49,7 @@ public class ApplicationCommand extends AbstractShellCommand { | ... | @@ -49,6 +49,7 @@ public class ApplicationCommand extends AbstractShellCommand { |
| 49 | print("Not supported via CLI yet."); | 49 | print("Not supported via CLI yet."); |
| 50 | 50 | ||
| 51 | } else { | 51 | } else { |
| 52 | + for (String name : names) { | ||
| 52 | ApplicationId appId = service.getId(name); | 53 | ApplicationId appId = service.getId(name); |
| 53 | if (appId == null) { | 54 | if (appId == null) { |
| 54 | print("No such application: %s", name); | 55 | print("No such application: %s", name); |
| ... | @@ -66,5 +67,6 @@ public class ApplicationCommand extends AbstractShellCommand { | ... | @@ -66,5 +67,6 @@ public class ApplicationCommand extends AbstractShellCommand { |
| 66 | } | 67 | } |
| 67 | } | 68 | } |
| 68 | } | 69 | } |
| 70 | + } | ||
| 69 | 71 | ||
| 70 | } | 72 | } | ... | ... |
| 1 | -/* | ||
| 2 | - * Copyright 2015 Open Networking Laboratory | ||
| 3 | - * | ||
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | - * you may not use this file except in compliance with the License. | ||
| 6 | - * You may obtain a copy of the License at | ||
| 7 | - * | ||
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | - * | ||
| 10 | - * Unless required by applicable law or agreed to in writing, software | ||
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | - * See the License for the specific language governing permissions and | ||
| 14 | - * limitations under the License. | ||
| 15 | - */ | ||
| 16 | -package org.onosproject.cli.app; | ||
| 17 | - | ||
| 18 | -import org.apache.karaf.shell.commands.Argument; | ||
| 19 | -import org.apache.karaf.shell.commands.Command; | ||
| 20 | -import org.onosproject.app.ApplicationAdminService; | ||
| 21 | -import org.onosproject.cli.AbstractShellCommand; | ||
| 22 | -import org.onosproject.core.ApplicationId; | ||
| 23 | - | ||
| 24 | -/** | ||
| 25 | - * Deactivates an installed application. | ||
| 26 | - */ | ||
| 27 | -@Deprecated | ||
| 28 | -@Command(scope = "onos", name = "app-deactivate", | ||
| 29 | - description = "Deactivates an installed application") | ||
| 30 | -public class ApplicationDeactivateCommand extends AbstractShellCommand { | ||
| 31 | - | ||
| 32 | - @Argument(index = 0, name = "name", description = "Application name", | ||
| 33 | - required = true, multiValued = false) | ||
| 34 | - String name = null; | ||
| 35 | - | ||
| 36 | - @Override | ||
| 37 | - protected void execute() { | ||
| 38 | - ApplicationAdminService service = get(ApplicationAdminService.class); | ||
| 39 | - ApplicationId appId = service.getId(name); | ||
| 40 | - if (appId != null) { | ||
| 41 | - service.deactivate(appId); | ||
| 42 | - } else { | ||
| 43 | - print("No such application: %s", name); | ||
| 44 | - } | ||
| 45 | - } | ||
| 46 | - | ||
| 47 | -} |
| 1 | -/* | ||
| 2 | - * Copyright 2015 Open Networking Laboratory | ||
| 3 | - * | ||
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | - * you may not use this file except in compliance with the License. | ||
| 6 | - * You may obtain a copy of the License at | ||
| 7 | - * | ||
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | - * | ||
| 10 | - * Unless required by applicable law or agreed to in writing, software | ||
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | - * See the License for the specific language governing permissions and | ||
| 14 | - * limitations under the License. | ||
| 15 | - */ | ||
| 16 | -package org.onosproject.cli.app; | ||
| 17 | - | ||
| 18 | -import org.apache.karaf.shell.commands.Argument; | ||
| 19 | -import org.apache.karaf.shell.commands.Command; | ||
| 20 | -import org.onosproject.app.ApplicationAdminService; | ||
| 21 | -import org.onosproject.cli.AbstractShellCommand; | ||
| 22 | -import org.onosproject.core.ApplicationId; | ||
| 23 | - | ||
| 24 | -/** | ||
| 25 | - * Uninstalls an application. | ||
| 26 | - */ | ||
| 27 | -@Deprecated | ||
| 28 | -@Command(scope = "onos", name = "app-uninstall", | ||
| 29 | - description = "Uninstalls an application") | ||
| 30 | -public class ApplicationUninstallCommand extends AbstractShellCommand { | ||
| 31 | - | ||
| 32 | - @Argument(index = 0, name = "name", description = "Application name", | ||
| 33 | - required = true, multiValued = false) | ||
| 34 | - String name = null; | ||
| 35 | - | ||
| 36 | - @Override | ||
| 37 | - protected void execute() { | ||
| 38 | - ApplicationAdminService service = get(ApplicationAdminService.class); | ||
| 39 | - ApplicationId appId = service.getId(name); | ||
| 40 | - if (appId != null) { | ||
| 41 | - service.uninstall(appId); | ||
| 42 | - } else { | ||
| 43 | - print("No such application: %s", name); | ||
| 44 | - } | ||
| 45 | - } | ||
| 46 | - | ||
| 47 | -} |
| ... | @@ -19,6 +19,7 @@ import com.fasterxml.jackson.databind.JsonNode; | ... | @@ -19,6 +19,7 @@ import com.fasterxml.jackson.databind.JsonNode; |
| 19 | import com.fasterxml.jackson.databind.ObjectMapper; | 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 20 | import com.fasterxml.jackson.databind.node.ArrayNode; | 20 | import com.fasterxml.jackson.databind.node.ArrayNode; |
| 21 | import org.apache.karaf.shell.commands.Command; | 21 | import org.apache.karaf.shell.commands.Command; |
| 22 | +import org.apache.karaf.shell.commands.Option; | ||
| 22 | import org.onosproject.app.ApplicationService; | 23 | import org.onosproject.app.ApplicationService; |
| 23 | import org.onosproject.cli.AbstractShellCommand; | 24 | import org.onosproject.cli.AbstractShellCommand; |
| 24 | import org.onosproject.cli.Comparators; | 25 | import org.onosproject.cli.Comparators; |
| ... | @@ -41,6 +42,11 @@ public class ApplicationsListCommand extends AbstractShellCommand { | ... | @@ -41,6 +42,11 @@ public class ApplicationsListCommand extends AbstractShellCommand { |
| 41 | "%s id=%d, name=%s, version=%s, origin=%s, description=%s, " + | 42 | "%s id=%d, name=%s, version=%s, origin=%s, description=%s, " + |
| 42 | "features=%s, featuresRepo=%s, permissions=%s"; | 43 | "features=%s, featuresRepo=%s, permissions=%s"; |
| 43 | 44 | ||
| 45 | + @Option(name = "-a", aliases = "--active", description = "Show active only", | ||
| 46 | + required = false, multiValued = false) | ||
| 47 | + private boolean activeOnly = false; | ||
| 48 | + | ||
| 49 | + | ||
| 44 | @Override | 50 | @Override |
| 45 | protected void execute() { | 51 | protected void execute() { |
| 46 | ApplicationService service = get(ApplicationService.class); | 52 | ApplicationService service = get(ApplicationService.class); |
| ... | @@ -51,7 +57,9 @@ public class ApplicationsListCommand extends AbstractShellCommand { | ... | @@ -51,7 +57,9 @@ public class ApplicationsListCommand extends AbstractShellCommand { |
| 51 | print("%s", json(service, apps)); | 57 | print("%s", json(service, apps)); |
| 52 | } else { | 58 | } else { |
| 53 | for (Application app : apps) { | 59 | for (Application app : apps) { |
| 54 | - print(FMT, service.getState(app.id()) == ACTIVE ? "*" : " ", | 60 | + boolean isActive = service.getState(app.id()) == ACTIVE; |
| 61 | + if (activeOnly && isActive || !activeOnly) { | ||
| 62 | + print(FMT, isActive ? "*" : " ", | ||
| 55 | app.id().id(), app.id().name(), app.version(), app.origin(), | 63 | app.id().id(), app.id().name(), app.version(), app.origin(), |
| 56 | app.description(), app.features(), | 64 | app.description(), app.features(), |
| 57 | app.featuresRepo().isPresent() ? app.featuresRepo().get().toString() : "", | 65 | app.featuresRepo().isPresent() ? app.featuresRepo().get().toString() : "", |
| ... | @@ -59,13 +67,17 @@ public class ApplicationsListCommand extends AbstractShellCommand { | ... | @@ -59,13 +67,17 @@ public class ApplicationsListCommand extends AbstractShellCommand { |
| 59 | } | 67 | } |
| 60 | } | 68 | } |
| 61 | } | 69 | } |
| 70 | + } | ||
| 62 | 71 | ||
| 63 | private JsonNode json(ApplicationService service, List<Application> apps) { | 72 | private JsonNode json(ApplicationService service, List<Application> apps) { |
| 64 | ObjectMapper mapper = new ObjectMapper(); | 73 | ObjectMapper mapper = new ObjectMapper(); |
| 65 | ArrayNode result = mapper.createArrayNode(); | 74 | ArrayNode result = mapper.createArrayNode(); |
| 66 | for (Application app : apps) { | 75 | for (Application app : apps) { |
| 76 | + boolean isActive = service.getState(app.id()) == ACTIVE; | ||
| 77 | + if (activeOnly && isActive || !activeOnly) { | ||
| 67 | result.add(json(service, mapper, app)); | 78 | result.add(json(service, mapper, app)); |
| 68 | } | 79 | } |
| 80 | + } | ||
| 69 | return result; | 81 | return result; |
| 70 | } | 82 | } |
| 71 | 83 | ... | ... |
| ... | @@ -29,7 +29,6 @@ | ... | @@ -29,7 +29,6 @@ |
| 29 | <completers> | 29 | <completers> |
| 30 | <ref component-id="appCommandCompleter"/> | 30 | <ref component-id="appCommandCompleter"/> |
| 31 | <ref component-id="appNameCompleter"/> | 31 | <ref component-id="appNameCompleter"/> |
| 32 | - <null/> | ||
| 33 | </completers> | 32 | </completers> |
| 34 | </command> | 33 | </command> |
| 35 | 34 | ... | ... |
| ... | @@ -15,10 +15,12 @@ case $cmd in | ... | @@ -15,10 +15,12 @@ case $cmd in |
| 15 | list) $curl -X GET $URL;; | 15 | list) $curl -X GET $URL;; |
| 16 | install) $curl -X POST $HDR $URL --data-binary @$app;; | 16 | install) $curl -X POST $HDR $URL --data-binary @$app;; |
| 17 | install!) $curl -X POST $HDR $URL?activate=true --data-binary @$app;; | 17 | install!) $curl -X POST $HDR $URL?activate=true --data-binary @$app;; |
| 18 | + reinstall) $curl -X DELETE $URL/$app && $curl -X POST $HDR $URL --data-binary @$app;; | ||
| 19 | + reinstall!) $curl -X DELETE $URL/$app && $curl -X POST $HDR $URL?activate=true --data-binary @$app;; | ||
| 18 | uninstall) $curl -X DELETE $URL/$app;; | 20 | uninstall) $curl -X DELETE $URL/$app;; |
| 19 | activate) $curl -X POST $URL/$app/active;; | 21 | activate) $curl -X POST $URL/$app/active;; |
| 20 | deactivate) $curl -X DELETE $URL/$app/active;; | 22 | deactivate) $curl -X DELETE $URL/$app/active;; |
| 21 | - *) echo "usage: onos-app {install|install!} <app-file>" >&2 | 23 | + *) echo "usage: onos-app {install|install!|reinstall|reinstall!} <app-file>" >&2 |
| 22 | echo " onos-app {activate|deactivate|uninstall} <app-name>" >&2 | 24 | echo " onos-app {activate|deactivate|uninstall} <app-name>" >&2 |
| 23 | exit 1;; | 25 | exit 1;; |
| 24 | esac | 26 | esac | ... | ... |
-
Please register or login to post a comment