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 2014/11/15 18:07:12 UTC

[4/8] incubator-brooklyn git commit: catch disappearing definitions of sensors/config between rebinds/version changes, and better error logging then also

catch disappearing definitions of sensors/config between rebinds/version changes, and better error logging then also


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

Branch: refs/heads/master
Commit: 7f00d677271c4e8e06a63fa19a28d7cf882ce791
Parents: 1bc16cf
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Sat Nov 15 03:57:41 2014 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Sat Nov 15 03:57:41 2014 +0000

----------------------------------------------------------------------
 .../entity/rebind/BasicEntityRebindSupport.java |  6 ++--
 .../entity/rebind/dto/BasicEntityMemento.java   | 36 ++++++++++++++++----
 2 files changed, 34 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7f00d677/core/src/main/java/brooklyn/entity/rebind/BasicEntityRebindSupport.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/rebind/BasicEntityRebindSupport.java b/core/src/main/java/brooklyn/entity/rebind/BasicEntityRebindSupport.java
index 6bb19cb..c2d8532 100644
--- a/core/src/main/java/brooklyn/entity/rebind/BasicEntityRebindSupport.java
+++ b/core/src/main/java/brooklyn/entity/rebind/BasicEntityRebindSupport.java
@@ -40,6 +40,7 @@ import brooklyn.event.feed.AbstractFeed;
 import brooklyn.location.Location;
 import brooklyn.mementos.EntityMemento;
 import brooklyn.policy.basic.AbstractPolicy;
+import brooklyn.util.exceptions.Exceptions;
 
 import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableList;
@@ -85,8 +86,9 @@ public class BasicEntityRebindSupport extends AbstractBrooklynObjectRebindSuppor
                 @SuppressWarnings("unused") // just to ensure we can load the declared type? or maybe not needed
                 Class<?> type = (key.getType() != null) ? key.getType() : rebindContext.loadClass(key.getTypeName());
                 ((EntityInternal)entity).setAttributeWithoutPublishing((AttributeSensor<Object>)key, value);
-            } catch (ClassNotFoundException e) {
-                throw Throwables.propagate(e);
+            } catch (Exception e) {
+                LOG.warn("Error adding custom sensor "+entry+" when rebinding "+entity+" (rethrowing): "+e);
+                throw Exceptions.propagate(e);
             }
         }
         

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7f00d677/core/src/main/java/brooklyn/entity/rebind/dto/BasicEntityMemento.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/rebind/dto/BasicEntityMemento.java b/core/src/main/java/brooklyn/entity/rebind/dto/BasicEntityMemento.java
index 3760381..0ef27e1 100644
--- a/core/src/main/java/brooklyn/entity/rebind/dto/BasicEntityMemento.java
+++ b/core/src/main/java/brooklyn/entity/rebind/dto/BasicEntityMemento.java
@@ -25,16 +25,20 @@ import java.util.Map;
 
 import org.codehaus.jackson.annotate.JsonAutoDetect;
 import org.codehaus.jackson.annotate.JsonAutoDetect.Visibility;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import brooklyn.basic.BrooklynTypes;
 import brooklyn.config.ConfigKey;
 import brooklyn.entity.Effector;
 import brooklyn.entity.Entity;
 import brooklyn.entity.basic.AbstractEntity;
+import brooklyn.entity.basic.ConfigKeys;
 import brooklyn.entity.basic.Entities;
 import brooklyn.entity.rebind.RebindSupport;
 import brooklyn.event.AttributeSensor;
 import brooklyn.event.Sensor;
+import brooklyn.event.basic.Sensors;
 import brooklyn.mementos.EntityMemento;
 import brooklyn.mementos.TreeNode;
 
@@ -54,6 +58,8 @@ import com.google.common.collect.Maps;
 @JsonAutoDetect(fieldVisibility=Visibility.ANY, getterVisibility=Visibility.NONE)
 public class BasicEntityMemento extends AbstractTreeNodeMemento implements EntityMemento, Serializable {
 
+    private static final Logger log = LoggerFactory.getLogger(BasicEntityMemento.class);
+    
     private static final long serialVersionUID = 8642959541121050126L;
     
     public static Builder builder() {
@@ -180,12 +186,22 @@ public class BasicEntityMemento extends AbstractTreeNodeMemento implements Entit
         return staticConfigKeys;
     }
 
+    final static String LEGACY_KEY_DESCRIPTION = "This item was defined in a different version of this blueprint; metadata unavailable here.";
+    
     protected ConfigKey<?> getConfigKey(String key) {
+        ConfigKey<?> result = null;
         if (configKeys!=null) {
-            ConfigKey<?> ck = configKeys.get(key);
-            if (ck!=null) return ck;
+            result = configKeys.get(key);
+            if (result!=null && !LEGACY_KEY_DESCRIPTION.equals(result.getDescription()))
+                    return result;
         }
-        return getStaticConfigKeys().get(key);
+        ConfigKey<?> resultStatic = getStaticConfigKeys().get(key);
+        if (resultStatic!=null) return resultStatic;
+        // if it was a legacy key, if it is added back, drop the legacy reference
+        if (result!=null) return result;
+        // can happen on rebind if a key has gone away; it will not be declared in the file or in the 
+        log.warn("Config key "+key+": "+LEGACY_KEY_DESCRIPTION);
+        return ConfigKeys.newConfigKey(Object.class, key, LEGACY_KEY_DESCRIPTION);
     }
 
     protected synchronized Map<String, Sensor<?>> getStaticSensorKeys() {
@@ -198,11 +214,19 @@ public class BasicEntityMemento extends AbstractTreeNodeMemento implements Entit
     }
 
     protected AttributeSensor<?> getAttributeKey(String key) {
+        AttributeSensor<?> result=null;
         if (attributeKeys!=null) {
-            AttributeSensor<?> ak = attributeKeys.get(key);
-            if (ak!=null) return ak;
+            result = attributeKeys.get(key);
+            if (result!=null && !LEGACY_KEY_DESCRIPTION.equals(result.getDescription()))
+                return result;
         }
-        return (AttributeSensor<?>) getStaticSensorKeys().get(key);
+        AttributeSensor<?> resultStatic = (AttributeSensor<?>) getStaticSensorKeys().get(key);
+        if (resultStatic!=null) return resultStatic;
+        // if it was a legacy key, if it is added back, drop the legacy reference
+        if (result!=null) return result;
+        // can happen on rebind if a key has gone away; it will not be declared in the file or in the 
+        log.warn("Sensor "+key+": "+LEGACY_KEY_DESCRIPTION);
+        return Sensors.newSensor(Object.class, key, LEGACY_KEY_DESCRIPTION);
     }
 
     /**