Thomas Vachuska
Committed by Gerrit Code Review

Added a more intuitive app management CLI; deprecated the old one for now.

Change-Id: I4f884cbf442b21c08415fe3ca3228edbbb5893f7
...@@ -24,6 +24,7 @@ import org.onosproject.core.ApplicationId; ...@@ -24,6 +24,7 @@ import org.onosproject.core.ApplicationId;
24 /** 24 /**
25 * Activates an installed application. 25 * Activates an installed application.
26 */ 26 */
27 +@Deprecated
27 @Command(scope = "onos", name = "app-activate", 28 @Command(scope = "onos", name = "app-activate",
28 description = "Activates an installed application") 29 description = "Activates an installed application")
29 public class ApplicationActivateCommand extends AbstractShellCommand { 30 public class ApplicationActivateCommand extends AbstractShellCommand {
......
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 + * Manages application inventory.
26 + */
27 +@Command(scope = "onos", name = "app",
28 + description = "Manages application inventory")
29 +public class ApplicationCommand extends AbstractShellCommand {
30 +
31 + static final String INSTALL = "install";
32 + static final String UNINSTALL = "uninstall";
33 + static final String ACTIVATE = "activate";
34 + static final String DEACTIVATE = "deactivate";
35 +
36 + @Argument(index = 0, name = "command",
37 + description = "Command name (activate|deactivate|uninstall)",
38 + required = true, multiValued = false)
39 + String command = null;
40 +
41 + @Argument(index = 1, name = "name", description = "Application name",
42 + required = true, multiValued = false)
43 + String name = null;
44 +
45 + @Override
46 + protected void execute() {
47 + ApplicationAdminService service = get(ApplicationAdminService.class);
48 + if (command.equals(INSTALL)) {
49 + print("Not supported via CLI yet.");
50 +
51 + } else {
52 + ApplicationId appId = service.getId(name);
53 + if (appId == null) {
54 + print("No such application: %s", name);
55 + return;
56 + }
57 +
58 + if (command.equals(UNINSTALL)) {
59 + service.uninstall(appId);
60 + } else if (command.equals(ACTIVATE)) {
61 + service.activate(appId);
62 + } else if (command.equals(DEACTIVATE)) {
63 + service.deactivate(appId);
64 + }
65 + }
66 + }
67 +
68 +}
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.console.Completer;
19 +import org.apache.karaf.shell.console.completer.StringsCompleter;
20 +
21 +import java.util.List;
22 +import java.util.SortedSet;
23 +
24 +import static org.onosproject.cli.app.ApplicationCommand.*;
25 +
26 +/**
27 + * Application name completer.
28 + */
29 +public class ApplicationCommandCompleter implements Completer {
30 + @Override
31 + public int complete(String buffer, int cursor, List<String> candidates) {
32 + // Delegate string completer
33 + StringsCompleter delegate = new StringsCompleter();
34 + SortedSet<String> strings = delegate.getStrings();
35 + strings.add(INSTALL);
36 + strings.add(UNINSTALL);
37 + strings.add(ACTIVATE);
38 + strings.add(DEACTIVATE);
39 +
40 + // Now let the completer do the work for figuring out what to offer.
41 + return delegate.complete(buffer, cursor, candidates);
42 + }
43 +
44 +}
...@@ -24,6 +24,7 @@ import org.onosproject.core.ApplicationId; ...@@ -24,6 +24,7 @@ import org.onosproject.core.ApplicationId;
24 /** 24 /**
25 * Deactivates an installed application. 25 * Deactivates an installed application.
26 */ 26 */
27 +@Deprecated
27 @Command(scope = "onos", name = "app-deactivate", 28 @Command(scope = "onos", name = "app-deactivate",
28 description = "Deactivates an installed application") 29 description = "Deactivates an installed application")
29 public class ApplicationDeactivateCommand extends AbstractShellCommand { 30 public class ApplicationDeactivateCommand extends AbstractShellCommand {
......
...@@ -24,6 +24,7 @@ import org.onosproject.core.ApplicationId; ...@@ -24,6 +24,7 @@ import org.onosproject.core.ApplicationId;
24 /** 24 /**
25 * Uninstalls an application. 25 * Uninstalls an application.
26 */ 26 */
27 +@Deprecated
27 @Command(scope = "onos", name = "app-uninstall", 28 @Command(scope = "onos", name = "app-uninstall",
28 description = "Uninstalls an application") 29 description = "Uninstalls an application")
29 public class ApplicationUninstallCommand extends AbstractShellCommand { 30 public class ApplicationUninstallCommand extends AbstractShellCommand {
......
...@@ -25,6 +25,16 @@ ...@@ -25,6 +25,16 @@
25 </command> 25 </command>
26 26
27 <command> 27 <command>
28 + <action class="org.onosproject.cli.app.ApplicationCommand"/>
29 + <completers>
30 + <ref component-id="appCommandCompleter"/>
31 + <ref component-id="appNameCompleter"/>
32 + <null/>
33 + </completers>
34 + </command>
35 +
36 + <!--
37 + <command>
28 <action class="org.onosproject.cli.app.ApplicationActivateCommand"/> 38 <action class="org.onosproject.cli.app.ApplicationActivateCommand"/>
29 <completers> 39 <completers>
30 <ref component-id="appNameCompleter"/> 40 <ref component-id="appNameCompleter"/>
...@@ -47,6 +57,7 @@ ...@@ -47,6 +57,7 @@
47 <null/> 57 <null/>
48 </completers> 58 </completers>
49 </command> 59 </command>
60 + -->
50 61
51 <command> 62 <command>
52 <action class="org.onosproject.cli.MetricsListCommand"/> 63 <action class="org.onosproject.cli.MetricsListCommand"/>
...@@ -55,14 +66,14 @@ ...@@ -55,14 +66,14 @@
55 <command> 66 <command>
56 <action class="org.onosproject.cli.NodesListCommand"/> 67 <action class="org.onosproject.cli.NodesListCommand"/>
57 </command> 68 </command>
58 -<!-- 69 + <!--
59 <command> 70 <command>
60 <action class="org.onosproject.cli.NodeAddCommand"/> 71 <action class="org.onosproject.cli.NodeAddCommand"/>
61 </command> 72 </command>
62 <command> 73 <command>
63 <action class="org.onosproject.cli.NodeRemoveCommand"/> 74 <action class="org.onosproject.cli.NodeRemoveCommand"/>
64 </command> 75 </command>
65 ---> 76 + -->
66 77
67 <command> 78 <command>
68 <action class="org.onosproject.cli.RolesCommand"/> 79 <action class="org.onosproject.cli.RolesCommand"/>
...@@ -130,7 +141,7 @@ ...@@ -130,7 +141,7 @@
130 <command> 141 <command>
131 <action class="org.onosproject.cli.net.IntentRemoveCommand"/> 142 <action class="org.onosproject.cli.net.IntentRemoveCommand"/>
132 <completers> 143 <completers>
133 - <ref component-id="appIdNameCompleter" /> 144 + <ref component-id="appIdNameCompleter"/>
134 <ref component-id="intentIdCompleter"/> 145 <ref component-id="intentIdCompleter"/>
135 <null/> 146 <null/>
136 </completers> 147 </completers>
...@@ -165,9 +176,9 @@ ...@@ -165,9 +176,9 @@
165 </command> 176 </command>
166 <command> 177 <command>
167 <action class="org.onosproject.cli.net.GetStatistics"/> 178 <action class="org.onosproject.cli.net.GetStatistics"/>
168 - <completers> 179 + <completers>
169 - <ref component-id="connectPointCompleter"/> 180 + <ref component-id="connectPointCompleter"/>
170 - </completers> 181 + </completers>
171 </command> 182 </command>
172 <command> 183 <command>
173 <action class="org.onosproject.cli.net.AddMultiPointToSinglePointIntentCommand"/> 184 <action class="org.onosproject.cli.net.AddMultiPointToSinglePointIntentCommand"/>
...@@ -272,13 +283,14 @@ ...@@ -272,13 +283,14 @@
272 <action class="org.onosproject.cli.net.WipeOutCommand"/> 283 <action class="org.onosproject.cli.net.WipeOutCommand"/>
273 </command> 284 </command>
274 <command> 285 <command>
275 - <action class="org.onosproject.cli.net.AddMplsIntent" /> 286 + <action class="org.onosproject.cli.net.AddMplsIntent"/>
276 - <completers> 287 + <completers>
277 - <ref component-id="connectPointCompleter" /> 288 + <ref component-id="connectPointCompleter"/>
278 - </completers> 289 + </completers>
279 - </command> 290 + </command>
280 </command-bundle> 291 </command-bundle>
281 292
293 + <bean id="appCommandCompleter" class="org.onosproject.cli.app.ApplicationCommandCompleter"/>
282 <bean id="appNameCompleter" class="org.onosproject.cli.app.ApplicationNameCompleter"/> 294 <bean id="appNameCompleter" class="org.onosproject.cli.app.ApplicationNameCompleter"/>
283 <bean id="appIdNameCompleter" class="org.onosproject.cli.app.ApplicationIdNameCompleter"/> 295 <bean id="appIdNameCompleter" class="org.onosproject.cli.app.ApplicationIdNameCompleter"/>
284 <bean id="nodeIdCompleter" class="org.onosproject.cli.NodeIdCompleter"/> 296 <bean id="nodeIdCompleter" class="org.onosproject.cli.NodeIdCompleter"/>
......