Repository: brooklyn-server Updated Branches: refs/heads/master 211e3dcf2 -> c69443942
Adds BrooklynViewerLauncher (for 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/753c3c60 Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/753c3c60 Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/753c3c60 Branch: refs/heads/master Commit: 753c3c608793285aa5adc99e3321bf991253e0e1 Parents: 6e5c2c2 Author: Aled Sage <aled.s...@gmail.com> Authored: Wed Jul 19 10:58:30 2017 +0100 Committer: Aled Sage <aled.s...@gmail.com> Committed: Wed Jul 19 11:03:36 2017 +0100 ---------------------------------------------------------------------- .../brooklyn/launcher/common/BasicLauncher.java | 2 +- .../brooklyn/launcher/BrooklynLauncher.java | 1 + .../launcher/BrooklynViewerLauncher.java | 81 ++++++++++++++++++++ .../blueprints/AbstractBlueprintTest.java | 3 +- 4 files changed, 85 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/753c3c60/launcher-common/src/main/java/org/apache/brooklyn/launcher/common/BasicLauncher.java ---------------------------------------------------------------------- diff --git a/launcher-common/src/main/java/org/apache/brooklyn/launcher/common/BasicLauncher.java b/launcher-common/src/main/java/org/apache/brooklyn/launcher/common/BasicLauncher.java index 03efc5d..04a127b 100644 --- a/launcher-common/src/main/java/org/apache/brooklyn/launcher/common/BasicLauncher.java +++ b/launcher-common/src/main/java/org/apache/brooklyn/launcher/common/BasicLauncher.java @@ -125,7 +125,7 @@ public class BasicLauncher<T extends BasicLauncher<T>> { private Duration haHeartbeatTimeoutOverride = null; private Duration haHeartbeatPeriodOverride = null; - private boolean started; + protected boolean started; private BrooklynProperties.Factory.Builder brooklynPropertiesBuilder; http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/753c3c60/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynLauncher.java ---------------------------------------------------------------------- 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 1dea657..ad399f7 100644 --- a/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynLauncher.java +++ b/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynLauncher.java @@ -74,6 +74,7 @@ import com.google.common.collect.Maps; * .start(); * * Entities.dumpInfo(launcher.getApplications()); + * } * </pre> */ public class BrooklynLauncher extends BasicLauncher<BrooklynLauncher> { http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/753c3c60/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynViewerLauncher.java ---------------------------------------------------------------------- diff --git a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynViewerLauncher.java b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynViewerLauncher.java new file mode 100644 index 0000000..8672916 --- /dev/null +++ b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynViewerLauncher.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.brooklyn.launcher; + +/** + * 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). + * + * An example of where this is very useful is when testing a blueprint where an effector hangs - + * one can visually inspect the app, drilling into the activities view to see what it is doing + * and why it is blocked. + * + * It must be configured with an existing {@link org.apache.brooklyn.api.mgmt.ManagementContext}. + * + * Various other configuration options (e.g. {@link #application(String)) will be ignored. + * + * Example usage is: + * <pre> + * {@code + * protected ManagementContext managementContext; + * protected BrooklynLauncher viewer; + * + * public void setUp() throws Exception { + * managementContext = ... + * viewer = BrooklynViewerLauncher.newInstance() + * .managementContext(managementContext) + * .start(); + * } + * + * public void tearDown() throws Exception { + * if (viewer != null) { + * viewer.terminate(); + * } + * ... + * } + * </pre> + */ +public class BrooklynViewerLauncher extends BrooklynLauncher { + + public static BrooklynViewerLauncher newInstance() { + return new BrooklynViewerLauncher(); + } + + /** + * A cut-down start, which just does the web-apps (intended as a read-only view). It assumes + * that a fully initialised management context will have been registered. + */ + @Override + public BrooklynLauncher start() { + if (started) throw new IllegalStateException("Cannot start() or launch() multiple times"); + started = true; + + if (getManagementContext() == null || !getManagementContext().isRunning()) { + throw new IllegalStateException("Management context must be set, and running"); + } + + startingUp(); + markStartupComplete(); + + initBrooklynNode(); + + return this; + } +} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/753c3c60/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/AbstractBlueprintTest.java ---------------------------------------------------------------------- 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 68ab781..ef3c0e7 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 @@ -41,6 +41,7 @@ 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; @@ -83,7 +84,7 @@ public abstract class AbstractBlueprintTest { }; } }; - viewer = BrooklynLauncher.newInstance() + viewer = BrooklynViewerLauncher.newInstance() .managementContext(mgmt) .start(); }