Deprecate getManagementPlaneId() in favour of getOptionalManagementPlaneId()


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

Branch: refs/heads/master
Commit: cb41895e162450ba3c3275b73f0748301350eacd
Parents: 178588f
Author: Svetoslav Neykov <svetoslav.ney...@cloudsoftcorp.com>
Authored: Fri Apr 7 13:43:59 2017 +0300
Committer: Svetoslav Neykov <svetoslav.ney...@cloudsoftcorp.com>
Committed: Tue Apr 11 17:59:22 2017 +0300

----------------------------------------------------------------------
 .../brooklyn/api/mgmt/ManagementContext.java    | 23 ++++++++++++++++----
 .../mgmt/internal/LocalManagementContext.java   |  9 ++------
 .../NonDeploymentManagementContext.java         |  1 +
 .../mgmt/persist/BrooklynPersistenceUtils.java  |  2 +-
 .../core/mgmt/rebind/ManagementPlaneIdTest.java | 22 ++++++++-----------
 .../transformer/CompoundTransformerTest.java    |  2 +-
 6 files changed, 33 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/cb41895e/api/src/main/java/org/apache/brooklyn/api/mgmt/ManagementContext.java
----------------------------------------------------------------------
diff --git 
a/api/src/main/java/org/apache/brooklyn/api/mgmt/ManagementContext.java 
b/api/src/main/java/org/apache/brooklyn/api/mgmt/ManagementContext.java
index 64e778a..aacc33d 100644
--- a/api/src/main/java/org/apache/brooklyn/api/mgmt/ManagementContext.java
+++ b/api/src/main/java/org/apache/brooklyn/api/mgmt/ManagementContext.java
@@ -67,18 +67,33 @@ public interface ManagementContext {
      * In other words the value of {@link 
Application#getManagementContext()#getManagementPlaneId()} 
      * will generally be constant (in contrast to {@link 
#getManagementNodeId()}).
      * <p>
-     * Throws an {@link NullPointerException} if the value hasn't been 
initialized yet. The value is set:
+     * This value should not be null unless the management context is still 
initialising. The value is set:
      * <ul>
      *   <li>no persistence - during launch
      *   <li>persistence enabled, HA disabled - on rebind (during launch)
      *   <li>persistence enabled, HA enabled - on the first HA state check 
(async to launch)
      * </ul>
+     * 
+     * @deprecated since 0.11.0, use {@link #getOptionalManagementPlaneId()} 
instead.
      */
+    @Deprecated
     String getManagementPlaneId();
 
     /**
-     * Same as {@link #getManagementPlaneId()}, but will return {@link 
Optional#absent()} if the
-     * {@code managementPlaneId} hasn't been initialized yet.
+     * UID for the Brooklyn management plane which this {@link 
ManagementContext} node is a part of.
+     * <p>
+     * Each Brooklyn entity is actively managed by a unique management plane 
+     * whose ID which should not normally change for the duration of that 
entity, 
+     * even though the nodes in that plane might, and the plane may go down 
and come back up. 
+     * In other words the value of {@link 
Application#getManagementContext()#getManagementPlaneId()} 
+     * will generally be constant (in contrast to {@link 
#getManagementNodeId()}).
+     * <p>
+     * Returns absent while the management context is still initialising. The 
value is set:
+     * <ul>
+     *   <li>no persistence - during launch
+     *   <li>persistence enabled, HA disabled - on rebind (during launch)
+     *   <li>persistence enabled, HA enabled - on the first HA state check 
(async to launch)
+     * </ul>
      */
     Optional<String> getOptionalManagementPlaneId();
     
@@ -87,7 +102,7 @@ public interface ManagementContext {
      * <p>
      * No two instances of {@link ManagementContext} should ever have the same 
node UID. 
      * The value of {@link 
Application#getManagementContext()#getManagementNodeId()} may
-     * change many times (in contrast to {@link #getManagementPlaneId()}). 
+     * change many times (in contrast to {@link 
#getOptionalManagementPlaneId()}). 
      * <p>
      * This value should not be null unless the management context is a 
non-functional
      * (non-deployment) instance. */

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/cb41895e/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/LocalManagementContext.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/LocalManagementContext.java
 
b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/LocalManagementContext.java
index 7418666..5a40111 100644
--- 
a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/LocalManagementContext.java
+++ 
b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/LocalManagementContext.java
@@ -211,14 +211,9 @@ public class LocalManagementContext extends 
AbstractManagementContext {
     }
 
     @Override
+    @Deprecated
     public String getManagementPlaneId() {
-        if (managementPlaneId != null) {
-            return managementPlaneId;
-        } else {
-            throw new NullPointerException("managementPlaneId not initialized 
yet. " +
-                    "Either it's too early in the process lifecycle or " +
-                    "ManagementContext hasn't been initialized properly");
-        }
+        return managementPlaneId;
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/cb41895e/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/NonDeploymentManagementContext.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/NonDeploymentManagementContext.java
 
b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/NonDeploymentManagementContext.java
index a839aed..10f49cd 100644
--- 
a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/NonDeploymentManagementContext.java
+++ 
b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/NonDeploymentManagementContext.java
@@ -124,6 +124,7 @@ public class NonDeploymentManagementContext implements 
ManagementContextInternal
     }
 
     @Override
+    @Deprecated
     public String getManagementPlaneId() {
         return (initialManagementContext == null) ? null : 
initialManagementContext.getManagementPlaneId();
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/cb41895e/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/BrooklynPersistenceUtils.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/BrooklynPersistenceUtils.java
 
b/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/BrooklynPersistenceUtils.java
index 4cade20..62030c8 100644
--- 
a/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/BrooklynPersistenceUtils.java
+++ 
b/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/BrooklynPersistenceUtils.java
@@ -163,7 +163,7 @@ public class BrooklynPersistenceUtils {
         MementoSerializer<Object> rawSerializer = new 
XmlMementoSerializer<Object>(mgmt.getClass().getClassLoader());
         RetryingMementoSerializer<Object> serializer = new 
RetryingMementoSerializer<Object>(rawSerializer, 1);
         
-        result.planeId(mgmt.getManagementPlaneId());
+        result.planeId(mgmt.getOptionalManagementPlaneId().orNull());
         for (Location instance: mgmt.getLocationManager().getLocations())
             result.location(instance.getId(), 
serializer.toString(newObjectMemento(instance)));
         for (Entity instance: mgmt.getEntityManager().getEntities()) {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/cb41895e/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/ManagementPlaneIdTest.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/ManagementPlaneIdTest.java
 
b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/ManagementPlaneIdTest.java
index 56ff7c0..22a2371 100644
--- 
a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/ManagementPlaneIdTest.java
+++ 
b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/ManagementPlaneIdTest.java
@@ -19,6 +19,7 @@
 package org.apache.brooklyn.core.mgmt.rebind;
 
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertNotEquals;
 
 import java.io.File;
@@ -75,12 +76,7 @@ public class ManagementPlaneIdTest {
     @Test
     public void testUninitializedThrows() {
         ManagementContext mgmt = new 
LocalManagementContext(BrooklynProperties.Factory.newEmpty());
-        try {
-            mgmt.getManagementPlaneId();
-            Asserts.shouldHaveFailedPreviously("managementPlaneId not 
initialized");
-        } catch (NullPointerException e) {
-            Asserts.expectedFailureContains(e, "not initialized");
-        }
+        assertFalse(mgmt.getOptionalManagementPlaneId().isPresent(), "expected 
managementPlaneId to be absent");
     }
     
     @Test
@@ -113,7 +109,7 @@ public class ManagementPlaneIdTest {
 
         LocalManagementContext rebindMgmt = 
createManagementContext(PersistMode.AUTO, HighAvailabilityMode.DISABLED);
 
-        assertEquals(origMgmt.getManagementPlaneId(), 
rebindMgmt.getManagementPlaneId());
+        assertEquals(origMgmt.getOptionalManagementPlaneId(), 
rebindMgmt.getOptionalManagementPlaneId());
     }
 
 
@@ -135,7 +131,7 @@ public class ManagementPlaneIdTest {
         Asserts.succeedsEventually(new Runnable() {
             @Override
             public void run() {
-                assertEquals(origMgmt.getManagementPlaneId(), 
rebindMgmt.getManagementPlaneId());
+                assertEquals(origMgmt.getOptionalManagementPlaneId(), 
rebindMgmt.getOptionalManagementPlaneId());
             }
         });
     }
@@ -148,7 +144,7 @@ public class ManagementPlaneIdTest {
         Asserts.succeedsEventually(new Runnable() {
             @Override
             public void run() {
-                assertEquals(origMgmt.getManagementPlaneId(), 
rebindMgmt.getManagementPlaneId());
+                assertEquals(origMgmt.getOptionalManagementPlaneId(), 
rebindMgmt.getOptionalManagementPlaneId());
             }
         });
 
@@ -164,7 +160,7 @@ public class ManagementPlaneIdTest {
             }
         });
 
-        assertEquals(origMgmt.getManagementPlaneId(), 
rebindMgmt.getManagementPlaneId());
+        assertEquals(origMgmt.getOptionalManagementPlaneId(), 
rebindMgmt.getOptionalManagementPlaneId());
     }
     
     @Test
@@ -175,7 +171,7 @@ public class ManagementPlaneIdTest {
 
         LocalManagementContext rebindMgmt = 
createManagementContextWithBackups(PersistMode.AUTO, HighAvailabilityMode.AUTO);
 
-        assertEquals(origMgmt.getManagementPlaneId(), 
rebindMgmt.getManagementPlaneId());
+        assertEquals(origMgmt.getOptionalManagementPlaneId(), 
rebindMgmt.getOptionalManagementPlaneId());
 
         String backupContainer = 
BrooklynServerPaths.newBackupPersistencePathResolver(rebindMgmt).resolve();
         
@@ -190,7 +186,7 @@ public class ManagementPlaneIdTest {
         
         File planeIdFile = new File(promotionFolders[0], 
BrooklynMementoPersisterToObjectStore.PLANE_ID_FILE_NAME);
         String planeId = readFile(planeIdFile);
-        assertEquals(origMgmt.getManagementPlaneId(), planeId);
+        assertEquals(origMgmt.getOptionalManagementPlaneId().get(), planeId);
     }
     
     @Test
@@ -239,7 +235,7 @@ public class ManagementPlaneIdTest {
             @Override
             public Void call() throws Exception {
                 String planeId = readFile(planeIdFile);
-                assertEquals(mgmt.getManagementPlaneId(), planeId);
+                assertEquals(mgmt.getOptionalManagementPlaneId().get(), 
planeId);
                 return null;
             }
         });

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/cb41895e/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/transformer/CompoundTransformerTest.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/transformer/CompoundTransformerTest.java
 
b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/transformer/CompoundTransformerTest.java
index b742444..f2b3418 100644
--- 
a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/transformer/CompoundTransformerTest.java
+++ 
b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/transformer/CompoundTransformerTest.java
@@ -169,7 +169,7 @@ public class CompoundTransformerTest extends 
RebindTestFixtureWithApp {
 
         // Assert has expected config/fields
         assertEquals(newApp.getId(), origApp.getId());
-        assertEquals(origManagementContext.getManagementPlaneId(), 
newManagementContext.getManagementPlaneId());
+        assertEquals(origManagementContext.getOptionalManagementPlaneId(), 
newManagementContext.getOptionalManagementPlaneId());
     }
     
     @Test

Reply via email to