brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tbouron <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #613: Returns catalog items created via REST AP...
Date Mon, 27 Mar 2017 12:16:16 GMT
Github user tbouron commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/613#discussion_r108153810
  
    --- Diff: rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java
---
    @@ -261,15 +245,37 @@ public Response createFromArchive(byte[] zipInput) {
                         throw new IllegalArgumentException("Error installing catalog items",
ex);
                     }
                 }
    -            
    -            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) {
    +        log.info("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):
"+t);
    +                // 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 --
    
    @geomacy I move this code from the `createFromYaml` function, agree that it could be refactored
but It is not in the scope of this PR. I would leave it for future improvement


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message