You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2015/11/17 12:19:54 UTC

[1/2] incubator-brooklyn git commit: BROOKLYN-193 Add configuration for skipping invalid config values during rebind

Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master cc30e6f36 -> bc54d1d18


BROOKLYN-193 Add configuration for skipping invalid config values during rebind


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

Branch: refs/heads/master
Commit: 680ee07b38da835a3cb3a2c2efc5e0ff3076169b
Parents: 2b23266
Author: Valentin Aitken <va...@cloudsoftcorp.com>
Authored: Fri Nov 13 23:58:27 2015 +0200
Committer: Valentin Aitken <va...@cloudsoftcorp.com>
Committed: Fri Nov 13 23:58:27 2015 +0200

----------------------------------------------------------------------
 .../api/mgmt/rebind/RebindExceptionHandler.java |  4 +++
 .../mgmt/rebind/BasicEntityRebindSupport.java   |  9 ++++---
 .../mgmt/rebind/RebindExceptionHandlerImpl.java | 27 ++++++++++++++++++++
 .../core/mgmt/rebind/RebindManagerImpl.java     |  8 ++++++
 docs/guide/ops/persistence/index.md             |  2 ++
 5 files changed, 46 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/680ee07b/api/src/main/java/org/apache/brooklyn/api/mgmt/rebind/RebindExceptionHandler.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/mgmt/rebind/RebindExceptionHandler.java b/api/src/main/java/org/apache/brooklyn/api/mgmt/rebind/RebindExceptionHandler.java
index 9660930..574a680 100644
--- a/api/src/main/java/org/apache/brooklyn/api/mgmt/rebind/RebindExceptionHandler.java
+++ b/api/src/main/java/org/apache/brooklyn/api/mgmt/rebind/RebindExceptionHandler.java
@@ -24,6 +24,7 @@ import org.apache.brooklyn.api.catalog.CatalogItem;
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.EntityLocal;
 import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.api.mgmt.rebind.mementos.EntityMemento;
 import org.apache.brooklyn.api.objs.BrooklynObject;
 import org.apache.brooklyn.api.objs.BrooklynObjectType;
 import org.apache.brooklyn.api.policy.Policy;
@@ -31,6 +32,7 @@ import org.apache.brooklyn.api.sensor.Enricher;
 import org.apache.brooklyn.api.sensor.Feed;
 
 import com.google.common.annotations.Beta;
+import org.apache.brooklyn.config.ConfigKey;
 
 /**
  * Handler called on all exceptions to do with rebind.
@@ -91,6 +93,8 @@ public interface RebindExceptionHandler {
 
     void onRebindFailed(BrooklynObjectType type, BrooklynObject instance, Exception e);
 
+    void onAddConfigFailed(EntityMemento type, ConfigKey<?> value, Exception e);
+
     void onAddPolicyFailed(EntityLocal entity, Policy policy, Exception e);
 
     void onAddEnricherFailed(EntityLocal entity, Enricher enricher, Exception e);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/680ee07b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicEntityRebindSupport.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicEntityRebindSupport.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicEntityRebindSupport.java
index abfc85d..a233067 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicEntityRebindSupport.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicEntityRebindSupport.java
@@ -42,7 +42,6 @@ import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableList;
 
 public class BasicEntityRebindSupport extends AbstractBrooklynObjectRebindSupport<EntityMemento> {
@@ -101,15 +100,17 @@ public class BasicEntityRebindSupport extends AbstractBrooklynObjectRebindSuppor
     @SuppressWarnings("unchecked")
     @Override
     protected void addConfig(RebindContext rebindContext, EntityMemento memento) {
+        ConfigKey<?> key = null;
         for (Map.Entry<ConfigKey<?>, Object> entry : memento.getConfig().entrySet()) {
             try {
-                ConfigKey<?> key = entry.getKey();
+                key = entry.getKey();
                 Object value = entry.getValue();
                 @SuppressWarnings("unused") // just to ensure we can load the declared type? or maybe not needed
+                        // In what cases key.getType() will be null?
                 Class<?> type = (key.getType() != null) ? key.getType() : rebindContext.loadClass(key.getTypeName());
                 entity.config().set((ConfigKey<Object>)key, value);
-            } catch (ClassNotFoundException e) {
-                throw Throwables.propagate(e);
+            } catch (ClassNotFoundException|IllegalArgumentException e) {
+                rebindContext.getExceptionHandler().onAddConfigFailed(memento, key, e);
             }
         }
         

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/680ee07b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindExceptionHandlerImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindExceptionHandlerImpl.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindExceptionHandlerImpl.java
index 7b4cd00..994a3a7 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindExceptionHandlerImpl.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindExceptionHandlerImpl.java
@@ -24,6 +24,8 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Set;
 
+import org.apache.brooklyn.api.mgmt.rebind.mementos.EntityMemento;
+import org.apache.brooklyn.config.ConfigKey;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.brooklyn.api.catalog.CatalogItem;
@@ -55,6 +57,7 @@ public class RebindExceptionHandlerImpl implements RebindExceptionHandler {
 
     protected final RebindManager.RebindFailureMode danglingRefFailureMode;
     protected final RebindManager.RebindFailureMode rebindFailureMode;
+    protected final RebindManager.RebindFailureMode addConfigFailureMode;
     protected final RebindFailureMode addPolicyFailureMode;
     protected final RebindFailureMode loadPolicyFailureMode;
     protected final QuorumCheck danglingRefsQuorumRequiredHealthy;
@@ -85,6 +88,7 @@ public class RebindExceptionHandlerImpl implements RebindExceptionHandler {
     public static class Builder {
         private RebindManager.RebindFailureMode danglingRefFailureMode = RebindManager.RebindFailureMode.CONTINUE;
         private RebindManager.RebindFailureMode rebindFailureMode = RebindManager.RebindFailureMode.FAIL_AT_END;
+        private RebindManager.RebindFailureMode addConfigFailureMode = RebindManager.RebindFailureMode.FAIL_AT_END;
         private RebindManager.RebindFailureMode addPolicyFailureMode = RebindManager.RebindFailureMode.CONTINUE;
         private RebindManager.RebindFailureMode deserializePolicyFailureMode = RebindManager.RebindFailureMode.CONTINUE;
         private QuorumCheck danglingRefsQuorumRequiredHealthy = RebindManagerImpl.DANGLING_REFERENCES_MIN_REQUIRED_HEALTHY.getDefaultValue();
@@ -105,6 +109,10 @@ public class RebindExceptionHandlerImpl implements RebindExceptionHandler {
             deserializePolicyFailureMode = val;
             return this;
         }
+        public Builder addConfigFailureMode(RebindManager.RebindFailureMode val) {
+            this.addConfigFailureMode = val;
+            return this;
+        }
         public Builder danglingRefQuorumRequiredHealthy(QuorumCheck val) {
             danglingRefsQuorumRequiredHealthy = val;
             return this;
@@ -117,6 +125,7 @@ public class RebindExceptionHandlerImpl implements RebindExceptionHandler {
     public RebindExceptionHandlerImpl(Builder builder) {
         this.danglingRefFailureMode = checkNotNull(builder.danglingRefFailureMode, "danglingRefFailureMode");
         this.rebindFailureMode = checkNotNull(builder.rebindFailureMode, "rebindFailureMode");
+        this.addConfigFailureMode = checkNotNull(builder.addConfigFailureMode, "addConfigFailureMode");
         this.addPolicyFailureMode = checkNotNull(builder.addPolicyFailureMode, "addPolicyFailureMode");
         this.loadPolicyFailureMode = checkNotNull(builder.deserializePolicyFailureMode, "deserializePolicyFailureMode");
         this.danglingRefsQuorumRequiredHealthy = checkNotNull(builder.danglingRefsQuorumRequiredHealthy, "danglingRefsQuorumRequiredHealthy");
@@ -298,6 +307,24 @@ public class RebindExceptionHandlerImpl implements RebindExceptionHandler {
         }
     }
 
+    public void onAddConfigFailed(EntityMemento entityMemento, ConfigKey<?> key, Exception e) {
+        Exceptions.propagateIfFatal(e);
+
+        String errmsg = "Failed to rebind " + key + " with value " + entityMemento.getConfig().get(key) + " for entity " + entityMemento;
+        switch (addConfigFailureMode) {
+            case FAIL_FAST:
+                throw new IllegalStateException(errmsg, e);
+            case FAIL_AT_END:
+                exceptions.add(new IllegalStateException(errmsg, e));
+                break;
+            case CONTINUE:
+                warn(errmsg + "; continuing", e);
+                break;
+            default:
+                throw new IllegalStateException("Unexpected state '"+addPolicyFailureMode+"' for addPolicyFailureMode");
+        }
+    }
+
     @Override
     public void onAddPolicyFailed(EntityLocal entity, Policy policy, Exception e) {
         Exceptions.propagateIfFatal(e);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/680ee07b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindManagerImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindManagerImpl.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindManagerImpl.java
index dccd91a..5525981 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindManagerImpl.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindManagerImpl.java
@@ -92,6 +92,9 @@ public class RebindManagerImpl implements RebindManager {
     public static final ConfigKey<RebindFailureMode> REBIND_FAILURE_MODE =
             ConfigKeys.newConfigKey(RebindFailureMode.class, "rebind.failureMode.rebind",
                     "Action to take if a failure occurs during rebind", RebindFailureMode.FAIL_AT_END);
+    public static final ConfigKey<RebindFailureMode> ADD_CONFIG_FAILURE_MODE =
+            ConfigKeys.newConfigKey(RebindFailureMode.class, "rebind.failureMode.addConfig",
+                    "Action to take if a failure occurs when setting a config value. It could happen coercion of the value type to fail.", RebindFailureMode.FAIL_AT_END);
     public static final ConfigKey<RebindFailureMode> ADD_POLICY_FAILURE_MODE =
             ConfigKeys.newConfigKey(RebindFailureMode.class, "rebind.failureMode.addPolicy",
                     "Action to take if a failure occurs when adding a policy or enricher", RebindFailureMode.CONTINUE);
@@ -131,6 +134,7 @@ public class RebindManagerImpl implements RebindManager {
     
     private RebindFailureMode danglingRefFailureMode;
     private RebindFailureMode rebindFailureMode;
+    private RebindFailureMode addConfigFailureMode;
     private RebindFailureMode addPolicyFailureMode;
     private RebindFailureMode loadPolicyFailureMode;
     private QuorumCheck danglingRefsQuorumRequiredHealthy;
@@ -177,6 +181,7 @@ public class RebindManagerImpl implements RebindManager {
 
         danglingRefFailureMode = managementContext.getConfig().getConfig(DANGLING_REFERENCE_FAILURE_MODE);
         rebindFailureMode = managementContext.getConfig().getConfig(REBIND_FAILURE_MODE);
+        addConfigFailureMode = managementContext.getConfig().getConfig(ADD_CONFIG_FAILURE_MODE);
         addPolicyFailureMode = managementContext.getConfig().getConfig(ADD_POLICY_FAILURE_MODE);
         loadPolicyFailureMode = managementContext.getConfig().getConfig(LOAD_POLICY_FAILURE_MODE);
         
@@ -384,6 +389,7 @@ public class RebindManagerImpl implements RebindManager {
                 .danglingRefFailureMode(danglingRefFailureMode)
                 .danglingRefQuorumRequiredHealthy(danglingRefsQuorumRequiredHealthy)
                 .rebindFailureMode(rebindFailureMode)
+                .addConfigFailureMode(addConfigFailureMode)
                 .addPolicyFailureMode(addPolicyFailureMode)
                 .loadPolicyFailureMode(loadPolicyFailureMode)
                 .build();
@@ -479,6 +485,7 @@ public class RebindManagerImpl implements RebindManager {
                 .danglingRefFailureMode(danglingRefFailureMode)
                 .danglingRefQuorumRequiredHealthy(danglingRefsQuorumRequiredHealthy)
                 .rebindFailureMode(rebindFailureMode)
+                .addConfigFailureMode(addConfigFailureMode)
                 .addPolicyFailureMode(addPolicyFailureMode)
                 .loadPolicyFailureMode(loadPolicyFailureMode)
                 .build();
@@ -509,6 +516,7 @@ public class RebindManagerImpl implements RebindManager {
         RebindExceptionHandler exceptionHandler = RebindExceptionHandlerImpl.builder()
                 .danglingRefFailureMode(danglingRefFailureMode)
                 .rebindFailureMode(rebindFailureMode)
+                .addConfigFailureMode(addConfigFailureMode)
                 .addPolicyFailureMode(addPolicyFailureMode)
                 .loadPolicyFailureMode(loadPolicyFailureMode)
                 .build();

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/680ee07b/docs/guide/ops/persistence/index.md
----------------------------------------------------------------------
diff --git a/docs/guide/ops/persistence/index.md b/docs/guide/ops/persistence/index.md
index a74f301..4788db9 100644
--- a/docs/guide/ops/persistence/index.md
+++ b/docs/guide/ops/persistence/index.md
@@ -191,6 +191,7 @@ rebind.failureMode.danglingRef=continue
 rebind.failureMode.loadPolicy=continue
 rebind.failureMode.addPolicy=continue
 rebind.failureMode.rebind=fail_at_end
+rebind.failureMode.addConfig=fail_at_end
 {% endhighlight %} 
 
 For each of these configuration options, the possible values are:
@@ -212,6 +213,7 @@ The meaning of the configuration options is:
 * `rebind.failureMode.addPolicy`: if there is an error re-adding the policy or enricher to
   its associated entity... whether to continue (discarding the policy or enricher) 
   or fail.
+* `rebind.failureMode.addConfig`: if there is invalid config value, or some other error occurs when adding a config.
 * `rebind.failureMode.rebind`: any errors on rebind not covered by the more specific error cases described above.
 
 


[2/2] incubator-brooklyn git commit: This closes #1033

Posted by al...@apache.org.
This closes #1033


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

Branch: refs/heads/master
Commit: bc54d1d184c439a950ab5b15782afccfc2e56986
Parents: cc30e6f 680ee07
Author: Aled Sage <al...@gmail.com>
Authored: Tue Nov 17 11:19:30 2015 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Tue Nov 17 11:19:30 2015 +0000

----------------------------------------------------------------------
 .../api/mgmt/rebind/RebindExceptionHandler.java |  4 +++
 .../mgmt/rebind/BasicEntityRebindSupport.java   |  9 ++++---
 .../mgmt/rebind/RebindExceptionHandlerImpl.java | 27 ++++++++++++++++++++
 .../core/mgmt/rebind/RebindManagerImpl.java     |  8 ++++++
 docs/guide/ops/persistence/index.md             |  2 ++
 5 files changed, 46 insertions(+), 4 deletions(-)
----------------------------------------------------------------------