brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [02/10] brooklyn-server git commit: fix too-early detection of standby promotion in tests, with definitive mgmt.getNodeState()
Date Wed, 01 Nov 2017 15:50:56 GMT
fix too-early detection of standby promotion in tests, with definitive mgmt.getNodeState()

and make reused OSGi framework the default (much faster) with more tests


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

Branch: refs/heads/master
Commit: 305df9c321818308d58caf80693bc56c4e0d6b1f
Parents: 7b92932
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Mon Oct 30 14:47:34 2017 +0000
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Mon Oct 30 14:55:34 2017 +0000

----------------------------------------------------------------------
 .../brooklyn/api/mgmt/ManagementContext.java    | 10 +++-
 .../api/mgmt/ha/HighAvailabilityManager.java    |  9 +++
 .../catalog/internal/CatalogInitialization.java | 17 +++++-
 .../mgmt/ha/HighAvailabilityManagerImpl.java    |  3 +-
 .../core/mgmt/ha/OsgiArchiveInstaller.java      |  8 +++
 .../brooklyn/core/mgmt/ha/OsgiManager.java      |  7 +++
 .../mgmt/internal/LocalManagementContext.java   | 32 ++++++++--
 .../NonDeploymentManagementContext.java         |  9 +--
 .../core/mgmt/rebind/RebindManagerImpl.java     |  4 ++
 .../BrooklynLauncherRebindCatalogOsgiTest.java  | 61 ++++++++++++--------
 .../java/org/apache/brooklyn/cli/CliTest.java   |  3 +-
 11 files changed, 128 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/305df9c3/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 c1a2c21..2c615ed 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
@@ -32,6 +32,7 @@ import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.api.location.LocationRegistry;
 import org.apache.brooklyn.api.mgmt.entitlement.EntitlementManager;
 import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityManager;
+import org.apache.brooklyn.api.mgmt.ha.ManagementNodeState;
 import org.apache.brooklyn.api.mgmt.rebind.RebindManager;
 import org.apache.brooklyn.api.objs.BrooklynObject;
 import org.apache.brooklyn.api.objs.EntityAdjunct;
@@ -236,11 +237,18 @@ public interface ManagementContext {
      * but some subsystems (e.g. persistence, OSGi, webapps, entities started at startup)
      * may not be available until this returns true.
      * <p>
-     * Also see {@link #isStartupComplete()}.
+     * Also returns false if HA state is transitioning.  See {@link #getNodeState()} to atomically
check node state,
+     * as the preferred way to tell if a node is master.
      */
     @Beta  // see comment on isRunning() as items might move to a status handler
     public boolean isStartupComplete();
 
+    /** Returns node state, always reporting {@link ManagementNodeState#INITIALIZING} if
there is any transition.
+     * If this returns {@link ManagementNodeState#MASTER} we can guarantee the node to be
in master state,
+     * unlike {@link HighAvailabilityManager#getNodeState()} which may return {@link ManagementNodeState#MASTER}
slightly early. 
+     */
+    public ManagementNodeState getNodeState();
+    
     /** Record of configured locations and location resolvers */
     LocationRegistry getLocationRegistry();
     

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/305df9c3/api/src/main/java/org/apache/brooklyn/api/mgmt/ha/HighAvailabilityManager.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/mgmt/ha/HighAvailabilityManager.java
b/api/src/main/java/org/apache/brooklyn/api/mgmt/ha/HighAvailabilityManager.java
index 76002cd..4f7ea8c 100644
--- a/api/src/main/java/org/apache/brooklyn/api/mgmt/ha/HighAvailabilityManager.java
+++ b/api/src/main/java/org/apache/brooklyn/api/mgmt/ha/HighAvailabilityManager.java
@@ -20,6 +20,8 @@ package org.apache.brooklyn.api.mgmt.ha;
 
 import java.util.Map;
 
+import org.apache.brooklyn.api.mgmt.ManagementContext;
+
 import com.google.common.annotations.Beta;
 import com.google.common.annotations.VisibleForTesting;
 
@@ -42,6 +44,13 @@ import com.google.common.annotations.VisibleForTesting;
 @Beta
 public interface HighAvailabilityManager {
 
+    /** Returns the current node state, including {@link ManagementNodeState#INITIALIZING}
on some transitions,
+     * but may return {@link ManagementNodeState#MASTER} before server is persisting.
+     * <p>
+     * See {@link ManagementContext#getNodeState()} to ensure {@link ManagementNodeState#MASTER}
is definitive and ready for use.
+     */
+    // Not sure why this has to return MASTER early, comment in impl says to prevent other
nodes taking it which sounds plausible.
+    // Don't think we should change that behaviour lightly though, hence extra check in ManagementContextInternal.
     ManagementNodeState getNodeState();
     
     /** The time in milliseconds when the state was last changed. -1 if no state transition
has occurred yet.*/

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/305df9c3/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
index 1012d63..9e28b26 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
@@ -46,6 +46,7 @@ import org.apache.brooklyn.core.mgmt.ManagementContextInjectable;
 import org.apache.brooklyn.core.mgmt.ha.OsgiBundleInstallationResult;
 import org.apache.brooklyn.core.mgmt.ha.OsgiManager;
 import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
+import org.apache.brooklyn.core.mgmt.rebind.RebindManagerImpl;
 import org.apache.brooklyn.core.objs.BrooklynTypes;
 import org.apache.brooklyn.core.server.BrooklynServerConfig;
 import org.apache.brooklyn.core.typereg.BundleUpgradeParser;
@@ -382,7 +383,7 @@ public class CatalogInitialization implements ManagementContextInjectable
{
             populateViaInitialBomImpl(catalog);
 
         } catch (Throwable e) {
-            if (!Thread.currentThread().isInterrupted()) {
+            if (!Thread.currentThread().isInterrupted() && !isRebindReadOnlyShuttingDown(getManagementContext()))
{
                 // normal on interruption, esp during tests; only worth remarking here otherwise
(we rethrow in any case)
                 log.warn("Error populating catalog (rethrowing): "+e, e);
             }
@@ -466,10 +467,24 @@ public class CatalogInitialization implements ManagementContextInjectable
{
             
         } catch (Exception e) {
             Exceptions.propagateIfFatal(e);
+            if (isRebindReadOnlyShuttingDown(getManagementContext())) {
+                throw Exceptions.propagate(e);
+            }
+
             log.warn("Error importing catalog from " + catalogUrl + ": " + e, e);
         }
     }
 
+    @Beta
+    public static boolean isRebindReadOnlyShuttingDown(ManagementContext mgmt) {
+        if (mgmt!=null && mgmt.getRebindManager() instanceof RebindManagerImpl) {
+            if (((RebindManagerImpl)mgmt.getRebindManager()).isReadOnlyStopping()) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     private void installPersistedBundles(Map<VersionedName, InstallableManagedBundle>
bundles, RebindExceptionHandler exceptionHandler, RebindLogger rebindLogger) {
         Map<InstallableManagedBundle, OsgiBundleInstallationResult> installs = MutableMap.of();
 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/305df9c3/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/HighAvailabilityManagerImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/HighAvailabilityManagerImpl.java
b/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/HighAvailabilityManagerImpl.java
index dac64a4..1d4d50c 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/HighAvailabilityManagerImpl.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/HighAvailabilityManagerImpl.java
@@ -62,7 +62,6 @@ import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
 import org.apache.brooklyn.core.mgmt.internal.ManagementTransitionMode;
 import org.apache.brooklyn.core.mgmt.persist.BrooklynPersistenceUtils;
 import org.apache.brooklyn.core.mgmt.persist.BrooklynPersistenceUtils.CreateBackupMode;
-import org.apache.brooklyn.core.mgmt.persist.PersistMode;
 import org.apache.brooklyn.core.mgmt.persist.PersistenceActivityMetrics;
 import org.apache.brooklyn.core.mgmt.rebind.RebindManagerImpl;
 import org.apache.brooklyn.core.mgmt.usage.ManagementNodeStateListener;
@@ -868,6 +867,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager
{
                 LOG.warn("Problem in promption-listener (continuing)", e);
             }
         }
+        ((LocalManagementContext)managementContext).noteStartupTransitioning();
         setInternalNodeState(ManagementNodeState.MASTER);
         publishPromotionToMaster();
         try {
@@ -878,6 +878,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager
{
             throw Exceptions.propagate(e);
         }
         managementContext.getRebindManager().start();
+        ((LocalManagementContext)managementContext).noteStartupComplete();
     }
     
     protected void backupOnDemotionIfNeeded() {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/305df9c3/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java
b/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java
index e41ec74..15d847e 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java
@@ -40,8 +40,10 @@ import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.config.ConfigKey;
 import org.apache.brooklyn.core.BrooklynVersion;
 import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog;
+import org.apache.brooklyn.core.catalog.internal.CatalogInitialization;
 import org.apache.brooklyn.core.mgmt.ha.OsgiBundleInstallationResult.ResultCode;
 import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
+import org.apache.brooklyn.core.mgmt.rebind.RebindManagerImpl;
 import org.apache.brooklyn.core.server.BrooklynServerConfig;
 import org.apache.brooklyn.core.typereg.BasicBrooklynTypeRegistry;
 import org.apache.brooklyn.core.typereg.BasicManagedBundle;
@@ -616,6 +618,12 @@ class OsgiArchiveInstaller {
                         } catch (Exception e) {
                             // unable to install new items; rollback bundles
                             // and reload replaced items
+
+                            if (CatalogInitialization.isRebindReadOnlyShuttingDown(osgiManager.mgmt))
{
+                                // very likely when RO mode interrupted - ignore
+                                throw Exceptions.propagate(e);
+                            }
+                            
                             log.warn("Error adding Brooklyn items from bundle "+result.getVersionedName()+",
uninstalling, restoring any old bundle and items, then re-throwing error: "+Exceptions.collapseText(e));
                             try {
                                 rollbackBundle();

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/305df9c3/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java
index e3c0e82..af23f1d 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java
@@ -344,6 +344,13 @@ public class OsgiManager {
         return Maybe.absent();
     }
     
+    @VisibleForTesting
+    public static List<Framework> peekFrameworksForReuse() {
+        synchronized (OSGI_FRAMEWORK_CONTAINERS_FOR_REUSE) {
+            return ImmutableList.copyOf(OSGI_FRAMEWORK_CONTAINERS_FOR_REUSE);
+        }
+    }
+    
     ManagementContext getManagementContext() {
         return mgmt;
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/305df9c3/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 9076845..d6c69d4 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
@@ -43,6 +43,7 @@ import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.api.mgmt.SubscriptionManager;
 import org.apache.brooklyn.api.mgmt.Task;
 import org.apache.brooklyn.api.mgmt.TaskAdaptable;
+import org.apache.brooklyn.api.mgmt.ha.ManagementNodeState;
 import org.apache.brooklyn.core.BrooklynFeatureEnablement;
 import org.apache.brooklyn.core.effector.Effectors;
 import org.apache.brooklyn.core.entity.drivers.downloads.BasicDownloadsManager;
@@ -330,13 +331,13 @@ public class LocalManagementContext extends AbstractManagementContext
{
 
         INSTANCES.remove(this);
         super.terminate();
+        if (usageManager != null) usageManager.terminate();
+        if (execution != null) execution.shutdownNow();
+        if (gc != null) gc.shutdownNow();
         if (osgiManager!=null) {
             osgiManager.stop();
             osgiManager = null;
         }
-        if (usageManager != null) usageManager.terminate();
-        if (execution != null) execution.shutdownNow();
-        if (gc != null) gc.shutdownNow();
 
         log.debug("Terminated management context "+this);
     }
@@ -429,7 +430,30 @@ public class LocalManagementContext extends AbstractManagementContext
{
         reloadListeners.remove(listener);
     }
 
+    private Object startupSynchObject = new Object();
     public void noteStartupComplete() {
-        startupComplete = true;
+        synchronized (startupSynchObject) {
+            startupComplete = true;
+        }
+    }
+    /** Exposed for services to advertise that startup tasks are again occurring */
+    public void noteStartupTransitioning() {
+        synchronized (startupSynchObject) {
+            startupComplete = false;
+        }
+    }
+    @Override
+    public boolean isStartupComplete() {
+        synchronized (startupSynchObject) {
+            return startupComplete;
+        }
+    }
+
+    @Override
+    public ManagementNodeState getNodeState() {
+        synchronized (startupSynchObject) {
+            if (!startupComplete) return ManagementNodeState.INITIALIZING;
+            return getHighAvailabilityManager().getNodeState();
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/305df9c3/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 1fc705c..8f65e62 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
@@ -67,7 +67,6 @@ import org.apache.brooklyn.core.internal.BrooklynProperties;
 import org.apache.brooklyn.core.internal.storage.BrooklynStorage;
 import org.apache.brooklyn.core.mgmt.BrooklynTaskTags;
 import org.apache.brooklyn.core.mgmt.ha.OsgiManager;
-import org.apache.brooklyn.core.mgmt.persist.PersistMode;
 import org.apache.brooklyn.core.mgmt.usage.UsageManager;
 import org.apache.brooklyn.core.objs.proxy.InternalEntityFactory;
 import org.apache.brooklyn.core.objs.proxy.InternalLocationFactory;
@@ -173,13 +172,15 @@ public class NonDeploymentManagementContext implements ManagementContextInternal
     
     @Override
     public boolean isStartupComplete() {
-        // This mgmt context is only used by items who are not yet fully started.
-        // It's slightly misleading as this does not refer to the main mgmt context.
-        // OTOH it probably won't be used.  TBC.  -Alex, Apr 2015
         return false;
     }
 
     @Override
+    public ManagementNodeState getNodeState() {
+        return ManagementNodeState.INITIALIZING;
+    }
+    
+    @Override
     public InternalEntityFactory getEntityFactory() {
         checkInitialManagementContextReal();
         return initialManagementContext.getEntityFactory();

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/305df9c3/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 8a096d4..a42b5d8 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
@@ -220,6 +220,10 @@ public class RebindManagerImpl implements RebindManager {
         return readOnlyRunning;
     }
     
+    public boolean isReadOnlyStopping() {
+        return readOnlyTask!=null && !readOnlyRunning;
+    }
+    
     @Override
     public void setPersister(BrooklynMementoPersister val) {
         PersistenceExceptionHandler exceptionHandler = PersistenceExceptionHandlerImpl.builder()

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/305df9c3/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindCatalogOsgiTest.java
----------------------------------------------------------------------
diff --git a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindCatalogOsgiTest.java
b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindCatalogOsgiTest.java
index bcc46ad..b2e4484 100644
--- a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindCatalogOsgiTest.java
+++ b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindCatalogOsgiTest.java
@@ -53,9 +53,11 @@ import org.osgi.framework.Bundle;
 import org.osgi.framework.launch.Framework;
 import org.testng.Assert;
 import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import com.google.common.base.Joiner;
+import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
@@ -76,10 +78,12 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
      * Whether we reuse OSGi Framework depends if we want it to feel like rebinding on a
new machine 
      * (so no cached bundles), or a local restart. We can also use {@code reuseOsgi = true}
to emulate
      * system bundles (by pre-installing them into the reused framework at the start of the
test).
+     * 
+     * Default true because this speeds things up, but some fixtures run with it false.
      */
-    protected boolean reuseOsgi = false;
+    protected boolean reuseOsgi = true;
     
-    protected List<Bundle> reusedBundles = new ArrayList<>();
+    protected List<Bundle> manuallyInsertedBundles = new ArrayList<>();
     
     BrooklynLauncher launcherT1, launcherT2, launcherLast;
     Runnable startupAssertions;
@@ -92,13 +96,16 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
         try {
             launcherT1 = null; launcherT2 = null; launcherLast = null;
             startupAssertions = null;
-            reuseOsgi = false;
-            for (Bundle bundle : reusedBundles) {
+            reuseOsgi = true;
+            
+            // OSGi reuse system will clear cache on framework no longer being used,
+            // but we've installed out of band so need to clean it up ourselves if the test
doesn't actually use it!
+            for (Bundle bundle : manuallyInsertedBundles) {
                 if (bundle != null && bundle.getState() != Bundle.UNINSTALLED) {
                     bundle.uninstall();
                 }
             }
-            reusedBundles.clear();
+            manuallyInsertedBundles.clear();
         } finally {
             super.tearDown();
         }
@@ -146,6 +153,7 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
             l.highAvailabilityMode(HighAvailabilityMode.HOT_STANDBY);
         }
         l.start();
+        Framework f = ((ManagementContextInternal)l.getManagementContext()).getOsgiManager().get().getFramework();
         launcherLast = launcherT2 = l;
         if (isT1KeptRunningWhenT2Starts()) {
             assertHotStandbyNow(launcherT2);
@@ -197,12 +205,10 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends
AbstractBroo
 
             File initialBomFile = newTmpFile(createCatalogYaml(ImmutableList.of(bundleFile.toURI()),
ImmutableList.of()));
 
-            reuseOsgi = true;
-            
             // Add our bundle, so it feels for all intents and purposes like a "system bundle"
             Framework reusedFramework = initReusableOsgiFramework();
             Bundle pseudoSystemBundle = installBundle(reusedFramework, bundleFileCopy);
-            reusedBundles.add(pseudoSystemBundle);
+            manuallyInsertedBundles.add(pseudoSystemBundle);
             
             startupAssertions = () -> {
                 assertCatalogConsistsOfIds(launcherLast, bundleItems);
@@ -228,12 +234,10 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends
AbstractBroo
             File bundleFile = newTmpBundle(bundleItems, bundleName);
             File bundleFileCopy = newTmpCopy(bundleFile);
 
-            reuseOsgi = true;
-            
             // Add our bundle, so it feels for all intents and purposes like a "system bundle"
             Framework reusedFramework = initReusableOsgiFramework();
             Bundle pseudoSystemBundle = installBundle(reusedFramework, bundleFileCopy);
-            reusedBundles.add(pseudoSystemBundle);
+            manuallyInsertedBundles.add(pseudoSystemBundle);
             
             // Launch brooklyn, and explicitly install pre-existing bundle.
             // Should bring it under brooklyn-management (should not re-install it).
@@ -266,12 +270,11 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends
AbstractBroo
             
             File initialBomFile = newTmpFile(createCatalogYaml(ImmutableList.of(bundleFile.toURI()),
ImmutableList.of()));
             
-            reuseOsgi = true;
-            
+            Preconditions.checkArgument(reuseOsgi, "Should be reusing OSGi; test did not
correctly reset it.");
             // Add our bundle, so it feels for all intents and purposes like a "system bundle"
             Framework reusedFramework = initReusableOsgiFramework();
             Bundle pseudoSystemBundle = installBundle(reusedFramework, systemBundleFile);
-            reusedBundles.add(pseudoSystemBundle);
+            manuallyInsertedBundles.add(pseudoSystemBundle);
             
             startupAssertions = () -> {
                 assertOnlyBundle(launcherLast, systemBundleName, pseudoSystemBundle);
@@ -314,12 +317,10 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends
AbstractBroo
             }
             File initialBomFile = newTmpFile(createCatalogYaml(ImmutableList.of(), ImmutableList.of(systemBundleNameRef),
ImmutableList.of()));
             
-            reuseOsgi = true;
-            
             // Add our bundle, so it feels for all intents and purposes like a "system bundle"
             Framework reusedFramework = initReusableOsgiFramework();
             Bundle pseudoSystemBundle = installBundle(reusedFramework, systemBundleFile);
-            reusedBundles.add(pseudoSystemBundle);
+            manuallyInsertedBundles.add(pseudoSystemBundle);
             
             startupAssertions = () -> {
                 assertOnlyBundle(launcherLast, systemBundleName, pseudoSystemBundle);
@@ -352,13 +353,10 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends
AbstractBroo
             File systemBundleFile = newTmpBundle(bundleItems, bundleName);
             File replacementBundleFile = newTmpBundle(bundleItems, bundleName, "randomDifference"+Identifiers.makeRandomId(4));
 
-            reuseOsgi = true;
-            
             // Add our bundle, so it feels for all intents and purposes like a "system bundle"
             Framework reusedFramework = initReusableOsgiFramework();
             Bundle pseudoSystemBundle = installBundle(reusedFramework, systemBundleFile);
-            reusedBundles.add(pseudoSystemBundle);
-            
+            manuallyInsertedBundles.add(pseudoSystemBundle);
             
             // Launch brooklyn, and explicitly install pre-existing bundle.
             // Should bring it under brooklyn-management (should not re-install it).
@@ -383,6 +381,23 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
         @Override protected boolean isT1KeptRunningWhenT2Starts() { return true; }
     }
 
+    public abstract static class AbstractNonReuseRebindSubTests extends BrooklynLauncherRebindCatalogOsgiTest
{
+        @BeforeMethod(alwaysRun=true)
+        @Override
+        public void setUp() throws Exception {
+            super.setUp();
+            //reuseOsgi = false;
+        }
+    }
+    @Test(groups="Integration")
+    public static class NonReuseRebindSubTests extends AbstractNonReuseRebindSubTests {
+        @Override protected boolean isT1KeptRunningWhenT2Starts() { return false; }
+    }
+    @Test(groups="Integration")
+    public static class HotStandbyNonReuseRebindSubTests extends AbstractNonReuseRebindSubTests
{
+        @Override protected boolean isT1KeptRunningWhenT2Starts() { return false; }
+    }
+    
     @Test
     public void testRebindGetsInitialOsgiCatalog() throws Exception {
         Set<VersionedName> bundleItems = ImmutableSet.of(VersionedName.fromString("one:1.0.0"));
@@ -606,7 +621,7 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
         ManagementContext mgmt = launcher.getManagementContext();
         assertTrue(mgmt.isStartupComplete());
         assertTrue(mgmt.isRunning());
-        assertEquals(mgmt.getHighAvailabilityManager().getNodeState(), ManagementNodeState.HOT_STANDBY);
+        assertEquals(mgmt.getNodeState(), ManagementNodeState.HOT_STANDBY);
     }
     
     protected void assertMasterEventually(BrooklynLauncher launcher) {
@@ -615,7 +630,7 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
             public void run() {
                 assertTrue(mgmt.isStartupComplete());
                 assertTrue(mgmt.isRunning());
-                assertEquals(mgmt.getHighAvailabilityManager().getNodeState(), ManagementNodeState.MASTER);
+                assertEquals(mgmt.getNodeState(), ManagementNodeState.MASTER);
             }});
     }
     

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/305df9c3/server-cli/src/test/java/org/apache/brooklyn/cli/CliTest.java
----------------------------------------------------------------------
diff --git a/server-cli/src/test/java/org/apache/brooklyn/cli/CliTest.java b/server-cli/src/test/java/org/apache/brooklyn/cli/CliTest.java
index 58b8874..07e63b6 100644
--- a/server-cli/src/test/java/org/apache/brooklyn/cli/CliTest.java
+++ b/server-cli/src/test/java/org/apache/brooklyn/cli/CliTest.java
@@ -47,6 +47,7 @@ import org.apache.brooklyn.api.entity.ImplementedBy;
 import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.api.location.LocationSpec;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
+import org.apache.brooklyn.api.mgmt.ha.ManagementNodeState;
 import org.apache.brooklyn.cli.AbstractMain.BrooklynCommand;
 import org.apache.brooklyn.cli.AbstractMain.BrooklynCommandCollectingArgs;
 import org.apache.brooklyn.cli.AbstractMain.DefaultInfoCommand;
@@ -54,7 +55,6 @@ import org.apache.brooklyn.cli.AbstractMain.HelpCommand;
 import org.apache.brooklyn.cli.Main.AppShutdownHandler;
 import org.apache.brooklyn.cli.Main.GeneratePasswordCommand;
 import org.apache.brooklyn.cli.Main.LaunchCommand;
-import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
 import org.apache.brooklyn.core.entity.AbstractApplication;
 import org.apache.brooklyn.core.entity.AbstractEntity;
 import org.apache.brooklyn.core.entity.Entities;
@@ -456,6 +456,7 @@ public class CliTest {
                         @Override
                         public void run() {
                             assertTrue(mgmt.isStartupComplete());
+                            assertEquals(mgmt.getNodeState(), ManagementNodeState.MASTER);
                         }});
                 }
             });


Mime
View raw message