brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tbou...@apache.org
Subject [1/5] brooklyn-server git commit: Persisting entity: don’t persist its adjuncts every time
Date Fri, 01 Jun 2018 10:00:47 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master 36cb70d2d -> 6f093c71f


Persisting entity: don’t persist its adjuncts every time

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

Branch: refs/heads/master
Commit: 492ebd58552b8f691ee22e0dd76e535fea56ef2c
Parents: ff38a5c
Author: Aled Sage <aled.sage@gmail.com>
Authored: Wed May 23 10:47:24 2018 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Thu May 24 12:24:13 2018 +0100

----------------------------------------------------------------------
 .../core/BrooklynFeatureEnablement.java         | 12 ++++++
 .../mgmt/internal/EntityChangeListener.java     |  1 +
 .../rebind/PeriodicDeltaChangeListener.java     | 39 +++++++++++++++++++-
 3 files changed, 51 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/492ebd58/core/src/main/java/org/apache/brooklyn/core/BrooklynFeatureEnablement.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/BrooklynFeatureEnablement.java b/core/src/main/java/org/apache/brooklyn/core/BrooklynFeatureEnablement.java
index 939a15d..8c142d8 100644
--- a/core/src/main/java/org/apache/brooklyn/core/BrooklynFeatureEnablement.java
+++ b/core/src/main/java/org/apache/brooklyn/core/BrooklynFeatureEnablement.java
@@ -59,6 +59,17 @@ public class BrooklynFeatureEnablement {
 
     public static final String FEATURE_FEED_PERSISTENCE_PROPERTY = FEATURE_PROPERTY_PREFIX+".feedPersistence";
     
+    /**
+     * When persisting an entity that changes, whether to persist its adjuncts and locations

+     * (i.e. its enrichers, policies, feeds and locations).
+     * 
+     * This was previously the default behaviour, which meant that (legacy) java-based Brooklyn
objects
+     * (e.g. entities, locations, policies, enrichers or feeds) could get away with bad practices
and 
+     * still be persisted. For example, they could change 'state' without telling the listener,
and hope
+     * that the entity they were attached to would soon persist (thus piggy-backing off it).
+     */
+    public static final String FEATURE_REFERENCED_OBJECTS_PERSISTENCE_PROPERTY = FEATURE_PROPERTY_PREFIX+".referencedObjectsPersistence";
+    
     /** whether feeds are automatically registered when set on entities, so that they are
persisted */
     public static final String FEATURE_FEED_REGISTRATION_PROPERTY = FEATURE_PROPERTY_PREFIX+".feedRegistration";
 
@@ -150,6 +161,7 @@ public class BrooklynFeatureEnablement {
         setDefault(FEATURE_FEED_REGISTRATION_PROPERTY, false);
         setDefault(FEATURE_BUNDLE_PERSISTENCE_PROPERTY, true);
         setDefault(FEATURE_CATALOG_PERSISTENCE_PROPERTY, true);
+        setDefault(FEATURE_REFERENCED_OBJECTS_PERSISTENCE_PROPERTY, false);
         setDefault(FEATURE_DEFAULT_STANDBY_IS_HOT_PROPERTY, false);
         setDefault(FEATURE_PERSIST_ENTITY_SPEC_AS_SUPPLIER, true);
         setDefault(FEATURE_RENAME_THREADS, false);

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/492ebd58/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/EntityChangeListener.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/EntityChangeListener.java
b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/EntityChangeListener.java
index b7f53a4..a0f5d73 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/EntityChangeListener.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/EntityChangeListener.java
@@ -29,6 +29,7 @@ public interface EntityChangeListener {
 
     // TODO for testing only!
     public static final EntityChangeListener NOOP = new EntityChangeListener() {
+        @Override public String toString() { return "EntityChangeListener.NOOP"; }
         @Override public void onChanged() {}
         @Override public void onAttributeChanged(AttributeSensor<?> attribute) {}
         @Override public void onConfigChanged(ConfigKey<?> key) {}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/492ebd58/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/PeriodicDeltaChangeListener.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/PeriodicDeltaChangeListener.java
b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/PeriodicDeltaChangeListener.java
index e4b2d7d..349f47f 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/PeriodicDeltaChangeListener.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/PeriodicDeltaChangeListener.java
@@ -195,6 +195,7 @@ public class PeriodicDeltaChangeListener implements ChangeListener {
     private final boolean persistPoliciesEnabled;
     private final boolean persistEnrichersEnabled;
     private final boolean persistFeedsEnabled;
+    private final boolean persistReferencedObjectsEnabled;
     
     private final Semaphore persistingMutex = new Semaphore(1);
     private final Object startStopMutex = new Object();
@@ -222,6 +223,7 @@ public class PeriodicDeltaChangeListener implements ChangeListener {
         this.persistPoliciesEnabled = BrooklynFeatureEnablement.isEnabled(BrooklynFeatureEnablement.FEATURE_POLICY_PERSISTENCE_PROPERTY);
         this.persistEnrichersEnabled = BrooklynFeatureEnablement.isEnabled(BrooklynFeatureEnablement.FEATURE_ENRICHER_PERSISTENCE_PROPERTY);
         this.persistFeedsEnabled = BrooklynFeatureEnablement.isEnabled(BrooklynFeatureEnablement.FEATURE_FEED_PERSISTENCE_PROPERTY);
+        this.persistReferencedObjectsEnabled = BrooklynFeatureEnablement.isEnabled(BrooklynFeatureEnablement.FEATURE_REFERENCED_OBJECTS_PERSISTENCE_PROPERTY);
     }
     
     public void start() {
@@ -355,6 +357,11 @@ public class PeriodicDeltaChangeListener implements ChangeListener {
         return state == ListenerState.STOPPING || state == ListenerState.STOPPED || executionContext.isShutdown();
     }
     
+    /**
+     * @deprecated since 1.0.0; its use is enabled via BrooklynFeatureEnablement.FEATURE_REFERENCED_OBJECTS_PERSISTENCE_PROPERTY,
+     *             to preserve backwards compatibility for legacy implementations of entities,
policies, etc.
+     */
+    @Deprecated
     private void addReferencedObjects(DeltaCollector deltaCollector) {
         MutableSet<BrooklynObject> referencedObjects = MutableSet.of();
         
@@ -443,7 +450,9 @@ public class PeriodicDeltaChangeListener implements ChangeListener {
                         limitedCountString(prevDeltaCollector.entities), limitedCountString(prevDeltaCollector.locations),
limitedCountString(prevDeltaCollector.policies), limitedCountString(prevDeltaCollector.enrichers),
limitedCountString(prevDeltaCollector.catalogItems), limitedCountString(prevDeltaCollector.bundles),

                         limitedCountString(prevDeltaCollector.removedEntityIds), limitedCountString(prevDeltaCollector.removedLocationIds),
limitedCountString(prevDeltaCollector.removedPolicyIds), limitedCountString(prevDeltaCollector.removedEnricherIds),
limitedCountString(prevDeltaCollector.removedCatalogItemIds), limitedCountString(prevDeltaCollector.removedBundleIds)});
 
-            addReferencedObjects(prevDeltaCollector);
+            if (persistReferencedObjectsEnabled) {
+                addReferencedObjects(prevDeltaCollector);
+            }
 
             if (LOG.isTraceEnabled()) LOG.trace("Checkpointing delta of memento with references:
"
                     + "updating {} entities, {} locations, {} policies, {} enrichers, {}
catalog items, {} bundles; "
@@ -527,7 +536,35 @@ public class PeriodicDeltaChangeListener implements ChangeListener {
     public synchronized void onManaged(BrooklynObject instance) {
         if (LOG.isTraceEnabled()) LOG.trace("onManaged: {}", instance);
         onChanged(instance);
+        addReferencedObjects(instance);
+    }
+
+    private void addReferencedObjects(BrooklynObject instance) {
+        if (!(instance instanceof Entity)) return;
+        Entity entity = (Entity) instance;
+        
+        MutableSet<BrooklynObject> referencedObjects = MutableSet.of();
+        
+        // collect references
+        for (Location location : entity.getLocations()) {
+            Collection<Location> findLocationsInHierarchy = TreeUtils.findLocationsInHierarchy(location);
+            referencedObjects.addAll(findLocationsInHierarchy);
+        }
+        if (persistPoliciesEnabled) {
+            referencedObjects.addAll(entity.policies());
+        }
+        if (persistEnrichersEnabled) {
+            referencedObjects.addAll(entity.enrichers());
+        }
+        if (persistFeedsEnabled) {
+            referencedObjects.addAll(((EntityInternal)entity).feeds().getFeeds());
+        }
+        
+        for (BrooklynObject ref : referencedObjects) {
+            deltaCollector.addIfNotRemoved(ref);
+        }
     }
+    
 
     @Override
     public synchronized void onUnmanaged(BrooklynObject instance) {


Mime
View raw message