You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by ge...@apache.org on 2017/03/27 15:21:27 UTC

[1/4] brooklyn-server git commit: Returns catalog items created via REST API when coming from an archive

Repository: brooklyn-server
Updated Branches:
  refs/heads/master 40d8cfa23 -> a940d4996


Returns catalog items created via REST API when coming from an archive


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/c17ac20b
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/c17ac20b
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/c17ac20b

Branch: refs/heads/master
Commit: c17ac20b3473b99445523225d6b9a09f431425f4
Parents: 40d8cfa
Author: Thomas Bouron <th...@cloudsoftcorp.com>
Authored: Mon Mar 27 12:34:12 2017 +0100
Committer: Thomas Bouron <th...@cloudsoftcorp.com>
Committed: Mon Mar 27 12:34:25 2017 +0100

----------------------------------------------------------------------
 .../rest/resources/CatalogResource.java         | 54 +++++++++++---------
 1 file changed, 30 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c17ac20b/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 ed4885f..8155bf6 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
@@ -146,33 +146,15 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
             throw WebResourceUtils.forbidden("User '%s' is not authorized to add catalog item",
                 Entitlements.getEntitlementContext().user());
         }
-        
-        Iterable<? extends CatalogItem<?, ?>> items; 
+
         try {
-            items = brooklyn().getCatalog().addItems(yaml);
+            final Iterable<? extends CatalogItem<?, ?>> items = brooklyn().getCatalog().addItems(yaml);
+            return buildCreateResponse(items);
         } catch (Exception e) {
             e.printStackTrace();
             Exceptions.propagateIfFatal(e);
             return ApiError.of(e).asBadRequestResponseJson();
         }
-
-        log.info("REST created catalog items: "+items);
-
-        Map<String,Object> result = MutableMap.of();
-        
-        for (CatalogItem<?,?> item: items) {
-            try {
-                result.put(item.getId(), CatalogTransformer.catalogItemSummary(brooklyn(), item, ui.getBaseUriBuilder()));
-            } catch (Throwable t) {
-                log.warn("Error loading catalog item '"+item+"' (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 ("+item.getId()+")", t);
-            }
-        }
-        return Response.status(Status.CREATED).entity(result).build();
     }
 
     @Override
@@ -242,6 +224,8 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
             f2 = bm.copyAddingManifest(f, mf);
             
             Bundle bundle = bm.installBundle(f2, true);
+
+            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)
@@ -251,7 +235,7 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
                     // here to get back the predicate from it.
                     final Predicate<Bundle> applicationsPermitted = Predicates.<Bundle>alwaysTrue();
 
-                    new CatalogBundleLoader(applicationsPermitted, mgmt()).scanForCatalog(bundle);
+                    catalogItems = new CatalogBundleLoader(applicationsPermitted, mgmt()).scanForCatalog(bundle);
                 } catch (RuntimeException ex) {
                     try {
                         bundle.uninstall();
@@ -261,8 +245,10 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
                     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 {
@@ -270,6 +256,26 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
             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);
+            }
+        }
+        return Response.status(Status.CREATED).entity(result).build();
+    }
     
     @SuppressWarnings("deprecation")
     @Override


[3/4] brooklyn-server git commit: Fix integration tests

Posted by ge...@apache.org.
Fix integration tests


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/a4242e91
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/a4242e91
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/a4242e91

Branch: refs/heads/master
Commit: a4242e913eed4c2b0750064c2d5339115b132942
Parents: f1d08ee
Author: Thomas Bouron <th...@cloudsoftcorp.com>
Authored: Mon Mar 27 15:06:18 2017 +0100
Committer: Thomas Bouron <th...@cloudsoftcorp.com>
Committed: Mon Mar 27 15:06:18 2017 +0100

----------------------------------------------------------------------
 .../brooklyn/rest/test/entity/VanillaSoftwareProcessTest.java      | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/a4242e91/rest/rest-server/src/test/java/org/apache/brooklyn/rest/test/entity/VanillaSoftwareProcessTest.java
----------------------------------------------------------------------
diff --git a/rest/rest-server/src/test/java/org/apache/brooklyn/rest/test/entity/VanillaSoftwareProcessTest.java b/rest/rest-server/src/test/java/org/apache/brooklyn/rest/test/entity/VanillaSoftwareProcessTest.java
index 05d63b9..1265aa6 100644
--- a/rest/rest-server/src/test/java/org/apache/brooklyn/rest/test/entity/VanillaSoftwareProcessTest.java
+++ b/rest/rest-server/src/test/java/org/apache/brooklyn/rest/test/entity/VanillaSoftwareProcessTest.java
@@ -81,7 +81,7 @@ public class VanillaSoftwareProcessTest extends BrooklynRestApiLauncherTestFixtu
         // Add catalogue item.
         HttpToolResponse response = node.http().post(
                 "/catalog",
-                ImmutableMap.<String, String>of(),
+                ImmutableMap.<String, String>of("Content-type", "application/yaml"),
                 catalogYaml.getBytes());
         HttpAsserts.assertHealthyStatusCode(response.getResponseCode());
 


[4/4] brooklyn-server git commit: Closes #613

Posted by ge...@apache.org.
Closes #613

Returns catalog items created via REST API when coming from an archive

There is still an issue when the `FEATURE_LOAD_BUNDLE_CATALOG_BOM` is enabled; the REST API won't return the added items as it is currently handled by the `CatalogBomScanner`

But, this feature is disabled by default so we can probably live with that for now


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/a940d499
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/a940d499
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/a940d499

Branch: refs/heads/master
Commit: a940d4996741c017587b10203ee330f07e97a008
Parents: 40d8cfa a4242e9
Author: Geoff Macartney <ge...@cloudsoftcorp.com>
Authored: Mon Mar 27 16:21:17 2017 +0100
Committer: Geoff Macartney <ge...@cloudsoftcorp.com>
Committed: Mon Mar 27 16:21:17 2017 +0100

----------------------------------------------------------------------
 .../rest/resources/CatalogResource.java         | 60 ++++++++++++--------
 .../test/entity/VanillaSoftwareProcessTest.java |  2 +-
 2 files changed, 37 insertions(+), 25 deletions(-)
----------------------------------------------------------------------



[2/4] brooklyn-server git commit: Address comments

Posted by ge...@apache.org.
Address comments


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/f1d08ee9
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/f1d08ee9
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/f1d08ee9

Branch: refs/heads/master
Commit: f1d08ee96b07105828c228774a6b5a38ec7479ee
Parents: c17ac20
Author: Thomas Bouron <th...@cloudsoftcorp.com>
Authored: Mon Mar 27 13:22:26 2017 +0100
Committer: Thomas Bouron <th...@cloudsoftcorp.com>
Committed: Mon Mar 27 13:22:26 2017 +0100

----------------------------------------------------------------------
 .../apache/brooklyn/rest/resources/CatalogResource.java | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f1d08ee9/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 8155bf6..05cee90 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
@@ -246,8 +246,12 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
                 }
             }
 
-            // 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.
+            // TODO improve on this - Currently, the added items are returned ONLY if the FEATURE_LOAD_BUNDLE_CATALOG_BOM
+            // is disabled. When enabled, the above code is not executed and the catalog items addition is delegated
+            // to the CatalogBomScanner. The REST API will therefore not know what are the added catalog items and won't
+            // return them.
+            // One way to improved this would be couple agoin the CatalogBomScanner with the CatalogBundleLoader to
+            // retrieve the list of added catalog items per bundle.
             return buildCreateResponse(catalogItems);
         } catch (RuntimeException ex) {
             throw WebResourceUtils.badRequest(ex);
@@ -264,7 +268,9 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
 
         for (CatalogItem<?,?> catalogItem: catalogItems) {
             try {
-                result.put(catalogItem.getId(), CatalogTransformer.catalogItemSummary(brooklyn(), catalogItem, ui.getBaseUriBuilder()));
+                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,