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;
/**
* Activates an installed application.
*/
@Deprecated
@Command(scope = "onos", name = "app-activate",
description = "Activates an installed application")
public class ApplicationActivateCommand extends AbstractShellCommand {
......
/*
* 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;
/**
* Manages application inventory.
*/
@Command(scope = "onos", name = "app",
description = "Manages application inventory")
public class ApplicationCommand extends AbstractShellCommand {
static final String INSTALL = "install";
static final String UNINSTALL = "uninstall";
static final String ACTIVATE = "activate";
static final String DEACTIVATE = "deactivate";
@Argument(index = 0, name = "command",
description = "Command name (activate|deactivate|uninstall)",
required = true, multiValued = false)
String command = null;
@Argument(index = 1, name = "name", description = "Application name",
required = true, multiValued = false)
String name = null;
@Override
protected void execute() {
ApplicationAdminService service = get(ApplicationAdminService.class);
if (command.equals(INSTALL)) {
print("Not supported via CLI yet.");
} else {
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);
}
}
}
}
/*
* 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.console.Completer;
import org.apache.karaf.shell.console.completer.StringsCompleter;
import java.util.List;
import java.util.SortedSet;
import static org.onosproject.cli.app.ApplicationCommand.*;
/**
* Application name completer.
*/
public class ApplicationCommandCompleter implements Completer {
@Override
public int complete(String buffer, int cursor, List<String> candidates) {
// Delegate string completer
StringsCompleter delegate = new StringsCompleter();
SortedSet<String> strings = delegate.getStrings();
strings.add(INSTALL);
strings.add(UNINSTALL);
strings.add(ACTIVATE);
strings.add(DEACTIVATE);
// Now let the completer do the work for figuring out what to offer.
return delegate.complete(buffer, cursor, candidates);
}
}
......@@ -24,6 +24,7 @@ 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 {
......
......@@ -24,6 +24,7 @@ import org.onosproject.core.ApplicationId;
/**
* Uninstalls an application.
*/
@Deprecated
@Command(scope = "onos", name = "app-uninstall",
description = "Uninstalls an application")
public class ApplicationUninstallCommand extends AbstractShellCommand {
......
......@@ -25,6 +25,16 @@
</command>
<command>
<action class="org.onosproject.cli.app.ApplicationCommand"/>
<completers>
<ref component-id="appCommandCompleter"/>
<ref component-id="appNameCompleter"/>
<null/>
</completers>
</command>
<!--
<command>
<action class="org.onosproject.cli.app.ApplicationActivateCommand"/>
<completers>
<ref component-id="appNameCompleter"/>
......@@ -47,6 +57,7 @@
<null/>
</completers>
</command>
-->
<command>
<action class="org.onosproject.cli.MetricsListCommand"/>
......@@ -55,14 +66,14 @@
<command>
<action class="org.onosproject.cli.NodesListCommand"/>
</command>
<!--
<!--
<command>
<action class="org.onosproject.cli.NodeAddCommand"/>
</command>
<command>
<action class="org.onosproject.cli.NodeRemoveCommand"/>
</command>
-->
-->
<command>
<action class="org.onosproject.cli.RolesCommand"/>
......@@ -130,7 +141,7 @@
<command>
<action class="org.onosproject.cli.net.IntentRemoveCommand"/>
<completers>
<ref component-id="appIdNameCompleter" />
<ref component-id="appIdNameCompleter"/>
<ref component-id="intentIdCompleter"/>
<null/>
</completers>
......@@ -272,13 +283,14 @@
<action class="org.onosproject.cli.net.WipeOutCommand"/>
</command>
<command>
<action class="org.onosproject.cli.net.AddMplsIntent" />
<action class="org.onosproject.cli.net.AddMplsIntent"/>
<completers>
<ref component-id="connectPointCompleter" />
<ref component-id="connectPointCompleter"/>
</completers>
</command>
</command-bundle>
<bean id="appCommandCompleter" class="org.onosproject.cli.app.ApplicationCommandCompleter"/>
<bean id="appNameCompleter" class="org.onosproject.cli.app.ApplicationNameCompleter"/>
<bean id="appIdNameCompleter" class="org.onosproject.cli.app.ApplicationIdNameCompleter"/>
<bean id="nodeIdCompleter" class="org.onosproject.cli.NodeIdCompleter"/>
......