brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From geomacy <>
Subject [GitHub] brooklyn-server pull request #613: Returns catalog items created via REST AP...
Date Mon, 27 Mar 2017 12:04:27 GMT
Github user geomacy commented on a diff in the pull request:
    --- Diff: rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/
    @@ -261,15 +245,37 @@ public Response createFromArchive(byte[] zipInput) {
                         throw new IllegalArgumentException("Error installing catalog items",
    -            return Response.status(Status.CREATED).build();
    +            // TODO improve on this - If the FEATURE_LOAD_BUNDLE_CATALOG_BOM is enabled,
the REST API won't return the
    +            // added items which breaks the contract on the API endpoint.
    +            return buildCreateResponse(catalogItems);
             } catch (RuntimeException ex) {
                 throw WebResourceUtils.badRequest(ex);
             } finally {
                 if (f!=null) f.delete();
                 if (f2!=null) f2.delete();
    +    private Response buildCreateResponse(Iterable<? extends CatalogItem<?, ?>>
catalogItems) {
    +"REST created catalog items: "+catalogItems);
    +        Map<String,Object> result = MutableMap.of();
    +        for (CatalogItem<?,?> catalogItem: catalogItems) {
    +            try {
    +                result.put(catalogItem.getId(), CatalogTransformer.catalogItemSummary(brooklyn(),
catalogItem, ui.getBaseUriBuilder()));
    +            } catch (Throwable t) {
    +                log.warn("Error loading catalog item '"+catalogItem+"' (rethrowing):
    +                // unfortunately items are already added to the catalog and hard to remove,
    +                // but at least let the user know;
    +                // happens eg if a class refers to a missing class, like
    +                // loading nosql items including mongo without the mongo bson class on
the classpath
    +                throw Exceptions.propagateAnnotated("At least one unusable item was added
("+catalogItem.getId()+")", t);
    --- End diff --
    I suggest you collect the exception in here rather than throwing it - 
    - let the loop run through all items, collect any failures that occur
    - if there are any failures, loop through the catalog items that _were_ added and remove
them again, before
    - create a failure response with the details of each item that could not be added.
    Having said that, I'm not sure there's much that really can go wrong above, as this is
just creating the summary objects.  It would be good to apply the logic above to the `CatalogItemLoader.scanForCatalog`,
but I don't think that is within the scope of this PR.

If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at or file a JIRA ticket
with INFRA.

View raw message