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 2016/07/07 23:05:20 UTC

[1/2] brooklyn-server git commit: Don't serialize NodeMetadata in location config

Repository: brooklyn-server
Updated Branches:
  refs/heads/master c586b2651 -> f0c550e52


Don't serialize NodeMetadata in location config


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

Branch: refs/heads/master
Commit: 705b17364972038bc2b74079692324fef42bb90a
Parents: 4b11f50
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Wed Jul 6 20:49:54 2016 +0300
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Thu Jul 7 18:04:46 2016 +0300

----------------------------------------------------------------------
 .../jclouds/JcloudsSshMachineLocation.java      | 26 +++++++++++---------
 .../jclouds/RebindJcloudsLocationLiveTest.java  |  6 +++++
 2 files changed, 21 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/705b1736/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocation.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocation.java b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocation.java
index 51a476f..6a3e905 100644
--- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocation.java
+++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocation.java
@@ -114,9 +114,15 @@ public class JcloudsSshMachineLocation extends SshMachineLocation implements Jcl
      * intermediate stage, where we want to handle rebinding to old state that has "node"
      * and new state that should not. We therefore leave in the {@code @SetFromFlag} on node
      * so that we read it back, but we ensure the value is null when we write it out!
+     *
+     * Note that fields in locations behave differently from those in entities. Locations will
+     * update the persisted state with the latest values of fields and will skip transient
+     * properties. Entities don't read back the field values.
      * 
      * TODO We will rename these to get rid of the ugly underscore when the old node/template 
      * fields are deleted.
+     * TODO Should we change callers to pass all the bits of node & template we are interested
+     * in instead of the objects themselves so we don't have to clear them here?
      */
     private transient Optional<NodeMetadata> _node;
 
@@ -146,19 +152,15 @@ public class JcloudsSshMachineLocation extends SshMachineLocation implements Jcl
             super.init();
             ComputeServiceContext context = jcloudsParent.getComputeService().getContext();
             runScriptFactory = context.utils().injector().getInstance(RunScriptOnNode.Factory.class);
-            if (node != null) {
-                setNode(node);
-            }
-            if (template != null) {
-                setTemplate(template);
-            }
         } else {
             // TODO Need to fix the rebind-detection, and not call init() on rebind.
             // This will all change when locations become entities.
+            // Note that the happy path for rebind will go through the above case!
             if (LOG.isDebugEnabled()) LOG.debug("Not doing init() of {} because parent not set; presuming rebinding", this);
         }
+        clearDeprecatedProperties();
     }
-    
+
     @Override
     public void rebind() {
         super.rebind();
@@ -171,15 +173,15 @@ public class JcloudsSshMachineLocation extends SshMachineLocation implements Jcl
             LOG.warn("Location {} does not have parent; cannot retrieve jclouds compute-service or "
                     + "run-script factory; later operations may fail (continuing)", this);
         }
-        
+        clearDeprecatedProperties();
+    }
+
+    protected void clearDeprecatedProperties() {
         if (node != null) {
             setNode(node);
-            node = null;
         }
-
         if (template != null) {
             setTemplate(template);
-            template = null;
         }
     }
     
@@ -200,6 +202,7 @@ public class JcloudsSshMachineLocation extends SshMachineLocation implements Jcl
 
     protected void setNode(NodeMetadata node) {
         this.node = null;
+        config().removeFromLocalBag("node");
         nodeId = node.getId();
         imageId = node.getImageId();
         privateAddresses = node.getPrivateAddresses();
@@ -209,6 +212,7 @@ public class JcloudsSshMachineLocation extends SshMachineLocation implements Jcl
 
     protected void setTemplate(Template template) {
         this.template = null;
+        config().removeFromLocalBag("template");
         _template = Optional.of(template);
         _image = Optional.fromNullable(template.getImage());
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/705b1736/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/RebindJcloudsLocationLiveTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/RebindJcloudsLocationLiveTest.java b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/RebindJcloudsLocationLiveTest.java
index dd6d58f..446aaa9 100644
--- a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/RebindJcloudsLocationLiveTest.java
+++ b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/RebindJcloudsLocationLiveTest.java
@@ -43,6 +43,7 @@ import org.testng.annotations.Test;
 import com.google.common.base.Optional;
 import com.google.common.base.Predicates;
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 import com.google.common.io.Files;
@@ -150,6 +151,8 @@ public class RebindJcloudsLocationLiveTest extends AbstractJcloudsLiveTest {
         assertEquals(ImmutableSet.copyOf(loc2.getChildren()), ImmutableSet.of(machine2));
         
         String errmsg = "loc="+loc2.toVerboseString()+"; machine="+machine2.toVerboseString();
+        assertNull(machine2.config().getLocalBag().getAllConfig().get("node"), errmsg);
+        assertNull(machine2.config().getLocalBag().getAllConfig().get("template"), errmsg);
         assertEquals(machine2.getId(), "aKEcbxKN", errmsg);
         assertEquals(machine2.getJcloudsId(), "ap-southeast-1/i-56fd53f2", errmsg);
         assertEquals(machine2.getSshHostAndPort(), HostAndPort.fromParts("ec2-54-254-23-53.ap-southeast-1.compute.amazonaws.com", 22), errmsg);
@@ -165,6 +168,9 @@ public class RebindJcloudsLocationLiveTest extends AbstractJcloudsLiveTest {
         assertEquals(machine2.getOsDetails().getArch(), "x86_64", errmsg);
         assertEquals(machine2.getOsDetails().getVersion(), "6.5", errmsg);
         assertEquals(machine2.getOsDetails().is64bit(), true, errmsg);
+        
+        // Re-populates the @SetFromFlag fields from config
+        machine2.configure(ImmutableMap.of());
 
         // Force it to be persisted again. Expect to pesist without the NodeMetadata and Template.
         app2.getManagementContext().getRebindManager().getChangeListener().onChanged(loc2);


[2/2] brooklyn-server git commit: This closes #238

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


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

Branch: refs/heads/master
Commit: f0c550e52c88208c002f472f4dc632e596522807
Parents: c586b26 705b173
Author: Aled Sage <al...@gmail.com>
Authored: Fri Jul 8 00:04:16 2016 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Fri Jul 8 00:04:16 2016 +0100

----------------------------------------------------------------------
 .../jclouds/JcloudsSshMachineLocation.java      | 26 +++++++++++---------
 .../jclouds/RebindJcloudsLocationLiveTest.java  |  6 +++++
 2 files changed, 21 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f0c550e5/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocation.java
----------------------------------------------------------------------