This is an automated email from the ASF dual-hosted git repository.
heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git
The following commit(s) were added to refs/heads/master by this push:
new 5def613 Add support for downloading bundle as ZIP files
new d1ba3f2 This closes #1131
5def613 is described below
commit 5def61300dc9cecf7d853f8c5a134bd6001c997a
Author: Thomas Bouron <[email protected]>
AuthorDate: Wed Dec 2 16:40:49 2020 +0000
Add support for downloading bundle as ZIP files
---
.../org/apache/brooklyn/rest/api/BundleApi.java | 10 ++++++++++
.../brooklyn/rest/resources/BundleResource.java | 22 ++++++++++++++++++++--
2 files changed, 30 insertions(+), 2 deletions(-)
diff --git
a/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/BundleApi.java
b/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/BundleApi.java
index 33fa6f5..8f692a2 100644
--- a/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/BundleApi.java
+++ b/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/BundleApi.java
@@ -90,6 +90,16 @@ public interface BundleApi {
@PathParam("version")
String version);
+ @Path("/{symbolicName}/{version}/download")
+ @GET
+ @ApiOperation(value = "Download a ZIP archive of a specific bundle given
its symbolic name and version")
+ public Response download(
+ @ApiParam(name = "symbolicName", value = "Bundle name to query",
required = true)
+ @PathParam("symbolicName")
+ String symbolicName,
+ @ApiParam(name = "version", value = "Version to query", required =
true)
+ @PathParam("version")
+ String version);
@Path("/{symbolicName}/{version}/types")
@GET
diff --git
a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/BundleResource.java
b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/BundleResource.java
index b2dd7d8..421e769 100644
---
a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/BundleResource.java
+++
b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/BundleResource.java
@@ -18,7 +18,8 @@
*/
package org.apache.brooklyn.rest.resources;
-import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
@@ -53,6 +54,7 @@ import org.apache.brooklyn.util.osgi.VersionedName;
import org.apache.brooklyn.util.osgi.VersionedName.VersionedNameComparator;
import org.apache.brooklyn.util.stream.InputStreamSource;
import org.apache.brooklyn.util.text.Strings;
+import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -118,7 +120,23 @@ public class BundleResource extends
AbstractBrooklynRestResource implements Bund
}
return b;
}
-
+
+ public Response download(String symbolicName, String version) {
+ ManagedBundle managedBundle = lookup(symbolicName, version);
+ File bundleFile = ((ManagementContextInternal)
mgmt()).getOsgiManager().get().getBundleFile(managedBundle);
+ if (bundleFile == null || !bundleFile.exists()) {
+ throw WebResourceUtils.notFound("Bundle with id '%s:%s' doesn't
have a ZIP archive found", symbolicName, version);
+ }
+
+ try {
+ return Response
+ .ok(FileUtils.readFileToByteArray(bundleFile),
"application/zip")
+ .header("Content-Disposition", "attachment; filename=" +
symbolicName + "-" + version + ".zip")
+ .build();
+ } catch (IOException e) {
+ throw WebResourceUtils.serverError("Cannot read the ZIP archive
for bundle '%s:%s'", symbolicName, version);
+ }
+ }
@Override
public List<TypeSummary> getTypes(String symbolicName, String version) {