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 2017/11/01 15:50:55 UTC
[01/10] brooklyn-server git commit: remove code duplication in tests,
run more standby
Repository: brooklyn-server
Updated Branches:
refs/heads/master 43a861c49 -> 48f090071
remove code duplication in tests, run more standby
refactor using fixtures to run more tests in both terminate-then-rebind and standby-promote modes,
without duplicating assertions
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/7b929320
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/7b929320
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/7b929320
Branch: refs/heads/master
Commit: 7b92932009453c22f62e97310a411893e116dd6f
Parents: 43a861c
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Mon Oct 30 10:21:39 2017 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Mon Oct 30 10:21:39 2017 +0000
----------------------------------------------------------------------
.../catalog/internal/CatalogInitialization.java | 5 +-
.../BrooklynLauncherRebindCatalogOsgiTest.java | 681 ++++++++++---------
2 files changed, 364 insertions(+), 322 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/7b929320/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 faa3b92..1012d63 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
@@ -382,7 +382,10 @@ public class CatalogInitialization implements ManagementContextInjectable {
populateViaInitialBomImpl(catalog);
} catch (Throwable e) {
- log.warn("Error populating catalog (rethrowing): "+e, e);
+ if (!Thread.currentThread().isInterrupted()) {
+ // normal on interruption, esp during tests; only worth remarking here otherwise (we rethrow in any case)
+ log.warn("Error populating catalog (rethrowing): "+e, e);
+ }
throw Exceptions.propagate(e);
} finally {
isPopulatingInitial = false;
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/7b929320/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 e9c7a07..bcc46ad 100644
--- a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindCatalogOsgiTest.java
+++ b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindCatalogOsgiTest.java
@@ -34,7 +34,6 @@ import org.apache.brooklyn.api.mgmt.ManagementContext;
import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityMode;
import org.apache.brooklyn.api.mgmt.ha.ManagementNodeState;
import org.apache.brooklyn.api.objs.BrooklynObjectType;
-import org.apache.brooklyn.api.typereg.ManagedBundle;
import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog;
import org.apache.brooklyn.core.catalog.internal.CatalogInitialization;
import org.apache.brooklyn.core.mgmt.ha.OsgiBundleInstallationResult;
@@ -52,6 +51,7 @@ import org.apache.brooklyn.util.osgi.VersionedName;
import org.apache.brooklyn.util.text.Identifiers;
import org.osgi.framework.Bundle;
import org.osgi.framework.launch.Framework;
+import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
@@ -61,7 +61,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
-public class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBrooklynLauncherRebindTest {
+public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBrooklynLauncherRebindTest {
private static final String CATALOG_EMPTY_INITIAL = "classpath://rebind-test-empty-catalog.bom";
@@ -77,14 +77,21 @@ public class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBrooklynLaunc
* (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).
*/
- private boolean reuseOsgi = false;
+ protected boolean reuseOsgi = false;
- private List<Bundle> reusedBundles = new ArrayList<>();
+ protected List<Bundle> reusedBundles = new ArrayList<>();
+
+ BrooklynLauncher launcherT1, launcherT2, launcherLast;
+ Runnable startupAssertions;
+
+ protected abstract boolean isT1KeptRunningWhenT2Starts();
@AfterMethod(alwaysRun=true)
@Override
public void tearDown() throws Exception {
try {
+ launcherT1 = null; launcherT2 = null; launcherLast = null;
+ startupAssertions = null;
reuseOsgi = false;
for (Bundle bundle : reusedBundles) {
if (bundle != null && bundle.getState() != Bundle.UNINSTALLED) {
@@ -107,253 +114,292 @@ public class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBrooklynLaunc
return reuseOsgi;
}
- private BrooklynLauncher newLauncherForTests(String catalogInitial) {
+ protected BrooklynLauncher newLauncherForTests(String catalogInitial) {
CatalogInitialization catalogInitialization = new CatalogInitialization(catalogInitial);
return super.newLauncherForTests()
.catalogInitialization(catalogInitialization);
- }
-
- @Test
- public void testRebindGetsInitialOsgiCatalog() throws Exception {
- Set<VersionedName> bundleItems = ImmutableSet.of(VersionedName.fromString("one:1.0.0"));
- String bundleBom = createCatalogYaml(ImmutableList.of(), bundleItems);
- VersionedName bundleName = new VersionedName("org.example.testRebindGetsInitialOsgiCatalog", "1.0.0");
- File bundleFile = newTmpBundle(ImmutableMap.of(BasicBrooklynCatalog.CATALOG_BOM, bundleBom.getBytes(StandardCharsets.UTF_8)), bundleName);
- File initialBomFile = newTmpFile(createCatalogYaml(ImmutableList.of(bundleFile.toURI()), ImmutableList.of()));
+ }
+
+ protected void startT1(BrooklynLauncher l) {
+ if (launcherT1!=null) throw new IllegalStateException("Already started T1 launcher");
- BrooklynLauncher launcher = newLauncherForTests(initialBomFile.getAbsolutePath());
- launcher.start();
- assertCatalogConsistsOfIds(launcher, bundleItems);
- assertManagedBundle(launcher, bundleName, bundleItems);
-
- launcher.terminate();
-
- BrooklynLauncher newLauncher = newLauncherForTests(initialBomFile.getAbsolutePath());
- newLauncher.start();
- assertCatalogConsistsOfIds(newLauncher, bundleItems);
- assertManagedBundle(newLauncher, bundleName, bundleItems);
- }
-
- /**
- * See https://issues.apache.org/jira/browse/BROOKLYN-546.
- *
- * We built up to launcher2, which will have three things:
- * 1. a pre-installed "system bundle"
- * 2. an initial catalog that references this same system bundle (hence the bundle will be "managed")
- * 3. persisted state that references this same system bundle.
- *
- * At the end of this, we want only one version of that "system bundle" to be installed, but also for
- * it to be a "brooklyn managed bundle".
- *
- * This scenario isn't quite the same as BROOKLYN-546. To make it fail, we'd need to have bundle URLs like:
- * "mvn:org.apache.brooklyn/brooklyn-software-cm-ansible/1.0.0-SNAPSHOT"
- * (as is used in brooklyn-library/karaf/catalog/target/classes/catalog.bom).
- *
- * When that is used, the "osgi unique url" is the same as for the system library, so when it tries
- * to replace the library by calling "installBundle" then it fails.
- *
- * We ensure this isn't happening by asserting that our manually installed "system bundle" is still the same.
- */
- @Test
- public void testRebindWithSystemBundleInCatalog() throws Exception {
- Set<VersionedName> bundleItems = ImmutableSet.of(VersionedName.fromString("one:1.0.0-SNAPSHOT"));
- VersionedName bundleName = new VersionedName("org.example.brooklynLauncherRebindCatalogOsgiTest."+Identifiers.makeRandomId(4), "1.0.0.SNAPSHOT");
- File bundleFile = newTmpBundle(bundleItems, bundleName);
- File bundleFileCopy = newTmpCopy(bundleFile);
-
- File initialBomFile = newTmpFile(createCatalogYaml(ImmutableList.of(bundleFile.toURI()), ImmutableList.of()));
-
- reuseOsgi = true;
+ if (isT1KeptRunningWhenT2Starts()) {
+ l.highAvailabilityMode(HighAvailabilityMode.MASTER);
+ }
+ l.start();
+ launcherLast = launcherT1 = l;
- // 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);
+ if (startupAssertions!=null) startupAssertions.run();
+ }
+
+ protected void startT2(BrooklynLauncher l) {
+ if (launcherT2!=null) throw new IllegalStateException("Already started T2 launcher");
- // Launch brooklyn, where initial catalog includes a duplicate of the system bundle
- BrooklynLauncher launcher = newLauncherForTests(initialBomFile.getAbsolutePath());
- launcher.start();
- assertCatalogConsistsOfIds(launcher, bundleItems);
- assertManagedBundle(launcher, bundleName, bundleItems);
- launcher.terminate();
-
- // Launch brooklyn, where persisted state now includes the initial catalog's bundle
- BrooklynLauncher launcher2 = newLauncherForTests(initialBomFile.getAbsolutePath());
- launcher2.start();
- assertCatalogConsistsOfIds(launcher2, bundleItems);
- assertManagedBundle(launcher2, bundleName, bundleItems);
+ try {
+ RebindTestUtils.waitForPersisted(launcherT1.getManagementContext());
+ } catch (Exception e) {
+ throw Exceptions.propagate(e);
+ }
+ if (!isT1KeptRunningWhenT2Starts()) {
+ launcherT1.terminate();
+ } else {
+ l.highAvailabilityMode(HighAvailabilityMode.HOT_STANDBY);
+ }
+ l.start();
+ launcherLast = launcherT2 = l;
+ if (isT1KeptRunningWhenT2Starts()) {
+ assertHotStandbyNow(launcherT2);
+ }
- // Should not have replaced the original "system bundle"
- assertOnlyBundle(reusedFramework, bundleName, pseudoSystemBundle);
-
- launcher2.terminate();
+ if (startupAssertions!=null) startupAssertions.run();
}
-
+ protected void promoteT2IfStandby() {
+ if (isT1KeptRunningWhenT2Starts()) {
+ launcherT1.terminate();
+ assertMasterEventually(launcherT2);
+
+ if (startupAssertions!=null) startupAssertions.run();
+ }
+ }
+
@Test
- public void testInstallPreexistingBundle() throws Exception {
- Set<VersionedName> bundleItems = ImmutableSet.of(VersionedName.fromString("one:1.0.0-SNAPSHOT"));
- VersionedName bundleName = new VersionedName("org.example.brooklynLauncherRebindCatalogOsgiTest."+Identifiers.makeRandomId(4), "1.0.0.SNAPSHOT");
- File bundleFile = newTmpBundle(bundleItems, bundleName);
- File bundleFileCopy = newTmpCopy(bundleFile);
-
- reuseOsgi = true;
+ public static class LauncherRebindSubTests extends BrooklynLauncherRebindCatalogOsgiTest {
+ @Override protected boolean isT1KeptRunningWhenT2Starts() { return false; }
- // 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);
+ // tests here should run only for straight rebind as they assume a reused framework
- // Launch brooklyn, and explicitly install pre-existing bundle.
- // Should bring it under brooklyn-management (should not re-install it).
- BrooklynLauncher launcher = newLauncherForTests(CATALOG_EMPTY_INITIAL);
- launcher.start();
- installBrooklynBundle(launcher, bundleFile, false).getWithError();
+ /**
+ * See https://issues.apache.org/jira/browse/BROOKLYN-546.
+ *
+ * We built up to launcher2, which will have three things:
+ * 1. a pre-installed "system bundle"
+ * 2. an initial catalog that references this same system bundle (hence the bundle will be "managed")
+ * 3. persisted state that references this same system bundle.
+ *
+ * At the end of this, we want only one version of that "system bundle" to be installed, but also for
+ * it to be a "brooklyn managed bundle".
+ *
+ * This scenario isn't quite the same as BROOKLYN-546. To make it fail, we'd need to have bundle URLs like:
+ * "mvn:org.apache.brooklyn/brooklyn-software-cm-ansible/1.0.0-SNAPSHOT"
+ * (as is used in brooklyn-library/karaf/catalog/target/classes/catalog.bom).
+ *
+ * When that is used, the "osgi unique url" is the same as for the system library, so when it tries
+ * to replace the library by calling "installBundle" then it fails.
+ *
+ * We ensure this isn't happening by asserting that our manually installed "system bundle" is still the same.
+ */
+ @Test
+ public void testRebindWithSystemBundleInCatalog() throws Exception {
+ Set<VersionedName> bundleItems = ImmutableSet.of(VersionedName.fromString("one:1.0.0-SNAPSHOT"));
+ VersionedName bundleName = new VersionedName("org.example.brooklynLauncherRebindCatalogOsgiTest."+Identifiers.makeRandomId(4), "1.0.0.SNAPSHOT");
+ File bundleFile = newTmpBundle(bundleItems, bundleName);
+ File bundleFileCopy = newTmpCopy(bundleFile);
+
+ 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);
+
+ startupAssertions = () -> {
+ assertCatalogConsistsOfIds(launcherLast, bundleItems);
+ assertManagedBundle(launcherLast, bundleName, bundleItems);
+ };
+
+ // Launch brooklyn, where initial catalog includes a duplicate of the system bundle
+ startT1(newLauncherForTests(initialBomFile.getAbsolutePath()));
+
+ // Launch brooklyn, where persisted state now includes the initial catalog's bundle
+ startT2(newLauncherForTests(initialBomFile.getAbsolutePath()));
+
+ // Should not have replaced the original "system bundle"
+ assertOnlyBundle(reusedFramework, bundleName, pseudoSystemBundle);
+
+ launcherT2.terminate();
+ }
- assertOnlyBundle(launcher, bundleName, pseudoSystemBundle);
- assertCatalogConsistsOfIds(launcher, bundleItems);
- assertManagedBundle(launcher, bundleName, bundleItems);
- launcher.terminate();
-
- // Launch brooklyn again (because will have persisted the pre-installed bundle)
- BrooklynLauncher launcher2 = newLauncherForTests(CATALOG_EMPTY_INITIAL);
- launcher2.start();
- assertOnlyBundle(reusedFramework, bundleName, pseudoSystemBundle);
- assertCatalogConsistsOfIds(launcher2, bundleItems);
- assertManagedBundle(launcher2, bundleName, bundleItems);
- launcher2.terminate();
- }
+ @Test
+ public void testInstallPreexistingBundle() throws Exception {
+ Set<VersionedName> bundleItems = ImmutableSet.of(VersionedName.fromString("one:1.0.0-SNAPSHOT"));
+ VersionedName bundleName = new VersionedName("org.example.brooklynLauncherRebindCatalogOsgiTest."+Identifiers.makeRandomId(4), "1.0.0.SNAPSHOT");
+ 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);
+
+ // Launch brooklyn, and explicitly install pre-existing bundle.
+ // Should bring it under brooklyn-management (should not re-install it).
+ startT1(newLauncherForTests(CATALOG_EMPTY_INITIAL));
+ installBrooklynBundle(launcherT1, bundleFile, false).getWithError();
+
+ assertOnlyBundle(launcherT1, bundleName, pseudoSystemBundle);
+ startupAssertions = () -> {
+ assertCatalogConsistsOfIds(launcherLast, bundleItems);
+ assertManagedBundle(launcherLast, bundleName, bundleItems);
+ };
+ startupAssertions.run();
+
+ // Launch brooklyn again (because will have persisted the pre-installed bundle)
+ startT2(newLauncherForTests(CATALOG_EMPTY_INITIAL));
+ assertOnlyBundle(reusedFramework, bundleName, pseudoSystemBundle);
+
+ launcherT2.terminate();
+ }
- @Test
- public void testInstallPreexistingBundleViaIndirectBrooklynLibrariesReference() throws Exception {
- Set<VersionedName> bundleItems = ImmutableSet.of(VersionedName.fromString("one:1.0.0-SNAPSHOT"));
- VersionedName systemBundleName = new VersionedName("org.example.brooklynLauncherRebindCatalogOsgiTest.system"+Identifiers.makeRandomId(4), "1.0.0.SNAPSHOT");
- File systemBundleFile = newTmpBundle(bundleItems, systemBundleName);
+ @Test
+ public void testInstallPreexistingBundleViaIndirectBrooklynLibrariesReference() throws Exception {
+ Set<VersionedName> bundleItems = ImmutableSet.of(VersionedName.fromString("one:1.0.0-SNAPSHOT"));
+ VersionedName systemBundleName = new VersionedName("org.example.brooklynLauncherRebindCatalogOsgiTest.system"+Identifiers.makeRandomId(4), "1.0.0.SNAPSHOT");
+ File systemBundleFile = newTmpBundle(bundleItems, systemBundleName);
+
+ String bundleBom = createCatalogYaml(ImmutableList.of(), ImmutableList.of(systemBundleName), ImmutableList.of());
+ VersionedName bundleName = new VersionedName("org.example.brooklynLauncherRebindCatalogOsgiTest.initial"+Identifiers.makeRandomId(4), "1.0.0.SNAPSHOT");
+ File bundleFile = newTmpBundle(ImmutableMap.of(BasicBrooklynCatalog.CATALOG_BOM, bundleBom.getBytes(StandardCharsets.UTF_8)), bundleName);
+
+ 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, systemBundleFile);
+ reusedBundles.add(pseudoSystemBundle);
+
+ startupAssertions = () -> {
+ assertOnlyBundle(launcherLast, systemBundleName, pseudoSystemBundle);
+ assertCatalogConsistsOfIds(launcherLast, bundleItems);
+ assertManagedBundle(launcherLast, systemBundleName, bundleItems);
+ assertManagedBundle(launcherLast, bundleName, ImmutableSet.of());
+ };
+
+ // Launch brooklyn, with initial catalog pointing at bundle that points at system bundle.
+ // Should bring it under brooklyn-management (without re-installing it).
+ startT1(newLauncherForTests(initialBomFile.getAbsolutePath()));
+
+ // Launch brooklyn again (because will have persisted both those bundles)
+ startT2(newLauncherForTests(CATALOG_EMPTY_INITIAL));
+
+ launcherT2.terminate();
+ }
- String bundleBom = createCatalogYaml(ImmutableList.of(), ImmutableList.of(systemBundleName), ImmutableList.of());
- VersionedName bundleName = new VersionedName("org.example.brooklynLauncherRebindCatalogOsgiTest.initial"+Identifiers.makeRandomId(4), "1.0.0.SNAPSHOT");
- File bundleFile = newTmpBundle(ImmutableMap.of(BasicBrooklynCatalog.CATALOG_BOM, bundleBom.getBytes(StandardCharsets.UTF_8)), bundleName);
-
- File initialBomFile = newTmpFile(createCatalogYaml(ImmutableList.of(bundleFile.toURI()), ImmutableList.of()));
-
- reuseOsgi = true;
+ @Test
+ public void testInstallPreexistingBundleViaInitialBomBrooklynLibrariesReference() throws Exception {
+ runInstallPreexistingBundleViaInitialBomBrooklynLibrariesReference(false);
+ }
- // 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);
+ // Aled thought we supported version ranges in 'brooklyn.libraries', but doesn't work here.
+ @Test(groups="Broken")
+ public void testInstallPreexistingBundleViaInitialBomBrooklynLibrariesReferenceWithVersionRange() throws Exception {
+ runInstallPreexistingBundleViaInitialBomBrooklynLibrariesReference(true);
+ }
- // Launch brooklyn, with initial catalog pointing at bundle that points at system bundle.
- // Should bring it under brooklyn-management (without re-installing it).
- BrooklynLauncher launcher = newLauncherForTests(initialBomFile.getAbsolutePath());
- launcher.start();
- assertOnlyBundle(launcher, systemBundleName, pseudoSystemBundle);
- assertCatalogConsistsOfIds(launcher, bundleItems);
- assertManagedBundle(launcher, systemBundleName, bundleItems);
- assertManagedBundle(launcher, bundleName, ImmutableSet.of());
- launcher.terminate();
-
- // Launch brooklyn again (because will have persisted both those bundles)
- BrooklynLauncher launcher2 = newLauncherForTests(CATALOG_EMPTY_INITIAL);
- launcher2.start();
- assertOnlyBundle(launcher2, systemBundleName, pseudoSystemBundle);
- assertCatalogConsistsOfIds(launcher2, bundleItems);
- assertManagedBundle(launcher2, systemBundleName, bundleItems);
- assertManagedBundle(launcher2, bundleName, ImmutableSet.of());
- launcher2.terminate();
- }
-
- @Test
- public void testInstallPreexistingBundleViaInitialBomBrooklynLibrariesReference() throws Exception {
- runInstallPreexistingBundleViaInitialBomBrooklynLibrariesReference(false);
- }
-
- // Aled thought we supported version ranges in 'brooklyn.libraries', but doesn't work here.
- @Test(groups="Broken")
- public void testInstallPreexistingBundleViaInitialBomBrooklynLibrariesReferenceWithVersionRange() throws Exception {
- runInstallPreexistingBundleViaInitialBomBrooklynLibrariesReference(true);
- }
-
- protected void runInstallPreexistingBundleViaInitialBomBrooklynLibrariesReference(boolean useVersionRange) throws Exception {
- Set<VersionedName> bundleItems = ImmutableSet.of(VersionedName.fromString("one:1.0.0"));
- VersionedName systemBundleName = new VersionedName("org.example.brooklynLauncherRebindCatalogOsgiTest.system"+Identifiers.makeRandomId(4), "1.0.0");
- File systemBundleFile = newTmpBundle(bundleItems, systemBundleName);
+ protected void runInstallPreexistingBundleViaInitialBomBrooklynLibrariesReference(boolean useVersionRange) throws Exception {
+ Set<VersionedName> bundleItems = ImmutableSet.of(VersionedName.fromString("one:1.0.0"));
+ VersionedName systemBundleName = new VersionedName("org.example.brooklynLauncherRebindCatalogOsgiTest.system"+Identifiers.makeRandomId(4), "1.0.0");
+ File systemBundleFile = newTmpBundle(bundleItems, systemBundleName);
+
+ VersionedName systemBundleNameRef;
+ if (useVersionRange) {
+ systemBundleNameRef = new VersionedName(systemBundleName.getSymbolicName(), "[1,2)");
+ } else {
+ systemBundleNameRef = systemBundleName;
+ }
+ 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);
+
+ startupAssertions = () -> {
+ assertOnlyBundle(launcherLast, systemBundleName, pseudoSystemBundle);
+ assertCatalogConsistsOfIds(launcherLast, bundleItems);
+ assertManagedBundle(launcherLast, systemBundleName, bundleItems);
+ };
+
+ // Launch brooklyn, with initial catalog pointing at system bundle.
+ // Should bring it under brooklyn-management (without re-installing it).
+ startT1(newLauncherForTests(initialBomFile.getAbsolutePath()));
+
+ // Launch brooklyn again (because will have persisted both those bundles)
+ startT2(newLauncherForTests(CATALOG_EMPTY_INITIAL));
+ launcherT2.terminate();
+ }
- VersionedName systemBundleNameRef;
- if (useVersionRange) {
- systemBundleNameRef = new VersionedName(systemBundleName.getSymbolicName(), "[1,2)");
- } else {
- systemBundleNameRef = systemBundleName;
+ @Test
+ public void testInstallReplacesPreexistingBundleWithoutForce() throws Exception {
+ runInstallReplacesPreexistingBundle(false);
}
- 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);
+ @Test
+ public void testInstallReplacesPreexistingBundleWithForce() throws Exception {
+ runInstallReplacesPreexistingBundle(true);
+ }
- // Launch brooklyn, with initial catalog pointing at system bundle.
- // Should bring it under brooklyn-management (without re-installing it).
- BrooklynLauncher launcher = newLauncherForTests(initialBomFile.getAbsolutePath());
- launcher.start();
- assertOnlyBundle(launcher, systemBundleName, pseudoSystemBundle);
- assertCatalogConsistsOfIds(launcher, bundleItems);
- assertManagedBundle(launcher, systemBundleName, bundleItems);
- launcher.terminate();
-
- // Launch brooklyn again (because will have persisted both those bundles)
- BrooklynLauncher launcher2 = newLauncherForTests(CATALOG_EMPTY_INITIAL);
- launcher2.start();
- assertOnlyBundle(launcher2, systemBundleName, pseudoSystemBundle);
- assertCatalogConsistsOfIds(launcher2, bundleItems);
- assertManagedBundle(launcher2, systemBundleName, bundleItems);
- launcher2.terminate();
- }
-
- @Test
- public void testInstallReplacesPreexistingBundleWithoutForce() throws Exception {
- runInstallReplacesPreexistingBundle(false);
+ protected void runInstallReplacesPreexistingBundle(boolean force) throws Exception {
+ Set<VersionedName> bundleItems = ImmutableSet.of(VersionedName.fromString("one:1.0.0-SNAPSHOT"));
+ VersionedName bundleName = new VersionedName("org.example.brooklynLauncherRebindCatalogOsgiTest."+Identifiers.makeRandomId(4), "1.0.0.SNAPSHOT");
+ 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);
+
+
+ // Launch brooklyn, and explicitly install pre-existing bundle.
+ // Should bring it under brooklyn-management (should not re-install it).
+ startT1(newLauncherForTests(CATALOG_EMPTY_INITIAL));
+ installBrooklynBundle(launcherT1, replacementBundleFile, force).getWithError();
+ assertOnlyBundleReplaced(launcherLast, bundleName, pseudoSystemBundle);
+ startupAssertions = () -> {
+ assertCatalogConsistsOfIds(launcherLast, bundleItems);
+ assertManagedBundle(launcherLast, bundleName, bundleItems);
+ };
+ startupAssertions.run();
+
+ // Launch brooklyn again (because will have persisted the pre-installed bundle)
+ startT2(newLauncherForTests(CATALOG_EMPTY_INITIAL));
+ assertOnlyBundleReplaced(reusedFramework, bundleName, pseudoSystemBundle);
+ launcherT2.terminate();
+ }
}
-
+
@Test
- public void testInstallReplacesPreexistingBundleWithForce() throws Exception {
- runInstallReplacesPreexistingBundle(true);
+ public static class HotStandbyRebindSubTests extends BrooklynLauncherRebindCatalogOsgiTest {
+ @Override protected boolean isT1KeptRunningWhenT2Starts() { return true; }
}
-
- protected void runInstallReplacesPreexistingBundle(boolean force) throws Exception {
- Set<VersionedName> bundleItems = ImmutableSet.of(VersionedName.fromString("one:1.0.0-SNAPSHOT"));
- VersionedName bundleName = new VersionedName("org.example.brooklynLauncherRebindCatalogOsgiTest."+Identifiers.makeRandomId(4), "1.0.0.SNAPSHOT");
- 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);
-
- // Launch brooklyn, and explicitly install pre-existing bundle.
- // Should bring it under brooklyn-management (should not re-install it).
- BrooklynLauncher launcher = newLauncherForTests(CATALOG_EMPTY_INITIAL);
- launcher.start();
- installBrooklynBundle(launcher, replacementBundleFile, force).getWithError();
+ @Test
+ public void testRebindGetsInitialOsgiCatalog() throws Exception {
+ Set<VersionedName> bundleItems = ImmutableSet.of(VersionedName.fromString("one:1.0.0"));
+ String bundleBom = createCatalogYaml(ImmutableList.of(), bundleItems);
+ VersionedName bundleName = new VersionedName("org.example.testRebindGetsInitialOsgiCatalog", "1.0.0");
+ File bundleFile = newTmpBundle(ImmutableMap.of(BasicBrooklynCatalog.CATALOG_BOM, bundleBom.getBytes(StandardCharsets.UTF_8)), bundleName);
+ File initialBomFile = newTmpFile(createCatalogYaml(ImmutableList.of(bundleFile.toURI()), ImmutableList.of()));
- assertOnlyBundleReplaced(launcher, bundleName, pseudoSystemBundle);
- assertCatalogConsistsOfIds(launcher, bundleItems);
- assertManagedBundle(launcher, bundleName, bundleItems);
- launcher.terminate();
-
- // Launch brooklyn again (because will have persisted the pre-installed bundle)
- BrooklynLauncher launcher2 = newLauncherForTests(CATALOG_EMPTY_INITIAL);
- launcher2.start();
- assertOnlyBundleReplaced(reusedFramework, bundleName, pseudoSystemBundle);
- assertCatalogConsistsOfIds(launcher2, bundleItems);
- assertManagedBundle(launcher2, bundleName, bundleItems);
- launcher2.terminate();
+ startupAssertions = () -> {
+ assertCatalogConsistsOfIds(launcherLast, bundleItems);
+ assertManagedBundle(launcherLast, bundleName, bundleItems);
+ };
+ startT1( newLauncherForTests(initialBomFile.getAbsolutePath()) );
+ startT2(newLauncherForTests(initialBomFile.getAbsolutePath()));
+ promoteT2IfStandby();
}
-
+
@Test
public void testRebindUpgradesBundleWithSameItems() throws Exception {
Set<VersionedName> bundleItems = ImmutableSet.of(VersionedName.fromString("one:1.0.0"));
@@ -367,17 +413,12 @@ public class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBrooklynLaunc
File bundleFileV2 = newTmpBundle(ImmutableMap.of(BasicBrooklynCatalog.CATALOG_BOM, bundleBom.getBytes(StandardCharsets.UTF_8)), bundleNameV2);
File initialBomFileV2 = newTmpFile(createCatalogYaml(ImmutableList.of(bundleFileV2.toURI()), ImmutableList.of()));
- BrooklynLauncher launcher = newLauncherForTests(initialBomFileV1.getAbsolutePath());
- launcher.start();
- assertCatalogConsistsOfIds(launcher, bundleItems);
- assertManagedBundle(launcher, bundleNameV1, bundleItems);
-
- launcher.terminate();
-
- BrooklynLauncher newLauncher = newLauncherForTests(initialBomFileV2.getAbsolutePath());
- newLauncher.start();
- assertCatalogConsistsOfIds(newLauncher, bundleItems);
- assertManagedBundle(newLauncher, bundleNameV2, bundleItems);
+ startupAssertions = () -> {
+ assertCatalogConsistsOfIds(launcherLast, bundleItems);
+ assertManagedBundle(launcherLast, bundleNameV1, bundleItems);
+ };
+ startT1(newLauncherForTests(initialBomFileV1.getAbsolutePath()));
+ startT2(newLauncherForTests(initialBomFileV2.getAbsolutePath()));
}
@Test
@@ -394,18 +435,19 @@ public class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBrooklynLaunc
File bundleFileV2 = newTmpBundle(ImmutableMap.of(BasicBrooklynCatalog.CATALOG_BOM, bundleBomV2.getBytes(StandardCharsets.UTF_8)), bundleNameV2);
File initialBomFileV2 = newTmpFile(createCatalogYaml(ImmutableList.of(bundleFileV2.toURI()), ImmutableList.of()));
- BrooklynLauncher launcher = newLauncherForTests(initialBomFileV1.getAbsolutePath());
- launcher.start();
- assertCatalogConsistsOfIds(launcher, bundleItemsV1);
- assertManagedBundle(launcher, bundleNameV1, bundleItemsV1);
-
- launcher.terminate();
-
- BrooklynLauncher newLauncher = newLauncherForTests(initialBomFileV2.getAbsolutePath());
- newLauncher.start();
- assertCatalogConsistsOfIds(newLauncher, Iterables.concat(bundleItemsV1, bundleItemsV2));
- assertManagedBundle(newLauncher, bundleNameV1, bundleItemsV1);
- assertManagedBundle(newLauncher, bundleNameV2, bundleItemsV2);
+ startT1(newLauncherForTests(initialBomFileV1.getAbsolutePath()));
+
+ assertCatalogConsistsOfIds(launcherLast, bundleItemsV1);
+ assertManagedBundle(launcherLast, bundleNameV1, bundleItemsV1);
+ // above for T1 should become the following for T2
+ startupAssertions = () -> {
+ assertCatalogConsistsOfIds(launcherLast, Iterables.concat(bundleItemsV1, bundleItemsV2));
+ assertManagedBundle(launcherLast, bundleNameV1, bundleItemsV1);
+ assertManagedBundle(launcherLast, bundleNameV2, bundleItemsV2);
+ };
+
+ startT2(newLauncherForTests(initialBomFileV2.getAbsolutePath()));
+ promoteT2IfStandby();
}
// TODO bundle fails to start:
@@ -423,48 +465,22 @@ public class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBrooklynLaunc
" - " + OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_URL);
File initialBomFile = newTmpFile(initialBom);
- BrooklynLauncher launcher = newLauncherForTests(initialBomFile.getAbsolutePath());
- launcher.start();
- assertCatalogConsistsOfIds(launcher, COM_EXAMPLE_BUNDLE_CATALOG_IDS);
- assertManagedBundle(launcher, COM_EXAMPLE_BUNDLE_ID, COM_EXAMPLE_BUNDLE_CATALOG_IDS);
-
- launcher.terminate();
-
- BrooklynLauncher newLauncher = newLauncherForTests(initialBomFile.getAbsolutePath());
- newLauncher.start();
- assertCatalogConsistsOfIds(newLauncher, COM_EXAMPLE_BUNDLE_CATALOG_IDS);
- assertManagedBundle(newLauncher, COM_EXAMPLE_BUNDLE_ID, COM_EXAMPLE_BUNDLE_CATALOG_IDS);
+ startupAssertions = () -> {
+ assertCatalogConsistsOfIds(launcherLast, COM_EXAMPLE_BUNDLE_CATALOG_IDS);
+ assertManagedBundle(launcherLast, COM_EXAMPLE_BUNDLE_ID, COM_EXAMPLE_BUNDLE_CATALOG_IDS);
+ };
+ startT1(newLauncherForTests(initialBomFile.getAbsolutePath()));
+ startT2(newLauncherForTests(initialBomFile.getAbsolutePath()));
+ promoteT2IfStandby();
}
- @Test
- public void testPersistsSingleCopyOfInitialCatalog() throws Exception {
- Set<VersionedName> bundleItems = ImmutableSet.of(VersionedName.fromString("one:1.0.0"));
- String bundleBom = createCatalogYaml(ImmutableList.of(), bundleItems);
- VersionedName bundleName = new VersionedName("org.example.testRebindGetsInitialOsgiCatalog"+Identifiers.makeRandomId(4), "1.0.0");
- File bundleFile = newTmpBundle(ImmutableMap.of(BasicBrooklynCatalog.CATALOG_BOM, bundleBom.getBytes(StandardCharsets.UTF_8)), bundleName);
- File initialBomFile = newTmpFile(createCatalogYaml(ImmutableList.of(bundleFile.toURI()), ImmutableList.of()));
-
- // First launcher should persist the bundle
- BrooklynLauncher launcher = newLauncherForTests(initialBomFile.getAbsolutePath());
- launcher.start();
- String bundlePersistenceId = findManagedBundle(launcher, bundleName).getId();
- launcher.terminate();
- assertEquals(getPersistenceListing(BrooklynObjectType.MANAGED_BUNDLE), ImmutableSet.of(bundlePersistenceId));
-
- // Second launcher should read from initial catalog and persisted state. Both those bundles have different ids.
- // Should only end up with one of them in persisted state.
- // (Current impl is that it will be the "initial catalog" version, discarding the previously persisted bundle).
- BrooklynLauncher launcher2 = newLauncherForTests(initialBomFile.getAbsolutePath());
- launcher2.start();
- String bundlePersistenceId2 = findManagedBundle(launcher2, bundleName).getId();
- launcher2.terminate();
- assertEquals(getPersistenceListing(BrooklynObjectType.MANAGED_BUNDLE), ImmutableSet.of(bundlePersistenceId2));
- }
-
/**
* It is vital that the brooklyn-managed-bundle ids match those in persisted state. If they do not,
* then deletion of a brooklyn-managed-bundle will not actually delete it from persisted state.
*
+ * This test (like many here) asserts for simple terminate-rebind and for hot-standby and promotion,
+ * but here note the paths are vbery different.
+ *
* Under the covers, the scenario of HOT_STANDBY promoted to MASTER is very different from when
* it starts as master:
* <ol>
@@ -513,7 +529,7 @@ public class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBrooklynLaunc
* </ol>
*/
@Test
- public void testPersistsSingleCopyOfInitialCatalogOnHotStandbyPromotion() throws Exception {
+ public void testPersistsSingleCopyOfInitialCatalog() throws Exception {
Set<VersionedName> bundleItems = ImmutableSet.of(VersionedName.fromString("one:1.0.0"));
String bundleBom = createCatalogYaml(ImmutableList.of(), bundleItems);
VersionedName bundleName = new VersionedName("org.example.testRebindGetsInitialOsgiCatalog"+Identifiers.makeRandomId(4), "1.0.0");
@@ -521,29 +537,47 @@ public class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBrooklynLaunc
File initialBomFile = newTmpFile(createCatalogYaml(ImmutableList.of(bundleFile.toURI()), ImmutableList.of()));
// First launcher should persist the bundle
- BrooklynLauncher launcher = newLauncherForTests(initialBomFile.getAbsolutePath())
- .highAvailabilityMode(HighAvailabilityMode.MASTER);
- launcher.start();
- String bundlePersistenceId = findManagedBundle(launcher, bundleName).getId();
- RebindTestUtils.waitForPersisted(launcher.getManagementContext());
- assertEquals(getPersistenceListing(BrooklynObjectType.MANAGED_BUNDLE), ImmutableSet.of(bundlePersistenceId));
-
- // Second launcher goes into hot-standby, and will thus rebind periodically.
- // When we terminate the first launcher, it will be promoted to master automatically.
- // However, we'll say state="master" before we've fully initialised, so need to use
- // assert-eventually.
- BrooklynLauncher launcher2 = newLauncherForTests(initialBomFile.getAbsolutePath())
- .highAvailabilityMode(HighAvailabilityMode.HOT_STANDBY);
- launcher2.start();
- assertHotStandbyEventually(launcher2);
+ startT1(newLauncherForTests(initialBomFile.getAbsolutePath()));
+ String bundlePersistenceId1 = findManagedBundle(launcherT1, bundleName).getId();
- launcher.terminate();
- assertMasterEventually(launcher2);
- assertPersistedBundleListingEqualsEventually(launcher2, ImmutableSet.of(bundleName));
- launcher2.terminate();
+ if (!isT1KeptRunningWhenT2Starts()) {
+ launcherT1.terminate();
+ } else {
+ RebindTestUtils.waitForPersisted(launcherT1.getManagementContext());
+ }
+ assertEquals(getPersistenceListing(BrooklynObjectType.MANAGED_BUNDLE), ImmutableSet.of(bundlePersistenceId1));
+
+ // Second launcher should read from initial catalog and persisted state. Both those bundles have different ids.
+ // Should only end up with one of them in persisted state.
+ // (Current impl is that it will be the "initial catalog" version, discarding the previously persisted bundle).
+ startT2(newLauncherForTests(initialBomFile.getAbsolutePath()));
+ if (isT1KeptRunningWhenT2Starts()) {
+ assertEquals(getPersistenceListing(BrooklynObjectType.MANAGED_BUNDLE), ImmutableSet.of(bundlePersistenceId1));
+ }
+
+ promoteT2IfStandby();
+
+ String bundlePersistenceId2 = findManagedBundle(launcherT2, bundleName).getId();
+ launcherT2.terminate();
+
+ // ID2 only persisted after promotion - checks above are for ID1
+ assertEquals(getPersistenceListing(BrooklynObjectType.MANAGED_BUNDLE), ImmutableSet.of(bundlePersistenceId2));
+
+ if (isT1KeptRunningWhenT2Starts()) {
+ // would like if we could make them the same but currently code should _always_ change
+ Assert.assertNotEquals(bundlePersistenceId1, bundlePersistenceId2);
+ }
}
- private void assertPersistedBundleListingEqualsEventually(BrooklynLauncher launcher, Set<VersionedName> bundles) {
+ // TODO tests:
+ // TODO remove on hot standby promotion (above), succeed and failing
+ // TODO deploy blueprint with old item after upgrade
+ // TODO rebind upgrade item deployed
+ // TODO rebind upgrade spec item in deployment
+ // TODO deploy mention of old item after upgrade
+ // TODO upgrade on hot standby and promotion
+
+ protected void assertPersistedBundleListingEqualsEventually(BrooklynLauncher launcher, Set<VersionedName> bundles) {
Asserts.succeedsEventually(new Runnable() {
@Override public void run() {
try {
@@ -560,17 +594,22 @@ public class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBrooklynLaunc
}});
}
- private void assertHotStandbyEventually(BrooklynLauncher launcher) {
- ManagementContext mgmt = launcher.getManagementContext();
+ protected void assertHotStandbyEventually(BrooklynLauncher launcher) {
Asserts.succeedsEventually(new Runnable() {
public void run() {
- assertTrue(mgmt.isStartupComplete());
- assertTrue(mgmt.isRunning());
- assertEquals(mgmt.getHighAvailabilityManager().getNodeState(), ManagementNodeState.HOT_STANDBY);
- }});
+ assertHotStandbyNow(launcher);
+ }
+ });
+ }
+
+ protected void assertHotStandbyNow(BrooklynLauncher launcher) {
+ ManagementContext mgmt = launcher.getManagementContext();
+ assertTrue(mgmt.isStartupComplete());
+ assertTrue(mgmt.isRunning());
+ assertEquals(mgmt.getHighAvailabilityManager().getNodeState(), ManagementNodeState.HOT_STANDBY);
}
- private void assertMasterEventually(BrooklynLauncher launcher) {
+ protected void assertMasterEventually(BrooklynLauncher launcher) {
ManagementContext mgmt = launcher.getManagementContext();
Asserts.succeedsEventually(new Runnable() {
public void run() {
@@ -580,42 +619,42 @@ public class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBrooklynLaunc
}});
}
- private Bundle installBundle(Framework framework, File bundle) throws Exception {
+ protected Bundle installBundle(Framework framework, File bundle) throws Exception {
try (FileInputStream stream = new FileInputStream(bundle)) {
return framework.getBundleContext().installBundle(bundle.toURI().toString(), stream);
}
}
- private ReferenceWithError<OsgiBundleInstallationResult> installBrooklynBundle(BrooklynLauncher launcher, File bundleFile, boolean force) throws Exception {
+ protected ReferenceWithError<OsgiBundleInstallationResult> installBrooklynBundle(BrooklynLauncher launcher, File bundleFile, boolean force) throws Exception {
OsgiManager osgiManager = ((ManagementContextInternal)launcher.getManagementContext()).getOsgiManager().get();
try (FileInputStream bundleStream = new FileInputStream(bundleFile)) {
return osgiManager.install(null, bundleStream, true, true, force);
}
}
- private void assertOnlyBundle(BrooklynLauncher launcher, VersionedName bundleName, Bundle expectedBundle) {
+ protected void assertOnlyBundle(BrooklynLauncher launcher, VersionedName bundleName, Bundle expectedBundle) {
Framework framework = ((ManagementContextInternal)launcher.getManagementContext()).getOsgiManager().get().getFramework();
assertOnlyBundle(framework, bundleName, expectedBundle);
}
- private void assertOnlyBundleReplaced(BrooklynLauncher launcher, VersionedName bundleName, Bundle expectedBundle) {
+ protected void assertOnlyBundleReplaced(BrooklynLauncher launcher, VersionedName bundleName, Bundle expectedBundle) {
Framework framework = ((ManagementContextInternal)launcher.getManagementContext()).getOsgiManager().get().getFramework();
assertOnlyBundleReplaced(framework, bundleName, expectedBundle);
}
- private void assertOnlyBundle(Framework framework, VersionedName bundleName, Bundle expectedBundle) {
+ protected void assertOnlyBundle(Framework framework, VersionedName bundleName, Bundle expectedBundle) {
List<Bundle> matchingBundles = Osgis.bundleFinder(framework).symbolicName(bundleName.getSymbolicName()).version(bundleName.getOsgiVersionString()).findAll();
assertTrue(matchingBundles.contains(expectedBundle), "Bundle missing; matching="+matchingBundles);
assertEquals(matchingBundles.size(), 1, "Extra bundles; matching="+matchingBundles);
}
- private void assertOnlyBundleReplaced(Framework framework, VersionedName bundleName, Bundle expectedBundle) {
+ protected void assertOnlyBundleReplaced(Framework framework, VersionedName bundleName, Bundle expectedBundle) {
List<Bundle> matchingBundles = Osgis.bundleFinder(framework).symbolicName(bundleName.getSymbolicName()).version(bundleName.getOsgiVersionString()).findAll();
assertFalse(matchingBundles.contains(expectedBundle), "Bundle still present; matching="+matchingBundles);
assertEquals(matchingBundles.size(), 1, "Extra bundles; matching="+matchingBundles);
}
- private Framework initReusableOsgiFramework() {
+ protected Framework initReusableOsgiFramework() {
if (!reuseOsgi) throw new IllegalStateException("Must first set reuseOsgi");
if (OsgiManager.tryPeekFrameworkForReuse().isAbsent()) {
@@ -627,11 +666,11 @@ public class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBrooklynLaunc
return OsgiManager.tryPeekFrameworkForReuse().get();
}
- private File newTmpBundle(Set<VersionedName> catalogItems, VersionedName bundleName) {
+ protected File newTmpBundle(Set<VersionedName> catalogItems, VersionedName bundleName) {
return newTmpBundle(catalogItems, bundleName, null);
}
- private File newTmpBundle(Set<VersionedName> catalogItems, VersionedName bundleName, String randomNoise) {
+ protected File newTmpBundle(Set<VersionedName> catalogItems, VersionedName bundleName, String randomNoise) {
String bundleBom = createCatalogYaml(ImmutableList.of(), ImmutableList.of(), catalogItems, randomNoise);
return newTmpBundle(ImmutableMap.of(BasicBrooklynCatalog.CATALOG_BOM, bundleBom.getBytes(StandardCharsets.UTF_8)), bundleName);
}
[05/10] brooklyn-server git commit: expand semantics of '*' for
catalog remove headers, and more tests (prep for upgrades)
Posted by he...@apache.org.
expand semantics of '*' for catalog remove headers, and more tests (prep for upgrades)
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/00df1d54
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/00df1d54
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/00df1d54
Branch: refs/heads/master
Commit: 00df1d54369c0f5da8d1467e23a8d532a88ceb54
Parents: 9173183
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Tue Oct 31 01:05:15 2017 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Tue Oct 31 01:07:44 2017 +0000
----------------------------------------------------------------------
.../core/typereg/BundleUpgradeParser.java | 96 +++++++++-------
.../core/typereg/BundleUpgradeParserTest.java | 10 +-
.../BrooklynLauncherRebindCatalogOsgiTest.java | 113 +++++++++++++++++--
3 files changed, 168 insertions(+), 51 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/00df1d54/core/src/main/java/org/apache/brooklyn/core/typereg/BundleUpgradeParser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/BundleUpgradeParser.java b/core/src/main/java/org/apache/brooklyn/core/typereg/BundleUpgradeParser.java
index bfac6c6..24d905f 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/BundleUpgradeParser.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/BundleUpgradeParser.java
@@ -31,6 +31,7 @@ import java.util.Set;
import org.apache.brooklyn.api.catalog.CatalogItem;
import org.apache.brooklyn.api.typereg.RegisteredType;
+import org.apache.brooklyn.util.collections.MutableList;
import org.apache.brooklyn.util.exceptions.Exceptions;
import org.apache.brooklyn.util.osgi.VersionedName;
import org.apache.brooklyn.util.text.BrooklynVersionSyntax;
@@ -60,16 +61,17 @@ public class BundleUpgradeParser {
* <ul>
* <li>Quoted {@code name:versionRange}, eg {@code "my-tomcat:[0,1)"};
* see {@link #MANIFEST_HEADER_FORCE_REMOVE_BUNDLES} for more information
- * <li>Comma-separated list of quoted {@code name:versionRange}, eg {@code "my-tomcat:[0,1)","my-nginx:[0,1)"};
- * see {@link #MANIFEST_HEADER_FORCE_REMOVE_BUNDLES} for more information
- * <li>{@code "*"} means all legacy items for things defined in this bundle, with version
- * numbers lower than the version of the bundle. For example, if the bundle is
- * version 1.0.0 and its catalog.bom contains items "foo" and "bar", then it is equivalent
- * to writing {@code "foo:[0,1.0.0)","bar:[0,1.0.0)"}.
+ * <li>{@code *} means all legacy items for things defined in this bundle, with version
+ * numbers lower than the version of the bundle,
+ * and quoted {@code *:versionRange} means the indicated version(s) of types in this bundle.
+ * For example, if the bundle is version 1.0.0 and its catalog.bom contains items "foo" and "bar", then
+ * {@code *} is equivalent to writing {@code "foo:[0,1.0.0)","bar:[0,1.0.0)"}.
* As per the comments on {@link #MANIFEST_HEADER_FORCE_REMOVE_BUNDLES},
* the version of the bundle and items being added by a bundle to replace legacy catalog items
* should typically be larger in major/minor/point value,
* as a qualifier bump can be quite complex due to ordering differences.
+ * <li>Comma-separated list of entries such as the above, eg {@code "my-tomcat:[0,1)","my-nginx:[0,1)"};
+ * see {@link #MANIFEST_HEADER_FORCE_REMOVE_BUNDLES} for more information
* </ul>
*/
@Beta
@@ -95,15 +97,18 @@ public class BundleUpgradeParser {
* as described in the "comma-separated list" format below.
* This is good anyway because there are different conventions for release names
* (e.g. "1.0.0" or "1.0.0.GA" or "1.0.0.2017-12") and any automation here is likely to cause surprises.
- * <li>Comma-separated list of quoted {@code name:versionRange}. For example,
+ * <li>{@code *} as an entry, meaning all lower versions of this bundle,
+ * or quote {@code *:versionRange}, meaning the given version range on this bundle.
+ * For example, if the bundle is {@code org.example.mybundle:1.0.0},
+ * then {@code *} is equivalent to writing {@code "org.example.mybundle:[0,1.0.0)"}
+ * and {@code "*:1-SNAPSHOT"} is equivalent to writing {@code "org.example.mybundle:1-SNAPSHOT"}
+ * (which when converted to OSGi is equivalent to {@code "org.example.mybundle:1.0.0.SNAPSHOT"})
+ * <li>Comma-separated list of entries such as the above. For example,
* {@code "org.example.mybundle:[0,1)","org.example.myotherbundle:[0,1)"} (useful for
* when this bundle merges the contents of two previous bundles), or
- * {@code "*","org.example.mybundle:1.0.0.SNAPSHOT","org.example.mybundle:1.0.0.rc1"}
+ * {@code "*","*:1.0.0.SNAPSHOT","*:1.0.0.rc1"}
* when releasing {@code org.example.mybundle:1.0.0.GA}
- * (to replace versions pre 1.0.0 as well as a snapshot and RC1)
- * <li>{@code "*"} means all lower versions of this bundle. For example, if the bundle is
- * {@code org.example.mybundle:1.0.0}, then it is equivalent to writing
- * {@code "org.example.mybundle:[0,1.0.0)"}
+ * (to replace versions pre 1.0.0 as well as a snapshot and an rc1)
* </ul>
*/
@Beta
@@ -283,10 +288,16 @@ public class BundleUpgradeParser {
}
if (parts.length == 1 || Strings.isBlank(parts[1])) {
throw new IllegalArgumentException("Identifier '"+val+"' must be of 'name:versionRange' syntax");
- } else if (singleVersionIsOsgiRange || (parts[1].startsWith("(") || parts[1].startsWith("["))) {
- return new VersionRangedName(parts[0], parts[1]);
+ }
+ return new VersionRangedName(parts[0], parts[1], singleVersionIsOsgiRange);
+ }
+
+ protected static String tidyVersionRange(String v, boolean singleVersionIsOsgiRange) {
+ if (v==null) return null;
+ if (singleVersionIsOsgiRange || (v.startsWith("(") || v.startsWith("["))) {
+ return v;
} else {
- return new VersionRangedName(parts[0], "["+parts[1]+","+parts[1]+"]");
+ return "["+v+","+v+"]";
}
}
@@ -295,9 +306,9 @@ public class BundleUpgradeParser {
this.v = checkNotNull(v, "versionRange").toString();
}
- private VersionRangedName(String name, String v) {
+ private VersionRangedName(String name, String v, boolean singleVersionIsOsgiRange) {
this.name = checkNotNull(name, "name");
- this.v = checkNotNull(v, "versionRange");
+ this.v = tidyVersionRange(checkNotNull(v, "versionRange"), singleVersionIsOsgiRange);
}
@Override
@@ -354,38 +365,32 @@ public class BundleUpgradeParser {
@VisibleForTesting
static List<VersionRangedName> parseForceRemoveLegacyItemsHeader(String input, Bundle bundle, Supplier<? extends Iterable<? extends RegisteredType>> typeSupplier) {
if (input == null) return ImmutableList.of();
- if (stripQuotes(input.trim()).equals("*")) {
- VersionRange versionRange = VersionRange.valueOf("[0,"+bundle.getVersion()+")");
- List<VersionRangedName> result = new ArrayList<>();
- for (RegisteredType item : typeSupplier.get()) {
- result.add(new VersionRangedName(item.getSymbolicName(), versionRange));
- }
- return result;
- } else {
- return parseVersionRangedNameList(input, false);
+ List<String> wildcardItems = MutableList.of();
+ for (RegisteredType item : typeSupplier.get()) {
+ wildcardItems.add(item.getSymbolicName());
}
+ return parseVersionRangedNameList(input, false, wildcardItems, "[0,"+bundle.getVersion()+")");
}
@VisibleForTesting
static List<VersionRangedName> parseForceRemoveBundlesHeader(String input, Bundle bundle) {
if (input == null) return ImmutableList.of();
- if (stripQuotes(input.trim()).equals("*")) {
- String bundleVersion = bundle.getVersion().toString();
- String maxVersion;
- if (BrooklynVersionSyntax.isSnapshot(bundleVersion)) {
- maxVersion = BrooklynVersionSyntax.stripSnapshot(bundleVersion);
- } else {
- maxVersion = bundleVersion;
- }
- return ImmutableList.of(new VersionRangedName(bundle.getSymbolicName(), "[0,"+maxVersion+")"));
+
+ String bundleVersion = bundle.getVersion().toString();
+ String maxVersion;
+ if (BrooklynVersionSyntax.isSnapshot(bundleVersion)) {
+ maxVersion = BrooklynVersionSyntax.stripSnapshot(bundleVersion);
} else {
- return parseVersionRangedNameList(input, false);
+ maxVersion = bundleVersion;
}
+
+ return parseVersionRangedNameList(input, false, MutableList.of(bundle.getSymbolicName()), "[0,"+maxVersion+")");
}
@VisibleForTesting
- static List<VersionRangedName> parseVersionRangedNameList(String input, boolean singleVersionIsOsgiRange) {
+ static List<VersionRangedName> parseVersionRangedNameList(String input, boolean singleVersionIsOsgiRange,
+ List<String> wildcardNames, String wildcardVersion) {
if (input == null) return ImmutableList.of();
List<String> vals = QuotedStringTokenizer.builder()
@@ -397,7 +402,22 @@ public class BundleUpgradeParser {
List<VersionRangedName> versionedItems = new ArrayList<>();
for (String val : vals) {
try {
- versionedItems.add(VersionRangedName.fromString(val.trim(), singleVersionIsOsgiRange));
+ val = val.trim();
+ if (val.startsWith("*")) {
+ String r;
+ if ("*".equals(val)) {
+ r = wildcardVersion;
+ } else if (val.startsWith("*:")) {
+ r = val.substring(2);
+ } else {
+ throw new IllegalArgumentException("Wildcard entry must be of the form \"*\" or \"*:range\"");
+ }
+ for (String item: wildcardNames) {
+ versionedItems.add(new VersionRangedName(item, r, false));
+ }
+ } else {
+ versionedItems.add(VersionRangedName.fromString(val, singleVersionIsOsgiRange));
+ }
} catch (Exception e) {
if (Strings.containsAny(val, "(", ")", "[", "]") &&
!Strings.containsAny(val, "'", "\"")) {
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/00df1d54/core/src/test/java/org/apache/brooklyn/core/typereg/BundleUpgradeParserTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/typereg/BundleUpgradeParserTest.java b/core/src/test/java/org/apache/brooklyn/core/typereg/BundleUpgradeParserTest.java
index 26bd27a..5fc5188 100644
--- a/core/src/test/java/org/apache/brooklyn/core/typereg/BundleUpgradeParserTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/typereg/BundleUpgradeParserTest.java
@@ -32,12 +32,14 @@ import org.apache.brooklyn.api.typereg.RegisteredType;
import org.apache.brooklyn.core.typereg.BundleUpgradeParser.CatalogUpgrades;
import org.apache.brooklyn.core.typereg.BundleUpgradeParser.VersionRangedName;
import org.apache.brooklyn.test.Asserts;
+import org.apache.brooklyn.util.collections.MutableList;
import org.apache.brooklyn.util.osgi.VersionedName;
import org.apache.brooklyn.util.text.BrooklynVersionSyntax;
import org.mockito.Mockito;
import org.osgi.framework.Bundle;
import org.osgi.framework.Version;
import org.osgi.framework.VersionRange;
+import org.testng.Assert;
import org.testng.annotations.Test;
import com.google.common.base.Supplier;
@@ -113,6 +115,9 @@ public class BundleUpgradeParserTest {
assertParseForceRemoveBundlesHeader("\"foo:0.1.0\"", bundle, ImmutableList.of(new VersionRangedName("foo", exactly0dot1)));
assertParseForceRemoveBundlesHeader("\"*\"", bundle, ImmutableList.of(new VersionRangedName("foo.bar", from0lessThan1_2_3)));
assertParseForceRemoveBundlesHeader("*", bundle, ImmutableList.of(new VersionRangedName("foo.bar", from0lessThan1_2_3)));
+ assertParseForceRemoveBundlesHeader("other:1, '*:[0,1)'", bundle, ImmutableList.of(
+ new VersionRangedName("other", VersionRange.valueOf("[1.0.0,1.0.0]")),
+ new VersionRangedName("foo.bar", new VersionRange('[', Version.valueOf("0"), Version.valueOf("1"), ')'))));
}
@Test
@@ -133,6 +138,9 @@ public class BundleUpgradeParserTest {
assertParseForceRemoveLegacyItemsHeader("\"foo:0.1.0\"", bundle, typeSupplier, ImmutableList.of(new VersionRangedName("foo", exactly0dot1)));
assertParseForceRemoveLegacyItemsHeader("\"*\"", bundle, typeSupplier, ImmutableList.of(new VersionRangedName("foo", from0lessThan1), new VersionRangedName("bar", from0lessThan1)));
assertParseForceRemoveLegacyItemsHeader("*", bundle, typeSupplier, ImmutableList.of(new VersionRangedName("foo", from0lessThan1), new VersionRangedName("bar", from0lessThan1)));
+ assertParseForceRemoveLegacyItemsHeader("*:1.0.0.SNAPSHOT, \"foo:[0.1,1)", bundle, typeSupplier,
+ ImmutableList.of(new VersionRangedName("foo", VersionRange.valueOf("[1.0.0.SNAPSHOT,1.0.0.SNAPSHOT]")), new VersionRangedName("bar", VersionRange.valueOf("[1.0.0.SNAPSHOT,1.0.0.SNAPSHOT]")),
+ new VersionRangedName("foo", VersionRange.valueOf("[0.1,1)"))));
}
@Test
@@ -247,7 +255,7 @@ public class BundleUpgradeParserTest {
}
private void assertParseList(String input, List<VersionRangedName> expected) throws Exception {
- List<VersionRangedName> actual = BundleUpgradeParser.parseVersionRangedNameList(input, false);
+ List<VersionRangedName> actual = BundleUpgradeParser.parseVersionRangedNameList(input, false, MutableList.of("WILCARD-NAME"), "0-WILDCARD_VERSION");
assertListsEqual(actual, expected);
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/00df1d54/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 b67a29e..3f261df 100644
--- a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindCatalogOsgiTest.java
+++ b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindCatalogOsgiTest.java
@@ -44,8 +44,11 @@ import org.apache.brooklyn.core.mgmt.ha.OsgiManager;
import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
import org.apache.brooklyn.core.mgmt.rebind.RebindTestUtils;
import org.apache.brooklyn.core.typereg.BundleUpgradeParser;
+import org.apache.brooklyn.entity.stock.BasicEntity;
import org.apache.brooklyn.test.Asserts;
import org.apache.brooklyn.test.support.TestResourceUnavailableException;
+import org.apache.brooklyn.util.collections.MutableList;
+import org.apache.brooklyn.util.collections.MutableSet;
import org.apache.brooklyn.util.core.osgi.Osgis;
import org.apache.brooklyn.util.exceptions.Exceptions;
import org.apache.brooklyn.util.exceptions.ReferenceWithError;
@@ -53,8 +56,6 @@ import org.apache.brooklyn.util.os.Os;
import org.apache.brooklyn.util.osgi.OsgiTestResources;
import org.apache.brooklyn.util.osgi.VersionedName;
import org.apache.brooklyn.util.text.Identifiers;
-import org.apache.brooklyn.util.time.Duration;
-import org.apache.brooklyn.util.time.Time;
import org.osgi.framework.Bundle;
import org.osgi.framework.launch.Framework;
import org.testng.Assert;
@@ -313,6 +314,7 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
}
// Aled thought we supported version ranges in 'brooklyn.libraries', but doesn't work here.
+ // Alex confirms nope, not supported there yet (2017-10).
@Test(groups="Broken")
public void testInstallPreexistingBundleViaInitialBomBrooklynLibrariesReferenceWithVersionRange() throws Exception {
runInstallPreexistingBundleViaInitialBomBrooklynLibrariesReference(true);
@@ -617,7 +619,6 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
}
@Test
- // might change this to fail in future, see RebindIteration.load
public void testRebindRemovedItemWorksIfJavaClassFound() throws Exception {
Set<VersionedName> bundleItemsV1 = ImmutableSet.of(VersionedName.fromString("one:1.0.0"));
String bundleBomV1 = createCatalogYaml(ImmutableList.of(), bundleItemsV1);
@@ -644,6 +645,90 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
Assert.assertEquals(entity.getCatalogItemId(), bundleItemsV1.iterator().next());
}
+ @Test
+ public void testRebindRemovedItemButLeavingJavaSucceeds() throws Exception {
+ File initialBomFileV2 = prepForRebindRemovedItemTestReturningBomV2(true);
+ createAndStartApplication(launcherLast.getManagementContext(),
+ "services: [ { type: 'simple-entity:1.0.0' } ]");
+
+ // should start and promote fine, even though original catalog item ID not available
+
+ // TODO when we switch to loading from type registry types instead of persisted java type (see RebindIteration.load)
+ // T2 startup should fail as the following test currently does, as we didn't allow the type to be upgraded
+ // (but note the following test should then succeed)
+ startT2(newLauncherForTests(initialBomFileV2.getAbsolutePath()));
+ promoteT2IfStandby();
+
+ Entity entity = Iterables.getOnlyElement( Iterables.getOnlyElement(launcherLast.getManagementContext().getApplications()).getChildren() );
+ // TODO prep should set upgrade types and this should be 2.0.0
+ Assert.assertEquals(entity.getCatalogItemId(), "simple-entity:1.0.0");
+ }
+ @Test
+ public void testRebindRemovedItemIncludingJavaFails() throws Exception {
+ File initialBomFileV2 = prepForRebindRemovedItemTestReturningBomV2(true);
+ createAndStartApplication(launcherLast.getManagementContext(),
+ "services: [ { type: 'simple-entity:1.0.0' } ]");
+
+ // should have errors on promotion
+
+ // TODO when we switch to loading from type registry types instead of persisted java type
+ // T2 startup should succeed as it knows the type is now a BasicEntity
+ startT2(newLauncherForTests(initialBomFileV2.getAbsolutePath()));
+ assertHotStandbyNow(launcherLast, false);
+ Assert.assertFalse( ((ManagementContextInternal)launcherLast.getManagementContext()).errors().isEmpty() );
+
+ promoteT2IfStandby();
+ assertMasterEventually(launcherLast, false);
+ Assert.assertFalse( ((ManagementContextInternal)launcherLast.getManagementContext()).errors().isEmpty() );
+
+ // entity shouldn't be loaded
+ Asserts.assertSize( launcherLast.getManagementContext().getApplications(), 0 );
+ }
+
+ private File prepForRebindRemovedItemTestReturningBomV2(boolean removeSourceJavaBundle) throws Exception {
+ TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_PATH);
+
+ String initialBomV1 = Joiner.on("\n").join(
+ "brooklyn.catalog:",
+ " brooklyn.libraries:",
+ " - " + OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_URL,
+ " items:",
+ " - id: simple-entity",
+ " item:",
+ " type: com.example.brooklyn.test.osgi.entities.SimpleEntity");
+ VersionedName bundleNameV1 = new VersionedName("org.example.testRebindGetsInitialOsgiCatalog", "1.0.0");
+ File bundleFileV1 = newTmpBundle(ImmutableMap.of(BasicBrooklynCatalog.CATALOG_BOM, initialBomV1.getBytes()), bundleNameV1);
+ File initialBomFileV1 = newTmpFile(createCatalogYaml(ImmutableList.of(bundleFileV1.toURI()), ImmutableList.of()));
+
+ String initialBomV2 = Joiner.on("\n").join(
+ "brooklyn.catalog:",
+ " items:",
+ " - id: simple-entity",
+ " item:",
+ " type: "+BasicEntity.class.getName());
+ VersionedName bundleNameV2 = new VersionedName("org.example.testRebindGetsInitialOsgiCatalog", "2.0.0");
+ File bundleFileV2 = newTmpBundle(ImmutableMap.of(BasicBrooklynCatalog.CATALOG_BOM, initialBomV2.getBytes()), bundleNameV2,
+ ImmutableMap.of(BundleUpgradeParser.MANIFEST_HEADER_FORCE_REMOVE_BUNDLES, "*"
+ + (removeSourceJavaBundle ? ","+"'"+OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_SYMBOLIC_NAME_FULL+":"+OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_VERSION+"'"
+ : "")));
+ File initialBomFileV2 = newTmpFile(createCatalogYaml(ImmutableList.of(bundleFileV2.toURI()), ImmutableList.of()));
+
+ startupAssertions = () -> {
+ String v = launcherT2==null ? "1.0.0" : "2.0.0";
+ VersionedName bv = new VersionedName("org.example.testRebindGetsInitialOsgiCatalog", v);
+ VersionedName iv = new VersionedName("simple-entity", v);
+ assertManagedBundle(launcherLast, bv, MutableSet.of(iv));
+ if (launcherT2==null) {
+ assertCatalogConsistsOfIds(launcherLast, MutableList.copyOf(COM_EXAMPLE_BUNDLE_CATALOG_IDS).append(iv));
+ } else {
+ assertCatalogConsistsOfIds(launcherLast, MutableList.of(iv));
+ }
+ };
+
+ startT1(newLauncherForTests(initialBomFileV1.getAbsolutePath()));
+ return initialBomFileV2;
+ }
+
protected void assertPersistedBundleListingEqualsEventually(BrooklynLauncher launcher, Set<VersionedName> bundles) {
Asserts.succeedsEventually(new Runnable() {
@Override public void run() {
@@ -661,28 +746,32 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
}});
}
- protected void assertHotStandbyEventually(BrooklynLauncher launcher) {
- Asserts.succeedsEventually(new Runnable() {
- public void run() {
- assertHotStandbyNow(launcher);
- }
- });
- }
-
protected void assertHotStandbyNow(BrooklynLauncher launcher) {
+ assertHotStandbyNow(launcher, true);
+ }
+ protected void assertHotStandbyNow(BrooklynLauncher launcher, boolean assertHealthy) {
ManagementContext mgmt = launcher.getManagementContext();
assertTrue(mgmt.isStartupComplete());
assertTrue(mgmt.isRunning());
assertEquals(mgmt.getNodeState(), ManagementNodeState.HOT_STANDBY);
+ if (assertHealthy) {
+ Asserts.assertSize(((ManagementContextInternal)mgmt).errors(), 0);
+ }
}
protected void assertMasterEventually(BrooklynLauncher launcher) {
+ assertMasterEventually(launcher, true);
+ }
+ protected void assertMasterEventually(BrooklynLauncher launcher, boolean assertHealthy) {
ManagementContext mgmt = launcher.getManagementContext();
Asserts.succeedsEventually(new Runnable() {
public void run() {
assertTrue(mgmt.isStartupComplete());
assertTrue(mgmt.isRunning());
assertEquals(mgmt.getNodeState(), ManagementNodeState.MASTER);
+ if (assertHealthy) {
+ Asserts.assertSize(((ManagementContextInternal)mgmt).errors(), 0);
+ }
}});
}
@@ -746,7 +835,7 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
try {
BrooklynLauncherRebindCatalogOsgiTest fixture = new LauncherRebindSubTests();
fixture.setUp();
- fixture.testRebindRemovedItemWorksIfJavaClassFound();
+ fixture.testRebindRemovedItemIncludingJavaFails();
fixture.tearDown();
} catch (Exception e) {
e.printStackTrace();
[04/10] brooklyn-server git commit: rebuild test JARs for use with
new major version, and update tests that so depend
Posted by he...@apache.org.
rebuild test JARs for use with new major version, and update tests that so depend
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/d64ca16b
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/d64ca16b
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/d64ca16b
Branch: refs/heads/master
Commit: d64ca16b5c8b198183e3a870cbfe5a83f4197570
Parents: b539605
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Mon Oct 30 22:45:03 2017 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Mon Oct 30 22:46:38 2017 +0000
----------------------------------------------------------------------
.../BrooklynLauncherRebindCatalogOsgiTest.java | 11 ++++-------
utils/common/dependencies/osgi/README.md | 2 ++
.../brooklyn-test-osgi-com-example-entities.jar | Bin 22115 -> 22125 bytes
.../osgi/brooklyn-test-osgi-entities.jar | Bin 22878 -> 22889 bytes
.../brooklyn-test-osgi-more-entities_0.1.0.jar | Bin 15983 -> 15996 bytes
.../brooklyn-test-osgi-more-entities_0.2.0.jar | Bin 16958 -> 16957 bytes
...-test-osgi-more-entities_evil-twin_0.2.0.jar | Bin 14146 -> 14144 bytes
7 files changed, 6 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d64ca16b/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 e925b33..119f341 100644
--- a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindCatalogOsgiTest.java
+++ b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindCatalogOsgiTest.java
@@ -72,7 +72,7 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_VERSION);
private static final Set<VersionedName> COM_EXAMPLE_BUNDLE_CATALOG_IDS = ImmutableSet.of(
- new VersionedName("com.example.simpleTest", "0.0.0-SNAPSHOT"));
+ new VersionedName("com.example.simpleTest", "0.1.0"));
/**
* Whether we reuse OSGi Framework depends if we want it to feel like rebinding on a new machine
@@ -485,12 +485,8 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
promoteT2IfStandby();
}
- // TODO bundle fails to start:
- // missing requirement [com.example.brooklyn.test.resources.osgi.brooklyn-test-osgi-com-example-entities [147](R 147.0)]
- // osgi.wiring.package; (&(osgi.wiring.package=org.apache.brooklyn.config)(version>=0.12.0)(!(version>=1.0.0)))
- // Presumably because brooklyn-api is just on the classpath rather than in osgi.
- // How did such tests work previously?!
- @Test(groups="Broken")
+ // if fails with wiring error you might need to rebuild items in utils/common/dependencies/osgi/
+ @Test
public void testRebindGetsInitialOsgiCatalogWithJava() throws Exception {
TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_PATH);
@@ -707,4 +703,5 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
String bundleBom = createCatalogYaml(ImmutableList.of(), ImmutableList.of(), catalogItems, randomNoise);
return newTmpBundle(ImmutableMap.of(BasicBrooklynCatalog.CATALOG_BOM, bundleBom.getBytes(StandardCharsets.UTF_8)), bundleName);
}
+
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d64ca16b/utils/common/dependencies/osgi/README.md
----------------------------------------------------------------------
diff --git a/utils/common/dependencies/osgi/README.md b/utils/common/dependencies/osgi/README.md
index bda2287..92aea6d 100644
--- a/utils/common/dependencies/osgi/README.md
+++ b/utils/common/dependencies/osgi/README.md
@@ -6,6 +6,8 @@ copied there when these projects are built, and the binaries
are included in source control to speed up build times
(as these projects do not change much). These projects are
NOT built as part of the normal brooklyn build.
+It typically only needs to be rebuilt on a major version
+upgrade (due to OSGi rules) or when contents are changed.
To rebuild all:
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d64ca16b/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-com-example-entities.jar
----------------------------------------------------------------------
diff --git a/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-com-example-entities.jar b/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-com-example-entities.jar
index 3caa879..5e7256a 100644
Binary files a/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-com-example-entities.jar and b/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-com-example-entities.jar differ
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d64ca16b/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-entities.jar
----------------------------------------------------------------------
diff --git a/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-entities.jar b/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-entities.jar
index 36caec6..835c394 100644
Binary files a/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-entities.jar and b/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-entities.jar differ
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d64ca16b/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-more-entities_0.1.0.jar
----------------------------------------------------------------------
diff --git a/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-more-entities_0.1.0.jar b/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-more-entities_0.1.0.jar
index 465f0ca..8d3f692 100644
Binary files a/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-more-entities_0.1.0.jar and b/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-more-entities_0.1.0.jar differ
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d64ca16b/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-more-entities_0.2.0.jar
----------------------------------------------------------------------
diff --git a/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-more-entities_0.2.0.jar b/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-more-entities_0.2.0.jar
index 3b76043..d19a48b 100644
Binary files a/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-more-entities_0.2.0.jar and b/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-more-entities_0.2.0.jar differ
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d64ca16b/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-more-entities_evil-twin_0.2.0.jar
----------------------------------------------------------------------
diff --git a/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-more-entities_evil-twin_0.2.0.jar b/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-more-entities_evil-twin_0.2.0.jar
index 5046d38..b528ff4 100644
Binary files a/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-more-entities_evil-twin_0.2.0.jar and b/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-more-entities_evil-twin_0.2.0.jar differ
[10/10] brooklyn-server git commit: This closes #872
Posted by he...@apache.org.
This closes #872
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/48f09007
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/48f09007
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/48f09007
Branch: refs/heads/master
Commit: 48f0900712b26de9892c696a537b81f45a61da38
Parents: 43a861c c840fbe
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Wed Nov 1 15:50:43 2017 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Wed Nov 1 15:50:43 2017 +0000
----------------------------------------------------------------------
.../brooklyn/api/mgmt/ManagementContext.java | 11 +-
.../api/mgmt/ha/HighAvailabilityManager.java | 9 +
.../CatalogOsgiVersionMoreEntityRebindTest.java | 2 +-
.../catalog/internal/CatalogInitialization.java | 20 +-
.../mgmt/ha/HighAvailabilityManagerImpl.java | 17 +-
.../core/mgmt/ha/OsgiArchiveInstaller.java | 8 +
.../brooklyn/core/mgmt/ha/OsgiManager.java | 7 +
.../mgmt/internal/LocalManagementContext.java | 33 +-
.../NonDeploymentManagementContext.java | 9 +-
.../mgmt/rebind/RebindExceptionHandlerImpl.java | 4 +-
.../core/mgmt/rebind/RebindIteration.java | 44 +-
.../core/mgmt/rebind/RebindManagerImpl.java | 4 +
.../core/typereg/BasicBrooklynTypeRegistry.java | 70 +-
.../core/typereg/BundleUpgradeParser.java | 390 +++++++-
.../core/typereg/RegisteredTypePredicates.java | 20 +-
.../core/typereg/BundleUpgradeParserTest.java | 226 ++++-
.../AbstractBrooklynLauncherRebindTest.java | 21 +-
.../BrooklynLauncherRebindCatalogOsgiTest.java | 930 ++++++++++++-------
.../BrooklynLauncherUpgradeCatalogOsgiTest.java | 42 +
.../java/org/apache/brooklyn/cli/CliTest.java | 3 +-
utils/common/dependencies/osgi/README.md | 2 +
.../brooklyn-test-osgi-com-example-entities.jar | Bin 22115 -> 22125 bytes
.../osgi/brooklyn-test-osgi-entities.jar | Bin 22878 -> 22889 bytes
.../brooklyn-test-osgi-more-entities_0.1.0.jar | Bin 15983 -> 15996 bytes
.../brooklyn-test-osgi-more-entities_0.2.0.jar | Bin 16958 -> 16957 bytes
...-test-osgi-more-entities_evil-twin_0.2.0.jar | Bin 14146 -> 14144 bytes
26 files changed, 1410 insertions(+), 462 deletions(-)
----------------------------------------------------------------------
[03/10] brooklyn-server git commit: fix ordering of catalog lookup,
and tidy naming of tests for rebind with catalog upgrades
Posted by he...@apache.org.
fix ordering of catalog lookup, and tidy naming of tests for rebind with catalog upgrades
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/b539605f
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/b539605f
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/b539605f
Branch: refs/heads/master
Commit: b539605ff4b1ad313812fef81fe326de8478e31e
Parents: 305df9c
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Mon Oct 30 15:56:58 2017 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Mon Oct 30 15:56:58 2017 +0000
----------------------------------------------------------------------
.../core/typereg/BasicBrooklynTypeRegistry.java | 7 ++-
.../BrooklynLauncherRebindCatalogOsgiTest.java | 52 +++++++++++++-------
2 files changed, 40 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b539605f/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
index 46d3400..dd0b4b9 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
@@ -43,6 +43,7 @@ import org.apache.brooklyn.core.catalog.internal.CatalogItemBuilder;
import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
import org.apache.brooklyn.core.mgmt.ha.OsgiManager;
import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
+import org.apache.brooklyn.core.typereg.RegisteredTypes.RegisteredTypeNameThenBestFirstComparator;
import org.apache.brooklyn.test.Asserts;
import org.apache.brooklyn.util.collections.MutableMap;
import org.apache.brooklyn.util.collections.MutableSet;
@@ -50,6 +51,7 @@ import org.apache.brooklyn.util.concurrent.Locks;
import org.apache.brooklyn.util.exceptions.Exceptions;
import org.apache.brooklyn.util.guava.Maybe;
import org.apache.brooklyn.util.osgi.VersionedName;
+import org.apache.brooklyn.util.osgi.VersionedName.VersionedNameComparator;
import org.apache.brooklyn.util.osgi.VersionedName.VersionedNameStringComparator;
import org.apache.brooklyn.util.text.BrooklynVersionSyntax;
import org.apache.brooklyn.util.text.Identifiers;
@@ -93,9 +95,10 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry {
private Iterable<RegisteredType> getAllWithoutCatalog(Predicate<? super RegisteredType> filter) {
// TODO optimisation? make indexes and look up?
+ Ordering<RegisteredType> typeOrder = Ordering.from(RegisteredTypeNameThenBestFirstComparator.INSTANCE);
return Locks.withLock(localRegistryLock.readLock(),
() -> localRegisteredTypesAndContainingBundles.values().stream().
- flatMap(m -> m.values().stream()).filter(filter::apply).collect(Collectors.toList()) );
+ flatMap(m -> { return typeOrder.sortedCopy(m.values()).stream(); }).filter(filter::apply).collect(Collectors.toList()) );
}
private Maybe<RegisteredType> getExactWithoutLegacyCatalog(String symbolicName, String version, RegisteredTypeLoadingContext constraint) {
@@ -109,7 +112,7 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry {
if (m.isEmpty()) return null;
if (m.size()==1) return m.values().iterator().next();
// get the highest version of first alphabetical - to have a canonical order
- return m.get( Ordering.from(VersionedNameStringComparator.INSTANCE).max(m.keySet()) );
+ return m.get( Ordering.from(VersionedNameStringComparator.INSTANCE).min(m.keySet()) );
}
@SuppressWarnings("deprecation")
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b539605f/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 b2e4484..e925b33 100644
--- a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindCatalogOsgiTest.java
+++ b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindCatalogOsgiTest.java
@@ -416,7 +416,7 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
}
@Test
- public void testRebindUpgradesBundleWithSameItems() throws Exception {
+ public void testRestartWithNewBundleWithSameItemsReplacesItems() throws Exception {
Set<VersionedName> bundleItems = ImmutableSet.of(VersionedName.fromString("one:1.0.0"));
String bundleBom = createCatalogYaml(ImmutableList.of(), bundleItems);
@@ -431,13 +431,30 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
startupAssertions = () -> {
assertCatalogConsistsOfIds(launcherLast, bundleItems);
assertManagedBundle(launcherLast, bundleNameV1, bundleItems);
+
+ String bundleVersionSupplyingType = getBundleSupplyingFirstType(bundleItems);
+ if (launcherT2==null) {
+ Assert.assertEquals(bundleVersionSupplyingType, "1.0.0");
+
+ } else {
+ assertManagedBundle(launcherLast, bundleNameV2, bundleItems);
+ getBundleSupplyingFirstType(bundleItems);
+ Assert.assertEquals(bundleVersionSupplyingType, "2.0.0");
+ }
};
startT1(newLauncherForTests(initialBomFileV1.getAbsolutePath()));
startT2(newLauncherForTests(initialBomFileV2.getAbsolutePath()));
+ assertManagedBundle(launcherLast, bundleNameV2, bundleItems);
+ promoteT2IfStandby();
+ }
+
+ protected String getBundleSupplyingFirstType(Set<VersionedName> bundleItems) {
+ return VersionedName.fromString( launcherLast.getManagementContext().getTypeRegistry().get(
+ bundleItems.iterator().next().toString() ).getContainingBundle() ).getVersionString();
}
@Test
- public void testRebindUpgradesBundleWithNewerItems() throws Exception {
+ public void testRestartWithNewBundleWithNewItemsAddsItems() throws Exception {
Set<VersionedName> bundleItemsV1 = ImmutableSet.of(VersionedName.fromString("one:1.0.0"));
String bundleBomV1 = createCatalogYaml(ImmutableList.of(), bundleItemsV1);
VersionedName bundleNameV1 = new VersionedName("org.example.testRebindGetsInitialOsgiCatalog", "1.0.0");
@@ -450,17 +467,20 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
File bundleFileV2 = newTmpBundle(ImmutableMap.of(BasicBrooklynCatalog.CATALOG_BOM, bundleBomV2.getBytes(StandardCharsets.UTF_8)), bundleNameV2);
File initialBomFileV2 = newTmpFile(createCatalogYaml(ImmutableList.of(bundleFileV2.toURI()), ImmutableList.of()));
- startT1(newLauncherForTests(initialBomFileV1.getAbsolutePath()));
-
- assertCatalogConsistsOfIds(launcherLast, bundleItemsV1);
- assertManagedBundle(launcherLast, bundleNameV1, bundleItemsV1);
- // above for T1 should become the following for T2
startupAssertions = () -> {
- assertCatalogConsistsOfIds(launcherLast, Iterables.concat(bundleItemsV1, bundleItemsV2));
assertManagedBundle(launcherLast, bundleNameV1, bundleItemsV1);
- assertManagedBundle(launcherLast, bundleNameV2, bundleItemsV2);
+ Assert.assertEquals(getBundleSupplyingFirstType(bundleItemsV1), "1.0.0");
+ if (launcherT2==null) {
+ assertCatalogConsistsOfIds(launcherLast, bundleItemsV1);
+
+ } else {
+ assertCatalogConsistsOfIds(launcherLast, Iterables.concat(bundleItemsV1, bundleItemsV2));
+
+ assertManagedBundle(launcherLast, bundleNameV2, bundleItemsV2);
+ Assert.assertEquals(getBundleSupplyingFirstType(bundleItemsV2), "2.0.0");
+ }
};
-
+ startT1(newLauncherForTests(initialBomFileV1.getAbsolutePath()));
startT2(newLauncherForTests(initialBomFileV2.getAbsolutePath()));
promoteT2IfStandby();
}
@@ -584,13 +604,11 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
}
}
- // TODO tests:
- // TODO remove on hot standby promotion (above), succeed and failing
- // TODO deploy blueprint with old item after upgrade
- // TODO rebind upgrade item deployed
- // TODO rebind upgrade spec item in deployment
- // TODO deploy mention of old item after upgrade
- // TODO upgrade on hot standby and promotion
+ // TODO removed item in deployment fails - rebind and upgrade uses new item
+ // TODO removed item in deployment upgrades - rebind and upgrade uses new item
+ // TODO removed item in spec fails
+ // TODO removed item in spec upgrades
+ // TODO removed item deployed after rebind
protected void assertPersistedBundleListingEqualsEventually(BrooklynLauncher launcher, Set<VersionedName> bundles) {
Asserts.succeedsEventually(new Runnable() {
[06/10] brooklyn-server git commit: more tests, warning messages,
prep for upgrading bundles and types
Posted by he...@apache.org.
more tests, warning messages, prep for upgrading bundles and types
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/9173183f
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/9173183f
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/9173183f
Branch: refs/heads/master
Commit: 9173183f247add9a99316c6f5276b28a45429d62
Parents: d64ca16
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Mon Oct 30 22:38:03 2017 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Tue Oct 31 01:07:44 2017 +0000
----------------------------------------------------------------------
.../brooklyn/api/mgmt/ManagementContext.java | 3 +-
.../CatalogOsgiVersionMoreEntityRebindTest.java | 2 +-
.../mgmt/internal/LocalManagementContext.java | 1 +
.../mgmt/rebind/RebindExceptionHandlerImpl.java | 2 +-
.../core/mgmt/rebind/RebindIteration.java | 44 +++++++---
.../core/typereg/BundleUpgradeParser.java | 87 +++++++++++++++++++-
.../AbstractBrooklynLauncherRebindTest.java | 18 +++-
.../BrooklynLauncherRebindCatalogOsgiTest.java | 72 +++++++++++++---
.../BrooklynLauncherUpgradeCatalogOsgiTest.java | 48 +++++++++++
9 files changed, 246 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9173183f/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 2c615ed..4ad9718 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
@@ -243,7 +243,8 @@ public interface ManagementContext {
@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.
+ /** Returns node state, always reporting {@link ManagementNodeState#INITIALIZING} if there is any transition
+ * and {@link ManagementNodeState#FAILED} if there are any server errors.
* 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.
*/
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9173183f/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityRebindTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityRebindTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityRebindTest.java
index 64cd99e..835609d 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityRebindTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityRebindTest.java
@@ -274,7 +274,7 @@ public class CatalogOsgiVersionMoreEntityRebindTest extends AbstractYamlRebindTe
Asserts.shouldHaveFailedPreviously("Expected deployment to fail rebind; instead got "+app2);
} catch (Exception e) {
// should fail to rebind this entity
- Asserts.expectedFailureContainsIgnoreCase(e, more.getId(), "unable to load", BROOKLYN_TEST_MORE_ENTITIES_MORE_ENTITY);
+ Asserts.expectedFailureContainsIgnoreCase(e, more.getId(), "class", BROOKLYN_TEST_MORE_ENTITIES_MORE_ENTITY, "not found");
}
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9173183f/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 d6c69d4..e5af9b1 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
@@ -453,6 +453,7 @@ public class LocalManagementContext extends AbstractManagementContext {
public ManagementNodeState getNodeState() {
synchronized (startupSynchObject) {
if (!startupComplete) return ManagementNodeState.INITIALIZING;
+ if (!errors().isEmpty()) return ManagementNodeState.FAILED;
return getHighAvailabilityManager().getNodeState();
}
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9173183f/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindExceptionHandlerImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindExceptionHandlerImpl.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindExceptionHandlerImpl.java
index 17d4073..794161b 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindExceptionHandlerImpl.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindExceptionHandlerImpl.java
@@ -242,7 +242,7 @@ public class RebindExceptionHandlerImpl implements RebindExceptionHandler {
if (danglingRefFailureMode == RebindManager.RebindFailureMode.FAIL_FAST) {
throw new IllegalStateException("No catalog item found with id "+id);
} else {
- warn("No catalog item found with id "+id+"; dangling reference on rebind");
+ warn("No catalog item found with id "+id+"; dangling reference on rebind (subsequent log messages will indicate context)");
return null;
}
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9173183f/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
index 8a667eb..4751341 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
@@ -970,10 +970,15 @@ public abstract class RebindIteration {
}
@SuppressWarnings("unchecked")
+ // TODO should prefer a registered type as the type to load (in lieu of jType),
+ // but note some callers (enrichers etc) use catalogItemId to be the first entry in search path rather than their actual type,
+ // so until callers are all updated all we can do here is load the java type with no guarantee the catalogItemId should be the same.
+ // (yoml should help a lot with this.)
protected <T extends BrooklynObject> LoadedClass<? extends T> load(Class<T> bType, String jType,
String catalogItemId, List<String> searchPath, String contextSuchAsId) {
checkNotNull(jType, "Type of %s (%s) must not be null", contextSuchAsId, bType.getSimpleName());
+ List<String> warnings = MutableList.of();
List<String> reboundSearchPath = MutableList.of();
if (searchPath != null && !searchPath.isEmpty()) {
for (String searchItemId : searchPath) {
@@ -987,8 +992,7 @@ public abstract class RebindIteration {
if (fixedSearchItemId != null) {
reboundSearchPath.add(fixedSearchItemId);
} else {
- LOG.warn("Unable to load catalog item "+ searchItemId
- + " for search path of "+contextSuchAsId + " (" + bType.getSimpleName()+"); attempting to load "+jType+" nevertheless");
+ warnings.add("unable to resolve search path entry "+ searchItemId);
}
}
}
@@ -1016,23 +1020,31 @@ public abstract class RebindIteration {
return new LoadedClass<T>(loader.loadClass(jType, bType), transformedCatalogItemId, reboundSearchPath);
} catch (Exception e) {
Exceptions.propagateIfFatal(e);
- LOG.warn("Unable to load class "+jType+" needed for "+catalogItemId+" for "+contextSuchAsId+", via "+transformedCatalogItemId+" loader (will try reflections)");
+ warnings.add("unable to load class "+jType+" for resovled context type "+transformedCatalogItemId);
}
} else {
- LOG.warn("Unable to load catalog item "+catalogItemId+" ("+bType+") for " + contextSuchAsId +
- " ("+bType.getSimpleName()+"); will try reflection");
+ // TODO fail, rather than fallback to java?
+ warnings.add("unable to resolve context type "+catalogItemId);
}
+ } else {
+ // can happen for enrichers etc added by java, and for BasicApplication when things are deployed;
+ // no need to warn
}
try {
- return new LoadedClass<T>((Class<T>)loadClass(jType), catalogItemId, reboundSearchPath);
+ Class<T> jTypeC = (Class<T>)loadClass(jType);
+ if (!warnings.isEmpty()) {
+ LOG.warn("Loaded java type "+jType+" for "+bType.getSimpleName().toLowerCase()+" "+contextSuchAsId+" but had errors: "+Strings.join(warnings, ";"));
+ }
+ return new LoadedClass<T>(jTypeC, catalogItemId, reboundSearchPath);
} catch (Exception e) {
Exceptions.propagateIfFatal(e);
- LOG.warn("Unable to load class "+jType+" needed for "+catalogItemId+" for "+contextSuchAsId+", via reflections (may try others, will throw if fails)");
}
if (catalogItemId != null) {
- throw new IllegalStateException("Unable to load "+jType+" for catalog item " + catalogItemId + " for " + contextSuchAsId);
+ String msg = "Class "+jType+" not found for "+bType.getSimpleName().toLowerCase()+" "+contextSuchAsId+" ("+catalogItemId+"): "+Strings.join(warnings, ";");
+ LOG.warn(msg+" (rethrowing)");
+ throw new IllegalStateException(msg);
} else if (BrooklynFeatureEnablement.isEnabled(FEATURE_BACKWARDS_COMPATIBILITY_INFER_CATALOG_ITEM_ON_REBIND)) {
//Try loading from whichever catalog bundle succeeds (legacy CI items only; also disabling this, as no longer needed 2017-09)
@@ -1041,15 +1053,21 @@ public abstract class RebindIteration {
BrooklynClassLoadingContext catalogLoader = CatalogUtils.newClassLoadingContext(managementContext, item);
Maybe<Class<?>> catalogClass = catalogLoader.tryLoadClass(jType);
if (catalogClass.isPresent()) {
- LOG.warn("Found "+jType+" only by scanning catalog item search paths");
+ LOG.warn("Falling back to java type "+jType+" for "+bType.getSimpleName().toLowerCase()+" "+contextSuchAsId+" using catalog search paths, found on "+item+
+ (warnings.isEmpty() ? "" : ", after errors: "+Strings.join(warnings, ";")));
return new LoadedClass<T>((Class<? extends T>) catalogClass.get(), catalogItemId, reboundSearchPath);
}
}
- throw new IllegalStateException("No catalogItemId specified for " + contextSuchAsId +
- " and can't load class (" + jType + ") from either classpath or catalog items");
+ String msg = "Class "+jType+" not found for "+bType.getSimpleName().toLowerCase()+" "+contextSuchAsId+", even after legacy global classpath search"+
+ (warnings.isEmpty() ? "" : ": "+Strings.join(warnings, ";"));
+ LOG.warn(msg+" (rethrowing)");
+ throw new IllegalStateException(msg);
+
} else {
- throw new IllegalStateException("No catalogItemId specified for " + contextSuchAsId +
- " and can't load class (" + jType + ") from classpath");
+ String msg = "Class "+jType+" not found for "+bType.getSimpleName().toLowerCase()+" "+contextSuchAsId+
+ (warnings.isEmpty() ? "" : ": "+Strings.join(warnings, ";"));
+ LOG.warn(msg+" (rethrowing)");
+ throw new IllegalStateException(msg);
}
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9173183f/core/src/main/java/org/apache/brooklyn/core/typereg/BundleUpgradeParser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/BundleUpgradeParser.java b/core/src/main/java/org/apache/brooklyn/core/typereg/BundleUpgradeParser.java
index e797137..bfac6c6 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/BundleUpgradeParser.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/BundleUpgradeParser.java
@@ -23,8 +23,10 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Dictionary;
+import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.apache.brooklyn.api.catalog.CatalogItem;
@@ -65,8 +67,8 @@ public class BundleUpgradeParser {
* version 1.0.0 and its catalog.bom contains items "foo" and "bar", then it is equivalent
* to writing {@code "foo:[0,1.0.0)","bar:[0,1.0.0)"}.
* As per the comments on {@link #MANIFEST_HEADER_FORCE_REMOVE_BUNDLES},
- * the version of the bundle and items being added here to replace legacy catalog items
- * should typically be larger in major/minor/point value
+ * the version of the bundle and items being added by a bundle to replace legacy catalog items
+ * should typically be larger in major/minor/point value,
* as a qualifier bump can be quite complex due to ordering differences.
* </ul>
*/
@@ -106,7 +108,84 @@ public class BundleUpgradeParser {
*/
@Beta
public static final String MANIFEST_HEADER_FORCE_REMOVE_BUNDLES = "brooklyn-catalog-force-remove-bundles";
-
+
+ /**
+ * A header in a bundle's manifest, indicating that this bundle recommends a set of upgrades.
+ * These will be advisory unless the bundle being upgraded is force-removed in which case it will be applied automatically
+ * wherever the bundle is in use.
+ *
+ * The format is a comma separate list of {@code key=value} pairs, where each key and value is a name with a version range
+ * (as per {@link #MANIFEST_HEADER_FORCE_REMOVE_BUNDLES}). The {@code =value} can be omitted, and usually is,
+ * to mean this bundle at this version. (The {@code =value} is available if one bundle is defining upgrades for other bundles.)
+ *
+ * A wildcard can be given as the key, without a version ({@code *}) or with ({@code *:[0,1)}) to refer to
+ * all previous versions (OSGi ordering, see below) or the indicated versions, respectively, of the bundle this manifest is defining.
+ *
+ * If this header is supplied and {@link #MANIFEST_HEADER_UPGRADE_FOR_TYPES} is omitted, the types to upgrade are inferred as
+ * being all types defined in the bundle this manifest is defining, and all versions of this bundle upgraded by this bundle
+ * according to this header. If this header is included but does not declare any versions of this bundle upgraded by this bundle,
+ * then {@link #MANIFEST_HEADER_UPGRADE_FOR_TYPES} must be explicitly set.
+ *
+ * Version ordering may be surprising particularly in regard to qualifiers.
+ * See {@link #MANIFEST_HEADER_FORCE_REMOVE_BUNDLES} for discussion of this.
+ *
+ * <p>
+ *
+ * In most use cases, one can provide a single line, e.g. if releasing a v2.0.0:
+ *
+ * {@code brooklyn-catalog-upgrade-for-bundles: *:[0,2)}
+ *
+ * to indicate that this bundle is able to upgrade all instances of this bundle lower than 2.0.0,
+ * and all types in this bundle will upgrade earlier types.
+ *
+ * This can be used in conjunction with:
+ *
+ * {@code brooklyn-catalog-force-remove-bundles: *:[0,2)}
+ *
+ * to forcibly remove older bundles at an appropriate point (eg a restart) and cause all earlier instances of the bundle
+ * and the type instances they contain to be upgraded with the same-named types in the 2.0.0 bundle.
+ *
+ * It is not necessary to supply {@link #MANIFEST_HEADER_UPGRADE_FOR_TYPES} unless types are being renamed
+ * or versions are not in line with previous versions of this bundle.
+ */
+ @Beta
+ public static final String MANIFEST_HEADER_UPGRADE_FOR_BUNDLES = "brooklyn-catalog-upgrade-for-bundles";
+
+ /**
+ * A header in a bundle's manifest, indicating that this bundle recommends a set of upgrades.
+ * These will be advisory unless the type being upgraded is force-removed in which case it will be applied automatically
+ * wherever the type is in use.
+ *
+ * The format is as per {@link #MANIFEST_HEADER_UPGRADE_FOR_BUNDLES}, with two differences in interpretation.
+ *
+ * If {@code =value} is omitted, the ugprade target is assumed to be the same type as the corresonding key but at the
+ * version of the bundle.
+ *
+ * A wildcard can be given as the key, without a version ({@code *}) or with ({@code *:[0,1)}) to refer to
+ * all types in the present bundle.
+ *
+ * If the version/range for a type is omitted in any key, it is inferred as the versions of this bundle
+ * that this bundle declares it can upgrade in the {@link #MANIFEST_HEADER_UPGRADE_FOR_BUNDLES} header.
+ * It is an error to omit a version/range if that header is not present or does not declare versions
+ * of the same bundle being upgraded.
+ *
+ * If this key is omitted, then the default is {@code *} if a {@link #MANIFEST_HEADER_UPGRADE_FOR_BUNDLES} header
+ * is present and empty if that header is not present.
+ *
+ * What this is saying in most cases is that if a bundle {@code foo:1} contains {@code foo-node:1}, and
+ * bundle {@code foo:2} contains {@code foo-node:2}, then:
+ * if {@code foo:2} declares {@code brooklyn-catalog-upgrade-for-bundles: foo:1} it will also declare that
+ * {@code foo-node:2} upgrades {@code foo-node:1};
+ * if {@code foo:2} declares {@code brooklyn-catalog-upgrade-for-bundles: *} the same thing will occur
+ * (and it would also upgrade a {@code foo:0} contains {@code foo-node:0});
+ * if {@code foo:2} declares no {@code brooklyn-catalog-upgrade} manifest headers, then no advisory
+ * upgrades will be noted.
+ *
+ * As noted in {@link #MANIFEST_HEADER_UPGRADE_FOR_BUNDLES} the primary use case for this header is type renames.
+ */
+ @Beta
+ public static final String MANIFEST_HEADER_UPGRADE_FOR_TYPES = "brooklyn-catalog-upgrade-for-types";
+
/**
* The result from parsing bundle(s) to find their upgrade info.
*/
@@ -116,6 +195,8 @@ public class BundleUpgradeParser {
public static class Builder {
private Set<VersionRangedName> removedLegacyItems = new LinkedHashSet<>();
private Set<VersionRangedName> removedBundles = new LinkedHashSet<>();
+ private Map<VersionedName,VersionRangedName> upgradeBundles = new LinkedHashMap<>();
+ private Map<VersionedName,VersionRangedName> upgradeTypes = new LinkedHashMap<>();
public Builder removedLegacyItems(Collection<VersionRangedName> vals) {
removedLegacyItems.addAll(vals);
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9173183f/launcher/src/test/java/org/apache/brooklyn/launcher/AbstractBrooklynLauncherRebindTest.java
----------------------------------------------------------------------
diff --git a/launcher/src/test/java/org/apache/brooklyn/launcher/AbstractBrooklynLauncherRebindTest.java b/launcher/src/test/java/org/apache/brooklyn/launcher/AbstractBrooklynLauncherRebindTest.java
index 474c72b..461dce7 100644
--- a/launcher/src/test/java/org/apache/brooklyn/launcher/AbstractBrooklynLauncherRebindTest.java
+++ b/launcher/src/test/java/org/apache/brooklyn/launcher/AbstractBrooklynLauncherRebindTest.java
@@ -41,15 +41,22 @@ import javax.annotation.Nullable;
import org.apache.brooklyn.api.catalog.BrooklynCatalog;
import org.apache.brooklyn.api.catalog.CatalogItem;
+import org.apache.brooklyn.api.entity.Application;
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.api.mgmt.ManagementContext;
import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityMode;
import org.apache.brooklyn.api.objs.BrooklynObjectType;
import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry;
import org.apache.brooklyn.api.typereg.ManagedBundle;
import org.apache.brooklyn.api.typereg.RegisteredType;
+import org.apache.brooklyn.camp.brooklyn.spi.creation.CampTypePlanTransformer;
import org.apache.brooklyn.core.catalog.internal.CatalogInitialization;
+import org.apache.brooklyn.core.entity.trait.Startable;
import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
import org.apache.brooklyn.core.mgmt.persist.PersistMode;
import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
+import org.apache.brooklyn.core.typereg.RegisteredTypeLoadingContexts;
import org.apache.brooklyn.entity.stock.BasicEntity;
import org.apache.brooklyn.util.collections.MutableMap;
import org.apache.brooklyn.util.core.ResourceUtils;
@@ -214,7 +221,7 @@ public abstract class AbstractBrooklynLauncherRebindTest {
}
protected void assertManagedBundle(BrooklynLauncher launcher, VersionedName bundleId, Set<VersionedName> expectedCatalogItems) {
- assertNotNull(findManagedBundle(launcher, bundleId), bundleId+" not found");
+ assertNotNull(findManagedBundle(launcher, bundleId), "Bundle "+bundleId+" not found");
Set<VersionedName> actualCatalogItems = new LinkedHashSet<>();
Iterable<RegisteredType> types = launcher.getManagementContext().getTypeRegistry().getAll();
@@ -402,4 +409,13 @@ public abstract class AbstractBrooklynLauncherRebindTest {
launcher.terminate();
}
}
+
+ public static Application createAndStartApplication(ManagementContext mgmt, String input) throws Exception {
+ EntitySpec<?> spec =
+ mgmt.getTypeRegistry().createSpecFromPlan(CampTypePlanTransformer.FORMAT, input, RegisteredTypeLoadingContexts.spec(Application.class), EntitySpec.class);
+ final Entity app = mgmt.getEntityManager().createEntity(spec);
+ app.invoke(Startable.START, MutableMap.of()).get();
+ return (Application) app;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9173183f/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 119f341..b67a29e 100644
--- a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindCatalogOsgiTest.java
+++ b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindCatalogOsgiTest.java
@@ -30,16 +30,20 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
+import org.apache.brooklyn.api.entity.Application;
+import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.mgmt.ManagementContext;
import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityMode;
import org.apache.brooklyn.api.mgmt.ha.ManagementNodeState;
import org.apache.brooklyn.api.objs.BrooklynObjectType;
+import org.apache.brooklyn.api.typereg.RegisteredType;
import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog;
import org.apache.brooklyn.core.catalog.internal.CatalogInitialization;
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.RebindTestUtils;
+import org.apache.brooklyn.core.typereg.BundleUpgradeParser;
import org.apache.brooklyn.test.Asserts;
import org.apache.brooklyn.test.support.TestResourceUnavailableException;
import org.apache.brooklyn.util.core.osgi.Osgis;
@@ -49,6 +53,8 @@ import org.apache.brooklyn.util.os.Os;
import org.apache.brooklyn.util.osgi.OsgiTestResources;
import org.apache.brooklyn.util.osgi.VersionedName;
import org.apache.brooklyn.util.text.Identifiers;
+import org.apache.brooklyn.util.time.Duration;
+import org.apache.brooklyn.util.time.Time;
import org.osgi.framework.Bundle;
import org.osgi.framework.launch.Framework;
import org.testng.Assert;
@@ -140,6 +146,10 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
}
protected void startT2(BrooklynLauncher l) {
+ startT2(l, true);
+ }
+
+ protected void startT2(BrooklynLauncher l, boolean assertSuccess) {
if (launcherT2!=null) throw new IllegalStateException("Already started T2 launcher");
try {
@@ -153,7 +163,6 @@ 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);
@@ -162,9 +171,14 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
if (startupAssertions!=null) startupAssertions.run();
}
protected void promoteT2IfStandby() {
+ promoteT2IfStandby(true);
+ }
+ protected void promoteT2IfStandby(boolean assertSuccess) {
if (isT1KeptRunningWhenT2Starts()) {
launcherT1.terminate();
- assertMasterEventually(launcherT2);
+ if (assertSuccess) {
+ assertMasterEventually(launcherT2);
+ }
if (startupAssertions!=null) startupAssertions.run();
}
@@ -449,8 +463,10 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
}
protected String getBundleSupplyingFirstType(Set<VersionedName> bundleItems) {
- return VersionedName.fromString( launcherLast.getManagementContext().getTypeRegistry().get(
- bundleItems.iterator().next().toString() ).getContainingBundle() ).getVersionString();
+ RegisteredType type = launcherLast.getManagementContext().getTypeRegistry().get(
+ bundleItems.iterator().next().toString() );
+ if (type==null) return null;
+ return VersionedName.fromString( type.getContainingBundle() ).getVersionString();
}
@Test
@@ -599,12 +615,34 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
Assert.assertNotEquals(bundlePersistenceId1, bundlePersistenceId2);
}
}
-
- // TODO removed item in deployment fails - rebind and upgrade uses new item
- // TODO removed item in deployment upgrades - rebind and upgrade uses new item
- // TODO removed item in spec fails
- // TODO removed item in spec upgrades
- // TODO removed item deployed after rebind
+
+ @Test
+ // might change this to fail in future, see RebindIteration.load
+ public void testRebindRemovedItemWorksIfJavaClassFound() throws Exception {
+ Set<VersionedName> bundleItemsV1 = ImmutableSet.of(VersionedName.fromString("one:1.0.0"));
+ String bundleBomV1 = createCatalogYaml(ImmutableList.of(), bundleItemsV1);
+ VersionedName bundleNameV1 = new VersionedName("org.example.testRebindGetsInitialOsgiCatalog", "1.0.0");
+ File bundleFileV1 = newTmpBundle(ImmutableMap.of(BasicBrooklynCatalog.CATALOG_BOM, bundleBomV1.getBytes(StandardCharsets.UTF_8)), bundleNameV1);
+ File initialBomFileV1 = newTmpFile(createCatalogYaml(ImmutableList.of(bundleFileV1.toURI()), ImmutableList.of()));
+
+ Set<VersionedName> bundleItemsV2 = ImmutableSet.of(VersionedName.fromString("one:2.0.0"));
+ String bundleBomV2 = createCatalogYaml(ImmutableList.of(), bundleItemsV2);
+ VersionedName bundleNameV2 = new VersionedName("org.example.testRebindGetsInitialOsgiCatalog", "2.0.0");
+ File bundleFileV2 = newTmpBundle(ImmutableMap.of(BasicBrooklynCatalog.CATALOG_BOM, bundleBomV2.getBytes(StandardCharsets.UTF_8)), bundleNameV2,
+ ImmutableMap.of(BundleUpgradeParser.MANIFEST_HEADER_FORCE_REMOVE_BUNDLES, "*"));
+ File initialBomFileV2 = newTmpFile(createCatalogYaml(ImmutableList.of(bundleFileV2.toURI()), ImmutableList.of()));
+
+ startT1(newLauncherForTests(initialBomFileV1.getAbsolutePath()));
+ Application app = createAndStartApplication(launcherLast.getManagementContext(),
+ "services: [ { type: 'one:1.0.0' } ]");
+
+ // should start and promote fine, but entity's type shouldn't be loadable (and there will be warnings)
+ startT2(newLauncherForTests(initialBomFileV2.getAbsolutePath()));
+ promoteT2IfStandby();
+
+ Entity entity = Iterables.getOnlyElement( Iterables.getOnlyElement(launcherLast.getManagementContext().getApplications()).getChildren() );
+ Assert.assertEquals(entity.getCatalogItemId(), bundleItemsV1.iterator().next());
+ }
protected void assertPersistedBundleListingEqualsEventually(BrooklynLauncher launcher, Set<VersionedName> bundles) {
Asserts.succeedsEventually(new Runnable() {
@@ -703,5 +741,17 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
String bundleBom = createCatalogYaml(ImmutableList.of(), ImmutableList.of(), catalogItems, randomNoise);
return newTmpBundle(ImmutableMap.of(BasicBrooklynCatalog.CATALOG_BOM, bundleBom.getBytes(StandardCharsets.UTF_8)), bundleName);
}
-
+
+ public static void main(String[] args) throws Exception {
+ try {
+ BrooklynLauncherRebindCatalogOsgiTest fixture = new LauncherRebindSubTests();
+ fixture.setUp();
+ fixture.testRebindRemovedItemWorksIfJavaClassFound();
+ fixture.tearDown();
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ System.exit(0);
+ }
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9173183f/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherUpgradeCatalogOsgiTest.java
----------------------------------------------------------------------
diff --git a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherUpgradeCatalogOsgiTest.java b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherUpgradeCatalogOsgiTest.java
index a6f5129..289b96a 100644
--- a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherUpgradeCatalogOsgiTest.java
+++ b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherUpgradeCatalogOsgiTest.java
@@ -21,21 +21,26 @@ package org.apache.brooklyn.launcher;
import static org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog.CATALOG_BOM;
import static org.apache.brooklyn.core.typereg.BundleUpgradeParser.MANIFEST_HEADER_FORCE_REMOVE_BUNDLES;
import static org.apache.brooklyn.core.typereg.BundleUpgradeParser.MANIFEST_HEADER_FORCE_REMOVE_LEGACY_ITEMS;
+import static org.apache.brooklyn.core.typereg.BundleUpgradeParser.MANIFEST_HEADER_UPGRADE_FOR_BUNDLES;
import java.io.File;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.Map;
+import org.apache.brooklyn.api.entity.Application;
+import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog;
import org.apache.brooklyn.core.catalog.internal.CatalogInitialization;
import org.apache.brooklyn.util.osgi.VersionedName;
+import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
public class BrooklynLauncherUpgradeCatalogOsgiTest extends AbstractBrooklynLauncherRebindTest {
@@ -144,4 +149,47 @@ public class BrooklynLauncherUpgradeCatalogOsgiTest extends AbstractBrooklynLaun
assertManagedBundle(launcher, bundleVersionedName, ImmutableSet.<VersionedName>of(one_1_0_0));
launcher.terminate();
}
+
+ // removed item with upgrade deployed after rebind
+ // TODO WIP
+ @Test
+ public void testForceUpgradeItemByRemovingBundle() throws Exception {
+ VersionedName one_1_0_0 = VersionedName.fromString("one:1.0.0");
+ VersionedName one_2_0_0 = VersionedName.fromString("one:2.0.0");
+
+ String bundleSymbolicName = "org.example.testForceUpgradeBundle";
+ VersionedName bundleVersionedName1 = new VersionedName(bundleSymbolicName, "1.0.0");
+ String bundleBom1 = createCatalogYaml(ImmutableList.<URI>of(), ImmutableSet.<VersionedName>of(one_1_0_0));
+ File bundleFile1 = newTmpBundle(ImmutableMap.of(BasicBrooklynCatalog.CATALOG_BOM, bundleBom1.getBytes(StandardCharsets.UTF_8)), bundleVersionedName1);
+
+ newPersistedStateInitializer()
+ .bundle(bundleVersionedName1, bundleFile1)
+ .initState();
+
+ VersionedName bundleVersionedName2 = new VersionedName(bundleSymbolicName, "2.0.0");
+ String bundleBom2 = createCatalogYaml(ImmutableList.<URI>of(), ImmutableSet.<VersionedName>of(one_2_0_0));
+ Map<String, String> bundleManifest2 = ImmutableMap.of(
+ MANIFEST_HEADER_FORCE_REMOVE_BUNDLES, "\""+bundleSymbolicName+":[0.0.0,2.0.0)\"",
+ MANIFEST_HEADER_UPGRADE_FOR_BUNDLES, "*");
+ File bundleFile2 = newTmpBundle(ImmutableMap.of(BasicBrooklynCatalog.CATALOG_BOM, bundleBom2.getBytes(StandardCharsets.UTF_8)), bundleVersionedName2, bundleManifest2);
+
+ File initialBomFile = newTmpFile(createCatalogYaml(ImmutableList.of(bundleFile2.toURI()), ImmutableList.of()));
+
+ BrooklynLauncher launcher = newLauncherForTests(initialBomFile.getAbsolutePath());
+ launcher.start();
+
+ Application app = createAndStartApplication(launcher.getManagementContext(),
+ "services: [ { type: 'one:1.0.0' } ]");
+ Entity one = Iterables.getOnlyElement( app.getChildren() );
+ Assert.assertEquals(one.getCatalogItemId(), "one:2.0.0");
+
+ launcher.terminate();
+ }
+
+ // NB other related tests in BrooklynLauncherRebindCatalogOsgiTest:
+ // * removed item in deployment fails - rebind and upgrade uses new item
+ // * removed item in deployment upgrades - rebind and upgrade uses new item
+ // * removed item in spec fails
+ // * removed item in spec upgrades
+
}
[08/10] brooklyn-server git commit: parse upgrade maps and test that
Posted by he...@apache.org.
parse upgrade maps and test that
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/af3f5f51
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/af3f5f51
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/af3f5f51
Branch: refs/heads/master
Commit: af3f5f511b44d0248acd7fd254f6aee8783ad811
Parents: 8473fb4
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Tue Oct 31 12:36:55 2017 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Tue Oct 31 12:36:55 2017 +0000
----------------------------------------------------------------------
.../core/typereg/BundleUpgradeParser.java | 203 ++++++++++++++---
.../core/typereg/BundleUpgradeParserTest.java | 223 +++++++++++++++++--
.../BrooklynLauncherUpgradeCatalogOsgiTest.java | 2 +-
3 files changed, 372 insertions(+), 56 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/af3f5f51/core/src/main/java/org/apache/brooklyn/core/typereg/BundleUpgradeParser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/BundleUpgradeParser.java b/core/src/main/java/org/apache/brooklyn/core/typereg/BundleUpgradeParser.java
index 73327e9..437fc5a 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/BundleUpgradeParser.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/BundleUpgradeParser.java
@@ -27,6 +27,7 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.stream.Collectors;
import org.apache.brooklyn.api.catalog.CatalogItem;
import org.apache.brooklyn.api.typereg.RegisteredType;
@@ -42,6 +43,7 @@ import org.osgi.framework.VersionRange;
import com.google.common.annotations.Beta;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
@@ -167,7 +169,7 @@ public class BundleUpgradeParser {
*
* The format is as per {@link #MANIFEST_HEADER_UPGRADE_FOR_BUNDLES}, with two differences in interpretation.
*
- * If {@code =value} is omitted, the ugprade target is assumed to be the same type as the corresonding key but at the
+ * If {@code =value} is omitted, the upgrade target is assumed to be the same type as the corresponding key but at the
* version of the bundle.
*
* A wildcard can be given as the key, without a version ({@code *}) or with ({@code *:[0,1)}) to refer to
@@ -252,7 +254,7 @@ public class BundleUpgradeParser {
}
public boolean isEmpty() {
- return removedLegacyItems.isEmpty() && removedBundles.isEmpty();
+ return removedLegacyItems.isEmpty() && removedBundles.isEmpty() && upgradesProvidedByBundles.isEmpty() && upgradesProvidedByTypes.isEmpty();
}
public Set<VersionRangedName> getRemovedLegacyItems() {
@@ -404,37 +406,77 @@ public class BundleUpgradeParser {
// section "Bundle Upgrade Metadata"
Dictionary<String, String> headers = bundle.getHeaders();
- Multimap<VersionedName,VersionRangedName> upgradesForBundles = parseUpgradeForBundlesHeader(headers.get(MANIFEST_HEADER_UPGRADE_FOR_BUNDLES), bundle);
+ String upgradesForBundlesHeader = headers.get(MANIFEST_HEADER_UPGRADE_FOR_BUNDLES);
+ Multimap<VersionedName,VersionRangedName> upgradesForBundles = parseUpgradeForBundlesHeader(upgradesForBundlesHeader, bundle);
return CatalogUpgrades.builder()
.removedLegacyItems(parseForceRemoveLegacyItemsHeader(headers.get(MANIFEST_HEADER_FORCE_REMOVE_LEGACY_ITEMS), bundle, typeSupplier))
.removedBundles(parseForceRemoveBundlesHeader(headers.get(MANIFEST_HEADER_FORCE_REMOVE_BUNDLES), bundle))
.upgradeBundles(upgradesForBundles)
- .upgradeTypes(parseUpgradeForTypesHeader(headers.get(MANIFEST_HEADER_UPGRADE_FOR_TYPES), bundle, upgradesForBundles))
+ .upgradeTypes(parseUpgradeForTypesHeader(headers.get(MANIFEST_HEADER_UPGRADE_FOR_TYPES), bundle, typeSupplier,
+ upgradesForBundlesHeader==null ? null : upgradesForBundles))
.build();
}
- private static Multimap<VersionedName, VersionRangedName> parseUpgradeForBundlesHeader(String input, Bundle bundle) {
- return LinkedHashMultimap.<VersionedName, VersionRangedName>create();
+ @VisibleForTesting
+ static List<VersionRangedName> parseForceRemoveLegacyItemsHeader(String input, Bundle bundle, Supplier<? extends Iterable<? extends RegisteredType>> typeSupplier) {
+ return parseVersionRangedNameList(input, false, getTypeNamesInBundle(typeSupplier), "[0,"+bundle.getVersion()+")");
}
- private static Multimap<VersionedName, VersionRangedName> parseUpgradeForTypesHeader(String input, Bundle bundle, Multimap<VersionedName, VersionRangedName> upgradesForBundles) {
- return LinkedHashMultimap.<VersionedName, VersionRangedName>create();
+
+ @VisibleForTesting
+ static List<VersionRangedName> parseForceRemoveBundlesHeader(String input, Bundle bundle) {
+ if (input == null) return ImmutableList.of();
+ return parseVersionRangedNameList(input, false, MutableList.of(bundle.getSymbolicName()), getDefaultSourceVersionRange(bundle));
}
+ private static Multimap<VersionedName, VersionRangedName> parseUpgradeForBundlesHeader(String input, Bundle bundle) {
+ return parseVersionRangedNameEqualsVersionedNameList(input, false,
+ // wildcard means this bundle, all lower versions
+ MutableList.of(bundle.getSymbolicName()), MutableList.of(getDefaultSourceVersionRange(bundle)),
+ // default target is this bundle
+ (i) -> { return new VersionedName(bundle); });
+ }
+ private static Multimap<VersionedName, VersionRangedName> parseUpgradeForTypesHeader(String input, Bundle bundle, Supplier<? extends Iterable<? extends RegisteredType>> typeSupplier, Multimap<VersionedName, VersionRangedName> upgradesForBundles) {
+ List<String> sourceVersions = null;
+ if (upgradesForBundles!=null) {
+ Collection<VersionRangedName> acceptableRanges = upgradesForBundles.get(new VersionedName(bundle));
+ if (acceptableRanges!=null && !acceptableRanges.isEmpty()) {
+ for (VersionRangedName n: acceptableRanges) {
+ if (n.getSymbolicName().equals(bundle.getSymbolicName())) {
+ if (sourceVersions==null) {
+ sourceVersions = MutableList.of();
+ }
+ sourceVersions.add(n.getOsgiVersionRange().toString());
+ }
+ }
+ }
+ }
+ Set<VersionedName> typeSupplierNames = MutableList.copyOf(typeSupplier.get()).stream().map(
+ (t) -> VersionedName.toOsgiVersionedName(t.getVersionedName())).collect(Collectors.toSet());
+ return parseVersionRangedNameEqualsVersionedNameList(input, false,
+ // wildcard means all types, all versions of this bundle this bundle replaces
+ getTypeNamesInBundle(typeSupplier), sourceVersions,
+ // default target is same type at version of this bundle
+ (i) -> {
+ VersionedName targetTypeAtBundleVersion = new VersionedName(i.getSymbolicName(), bundle.getVersion());
+ if (!typeSupplierNames.contains(VersionedName.toOsgiVersionedName(targetTypeAtBundleVersion))) {
+ throw new IllegalStateException("Bundle manifest declares it upgrades "+i+" "
+ + "but does not declare an explicit target and does not contain inferred target "+targetTypeAtBundleVersion);
+ }
+ return targetTypeAtBundleVersion;
+ });
+ }
+
@VisibleForTesting
- static List<VersionRangedName> parseForceRemoveLegacyItemsHeader(String input, Bundle bundle, Supplier<? extends Iterable<? extends RegisteredType>> typeSupplier) {
- if (input == null) return ImmutableList.of();
+ static List<String> getTypeNamesInBundle(Supplier<? extends Iterable<? extends RegisteredType>> typeSupplier) {
List<String> wildcardItems = MutableList.of();
for (RegisteredType item : typeSupplier.get()) {
wildcardItems.add(item.getSymbolicName());
}
- return parseVersionRangedNameList(input, false, wildcardItems, "[0,"+bundle.getVersion()+")");
+ return wildcardItems;
}
-
@VisibleForTesting
- static List<VersionRangedName> parseForceRemoveBundlesHeader(String input, Bundle bundle) {
- if (input == null) return ImmutableList.of();
-
+ static String getDefaultSourceVersionRange(Bundle bundle) {
String bundleVersion = bundle.getVersion().toString();
String maxVersion;
if (BrooklynVersionSyntax.isSnapshot(bundleVersion)) {
@@ -442,8 +484,8 @@ public class BundleUpgradeParser {
} else {
maxVersion = bundleVersion;
}
-
- return parseVersionRangedNameList(input, false, MutableList.of(bundle.getSymbolicName()), "[0,"+maxVersion+")");
+ String defaultSourceVersion = "[0,"+maxVersion+")";
+ return defaultSourceVersion;
}
@VisibleForTesting
@@ -459,23 +501,29 @@ public class BundleUpgradeParser {
List<VersionRangedName> versionedItems = new ArrayList<>();
for (String val : vals) {
- try {
- val = val.trim();
- if (val.startsWith("*")) {
- String r;
- if ("*".equals(val)) {
- r = wildcardVersion;
- } else if (val.startsWith("*:")) {
- r = val.substring(2);
- } else {
- throw new IllegalArgumentException("Wildcard entry must be of the form \"*\" or \"*:range\"");
- }
- for (String item: wildcardNames) {
- versionedItems.add(new VersionRangedName(item, r, false));
- }
+ val = val.trim();
+ if (val.startsWith("*")) {
+ String r;
+ if ("*".equals(val)) {
+ r = wildcardVersion;
+ } else if (val.startsWith("*:")) {
+ r = val.substring(2);
} else {
- versionedItems.add(VersionRangedName.fromString(val, singleVersionIsOsgiRange));
+ throw new IllegalArgumentException("Wildcard entry must be of the form \"*\" or \"*:range\"");
}
+ for (String item: wildcardNames) {
+ versionedItems.add(parseVersionRangedName(item, r, false));
+ }
+ } else {
+ versionedItems.add(parseVersionRangedName(val, singleVersionIsOsgiRange));
+ }
+ }
+ return versionedItems;
+ }
+
+ private static VersionRangedName parseVersionRangedName(String val, boolean singleVersionIsOsgiRange) {
+ try {
+ return VersionRangedName.fromString(val, singleVersionIsOsgiRange);
} catch (Exception e) {
if (Strings.containsAny(val, "(", ")", "[", "]") &&
!Strings.containsAny(val, "'", "\"")) {
@@ -484,7 +532,93 @@ public class BundleUpgradeParser {
throw Exceptions.propagate(e);
}
}
- return versionedItems;
+
+ private static VersionRangedName parseVersionRangedName(String name, String range, boolean singleVersionIsOsgiRange) {
+ try {
+ return new VersionRangedName(name, range, singleVersionIsOsgiRange);
+ } catch (Exception e) {
+ if (Strings.containsAny(range, "(", ")", "[", "]") &&
+ !Strings.containsAny(range, "'", "\"")) {
+ throw Exceptions.propagateAnnotated("Entry cannot be parsed. If defining a range on an entry you must quote the entry.", e);
+ }
+ throw Exceptions.propagate(e);
+ }
+ }
+
+ @VisibleForTesting
+ static Multimap<VersionedName,VersionRangedName> parseVersionRangedNameEqualsVersionedNameList(String input, boolean singleVersionIsOsgiRange,
+ List<String> wildcardNames, List<String> wildcardVersions,
+ Function<VersionRangedName,VersionedName> defaultTargetFunction) {
+ LinkedHashMultimap<VersionedName,VersionRangedName> result = LinkedHashMultimap.create();
+ if (input == null) return result;
+
+ List<String> vals = QuotedStringTokenizer.builder()
+ .delimiterChars(",")
+ .includeQuotes(false)
+ .includeDelimiters(false)
+ .buildList(input);
+
+ for (String entry : vals) {
+ entry = entry.trim();
+ String key, val;
+ String[] keVals = entry.split("=");
+ if (keVals.length>2) {
+ throw new IllegalArgumentException("Max one = permitted in entry (\""+entry+"\"). If defining a range on an entry you must quote the entry.");
+ } else if (keVals.length==2) {
+ key = keVals[0];
+ val = keVals[1];
+ } else {
+ key = keVals[0];
+ val = null;
+ }
+
+ List<String> sourceNames, sourceVersions;
+ if (key.startsWith("*")) {
+ if (wildcardNames==null) {
+ throw new IllegalArgumentException("Wildcard cannot be inferred");
+ }
+ if ("*".equals(key)) {
+ if (wildcardVersions==null) {
+ throw new IllegalArgumentException("Version for wildcard cannot be inferred");
+ }
+ sourceVersions = wildcardVersions;
+ } else if (key.startsWith("*:")) {
+ sourceVersions = MutableList.of(key.substring(2));
+ } else {
+ throw new IllegalArgumentException("Wildcard entry key must be of the form \"*\" or \"*:range\"");
+ }
+ sourceNames = MutableList.copyOf(wildcardNames);
+ } else {
+ String[] parts = key.split(":");
+ if (parts.length==1) {
+ if (wildcardVersions==null) {
+ throw new IllegalArgumentException("Version for "+key+" cannot be inferred");
+ }
+ sourceNames = MutableList.of(key);
+ sourceVersions = wildcardVersions;
+ } else if (parts.length==2) {
+ sourceNames = MutableList.of(parts[0]);
+ sourceVersions = MutableList.of(parts[1]);
+ } else {
+ throw new IllegalArgumentException("Entry '"+entry+"' should be of form 'name[:versionRange][=name[:version]]'");
+ }
+ }
+ for (String item: sourceNames) {
+ for (String v: sourceVersions) {
+ VersionRangedName source = parseVersionRangedName(item, v, false);
+ VersionedName target;
+ if (val!=null) {
+ target = VersionedName.fromString(val);
+ } else if (defaultTargetFunction!=null) {
+ target = defaultTargetFunction.apply(source);
+ } else {
+ throw new IllegalArgumentException("Wildcard entry key must be of the form \"*\" or \"*:range\"");
+ }
+ result.put(target, source);
+ }
+ }
+ }
+ return result;
}
@VisibleForTesting
@@ -494,4 +628,5 @@ public class BundleUpgradeParser {
&& quoteChars.contains(input.substring(input.length() - 1));
return (quoted ? input.substring(1, input.length() - 1) : input);
}
-}
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/af3f5f51/core/src/test/java/org/apache/brooklyn/core/typereg/BundleUpgradeParserTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/typereg/BundleUpgradeParserTest.java b/core/src/test/java/org/apache/brooklyn/core/typereg/BundleUpgradeParserTest.java
index 64c8a6e..16f87b7 100644
--- a/core/src/test/java/org/apache/brooklyn/core/typereg/BundleUpgradeParserTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/typereg/BundleUpgradeParserTest.java
@@ -26,6 +26,7 @@ import java.util.Dictionary;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.apache.brooklyn.api.catalog.CatalogItem;
import org.apache.brooklyn.api.typereg.RegisteredType;
@@ -39,15 +40,23 @@ import org.mockito.Mockito;
import org.osgi.framework.Bundle;
import org.osgi.framework.Version;
import org.osgi.framework.VersionRange;
+import org.testng.Assert;
import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.LinkedHashMultimap;
+import com.google.common.collect.Multimap;
public class BundleUpgradeParserTest {
+ private static final String DEFAULT_WILDCARD_NAME = "WILDCARD-NAME";
+ private static final String DEFAULT_WILDCARD_VERSION = "0-WILDCARD_VERSION";
+ private static final String DEFAULT_WILDCARD_VERSION_RANGE = "[0,"+DEFAULT_WILDCARD_VERSION+")";
+ private static final String DEFAULT_TARGET_VERSION = "0-DEFAULT-TARGET";
+
private VersionRange from0lessThan1 = new VersionRange('[', Version.valueOf("0"), Version.valueOf("1.0.0"), ')');
private VersionRange from0lessThan1_2_3 = new VersionRange('[', Version.valueOf("0"), Version.valueOf("1.2.3"), ')');
private VersionRange exactly0dot1 = new VersionRange('[', Version.valueOf("0.1.0"), Version.valueOf("0.1.0"), ']');
@@ -86,27 +95,64 @@ public class BundleUpgradeParserTest {
@Test
public void testParseSingleQuotedVal() throws Exception {
String input = "\"foo:[0,1.0.0)\"";
- assertParseList(input, ImmutableList.of(fooFrom0lessThan1));
+ assertParseListVersionRangeNames(input, ImmutableList.of(fooFrom0lessThan1));
}
@Test
public void testParseSingleQuotedValWithNestedQuotes() throws Exception {
String input = "\"foo:[0,\"1.0.0\")\"";
- assertParseList(input, ImmutableList.of(fooFrom0lessThan1));
+ assertParseListVersionRangeNames(input, ImmutableList.of(fooFrom0lessThan1));
}
@Test
public void testParseMultipleVals() throws Exception {
String input = "\"foo:[0,1.0.0)\",\"bar:[0,1.0.0)\"";
- assertParseList(input, ImmutableList.of(fooFrom0lessThan1, barFrom0lessThan1));
+ assertParseListVersionRangeNames(input, ImmutableList.of(fooFrom0lessThan1, barFrom0lessThan1));
}
@Test
public void testParseValWithExactVersion() throws Exception {
String input = "\"foo:0.1.0\"";
- assertParseList(input, ImmutableList.of(new VersionRangedName("foo", exactly0dot1)));
+ assertParseListVersionRangeNames(input, ImmutableList.of(new VersionRangedName("foo", exactly0dot1)));
}
-
+
+ @Test
+ public void testParseKeyEqualsValue() throws Exception {
+ String input = "\"foo:[0,1)=foo:1\"";
+ Multimap<VersionedName, VersionRangedName> expected = LinkedHashMultimap.create();
+ expected.put(VersionedName.fromString("foo:1"), VersionRangedName.fromString("foo:[0,1)", false));
+ assertParseListVersionRangedNameToVersionedNames(input, expected);
+ }
+
+ @Test
+ public void testParseKeyEqualsValueList() throws Exception {
+ String input = "\"foo:[0,1)=foo:1\", foo:1-SNAPSHOT=foo:1, bar:0=bar:1";
+ Multimap<VersionedName, VersionRangedName> expected = LinkedHashMultimap.create();
+ expected.put(VersionedName.fromString("foo:1"), VersionRangedName.fromString("foo:[0,1)", false));
+ expected.put(VersionedName.fromString("foo:1"), VersionRangedName.fromString("foo:1-SNAPSHOT", false));
+ expected.put(VersionedName.fromString("bar:1"), VersionRangedName.fromString("bar:0", false));
+ assertParseListVersionRangedNameToVersionedNames(input, expected);
+ }
+
+ @Test
+ public void testParseKeyEqualsValueWildcardsAndDefault() throws Exception {
+ String input = "foo, foo:9-bogus, *, *:8, \"*:[9-bogus,9-bogut)=foo9:10.bogus\"";
+ Multimap<VersionedName, VersionRangedName> expected = LinkedHashMultimap.create();
+ expected.putAll(new VersionedName("foo", DEFAULT_TARGET_VERSION),
+ MutableList.of(
+ VersionRangedName.fromString("foo:"+DEFAULT_WILDCARD_VERSION_RANGE, false),
+ VersionRangedName.fromString("foo:"+"9-bogus", false)
+ ));
+ expected.putAll(new VersionedName(DEFAULT_WILDCARD_NAME, DEFAULT_TARGET_VERSION),
+ MutableList.of(
+ VersionRangedName.fromString(DEFAULT_WILDCARD_NAME+":"+DEFAULT_WILDCARD_VERSION_RANGE, false),
+ VersionRangedName.fromString(DEFAULT_WILDCARD_NAME+":8", false)
+ ));
+ expected.put(new VersionedName("foo9", "10.bogus"),
+ VersionRangedName.fromString(DEFAULT_WILDCARD_NAME+":[9-bogus,9-bogut)", false));
+ assertParseListVersionRangedNameToVersionedNames(input, expected);
+ }
+
@Test
public void testParseForceRemoveBundlesHeader() throws Exception {
Bundle bundle = newMockBundle(new VersionedName("foo.bar", "1.2.3"));
@@ -154,24 +200,14 @@ public class BundleUpgradeParserTest {
}
@Test
- public void testParseBundleManifest() throws Exception {
+ public void testParseBundleManifestRemovals() throws Exception {
Bundle bundle = newMockBundle(ImmutableMap.of(
BundleUpgradeParser.MANIFEST_HEADER_FORCE_REMOVE_LEGACY_ITEMS, "\"foo:[0,1.0.0)\",\"foo:1.0.0.SNAPSHOT\",\"bar:[0,1.0.0)\"",
- BundleUpgradeParser.MANIFEST_HEADER_FORCE_REMOVE_BUNDLES, "\"org.example.brooklyn.mybundle:[0,1.0.0)\"",
- BundleUpgradeParser.MANIFEST_HEADER_UPGRADE_FOR_BUNDLES, "\"org.example.brooklyn.mybundle:[0,1.0.0)=org.example.brooklyn.mybundle:1\"",
- BundleUpgradeParser.MANIFEST_HEADER_UPGRADE_FOR_TYPES, "\"foo:[0,1)=foo:1\""));
- checkParse(bundle);
+ BundleUpgradeParser.MANIFEST_HEADER_FORCE_REMOVE_BUNDLES, "\"org.example.brooklyn.mybundle:[0,1.0.0)\""));
+ checkParseRemovals(bundle);
}
- @Test
- public void testParseBundleManifestWithSpaces() throws Exception {
- Bundle bundle = newMockBundle(ImmutableMap.of(
- BundleUpgradeParser.MANIFEST_HEADER_FORCE_REMOVE_LEGACY_ITEMS, "\"foo:[0,1.0.0)\", \"foo:1.0.0.SNAPSHOT\", \"bar:[0,1.0.0)\"",
- BundleUpgradeParser.MANIFEST_HEADER_FORCE_REMOVE_BUNDLES, " \"org.example.brooklyn.mybundle:[0,1.0.0)\""));
- checkParse(bundle);
- }
-
- protected void checkParse(Bundle bundle) {
+ protected void checkParseRemovals(Bundle bundle) {
Supplier<Iterable<RegisteredType>> typeSupplier = Suppliers.ofInstance(ImmutableList.of());
CatalogUpgrades upgrades = BundleUpgradeParser.parseBundleManifestForCatalogUpgrades(bundle, typeSupplier);
@@ -194,6 +230,144 @@ public class BundleUpgradeParserTest {
}
@Test
+ public void testParseBundleManifestUpgrades1() throws Exception {
+ Bundle bundle = newMockBundle(ImmutableMap.of(
+ BundleUpgradeParser.MANIFEST_HEADER_UPGRADE_FOR_BUNDLES, "\"org.example.brooklyn.mybundle:[0,1.0.0)=org.example.brooklyn.mybundle:1\"",
+ BundleUpgradeParser.MANIFEST_HEADER_UPGRADE_FOR_TYPES, "\"foo:[0,1)=foo:1\""));
+ checkParseUpgrades1(bundle);
+ }
+
+ protected void checkParseUpgrades1(Bundle bundle) {
+ Supplier<Iterable<RegisteredType>> typeSupplier = Suppliers.ofInstance(ImmutableList.of());
+
+ CatalogUpgrades upgrades = BundleUpgradeParser.parseBundleManifestForCatalogUpgrades(bundle, typeSupplier);
+ assertFalse(upgrades.isEmpty());
+ assertBundleUpgrade(upgrades, "org.example.brooklyn.mybundle", "0", "org.example.brooklyn.mybundle", "1");
+ assertBundleUpgrade(upgrades, "org.example.brooklyn.mybundle", "1", null, null);
+ assertTypeUpgrade(upgrades, "foo", "0", "foo", "1");
+ assertTypeUpgrade(upgrades, "foo", "0.2", "foo", "1");
+ assertTypeUpgrade(upgrades, "foo", "0-SNAPSHOT", "foo", "1");
+ assertTypeUpgrade(upgrades, "foo", "1", null, null);
+ }
+
+ @Test
+ public void testParseBundleManifest() throws Exception {
+ Bundle bundle = newMockBundle(ImmutableMap.of(
+ BundleUpgradeParser.MANIFEST_HEADER_FORCE_REMOVE_LEGACY_ITEMS, "\"foo:[0,1.0.0)\",\"foo:1.0.0.SNAPSHOT\",\"bar:[0,1.0.0)\"",
+ BundleUpgradeParser.MANIFEST_HEADER_FORCE_REMOVE_BUNDLES, "\"org.example.brooklyn.mybundle:[0,1.0.0)\"",
+ BundleUpgradeParser.MANIFEST_HEADER_UPGRADE_FOR_BUNDLES, "\"org.example.brooklyn.mybundle:[0,1.0.0)=org.example.brooklyn.mybundle:1\"",
+ BundleUpgradeParser.MANIFEST_HEADER_UPGRADE_FOR_TYPES, "\"foo:[0,1)=foo:1\""));
+ checkParseRemovals(bundle);
+ checkParseUpgrades1(bundle);
+ }
+
+ @Test
+ public void testParseBundleManifestWithSpaces() throws Exception {
+ Bundle bundle = newMockBundle(ImmutableMap.of(
+ BundleUpgradeParser.MANIFEST_HEADER_FORCE_REMOVE_LEGACY_ITEMS, "\"foo:[0,1.0.0)\", \"foo:1.0.0.SNAPSHOT\", \"bar:[0,1.0.0)\"",
+ BundleUpgradeParser.MANIFEST_HEADER_FORCE_REMOVE_BUNDLES, " \"org.example.brooklyn.mybundle:[0,1.0.0)\"",
+ BundleUpgradeParser.MANIFEST_HEADER_UPGRADE_FOR_BUNDLES, "\"org.example.brooklyn.mybundle:[0,1.0.0)=org.example.brooklyn.mybundle:1\" ",
+ BundleUpgradeParser.MANIFEST_HEADER_UPGRADE_FOR_TYPES, "\"foo:[0,1)=foo:1\""));
+ checkParseRemovals(bundle);
+ checkParseUpgrades1(bundle);
+ }
+
+
+ @Test
+ public void testParseBundleManifestUpgrades2() throws Exception {
+ Bundle bundle = newMockBundle(new VersionedName("bun", "2"),
+ ImmutableMap.of(
+ BundleUpgradeParser.MANIFEST_HEADER_UPGRADE_FOR_BUNDLES,
+ "foo, foo:9-bogus, *, *:8, \"*:[9-bogus,9-bogut)=foo9:10.bogus\"",
+ BundleUpgradeParser.MANIFEST_HEADER_UPGRADE_FOR_TYPES,
+ "foo=foo:3, foo:9-bogus=foo:3, *, *:8, bar:2-SNAPSHOT, \"*:[9-bogus,9-bogut)=foo9:10.bogus\""));
+ checkParseUpgrades2(bundle);
+ }
+
+ protected void checkParseUpgrades2(Bundle bundle) {
+ Supplier<Iterable<RegisteredType>> typeSupplier = Suppliers.ofInstance(ImmutableList.of(
+ new BasicRegisteredType(null, "bar", "2", null),
+ new BasicRegisteredType(null, "bub", "2", null)));
+ CatalogUpgrades upgrades = BundleUpgradeParser.parseBundleManifestForCatalogUpgrades(bundle, typeSupplier);
+
+ assertFalse(upgrades.isEmpty());
+
+ assertBundleUpgrade(upgrades, "foo", "0.1", "bun", "2.0.0");
+ assertBundleUpgrade(upgrades, "foo", "9-bogus", "bun", "2.0.0");
+ assertBundleUpgrade(upgrades, "foo", "1.5", "bun", "2.0.0");
+ assertBundleUpgrade(upgrades, "foo", "3", null, null);
+
+ assertBundleUpgrade(upgrades, "bun", "1", "bun", "2.0.0");
+ assertBundleUpgrade(upgrades, "bun", "3", null, null);
+
+ assertTypeUpgrade(upgrades, "foo", "1", "foo", "3");
+ assertTypeUpgrade(upgrades, "foo", "2.2", null, null);
+ assertTypeUpgrade(upgrades, "foo", "9-bogus", "foo", "3");
+
+ assertTypeUpgrade(upgrades, "bar", "1", "bar", "2.0.0");
+ assertTypeUpgrade(upgrades, "bar", "8", "bar", "2.0.0");
+ assertTypeUpgrade(upgrades, "bar", "2-SNAPSHOT", "bar", "2.0.0");
+ assertTypeUpgrade(upgrades, "bar", "2.0.0.SNAPSHOT", "bar", "2.0.0");
+
+ assertTypeUpgrade(upgrades, "bub", "1", "bub", "2.0.0");
+ assertTypeUpgrade(upgrades, "bub", "8", "bub", "2.0.0");
+ assertTypeUpgrade(upgrades, "bub", "2-SNAPSHOT", null, null);
+
+ assertTypeUpgrade(upgrades, "bar", "9-bogus-one", "foo9", "10.bogus");
+ assertTypeUpgrade(upgrades, "bar", "9.bogus", "foo9", "10.bogus");
+ assertTypeUpgrade(upgrades, "baz", "9-bogus-one", null, null);
+ assertTypeUpgrade(upgrades, "bar", "9-bogut", null, null);
+ assertTypeUpgrade(upgrades, "bar", "9.bogut", null, null);
+ }
+
+ @Test
+ public void testParseBundleManifestUpgradesValidatesIfNoBundleUpgradeVersion() throws Exception {
+ Supplier<Iterable<RegisteredType>> typeSupplier = Suppliers.ofInstance(ImmutableList.of(
+ new BasicRegisteredType(null, "foo", "1.0", null) ));
+ Bundle bundle = newMockBundle(new VersionedName("bundle", "1.0"),
+ ImmutableMap.of(BundleUpgradeParser.MANIFEST_HEADER_UPGRADE_FOR_TYPES, "foo"));
+ try {
+ BundleUpgradeParser.parseBundleManifestForCatalogUpgrades(bundle, typeSupplier);
+ Asserts.shouldHaveFailedPreviously();
+ } catch (Exception e) {
+ Asserts.expectedFailureContainsIgnoreCase(e, "foo", "version", "cannot be inferred");
+ }
+ }
+
+ @Test
+ public void testParseBundleManifestUpgradesValidatesIfTypeNotContained() throws Exception {
+ Supplier<Iterable<RegisteredType>> typeSupplier = Suppliers.ofInstance(ImmutableList.of());
+ Bundle bundle = newMockBundle(new VersionedName("bundle", "1.0"),
+ ImmutableMap.of(
+ BundleUpgradeParser.MANIFEST_HEADER_UPGRADE_FOR_BUNDLES, "*",
+ BundleUpgradeParser.MANIFEST_HEADER_UPGRADE_FOR_TYPES, "foo"));
+ try {
+ BundleUpgradeParser.parseBundleManifestForCatalogUpgrades(bundle, typeSupplier);
+ Asserts.shouldHaveFailedPreviously();
+ } catch (Exception e) {
+ Asserts.expectedFailureContainsIgnoreCase(e, "foo", "bundle", "upgrade", "does not contain", "target");
+ }
+ }
+
+ private void assertBundleUpgrade(CatalogUpgrades upgrades, String sn, String sv, String tn, String tv) {
+ Set<VersionedName> targets = upgrades.getUpgradesForBundle(new VersionedName(sn, sv));
+ if (tn==null) {
+ Asserts.assertSize(targets, 0);
+ } else if (!targets.contains(new VersionedName(tn, tv))) {
+ Assert.fail("Failed target "+tn+":"+tv+" expected for "+sn+":"+sv+"; got "+targets);
+ }
+ }
+
+ private void assertTypeUpgrade(CatalogUpgrades upgrades, String sn, String sv, String tn, String tv) {
+ Set<VersionedName> targets = upgrades.getUpgradesForType(new VersionedName(sn, sv));
+ if (tn==null) {
+ Asserts.assertSize(targets, 0);
+ } else if (!targets.contains(new VersionedName(tn, tv))) {
+ Assert.fail("Failed target "+tn+":"+tv+" expected for "+sn+":"+sv+"; got "+targets);
+ }
+ }
+
+ @Test
public void testForgetQuotesGivesNiceError() throws Exception {
Bundle bundle = newMockBundle(ImmutableMap.of(
BundleUpgradeParser.MANIFEST_HEADER_FORCE_REMOVE_LEGACY_ITEMS, "foo:[0,1.0.0),bar:[0,1.0.0)"));
@@ -255,11 +429,18 @@ public class BundleUpgradeParserTest {
return result;
}
- private void assertParseList(String input, List<VersionRangedName> expected) throws Exception {
- List<VersionRangedName> actual = BundleUpgradeParser.parseVersionRangedNameList(input, false, MutableList.of("WILCARD-NAME"), "0-WILDCARD_VERSION");
+ private void assertParseListVersionRangeNames(String input, List<VersionRangedName> expected) throws Exception {
+ List<VersionRangedName> actual = BundleUpgradeParser.parseVersionRangedNameList(input, false, MutableList.of(DEFAULT_WILDCARD_NAME), DEFAULT_WILDCARD_VERSION);
assertListsEqual(actual, expected);
}
+ private void assertParseListVersionRangedNameToVersionedNames(String input, Multimap<VersionedName,VersionRangedName> expected) throws Exception {
+ Multimap<VersionedName, VersionRangedName> actual = BundleUpgradeParser.parseVersionRangedNameEqualsVersionedNameList(input, false,
+ MutableList.of(DEFAULT_WILDCARD_NAME), MutableList.of(DEFAULT_WILDCARD_VERSION_RANGE),
+ (i) -> new VersionedName(i.getSymbolicName(), DEFAULT_TARGET_VERSION));
+ assertEquals(actual, expected);
+ }
+
private void assertParseForceRemoveBundlesHeader(String input, Bundle bundle, List<VersionRangedName> expected) throws Exception {
List<VersionRangedName> actual = BundleUpgradeParser.parseForceRemoveBundlesHeader(input, bundle);
assertListsEqual(actual, expected);
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/af3f5f51/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherUpgradeCatalogOsgiTest.java
----------------------------------------------------------------------
diff --git a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherUpgradeCatalogOsgiTest.java b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherUpgradeCatalogOsgiTest.java
index 289b96a..595f5f9 100644
--- a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherUpgradeCatalogOsgiTest.java
+++ b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherUpgradeCatalogOsgiTest.java
@@ -152,7 +152,7 @@ public class BrooklynLauncherUpgradeCatalogOsgiTest extends AbstractBrooklynLaun
// removed item with upgrade deployed after rebind
// TODO WIP
- @Test
+ @Test(groups="WIP")
public void testForceUpgradeItemByRemovingBundle() throws Exception {
VersionedName one_1_0_0 = VersionedName.fromString("one:1.0.0");
VersionedName one_2_0_0 = VersionedName.fromString("one:2.0.0");
[07/10] brooklyn-server git commit: maps for upgrade types and
bundles, and related test fixes incl tidy HA transition clearing
Posted by he...@apache.org.
maps for upgrade types and bundles, and related test fixes incl tidy HA transition clearing
fix recent rebind header tests which i forgot to test in previous, some subtle HA behaviours,
but now all fixed and documented.
need to clear type registry as part of other clears on HA promotion fail
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/8473fb4b
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/8473fb4b
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/8473fb4b
Branch: refs/heads/master
Commit: 8473fb4be2c21d275bab8b2c92880abcf83eb68a
Parents: 00df1d5
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Tue Oct 31 09:34:25 2017 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Tue Oct 31 09:35:16 2017 +0000
----------------------------------------------------------------------
.../mgmt/ha/HighAvailabilityManagerImpl.java | 14 ++-
.../mgmt/rebind/RebindExceptionHandlerImpl.java | 2 +-
.../core/typereg/BasicBrooklynTypeRegistry.java | 7 +-
.../core/typereg/BundleUpgradeParser.java | 72 +++++++++++++--
.../core/typereg/BundleUpgradeParserTest.java | 5 +-
.../BrooklynLauncherRebindCatalogOsgiTest.java | 97 +++++++++-----------
6 files changed, 127 insertions(+), 70 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8473fb4b/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 1d4d50c..7220091 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
@@ -66,6 +66,7 @@ import org.apache.brooklyn.core.mgmt.persist.PersistenceActivityMetrics;
import org.apache.brooklyn.core.mgmt.rebind.RebindManagerImpl;
import org.apache.brooklyn.core.mgmt.usage.ManagementNodeStateListener;
import org.apache.brooklyn.core.server.BrooklynServerConfig;
+import org.apache.brooklyn.core.typereg.BasicBrooklynTypeRegistry;
import org.apache.brooklyn.util.collections.MutableList;
import org.apache.brooklyn.util.collections.MutableMap;
import org.apache.brooklyn.util.core.task.ScheduledTask;
@@ -939,12 +940,15 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
/**
* Clears all managed items from the management context.
*
- * The same items are destroyed as in the course of a rebind cycle, except for clearBrooklynManagedBundles.
- * That last operation could be expensive (causing bundles to be installed again). Therefore we only do it
- * when we stop being a hotProxy or when we are demoted (e.g. during the periodic rebind as hot_stanby
- * we will not repeatedly clear the brooklyn-managed-bundles).
+ * The same items are destroyed as in the course of a rebind cycle, with the addition of bundles/types
+ * which is comparatively more expensive, so we only do it when we stop being a hotProxy or when we are demoted
+ * (e.g. during the periodic rebind as hot_stanby we will not repeatedly clear the brooklyn-managed-bundles).
*/
protected void clearManagedItems(ManagementTransitionMode mode) {
+ // log this because it may be surprising, it is just HA transitions,
+ // not symmetric with usual single-node start
+ LOG.info("Clearing all managed items on transition to "+mode);
+
// start with the root applications
for (Application app: managementContext.getApplications()) {
if (((EntityInternal)app).getManagementSupport().isDeployed()) {
@@ -967,7 +971,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
}
((BasicBrooklynCatalog)managementContext.getCatalog()).reset(CatalogDto.newEmptyInstance("<reset-by-ha-status-change>"));
-
+ ((BasicBrooklynTypeRegistry)managementContext.getTypeRegistry()).clear();
managementContext.getCatalogInitialization().clearBrooklynManagedBundles();
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8473fb4b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindExceptionHandlerImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindExceptionHandlerImpl.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindExceptionHandlerImpl.java
index 794161b..54564a8 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindExceptionHandlerImpl.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindExceptionHandlerImpl.java
@@ -453,7 +453,7 @@ public class RebindExceptionHandlerImpl implements RebindExceptionHandler {
warn("Dangling item"+Strings.s(totalDangling)+" ("+totalDangling+" of "+totalItems+") found on rebind exceeds quorum, assuming failed: "+danglingIds);
allExceptions.add(new IllegalStateException("Too many dangling references: "+totalDangling+" of "+totalItems));
} else {
- LOG.info("Dangling item"+Strings.s(totalDangling)+" ("+totalDangling+" of "+totalItems+") found on rebind, assuming deleted: "+danglingIds);
+ LOG.info("Dangling item"+Strings.s(totalDangling)+" ("+totalDangling+" of "+totalItems+") found on rebind, within quorum, assuming deleted: "+danglingIds);
}
}
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8473fb4b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
index dd0b4b9..94e9b6b 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
@@ -51,7 +51,6 @@ import org.apache.brooklyn.util.concurrent.Locks;
import org.apache.brooklyn.util.exceptions.Exceptions;
import org.apache.brooklyn.util.guava.Maybe;
import org.apache.brooklyn.util.osgi.VersionedName;
-import org.apache.brooklyn.util.osgi.VersionedName.VersionedNameComparator;
import org.apache.brooklyn.util.osgi.VersionedName.VersionedNameStringComparator;
import org.apache.brooklyn.util.text.BrooklynVersionSyntax;
import org.apache.brooklyn.util.text.Identifiers;
@@ -425,6 +424,7 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry {
oldContainingBundlesToRemove.add(existingT.getContainingBundle());
}
if (canForce) {
+ // may be forcing because of internal type validation, or of course user flag
log.debug("Addition of "+type+" to replace "+existingT+" allowed because force is on");
continue;
}
@@ -616,5 +616,10 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry {
public void delete(String id) {
delete(VersionedName.fromString(id));
}
+
+ /** Deletes all items, for use when resetting management context */
+ public void clear() {
+ Locks.withLock(localRegistryLock.writeLock(), () -> localRegisteredTypesAndContainingBundles.clear());
+ }
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8473fb4b/core/src/main/java/org/apache/brooklyn/core/typereg/BundleUpgradeParser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/BundleUpgradeParser.java b/core/src/main/java/org/apache/brooklyn/core/typereg/BundleUpgradeParser.java
index 24d905f..73327e9 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/BundleUpgradeParser.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/BundleUpgradeParser.java
@@ -23,7 +23,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Dictionary;
-import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@@ -32,6 +31,7 @@ import java.util.Set;
import org.apache.brooklyn.api.catalog.CatalogItem;
import org.apache.brooklyn.api.typereg.RegisteredType;
import org.apache.brooklyn.util.collections.MutableList;
+import org.apache.brooklyn.util.collections.MutableSet;
import org.apache.brooklyn.util.exceptions.Exceptions;
import org.apache.brooklyn.util.osgi.VersionedName;
import org.apache.brooklyn.util.text.BrooklynVersionSyntax;
@@ -45,7 +45,10 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Objects;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.LinkedHashMultimap;
+import com.google.common.collect.Multimap;
/**
* Internal class for parsing bundle manifests to extract their upgrade instructions.
@@ -119,8 +122,9 @@ public class BundleUpgradeParser {
* These will be advisory unless the bundle being upgraded is force-removed in which case it will be applied automatically
* wherever the bundle is in use.
*
- * The format is a comma separate list of {@code key=value} pairs, where each key and value is a name with a version range
- * (as per {@link #MANIFEST_HEADER_FORCE_REMOVE_BUNDLES}). The {@code =value} can be omitted, and usually is,
+ * The format is a comma separate list of {@code key=value} pairs, where each key is a name with a version range
+ * (as per {@link #MANIFEST_HEADER_FORCE_REMOVE_BUNDLES}) specifying what should be upgraded, and {@code value} is a name and
+ * version specifying what it should be ugpraded to. The {@code =value} can be omitted, and usually is,
* to mean this bundle at this version. (The {@code =value} is available if one bundle is defining upgrades for other bundles.)
*
* A wildcard can be given as the key, without a version ({@code *}) or with ({@code *:[0,1)}) to refer to
@@ -200,8 +204,8 @@ public class BundleUpgradeParser {
public static class Builder {
private Set<VersionRangedName> removedLegacyItems = new LinkedHashSet<>();
private Set<VersionRangedName> removedBundles = new LinkedHashSet<>();
- private Map<VersionedName,VersionRangedName> upgradeBundles = new LinkedHashMap<>();
- private Map<VersionedName,VersionRangedName> upgradeTypes = new LinkedHashMap<>();
+ private Multimap<VersionedName,VersionRangedName> upgradesProvidedByBundles = LinkedHashMultimap.create();
+ private Multimap<VersionedName,VersionRangedName> upgradesProvidedByTypes = LinkedHashMultimap.create();
public Builder removedLegacyItems(Collection<VersionRangedName> vals) {
removedLegacyItems.addAll(vals);
@@ -211,9 +215,19 @@ public class BundleUpgradeParser {
removedBundles.addAll(vals);
return this;
}
+ public Builder upgradeBundles(Multimap<VersionedName,VersionRangedName> vals) {
+ upgradesProvidedByBundles.putAll(vals);
+ return this;
+ }
+ public Builder upgradeTypes(Multimap<VersionedName,VersionRangedName> vals) {
+ upgradesProvidedByTypes.putAll(vals);
+ return this;
+ }
public Builder addAll(CatalogUpgrades other) {
removedLegacyItems.addAll(other.removedLegacyItems);
removedBundles.addAll(other.removedBundles);
+ upgradesProvidedByBundles.putAll(other.upgradesProvidedByBundles);
+ upgradesProvidedByTypes.putAll(other.upgradesProvidedByTypes);
return this;
}
public CatalogUpgrades build() {
@@ -227,10 +241,14 @@ public class BundleUpgradeParser {
private final Set<VersionRangedName> removedLegacyItems;
private final Set<VersionRangedName> removedBundles;
+ private final Multimap<VersionedName,VersionRangedName> upgradesProvidedByBundles;
+ private final Multimap<VersionedName,VersionRangedName> upgradesProvidedByTypes;
public CatalogUpgrades(Builder builder) {
this.removedLegacyItems = ImmutableSet.copyOf(builder.removedLegacyItems);
this.removedBundles = ImmutableSet.copyOf(builder.removedBundles);
+ this.upgradesProvidedByBundles = ImmutableMultimap.copyOf(builder.upgradesProvidedByBundles);
+ this.upgradesProvidedByTypes = ImmutableMultimap.copyOf(builder.upgradesProvidedByTypes);
}
public boolean isEmpty() {
@@ -245,6 +263,14 @@ public class BundleUpgradeParser {
return removedBundles;
}
+ public Multimap<VersionedName, VersionRangedName> getUpgradesProvidedByBundles() {
+ return upgradesProvidedByBundles;
+ }
+
+ public Multimap<VersionedName, VersionRangedName> getUpgradesProvidedByTypes() {
+ return upgradesProvidedByTypes;
+ }
+
public boolean isLegacyItemRemoved(CatalogItem<?, ?> legacyCatalogItem) {
VersionedName name = new VersionedName(legacyCatalogItem.getSymbolicName(), legacyCatalogItem.getVersion());
return contains(removedLegacyItems, name);
@@ -254,14 +280,36 @@ public class BundleUpgradeParser {
return contains(removedBundles, bundle);
}
- public boolean contains(Iterable<VersionRangedName> names, VersionedName name) {
+ public Set<VersionedName> getUpgradesForBundle(VersionedName bundle) {
+ return findUpgradesIn(bundle, upgradesProvidedByBundles);
+ }
+ public Set<VersionedName> getUpgradesForType(VersionedName type) {
+ return findUpgradesIn(type, upgradesProvidedByTypes);
+ }
+ private static Set<VersionedName> findUpgradesIn(VersionedName bundle, Multimap<VersionedName,VersionRangedName> upgradesMap) {
+ Set<VersionedName> result = MutableSet.of();
+ for (Map.Entry<VersionedName,VersionRangedName> n: upgradesMap.entries()) {
+ if (contains(n.getValue(), bundle)) {
+ result.add(n.getKey());
+ }
+ }
+ return result;
+ }
+
+ @Beta
+ public static boolean contains(Iterable<VersionRangedName> names, VersionedName name) {
for (VersionRangedName contender : names) {
- if (contender.getSymbolicName().equals(name.getSymbolicName()) && contender.getOsgiVersionRange().includes(name.getOsgiVersion())) {
+ if (contains(contender, name)) {
return true;
}
}
return false;
}
+
+ @Beta
+ public static boolean contains(VersionRangedName range, VersionedName name) {
+ return range.getSymbolicName().equals(name.getSymbolicName()) && range.getOsgiVersionRange().includes(name.getOsgiVersion());
+ }
}
/**
@@ -356,12 +404,22 @@ public class BundleUpgradeParser {
// section "Bundle Upgrade Metadata"
Dictionary<String, String> headers = bundle.getHeaders();
+ Multimap<VersionedName,VersionRangedName> upgradesForBundles = parseUpgradeForBundlesHeader(headers.get(MANIFEST_HEADER_UPGRADE_FOR_BUNDLES), bundle);
return CatalogUpgrades.builder()
.removedLegacyItems(parseForceRemoveLegacyItemsHeader(headers.get(MANIFEST_HEADER_FORCE_REMOVE_LEGACY_ITEMS), bundle, typeSupplier))
.removedBundles(parseForceRemoveBundlesHeader(headers.get(MANIFEST_HEADER_FORCE_REMOVE_BUNDLES), bundle))
+ .upgradeBundles(upgradesForBundles)
+ .upgradeTypes(parseUpgradeForTypesHeader(headers.get(MANIFEST_HEADER_UPGRADE_FOR_TYPES), bundle, upgradesForBundles))
.build();
}
+ private static Multimap<VersionedName, VersionRangedName> parseUpgradeForBundlesHeader(String input, Bundle bundle) {
+ return LinkedHashMultimap.<VersionedName, VersionRangedName>create();
+ }
+ private static Multimap<VersionedName, VersionRangedName> parseUpgradeForTypesHeader(String input, Bundle bundle, Multimap<VersionedName, VersionRangedName> upgradesForBundles) {
+ return LinkedHashMultimap.<VersionedName, VersionRangedName>create();
+ }
+
@VisibleForTesting
static List<VersionRangedName> parseForceRemoveLegacyItemsHeader(String input, Bundle bundle, Supplier<? extends Iterable<? extends RegisteredType>> typeSupplier) {
if (input == null) return ImmutableList.of();
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8473fb4b/core/src/test/java/org/apache/brooklyn/core/typereg/BundleUpgradeParserTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/typereg/BundleUpgradeParserTest.java b/core/src/test/java/org/apache/brooklyn/core/typereg/BundleUpgradeParserTest.java
index 5fc5188..64c8a6e 100644
--- a/core/src/test/java/org/apache/brooklyn/core/typereg/BundleUpgradeParserTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/typereg/BundleUpgradeParserTest.java
@@ -39,7 +39,6 @@ import org.mockito.Mockito;
import org.osgi.framework.Bundle;
import org.osgi.framework.Version;
import org.osgi.framework.VersionRange;
-import org.testng.Assert;
import org.testng.annotations.Test;
import com.google.common.base.Supplier;
@@ -158,7 +157,9 @@ public class BundleUpgradeParserTest {
public void testParseBundleManifest() throws Exception {
Bundle bundle = newMockBundle(ImmutableMap.of(
BundleUpgradeParser.MANIFEST_HEADER_FORCE_REMOVE_LEGACY_ITEMS, "\"foo:[0,1.0.0)\",\"foo:1.0.0.SNAPSHOT\",\"bar:[0,1.0.0)\"",
- BundleUpgradeParser.MANIFEST_HEADER_FORCE_REMOVE_BUNDLES, "\"org.example.brooklyn.mybundle:[0,1.0.0)\""));
+ BundleUpgradeParser.MANIFEST_HEADER_FORCE_REMOVE_BUNDLES, "\"org.example.brooklyn.mybundle:[0,1.0.0)\"",
+ BundleUpgradeParser.MANIFEST_HEADER_UPGRADE_FOR_BUNDLES, "\"org.example.brooklyn.mybundle:[0,1.0.0)=org.example.brooklyn.mybundle:1\"",
+ BundleUpgradeParser.MANIFEST_HEADER_UPGRADE_FOR_TYPES, "\"foo:[0,1)=foo:1\""));
checkParse(bundle);
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8473fb4b/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 3f261df..23f564c 100644
--- a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindCatalogOsgiTest.java
+++ b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindCatalogOsgiTest.java
@@ -30,7 +30,6 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
-import org.apache.brooklyn.api.entity.Application;
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.mgmt.ManagementContext;
import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityMode;
@@ -142,6 +141,7 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
}
l.start();
launcherLast = launcherT1 = l;
+ assertMasterEventually(launcherT1);
if (startupAssertions!=null) startupAssertions.run();
}
@@ -150,7 +150,7 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
startT2(l, true);
}
- protected void startT2(BrooklynLauncher l, boolean assertSuccess) {
+ protected void startT2(BrooklynLauncher l, boolean expectSuccess) {
if (launcherT2!=null) throw new IllegalStateException("Already started T2 launcher");
try {
@@ -165,8 +165,14 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
}
l.start();
launcherLast = launcherT2 = l;
- if (isT1KeptRunningWhenT2Starts()) {
- assertHotStandbyNow(launcherT2);
+ if (expectSuccess) {
+ if (isT1KeptRunningWhenT2Starts()) {
+ assertHotStandbyNow(launcherT2);
+ } else {
+ assertMasterEventually(launcherT2);
+ }
+ } else {
+ assertFailsEventually(launcherLast);
}
if (startupAssertions!=null) startupAssertions.run();
@@ -174,11 +180,13 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
protected void promoteT2IfStandby() {
promoteT2IfStandby(true);
}
- protected void promoteT2IfStandby(boolean assertSuccess) {
+ protected void promoteT2IfStandby(boolean expectHealthy) {
if (isT1KeptRunningWhenT2Starts()) {
launcherT1.terminate();
- if (assertSuccess) {
+ if (expectHealthy) {
assertMasterEventually(launcherT2);
+ } else {
+ assertFailsEventually(launcherT2);
}
if (startupAssertions!=null) startupAssertions.run();
@@ -617,37 +625,10 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
Assert.assertNotEquals(bundlePersistenceId1, bundlePersistenceId2);
}
}
-
- @Test
- public void testRebindRemovedItemWorksIfJavaClassFound() throws Exception {
- Set<VersionedName> bundleItemsV1 = ImmutableSet.of(VersionedName.fromString("one:1.0.0"));
- String bundleBomV1 = createCatalogYaml(ImmutableList.of(), bundleItemsV1);
- VersionedName bundleNameV1 = new VersionedName("org.example.testRebindGetsInitialOsgiCatalog", "1.0.0");
- File bundleFileV1 = newTmpBundle(ImmutableMap.of(BasicBrooklynCatalog.CATALOG_BOM, bundleBomV1.getBytes(StandardCharsets.UTF_8)), bundleNameV1);
- File initialBomFileV1 = newTmpFile(createCatalogYaml(ImmutableList.of(bundleFileV1.toURI()), ImmutableList.of()));
-
- Set<VersionedName> bundleItemsV2 = ImmutableSet.of(VersionedName.fromString("one:2.0.0"));
- String bundleBomV2 = createCatalogYaml(ImmutableList.of(), bundleItemsV2);
- VersionedName bundleNameV2 = new VersionedName("org.example.testRebindGetsInitialOsgiCatalog", "2.0.0");
- File bundleFileV2 = newTmpBundle(ImmutableMap.of(BasicBrooklynCatalog.CATALOG_BOM, bundleBomV2.getBytes(StandardCharsets.UTF_8)), bundleNameV2,
- ImmutableMap.of(BundleUpgradeParser.MANIFEST_HEADER_FORCE_REMOVE_BUNDLES, "*"));
- File initialBomFileV2 = newTmpFile(createCatalogYaml(ImmutableList.of(bundleFileV2.toURI()), ImmutableList.of()));
-
- startT1(newLauncherForTests(initialBomFileV1.getAbsolutePath()));
- Application app = createAndStartApplication(launcherLast.getManagementContext(),
- "services: [ { type: 'one:1.0.0' } ]");
-
- // should start and promote fine, but entity's type shouldn't be loadable (and there will be warnings)
- startT2(newLauncherForTests(initialBomFileV2.getAbsolutePath()));
- promoteT2IfStandby();
-
- Entity entity = Iterables.getOnlyElement( Iterables.getOnlyElement(launcherLast.getManagementContext().getApplications()).getChildren() );
- Assert.assertEquals(entity.getCatalogItemId(), bundleItemsV1.iterator().next());
- }
@Test
public void testRebindRemovedItemButLeavingJavaSucceeds() throws Exception {
- File initialBomFileV2 = prepForRebindRemovedItemTestReturningBomV2(true);
+ File initialBomFileV2 = prepForRebindRemovedItemTestReturningBomV2(false);
createAndStartApplication(launcherLast.getManagementContext(),
"services: [ { type: 'simple-entity:1.0.0' } ]");
@@ -663,6 +644,7 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
// TODO prep should set upgrade types and this should be 2.0.0
Assert.assertEquals(entity.getCatalogItemId(), "simple-entity:1.0.0");
}
+
@Test
public void testRebindRemovedItemIncludingJavaFails() throws Exception {
File initialBomFileV2 = prepForRebindRemovedItemTestReturningBomV2(true);
@@ -673,16 +655,28 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
// TODO when we switch to loading from type registry types instead of persisted java type
// T2 startup should succeed as it knows the type is now a BasicEntity
- startT2(newLauncherForTests(initialBomFileV2.getAbsolutePath()));
- assertHotStandbyNow(launcherLast, false);
+
+ // for now however:
+ if (isT1KeptRunningWhenT2Starts()) {
+ // if starting hot-standby, HA manager will clear all state and set it to FAILED state;
+ // for master/standalone/single it treats it as a startup subsystem error and does not
+ // so for hot-standby we should assert everything is cleared
+ startupAssertions = () -> {
+ Asserts.assertSize(launcherLast.getManagementContext().getTypeRegistry().getAll(), 0);
+ Asserts.assertSize(launcherLast.getManagementContext().getEntityManager().getEntities(), 0);
+ };
+ }
+ startT2(newLauncherForTests(initialBomFileV2.getAbsolutePath()), false);
Assert.assertFalse( ((ManagementContextInternal)launcherLast.getManagementContext()).errors().isEmpty() );
- promoteT2IfStandby();
- assertMasterEventually(launcherLast, false);
+ promoteT2IfStandby(false);
Assert.assertFalse( ((ManagementContextInternal)launcherLast.getManagementContext()).errors().isEmpty() );
- // entity shouldn't be loaded
- Asserts.assertSize( launcherLast.getManagementContext().getApplications(), 0 );
+ if (!isT1KeptRunningWhenT2Starts()) {
+ // if it did start, then entity shouldn't be loaded, though app is
+ Asserts.assertSize( launcherLast.getManagementContext().getApplications(), 1 );
+ Asserts.assertSize( Iterables.getOnlyElement(launcherLast.getManagementContext().getApplications()).getChildren(), 0 );
+ }
}
private File prepForRebindRemovedItemTestReturningBomV2(boolean removeSourceJavaBundle) throws Exception {
@@ -718,7 +712,7 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
VersionedName bv = new VersionedName("org.example.testRebindGetsInitialOsgiCatalog", v);
VersionedName iv = new VersionedName("simple-entity", v);
assertManagedBundle(launcherLast, bv, MutableSet.of(iv));
- if (launcherT2==null) {
+ if (launcherT2==null || !removeSourceJavaBundle) {
assertCatalogConsistsOfIds(launcherLast, MutableList.copyOf(COM_EXAMPLE_BUNDLE_CATALOG_IDS).append(iv));
} else {
assertCatalogConsistsOfIds(launcherLast, MutableList.of(iv));
@@ -747,34 +741,28 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
}
protected void assertHotStandbyNow(BrooklynLauncher launcher) {
- assertHotStandbyNow(launcher, true);
- }
- protected void assertHotStandbyNow(BrooklynLauncher launcher, boolean assertHealthy) {
ManagementContext mgmt = launcher.getManagementContext();
assertTrue(mgmt.isStartupComplete());
assertTrue(mgmt.isRunning());
assertEquals(mgmt.getNodeState(), ManagementNodeState.HOT_STANDBY);
- if (assertHealthy) {
- Asserts.assertSize(((ManagementContextInternal)mgmt).errors(), 0);
- }
+ Asserts.assertSize(((ManagementContextInternal)mgmt).errors(), 0);
}
protected void assertMasterEventually(BrooklynLauncher launcher) {
- assertMasterEventually(launcher, true);
- }
- protected void assertMasterEventually(BrooklynLauncher launcher, boolean assertHealthy) {
ManagementContext mgmt = launcher.getManagementContext();
Asserts.succeedsEventually(new Runnable() {
public void run() {
assertTrue(mgmt.isStartupComplete());
assertTrue(mgmt.isRunning());
assertEquals(mgmt.getNodeState(), ManagementNodeState.MASTER);
- if (assertHealthy) {
- Asserts.assertSize(((ManagementContextInternal)mgmt).errors(), 0);
- }
+ Asserts.assertSize(((ManagementContextInternal)mgmt).errors(), 0);
}});
}
+ protected void assertFailsEventually(BrooklynLauncher launcher) {
+ Asserts.succeedsEventually(() -> assertEquals(launcher.getManagementContext().getNodeState(), ManagementNodeState.FAILED));
+ }
+
protected Bundle installBundle(Framework framework, File bundle) throws Exception {
try (FileInputStream stream = new FileInputStream(bundle)) {
return framework.getBundleContext().installBundle(bundle.toURI().toString(), stream);
@@ -831,13 +819,14 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
return newTmpBundle(ImmutableMap.of(BasicBrooklynCatalog.CATALOG_BOM, bundleBom.getBytes(StandardCharsets.UTF_8)), bundleName);
}
+ // convenience for testing just a single test (TestNG plugin otherwise runs lots of them)
public static void main(String[] args) throws Exception {
try {
BrooklynLauncherRebindCatalogOsgiTest fixture = new LauncherRebindSubTests();
fixture.setUp();
fixture.testRebindRemovedItemIncludingJavaFails();
fixture.tearDown();
- } catch (Exception e) {
+ } catch (Throwable e) {
e.printStackTrace();
System.exit(1);
}
[02/10] brooklyn-server git commit: fix too-early detection of
standby promotion in tests, with definitive mgmt.getNodeState()
Posted by he...@apache.org.
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 <al...@cloudsoftcorp.com>
Authored: Mon Oct 30 14:47:34 2017 +0000
Committer: Alex Heneveld <al...@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);
}});
}
});
[09/10] brooklyn-server git commit: test tidy,
accept osgi version equality when loading types, remove warns
Posted by he...@apache.org.
test tidy, accept osgi version equality when loading types, remove warns
tests with comments ready for ugprades
(type registry lookup still prefers exact non-osgi version match but will use osgi)
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/c840fbe9
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/c840fbe9
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/c840fbe9
Branch: refs/heads/master
Commit: c840fbe9f027a2f9c253f5ddbaa815e3ff0bd475
Parents: af3f5f5
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Tue Oct 31 12:53:16 2017 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Tue Oct 31 16:30:43 2017 +0000
----------------------------------------------------------------------
.../core/typereg/BasicBrooklynTypeRegistry.java | 58 ++++++-----
.../core/typereg/RegisteredTypePredicates.java | 20 +++-
.../AbstractBrooklynLauncherRebindTest.java | 3 +-
.../BrooklynLauncherRebindCatalogOsgiTest.java | 103 +++++++++++++++----
.../BrooklynLauncherUpgradeCatalogOsgiTest.java | 6 --
5 files changed, 139 insertions(+), 51 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c840fbe9/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
index 94e9b6b..c077f8a 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
@@ -143,7 +143,7 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry {
return result;
}
- @SuppressWarnings("deprecation")
+ @SuppressWarnings({ "deprecation", "unchecked" })
private Maybe<RegisteredType> getSingle(String symbolicNameOrAliasIfNoVersion, final String versionFinal, final RegisteredTypeLoadingContext contextFinal) {
RegisteredTypeLoadingContext context = contextFinal;
if (context==null) context = RegisteredTypeLoadingContexts.any();
@@ -156,34 +156,46 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry {
Maybe<RegisteredType> type = getExactWithoutLegacyCatalog(symbolicNameOrAliasIfNoVersion, version, context);
if (type.isPresent()) return type;
}
+
+ Predicate<RegisteredType> versionCheck;
if (BrooklynCatalog.DEFAULT_VERSION.equals(version)) {
- // alternate code path, if version blank or default
-
- Iterable<RegisteredType> types = getMatching(Predicates.and(RegisteredTypePredicates.symbolicName(symbolicNameOrAliasIfNoVersion),
- RegisteredTypePredicates.satisfies(context)));
- if (Iterables.isEmpty(types)) {
- // look for alias if no exact symbolic name match AND no version is specified
- types = getMatching(Predicates.and(RegisteredTypePredicates.alias(symbolicNameOrAliasIfNoVersion),
- RegisteredTypePredicates.satisfies(context) ) );
- // if there are multiple symbolic names then throw?
- Set<String> uniqueSymbolicNames = MutableSet.of();
- for (RegisteredType t: types) {
- uniqueSymbolicNames.add(t.getSymbolicName());
- }
- if (uniqueSymbolicNames.size()>1) {
- String message = "Multiple matches found for alias '"+symbolicNameOrAliasIfNoVersion+"': "+uniqueSymbolicNames+"; "
- + "refusing to select any.";
- log.warn(message);
- return Maybe.absent(message);
- }
+ // if version blank or default
+ versionCheck = Predicates.alwaysTrue();
+ } else {
+ // didn't find exact so will search against osgi version
+ versionCheck = RegisteredTypePredicates.versionOsgi(version);
+ }
+
+ Iterable<RegisteredType> types = getMatching(Predicates.and(
+ RegisteredTypePredicates.symbolicName(symbolicNameOrAliasIfNoVersion),
+ versionCheck,
+ RegisteredTypePredicates.satisfies(context)));
+
+ if (Iterables.isEmpty(types)) {
+ // look for alias if no exact symbolic name match AND no version is specified
+ types = getMatching(Predicates.and(
+ RegisteredTypePredicates.alias(symbolicNameOrAliasIfNoVersion),
+ versionCheck,
+ RegisteredTypePredicates.satisfies(context) ) );
+ // if there are multiple symbolic names then throw?
+ Set<String> uniqueSymbolicNames = MutableSet.of();
+ for (RegisteredType t: types) {
+ uniqueSymbolicNames.add(t.getSymbolicName());
}
- if (!Iterables.isEmpty(types)) {
- RegisteredType type = RegisteredTypes.getBestVersion(types);
- if (type!=null) return Maybe.of(type);
+ if (uniqueSymbolicNames.size()>1) {
+ String message = "Multiple matches found for alias '"+symbolicNameOrAliasIfNoVersion+"': "+uniqueSymbolicNames+"; "
+ + "refusing to select any.";
+ log.warn(message);
+ return Maybe.absent(message);
}
}
+ if (!Iterables.isEmpty(types)) {
+ RegisteredType type = RegisteredTypes.getBestVersion(types);
+ if (type!=null) return Maybe.of(type);
+ }
+
// missing case is to look for exact version in legacy catalog
CatalogItem<?, ?> item = mgmt.getCatalog().getCatalogItemLegacy(symbolicNameOrAliasIfNoVersion, version);
if (item!=null)
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c840fbe9/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypePredicates.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypePredicates.java b/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypePredicates.java
index 30aa214..bdc1ada 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypePredicates.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypePredicates.java
@@ -37,6 +37,7 @@ import org.apache.brooklyn.core.mgmt.entitlement.Entitlements;
import org.apache.brooklyn.util.collections.CollectionFunctionals;
import org.apache.brooklyn.util.exceptions.Exceptions;
import org.apache.brooklyn.util.osgi.VersionedName;
+import org.apache.brooklyn.util.text.BrooklynVersionSyntax;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -145,7 +146,6 @@ public class RegisteredTypePredicates {
public static Predicate<RegisteredType> version(final Predicate<? super String> filter) {
return new VersionMatches(filter);
}
-
private static class VersionMatches implements Predicate<RegisteredType> {
private final Predicate<? super String> filter;
@@ -157,6 +157,24 @@ public class RegisteredTypePredicates {
return (item != null) && filter.apply(item.getVersion());
}
}
+
+ public static Predicate<RegisteredType> versionOsgi(final String val) {
+ return versionOsgi(Predicates.equalTo(BrooklynVersionSyntax.toValidOsgiVersion(val)));
+ }
+ public static Predicate<RegisteredType> versionOsgi(final Predicate<? super String> filter) {
+ return new VersionOsgiMatches(filter);
+ }
+ private static class VersionOsgiMatches implements Predicate<RegisteredType> {
+ private final Predicate<? super String> filter;
+
+ public VersionOsgiMatches(Predicate<? super String> filter) {
+ this.filter = filter;
+ }
+ @Override
+ public boolean apply(@Nullable RegisteredType item) {
+ return (item != null) && filter.apply(BrooklynVersionSyntax.toValidOsgiVersion(item.getVersion()));
+ }
+ }
public static Predicate<RegisteredType> alias(final String alias) {
return aliases(CollectionFunctionals.any(Predicates.equalTo(alias)));
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c840fbe9/launcher/src/test/java/org/apache/brooklyn/launcher/AbstractBrooklynLauncherRebindTest.java
----------------------------------------------------------------------
diff --git a/launcher/src/test/java/org/apache/brooklyn/launcher/AbstractBrooklynLauncherRebindTest.java b/launcher/src/test/java/org/apache/brooklyn/launcher/AbstractBrooklynLauncherRebindTest.java
index 461dce7..9a97644 100644
--- a/launcher/src/test/java/org/apache/brooklyn/launcher/AbstractBrooklynLauncherRebindTest.java
+++ b/launcher/src/test/java/org/apache/brooklyn/launcher/AbstractBrooklynLauncherRebindTest.java
@@ -119,7 +119,8 @@ public abstract class AbstractBrooklynLauncherRebindTest {
}
protected BrooklynLauncher newLauncherForTests() {
- return newLauncherForTests(PersistMode.AUTO, HighAvailabilityMode.DISABLED);
+ return newLauncherForTests(PersistMode.AUTO, HighAvailabilityMode.DISABLED)
+ .globalBrooklynPropertiesFile(null);
}
protected BrooklynLauncher newLauncherForTests(PersistMode persistMode, HighAvailabilityMode haMode) {
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c840fbe9/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 23f564c..5809d06 100644
--- a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindCatalogOsgiTest.java
+++ b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindCatalogOsgiTest.java
@@ -28,8 +28,10 @@ import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
+import org.apache.brooklyn.api.entity.Application;
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.mgmt.ManagementContext;
import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityMode;
@@ -38,15 +40,18 @@ import org.apache.brooklyn.api.objs.BrooklynObjectType;
import org.apache.brooklyn.api.typereg.RegisteredType;
import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog;
import org.apache.brooklyn.core.catalog.internal.CatalogInitialization;
+import org.apache.brooklyn.core.entity.Entities;
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.RebindTestUtils;
import org.apache.brooklyn.core.typereg.BundleUpgradeParser;
+import org.apache.brooklyn.entity.group.DynamicCluster;
import org.apache.brooklyn.entity.stock.BasicEntity;
import org.apache.brooklyn.test.Asserts;
import org.apache.brooklyn.test.support.TestResourceUnavailableException;
import org.apache.brooklyn.util.collections.MutableList;
+import org.apache.brooklyn.util.collections.MutableMap;
import org.apache.brooklyn.util.collections.MutableSet;
import org.apache.brooklyn.util.core.osgi.Osgis;
import org.apache.brooklyn.util.exceptions.Exceptions;
@@ -628,35 +633,30 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
@Test
public void testRebindRemovedItemButLeavingJavaSucceeds() throws Exception {
- File initialBomFileV2 = prepForRebindRemovedItemTestReturningBomV2(false);
+ File initialBomFileV2 = prepForRebindRemovedItemTestReturningBomV2(false, false);
createAndStartApplication(launcherLast.getManagementContext(),
- "services: [ { type: 'simple-entity:1.0.0' } ]");
+ "services: [ { type: 'simple-entity:1' } ]");
// should start and promote fine, even though original catalog item ID not available
- // TODO when we switch to loading from type registry types instead of persisted java type (see RebindIteration.load)
- // T2 startup should fail as the following test currently does, as we didn't allow the type to be upgraded
- // (but note the following test should then succeed)
+ // when we switch to loading from type registry types instead of persisted java type (see RebindIteration.load)
+ // T2 startup may fail like testRebindRemovedItemIAlsoRemovingJavaDependencyCausesFailure does,
+ // or it may fall back to the java type and succeed (but note this test does NOT allow the type to be upgraded)
startT2(newLauncherForTests(initialBomFileV2.getAbsolutePath()));
promoteT2IfStandby();
Entity entity = Iterables.getOnlyElement( Iterables.getOnlyElement(launcherLast.getManagementContext().getApplications()).getChildren() );
- // TODO prep should set upgrade types and this should be 2.0.0
Assert.assertEquals(entity.getCatalogItemId(), "simple-entity:1.0.0");
}
@Test
- public void testRebindRemovedItemIncludingJavaFails() throws Exception {
- File initialBomFileV2 = prepForRebindRemovedItemTestReturningBomV2(true);
+ public void testRebindRemovedItemAndRemovingJavaDependencyCausesFailure() throws Exception {
+ File initialBomFileV2 = prepForRebindRemovedItemTestReturningBomV2(true, false);
createAndStartApplication(launcherLast.getManagementContext(),
- "services: [ { type: 'simple-entity:1.0.0' } ]");
+ "services: [ { type: 'simple-entity:1.0' } ]");
- // should have errors on promotion
-
- // TODO when we switch to loading from type registry types instead of persisted java type
- // T2 startup should succeed as it knows the type is now a BasicEntity
+ // errors on promotion because the SimpleEntity.class isn't available
- // for now however:
if (isT1KeptRunningWhenT2Starts()) {
// if starting hot-standby, HA manager will clear all state and set it to FAILED state;
// for master/standalone/single it treats it as a startup subsystem error and does not
@@ -673,13 +673,14 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
Assert.assertFalse( ((ManagementContextInternal)launcherLast.getManagementContext()).errors().isEmpty() );
if (!isT1KeptRunningWhenT2Starts()) {
- // if it did start, then entity shouldn't be loaded, though app is
+ // if t2 not running as standby then it should start, but with errors,
+ // including entity shouldn't be loaded (but app is)
Asserts.assertSize( launcherLast.getManagementContext().getApplications(), 1 );
Asserts.assertSize( Iterables.getOnlyElement(launcherLast.getManagementContext().getApplications()).getChildren(), 0 );
}
}
- private File prepForRebindRemovedItemTestReturningBomV2(boolean removeSourceJavaBundle) throws Exception {
+ private File prepForRebindRemovedItemTestReturningBomV2(boolean removeSourceJavaBundle, boolean upgradeEntity) throws Exception {
TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_PATH);
String initialBomV1 = Joiner.on("\n").join(
@@ -701,10 +702,14 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
" item:",
" type: "+BasicEntity.class.getName());
VersionedName bundleNameV2 = new VersionedName("org.example.testRebindGetsInitialOsgiCatalog", "2.0.0");
- File bundleFileV2 = newTmpBundle(ImmutableMap.of(BasicBrooklynCatalog.CATALOG_BOM, initialBomV2.getBytes()), bundleNameV2,
- ImmutableMap.of(BundleUpgradeParser.MANIFEST_HEADER_FORCE_REMOVE_BUNDLES, "*"
+ Map<String,String> headers = MutableMap.of(
+ BundleUpgradeParser.MANIFEST_HEADER_FORCE_REMOVE_BUNDLES, "*"
+ (removeSourceJavaBundle ? ","+"'"+OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_SYMBOLIC_NAME_FULL+":"+OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_VERSION+"'"
- : "")));
+ : ""));
+ if (upgradeEntity) {
+ headers.put(BundleUpgradeParser.MANIFEST_HEADER_UPGRADE_FOR_BUNDLES, "*");
+ }
+ File bundleFileV2 = newTmpBundle(ImmutableMap.of(BasicBrooklynCatalog.CATALOG_BOM, initialBomV2.getBytes()), bundleNameV2, headers);
File initialBomFileV2 = newTmpFile(createCatalogYaml(ImmutableList.of(bundleFileV2.toURI()), ImmutableList.of()));
startupAssertions = () -> {
@@ -723,6 +728,64 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
return initialBomFileV2;
}
+ @Test
+ public void testRebindUpgradeEntity() throws Exception {
+ File initialBomFileV2 = prepForRebindRemovedItemTestReturningBomV2(false, true);
+ createAndStartApplication(launcherLast.getManagementContext(),
+ "services: [ { type: 'simple-entity:1' } ]");
+
+ startT2(newLauncherForTests(initialBomFileV2.getAbsolutePath()));
+ promoteT2IfStandby();
+
+ Entity entity = Iterables.getOnlyElement( Iterables.getOnlyElement(launcherLast.getManagementContext().getApplications()).getChildren() );
+
+ // assert it was updated
+
+ Assert.assertEquals(entity.getCatalogItemId(), "simple-entity:1.0.0");
+ // TODO when upgrades work at level of catalog item ID and bundle ID, do below instead of above
+// Assert.assertEquals(entity.getCatalogItemId(), "simple-entity:2.0.0");
+
+ Assert.assertEquals(Entities.deproxy(entity).getClass().getName(), "com.example.brooklyn.test.osgi.entities.SimpleEntityImpl");
+ // TODO when registered types are used to create, instead of java type,
+ // upgrade should cause the line below instead of the line above (see RebindIteration.load)
+// Assert.assertEquals(Entities.deproxy(entity).getClass().getName(), BasicEntityImpl.class.getName());
+ }
+
+ @Test(groups="WIP")
+ public void testRebindUpgradeSpec() throws Exception {
+ File initialBomFileV2 = prepForRebindRemovedItemTestReturningBomV2(true, true);
+ Application app = createAndStartApplication(launcherLast.getManagementContext(),
+ Joiner.on("\n").join(
+ "services:",
+ "- type: org.apache.brooklyn.entity.group.DynamicCluster",
+ " cluster.initial.size: 1",
+ " dynamiccluster.memberspec:",
+ " $brooklyn:entitySpec:",
+ " type: simple-entity:1") );
+ Entity cluster = Iterables.getOnlyElement( app.getChildren() );
+ ((DynamicCluster)cluster).resize(0);
+ // at size 0 it should always persist and rebind, even with the dependent java removed (args to prep method above)
+
+ startT2(newLauncherForTests(initialBomFileV2.getAbsolutePath()));
+ promoteT2IfStandby();
+
+ cluster = Iterables.getOnlyElement( Iterables.getOnlyElement(launcherLast.getManagementContext().getApplications()).getChildren() );
+ ((DynamicCluster)cluster).resize(1);
+
+ Entity entity = Iterables.getOnlyElement( ((DynamicCluster)cluster).getMembers() );
+
+ // assert it uses the new spec
+
+ Assert.assertEquals(entity.getCatalogItemId(), "simple-entity:1.0.0");
+ // TODO when upgrades work at level of catalog item ID and bundle ID, do below instead of above
+// Assert.assertEquals(entity.getCatalogItemId(), "simple-entity:2.0.0");
+
+ Assert.assertEquals(Entities.deproxy(entity).getClass().getName(), "com.example.brooklyn.test.osgi.entities.SimpleEntityImpl");
+ // TODO when registered types are used to create, instead of java type,
+ // upgrade should cause the line below instead of the line above (see RebindIteration.load)
+// Assert.assertEquals(Entities.deproxy(entity).getClass().getName(), BasicEntityImpl.class.getName());
+ }
+
protected void assertPersistedBundleListingEqualsEventually(BrooklynLauncher launcher, Set<VersionedName> bundles) {
Asserts.succeedsEventually(new Runnable() {
@Override public void run() {
@@ -824,7 +887,7 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
try {
BrooklynLauncherRebindCatalogOsgiTest fixture = new LauncherRebindSubTests();
fixture.setUp();
- fixture.testRebindRemovedItemIncludingJavaFails();
+ fixture.testRebindUpgradeEntity();
fixture.tearDown();
} catch (Throwable e) {
e.printStackTrace();
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c840fbe9/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherUpgradeCatalogOsgiTest.java
----------------------------------------------------------------------
diff --git a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherUpgradeCatalogOsgiTest.java b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherUpgradeCatalogOsgiTest.java
index 595f5f9..f943f07 100644
--- a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherUpgradeCatalogOsgiTest.java
+++ b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherUpgradeCatalogOsgiTest.java
@@ -186,10 +186,4 @@ public class BrooklynLauncherUpgradeCatalogOsgiTest extends AbstractBrooklynLaun
launcher.terminate();
}
- // NB other related tests in BrooklynLauncherRebindCatalogOsgiTest:
- // * removed item in deployment fails - rebind and upgrade uses new item
- // * removed item in deployment upgrades - rebind and upgrade uses new item
- // * removed item in spec fails
- // * removed item in spec upgrades
-
}