brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rich...@apache.org
Subject [06/25] git commit: Policy/enricher rebind: set config
Date Sun, 01 Jun 2014 20:15:21 GMT
Policy/enricher rebind: set config


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

Branch: refs/heads/master
Commit: 546513ac123efba8c3dc72648e28b69e939cee65
Parents: 94456fc
Author: Aled Sage <aled.sage@gmail.com>
Authored: Tue May 27 00:16:45 2014 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Fri May 30 10:24:37 2014 +0100

----------------------------------------------------------------------
 .../java/brooklyn/mementos/EnricherMemento.java   |  3 +--
 .../java/brooklyn/mementos/LocationMemento.java   |  2 +-
 .../java/brooklyn/mementos/PolicyMemento.java     |  2 +-
 api/src/main/java/brooklyn/policy/Enricher.java   |  3 ++-
 api/src/main/java/brooklyn/policy/Policy.java     |  3 ++-
 .../entity/rebind/BasicEnricherRebindSupport.java | 14 +++++++++-----
 .../entity/rebind/BasicPolicyRebindSupport.java   |  8 +++++++-
 .../brooklyn/entity/rebind/RebindManagerImpl.java |  4 ++--
 .../entity/rebind/dto/BasicEnricherMemento.java   | 18 +++++++++---------
 .../entity/rebind/dto/BasicPolicyMemento.java     | 18 +++++++++---------
 10 files changed, 43 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/546513ac/api/src/main/java/brooklyn/mementos/EnricherMemento.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/brooklyn/mementos/EnricherMemento.java b/api/src/main/java/brooklyn/mementos/EnricherMemento.java
index 4213d40..f76d294 100644
--- a/api/src/main/java/brooklyn/mementos/EnricherMemento.java
+++ b/api/src/main/java/brooklyn/mementos/EnricherMemento.java
@@ -11,6 +11,5 @@ import brooklyn.entity.rebind.RebindSupport;
  */
 public interface EnricherMemento extends Memento {
 
-    Map<String, Object> getFlags();
-
+    Map<String, Object> getConfig();
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/546513ac/api/src/main/java/brooklyn/mementos/LocationMemento.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/brooklyn/mementos/LocationMemento.java b/api/src/main/java/brooklyn/mementos/LocationMemento.java
index 7d6401b..840ec70 100644
--- a/api/src/main/java/brooklyn/mementos/LocationMemento.java
+++ b/api/src/main/java/brooklyn/mementos/LocationMemento.java
@@ -6,7 +6,7 @@ import java.util.Set;
 import brooklyn.entity.rebind.RebindSupport;
 
 /**
- * Represents the state of an location, so that it can be reconstructed (e.g. after restarting
brooklyn).
+ * Represents the state of a location, so that it can be reconstructed (e.g. after restarting
brooklyn).
  * 
  * @see RebindSupport
  * 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/546513ac/api/src/main/java/brooklyn/mementos/PolicyMemento.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/brooklyn/mementos/PolicyMemento.java b/api/src/main/java/brooklyn/mementos/PolicyMemento.java
index 2a10404..9b2e266 100644
--- a/api/src/main/java/brooklyn/mementos/PolicyMemento.java
+++ b/api/src/main/java/brooklyn/mementos/PolicyMemento.java
@@ -13,5 +13,5 @@ import brooklyn.entity.rebind.RebindSupport;
  */
 public interface PolicyMemento extends Memento {
 
-    Map<String, Object> getFlags();
+    Map<String, Object> getConfig();
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/546513ac/api/src/main/java/brooklyn/policy/Enricher.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/brooklyn/policy/Enricher.java b/api/src/main/java/brooklyn/policy/Enricher.java
index 6be006d..50518ba 100644
--- a/api/src/main/java/brooklyn/policy/Enricher.java
+++ b/api/src/main/java/brooklyn/policy/Enricher.java
@@ -5,6 +5,7 @@ import java.util.Map;
 import brooklyn.config.ConfigKey;
 import brooklyn.entity.rebind.RebindSupport;
 import brooklyn.entity.rebind.Rebindable;
+import brooklyn.entity.trait.Configurable;
 import brooklyn.mementos.EnricherMemento;
 
 import com.google.common.annotations.Beta;
@@ -15,7 +16,7 @@ import com.google.common.annotations.Beta;
  * Has some similarities to {@link Policy}. However, enrichers specifically do not invoke
  * effectors and should only function to publish new metrics.
  */
-public interface Enricher extends EntityAdjunct, Rebindable {
+public interface Enricher extends EntityAdjunct, Rebindable, Configurable {
     /**
      * A unique id for this enricher.
      */

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/546513ac/api/src/main/java/brooklyn/policy/Policy.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/brooklyn/policy/Policy.java b/api/src/main/java/brooklyn/policy/Policy.java
index 6594469..5aab17e 100644
--- a/api/src/main/java/brooklyn/policy/Policy.java
+++ b/api/src/main/java/brooklyn/policy/Policy.java
@@ -5,6 +5,7 @@ import java.util.Map;
 import brooklyn.config.ConfigKey;
 import brooklyn.entity.rebind.RebindSupport;
 import brooklyn.entity.rebind.Rebindable;
+import brooklyn.entity.trait.Configurable;
 import brooklyn.mementos.PolicyMemento;
 
 import com.google.common.annotations.Beta;
@@ -13,7 +14,7 @@ import com.google.common.annotations.Beta;
  * Policies implement actions and thus must be suspendable; policies should continue to evaluate
their sensors
  * and indicate their desired planned action even if they aren't invoking them
  */
-public interface Policy extends EntityAdjunct, Rebindable {
+public interface Policy extends EntityAdjunct, Rebindable, Configurable {
     /**
      * A unique id for this policy.
      */

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/546513ac/core/src/main/java/brooklyn/entity/rebind/BasicEnricherRebindSupport.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/rebind/BasicEnricherRebindSupport.java b/core/src/main/java/brooklyn/entity/rebind/BasicEnricherRebindSupport.java
index a8364bc..6ab1e58 100644
--- a/core/src/main/java/brooklyn/entity/rebind/BasicEnricherRebindSupport.java
+++ b/core/src/main/java/brooklyn/entity/rebind/BasicEnricherRebindSupport.java
@@ -1,14 +1,13 @@
 package brooklyn.entity.rebind;
 
-import java.util.Collections;
-import java.util.Map;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import brooklyn.enricher.basic.AbstractEnricher;
 import brooklyn.entity.rebind.dto.MementosGenerators;
 import brooklyn.mementos.EnricherMemento;
-import brooklyn.enricher.basic.AbstractEnricher;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.flags.FlagUtils;
 
 public class BasicEnricherRebindSupport implements RebindSupport<EnricherMemento> {
 
@@ -31,12 +30,17 @@ public class BasicEnricherRebindSupport implements RebindSupport<EnricherMemento
     public void reconstruct(RebindContext rebindContext, EnricherMemento memento) {
         if (LOG.isTraceEnabled()) LOG.trace("Reconstructing enricher: {}", memento.toVerboseString());
 
-        // Note that the flags have been set in the constructor
         enricher.setName(memento.getDisplayName());
         
+        // FIXME Will this set config keys that are not marked with `@SetFromFlag`?
+        // Note that the flags may have been set in the constructor; but some have no-arg
constructors
+        ConfigBag configBag = ConfigBag.newInstance(memento.getConfig());
+        FlagUtils.setFieldsFromFlags(enricher, configBag);
+        
         doReconsruct(rebindContext, memento);
     }
 
+
     /**
      * For overriding, to give custom reconsruct behaviour.
      */

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/546513ac/core/src/main/java/brooklyn/entity/rebind/BasicPolicyRebindSupport.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/rebind/BasicPolicyRebindSupport.java b/core/src/main/java/brooklyn/entity/rebind/BasicPolicyRebindSupport.java
index 3f21d64..5f32f7f 100644
--- a/core/src/main/java/brooklyn/entity/rebind/BasicPolicyRebindSupport.java
+++ b/core/src/main/java/brooklyn/entity/rebind/BasicPolicyRebindSupport.java
@@ -6,6 +6,8 @@ import org.slf4j.LoggerFactory;
 import brooklyn.entity.rebind.dto.MementosGenerators;
 import brooklyn.mementos.PolicyMemento;
 import brooklyn.policy.basic.AbstractPolicy;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.flags.FlagUtils;
 
 public class BasicPolicyRebindSupport implements RebindSupport<PolicyMemento> {
 
@@ -28,9 +30,13 @@ public class BasicPolicyRebindSupport implements RebindSupport<PolicyMemento>
{
     public void reconstruct(RebindContext rebindContext, PolicyMemento memento) {
         if (LOG.isTraceEnabled()) LOG.trace("Reconstructing policy: {}", memento.toVerboseString());
 
-        // Note that the flags have been set in the constructor
         policy.setName(memento.getDisplayName());
         
+        // FIXME Will this set config keys that are not marked with `@SetFromFlag`?
+        // Note that the flags may have been set in the constructor; but some have no-arg
constructors
+        ConfigBag configBag = ConfigBag.newInstance(memento.getConfig());
+        FlagUtils.setFieldsFromFlags(policy, configBag);
+        
         doReconsruct(rebindContext, memento);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/546513ac/core/src/main/java/brooklyn/entity/rebind/RebindManagerImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/rebind/RebindManagerImpl.java b/core/src/main/java/brooklyn/entity/rebind/RebindManagerImpl.java
index 8142546..ab5a8eb 100644
--- a/core/src/main/java/brooklyn/entity/rebind/RebindManagerImpl.java
+++ b/core/src/main/java/brooklyn/entity/rebind/RebindManagerImpl.java
@@ -522,7 +522,7 @@ public class RebindManagerImpl implements RebindManager {
 
         Map<String, Object> flags = MutableMap.<String, Object>builder()
                 .put("id", id)
-                .putAll(memento.getFlags())
+                .putAll(memento.getConfig())
                 .build();
 
         return (Policy) invokeConstructor(reflections, policyClazz, new Object[] {flags});
@@ -538,7 +538,7 @@ public class RebindManagerImpl implements RebindManager {
 
         Map<String, Object> flags = MutableMap.<String, Object>builder()
                 .put("id", id)
-                .putAll(memento.getFlags())
+                .putAll(memento.getConfig())
                 .build();
 
         return (Enricher) invokeConstructor(reflections, enricherClazz, new Object[] {flags});

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/546513ac/core/src/main/java/brooklyn/entity/rebind/dto/BasicEnricherMemento.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/rebind/dto/BasicEnricherMemento.java b/core/src/main/java/brooklyn/entity/rebind/dto/BasicEnricherMemento.java
index 9433798..e1c751a 100644
--- a/core/src/main/java/brooklyn/entity/rebind/dto/BasicEnricherMemento.java
+++ b/core/src/main/java/brooklyn/entity/rebind/dto/BasicEnricherMemento.java
@@ -23,27 +23,27 @@ public class BasicEnricherMemento extends AbstractMemento implements EnricherMem
     }
 
     public static class Builder extends AbstractMemento.Builder<Builder> {
-        protected Map<String,Object> flags = Maps.newLinkedHashMap();
+        protected Map<String,Object> config = Maps.newLinkedHashMap();
 
         public Builder from(EnricherMemento other) {
             super.from(other);
-            flags.putAll(other.getFlags());
+            config.putAll(other.getConfig());
             return this;
         }
-        public Builder flags(Map<String,?> vals) {
-            flags.putAll(vals); return this;
+        public Builder config(Map<String,?> vals) {
+            config.putAll(vals); return this;
         }
         public EnricherMemento build() {
             return new BasicEnricherMemento(this);
         }
     }
 
-    private Map<String,Object> flags;
+    private Map<String,Object> config;
     private Map<String, Object> fields;
 
     // Trusts the builder to not mess around with mutability after calling build()
     protected BasicEnricherMemento(Builder builder) {
-        flags = toPersistedMap(builder.flags);
+        config = toPersistedMap(builder.config);
     }
 
     @Deprecated
@@ -59,12 +59,12 @@ public class BasicEnricherMemento extends AbstractMemento implements EnricherMem
     }
 
     @Override
-    public Map<String, Object> getFlags() {
-        return fromPersistedMap(flags);
+    public Map<String, Object> getConfig() {
+        return fromPersistedMap(config);
     }
 
     @Override
     protected ToStringHelper newVerboseStringHelper() {
-        return super.newVerboseStringHelper().add("flags", Entities.sanitize(getFlags()));
+        return super.newVerboseStringHelper().add("config", Entities.sanitize(getConfig()));
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/546513ac/core/src/main/java/brooklyn/entity/rebind/dto/BasicPolicyMemento.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/rebind/dto/BasicPolicyMemento.java b/core/src/main/java/brooklyn/entity/rebind/dto/BasicPolicyMemento.java
index e8b3190..2b71ad3 100644
--- a/core/src/main/java/brooklyn/entity/rebind/dto/BasicPolicyMemento.java
+++ b/core/src/main/java/brooklyn/entity/rebind/dto/BasicPolicyMemento.java
@@ -23,27 +23,27 @@ public class BasicPolicyMemento extends AbstractMemento implements PolicyMemento
     }
 
     public static class Builder extends AbstractMemento.Builder<Builder> {
-        protected Map<String,Object> flags = Maps.newLinkedHashMap();
+        protected Map<String,Object> config = Maps.newLinkedHashMap();
         
         public Builder from(PolicyMemento other) {
             super.from(other);
-            flags.putAll(other.getFlags());
+            config.putAll(other.getConfig());
             return this;
         }
-        public Builder flags(Map<String,?> vals) {
-            flags.putAll(vals); return this;
+        public Builder config(Map<String,?> vals) {
+            config.putAll(vals); return this;
         }
         public PolicyMemento build() {
             return new BasicPolicyMemento(this);
         }
     }
     
-	private Map<String,Object> flags;
+	private Map<String,Object> config;
     private Map<String, Object> fields;
 
     // Trusts the builder to not mess around with mutability after calling build()
 	protected BasicPolicyMemento(Builder builder) {
-	    flags = toPersistedMap(builder.flags);
+	    config = toPersistedMap(builder.config);
 	}
 	
     @Deprecated
@@ -59,12 +59,12 @@ public class BasicPolicyMemento extends AbstractMemento implements PolicyMemento
     }
 
     @Override
-    public Map<String, Object> getFlags() {
-		return fromPersistedMap(flags);
+    public Map<String, Object> getConfig() {
+		return fromPersistedMap(config);
 	}
     
     @Override
     protected ToStringHelper newVerboseStringHelper() {
-        return super.newVerboseStringHelper().add("flags", Entities.sanitize(getFlags()));
+        return super.newVerboseStringHelper().add("config", Entities.sanitize(getConfig()));
     }
 }


Mime
View raw message