ONOS-6980 Adding support for download of application bits.
Change-Id: I742950690b50038cac0bb2ad2da4eaac5781da85
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 5916dbf..4db129d 100644
--- a/cli/src/main/java/org/onosproject/cli/app/ApplicationCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/app/ApplicationCommand.java
@@ -15,6 +15,7 @@
*/
package org.onosproject.cli.app;
+import com.google.common.io.ByteStreams;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onosproject.app.ApplicationAdminService;
@@ -38,9 +39,10 @@
static final String UNINSTALL = "uninstall";
static final String ACTIVATE = "activate";
static final String DEACTIVATE = "deactivate";
+ static final String DOWNLOAD = "download";
@Argument(index = 0, name = "command",
- description = "Command name (install|activate|deactivate|uninstall)",
+ description = "Command name (install|activate|deactivate|uninstall|download)",
required = true, multiValued = false)
String command = null;
@@ -58,14 +60,20 @@
}
}
- } else {
+ } else if (command.equals(DOWNLOAD)) {
for (String name : names) {
- if (!manageApp(service, name)) {
+ if (!downloadApp(service, name)) {
return;
}
}
+ } else {
+ for (String name : names) {
+ if (!manageApp(service, name)) {
+ return;
+ }
+ }
+ }
}
- }
// Installs the application from input of the specified URL
private boolean installApp(ApplicationAdminService service, String url) {
@@ -82,6 +90,18 @@
return true;
}
+ // Downloads the application bits to the standard output.
+ private boolean downloadApp(ApplicationAdminService service, String name) {
+ try {
+ ByteStreams.copy(service.getApplicationArchive(service.getId(name)),
+ System.out);
+ } catch (IOException e) {
+ error("Unable to download bits for application %s", name);
+ return false;
+ }
+ return true;
+ }
+
// Manages the specified application.
private boolean manageApp(ApplicationAdminService service, String name) {
ApplicationId appId = service.getId(name);