better detail in REST API response when posting ZIP preserves backwards compatibility, adding a detail=true flag which gives richer info. see extended comment in code.
also fixes bug where the added/changed items weren't actually listed, and where it tried to return the full BasicManagedBundle when it just wants an ID. Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/33d9fd63 Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/33d9fd63 Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/33d9fd63 Branch: refs/heads/master Commit: 33d9fd63aae2f7da3b2467bba3e47df8269d5acd Parents: e1b0be1 Author: Alex Heneveld <[email protected]> Authored: Mon Jun 5 13:58:56 2017 +0100 Committer: Alex Heneveld <[email protected]> Committed: Mon Jun 5 14:00:14 2017 +0100 ---------------------------------------------------------------------- .../apache/brooklyn/core/mgmt/ha/OsgiManager.java | 7 +++---- .../org/apache/brooklyn/rest/api/CatalogApi.java | 16 ++++++++++++++-- .../brooklyn/rest/resources/CatalogResource.java | 12 ++++++------ 3 files changed, 23 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/33d9fd63/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java index 69021fe..2f61d16 100644 --- a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java +++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java @@ -372,12 +372,11 @@ public class OsgiManager { // possibly remove that other capability, so that bundles with BOMs _have_ to be installed via this method. // (load order gets confusing with auto-scanning...) public List<? extends CatalogItem<?,?>> loadCatalogBom(Bundle bundle) { - List<? extends CatalogItem<?, ?>> catalogItems = MutableList.of(); - loadCatalogBom(mgmt, bundle, catalogItems); - return catalogItems; + return MutableList.copyOf(loadCatalogBom(mgmt, bundle)); } - private static Iterable<? extends CatalogItem<?, ?>> loadCatalogBom(ManagementContext mgmt, Bundle bundle, Iterable<? extends CatalogItem<?, ?>> catalogItems) { + private static Iterable<? extends CatalogItem<?, ?>> loadCatalogBom(ManagementContext mgmt, Bundle bundle) { + Iterable<? extends CatalogItem<?, ?>> catalogItems = MutableList.of(); if (!BrooklynFeatureEnablement.isEnabled(BrooklynFeatureEnablement.FEATURE_LOAD_BUNDLE_CATALOG_BOM)) { // if the above feature is not enabled, let's do it manually (as a contract of this method) try { http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/33d9fd63/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/CatalogApi.java ---------------------------------------------------------------------- diff --git a/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/CatalogApi.java b/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/CatalogApi.java index 972c2a6..fe2346f 100644 --- a/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/CatalogApi.java +++ b/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/CatalogApi.java @@ -88,13 +88,22 @@ public interface CatalogApi { @Valid String yaml); @Beta + /* TODO the polymorphic return type dependent on 'detail' is ugly, + * but we're stuck in this API because backwards compatibility expects the types map + * whereas typical usage wants more feedback. we should introduce a + * /registry and/or /types and/or /bundles endpoint that always provides details + * (and an approach to handling types more aligned with BrooklynTypeRegistry and OSGi bundling). + * Not too concerned here as this method is beta and the above switch will probably naturally happen soon. + * The main client who cares about this is the Go CLI. */ @POST @Consumes({"application/x-zip", "application/x-jar"}) @ApiOperation( value = "Add a catalog items (e.g. new type of entity, policy or location) by uploading a ZIP/JAR archive.", notes = "Accepts either an OSGi bundle JAR, or ZIP which will be turned into bundle JAR. Bother format must " + "contain a catalog.bom at the root of the archive, which must contain the bundle and version key." - + "Return value is map of ID to CatalogItemSummary.", + + "Return value is map of ID to CatalogItemSummary unless detail=true is passed as a parameter in which " + + "case the return value is a BundleInstallationRestResult map containing the types map in types along " + + "with a message, bundle, and code.", response = String.class, hidden = true) @ApiResponses(value = { @@ -106,7 +115,10 @@ public interface CatalogApi { name = "archive", value = "Bundle to install, in ZIP or JAR format, requiring catalog.bom containing bundle name and version", required = true) - byte[] archive); + byte[] archive, + @ApiParam(name="detail", value="Provide a wrapping details map", required=false) + @QueryParam("detail") @DefaultValue("false") + boolean detail); @Beta @POST http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/33d9fd63/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java ---------------------------------------------------------------------- diff --git a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java index 57c4ead..612e2a0 100644 --- a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java +++ b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java @@ -45,7 +45,6 @@ import org.apache.brooklyn.api.policy.Policy; import org.apache.brooklyn.api.policy.PolicySpec; import org.apache.brooklyn.api.sensor.Enricher; import org.apache.brooklyn.api.sensor.EnricherSpec; -import org.apache.brooklyn.api.typereg.ManagedBundle; import org.apache.brooklyn.api.typereg.RegisteredType; import org.apache.brooklyn.core.catalog.CatalogPredicates; import org.apache.brooklyn.core.catalog.internal.CatalogItemComparator; @@ -130,7 +129,7 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat return createFromYaml(new String(item)); } - return createFromArchive(item); + return createFromArchive(item, false); } @Override @@ -159,7 +158,7 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat // as Osgi result, but without bundle, and with maps of catalog items installed String message; - ManagedBundle metadata; + String bundle; OsgiBundleInstallationResult.ResultCode code; Map<String,Object> types; @@ -172,7 +171,7 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat public static BundleInstallationRestResult of(OsgiBundleInstallationResult in, ManagementContext mgmt, BrooklynRestResourceUtils brooklynU, UriInfo ui) { BundleInstallationRestResult result = new BundleInstallationRestResult(); result.message = in.getMessage(); - result.metadata = in.getMetadata(); + result.bundle = in.getMetadata().getVersionedName().toString(); result.code = in.getCode(); if (in.getCatalogItemsInstalled()!=null) { result.types = MutableMap.of(); @@ -191,7 +190,7 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat @Override @Beta - public Response createFromArchive(byte[] zipInput) { + public Response createFromArchive(byte[] zipInput, boolean detail) { if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.ROOT, null)) { throw WebResourceUtils.forbidden("User '%s' is not authorized to add catalog item", Entitlements.getEntitlementContext().user()); @@ -205,7 +204,8 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat .data(BundleInstallationRestResult.of(result.getWithoutError(), mgmt(), brooklyn(), ui)).build().asJsonResponse(); } - return Response.status(Status.CREATED).entity( BundleInstallationRestResult.of(result.get(), mgmt(), brooklyn(), ui) ).build(); + BundleInstallationRestResult resultR = BundleInstallationRestResult.of(result.get(), mgmt(), brooklyn(), ui); + return Response.status(Status.CREATED).entity( detail ? resultR : resultR.types ).build(); } private Response buildCreateResponse(Iterable<? extends CatalogItem<?, ?>> catalogItems) {
