This is an automated email from the ASF dual-hosted git repository. heneveld pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git
commit 6232b64f99528619ec8108bfec1cfed171155803 Author: Alex Heneveld <[email protected]> AuthorDate: Fri Sep 10 12:46:11 2021 +0100 add method to check if entity is managed by a primary (not readonly) --- .../java/org/apache/brooklyn/core/entity/Entities.java | 18 ++++++++++++++---- .../apache/brooklyn/core/mgmt/ha/HotStandbyTest.java | 15 +++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java b/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java index cd28df8..4bb5835 100644 --- a/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java +++ b/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java @@ -790,7 +790,18 @@ public class Entities { } } + /** As {@link #isManagedOrReadOnly(Entity)}. Consider using {@link #isManagedActive(Entity)} instead. */ public static boolean isManaged(Entity e) { + return isManagedOrReadOnly(e); + } + + /** If entity is under management and the management node is the primary for this entity, i.e. not read-only. */ + public static boolean isManagedActive(Entity e) { + return ((EntityInternal)e).getManagementSupport().isDeployed() && ((EntityInternal)e).getManagementContext().isRunning() && !isReadOnly(e); + } + + /** If entity is under management either as primary or in read-only (hot-standby) state. */ + public static boolean isManagedOrReadOnly(Entity e) { return ((EntityInternal)e).getManagementSupport().isDeployed() && ((EntityInternal)e).getManagementContext().isRunning(); } @@ -798,10 +809,9 @@ public class Entities { return ((EntityInternal)e).getManagementSupport().isNoLongerManaged(); } - /** as {@link EntityManagerInternal#isReadOnly(Entity)} */ - @Beta - public static Boolean isReadOnly(Entity e) { - return ((EntityInternal)e).getManagementSupport().isReadOnly(); + /** if entity is managed, but in a read-only state */ + public static boolean isReadOnly(Entity e) { + return Boolean.TRUE.equals( ((EntityInternal)e).getManagementSupport().isReadOnlyRaw() ); } /** Unwraps a proxy to retrieve the real item, if available. diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/ha/HotStandbyTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/ha/HotStandbyTest.java index ab0e94f..f3bd7fc 100644 --- a/core/src/test/java/org/apache/brooklyn/core/mgmt/ha/HotStandbyTest.java +++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/ha/HotStandbyTest.java @@ -18,6 +18,7 @@ */ package org.apache.brooklyn.core.mgmt.ha; +import java.util.Collection; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; @@ -663,5 +664,19 @@ public class HotStandbyTest { RebindTestFixture.waitForTaskCountToBecome(hsb.mgmt, 5); } + @Test(groups="Integration") // could be promoted to non-integration test if we can guarantee app is present + public void testHotStandbyEntityIsManagedFalse() throws Exception { + HaMgmtNode n1 = createMaster(Duration.PRACTICALLY_FOREVER); + TestApplication app = createFirstAppAndPersist(n1); + forcePersistNow(n1); + Assert.assertTrue(Entities.isManaged(app)); + + final HaMgmtNode hsb = createHotStandby(Duration.millis(10)); + Collection<Application> apps = hsb.mgmt.getApplications(); + Asserts.assertSize(apps, 1); + Assert.assertFalse(Entities.isManagedActive(apps.iterator().next())); + Assert.assertTrue(Entities.isManaged(apps.iterator().next())); + } + }
