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
diff --git a/apps/metrics/intent/src/main/java/org/onosproject/metrics/intent/IntentMetrics.java b/apps/metrics/intent/src/main/java/org/onosproject/metrics/intent/IntentMetrics.java
index 237fd17..21878ca 100644
--- a/apps/metrics/intent/src/main/java/org/onosproject/metrics/intent/IntentMetrics.java
+++ b/apps/metrics/intent/src/main/java/org/onosproject/metrics/intent/IntentMetrics.java
@@ -88,8 +88,7 @@
 
     @Activate
     protected void activate() {
-        appId =
-            coreService.registerApplication("org.onosproject.metrics.intent");
+        appId = coreService.registerApplication("org.onosproject.metrics");
 
         clear();
         registerMetrics();
diff --git a/apps/metrics/topology/src/main/java/org/onosproject/metrics/topology/TopologyMetrics.java b/apps/metrics/topology/src/main/java/org/onosproject/metrics/topology/TopologyMetrics.java
index a2f0d5c..ec02c3b 100644
--- a/apps/metrics/topology/src/main/java/org/onosproject/metrics/topology/TopologyMetrics.java
+++ b/apps/metrics/topology/src/main/java/org/onosproject/metrics/topology/TopologyMetrics.java
@@ -108,8 +108,7 @@
 
     @Activate
     protected void activate() {
-        appId =
-            coreService.registerApplication("org.onosproject.metrics.topology");
+        appId = coreService.registerApplication("org.onosproject.metrics");
 
         clear();
         registerMetrics();
diff --git a/cli/src/main/java/org/onosproject/cli/app/ApplicationActivateCommand.java b/cli/src/main/java/org/onosproject/cli/app/ApplicationActivateCommand.java
deleted file mode 100644
index eadaa7d..0000000
--- a/cli/src/main/java/org/onosproject/cli/app/ApplicationActivateCommand.java
+++ /dev/null
@@ -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);
-        }
-    }
-
-}
diff --git a/cli/src/main/java/org/onosproject/cli/app/ApplicationCommand.java b/cli/src/main/java/org/onosproject/cli/app/ApplicationCommand.java
index 4a0a9e0..68a1957 100644
--- a/cli/src/main/java/org/onosproject/cli/app/ApplicationCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/app/ApplicationCommand.java
@@ -38,9 +38,9 @@
             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,20 +49,22 @@
             print("Not supported via CLI yet.");
 
         } else {
-            ApplicationId appId = service.getId(name);
-            if (appId == null) {
-                print("No such application: %s", name);
-                return;
-            }
+            for (String name : names) {
+                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);
-            } else {
-                print("Unsupported command: %s", command);
+                if (command.equals(UNINSTALL)) {
+                    service.uninstall(appId);
+                } else if (command.equals(ACTIVATE)) {
+                    service.activate(appId);
+                } else if (command.equals(DEACTIVATE)) {
+                    service.deactivate(appId);
+                } else {
+                    print("Unsupported command: %s", command);
+                }
             }
         }
     }
diff --git a/cli/src/main/java/org/onosproject/cli/app/ApplicationDeactivateCommand.java b/cli/src/main/java/org/onosproject/cli/app/ApplicationDeactivateCommand.java
deleted file mode 100644
index 3e0195d..0000000
--- a/cli/src/main/java/org/onosproject/cli/app/ApplicationDeactivateCommand.java
+++ /dev/null
@@ -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);
-        }
-    }
-
-}
diff --git a/cli/src/main/java/org/onosproject/cli/app/ApplicationUninstallCommand.java b/cli/src/main/java/org/onosproject/cli/app/ApplicationUninstallCommand.java
deleted file mode 100644
index 2e05c0c..0000000
--- a/cli/src/main/java/org/onosproject/cli/app/ApplicationUninstallCommand.java
+++ /dev/null
@@ -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);
-        }
-    }
-
-}
diff --git a/cli/src/main/java/org/onosproject/cli/app/ApplicationsListCommand.java b/cli/src/main/java/org/onosproject/cli/app/ApplicationsListCommand.java
index 13d5cd8..d9debdb 100644
--- a/cli/src/main/java/org/onosproject/cli/app/ApplicationsListCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/app/ApplicationsListCommand.java
@@ -19,6 +19,7 @@
 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 @@
             "%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,11 +57,14 @@
             print("%s", json(service, apps));
         } else {
             for (Application app : apps) {
-                print(FMT, service.getState(app.id()) == ACTIVE ? "*" : " ",
-                      app.id().id(), app.id().name(), app.version(), app.origin(),
-                      app.description(), app.features(),
-                      app.featuresRepo().isPresent() ? app.featuresRepo().get().toString() : "",
-                      app.permissions());
+                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() : "",
+                          app.permissions());
+                }
             }
         }
     }
@@ -64,7 +73,10 @@
         ObjectMapper mapper = new ObjectMapper();
         ArrayNode result = mapper.createArrayNode();
         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;
     }
diff --git a/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
index 265dcd0..e065d31 100644
--- a/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
+++ b/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -29,7 +29,6 @@
             <completers>
                 <ref component-id="appCommandCompleter"/>
                 <ref component-id="appNameCompleter"/>
-                <null/>
             </completers>
         </command>
 
diff --git a/tools/test/bin/onos-app b/tools/test/bin/onos-app
index 31b87d3..0515e83 100755
--- a/tools/test/bin/onos-app
+++ b/tools/test/bin/onos-app
@@ -15,10 +15,12 @@
     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