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/21 17:08:18 UTC
[3/8] brooklyn-server git commit: Bundle-upgrade tests: tidies
Bundle-upgrade tests: tidies
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/419f03f1
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/419f03f1
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/419f03f1
Branch: refs/heads/master
Commit: 419f03f1eeae4d1093ca59f33950c3f7ff42055b
Parents: b575350
Author: Aled Sage <al...@gmail.com>
Authored: Thu Nov 16 18:47:54 2017 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Thu Nov 16 18:47:54 2017 +0000
----------------------------------------------------------------------
.../AbstractBrooklynLauncherRebindTest.java | 99 ++++++++++++++++++++
.../BrooklynLauncherUpgradeCatalogOsgiTest.java | 86 +++++++++--------
2 files changed, 144 insertions(+), 41 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/419f03f1/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 9a97644..e778f41 100644
--- a/launcher/src/test/java/org/apache/brooklyn/launcher/AbstractBrooklynLauncherRebindTest.java
+++ b/launcher/src/test/java/org/apache/brooklyn/launcher/AbstractBrooklynLauncherRebindTest.java
@@ -21,11 +21,13 @@ package org.apache.brooklyn.launcher;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.nio.charset.StandardCharsets;
@@ -46,13 +48,16 @@ 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.mgmt.ha.ManagementNodeState;
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.BasicBrooklynCatalog;
import org.apache.brooklyn.core.catalog.internal.CatalogInitialization;
import org.apache.brooklyn.core.entity.trait.Startable;
+import org.apache.brooklyn.core.mgmt.ha.OsgiBundleInstallationResult;
import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
import org.apache.brooklyn.core.mgmt.persist.PersistMode;
import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
@@ -61,6 +66,7 @@ import org.apache.brooklyn.entity.stock.BasicEntity;
import org.apache.brooklyn.util.collections.MutableMap;
import org.apache.brooklyn.util.core.ResourceUtils;
import org.apache.brooklyn.util.core.osgi.BundleMaker;
+import org.apache.brooklyn.util.exceptions.ReferenceWithError;
import org.apache.brooklyn.util.os.Os;
import org.apache.brooklyn.util.osgi.VersionedName;
import org.apache.brooklyn.util.stream.Streams;
@@ -184,7 +190,87 @@ public abstract class AbstractBrooklynLauncherRebindTest {
}
return bf;
}
+
+ BundleFile.Builder bundleBuilder() {
+ return new BundleFile.Builder(this);
+ }
+ protected static class BundleFile {
+ public static class Builder {
+ private final AbstractBrooklynLauncherRebindTest test;
+ private VersionedName name;
+ private String catalogBom;
+ private Map<String, String> manifestLines;
+
+ public Builder(AbstractBrooklynLauncherRebindTest test) {
+ this.test = test;
+ }
+ public Builder name(VersionedName val) {
+ this.name = val;
+ return this;
+ }
+ public Builder name(String symbolicName, String version) {
+ this.name = new VersionedName(symbolicName, version);
+ return this;
+ }
+ public Builder catalogBom(String val) {
+ this.catalogBom = val;
+ return this;
+ }
+ protected Builder catalogBom(Iterable<URI> libraries, Iterable<VersionedName> entities) {
+ return catalogBom(libraries, ImmutableList.of(), entities, null);
+ }
+ protected Builder catalogBom(Iterable<URI> libraryUris, Iterable<VersionedName> libraryNames, Iterable<VersionedName> entities) {
+ return catalogBom(libraryUris, libraryNames, entities, null);
+ }
+ protected Builder catalogBom(Iterable<URI> libraryUris, Iterable<VersionedName> libraryNames, Iterable<VersionedName> entities, String randomNoise) {
+ return catalogBom(test.createCatalogYaml(libraryUris, libraryNames, entities, randomNoise));
+ }
+ public Builder manifestLines(Map<String, String> val) {
+ this.manifestLines = val;
+ return this;
+ }
+ public BundleFile build() {
+ if (name == null) {
+ name = new VersionedName("com.example.brooklyntests."+Identifiers.makeRandomId(4), "1.0.0");
+ }
+ Map<String, byte[]> filesInBundle;
+ if (catalogBom != null) {
+ filesInBundle = ImmutableMap.of(BasicBrooklynCatalog.CATALOG_BOM, catalogBom.getBytes(StandardCharsets.UTF_8));
+ } else {
+ filesInBundle = ImmutableMap.of();
+ }
+ File file = test.newTmpBundle(filesInBundle, name, manifestLines);
+
+ return new BundleFile(name, file);
+ }
+ }
+
+ public final VersionedName name;
+ public final File file;
+
+ BundleFile(VersionedName name, File file) {
+ this.name = name;
+ this.file = file;
+ }
+
+ public VersionedName getVersionedName() {
+ return name;
+ }
+
+ public File getFile() {
+ return file;
+ }
+ }
+
+ protected void assertHealthyMaster(BrooklynLauncher launcher) {
+ ManagementContextInternal mgmt = (ManagementContextInternal) launcher.getServerDetails().getManagementContext();
+ assertTrue(mgmt.isStartupComplete());
+ assertTrue(mgmt.isRunning());
+ assertTrue(mgmt.errors().isEmpty(), "errs="+mgmt.errors());
+ assertEquals(mgmt.getHighAvailabilityManager().getNodeState(), ManagementNodeState.MASTER);
+ }
+
protected void assertCatalogConsistsOfIds(BrooklynLauncher launcher, Iterable<VersionedName> ids) {
BrooklynTypeRegistry typeRegistry = launcher.getServerDetails().getManagementContext().getTypeRegistry();
BrooklynCatalog catalog = launcher.getServerDetails().getManagementContext().getCatalog();
@@ -214,6 +300,15 @@ public abstract class AbstractBrooklynLauncherRebindTest {
Assert.assertTrue(compareIterablesWithoutOrderMatters(ids, idsFromItems), String.format("Expected %s, found %s", ids, idsFromItems));
}
+ protected ReferenceWithError<OsgiBundleInstallationResult> installBundle(BrooklynLauncher launcher, File file, boolean force) throws Exception {
+ return installBundle(launcher, java.nio.file.Files.readAllBytes(file.toPath()), force);
+ }
+
+ protected ReferenceWithError<OsgiBundleInstallationResult> installBundle(BrooklynLauncher launcher, byte[] zipInput, boolean force) {
+ ManagementContextInternal mgmt = (ManagementContextInternal)launcher.getManagementContext();
+ return mgmt.getOsgiManager().get().install(null, new ByteArrayInputStream(zipInput), true, true, force);
+ }
+
protected ManagedBundle findManagedBundle(BrooklynLauncher launcher, VersionedName bundleId) {
ManagementContextInternal mgmt = (ManagementContextInternal)launcher.getManagementContext();
ManagedBundle bundle = mgmt.getOsgiManager().get().getManagedBundle(bundleId);
@@ -360,6 +455,10 @@ public abstract class AbstractBrooklynLauncherRebindTest {
return this;
}
+ public PersistedStateInitializer bundle(BundleFile bundleFile) throws Exception {
+ return bundle(bundleFile.getVersionedName(), bundleFile.getFile());
+ }
+
public PersistedStateInitializer bundles(Map<VersionedName, File> vals) throws Exception {
bundles.putAll(vals);
return this;
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/419f03f1/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 39998bb..3bd73dc 100644
--- a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherUpgradeCatalogOsgiTest.java
+++ b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherUpgradeCatalogOsgiTest.java
@@ -18,20 +18,16 @@
*/
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.api.entity.Group;
-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;
@@ -88,16 +84,19 @@ public class BrooklynLauncherUpgradeCatalogOsgiTest extends AbstractBrooklynLaun
.build())
.initState();
- String bundleBom = createCatalogYaml(ImmutableList.<URI>of(), ImmutableSet.<VersionedName>of());
- VersionedName bundleName = new VersionedName("org.example.testRemoveLegacyItems", "1.0.0");
- Map<String, String> bundleManifest = ImmutableMap.of(MANIFEST_HEADER_FORCE_REMOVE_LEGACY_ITEMS, "\"one:[0,1.0.0)\",\"two:[0,1.0.0)\",\"three:0.1.0\"");
- File bundleFile = newTmpBundle(ImmutableMap.of(CATALOG_BOM, bundleBom.getBytes(StandardCharsets.UTF_8)), bundleName, bundleManifest);
- File initialBomFile = newTmpFile(createCatalogYaml(ImmutableList.of(bundleFile.toURI()), ImmutableList.of()));
+ BundleFile bundleRemovingItems = bundleBuilder()
+ .name("org.example.testRemoveLegacyItems", "1.0.0")
+ .catalogBom(ImmutableList.<URI>of(), ImmutableSet.<VersionedName>of())
+ .manifestLines(ImmutableMap.<String, String>builder()
+ .put(MANIFEST_HEADER_FORCE_REMOVE_LEGACY_ITEMS, "\"one:[0,1.0.0)\",\"two:[0,1.0.0)\",\"three:0.1.0\"")
+ .build())
+ .build();
+ File initialBomFile = newTmpFile(createCatalogYaml(ImmutableList.of(bundleRemovingItems.getFile().toURI()), ImmutableList.of()));
BrooklynLauncher launcher = newLauncherForTests(initialBomFile.getAbsolutePath());
launcher.start();
assertCatalogConsistsOfIds(launcher, ImmutableList.of(two_1_0_0, three_0_2_0, four_0_1_0));
- assertManagedBundle(launcher, bundleName, ImmutableSet.<VersionedName>of());
+ assertManagedBundle(launcher, bundleRemovingItems.getVersionedName(), ImmutableSet.<VersionedName>of());
launcher.terminate();
}
@@ -107,27 +106,31 @@ public class BrooklynLauncherUpgradeCatalogOsgiTest extends AbstractBrooklynLaun
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);
+ BundleFile bundleV1 = bundleBuilder()
+ .name("org.example.testForceUpgradeBundle", "1.0.0")
+ .catalogBom(ImmutableList.<URI>of(), ImmutableSet.<VersionedName>of(one_1_0_0))
+ .build();
newPersistedStateInitializer()
- .bundle(bundleVersionedName1, bundleFile1)
+ .bundle(bundleV1)
.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)\"");
- File bundleFile2 = newTmpBundle(ImmutableMap.of(BasicBrooklynCatalog.CATALOG_BOM, bundleBom2.getBytes(StandardCharsets.UTF_8)), bundleVersionedName2, bundleManifest2);
+ BundleFile bundleV2 = bundleBuilder()
+ .name(bundleV1.getVersionedName().getSymbolicName(), "2.0.0")
+ .catalogBom(ImmutableList.<URI>of(), ImmutableSet.<VersionedName>of(one_2_0_0))
+ .manifestLines(ImmutableMap.<String, String>builder()
+ .put(MANIFEST_HEADER_FORCE_REMOVE_BUNDLES, "\"*\"")
+ .put(MANIFEST_HEADER_UPGRADE_FOR_BUNDLES, "\"*\"")
+ .build())
+ .build();
- File initialBomFile = newTmpFile(createCatalogYaml(ImmutableList.of(bundleFile2.toURI()), ImmutableList.of()));
+ File initialBomFile = newTmpFile(createCatalogYaml(ImmutableList.of(bundleV2.getFile().toURI()), ImmutableList.of()));
BrooklynLauncher launcher = newLauncherForTests(initialBomFile.getAbsolutePath());
launcher.start();
assertCatalogConsistsOfIds(launcher, ImmutableList.of(one_2_0_0));
- assertManagedBundle(launcher, bundleVersionedName2, ImmutableSet.<VersionedName>of(one_2_0_0));
- assertNotManagedBundle(launcher, bundleVersionedName1);
+ assertManagedBundle(launcher, bundleV2.getVersionedName(), ImmutableSet.<VersionedName>of(one_2_0_0));
+ assertNotManagedBundle(launcher, bundleV1.getVersionedName());
launcher.terminate();
}
@@ -136,19 +139,19 @@ public class BrooklynLauncherUpgradeCatalogOsgiTest extends AbstractBrooklynLaun
public void testLoadsBundleFromPersistedState() throws Exception {
VersionedName one_1_0_0 = VersionedName.fromString("one:1.0.0");
- String bundleSymbolicName = "org.example.testForceUpgradeBundle";
- VersionedName bundleVersionedName = new VersionedName(bundleSymbolicName, "1.0.0");
- String bundleBom = createCatalogYaml(ImmutableList.<URI>of(), ImmutableSet.<VersionedName>of(one_1_0_0));
- File bundleFile = newTmpBundle(ImmutableMap.of(BasicBrooklynCatalog.CATALOG_BOM, bundleBom.getBytes(StandardCharsets.UTF_8)), bundleVersionedName);
+ BundleFile bundleV1 = bundleBuilder()
+ .name("org.example.testForceUpgradeBundle", "1.0.0")
+ .catalogBom(ImmutableList.<URI>of(), ImmutableSet.<VersionedName>of(one_1_0_0))
+ .build();
newPersistedStateInitializer()
- .bundle(bundleVersionedName, bundleFile)
+ .bundle(bundleV1)
.initState();
BrooklynLauncher launcher = newLauncherForTests(CATALOG_EMPTY_INITIAL);
launcher.start();
assertCatalogConsistsOfIds(launcher, ImmutableList.of(one_1_0_0));
- assertManagedBundle(launcher, bundleVersionedName, ImmutableSet.<VersionedName>of(one_1_0_0));
+ assertManagedBundle(launcher, bundleV1.getVersionedName(), ImmutableSet.<VersionedName>of(one_1_0_0));
launcher.terminate();
}
@@ -160,23 +163,25 @@ public class BrooklynLauncherUpgradeCatalogOsgiTest extends AbstractBrooklynLaun
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);
+ BundleFile bundleV1 = bundleBuilder()
+ .name("org.example.testForceUpgradeBundle", "1.0.0")
+ .catalogBom(ImmutableList.<URI>of(), ImmutableSet.<VersionedName>of(one_1_0_0))
+ .build();
newPersistedStateInitializer()
- .bundle(bundleVersionedName1, bundleFile1)
+ .bundle(bundleV1)
.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);
+ BundleFile bundleV2 = bundleBuilder()
+ .name(bundleV1.getVersionedName().getSymbolicName(), "2.0.0")
+ .catalogBom(ImmutableList.<URI>of(), ImmutableSet.<VersionedName>of(one_2_0_0))
+ .manifestLines(ImmutableMap.<String, String>builder()
+ .put(MANIFEST_HEADER_FORCE_REMOVE_BUNDLES, "\"*\"")
+ .put(MANIFEST_HEADER_UPGRADE_FOR_BUNDLES, "\"*\"")
+ .build())
+ .build();
- File initialBomFile = newTmpFile(createCatalogYaml(ImmutableList.of(bundleFile2.toURI()), ImmutableList.of()));
+ File initialBomFile = newTmpFile(createCatalogYaml(ImmutableList.of(bundleV2.getFile().toURI()), ImmutableList.of()));
BrooklynLauncher launcher = newLauncherForTests(initialBomFile.getAbsolutePath());
launcher.start();
@@ -200,5 +205,4 @@ public class BrooklynLauncherUpgradeCatalogOsgiTest extends AbstractBrooklynLaun
launcher.terminate();
}
-
}