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/23 20:20:38 UTC

[brooklyn-server] branch master updated (cc86e2f4dd -> 8fe9c4fc1b)

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 cc86e2f4dd transform syntax improved
     new 11afb17084 fix for NPE when condition gets a Maybe containing null, and disallow that for entity coercion
     new 0003ba4b04 cache service lookup results
     new 8fe9c4fc1b don't warn if an active task deletes itself

The 3 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:
 .../brooklyn/api/framework/FrameworkLookup.java    | 39 ++++++++++--
 .../camp/brooklyn/WorkflowExpressionsYamlTest.java | 69 +++++++++++++++++++++-
 .../apache/brooklyn/core/mgmt/ha/OsgiManager.java  |  5 ++
 .../core/resolve/jackson/BeanWithTypeUtils.java    |  2 +-
 .../resolve/jackson/CommonTypesSerialization.java  |  2 +-
 .../core/workflow/steps/CustomWorkflowStep.java    |  1 +
 .../brooklyn/util/core/flags/TypeCoercions.java    |  5 ++
 .../util/core/predicates/DslPredicates.java        |  2 +-
 .../util/core/task/BasicExecutionManager.java      | 12 ++--
 .../brooklyn/core/workflow/WorkflowBasicTest.java  |  2 +-
 .../brooklyn/launcher/osgi/OsgiLauncherImpl.java   |  3 +
 .../javalang/coerce/TypeCoercerExtensible.java     | 10 +++-
 12 files changed, 134 insertions(+), 18 deletions(-)


[brooklyn-server] 01/03: fix for NPE when condition gets a Maybe containing null, and disallow that for entity coercion

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 11afb170840fb028ca9c383629e0d1208c858d31
Author: Alex Heneveld <al...@cloudsoft.io>
AuthorDate: Wed Jun 21 15:22:22 2023 +0100

    fix for NPE when condition gets a Maybe containing null, and disallow that for entity coercion
    
    slightly stricter and better logging for entities and other things that become null on failed deserialization, rather than throwing
---
 .../camp/brooklyn/WorkflowExpressionsYamlTest.java | 69 +++++++++++++++++++++-
 .../core/resolve/jackson/BeanWithTypeUtils.java    |  2 +-
 .../resolve/jackson/CommonTypesSerialization.java  |  2 +-
 .../brooklyn/util/core/flags/TypeCoercions.java    |  5 ++
 .../util/core/predicates/DslPredicates.java        |  2 +-
 .../brooklyn/core/workflow/WorkflowBasicTest.java  |  2 +-
 .../javalang/coerce/TypeCoercerExtensible.java     | 10 +++-
 7 files changed, 84 insertions(+), 8 deletions(-)

diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/WorkflowExpressionsYamlTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/WorkflowExpressionsYamlTest.java
index cd21a00522..d0fb7d02e2 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/WorkflowExpressionsYamlTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/WorkflowExpressionsYamlTest.java
@@ -19,18 +19,29 @@
 package org.apache.brooklyn.camp.brooklyn;
 
 import com.google.common.collect.Iterables;
+import com.google.common.reflect.TypeToken;
 import org.apache.brooklyn.api.effector.Effector;
 import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.mgmt.Task;
 import org.apache.brooklyn.core.config.ConfigKeys;
+import org.apache.brooklyn.core.entity.Entities;
+import org.apache.brooklyn.core.entity.EntityInternal;
+import org.apache.brooklyn.core.resolve.jackson.BeanWithTypeUtils;
 import org.apache.brooklyn.core.sensor.Sensors;
 import org.apache.brooklyn.core.workflow.WorkflowBasicTest;
 import org.apache.brooklyn.core.workflow.WorkflowExecutionContext;
 import org.apache.brooklyn.core.workflow.steps.flow.LogWorkflowStep;
+import org.apache.brooklyn.entity.stock.BasicApplication;
 import org.apache.brooklyn.entity.stock.BasicEntity;
+import org.apache.brooklyn.entity.stock.BasicEntityImpl;
 import org.apache.brooklyn.test.Asserts;
 import org.apache.brooklyn.test.ClassLogWatcher;
+import org.apache.brooklyn.util.core.flags.TypeCoercions;
+import org.apache.brooklyn.util.core.internal.TypeCoercionsTest;
+import org.apache.brooklyn.util.core.task.Tasks;
 import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.apache.brooklyn.util.guava.Maybe;
 import org.apache.brooklyn.util.text.Secret;
 import org.apache.brooklyn.util.text.Strings;
 import org.apache.brooklyn.util.time.Duration;
@@ -39,6 +50,7 @@ import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import java.util.concurrent.Callable;
+import java.util.function.Function;
 
 public class WorkflowExpressionsYamlTest extends AbstractYamlTest {
 
@@ -93,9 +105,13 @@ public class WorkflowExpressionsYamlTest extends AbstractYamlTest {
         return WorkflowBasicTest.runWorkflow(lastEntity, Strings.lines(workflowDefinition), "custom");
     }
 
-    private Object invokeWorkflowOnLastEntity(String ...workflowDefinition) throws Exception {
-        WorkflowExecutionContext context = invocationWorkflowOnLastEntity(workflowDefinition);
-        return context.getTask(false).get().get(Duration.seconds(5));
+    private Object invokeWorkflowOnLastEntity(String ...workflowDefinition) {
+        try {
+            WorkflowExecutionContext context = invocationWorkflowOnLastEntity(workflowDefinition);
+            return context.getTask(false).get().get(Duration.seconds(5));
+        } catch (Exception e) {
+            throw Exceptions.propagate(e);
+        }
     }
 
     Entity waitForLastEntity() {
@@ -225,4 +241,51 @@ public class WorkflowExpressionsYamlTest extends AbstractYamlTest {
         Asserts.assertEquals(invokeWorkflowStepsWithLogging(), "53cr37");
     }
 
+
+    @Test
+    public void testEntityConditionSucceeds() throws Exception {
+        createEntityWithWorkflowEffector("- return ignored");
+        Function<String,Object> test = equalsCheckTarget -> invokeWorkflowOnLastEntity(
+                "steps:\n" +
+                        "  - let ent = $brooklyn:self()\n" +
+                        "  - let root = $brooklyn:root()\n" +
+                        "  - transform checkTargetS = "+equalsCheckTarget+" | to_string\n" +
+                        "  - log comparing ${ent.id} with ${checkTargetS}\n" +
+                        "  - step: return condition met\n" +
+                        "    condition:\n" +
+                        "      target: ${ent}\n" +
+                        "      equals: "+equalsCheckTarget+"\n" +
+                        "  - step: return condition not met");
+
+        Asserts.assertEquals(test.apply("xxx"), "condition not met");
+        Asserts.assertEquals(test.apply("${root}"), "condition not met");
+        Asserts.assertEquals(test.apply("${root.children[0]}"), "condition met");
+
+
+        // checking equality to the ID does not work
+        // it could, fairly easily -- the ID *is* coerced to an entity;
+        // but it then fails because it is coerced to the _proxy_ which is *not* coerced to the real delegate
+        Asserts.assertEquals(test.apply("${ent.id}"), "condition not met");
+
+        // notes and minor tests on the above
+        // coercion of ID
+        Entity coercedFromId = Entities.submit(lastEntity, Tasks.of("test", () -> TypeCoercions.coerce(lastEntity.getId(), Entity.class))).get();
+        Asserts.assertEquals(coercedFromId, lastEntity);
+        Maybe<BasicEntityImpl> coercedFromIdProxyToConcreteFails = Entities.submit(lastEntity, Tasks.of("test", () -> TypeCoercions.tryCoerce(lastEntity.getId(), BasicEntityImpl.class))).get();
+        Asserts.assertThat(coercedFromIdProxyToConcreteFails, Maybe::isAbsent);
+        // under the covers above works using coercer 80-bean, which does
+        Entity coercedFromIdEntity = BeanWithTypeUtils.convert(mgmt(), lastEntity.getId(), TypeToken.of(Entity.class), true, null, true);
+        Asserts.assertEquals(coercedFromIdEntity, lastEntity);
+
+        // some extra checks for coercion of unknown IDs -- conversion returns null, but tryConvert and coerce will not accept that
+        Entity coercedFromMissingIdRaw = BeanWithTypeUtils.convert(mgmt(), "xxx", TypeToken.of(Entity.class), true, null, true);
+        Asserts.assertNull(coercedFromMissingIdRaw);
+
+        Maybe<Entity> coercedFromMissingId;
+        coercedFromMissingId = BeanWithTypeUtils.tryConvertOrAbsent(mgmt(), Maybe.of("xxx"), TypeToken.of(Entity.class), true, null, true);
+        Asserts.assertThat(coercedFromMissingId, Maybe::isAbsent);
+
+        coercedFromMissingId = Entities.submit(lastEntity, Tasks.of("test", () -> TypeCoercions.tryCoerce("does_not_exist", Entity.class))).get();
+        Asserts.assertThat(coercedFromMissingId, Maybe::isAbsent);
+    }
 }
diff --git a/core/src/main/java/org/apache/brooklyn/core/resolve/jackson/BeanWithTypeUtils.java b/core/src/main/java/org/apache/brooklyn/core/resolve/jackson/BeanWithTypeUtils.java
index 91835f23ee..9b2a6dde2b 100644
--- a/core/src/main/java/org/apache/brooklyn/core/resolve/jackson/BeanWithTypeUtils.java
+++ b/core/src/main/java/org/apache/brooklyn/core/resolve/jackson/BeanWithTypeUtils.java
@@ -270,7 +270,7 @@ public class BeanWithTypeUtils {
         }
 
         try {
-            return Maybe.of(convert(mgmt, o, type, allowRegisteredTypes, loader, allowJavaTypes));
+            return Maybe.ofDisallowingNull(convert(mgmt, o, type, allowRegisteredTypes, loader, allowJavaTypes));
         } catch (Exception e) {
             if (fallback!=null) return fallback;
             return Maybe.absent("BeanWithType cannot convert given input "+o+" to "+type, e);
diff --git a/core/src/main/java/org/apache/brooklyn/core/resolve/jackson/CommonTypesSerialization.java b/core/src/main/java/org/apache/brooklyn/core/resolve/jackson/CommonTypesSerialization.java
index 53b7e4bc53..fb5e553bec 100644
--- a/core/src/main/java/org/apache/brooklyn/core/resolve/jackson/CommonTypesSerialization.java
+++ b/core/src/main/java/org/apache/brooklyn/core/resolve/jackson/CommonTypesSerialization.java
@@ -443,7 +443,7 @@ public class CommonTypesSerialization {
                     return super.convertStringToObject(value, p, ctxt);
                 } catch (Exception e) {
                     Exceptions.propagateIfFatal(e);
-                    LOG.warn("Reference to BrooklynObject "+value+" which is no longer available; replacing with 'null'");
+                    LOG.warn("Reference to BrooklynObject "+value+" which is unknown or no longer available; replacing with 'null'");
                     return null;
                 }
             }
diff --git a/core/src/main/java/org/apache/brooklyn/util/core/flags/TypeCoercions.java b/core/src/main/java/org/apache/brooklyn/util/core/flags/TypeCoercions.java
index ed2e66f165..815363e270 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/flags/TypeCoercions.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/flags/TypeCoercions.java
@@ -367,6 +367,11 @@ public class TypeCoercions {
                     if (BeanWithTypeUtils.isConversionRecommended(Maybe.of(input), type)) {
                         try {
                             Maybe<T> result = BeanWithTypeUtils.tryConvertOrAbsentUsingContext(Maybe.of(input), type);
+                            if (result.isPresent() && result.get()==null) {
+                                // normal for entities that are unknown; but when coercing we should not allow that
+                                log.debug("Coercion of "+input+" to "+type+" returned null");
+                                return null;
+                            }
                             return result;
                         } catch (Exception e) {
                             return Maybe.absent(e);
diff --git a/core/src/main/java/org/apache/brooklyn/util/core/predicates/DslPredicates.java b/core/src/main/java/org/apache/brooklyn/util/core/predicates/DslPredicates.java
index f3d6673095..8dc29b47e3 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/predicates/DslPredicates.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/predicates/DslPredicates.java
@@ -164,7 +164,7 @@ public class DslPredicates {
                 Maybe<? extends Object> mma = TypeCoercions.tryCoerce(ma, mb.getClass());
                 if (mma.isPresent()) {
                     // repeat equality check
-                    if (mma.get().equals(mb) || mb.equals(mma.get())) return Maybe.of(true);
+                    if (Objects.equals(mma.get(), mb) || Objects.equals(mb, mma.get())) return Maybe.of(true);
                 }
                 return Maybe.absent("coercion not supported in equality check, to "+mb.getClass());
             }
diff --git a/core/src/test/java/org/apache/brooklyn/core/workflow/WorkflowBasicTest.java b/core/src/test/java/org/apache/brooklyn/core/workflow/WorkflowBasicTest.java
index e8da1bf0de..098e0c23a2 100644
--- a/core/src/test/java/org/apache/brooklyn/core/workflow/WorkflowBasicTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/workflow/WorkflowBasicTest.java
@@ -478,5 +478,5 @@ public class WorkflowBasicTest extends BrooklynMgmtUnitTestSupport {
                 w1.getTask(false).get().getUnchecked(),
                 MutableList.of("a=b", "b=c"));
     }
-
+    
 }
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/javalang/coerce/TypeCoercerExtensible.java b/utils/common/src/main/java/org/apache/brooklyn/util/javalang/coerce/TypeCoercerExtensible.java
index c9c03b1910..c1274810f7 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/util/javalang/coerce/TypeCoercerExtensible.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/javalang/coerce/TypeCoercerExtensible.java
@@ -175,7 +175,15 @@ public class TypeCoercerExtensible implements TypeCoercer {
                 }
             }
             
-            if (result!=null) errors.add(result);
+            if (result!=null) {
+                if (result.isAbsent()) errors.add(result);
+                else {
+                    log.warn("Coercer " + coercer + " returned wrapped null when coercing " + value);
+                    errors.add(Maybe.absent("coercion returned null"));
+                    // arguably it should return null here
+//                    return null;
+                }
+            }
         }
         
         //ENHANCEMENT could look in type hierarchy of both types for a conversion method...


[brooklyn-server] 03/03: don't warn if an active task deletes itself

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 8fe9c4fc1bfe9ee75e0e7ae00228af95fa3cae26
Author: Alex Heneveld <al...@cloudsoft.io>
AuthorDate: Fri Jun 23 21:19:48 2023 +0100

    don't warn if an active task deletes itself
    
    this happens eg for workflows that are expiring after completed in their task
---
 .../org/apache/brooklyn/util/core/task/BasicExecutionManager.java     | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionManager.java b/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionManager.java
index 97e63bedce..26756368f1 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionManager.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionManager.java
@@ -487,8 +487,10 @@ public class BasicExecutionManager implements ExecutionManager {
 
                 if (debugOnly) {
                     log.debug("Deleting cancelled task before completion: " + removedById + "; this task will continue to run in the background outwith " + this);
+                } else if (removedById.equals(Tasks.current())) {
+                    log.debug("Deleting currently running task "+removedById+" from memory; normal on tasks that do not want to be remembered but if not done carefully subsequent interaction capabilities may be limited");
                 } else {
-                    log.warn("Deleting submitted task before completion: " + removedById + " (tags " + removedById.getTags() + "); this task will continue to run in the background outwith " + this + ", but perhaps it should have been cancelled?");
+                    log.warn("Deleting submitted task before completion: " + removedById + " (tags " + removedById.getTags() + "), submitted by "+Tasks.current()+"; deleted task will continue to run in the background outwith " + this + ", but perhaps it should have been cancelled?");
                     log.debug("Active task deletion trace", new Throwable("Active task deletion trace"));
                 }
             }


[brooklyn-server] 02/03: cache service lookup results

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 0003ba4b04435ecf5a5a470be5a3b0b95e57d166
Author: Alex Heneveld <al...@cloudsoft.io>
AuthorDate: Fri Jun 23 16:30:21 2023 +0100

    cache service lookup results
    
    saves a not insignificant time because the underlying implementations rescan classes;
    we invalidate the cache whenever bundles change or startup completes
---
 .../brooklyn/api/framework/FrameworkLookup.java    | 39 ++++++++++++++++++----
 .../apache/brooklyn/core/mgmt/ha/OsgiManager.java  |  5 +++
 .../core/workflow/steps/CustomWorkflowStep.java    |  1 +
 .../util/core/task/BasicExecutionManager.java      |  8 +++--
 .../brooklyn/launcher/osgi/OsgiLauncherImpl.java   |  3 ++
 5 files changed, 47 insertions(+), 9 deletions(-)

diff --git a/api/src/main/java/org/apache/brooklyn/api/framework/FrameworkLookup.java b/api/src/main/java/org/apache/brooklyn/api/framework/FrameworkLookup.java
index 079117a4a1..829bfc8fc0 100644
--- a/api/src/main/java/org/apache/brooklyn/api/framework/FrameworkLookup.java
+++ b/api/src/main/java/org/apache/brooklyn/api/framework/FrameworkLookup.java
@@ -18,16 +18,14 @@
  */
 package org.apache.brooklyn.api.framework;
 
+import com.google.common.collect.Maps;
 import org.apache.brooklyn.util.guava.Maybe;
 import org.apache.brooklyn.util.osgi.OsgiUtil;
 import org.osgi.framework.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.ServiceLoader;
+import java.util.*;
 
 /**
  * A utility to fetch an instance of a class from either OSGI if available, or by a Service Loader otherwise.
@@ -42,11 +40,28 @@ import java.util.ServiceLoader;
  * which this code does not do.  Therefore this class is not suitable for use in a situation where client code needs
  * to take account of services coming and going, and explicitly avoid using the service when its reference count has
  * gone to zero.
+ *
+ * This is achieved by clients looking up services as they need,
+ * and maintaining a cache here.
+ *
+ * The cache is explicitly invalidated when bundles are installed and when brooklyn finishes loading.
  */
 public class FrameworkLookup {
 
     private static final Logger LOG = LoggerFactory.getLogger(FrameworkLookup.class);
 
+    private static boolean cachingEnabled = false;
+    public static void setCachingEnabled(boolean cachingEnabled) {
+        FrameworkLookup.cachingEnabled = cachingEnabled;
+    }
+
+    public static void invalidateCaches() {
+        cacheOfSingleInstancesWithNoLoader.clear();
+    }
+
+    static Map<Class,Maybe> cacheOfSingleInstancesWithNoLoader = Maps.newConcurrentMap();
+    static Map<Class,Iterable> cacheOfAllInstancesWithNoLoader = Maps.newConcurrentMap();
+
     /**
      * Find an instance of the given class in the framework.
      * This first performs an OSGI lookup if the OSGI framework is available. If it is not then it falls back to
@@ -72,13 +87,18 @@ public class FrameworkLookup {
      * @return  A maybe of the instance found in the framework.
      */
     public static <T> Maybe<T> lookup (Class<T> clazz, ClassLoader loader) {
-
         Maybe<T> result;
+        if (loader==null) {
+            result = cacheOfSingleInstancesWithNoLoader.get(clazz);
+            if (result!=null) return result;
+        }
+
         if (OsgiUtil.isBrooklynInsideFramework()) {
             result = lookupInOsgi(clazz);
         } else {
             result = lookupViaServiceLoader(clazz, loader);
         }
+        cacheOfSingleInstancesWithNoLoader.put(clazz, result);
 
         return result;
     }
@@ -108,13 +128,20 @@ public class FrameworkLookup {
      * @return  An iterable over the instances found in the framework.
      */
     public static <T> Iterable<T> lookupAll(Class<T> clazz, ClassLoader loader) {
-
         Iterable<T> result;
+
+        if (loader==null) {
+            result = cacheOfAllInstancesWithNoLoader.get(clazz);
+            if (result!=null) return result;
+        }
+
         if (OsgiUtil.isBrooklynInsideFramework()) {
             result = lookupAllInOsgi(clazz);
         } else {
             result = lookupAllViaServiceLoader(clazz, loader);
         }
+        cacheOfAllInstancesWithNoLoader.put(clazz, result);
+
         return result;
     }
 
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 7482dd88a3..32588c6ee7 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
@@ -37,6 +37,7 @@ import java.util.concurrent.atomic.AtomicReference;
 import java.util.function.Supplier;
 import javax.annotation.Nullable;
 import org.apache.brooklyn.api.catalog.CatalogItem.CatalogBundle;
+import org.apache.brooklyn.api.framework.FrameworkLookup;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.api.typereg.ManagedBundle;
 import org.apache.brooklyn.api.typereg.OsgiBundleWithUrl;
@@ -155,6 +156,7 @@ public class OsgiManager {
             if (Strings.isNonBlank(result.getMetadata().getUrl())) {
                 managedBundlesUidByUrl.put(result.getMetadata().getUrl(), result.getMetadata().getId());
             }
+            FrameworkLookup.invalidateCaches();
         }
 
         private File fileFor(ManagedBundle managedBundle) {
@@ -178,6 +180,7 @@ public class OsgiManager {
             managedBundlesRecord.managedBundlesUidByUrl.remove(bundleMetadata.getUrl());
             removeInstalledWrapperBundle(bundleMetadata);
             fileFor(bundleMetadata).delete();
+            FrameworkLookup.invalidateCaches();
             return true;
         }
 
@@ -202,6 +205,7 @@ public class OsgiManager {
             }
 
             ManagedBundle mbBak = managedBundlesByUid.put(result.getMetadata().getId(), result.getMetadata());
+            FrameworkLookup.invalidateCaches();
 
             return Pair.of(fBak, mbBak);
         }
@@ -221,6 +225,7 @@ public class OsgiManager {
             fBak.renameTo(fCached);
 
             managedBundlesByUid.put(result.getMetadata().getId(), mbBak);
+            FrameworkLookup.invalidateCaches();
 
             return fCached;
         }
diff --git a/core/src/main/java/org/apache/brooklyn/core/workflow/steps/CustomWorkflowStep.java b/core/src/main/java/org/apache/brooklyn/core/workflow/steps/CustomWorkflowStep.java
index 0fdd8ab981..d1925d2327 100644
--- a/core/src/main/java/org/apache/brooklyn/core/workflow/steps/CustomWorkflowStep.java
+++ b/core/src/main/java/org/apache/brooklyn/core/workflow/steps/CustomWorkflowStep.java
@@ -132,6 +132,7 @@ public class CustomWorkflowStep extends WorkflowStepDefinition implements Workfl
         retention = (String) input.remove("retention");
     }
 
+    /** disabled or count, hashes, etc; see {@link WorkflowRetentionParser} or documentation for full info */
     protected String retention;
 
     /** What to run this set of steps against, either an entity to run in that context, 'children' or 'members' to run over those, a range eg 1..10,  or a list (often in a variable) to run over elements of the list */
diff --git a/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionManager.java b/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionManager.java
index e2cde9a050..97e63bedce 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionManager.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionManager.java
@@ -1128,6 +1128,7 @@ public class BasicExecutionManager implements ExecutionManager {
     private static class TaskLookup implements Supplier<Task<?>> {
         // this class is not meant to be serialized, but if it is, make sure exec mgr doesn't sneak in
         transient BasicExecutionManager mgr;
+        transient Task<?> cachedResult;
 
         String id;
         String displayName;
@@ -1144,9 +1145,10 @@ public class BasicExecutionManager implements ExecutionManager {
         @Override
         public Task<?> get() {
             if (mgr == null) return gone();
-            Task<?> result = mgr.getTask(id);
-            if (result != null) return result;
-            return gone();
+
+            cachedResult = mgr.getTask(id);
+            if (cachedResult==null) cachedResult = gone();
+            return cachedResult;
         }
 
         private <T> Task<T> gone() {
diff --git a/karaf/init/src/main/java/org/apache/brooklyn/launcher/osgi/OsgiLauncherImpl.java b/karaf/init/src/main/java/org/apache/brooklyn/launcher/osgi/OsgiLauncherImpl.java
index 64edcfa702..76bc0d21af 100644
--- a/karaf/init/src/main/java/org/apache/brooklyn/launcher/osgi/OsgiLauncherImpl.java
+++ b/karaf/init/src/main/java/org/apache/brooklyn/launcher/osgi/OsgiLauncherImpl.java
@@ -21,6 +21,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicBoolean;
 import javax.annotation.Nullable;
+
+import org.apache.brooklyn.api.framework.FrameworkLookup;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityMode;
 import org.apache.brooklyn.core.BrooklynVersionService;
@@ -305,6 +307,7 @@ public class OsgiLauncherImpl extends BasicLauncher<OsgiLauncherImpl> implements
             ((ManagementContextInternal)getManagementContext()).getBrooklynProperties().put(OsgiManager.OSGI_STARTUP_COMPLETE, true);
             startupTimer.stop();
             LOG.info("Brooklyn initialization (part two) complete after {}", startupTimer.toString());
+            FrameworkLookup.invalidateCaches();
         }
     }