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 2021/08/04 11:55:38 UTC
[brooklyn-server] branch master updated: blueprint tests with
viewer simplification
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
The following commit(s) were added to refs/heads/master by this push:
new 7089dd8 blueprint tests with viewer simplification
new 963b9dd Merge branch 'master' of https://gitbox.apache.org/repos/asf/brooklyn-server
7089dd8 is described below
commit 7089dd8b6d32fc8b3b529d6619f876b24d36e32c
Author: Alex Heneveld <al...@cloudsoftcorp.com>
AuthorDate: Wed Aug 4 12:54:32 2021 +0100
blueprint tests with viewer simplification
only opens 1 port, not 3, and fixes viewer after rebinding,
allowing multiple viewers if desired
---
.../apache/brooklyn/launcher/BrooklynLauncher.java | 18 +++--
.../camp/BrooklynCampPlatformLauncher.java | 21 ++----
.../brooklyn/launcher/BrooklynViewerLauncher.java | 19 ++---
.../launcher/blueprints/AbstractBlueprintTest.java | 82 ++++++++++++++++------
.../launcher/blueprints/SimpleBlueprintTest.java | 13 ++++
5 files changed, 99 insertions(+), 54 deletions(-)
diff --git a/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynLauncher.java b/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynLauncher.java
index a56d6dd..46cee52 100644
--- a/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynLauncher.java
+++ b/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynLauncher.java
@@ -381,13 +381,7 @@ public class BrooklynLauncher extends BasicLauncher<BrooklynLauncher> {
public void terminate() {
if (!isStarted()) return; // no-op
- if (webServer != null) {
- try {
- webServer.stop();
- } catch (Exception e) {
- LOG.warn("Error stopping web-server; continuing with termination", e);
- }
- }
+ terminateWebServer();
ManagementContext managementContext = getManagementContext();
@@ -423,6 +417,16 @@ public class BrooklynLauncher extends BasicLauncher<BrooklynLauncher> {
}
}
+ protected void terminateWebServer() {
+ if (webServer != null) {
+ try {
+ webServer.stop();
+ } catch (Exception e) {
+ LOG.warn("Error stopping web-server; continuing with termination", e);
+ }
+ }
+ }
+
public BrooklynLauncher globalBrooklynPropertiesFile(String file) {
globalBrooklynPropertiesFile = file;
return this;
diff --git a/launcher/src/main/java/org/apache/brooklyn/launcher/camp/BrooklynCampPlatformLauncher.java b/launcher/src/main/java/org/apache/brooklyn/launcher/camp/BrooklynCampPlatformLauncher.java
index a983087..abfa027 100644
--- a/launcher/src/main/java/org/apache/brooklyn/launcher/camp/BrooklynCampPlatformLauncher.java
+++ b/launcher/src/main/java/org/apache/brooklyn/launcher/camp/BrooklynCampPlatformLauncher.java
@@ -38,19 +38,16 @@ public class BrooklynCampPlatformLauncher extends BrooklynCampPlatformLauncherAb
@Override
public BrooklynCampPlatformLauncher launch() {
- assert platform == null;
+ if (getBrooklynMgmt()==null)
+ useManagementContext(newMgmtContext());
- mgmt = getManagementContextForLauncher();
-
// We created the management context, so we are responsible for terminating it
BrooklynShutdownHooks.invokeTerminateOnShutdown(mgmt);
brooklynLauncher = getBrooklynLauncherStarted(mgmt);
- platform = new BrooklynCampPlatform(
- PlatformRootSummary.builder().name("Brooklyn CAMP Platform").build(),
- mgmt)
- .setConfigKeyAtManagmentContext();
-
+
+ super.launch();
+
campServer = new CampServer(getCampPlatform(), "").start();
return this;
@@ -60,14 +57,6 @@ public class BrooklynCampPlatformLauncher extends BrooklynCampPlatformLauncherAb
return BrooklynLauncher.newInstance().managementContext(mgmt).start();
}
- protected ManagementContext newManagementContext() {
- return new LocalManagementContext();
- }
-
- protected ManagementContext getManagementContextForLauncher() {
- return newManagementContext();
- }
-
public static void main(String[] args) {
new BrooklynCampPlatformLauncher().launch();
}
diff --git a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynViewerLauncher.java b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynViewerLauncher.java
index a06a0de..56a9a73 100644
--- a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynViewerLauncher.java
+++ b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynViewerLauncher.java
@@ -19,7 +19,9 @@
package org.apache.brooklyn.launcher;
/**
- * A convenience for started the Brooklyn REST api and web-app in a test, so that one can visually
+ * Starts a viewing instance on an already-started management context - skipping catalog etc.
+ *
+ * This is a convenience for started the Brooklyn REST api and web-app in a test, so that one can visually
* inspect the app that the test creates. This is intended as a read-only view (but it has the real
* management context so one can perform actions through this UI).
*
@@ -67,12 +69,17 @@ public class BrooklynViewerLauncher extends BrooklynLauncher {
if (started) throw new IllegalStateException("Cannot start() or launch() multiple times");
started = true;
- startViewer();
+ startViewerOnly();
return this;
}
- protected void startViewer() {
+ @Override
+ public void terminate() {
+ terminateWebServer();
+ }
+
+ protected void startViewerOnly() {
if (getManagementContext() == null || !getManagementContext().isRunning()) {
throw new IllegalStateException("Management context must be set, and running");
}
@@ -83,10 +90,4 @@ public class BrooklynViewerLauncher extends BrooklynLauncher {
initBrooklynNode();
}
- public BrooklynLauncher startBrooklynAndViewer() {
- super.start();
- startViewer();
- return this;
- }
-
}
diff --git a/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/AbstractBlueprintTest.java b/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/AbstractBlueprintTest.java
index 23a3e94..7d6bcc4 100644
--- a/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/AbstractBlueprintTest.java
+++ b/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/AbstractBlueprintTest.java
@@ -18,8 +18,12 @@
*/
package org.apache.brooklyn.launcher.blueprints;
+import java.util.Set;
import java.util.function.Consumer;
+import org.apache.brooklyn.camp.brooklyn.BrooklynCampPlatformLauncherNoServer;
import org.apache.brooklyn.core.mgmt.persist.PersistMode;
+import org.apache.brooklyn.core.mgmt.rebind.RebindManagerImpl;
+import org.apache.brooklyn.util.collections.MutableSet;
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertTrue;
@@ -42,10 +46,8 @@ import org.apache.brooklyn.core.mgmt.persist.FileBasedObjectStore;
import org.apache.brooklyn.core.mgmt.rebind.RebindOptions;
import org.apache.brooklyn.core.mgmt.rebind.RebindTestUtils;
import org.apache.brooklyn.entity.software.base.SoftwareProcess;
-import org.apache.brooklyn.launcher.BrooklynLauncher;
import org.apache.brooklyn.launcher.BrooklynViewerLauncher;
import org.apache.brooklyn.launcher.SimpleYamlLauncherForTests;
-import org.apache.brooklyn.launcher.camp.BrooklynCampPlatformLauncher;
import org.apache.brooklyn.test.Asserts;
import org.apache.brooklyn.util.core.ResourceUtils;
import org.apache.brooklyn.util.os.Os;
@@ -67,41 +69,64 @@ public abstract class AbstractBlueprintTest {
protected ManagementContext mgmt;
protected SimpleYamlLauncherForTests launcher;
- protected BrooklynViewerLauncher viewer;
+ protected Set<BrooklynViewerLauncher> viewers = MutableSet.of();
@BeforeMethod(alwaysRun=true)
public void setUp() throws Exception {
mementoDir = Os.newTempDir(getClass());
mgmt = createOrigManagementContext();
+
+ // required for REST access - otherwise it is viewed as not yet ready
+ ((RebindManagerImpl)mgmt.getRebindManager()).setAwaitingInitialRebind(false);
+
LOG.info("Test "+getClass()+" persisting to "+mementoDir);
+ startViewer(true);
+
launcher = new SimpleYamlLauncherForTests() {
@Override
protected BrooklynCampPlatformLauncherAbstract newPlatformLauncher() {
- return new BrooklynCampPlatformLauncher() {
+ return new BrooklynCampPlatformLauncherNoServer() {
@Override
- protected ManagementContext getManagementContextForLauncher() {
- return AbstractBlueprintTest.this.mgmt;
- }
-
- @Override
- protected BrooklynLauncher getBrooklynLauncherStarted(ManagementContext mgmt) {
- if (viewer!=null) {
- throw new IllegalStateException("Viewer already running");
- }
- viewer = BrooklynViewerLauncher.newInstance();
- viewer.managementContext(mgmt);
-
- // other persistence options come from mgmt console but launcher needs to know this:
- viewer.persistMode(PersistMode.AUTO);
-
- return viewer.startBrooklynAndViewer();
+ public BrooklynCampPlatformLauncherAbstract launch() {
+ useManagementContext(AbstractBlueprintTest.this.mgmt);
+ return super.launch();
}
};
}
};
}
+ protected void startViewer(boolean killCurrent) {
+ if (isViewerEnabled()) {
+ if (killCurrent) {
+ // typically we kill the old and restart on the same port during rebind;
+ // the old mgmt context is no longer active so isn't useful;
+ // but if we wanted to have multiple viewers we could
+ stopAllViewers();
+ }
+
+ BrooklynViewerLauncher viewer = BrooklynViewerLauncher.newInstance();
+ synchronized (viewers) {
+ viewers.add(viewer);
+ }
+
+ viewer.managementContext(mgmt);
+
+ // other persistence options come from mgmt console but launcher needs to know this:
+ viewer.persistMode(PersistMode.AUTO);
+
+ viewer.start();
+ }
+ }
+
+ protected void stopAllViewers() {
+ synchronized (viewers) {
+ viewers.forEach(BrooklynViewerLauncher::terminate);
+ viewers.clear();
+ }
+ }
+
@AfterMethod(alwaysRun=true)
public void tearDown() throws Exception {
try {
@@ -117,7 +142,7 @@ public abstract class AbstractBlueprintTest {
}
}
if (launcher != null) launcher.destroyAll();
- if (viewer != null) viewer.terminate();
+ if (viewers!=null) stopAllViewers();
if (mgmt != null) Entities.destroyAll(mgmt);
if (mementoDir != null) FileBasedObjectStore.deleteCompletely(mementoDir);
} catch (Throwable t) {
@@ -241,10 +266,23 @@ public abstract class AbstractBlueprintTest {
}
mgmt = options.newManagementContext;
+
+ startViewer(!isUsingNewViewerForRebind());
+
Application newApp = RebindTestUtils.rebind(options);
return newApp;
}
-
+
+ /** override this to specify whether you want a viewer created (for testing) */
+ protected boolean isViewerEnabled() {
+ return true;
+ }
+
+ /** override this to return true if you want separate viewers for pre- and post- rebind */
+ protected boolean isUsingNewViewerForRebind() {
+ return false;
+ }
+
/** @return A started management context */
protected LocalManagementContext createOrigManagementContext() {
return RebindTestUtils.managementContextBuilder(mementoDir, classLoader)
diff --git a/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/SimpleBlueprintTest.java b/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/SimpleBlueprintTest.java
index 0ac668c..b1d3f75 100644
--- a/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/SimpleBlueprintTest.java
+++ b/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/SimpleBlueprintTest.java
@@ -25,10 +25,23 @@ import org.testng.annotations.Test;
public class SimpleBlueprintTest extends AbstractBlueprintTest {
+ @Override
+ protected boolean isViewerEnabled() {
+ return true;
+ }
+
+ @Override
+ protected boolean isUsingNewViewerForRebind() {
+ return true;
+ }
+
// only Live because it starts a server
@Test(groups={"Live"})
public void testBasicEntity() throws Exception {
Application app = runTestOnBlueprint("services: [ { type: " + BasicEntity.class.getName() + " } ]");
+
+ // stick a breakpoint on the following line (make sure it is thread-only, not all-threads!)
+ // then connect a UI eg brooklyn-ui/app-inspector `make dev` to the API endpoint used
Dumper.dumpInfo(app);
}