You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2023/06/01 10:52:03 UTC

[brooklyn-server] branch master updated (f1a7df85da -> 915f079ff6)

This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git


    from f1a7df85da more cautious convertShallow object references
     new 41d5d32873 more resilient catching of freemarker exception when creating classes
     new 915f079ff6 allow blueprint viewer tests to indicate they don't want to rebind

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../core/internal/BrooklynPropertiesImpl.java      |  2 +-
 .../brooklyn/util/core/text/TemplateProcessor.java | 46 ++++++++++++++--------
 .../launcher/blueprints/AbstractBlueprintTest.java | 17 +++++---
 ...Test.java => SimpleBlueprintNonRebindTest.java} | 10 ++---
 .../launcher/blueprints/SimpleBlueprintTest.java   |  2 +-
 5 files changed, 48 insertions(+), 29 deletions(-)
 copy launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/{SimpleBlueprintTest.java => SimpleBlueprintNonRebindTest.java} (85%)


[brooklyn-server] 02/02: allow blueprint viewer tests to indicate they don't want to rebind

Posted by he...@apache.org.
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

commit 915f079ff6f203e8cbb6e177f5494d75c8c49463
Author: Alex Heneveld <al...@cloudsoft.io>
AuthorDate: Thu Jun 1 09:44:45 2023 +0100

    allow blueprint viewer tests to indicate they don't want to rebind
---
 .../brooklyn/core/internal/BrooklynPropertiesImpl.java  |  2 +-
 .../launcher/blueprints/AbstractBlueprintTest.java      | 17 ++++++++++++-----
 ...printTest.java => SimpleBlueprintNonRebindTest.java} | 10 ++++------
 .../launcher/blueprints/SimpleBlueprintTest.java        |  2 +-
 4 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/core/src/main/java/org/apache/brooklyn/core/internal/BrooklynPropertiesImpl.java b/core/src/main/java/org/apache/brooklyn/core/internal/BrooklynPropertiesImpl.java
index b7b7483b31..026c8c0fc0 100644
--- a/core/src/main/java/org/apache/brooklyn/core/internal/BrooklynPropertiesImpl.java
+++ b/core/src/main/java/org/apache/brooklyn/core/internal/BrooklynPropertiesImpl.java
@@ -252,7 +252,7 @@ public class BrooklynPropertiesImpl implements BrooklynProperties {
     @Override
     @SuppressWarnings("unchecked")
     public BrooklynPropertiesImpl addFrom(Map map) {
-        putAll(Maps.transformValues(map, StringFunctions.trim()));
+        putAll(Maps.transformValues(map, x -> x instanceof String ? ((String)x).trim() : x));
         return this;
     }
 
diff --git a/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/AbstractBlueprintTest.java b/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/AbstractBlueprintTest.java
index c5bf51cf04..619645583a 100644
--- a/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/AbstractBlueprintTest.java
+++ b/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/AbstractBlueprintTest.java
@@ -73,6 +73,7 @@ import org.testng.annotations.BeforeMethod;
 import com.google.common.base.Predicate;
 import com.google.common.base.Predicates;
 
+/** Ancestor for blueprint tests which can easily allow rebind (default true) and a REST API attached (default false). */
 public abstract class AbstractBlueprintTest {
 
     private static final Logger LOG = LoggerFactory.getLogger(AbstractBlueprintTest.class);
@@ -92,7 +93,9 @@ public abstract class AbstractBlueprintTest {
         // required for REST access - otherwise it is viewed as not yet ready
         ((RebindManagerImpl)mgmt.getRebindManager()).setAwaitingInitialRebind(false);
 
-        LOG.info("Test "+getClass()+" persisting to "+mementoDir);
+        if (isRebindEnabled()) {
+            LOG.info("Test " + getClass() + " persisting to " + mementoDir);
+        }
 
         startViewer(true);
 
@@ -212,9 +215,11 @@ public abstract class AbstractBlueprintTest {
 
     protected Application runTest(Application app, Consumer<Application> check) throws Exception {
         check.accept(app);
-        
-        Application newApp = rebind();
-        check.accept(newApp);
+
+        if (isRebindEnabled()) {
+            Application newApp = rebind();
+            check.accept(newApp);
+        }
 
         return app;
     }
@@ -334,7 +339,9 @@ public abstract class AbstractBlueprintTest {
         if (isRebindEnabled()) {
             return decorateManagementContext(createBuilderForRebindingManagementContext().buildStarted());
         } else {
-            return decorateManagementContext(LocalManagementContextForTests.newInstance());
+            LocalManagementContext mgmt = LocalManagementContextForTests.newInstance();
+            mgmt.getHighAvailabilityManager().disabled(false);
+            return decorateManagementContext(mgmt);
         }
     }
 
diff --git a/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/SimpleBlueprintTest.java b/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/SimpleBlueprintNonRebindTest.java
similarity index 85%
copy from launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/SimpleBlueprintTest.java
copy to launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/SimpleBlueprintNonRebindTest.java
index b1d3f75187..f234cfaa7b 100644
--- a/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/SimpleBlueprintTest.java
+++ b/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/SimpleBlueprintNonRebindTest.java
@@ -23,21 +23,19 @@ import org.apache.brooklyn.core.entity.Dumper;
 import org.apache.brooklyn.entity.stock.BasicEntity;
 import org.testng.annotations.Test;
 
-public class SimpleBlueprintTest extends AbstractBlueprintTest {
+public class SimpleBlueprintNonRebindTest extends AbstractBlueprintTest {
 
     @Override
     protected boolean isViewerEnabled() {
         return true;
     }
 
-    @Override
-    protected boolean isUsingNewViewerForRebind() {
-        return true;
+    protected boolean isRebindEnabled() {
+        return false;
     }
 
-    // only Live because it starts a server
     @Test(groups={"Live"})
-    public void testBasicEntity() throws Exception {
+    public void testBasicEntityNonRebind() throws Exception {
         Application app = runTestOnBlueprint("services: [ { type: " + BasicEntity.class.getName() + " } ]");
 
         // stick a breakpoint on the following line (make sure it is thread-only, not all-threads!)
diff --git a/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/SimpleBlueprintTest.java b/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/SimpleBlueprintTest.java
index b1d3f75187..7adcc91d5b 100644
--- a/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/SimpleBlueprintTest.java
+++ b/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/SimpleBlueprintTest.java
@@ -23,6 +23,7 @@ import org.apache.brooklyn.core.entity.Dumper;
 import org.apache.brooklyn.entity.stock.BasicEntity;
 import org.testng.annotations.Test;
 
+/** This does rebind. See SimpleBlueprintNonRebindTest for an example with rebind disabled. */
 public class SimpleBlueprintTest extends AbstractBlueprintTest {
 
     @Override
@@ -35,7 +36,6 @@ public class SimpleBlueprintTest extends AbstractBlueprintTest {
         return true;
     }
 
-    // only Live because it starts a server
     @Test(groups={"Live"})
     public void testBasicEntity() throws Exception {
         Application app = runTestOnBlueprint("services: [ { type: " + BasicEntity.class.getName() + " } ]");


[brooklyn-server] 01/02: more resilient catching of freemarker exception when creating classes

Posted by he...@apache.org.
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

commit 41d5d32873d49dbcef10af71050b5120b4a4ab4c
Author: Alex Heneveld <al...@cloudsoft.io>
AuthorDate: Tue May 30 12:29:24 2023 +0100

    more resilient catching of freemarker exception when creating classes
---
 .../brooklyn/util/core/text/TemplateProcessor.java | 46 ++++++++++++++--------
 1 file changed, 30 insertions(+), 16 deletions(-)

diff --git a/core/src/main/java/org/apache/brooklyn/util/core/text/TemplateProcessor.java b/core/src/main/java/org/apache/brooklyn/util/core/text/TemplateProcessor.java
index d6f848eb49..815a9642c7 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/text/TemplateProcessor.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/text/TemplateProcessor.java
@@ -180,8 +180,37 @@ public class TemplateProcessor {
             return super.wrap(objOrig);
         }
 
+        static final ThreadLocal<Boolean> handleUnknownTypeLoopPrevention = new ThreadLocal<>();
+
         @Override
         protected TemplateModel handleUnknownType(final Object o) throws TemplateModelException {
+            if (handleUnknownTypeLoopPrevention.get()!=null) {
+                return super.handleUnknownType(o);
+            }
+            try {
+                handleUnknownTypeLoopPrevention.set(true);
+                // can get "Class inrospection data lookup aborded" from freemarker ClassIntrospector:250
+                // if thread is interrupted because class lookup uses wait on a shared cache;
+                // if the "interruption" is because of us, retry in this instance
+                while (true) {
+                    try {
+                        return handleUnknownTypeReal(o);
+                    } catch (Exception e) {
+                        if (WorkflowExpressionResolution.isInterruptSetToPreventWaiting()) {
+                            if (Exceptions.isRootCauseIsInterruption(e) || e.toString().contains(InterruptedException.class.getSimpleName())) {
+                                Thread.yield();
+                                continue;
+                            }
+                        }
+                        throw e;
+                    }
+                }
+            } finally {
+                handleUnknownTypeLoopPrevention.remove();
+            }
+        }
+
+        protected TemplateModel handleUnknownTypeReal(final Object o) throws TemplateModelException {
             if (o instanceof EntityInternal) return EntityAndMapTemplateModel.forEntity((EntityInternal)o, null);
             if (o instanceof Location) return LocationAndMapTemplateModel.forLocation((LocationInternal)o, null);
 
@@ -193,22 +222,7 @@ public class TemplateProcessor {
                 // deproxy to reduce freemarker introspection interrupted errors
                 o = Entities.deproxy((BrooklynObject) o);
             }
-            // can get "Class inrospection data lookup aborded" from freemarker ClassIntrospector:250
-            // if thread is interrupted because class lookup uses wait on a shared cache;
-            // if the "interruption" is because of us, retry in this instance
-            while (true) {
-                try {
-                    return super.handleUnknownType(o);
-                } catch (Exception e) {
-                    if (WorkflowExpressionResolution.isInterruptSetToPreventWaiting()) {
-                        if (Exceptions.isRootCauseIsInterruption(e) || e.toString().contains(InterruptedException.class.getSimpleName())) {
-                            Thread.yield();
-                            continue;
-                        }
-                    }
-                    throw e;
-                }
-            }
+            return handleUnknownType(o);
         }
 
     }