From fc4045e70b02760ca3e8ed6f0f6b6e267f1b48a3 Mon Sep 17 00:00:00 2001 From: Alex Heneveld Date: Thu, 7 Aug 2014 15:53:37 -0400 Subject: [PATCH 1/8] fix semantics for masking error; it was the wrong way round! --- .../java/brooklyn/util/exceptions/ReferenceWithError.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/utils/common/src/main/java/brooklyn/util/exceptions/ReferenceWithError.java b/utils/common/src/main/java/brooklyn/util/exceptions/ReferenceWithError.java index cdb592502d..9e4fe08fc1 100644 --- a/utils/common/src/main/java/brooklyn/util/exceptions/ReferenceWithError.java +++ b/utils/common/src/main/java/brooklyn/util/exceptions/ReferenceWithError.java @@ -31,12 +31,12 @@ public class ReferenceWithError implements Supplier { /** returns a reference which includes an error, and where attempts to get the content cause the error to throw */ public static ReferenceWithError newInstanceThrowingError(T object, Throwable error) { - return new ReferenceWithError(object, error, true); + return new ReferenceWithError(object, error, false); } /** returns a reference which includes an error, but attempts to get the content do not cause the error to throw */ public static ReferenceWithError newInstanceMaskingError(T object, Throwable error) { - return new ReferenceWithError(object, error, false); + return new ReferenceWithError(object, error, true); } /** returns a reference which includes an error, but attempts to get the content do not cause the error to throw */ @@ -44,10 +44,10 @@ public static ReferenceWithError newInstanceWithoutError(T object) { return new ReferenceWithError(object, null, false); } - protected ReferenceWithError(@Nullable T object, @Nullable Throwable error, boolean throwErrorOnAccess) { + protected ReferenceWithError(@Nullable T object, @Nullable Throwable error, boolean maskError) { this.object = object; this.error = error; - this.maskError = throwErrorOnAccess; + this.maskError = maskError; } /** whether this will mask any error on an attempt to {@link #get()}; From 81f17888fadca61ce23bf9411678de433c5005db Mon Sep 17 00:00:00 2001 From: Alex Heneveld Date: Thu, 7 Aug 2014 15:53:53 -0400 Subject: [PATCH 2/8] tidy osgi logging following code review comments in #109 --- .../main/java/brooklyn/util/osgi/Osgis.java | 41 ++++++++++++++----- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/brooklyn/util/osgi/Osgis.java b/core/src/main/java/brooklyn/util/osgi/Osgis.java index 6b0d99fead..418e417f45 100644 --- a/core/src/main/java/brooklyn/util/osgi/Osgis.java +++ b/core/src/main/java/brooklyn/util/osgi/Osgis.java @@ -57,6 +57,7 @@ import brooklyn.util.collections.MutableList; import brooklyn.util.collections.MutableMap; import brooklyn.util.exceptions.Exceptions; +import brooklyn.util.exceptions.ReferenceWithError; import brooklyn.util.guava.Maybe; import brooklyn.util.net.Urls; import brooklyn.util.os.Os; @@ -179,7 +180,7 @@ public static Framework newFrameworkStarted(String felixCacheDir, boolean clean, // framework bundle start exceptions are not interesting to caller... throw Exceptions.propagate(e); } - LOG.debug("OSGi framework started in " + Duration.of(timer) + " seconds."); + LOG.debug("OSGi framework started in " + Duration.of(timer)); return framework; } @@ -195,7 +196,22 @@ private static void installBootBundles(Framework framework) { Map installedBundles = getInstalledBundles(bundleContext); while(resources.hasMoreElements()) { URL url = resources.nextElement(); - installExtensionBundle(bundleContext, url, installedBundles, getVersionedId(framework)); + ReferenceWithError installResult = installExtensionBundle(bundleContext, url, installedBundles, getVersionedId(framework)); + if (installResult.hasError()) { + if (installResult.getMaskingError()) { + // true return code means it was installed or trivially not installed + if (LOG.isTraceEnabled()) + LOG.trace(installResult.getError().getMessage()); + } else { + if (installResult.masksErrorIfPresent()) { + // if error is masked, then it's not so important (many of the bundles we are looking at won't have manifests) + LOG.debug(installResult.getError().getMessage()); + } else { + // it's reported as a critical error, so warn here + LOG.warn("Unable to install manifest from "+url+": "+installResult.getError(), installResult.getError()); + } + } + } } } @@ -208,13 +224,15 @@ private static Map getInstalledBundles(BundleContext bundleConte return installedBundles; } - private static void installExtensionBundle(BundleContext bundleContext, URL manifestUrl, Map installedBundles, String frameworkVersionedId) { + private static ReferenceWithError installExtensionBundle(BundleContext bundleContext, URL manifestUrl, Map installedBundles, String frameworkVersionedId) { //ignore http://felix.extensions:9/ system entry - if("felix.extensions".equals(manifestUrl.getHost())) return; + if("felix.extensions".equals(manifestUrl.getHost())) + return ReferenceWithError.newInstanceMaskingError(true, new IllegalArgumentException("Skiping install of internal extension bundle from "+manifestUrl)); try { Manifest manifest = readManifest(manifestUrl); - if (!isValidBundle(manifest)) return; + if (!isValidBundle(manifest)) + return ReferenceWithError.newInstanceMaskingError(false, new IllegalArgumentException("Resource at "+manifestUrl+" is not an OSGi bundle: no valid manifest")); String versionedId = getVersionedId(manifest); URL bundleUrl = ResourceUtils.getContainerUrl(manifestUrl, MANIFEST_PATH); @@ -224,9 +242,9 @@ private static void installExtensionBundle(BundleContext bundleContext, URL mani if (!bundleUrl.equals(existingBundle.getLocation()) && //the framework bundle is always pre-installed, don't display duplicate info !versionedId.equals(frameworkVersionedId)) { - LOG.info("Ignoring duplicate " + versionedId + " from manifest " + manifestUrl + ", already loaded from " + existingBundle.getLocation()); + return ReferenceWithError.newInstanceMaskingError(false, new IllegalArgumentException("Bundle "+versionedId+" (from manifest " + manifestUrl + ") is already installed, from " + existingBundle.getLocation())); } - return; + return ReferenceWithError.newInstanceMaskingError(true, new IllegalArgumentException("Bundle "+versionedId+" from manifest " + manifestUrl + " is already installed")); } byte[] jar = buildExtensionBundle(manifest); @@ -235,10 +253,11 @@ private static void installExtensionBundle(BundleContext bundleContext, URL mani //(since we cannot access BundleImpl.isExtension) Bundle newBundle = bundleContext.installBundle(EXTENSION_PROTOCOL + ":" + bundleUrl.toString(), new ByteArrayInputStream(jar)); installedBundles.put(versionedId, newBundle); - } catch (IOException e) { - LOG.warn("Error installing extension bundle " + manifestUrl + ", ignoring: "+e, e); - } catch (BundleException e) { - LOG.warn("Error installing extension bundle " + manifestUrl + ", ignoring: "+e, e); + return ReferenceWithError.newInstanceWithoutError(true); + } catch (Exception e) { + Exceptions.propagateIfFatal(e); + return ReferenceWithError.newInstanceThrowingError(false, + new IllegalStateException("Problem installing extension bundle " + manifestUrl + ": "+e, e)); } } From 9f439dd8677e32c8daa14f1968cc19a526aab1b5 Mon Sep 17 00:00:00 2001 From: Alex Heneveld Date: Thu, 7 Aug 2014 18:17:00 -0400 Subject: [PATCH 3/8] add builder for LocalManagementContextForTests and use in more places to speed things up, also adding conveniences for the BrooklynProperties.Factory.Builder --- .../catalog/internal/CatalogLibrariesDo.java | 26 +-- .../brooklyn/config/BrooklynProperties.java | 46 ++++- .../internal/LocalManagementContext.java | 1 + .../brooklyn/camp/lite/CampYamlLiteTest.java | 4 +- .../basic/AbstractEntityLegacyTest.java | 3 +- .../entity/basic/DynamicEntityTest.java | 3 +- .../entity/basic/DynamicGroupTest.java | 4 +- .../persister/XmlMementoSerializerTest.java | 11 +- .../basic/ByonLocationResolverTest.java | 3 +- .../location/basic/MachineDetailsTest.java | 5 +- .../SshMachineLocationIntegrationTest.java | 3 +- .../location/cloud/CloudMachineNamerTest.java | 13 +- .../cloud/CustomMachineNamerTest.java | 3 +- .../internal/EntityExecutionManagerTest.java | 15 +- .../internal/LocalManagementContextTest.java | 15 +- .../LocalManagementContextForTests.java | 93 +++++++++- .../location/jclouds/JcloudsLocation.java | 2 +- ...Test.java => AbstractJcloudsLiveTest.java} | 8 +- .../JcloudsByonLocationResolverLiveTest.java | 175 ++++++++++++++++++ .../JcloudsByonLocationResolverTest.java | 166 ++--------------- .../jclouds/JcloudsLocationMetadataTest.java | 3 +- .../JcloudsLocationRebindMachineLiveTest.java | 5 +- .../jclouds/JcloudsLocationResolverTest.java | 3 +- .../location/jclouds/JcloudsLocationTest.java | 14 +- .../jclouds/JcloudsLoginLiveTest.java | 2 +- .../jclouds/JcloudsMinRamLiveTest.java | 2 +- .../location/jclouds/LiveTestEntity.java | 15 +- .../RebindJcloudsLocationLiveTest.java | 36 ++-- ...udsLocationUserLoginAndConfigLiveTest.java | 3 +- ...neProvisioningLocationJcloudsLiveTest.java | 2 +- .../jclouds/StandaloneJcloudsLiveTest.java | 4 +- .../JcloudsPortForwardingLiveTest.java | 4 +- .../pool/JcloudsMachinePoolLiveTest.java | 4 +- .../AwsAvailabilityZoneExtensionTest.java | 8 +- .../entity/brooklyn/BrooklynMetricsTest.java | 4 +- .../entity/basic/SameServerEntityTest.java | 2 +- ...wareProcessAndChildrenIntegrationTest.java | 2 +- .../entity/software/SoftwareEffectorTest.java | 3 +- .../entity/software/SshEffectorTasksTest.java | 2 +- .../ssh/SshCommandIntegrationTest.java | 3 +- .../brooklyn/event/feed/jmx/JmxFeedTest.java | 2 +- .../camp/brooklyn/AbstractYamlTest.java | 8 +- 42 files changed, 449 insertions(+), 281 deletions(-) rename locations/jclouds/src/test/java/brooklyn/location/jclouds/{AbstractJcloudsTest.java => AbstractJcloudsLiveTest.java} (95%) create mode 100644 locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverLiveTest.java diff --git a/core/src/main/java/brooklyn/catalog/internal/CatalogLibrariesDo.java b/core/src/main/java/brooklyn/catalog/internal/CatalogLibrariesDo.java index 84590f7160..2a9fdbc3bd 100644 --- a/core/src/main/java/brooklyn/catalog/internal/CatalogLibrariesDo.java +++ b/core/src/main/java/brooklyn/catalog/internal/CatalogLibrariesDo.java @@ -54,22 +54,22 @@ public List getBundles() { */ void load(ManagementContext managementContext) { ManagementContextInternal mgmt = (ManagementContextInternal) managementContext; - Maybe osgi = mgmt.getOsgiManager(); List bundles = getBundles(); - if (osgi.isAbsent()) { - LOG.warn("{} not loading bundles in {} because osgi manager is unavailable. Bundles: {}", + if (!bundles.isEmpty()) { + Maybe osgi = mgmt.getOsgiManager(); + if (osgi.isAbsent()) { + throw new IllegalStateException("Unable to load bundles "+bundles+" because OSGi is not running."); + } else if (LOG.isDebugEnabled()) { + LOG.debug("{} loading bundles in {}: {}", new Object[]{this, managementContext, Joiner.on(", ").join(bundles)}); - return; - } else if (LOG.isDebugEnabled()) { - LOG.debug("{} loading bundles in {}: {}", - new Object[]{this, managementContext, Joiner.on(", ").join(bundles)}); - } - Stopwatch timer = Stopwatch.createStarted(); - for (String bundleUrl : bundles) { - osgi.get().registerBundle(bundleUrl); - } - LOG.debug("{} registered {} bundles in {}", + } + Stopwatch timer = Stopwatch.createStarted(); + for (String bundleUrl : bundles) { + osgi.get().registerBundle(bundleUrl); + } + LOG.debug("{} registered {} bundles in {}", new Object[]{this, bundles.size(), Time.makeTimeStringRounded(timer)}); + } } } diff --git a/core/src/main/java/brooklyn/config/BrooklynProperties.java b/core/src/main/java/brooklyn/config/BrooklynProperties.java index bd278e5940..b5d63bae7d 100644 --- a/core/src/main/java/brooklyn/config/BrooklynProperties.java +++ b/core/src/main/java/brooklyn/config/BrooklynProperties.java @@ -72,17 +72,46 @@ public static BrooklynProperties newEmpty() { /** creates a new {@link BrooklynProperties} with contents loaded * from the usual places, including *.properties files and environment variables */ public static BrooklynProperties newDefault() { - return new Builder().build(); + return new Builder(true).build(); + } + + public static Builder builderDefault() { + return new Builder(true); + } + + public static Builder builderEmpty() { + return new Builder(true); } public static class Builder { - private String defaultLocationMetadataUrl = "classpath://brooklyn/location-metadata.properties"; - private String globalLocationMetadataFile = Os.mergePaths(Os.home(), ".brooklyn", "location-metadata.properties"); - private String globalPropertiesFile = Os.mergePaths(Os.home(), ".brooklyn", "brooklyn.properties"); + private String defaultLocationMetadataUrl; + private String globalLocationMetadataFile = null; + private String globalPropertiesFile = null; private String localPropertiesFile = null; private BrooklynProperties originalProperties = null; - public Builder(){} + /** @deprecated since 0.7.0 use static methods in {@link Factory} to create */ + public Builder() { + this(true); + } + + private Builder(boolean setGlobalFileDefaults) { + resetDefaultLocationMetadataUrl(); + if (setGlobalFileDefaults) { + resetGlobalFiles(); + } + } + + public Builder resetDefaultLocationMetadataUrl() { + defaultLocationMetadataUrl = "classpath://brooklyn/location-metadata.properties"; + return this; + } + public Builder resetGlobalFiles() { + defaultLocationMetadataUrl = "classpath://brooklyn/location-metadata.properties"; + globalLocationMetadataFile = Os.mergePaths(Os.home(), ".brooklyn", "location-metadata.properties"); + globalPropertiesFile = Os.mergePaths(Os.home(), ".brooklyn", "brooklyn.properties"); + return this; + } /** * Creates a Builder that when built, will return the BrooklynProperties passed to this constructor @@ -133,6 +162,7 @@ public Builder localPropertiesFile(String val) { public BrooklynProperties build() { if (originalProperties != null) return new BrooklynProperties().addFromMap(originalProperties); + BrooklynProperties properties = new BrooklynProperties(); // TODO Could also read from http://brooklyn.io, for up-to-date values? @@ -141,7 +171,7 @@ public BrooklynProperties build() { addPropertiesFromFile(properties, globalLocationMetadataFile); addPropertiesFromFile(properties, globalPropertiesFile); - if (localPropertiesFile != null) addPropertiesFromFile(properties, localPropertiesFile); + addPropertiesFromFile(properties, localPropertiesFile); properties.addEnvironmentVars(); properties.addSystemProperties(); @@ -167,6 +197,8 @@ public String toString() { } private static void addPropertiesFromUrl(BrooklynProperties p, String url, boolean warnIfNotFound) { + if (url==null) return; + try { p.addFrom(ResourceUtils.create(BrooklynProperties.class).getResourceFromUrl(url)); } catch (Exception e) { @@ -177,6 +209,8 @@ private static void addPropertiesFromUrl(BrooklynProperties p, String url, boole } private static void addPropertiesFromFile(BrooklynProperties p, String file) { + if (file==null) return; + String fileTidied = Os.tidyPath(file); File f = new File(fileTidied); diff --git a/core/src/main/java/brooklyn/management/internal/LocalManagementContext.java b/core/src/main/java/brooklyn/management/internal/LocalManagementContext.java index 136dba178a..2c3d43aff8 100644 --- a/core/src/main/java/brooklyn/management/internal/LocalManagementContext.java +++ b/core/src/main/java/brooklyn/management/internal/LocalManagementContext.java @@ -280,6 +280,7 @@ public synchronized LocalUsageManager getUsageManager() { @Override public synchronized Maybe getOsgiManager() { if (!isRunning()) throw new IllegalStateException("Management context no longer running"); + if (osgiManager==null) return Maybe.absent("OSGi not available in this instance"); return Maybe.of(osgiManager); } diff --git a/core/src/test/java/brooklyn/camp/lite/CampYamlLiteTest.java b/core/src/test/java/brooklyn/camp/lite/CampYamlLiteTest.java index 0e081cf0e5..8eedabfa7b 100644 --- a/core/src/test/java/brooklyn/camp/lite/CampYamlLiteTest.java +++ b/core/src/test/java/brooklyn/camp/lite/CampYamlLiteTest.java @@ -68,7 +68,7 @@ public class CampYamlLiteTest { @BeforeMethod(alwaysRun=true) public void setUp() { - mgmt = new LocalManagementContextForTests(); + mgmt = LocalManagementContextForTests.newInstanceWithOsgi(); platform = new CampPlatformWithJustBrooklynMgmt(mgmt); } @@ -187,7 +187,7 @@ public void testResetXmlWithCustomEntity() throws IOException { String bundleUrl = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL; String yaml = getSampleMyCatalogAppYaml(registeredTypeName, bundleUrl); - LocalManagementContextForTests mgmt2 = new LocalManagementContextForTests(); + LocalManagementContext mgmt2 = LocalManagementContextForTests.newInstanceWithOsgi(); try { CampPlatformWithJustBrooklynMgmt platform2 = new CampPlatformWithJustBrooklynMgmt(mgmt2); MockWebPlatform.populate(platform2, TestAppAssemblyInstantiator.class); diff --git a/core/src/test/java/brooklyn/entity/basic/AbstractEntityLegacyTest.java b/core/src/test/java/brooklyn/entity/basic/AbstractEntityLegacyTest.java index 3c0bb1e1da..723420b37b 100644 --- a/core/src/test/java/brooklyn/entity/basic/AbstractEntityLegacyTest.java +++ b/core/src/test/java/brooklyn/entity/basic/AbstractEntityLegacyTest.java @@ -32,6 +32,7 @@ import brooklyn.entity.proxying.EntitySpec; import brooklyn.entity.proxying.ImplementedBy; import brooklyn.location.basic.SimulatedLocation; +import brooklyn.test.entity.LocalManagementContextForTests; import brooklyn.test.entity.TestApplication; import brooklyn.test.entity.TestApplicationImpl; import brooklyn.util.collections.MutableMap; @@ -147,7 +148,7 @@ public void testNewStyleSetsDefaultDisplayName() throws Exception { @Test public void testNewStyleUsesCustomDisplayName() throws Exception { - app = ApplicationBuilder.newManagedApp(EntitySpec.create(TestApplication.class).displayName("appname")); + app = ApplicationBuilder.newManagedApp(EntitySpec.create(TestApplication.class).displayName("appname"), LocalManagementContextForTests.newInstance()); MyEntity entity = app.addChild(EntitySpec.create(MyEntity.class).displayName("entityname")); assertEquals(app.getDisplayName(), "appname"); diff --git a/core/src/test/java/brooklyn/entity/basic/DynamicEntityTest.java b/core/src/test/java/brooklyn/entity/basic/DynamicEntityTest.java index a9b25799e5..1b5928d090 100644 --- a/core/src/test/java/brooklyn/entity/basic/DynamicEntityTest.java +++ b/core/src/test/java/brooklyn/entity/basic/DynamicEntityTest.java @@ -27,6 +27,7 @@ import brooklyn.entity.effector.EffectorTaskTest; import brooklyn.entity.proxying.EntityInitializer; import brooklyn.entity.proxying.EntitySpec; +import brooklyn.test.entity.LocalManagementContextForTests; import brooklyn.util.collections.MutableMap; public class DynamicEntityTest { @@ -35,7 +36,7 @@ public class DynamicEntityTest { @BeforeMethod(alwaysRun=true) public void setup() throws Exception { - app = ApplicationBuilder.newManagedApp(EntitySpec.create(BasicApplication.class)); + app = ApplicationBuilder.newManagedApp(EntitySpec.create(BasicApplication.class), LocalManagementContextForTests.newInstance()); } @AfterMethod(alwaysRun=true) diff --git a/core/src/test/java/brooklyn/entity/basic/DynamicGroupTest.java b/core/src/test/java/brooklyn/entity/basic/DynamicGroupTest.java index 00ed47a103..12c3b55d58 100644 --- a/core/src/test/java/brooklyn/entity/basic/DynamicGroupTest.java +++ b/core/src/test/java/brooklyn/entity/basic/DynamicGroupTest.java @@ -71,7 +71,7 @@ public class DynamicGroupTest { @BeforeMethod(alwaysRun=true) public void setUp() { - app = ApplicationBuilder.newManagedApp(TestApplication.class); + app = TestApplication.Factory.newManagedInstanceForTests(); group = app.createAndManageChild(EntitySpec.create(DynamicGroup.class)); e1 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); e2 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); @@ -101,7 +101,7 @@ public void testGroupWithMatchingFilterReturnsOnlyMatchingMembers() throws Excep @Test public void testCanUsePredicateAsFilter() throws Exception { - Predicate predicate = Predicates.equalTo(e1); + Predicate predicate = Predicates.equalTo(e1); group.setEntityFilter(predicate); assertEqualsIgnoringOrder(group.getMembers(), ImmutableSet.of(e1)); } diff --git a/core/src/test/java/brooklyn/entity/rebind/persister/XmlMementoSerializerTest.java b/core/src/test/java/brooklyn/entity/rebind/persister/XmlMementoSerializerTest.java index 777629137e..4eb08b9500 100644 --- a/core/src/test/java/brooklyn/entity/rebind/persister/XmlMementoSerializerTest.java +++ b/core/src/test/java/brooklyn/entity/rebind/persister/XmlMementoSerializerTest.java @@ -34,7 +34,6 @@ import org.testng.annotations.Test; import brooklyn.entity.Entity; -import brooklyn.entity.basic.ApplicationBuilder; import brooklyn.entity.basic.Entities; import brooklyn.entity.proxying.EntitySpec; import brooklyn.location.Location; @@ -126,7 +125,7 @@ public void testImmutableMap() throws Exception { @Test public void testEntity() throws Exception { - final TestApplication app = ApplicationBuilder.newManagedApp(TestApplication.class); + final TestApplication app = TestApplication.Factory.newManagedInstanceForTests(); ManagementContext managementContext = app.getManagementContext(); try { serializer.setLookupContext(new LookupContextImpl(managementContext, ImmutableList.of(app), ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), true)); @@ -138,7 +137,7 @@ public void testEntity() throws Exception { @Test public void testLocation() throws Exception { - TestApplication app = ApplicationBuilder.newManagedApp(TestApplication.class); + final TestApplication app = TestApplication.Factory.newManagedInstanceForTests(); ManagementContext managementContext = app.getManagementContext(); try { @SuppressWarnings("deprecation") @@ -155,7 +154,7 @@ public void testImmutableCollectionsWithDanglingEntityRef() throws Exception { // If there's a dangling entity in an ImmutableList etc, then discard it entirely. // If we try to insert null then it fails, breaking the deserialization of that entire file. - final TestApplication app = ApplicationBuilder.newManagedApp(TestApplication.class); + final TestApplication app = TestApplication.Factory.newManagedInstanceForTests(); final TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)); ManagementContext managementContext = app.getManagementContext(); try { @@ -178,7 +177,7 @@ public void testImmutableCollectionsWithDanglingEntityRef() throws Exception { @Test public void testFieldReffingEntity() throws Exception { - final TestApplication app = ApplicationBuilder.newManagedApp(TestApplication.class); + final TestApplication app = TestApplication.Factory.newManagedInstanceForTests(); ReffingEntity reffer = new ReffingEntity(app); ManagementContext managementContext = app.getManagementContext(); try { @@ -192,7 +191,7 @@ public void testFieldReffingEntity() throws Exception { @Test public void testUntypedFieldReffingEntity() throws Exception { - final TestApplication app = ApplicationBuilder.newManagedApp(TestApplication.class); + final TestApplication app = TestApplication.Factory.newManagedInstanceForTests(); ReffingEntity reffer = new ReffingEntity((Object)app); ManagementContext managementContext = app.getManagementContext(); try { diff --git a/core/src/test/java/brooklyn/location/basic/ByonLocationResolverTest.java b/core/src/test/java/brooklyn/location/basic/ByonLocationResolverTest.java index 4bef04dcff..08d8dcafd9 100644 --- a/core/src/test/java/brooklyn/location/basic/ByonLocationResolverTest.java +++ b/core/src/test/java/brooklyn/location/basic/ByonLocationResolverTest.java @@ -43,6 +43,7 @@ import brooklyn.location.MachineProvisioningLocation; import brooklyn.management.internal.LocalManagementContext; import brooklyn.test.Asserts; +import brooklyn.test.entity.LocalManagementContextForTests; import brooklyn.util.collections.MutableMap; import brooklyn.util.os.Os; import brooklyn.util.text.StringPredicates; @@ -67,7 +68,7 @@ public class ByonLocationResolverTest { @BeforeMethod(alwaysRun=true) public void setUp() throws Exception { - managementContext = new LocalManagementContext(BrooklynProperties.Factory.newEmpty()); + managementContext = LocalManagementContextForTests.newInstance(); brooklynProperties = managementContext.getBrooklynProperties(); defaultNamePredicate = StringPredicates.startsWith(FixedListMachineProvisioningLocation.class.getSimpleName()); } diff --git a/core/src/test/java/brooklyn/location/basic/MachineDetailsTest.java b/core/src/test/java/brooklyn/location/basic/MachineDetailsTest.java index 53b708c61d..c6f36855c6 100644 --- a/core/src/test/java/brooklyn/location/basic/MachineDetailsTest.java +++ b/core/src/test/java/brooklyn/location/basic/MachineDetailsTest.java @@ -29,7 +29,6 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import brooklyn.entity.basic.ApplicationBuilder; import brooklyn.entity.basic.Entities; import brooklyn.location.LocationSpec; import brooklyn.location.MachineDetails; @@ -37,8 +36,6 @@ import brooklyn.management.ManagementContext; import brooklyn.management.Task; import brooklyn.test.entity.TestApplication; -import brooklyn.util.task.DynamicSequentialTask; -import brooklyn.util.task.DynamicTasks; public class MachineDetailsTest { @@ -50,7 +47,7 @@ public class MachineDetailsTest { @BeforeMethod(alwaysRun=true) public void setup() throws Exception { - app = ApplicationBuilder.newManagedApp(TestApplication.class); + app = TestApplication.Factory.newManagedInstanceForTests(); mgmt = app.getManagementContext(); LocalhostMachineProvisioningLocation localhost = mgmt.getLocationManager().createLocation( diff --git a/core/src/test/java/brooklyn/location/basic/SshMachineLocationIntegrationTest.java b/core/src/test/java/brooklyn/location/basic/SshMachineLocationIntegrationTest.java index 30a6f3288a..9f743f51da 100644 --- a/core/src/test/java/brooklyn/location/basic/SshMachineLocationIntegrationTest.java +++ b/core/src/test/java/brooklyn/location/basic/SshMachineLocationIntegrationTest.java @@ -27,7 +27,6 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import brooklyn.entity.basic.ApplicationBuilder; import brooklyn.entity.basic.Entities; import brooklyn.management.ManagementContext; import brooklyn.test.entity.TestApplication; @@ -45,7 +44,7 @@ public class SshMachineLocationIntegrationTest { @BeforeMethod(alwaysRun=true) public void setup() throws Exception { - app = ApplicationBuilder.newManagedApp(TestApplication.class); + app = TestApplication.Factory.newManagedInstanceForTests(); mgmt = app.getManagementContext(); } diff --git a/core/src/test/java/brooklyn/location/cloud/CloudMachineNamerTest.java b/core/src/test/java/brooklyn/location/cloud/CloudMachineNamerTest.java index bb695087ab..4da08bcd81 100644 --- a/core/src/test/java/brooklyn/location/cloud/CloudMachineNamerTest.java +++ b/core/src/test/java/brooklyn/location/cloud/CloudMachineNamerTest.java @@ -30,6 +30,7 @@ import brooklyn.entity.basic.ApplicationBuilder; import brooklyn.entity.basic.Entities; import brooklyn.entity.proxying.EntitySpec; +import brooklyn.test.entity.LocalManagementContextForTests; import brooklyn.test.entity.TestApplication; import brooklyn.test.entity.TestEntity; import brooklyn.util.config.ConfigBag; @@ -47,7 +48,7 @@ public void tearDown() throws Exception { @Test public void testGenerateGroupIdWithEntity() { - app = ApplicationBuilder.newManagedApp(EntitySpec.create(TestApplication.class).displayName("TistApp")); + app = ApplicationBuilder.newManagedApp(EntitySpec.create(TestApplication.class).displayName("TistApp"), LocalManagementContextForTests.newInstance()); TestEntity child = app.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("TestEnt")); ConfigBag cfg = new ConfigBag() @@ -69,7 +70,7 @@ public void testGenerateGroupIdWithEntity() { @Test public void testGenerateNewMachineName() { - app = ApplicationBuilder.newManagedApp(EntitySpec.create(TestApplication.class).displayName("TistApp")); + app = ApplicationBuilder.newManagedApp(EntitySpec.create(TestApplication.class).displayName("TistApp"), LocalManagementContextForTests.newInstance()); TestEntity child = app.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("TestEnt")); ConfigBag cfg = new ConfigBag() @@ -88,7 +89,7 @@ public void testGenerateNewMachineName() { @Test public void testGenerateNewMachineUniqueNameFromGroupId() { - app = ApplicationBuilder.newManagedApp(EntitySpec.create(TestApplication.class).displayName("TistApp")); + app = ApplicationBuilder.newManagedApp(EntitySpec.create(TestApplication.class).displayName("TistApp"), LocalManagementContextForTests.newInstance()); TestEntity child = app.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("TestEnt")); ConfigBag cfg = new ConfigBag() @@ -103,7 +104,7 @@ public void testGenerateNewMachineUniqueNameFromGroupId() { @Test public void testLengthMaxPermittedForMachineName() { - app = ApplicationBuilder.newManagedApp(EntitySpec.create(TestApplication.class).displayName("TistApp")); + app = ApplicationBuilder.newManagedApp(EntitySpec.create(TestApplication.class).displayName("TistApp"), LocalManagementContextForTests.newInstance()); TestEntity child = app.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("TestEnt")); ConfigBag cfg = new ConfigBag() @@ -116,7 +117,7 @@ public void testLengthMaxPermittedForMachineName() { @Test public void testLengthReserverdForNameInGroup() { - app = ApplicationBuilder.newManagedApp(EntitySpec.create(TestApplication.class).displayName("TistApp")); + app = ApplicationBuilder.newManagedApp(EntitySpec.create(TestApplication.class).displayName("TistApp"), LocalManagementContextForTests.newInstance()); TestEntity child = app.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("TestEnt")); ConfigBag cfg = new ConfigBag() @@ -130,7 +131,7 @@ public void testLengthReserverdForNameInGroup() { @Test public void testSanitizesNewMachineName() { - app = ApplicationBuilder.newManagedApp(EntitySpec.create(TestApplication.class).displayName("T_%$()\r\n\t[]*.!App")); + app = ApplicationBuilder.newManagedApp(EntitySpec.create(TestApplication.class).displayName("T_%$()\r\n\t[]*.!App"), LocalManagementContextForTests.newInstance()); TestEntity child = app.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("ent")); ConfigBag cfg = new ConfigBag() diff --git a/core/src/test/java/brooklyn/location/cloud/CustomMachineNamerTest.java b/core/src/test/java/brooklyn/location/cloud/CustomMachineNamerTest.java index 7d6c63f8c5..829edb41ba 100644 --- a/core/src/test/java/brooklyn/location/cloud/CustomMachineNamerTest.java +++ b/core/src/test/java/brooklyn/location/cloud/CustomMachineNamerTest.java @@ -26,6 +26,7 @@ import brooklyn.entity.basic.ApplicationBuilder; import brooklyn.entity.basic.Entities; import brooklyn.entity.proxying.EntitySpec; +import brooklyn.test.entity.LocalManagementContextForTests; import brooklyn.test.entity.TestApplication; import brooklyn.test.entity.TestEntity; import brooklyn.util.config.ConfigBag; @@ -40,7 +41,7 @@ public class CustomMachineNamerTest { @BeforeMethod(alwaysRun=true) public void setUp() { - app = ApplicationBuilder.newManagedApp(EntitySpec.create(TestApplication.class).displayName("TestApp")); + app = ApplicationBuilder.newManagedApp(EntitySpec.create(TestApplication.class).displayName("TestApp"), LocalManagementContextForTests.newInstance()); child = app.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("TestEnt")); config = new ConfigBag() .configure(CloudLocationConfig.CALLER_CONTEXT, child); diff --git a/core/src/test/java/brooklyn/management/internal/EntityExecutionManagerTest.java b/core/src/test/java/brooklyn/management/internal/EntityExecutionManagerTest.java index cd58c821c4..e8d8986fe2 100644 --- a/core/src/test/java/brooklyn/management/internal/EntityExecutionManagerTest.java +++ b/core/src/test/java/brooklyn/management/internal/EntityExecutionManagerTest.java @@ -45,6 +45,7 @@ import brooklyn.event.basic.BasicAttributeSensor; import brooklyn.management.Task; import brooklyn.test.Asserts; +import brooklyn.test.entity.LocalManagementContextForTests; import brooklyn.test.entity.TestApplication; import brooklyn.test.entity.TestEntity; import brooklyn.util.collections.MutableMap; @@ -77,7 +78,7 @@ public void tearDown() throws Exception { @Test public void testGetTasksOfEntity() throws Exception { - app = ApplicationBuilder.newManagedApp(TestApplication.class); + app = TestApplication.Factory.newManagedInstanceForTests(); e = app.createAndManageChild(EntitySpec.create(TestEntity.class)); final CountDownLatch latch = new CountDownLatch(1); @@ -95,7 +96,7 @@ public void testGetTasksOfEntity() throws Exception { @Test public void testUnmanagedEntityCanBeGcedEvenIfPreviouslyTagged() throws Exception { - app = ApplicationBuilder.newManagedApp(TestApplication.class); + app = TestApplication.Factory.newManagedInstanceForTests(); e = app.createAndManageChild(EntitySpec.create(TestEntity.class)); String eId = e.getId(); @@ -126,7 +127,7 @@ public void testUnmanagedEntityCanBeGcedEvenIfPreviouslyTagged() throws Exceptio @Test(groups="Integration") public void testUnmanagedEntityGcedOnUnmanageEvenIfEffectorInvoked() throws Exception { - app = ApplicationBuilder.newManagedApp(TestApplication.class); + app = TestApplication.Factory.newManagedInstanceForTests(); BasicAttributeSensor byteArrayAttrib = new BasicAttributeSensor(Object.class, "test.byteArray", ""); @@ -155,7 +156,7 @@ public void testEffectorTasksGcedSoNoOome() throws Exception { brooklynProperties.put(BrooklynGarbageCollector.GC_PERIOD, 1); brooklynProperties.put(BrooklynGarbageCollector.MAX_TASKS_PER_TAG, 2); - app = ApplicationBuilder.newManagedApp(TestApplication.class, new LocalManagementContext(brooklynProperties)); + app = ApplicationBuilder.newManagedApp(TestApplication.class, LocalManagementContextForTests.newInstance(brooklynProperties)); TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)); for (int i = 0; i < 1000; i++) { @@ -185,7 +186,7 @@ public void testEffectorTasksGcedForMaxPerTag() throws Exception { brooklynProperties.put(BrooklynGarbageCollector.GC_PERIOD, 1000); brooklynProperties.put(BrooklynGarbageCollector.MAX_TASKS_PER_TAG, 2); - app = ApplicationBuilder.newManagedApp(TestApplication.class, new LocalManagementContext(brooklynProperties)); + app = ApplicationBuilder.newManagedApp(TestApplication.class, LocalManagementContextForTests.newInstance(brooklynProperties)); final TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)); List> tasks = Lists.newArrayList(); @@ -220,7 +221,7 @@ public void testEffectorTasksGcedForAge() throws Exception { brooklynProperties.put(BrooklynGarbageCollector.GC_PERIOD, 1); brooklynProperties.put(BrooklynGarbageCollector.MAX_TASK_AGE, maxTaskAge); - app = ApplicationBuilder.newManagedApp(TestApplication.class, new LocalManagementContext(brooklynProperties)); + app = ApplicationBuilder.newManagedApp(TestApplication.class, LocalManagementContextForTests.newInstance(brooklynProperties)); final TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)); Stopwatch stopwatch = Stopwatch.createStarted(); @@ -253,7 +254,7 @@ private static class BigObject implements Serializable { @Override public String toString() { - return "BigObject["+sizeBytes+"]"; + return "BigObject["+sizeBytes+"/"+data.length+"]"; } } } diff --git a/core/src/test/java/brooklyn/management/internal/LocalManagementContextTest.java b/core/src/test/java/brooklyn/management/internal/LocalManagementContextTest.java index 68567bf784..be29a73dc1 100644 --- a/core/src/test/java/brooklyn/management/internal/LocalManagementContextTest.java +++ b/core/src/test/java/brooklyn/management/internal/LocalManagementContextTest.java @@ -33,6 +33,7 @@ import brooklyn.config.BrooklynProperties.Factory.Builder; import brooklyn.location.Location; import brooklyn.management.ManagementContext.PropertiesReloadListener; +import brooklyn.test.entity.LocalManagementContextForTests; import brooklyn.util.os.Os; import com.google.common.base.Charsets; @@ -40,15 +41,18 @@ public class LocalManagementContextTest { + private LocalManagementContext context; private File globalPropertiesFile; @BeforeMethod(alwaysRun=true) public void setUp() throws Exception { + context = null; globalPropertiesFile = Os.newTempFile(getClass(), "global.properties"); } @AfterMethod(alwaysRun=true) public void tearDown() throws Exception { + if (context!=null) context.terminate(); if (globalPropertiesFile != null) globalPropertiesFile.delete(); } @@ -56,9 +60,10 @@ public void tearDown() throws Exception { public void testReloadPropertiesFromBuilder() throws IOException { String globalPropertiesContents = "brooklyn.location.localhost.displayName=myname"; Files.write(globalPropertiesContents, globalPropertiesFile, Charsets.UTF_8); - Builder builder = new BrooklynProperties.Factory.Builder() + Builder propsBuilder = new BrooklynProperties.Factory.Builder() .globalPropertiesFile(globalPropertiesFile.getAbsolutePath()); - LocalManagementContext context = new LocalManagementContext(builder); + // no builder support in LocalManagementContextForTests (we are testing that the builder's files are reloaded so we need it here) + context = new LocalManagementContext(propsBuilder); Location location = context.getLocationRegistry().resolve("localhost"); assertEquals(location.getDisplayName(), "myname"); String newGlobalPropertiesContents = "brooklyn.location.localhost.displayName=myname2"; @@ -76,7 +81,7 @@ public void testReloadPropertiesFromProperties() throws IOException { BrooklynProperties brooklynProperties = new BrooklynProperties.Factory.Builder() .globalPropertiesFile(globalPropertiesFile.getAbsolutePath()) .build(); - LocalManagementContext context = new LocalManagementContext(brooklynProperties); + context = LocalManagementContextForTests.builder(true).useProperties(brooklynProperties).build(); Location location = context.getLocationRegistry().resolve("localhost"); assertEquals(location.getDisplayName(), "myname"); String newGlobalPropertiesContents = "brooklyn.location.localhost.displayName=myname2"; @@ -91,7 +96,7 @@ public void testReloadPropertiesFromProperties() throws IOException { public void testPropertiesModified() throws IOException { BrooklynProperties properties = BrooklynProperties.Factory.newEmpty(); properties.put("myname", "myval"); - LocalManagementContext context = new LocalManagementContext(properties); + context = LocalManagementContextForTests.builder(true).useProperties(properties).build(); assertEquals(context.getBrooklynProperties().get("myname"), "myval"); properties.put("myname", "newval"); assertEquals(properties.get("myname"), "newval"); @@ -104,7 +109,7 @@ public void testAddAndRemoveReloadListener() { final AtomicInteger reloadedCallbackCount = new AtomicInteger(0); BrooklynProperties properties = BrooklynProperties.Factory.newEmpty(); properties.put("myname", "myval"); - LocalManagementContext context = new LocalManagementContext(properties); + context = LocalManagementContextForTests.builder(true).useProperties(properties).build(); PropertiesReloadListener listener = new PropertiesReloadListener() { public void reloaded() { reloadedCallbackCount.incrementAndGet(); diff --git a/core/src/test/java/brooklyn/test/entity/LocalManagementContextForTests.java b/core/src/test/java/brooklyn/test/entity/LocalManagementContextForTests.java index c4d7cc821f..5bc962befb 100644 --- a/core/src/test/java/brooklyn/test/entity/LocalManagementContextForTests.java +++ b/core/src/test/java/brooklyn/test/entity/LocalManagementContextForTests.java @@ -22,13 +22,29 @@ import brooklyn.config.BrooklynServerConfig; import brooklyn.management.internal.LocalManagementContext; -/** management context which forces an empty catalog to prevent scanning / interacting with local filesystem. - * TODO this class could also force standard properties - * TODO this should be more widely used in tests! */ +/** management context which allows disabling common time-consuming tasks. + * most instances have: + *
  • empty properties + *
  • no catalog + *
  • persistence off + *
  • osgi off + *

    + * the constructor, {@link #newInstance()}, and {@link #builder(boolean)} (with true) return the above; + * the constructor and the builder allow custom properties to be set, + * and the builder allows individual items to be turned back on. + */ public class LocalManagementContextForTests extends LocalManagementContext { + protected LocalManagementContextForTests(BrooklynProperties brooklynProperties, boolean minimal) { + super(builder(minimal).useProperties(brooklynProperties).buildProperties()); + } + + public LocalManagementContextForTests() { + this(null); + } + public LocalManagementContextForTests(BrooklynProperties brooklynProperties) { - super(disablePersistentStoreBackup(emptyIfNull(setEmptyCatalogAsDefault(emptyIfNull(brooklynProperties))))); + this(brooklynProperties, true); } private static BrooklynProperties emptyIfNull(BrooklynProperties bp) { @@ -54,8 +70,73 @@ public static BrooklynProperties disablePersistentStoreBackup(BrooklynProperties return brooklynProperties; } - public LocalManagementContextForTests() { - this(null); + public static class Builder { + boolean disablePersistence = false; + boolean disableOsgi = false; + boolean emptyCatalog = false; + BrooklynProperties properties = null; + + public Builder disablePersistence() { return disablePersistence(true); } + public Builder disableOsgi() { return disableOsgi(true); } + public Builder emptyCatalog() { return emptyCatalog(true); } + + public Builder disablePersistence(boolean disablePersistence) { this.disablePersistence = disablePersistence; return this; } + public Builder disableOsgi(boolean disableOsgi) { this.disableOsgi = disableOsgi; return this; } + public Builder emptyCatalog(boolean emptyCatalog) { this.emptyCatalog = emptyCatalog; return this; } + + // for use in the outer class's constructor + private Builder minimal(boolean really) { + if (really) minimal(); + return this; + } + + public Builder minimal() { + disablePersistence(); + disableOsgi(); + emptyCatalog(); + properties = null; + return this; + } + + public Builder useProperties(BrooklynProperties properties) { + if (this.properties!=null && properties!=null) + throw new IllegalStateException("Cannot set multiple properties"); + this.properties = properties; + return this; + } + + public BrooklynProperties buildProperties() { + BrooklynProperties result = emptyIfNull(properties); + if (disablePersistence) LocalManagementContextForTests.disablePersistentStoreBackup(result); + if (disableOsgi) LocalManagementContextForTests.disableOsgi(result); + if (emptyCatalog) LocalManagementContextForTests.setEmptyCatalogAsDefault(result); + return result; + } + + public LocalManagementContext build() { + return new LocalManagementContextForTests(buildProperties(), false); + } + public Builder useDefaultProperties() { + properties = BrooklynProperties.Factory.newDefault(); + return this; + } } + /** create a new builder, defaulting to empty properties, and with the parameter determining whether + * by default to disable common things disabled in tests (and the caller can re-enable selected ones individually) + * or (if false) leaving everything enabled (so the caller turns things off) */ + public static Builder builder(boolean minimal) { return new Builder().minimal(minimal); } + + public static LocalManagementContext newInstance() { + return builder(true).build(); + } + + public static LocalManagementContext newInstance(BrooklynProperties properties) { + return builder(true).useProperties(properties).build(); + } + + public static LocalManagementContext newInstanceWithOsgi() { + return builder(true).disableOsgi(false).build(); + } + } diff --git a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java index 380e351269..bc2c45733a 100644 --- a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java +++ b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java @@ -93,7 +93,6 @@ import brooklyn.location.MachineManagementMixins.RichMachineProvisioningLocation; import brooklyn.location.NoMachinesAvailableException; import brooklyn.location.access.PortForwardManager; -import brooklyn.location.basic.AbstractLocation; import brooklyn.location.basic.BasicMachineMetadata; import brooklyn.location.basic.LocationConfigKeys; import brooklyn.location.basic.LocationConfigUtils; @@ -165,6 +164,7 @@ * For provisioning and managing VMs in a particular provider/region, using jclouds. * Configuration flags are defined in {@link JcloudsLocationConfig}. */ +@SuppressWarnings("serial") public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation implements JcloudsLocationConfig, RichMachineProvisioningLocation { // TODO After converting from Groovy to Java, this is now very bad code! It relies entirely on putting diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/AbstractJcloudsTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/AbstractJcloudsLiveTest.java similarity index 95% rename from locations/jclouds/src/test/java/brooklyn/location/jclouds/AbstractJcloudsTest.java rename to locations/jclouds/src/test/java/brooklyn/location/jclouds/AbstractJcloudsLiveTest.java index 713229dba0..0af5ad5374 100644 --- a/locations/jclouds/src/test/java/brooklyn/location/jclouds/AbstractJcloudsTest.java +++ b/locations/jclouds/src/test/java/brooklyn/location/jclouds/AbstractJcloudsLiveTest.java @@ -34,6 +34,7 @@ import brooklyn.entity.basic.Entities; import brooklyn.location.basic.SshMachineLocation; import brooklyn.management.internal.LocalManagementContext; +import brooklyn.test.entity.LocalManagementContextForTests; import brooklyn.util.exceptions.CompoundRuntimeException; import com.google.common.collect.ImmutableList; @@ -41,9 +42,9 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; -public class AbstractJcloudsTest { +public class AbstractJcloudsLiveTest { - private static final Logger LOG = LoggerFactory.getLogger(AbstractJcloudsTest.class); + private static final Logger LOG = LoggerFactory.getLogger(AbstractJcloudsLiveTest.class); public static final String BROOKLYN_PROPERTIES_PREFIX = "brooklyn.location.jclouds."; public static final String BROOKLYN_PROPERTIES_LEGACY_PREFIX = "brooklyn.jclouds."; @@ -107,7 +108,8 @@ public void tearDown() throws Exception { } protected LocalManagementContext newManagementContext() { - return new LocalManagementContext(); + // loads properties, by default, but not OSGi or anything else + return LocalManagementContextForTests.builder(true).useDefaultProperties().build(); } protected void stripBrooklynProperties(BrooklynProperties props) { diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverLiveTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverLiveTest.java new file mode 100644 index 0000000000..49e1faa789 --- /dev/null +++ b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverLiveTest.java @@ -0,0 +1,175 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package brooklyn.location.jclouds; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import java.net.InetAddress; +import java.util.Map; +import java.util.Set; + +import org.testng.annotations.Test; + +import brooklyn.location.basic.FixedListMachineProvisioningLocation; + +import com.google.common.collect.Iterables; + +public class JcloudsByonLocationResolverLiveTest extends AbstractJcloudsLiveTest { + + // FIXME Expects this VM to exist; how to write this better? + // We should create a VM in @BeforeClass - slower but automated and will work for everyone + private final String awsVm1User = "aled"; + private final String awsVm1InstanceId = "i-72b1b132"; + private final String awsVmIp = "54.195.164.70"; + private final String awsVmHostname = "ec2-54-195-164-70.eu-west-1.compute.amazonaws.com"; + + private final String slVmInstanceId = "4107756"; + private final String slVmIp = "81.95.147.234"; + private final String slVmHostname = "amp"; + + // TODO Requires that a VM already exists; could create that VM first to make test more robust + @Test(groups={"Live","WIP"}) + public void testResolvesJcloudsByonAws() throws Exception { + String spec = "jcloudsByon:(provider=\"aws-ec2\",region=\"eu-west-1\",user=\""+awsVm1User+"\",hosts=\""+awsVm1InstanceId+"\")"; + + FixedListMachineProvisioningLocation loc = resolve(spec); + + Set machines = loc.getAllMachines(); + JcloudsSshMachineLocation machine = Iterables.getOnlyElement(machines); + assertEquals(machine.getParent().getProvider(), "aws-ec2"); + assertEquals(machine.getAddress().getHostAddress(), awsVmIp); + assertEquals(machine.getAddress().getHostName(), awsVmHostname); + assertEquals(machine.getUser(), awsVm1User); + + assertTrue(machine.isSshable()); + } + + // TODO Requires that a VM already exists; could create that VM first to make test more robust + @Test(groups={"Live","WIP"}) + public void testResolvesNamedJcloudsByon() throws Exception { + String spec = "jcloudsByon:(provider=\"aws-ec2\",region=\"eu-west-1\",user=\""+awsVm1User+"\",hosts=\""+awsVm1InstanceId+"\")"; + brooklynProperties.put("brooklyn.location.named.mynamed", spec); + + FixedListMachineProvisioningLocation loc = resolve("named:mynamed"); + assertEquals(loc.obtain().getAddress(), InetAddress.getByName(awsVmHostname)); + } + + // TODO Requires that a VM already exists; could create that VM first to make test more robust + @Test(groups={"Live","WIP"}) + public void testJcloudsPropertiesPrecedence() throws Exception { + String spec = "jcloudsByon:(provider=\"aws-ec2\",region=\"eu-west-1\",user=\""+awsVm1User+"\",hosts=\""+awsVm1InstanceId+"\")"; + brooklynProperties.put("brooklyn.location.named.mynamed", spec); + + // prefer those in spec string over everything else + brooklynProperties.put("brooklyn.location.named.mynamed.user", "user-inNamed"); + brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.user", "user-inProviderSpecific"); + brooklynProperties.put("brooklyn.jclouds.aws-ec2.user", "user-inProviderSpecificDeprecated"); + brooklynProperties.put("brooklyn.location.jclouds.user", "user-inJcloudsGeneric"); + brooklynProperties.put("brooklyn.jclouds.user", "user-inJcloudsGenericDeprecated"); + brooklynProperties.put("brooklyn.location.user", "user-inLocationGeneric"); + + // prefer those in "named" over everything else (except spec string itself) + brooklynProperties.put("brooklyn.location.named.mynamed.privateKeyFile", "privateKeyFile-inNamed"); + brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.privateKeyFile", "privateKeyFile-inProviderSpecific"); + brooklynProperties.put("brooklyn.jclouds.aws-ec2.privateKeyFile", "privateKeyFile-inProviderSpecificDeprecated"); + brooklynProperties.put("brooklyn.location.jclouds.privateKeyFile", "privateKeyFile-inJcloudsGeneric"); + brooklynProperties.put("brooklyn.jclouds.privateKeyFile", "privateKeyFile-inJcloudsGenericDeprecated"); + brooklynProperties.put("brooklyn.location.privateKeyFile", "privateKeyFile-inLocationGeneric"); + + // prefer those in provider-specific over generic + brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.publicKeyFile", "publicKeyFile-inProviderSpecific"); + brooklynProperties.put("brooklyn.jclouds.aws-ec2.publicKeyFile", "publicKeyFile-inProviderSpecificDeprecated"); + brooklynProperties.put("brooklyn.location.jclouds.publicKeyFile", "publicKeyFile-inJcloudsGeneric"); + brooklynProperties.put("brooklyn.jclouds.publicKeyFile", "publicKeyFile-inJcloudsGenericDeprecated"); + brooklynProperties.put("brooklyn.location.publicKeyFile", "publicKeyFile-inLocationGeneric"); + + // prefer those in provider-specific (deprecated scope) over generic + brooklynProperties.put("brooklyn.jclouds.aws-ec2.securityGroups", "securityGroups-inProviderSpecificDeprecated"); + brooklynProperties.put("brooklyn.location.jclouds.securityGroups", "securityGroups-inJcloudsGeneric"); + brooklynProperties.put("brooklyn.jclouds.securityGroups", "securityGroups-inJcloudsGenericDeprecated"); + brooklynProperties.put("brooklyn.location.securityGroups", "securityGroups-inLocationGeneric"); + + // prefer those in jclouds-generic over location-generic + brooklynProperties.put("brooklyn.location.jclouds.loginUser", "loginUser-inJcloudsGeneric"); + brooklynProperties.put("brooklyn.jclouds.loginUser", "loginUser-inJcloudsGenericDeprecated"); + brooklynProperties.put("brooklyn.location.loginUser", "loginUser-inLocationGeneric"); + + // prefer those in jclouds-generic (deprecated) over location-generic + brooklynProperties.put("brooklyn.jclouds.imageId", "imageId-inJcloudsGenericDeprecated"); + brooklynProperties.put("brooklyn.location.imageId", "imageId-inLocationGeneric"); + + // prefer location-generic if nothing else + brooklynProperties.put("brooklyn.location.keyPair", "keyPair-inLocationGeneric"); + + // prefer deprecated properties in "named" over those less specific + brooklynProperties.put("brooklyn.location.named.mynamed.private-key-data", "privateKeyData-inNamed"); + brooklynProperties.put("brooklyn.jclouds.aws-ec2.privateKeyData", "privateKeyData-inProviderSpecific"); + brooklynProperties.put("brooklyn.jclouds.privateKeyData", "privateKeyData-inJcloudsGeneric"); + + // prefer "named" over everything else: confirm deprecated don't get transformed to overwrite it accidentally + brooklynProperties.put("brooklyn.location.named.mynamed.privateKeyPassphrase", "privateKeyPassphrase-inNamed"); + brooklynProperties.put("brooklyn.jclouds.aws-ec2.private-key-passphrase", "privateKeyPassphrase-inProviderSpecific"); + brooklynProperties.put("brooklyn.jclouds.private-key-passphrase", "privateKeyPassphrase-inJcloudsGeneric"); + + Map conf = resolve("named:mynamed").obtain().getAllConfig(true); + + assertEquals(conf.get("user"), awsVm1User); + assertEquals(conf.get("privateKeyFile"), "privateKeyFile-inNamed"); + assertEquals(conf.get("publicKeyFile"), "publicKeyFile-inProviderSpecific"); + assertEquals(conf.get("securityGroups"), "securityGroups-inProviderSpecificDeprecated"); + assertEquals(conf.get("loginUser"), "loginUser-inJcloudsGeneric"); + assertEquals(conf.get("imageId"), "imageId-inJcloudsGenericDeprecated"); + assertEquals(conf.get("keyPair"), "keyPair-inLocationGeneric"); + assertEquals(conf.get("privateKeyData"), "privateKeyData-inNamed"); + assertEquals(conf.get("privateKeyPassphrase"), "privateKeyPassphrase-inNamed"); + } + + // TODO Requires that a VM already exists; could create that VM first to make test more robust + @Test(groups={"Live","WIP"}) + public void testResolvesJcloudsByonSoftlayer() throws Exception { + checkSoftlayer("jcloudsByon:(provider=\"softlayer\",region=\"dal05\",hosts=\""+slVmInstanceId+"\")"); + checkSoftlayer("jcloudsByon:(provider=\"softlayer\",region=\"dal05\",hosts=\""+slVmHostname+"\")"); + checkSoftlayer("jcloudsByon:(provider=\"softlayer\",region=\"dal05\",hosts=\""+slVmIp+"\")"); + checkSoftlayer("jcloudsByon:(provider=\"softlayer\",hosts=\""+slVmIp+"\")"); + } + + private void checkSoftlayer(String spec) { + FixedListMachineProvisioningLocation loc = resolve(spec); + + Set machines = loc.getAllMachines(); + JcloudsSshMachineLocation machine = Iterables.getOnlyElement(machines); + assertEquals(machine.getParent().getProvider(), "softlayer"); + assertEquals(machine.getNode().getId(), slVmInstanceId); + assertEquals(machine.getAddress().getHostAddress(), slVmIp); + assertTrue(slVmHostname.equals(machine.getAddress().getHostName()) || slVmIp.equals(machine.getAddress().getHostName()), + "address hostname is: "+machine.getAddress().getHostName()); + assertTrue(slVmHostname.equals(machine.getNode().getHostname()) || slVmIp.equals(machine.getNode().getHostname()), + "node hostname is: "+machine.getNode().getHostname()); + + // could also assert this, given a user credential, but not currently set up +// assertTrue(machine.isSshable()); + } + + @SuppressWarnings("unchecked") + private FixedListMachineProvisioningLocation resolve(String spec) { + return (FixedListMachineProvisioningLocation) managementContext.getLocationRegistry().resolve(spec); + } + +} diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverTest.java index f01f365ac1..86e790f070 100644 --- a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverTest.java +++ b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverTest.java @@ -18,46 +18,33 @@ */ package brooklyn.location.jclouds; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; -import java.net.InetAddress; -import java.util.Map; import java.util.NoSuchElementException; -import java.util.Set; +import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import brooklyn.location.LocationRegistry; -import brooklyn.location.basic.BasicLocationRegistry; +import brooklyn.entity.basic.Entities; import brooklyn.location.basic.FixedListMachineProvisioningLocation; +import brooklyn.management.internal.LocalManagementContext; +import brooklyn.test.entity.LocalManagementContextForTests; -import com.google.common.collect.Iterables; +public class JcloudsByonLocationResolverTest { -public class JcloudsByonLocationResolverTest extends AbstractJcloudsTest { - - private LocationRegistry registry; - - // FIXME Expects this VM to exist; how to write this better? - // We should create a VM in @BeforeClass - slower but automated and will work for everyone - private final String awsVm1User = "aled"; - private final String awsVm1InstanceId = "i-72b1b132"; - private final String awsVmIp = "54.195.164.70"; - private final String awsVmHostname = "ec2-54-195-164-70.eu-west-1.compute.amazonaws.com"; - - private final String slVmInstanceId = "4107756"; - private final String slVmIp = "81.95.147.234"; - private final String slVmHostname = "amp"; + private LocalManagementContext managementContext; @BeforeMethod(alwaysRun=true) - @Override public void setUp() throws Exception { - super.setUp(); - registry = new BasicLocationRegistry(managementContext); + managementContext = LocalManagementContextForTests.newInstance(); } - + + @AfterMethod(alwaysRun=true) + public void tearDown() throws Exception { + if (managementContext != null) Entities.destroyAll(managementContext); + } + @Test public void testThrowsOnInvalid() throws Exception { assertThrowsNoSuchElement("wrongprefix:(hosts=\"1.1.1.1\")"); @@ -68,135 +55,10 @@ public void testThrowsOnInvalid() throws Exception { assertThrowsIllegalArgument("jcloudsByon:(hosts=\"1.1.1.1\", name)"); // no value for name assertThrowsIllegalArgument("jcloudsByon:(hosts=\"1.1.1.1\", name=)"); // no value for name } - - // TODO Requires that a VM already exists; could create that VM first to make test more robust - @Test(groups={"Live","WIP"}) - public void testResolvesJcloudsByonAws() throws Exception { - String spec = "jcloudsByon:(provider=\"aws-ec2\",region=\"eu-west-1\",user=\""+awsVm1User+"\",hosts=\""+awsVm1InstanceId+"\")"; - - FixedListMachineProvisioningLocation loc = resolve(spec); - - Set machines = loc.getAllMachines(); - JcloudsSshMachineLocation machine = Iterables.getOnlyElement(machines); - assertEquals(machine.getParent().getProvider(), "aws-ec2"); - assertEquals(machine.getAddress().getHostAddress(), awsVmIp); - assertEquals(machine.getAddress().getHostName(), awsVmHostname); - assertEquals(machine.getUser(), awsVm1User); - - assertTrue(machine.isSshable()); - } - - // TODO Requires that a VM already exists; could create that VM first to make test more robust - @Test(groups={"Live","WIP"}) - public void testResolvesNamedJcloudsByon() throws Exception { - String spec = "jcloudsByon:(provider=\"aws-ec2\",region=\"eu-west-1\",user=\""+awsVm1User+"\",hosts=\""+awsVm1InstanceId+"\")"; - brooklynProperties.put("brooklyn.location.named.mynamed", spec); - registry = new BasicLocationRegistry(managementContext); - - FixedListMachineProvisioningLocation loc = resolve("named:mynamed"); - assertEquals(loc.obtain().getAddress(), InetAddress.getByName(awsVmHostname)); - } - - // TODO Requires that a VM already exists; could create that VM first to make test more robust - @Test(groups={"Live","WIP"}) - public void testJcloudsPropertiesPrecedence() throws Exception { - String spec = "jcloudsByon:(provider=\"aws-ec2\",region=\"eu-west-1\",user=\""+awsVm1User+"\",hosts=\""+awsVm1InstanceId+"\")"; - brooklynProperties.put("brooklyn.location.named.mynamed", spec); - - // prefer those in spec string over everything else - brooklynProperties.put("brooklyn.location.named.mynamed.user", "user-inNamed"); - brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.user", "user-inProviderSpecific"); - brooklynProperties.put("brooklyn.jclouds.aws-ec2.user", "user-inProviderSpecificDeprecated"); - brooklynProperties.put("brooklyn.location.jclouds.user", "user-inJcloudsGeneric"); - brooklynProperties.put("brooklyn.jclouds.user", "user-inJcloudsGenericDeprecated"); - brooklynProperties.put("brooklyn.location.user", "user-inLocationGeneric"); - - // prefer those in "named" over everything else (except spec string itself) - brooklynProperties.put("brooklyn.location.named.mynamed.privateKeyFile", "privateKeyFile-inNamed"); - brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.privateKeyFile", "privateKeyFile-inProviderSpecific"); - brooklynProperties.put("brooklyn.jclouds.aws-ec2.privateKeyFile", "privateKeyFile-inProviderSpecificDeprecated"); - brooklynProperties.put("brooklyn.location.jclouds.privateKeyFile", "privateKeyFile-inJcloudsGeneric"); - brooklynProperties.put("brooklyn.jclouds.privateKeyFile", "privateKeyFile-inJcloudsGenericDeprecated"); - brooklynProperties.put("brooklyn.location.privateKeyFile", "privateKeyFile-inLocationGeneric"); - - // prefer those in provider-specific over generic - brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.publicKeyFile", "publicKeyFile-inProviderSpecific"); - brooklynProperties.put("brooklyn.jclouds.aws-ec2.publicKeyFile", "publicKeyFile-inProviderSpecificDeprecated"); - brooklynProperties.put("brooklyn.location.jclouds.publicKeyFile", "publicKeyFile-inJcloudsGeneric"); - brooklynProperties.put("brooklyn.jclouds.publicKeyFile", "publicKeyFile-inJcloudsGenericDeprecated"); - brooklynProperties.put("brooklyn.location.publicKeyFile", "publicKeyFile-inLocationGeneric"); - - // prefer those in provider-specific (deprecated scope) over generic - brooklynProperties.put("brooklyn.jclouds.aws-ec2.securityGroups", "securityGroups-inProviderSpecificDeprecated"); - brooklynProperties.put("brooklyn.location.jclouds.securityGroups", "securityGroups-inJcloudsGeneric"); - brooklynProperties.put("brooklyn.jclouds.securityGroups", "securityGroups-inJcloudsGenericDeprecated"); - brooklynProperties.put("brooklyn.location.securityGroups", "securityGroups-inLocationGeneric"); - - // prefer those in jclouds-generic over location-generic - brooklynProperties.put("brooklyn.location.jclouds.loginUser", "loginUser-inJcloudsGeneric"); - brooklynProperties.put("brooklyn.jclouds.loginUser", "loginUser-inJcloudsGenericDeprecated"); - brooklynProperties.put("brooklyn.location.loginUser", "loginUser-inLocationGeneric"); - - // prefer those in jclouds-generic (deprecated) over location-generic - brooklynProperties.put("brooklyn.jclouds.imageId", "imageId-inJcloudsGenericDeprecated"); - brooklynProperties.put("brooklyn.location.imageId", "imageId-inLocationGeneric"); - - // prefer location-generic if nothing else - brooklynProperties.put("brooklyn.location.keyPair", "keyPair-inLocationGeneric"); - - // prefer deprecated properties in "named" over those less specific - brooklynProperties.put("brooklyn.location.named.mynamed.private-key-data", "privateKeyData-inNamed"); - brooklynProperties.put("brooklyn.jclouds.aws-ec2.privateKeyData", "privateKeyData-inProviderSpecific"); - brooklynProperties.put("brooklyn.jclouds.privateKeyData", "privateKeyData-inJcloudsGeneric"); - - // prefer "named" over everything else: confirm deprecated don't get transformed to overwrite it accidentally - brooklynProperties.put("brooklyn.location.named.mynamed.privateKeyPassphrase", "privateKeyPassphrase-inNamed"); - brooklynProperties.put("brooklyn.jclouds.aws-ec2.private-key-passphrase", "privateKeyPassphrase-inProviderSpecific"); - brooklynProperties.put("brooklyn.jclouds.private-key-passphrase", "privateKeyPassphrase-inJcloudsGeneric"); - - registry = new BasicLocationRegistry(managementContext); - Map conf = resolve("named:mynamed").obtain().getAllConfig(true); - - assertEquals(conf.get("user"), awsVm1User); - assertEquals(conf.get("privateKeyFile"), "privateKeyFile-inNamed"); - assertEquals(conf.get("publicKeyFile"), "publicKeyFile-inProviderSpecific"); - assertEquals(conf.get("securityGroups"), "securityGroups-inProviderSpecificDeprecated"); - assertEquals(conf.get("loginUser"), "loginUser-inJcloudsGeneric"); - assertEquals(conf.get("imageId"), "imageId-inJcloudsGenericDeprecated"); - assertEquals(conf.get("keyPair"), "keyPair-inLocationGeneric"); - assertEquals(conf.get("privateKeyData"), "privateKeyData-inNamed"); - assertEquals(conf.get("privateKeyPassphrase"), "privateKeyPassphrase-inNamed"); - } - - // TODO Requires that a VM already exists; could create that VM first to make test more robust - @Test(groups={"Live","WIP"}) - public void testResolvesJcloudsByonSoftlayer() throws Exception { - checkSoftlayer("jcloudsByon:(provider=\"softlayer\",region=\"dal05\",hosts=\""+slVmInstanceId+"\")"); - checkSoftlayer("jcloudsByon:(provider=\"softlayer\",region=\"dal05\",hosts=\""+slVmHostname+"\")"); - checkSoftlayer("jcloudsByon:(provider=\"softlayer\",region=\"dal05\",hosts=\""+slVmIp+"\")"); - checkSoftlayer("jcloudsByon:(provider=\"softlayer\",hosts=\""+slVmIp+"\")"); - } - - private void checkSoftlayer(String spec) { - FixedListMachineProvisioningLocation loc = resolve(spec); - - Set machines = loc.getAllMachines(); - JcloudsSshMachineLocation machine = Iterables.getOnlyElement(machines); - assertEquals(machine.getParent().getProvider(), "softlayer"); - assertEquals(machine.getNode().getId(), slVmInstanceId); - assertEquals(machine.getAddress().getHostAddress(), slVmIp); - assertTrue(slVmHostname.equals(machine.getAddress().getHostName()) || slVmIp.equals(machine.getAddress().getHostName()), - "address hostname is: "+machine.getAddress().getHostName()); - assertTrue(slVmHostname.equals(machine.getNode().getHostname()) || slVmIp.equals(machine.getNode().getHostname()), - "node hostname is: "+machine.getNode().getHostname()); - - // could also assert this, given a user credential, but not currently set up -// assertTrue(machine.isSshable()); - } @SuppressWarnings("unchecked") private FixedListMachineProvisioningLocation resolve(String spec) { - return (FixedListMachineProvisioningLocation) registry.resolve(spec); + return (FixedListMachineProvisioningLocation) managementContext.getLocationRegistry().resolve(spec); } private void assertThrowsNoSuchElement(String val) { diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationMetadataTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationMetadataTest.java index 56e4d1c2dd..e5ebfab504 100644 --- a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationMetadataTest.java +++ b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationMetadataTest.java @@ -29,6 +29,7 @@ import brooklyn.location.Location; import brooklyn.location.basic.LocationConfigKeys; import brooklyn.management.internal.LocalManagementContext; +import brooklyn.test.entity.LocalManagementContextForTests; import com.google.common.collect.ImmutableSet; @@ -42,7 +43,7 @@ public class JcloudsLocationMetadataTest implements JcloudsLocationConfig { @BeforeMethod(alwaysRun=true) public void setUp() throws Exception { - managementContext = new LocalManagementContext(); + managementContext = LocalManagementContextForTests.newInstance(BrooklynProperties.Factory.builderEmpty().build()); brooklynProperties = managementContext.getBrooklynProperties(); } diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationRebindMachineLiveTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationRebindMachineLiveTest.java index a0a4989af7..7ec58cf211 100644 --- a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationRebindMachineLiveTest.java +++ b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationRebindMachineLiveTest.java @@ -36,7 +36,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -public class JcloudsLocationRebindMachineLiveTest extends AbstractJcloudsTest { +public class JcloudsLocationRebindMachineLiveTest extends AbstractJcloudsLiveTest { private static final Logger LOG = LoggerFactory.getLogger(JcloudsLocationRebindMachineLiveTest.class); @@ -71,6 +71,7 @@ public void testRebindVm() throws Exception { // Create a VM through jclouds JcloudsSshMachineLocation machine = obtainMachine(ImmutableMap.of("imageId", EUWEST_IMAGE_ID, "imageOwner", IMAGE_OWNER)); assertTrue(machine.isSshable()); + LOG.info("obtained "+machine); String id = checkNotNull(machine.getJcloudsId(), "id"); InetAddress address = checkNotNull(machine.getAddress(), "address"); @@ -81,6 +82,8 @@ public void testRebindVm() throws Exception { JcloudsLocation loc2 = (JcloudsLocation) managementContext.getLocationRegistry().resolve(AWS_EC2_PROVIDER+":"+AWS_EC2_EUWEST_REGION_NAME); SshMachineLocation machine2 = loc2.rebindMachine(ImmutableMap.of("id", id, "hostname", hostname, "user", user)); + LOG.info("rebinded to "+machine2); + // Confirm the re-bound machine is wired up assertTrue(machine2.isSshable()); assertEquals(ImmutableSet.copyOf(loc2.getChildren()), ImmutableSet.of(machine2)); diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationResolverTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationResolverTest.java index 5533b8aeef..92b09d19f7 100644 --- a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationResolverTest.java +++ b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationResolverTest.java @@ -34,6 +34,7 @@ import brooklyn.config.BrooklynProperties; import brooklyn.location.cloud.CloudLocationConfig; import brooklyn.management.internal.LocalManagementContext; +import brooklyn.test.entity.LocalManagementContextForTests; public class JcloudsLocationResolverTest { @@ -45,7 +46,7 @@ public class JcloudsLocationResolverTest { @BeforeMethod(alwaysRun = true) public void setUp() throws Exception { - managementContext = new LocalManagementContext(BrooklynProperties.Factory.newEmpty()); + managementContext = LocalManagementContextForTests.newInstance(); brooklynProperties = managementContext.getBrooklynProperties(); brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.identity", "aws-ec2-id"); diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationTest.java index 24fde389bb..b41f24e5ff 100644 --- a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationTest.java +++ b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationTest.java @@ -46,6 +46,7 @@ import brooklyn.location.geo.HostGeoInfo; import brooklyn.management.internal.LocalManagementContext; import brooklyn.test.Asserts; +import brooklyn.test.entity.LocalManagementContextForTests; import brooklyn.util.collections.MutableMap; import brooklyn.util.config.ConfigBag; import brooklyn.util.exceptions.CompoundRuntimeException; @@ -71,6 +72,7 @@ public class JcloudsLocationTest implements JcloudsLocationConfig { public static final RuntimeException BAIL_OUT_FOR_TESTING = new RuntimeException("early termination for test"); + @SuppressWarnings("serial") public static class BailOutJcloudsLocation extends JcloudsLocation { public static final ConfigKey> BUILD_TEMPLATE_INTERCEPTOR = ConfigKeys.newConfigKey(new TypeToken>() {}, "buildtemplateinterceptor"); @@ -104,6 +106,7 @@ protected void tryObtainAndCheck(Map flags, Predicate te } } + @SuppressWarnings("serial") public static class CountingBailOutJcloudsLocation extends BailOutJcloudsLocation { int buildTemplateCount = 0; @Override @@ -113,6 +116,7 @@ public Template buildTemplate(ComputeService computeService, ConfigBag config) { } } + @SuppressWarnings("serial") public static class BailOutWithTemplateJcloudsLocation extends JcloudsLocation { ConfigBag lastConfigBag; Template template; @@ -154,6 +158,7 @@ protected BailOutJcloudsLocation newSampleBailOutJcloudsLocationForTesting() { return newSampleBailOutJcloudsLocationForTesting(ImmutableMap.,Object>of()); } + @SuppressWarnings({ "unchecked", "rawtypes" }) protected BailOutJcloudsLocation newSampleBailOutJcloudsLocationForTesting(Map config) { Map,?> allConfig = MutableMap.,Object>builder() .put(IMAGE_ID, "bogus") @@ -174,6 +179,7 @@ protected BailOutWithTemplateJcloudsLocation newSampleBailOutWithTemplateJclouds return newSampleBailOutWithTemplateJcloudsLocation(ImmutableMap.,Object>of()); } + @SuppressWarnings({ "unchecked", "rawtypes" }) protected BailOutWithTemplateJcloudsLocation newSampleBailOutWithTemplateJcloudsLocation(Map config) { String identity = (String) brooklynProperties.get("brooklyn.location.jclouds.aws-ec2.identity"); if (identity == null) identity = (String) brooklynProperties.get("brooklyn.jclouds.aws-ec2.identity"); @@ -181,8 +187,8 @@ protected BailOutWithTemplateJcloudsLocation newSampleBailOutWithTemplateJclouds if (credential == null) credential = (String) brooklynProperties.get("brooklyn.jclouds.aws-ec2.credential"); Map,?> allConfig = MutableMap.,Object>builder() - .put(CLOUD_PROVIDER, AbstractJcloudsTest.AWS_EC2_PROVIDER) - .put(CLOUD_REGION_ID, AbstractJcloudsTest.AWS_EC2_USEAST_REGION_NAME) + .put(CLOUD_PROVIDER, AbstractJcloudsLiveTest.AWS_EC2_PROVIDER) + .put(CLOUD_REGION_ID, AbstractJcloudsLiveTest.AWS_EC2_USEAST_REGION_NAME) .put(IMAGE_ID, US_EAST_IMAGE_ID) // so it runs faster, without loading all EC2 images .put(ACCESS_IDENTITY, identity) .put(ACCESS_CREDENTIAL, credential) @@ -222,7 +228,7 @@ public boolean apply(@Nullable ConfigBag input) { @BeforeMethod(alwaysRun=true) public void setUp() throws Exception { - managementContext = new LocalManagementContext(); + managementContext = LocalManagementContextForTests.newInstance(BrooklynProperties.Factory.builderEmpty().build()); brooklynProperties = managementContext.getBrooklynProperties(); } @@ -479,6 +485,7 @@ public void assertCallCountContinually(final int expected) { } + @SuppressWarnings("serial") public static class FakeLocalhostWithParentJcloudsLocation extends JcloudsLocation { public static final ConfigKey> BUILD_TEMPLATE_INTERCEPTOR = ConfigKeys.newConfigKey(new TypeToken>() {}, "buildtemplateinterceptor"); @@ -522,6 +529,7 @@ public void testInheritsGeo() throws Exception { Assert.assertEquals(geo.longitude, -20d, 0.00001); } + @SuppressWarnings("unchecked") @Test public void testInheritsGeoFromLocationMetadataProperties() throws Exception { // in location-metadata.properties: diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLoginLiveTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLoginLiveTest.java index 5a5084d1ac..3cc3efe259 100644 --- a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLoginLiveTest.java +++ b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLoginLiveTest.java @@ -39,7 +39,7 @@ /** * Tests different login options for ssh keys, passwords, etc. */ -public class JcloudsLoginLiveTest extends AbstractJcloudsTest { +public class JcloudsLoginLiveTest extends AbstractJcloudsLiveTest { private static final Logger LOG = LoggerFactory.getLogger(JcloudsLoginLiveTest.class); diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsMinRamLiveTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsMinRamLiveTest.java index ca66d75e75..ee072f2236 100644 --- a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsMinRamLiveTest.java +++ b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsMinRamLiveTest.java @@ -26,7 +26,7 @@ import com.google.common.collect.ImmutableMap; -public class JcloudsMinRamLiveTest extends AbstractJcloudsTest { +public class JcloudsMinRamLiveTest extends AbstractJcloudsLiveTest { private static final Logger log = LoggerFactory.getLogger(JcloudsMinRamLiveTest.class); diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/LiveTestEntity.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/LiveTestEntity.java index b9e0dff243..feb4aca4df 100644 --- a/locations/jclouds/src/test/java/brooklyn/location/jclouds/LiveTestEntity.java +++ b/locations/jclouds/src/test/java/brooklyn/location/jclouds/LiveTestEntity.java @@ -23,24 +23,23 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Predicates; -import com.google.common.base.Throwables; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; - import brooklyn.entity.basic.Lifecycle; import brooklyn.entity.proxying.ImplementedBy; import brooklyn.location.Location; -import brooklyn.location.MachineLocation; import brooklyn.location.MachineProvisioningLocation; import brooklyn.location.NoMachinesAvailableException; import brooklyn.test.entity.TestEntity; import brooklyn.test.entity.TestEntityImpl; +import com.google.common.base.Predicates; +import com.google.common.base.Throwables; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Iterables; + @ImplementedBy(LiveTestEntity.LiveTestEntityImpl.class) public interface LiveTestEntity extends TestEntity { - MachineProvisioningLocation getProvisioningLocation(); + MachineProvisioningLocation getProvisioningLocation(); JcloudsSshMachineLocation getObtainedLocation(); public static class LiveTestEntityImpl extends TestEntityImpl implements LiveTestEntity { @@ -78,7 +77,7 @@ public void stop() { setAttribute(SERVICE_STATE, Lifecycle.STOPPED); } - public MachineProvisioningLocation getProvisioningLocation() { + public MachineProvisioningLocation getProvisioningLocation() { return provisioningLocation; } diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/RebindJcloudsLocationLiveTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/RebindJcloudsLocationLiveTest.java index 955b70e411..14aa1faf64 100644 --- a/locations/jclouds/src/test/java/brooklyn/location/jclouds/RebindJcloudsLocationLiveTest.java +++ b/locations/jclouds/src/test/java/brooklyn/location/jclouds/RebindJcloudsLocationLiveTest.java @@ -23,29 +23,26 @@ import static org.testng.Assert.assertTrue; import java.io.File; -import java.util.List; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import com.google.common.base.Predicates; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; -import com.google.common.io.Files; - import brooklyn.entity.basic.ApplicationBuilder; import brooklyn.entity.basic.Entities; import brooklyn.entity.proxying.EntitySpec; import brooklyn.entity.rebind.RebindTestUtils; -import brooklyn.location.MachineLocation; import brooklyn.location.OsDetails; import brooklyn.management.internal.LocalManagementContext; import brooklyn.test.entity.TestApplication; -import brooklyn.util.collections.MutableMap; import brooklyn.util.config.ConfigBag; -public class RebindJcloudsLocationLiveTest extends AbstractJcloudsTest { +import com.google.common.base.Predicates; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Iterables; +import com.google.common.io.Files; + +public class RebindJcloudsLocationLiveTest extends AbstractJcloudsLiveTest { public static final String AWS_EC2_REGION_NAME = AWS_EC2_USEAST_REGION_NAME; public static final String AWS_EC2_LOCATION_SPEC = "jclouds:" + AWS_EC2_PROVIDER + ":" + AWS_EC2_REGION_NAME; @@ -132,17 +129,18 @@ private void assertJcloudsLocationEquals(JcloudsLocation actual, JcloudsLocation } private void assertConfigBagEquals(ConfigBag actual, ConfigBag expected, String errmsg) { - // TODO Can we include all of these things (e.g. when locations are entities, so flagged fields not treated special)? - List configToIgnore = ImmutableList.of("id", "template", "usedPorts", "machineCreationSemaphore", "config"); - MutableMap actualMap = MutableMap.builder().putAll(actual.getAllConfig()) - .removeAll(configToIgnore) - .build(); - MutableMap expectedMap = MutableMap.builder().putAll(expected.getAllConfig()) - .removeAll(configToIgnore) - .build(); - // TODO revisit the strong assertion that configBags are equal - //assertEquals(actualMap, expectedMap, errmsg+"; actualBag="+actualMap+"; expectedBag="+expectedMap); + +// // TODO Can we include all of these things (e.g. when locations are entities, so flagged fields not treated special)? +// List configToIgnore = ImmutableList.of("id", "template", "usedPorts", "machineCreationSemaphore", "config"); +// MutableMap actualMap = MutableMap.builder().putAll(actual.getAllConfig()) +// .removeAll(configToIgnore) +// .build(); +// MutableMap expectedMap = MutableMap.builder().putAll(expected.getAllConfig()) +// .removeAll(configToIgnore) +// .build(); +// +// assertEquals(actualMap, expectedMap, errmsg+"; actualBag="+actualMap+"; expectedBag="+expectedMap); } private TestApplication rebind() throws Exception { diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/SimpleJcloudsLocationUserLoginAndConfigLiveTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/SimpleJcloudsLocationUserLoginAndConfigLiveTest.java index e5a79986f3..193f10848e 100644 --- a/locations/jclouds/src/test/java/brooklyn/location/jclouds/SimpleJcloudsLocationUserLoginAndConfigLiveTest.java +++ b/locations/jclouds/src/test/java/brooklyn/location/jclouds/SimpleJcloudsLocationUserLoginAndConfigLiveTest.java @@ -20,7 +20,6 @@ import java.io.ByteArrayOutputStream; import java.util.Arrays; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -40,7 +39,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; -public class SimpleJcloudsLocationUserLoginAndConfigLiveTest extends AbstractJcloudsTest { +public class SimpleJcloudsLocationUserLoginAndConfigLiveTest extends AbstractJcloudsLiveTest { // FIXME And tidy up this one diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/SingleMachineProvisioningLocationJcloudsLiveTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/SingleMachineProvisioningLocationJcloudsLiveTest.java index e088da49ad..a40660a8c2 100644 --- a/locations/jclouds/src/test/java/brooklyn/location/jclouds/SingleMachineProvisioningLocationJcloudsLiveTest.java +++ b/locations/jclouds/src/test/java/brooklyn/location/jclouds/SingleMachineProvisioningLocationJcloudsLiveTest.java @@ -34,7 +34,7 @@ import brooklyn.location.MachineLocation; import brooklyn.location.basic.SingleMachineProvisioningLocation; -public class SingleMachineProvisioningLocationJcloudsLiveTest extends AbstractJcloudsTest { +public class SingleMachineProvisioningLocationJcloudsLiveTest extends AbstractJcloudsLiveTest { private static final Logger log = LoggerFactory.getLogger(SingleMachineProvisioningLocation.class); private SingleMachineProvisioningLocation location; diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/StandaloneJcloudsLiveTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/StandaloneJcloudsLiveTest.java index 30f887da98..d8b39156e0 100644 --- a/locations/jclouds/src/test/java/brooklyn/location/jclouds/StandaloneJcloudsLiveTest.java +++ b/locations/jclouds/src/test/java/brooklyn/location/jclouds/StandaloneJcloudsLiveTest.java @@ -64,8 +64,8 @@ public class StandaloneJcloudsLiveTest { public static final Logger LOG = LoggerFactory.getLogger(StandaloneJcloudsLiveTest.class); - private static final String PROVIDER = AbstractJcloudsTest.AWS_EC2_PROVIDER; - private static final String REGION = AbstractJcloudsTest.AWS_EC2_USEAST_REGION_NAME; + private static final String PROVIDER = AbstractJcloudsLiveTest.AWS_EC2_PROVIDER; + private static final String REGION = AbstractJcloudsLiveTest.AWS_EC2_USEAST_REGION_NAME; private static final String PRIVATE_IMAGE_ID = "us-east-1/ami-f95cf390"; static BrooklynProperties globals = BrooklynProperties.Factory.newDefault(); diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/networking/JcloudsPortForwardingLiveTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/networking/JcloudsPortForwardingLiveTest.java index c8f4c4b9e5..c9d83933e4 100644 --- a/locations/jclouds/src/test/java/brooklyn/location/jclouds/networking/JcloudsPortForwardingLiveTest.java +++ b/locations/jclouds/src/test/java/brooklyn/location/jclouds/networking/JcloudsPortForwardingLiveTest.java @@ -30,7 +30,7 @@ import org.testng.annotations.Test; import brooklyn.config.ConfigKey; -import brooklyn.location.jclouds.AbstractJcloudsTest; +import brooklyn.location.jclouds.AbstractJcloudsLiveTest; import brooklyn.location.jclouds.JcloudsLocation; import brooklyn.location.jclouds.JcloudsSshMachineLocation; import brooklyn.location.jclouds.networking.JcloudsPortForwarderExtension; @@ -48,7 +48,7 @@ /** * Tests different login options for ssh keys, passwords, etc. */ -public class JcloudsPortForwardingLiveTest extends AbstractJcloudsTest { +public class JcloudsPortForwardingLiveTest extends AbstractJcloudsLiveTest { private static final Logger LOG = LoggerFactory.getLogger(JcloudsPortForwardingLiveTest.class); diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/pool/JcloudsMachinePoolLiveTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/pool/JcloudsMachinePoolLiveTest.java index db126cacc4..4a08217dfe 100644 --- a/locations/jclouds/src/test/java/brooklyn/location/jclouds/pool/JcloudsMachinePoolLiveTest.java +++ b/locations/jclouds/src/test/java/brooklyn/location/jclouds/pool/JcloudsMachinePoolLiveTest.java @@ -32,10 +32,10 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import brooklyn.location.jclouds.AbstractJcloudsTest; +import brooklyn.location.jclouds.AbstractJcloudsLiveTest; import brooklyn.location.jclouds.JcloudsLocation; -public class JcloudsMachinePoolLiveTest extends AbstractJcloudsTest { +public class JcloudsMachinePoolLiveTest extends AbstractJcloudsLiveTest { public static final Logger log = LoggerFactory.getLogger(JcloudsMachinePoolLiveTest.class); diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/zone/AwsAvailabilityZoneExtensionTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/zone/AwsAvailabilityZoneExtensionTest.java index 19336792f2..19804e52cd 100644 --- a/locations/jclouds/src/test/java/brooklyn/location/jclouds/zone/AwsAvailabilityZoneExtensionTest.java +++ b/locations/jclouds/src/test/java/brooklyn/location/jclouds/zone/AwsAvailabilityZoneExtensionTest.java @@ -30,7 +30,7 @@ import brooklyn.entity.basic.Entities; import brooklyn.location.Location; -import brooklyn.location.jclouds.AbstractJcloudsTest; +import brooklyn.location.jclouds.AbstractJcloudsLiveTest; import brooklyn.location.jclouds.JcloudsLocation; import brooklyn.location.jclouds.JcloudsSshMachineLocation; import brooklyn.management.internal.LocalManagementContext; @@ -43,10 +43,10 @@ public class AwsAvailabilityZoneExtensionTest { - public static final String PROVIDER = AbstractJcloudsTest.AWS_EC2_PROVIDER; - public static final String REGION_NAME = AbstractJcloudsTest.AWS_EC2_USEAST_REGION_NAME; + public static final String PROVIDER = AbstractJcloudsLiveTest.AWS_EC2_PROVIDER; + public static final String REGION_NAME = AbstractJcloudsLiveTest.AWS_EC2_USEAST_REGION_NAME; public static final String LOCATION_SPEC = PROVIDER + (REGION_NAME == null ? "" : ":" + REGION_NAME); - public static final String SMALL_HARDWARE_ID = AbstractJcloudsTest.AWS_EC2_SMALL_HARDWARE_ID; + public static final String SMALL_HARDWARE_ID = AbstractJcloudsLiveTest.AWS_EC2_SMALL_HARDWARE_ID; public static final String US_EAST_IMAGE_ID = "us-east-1/ami-7d7bfc14"; // centos 6.3 diff --git a/policy/src/test/java/brooklyn/entity/brooklyn/BrooklynMetricsTest.java b/policy/src/test/java/brooklyn/entity/brooklyn/BrooklynMetricsTest.java index 1e8b314b9c..39be9d4107 100644 --- a/policy/src/test/java/brooklyn/entity/brooklyn/BrooklynMetricsTest.java +++ b/policy/src/test/java/brooklyn/entity/brooklyn/BrooklynMetricsTest.java @@ -33,6 +33,7 @@ import brooklyn.event.SensorEventListener; import brooklyn.location.basic.SimulatedLocation; import brooklyn.test.Asserts; +import brooklyn.test.entity.LocalManagementContextForTests; import brooklyn.test.entity.TestApplication; import brooklyn.test.entity.TestEntity; @@ -49,7 +50,7 @@ public class BrooklynMetricsTest { @BeforeMethod(alwaysRun=true) public void setUp() { loc = new SimulatedLocation(); - app = ApplicationBuilder.newManagedApp(TestApplication.class); + app = TestApplication.Factory.newManagedInstanceForTests(); brooklynMetrics = app.createAndManageChild(EntitySpec.create(BrooklynMetrics.class).configure("updatePeriod", 10L)); Entities.manage(brooklynMetrics); } @@ -90,7 +91,6 @@ public void run() { final long tasksSubmitted = getAttribute(brooklynMetrics, BrooklynMetrics.TOTAL_TASKS_SUBMITTED, 0); final long eventsPublished = getAttribute(brooklynMetrics, BrooklynMetrics.TOTAL_EVENTS_PUBLISHED, 0); final long eventsDelivered = getAttribute(brooklynMetrics, BrooklynMetrics.TOTAL_EVENTS_DELIVERED, 0); - final long subscriptions = getAttribute(brooklynMetrics, BrooklynMetrics.NUM_SUBSCRIPTIONS, 0); // Invoking an effector increments effector/task count e.myEffector(); diff --git a/software/base/src/test/java/brooklyn/entity/basic/SameServerEntityTest.java b/software/base/src/test/java/brooklyn/entity/basic/SameServerEntityTest.java index 84d126601c..97b21635a8 100644 --- a/software/base/src/test/java/brooklyn/entity/basic/SameServerEntityTest.java +++ b/software/base/src/test/java/brooklyn/entity/basic/SameServerEntityTest.java @@ -49,7 +49,7 @@ public class SameServerEntityTest { @BeforeMethod(alwaysRun=true) public void setUp() { loc = new LocalhostMachineProvisioningLocation(); - app = ApplicationBuilder.newManagedApp(TestApplication.class); + app = TestApplication.Factory.newManagedInstanceForTests(); mgmt = app.getManagementContext(); entity = app.createAndManageChild(EntitySpec.create(SameServerEntity.class)); } diff --git a/software/base/src/test/java/brooklyn/entity/basic/VanillaSoftwareProcessAndChildrenIntegrationTest.java b/software/base/src/test/java/brooklyn/entity/basic/VanillaSoftwareProcessAndChildrenIntegrationTest.java index 70568740ce..37f569a665 100644 --- a/software/base/src/test/java/brooklyn/entity/basic/VanillaSoftwareProcessAndChildrenIntegrationTest.java +++ b/software/base/src/test/java/brooklyn/entity/basic/VanillaSoftwareProcessAndChildrenIntegrationTest.java @@ -67,7 +67,7 @@ public class VanillaSoftwareProcessAndChildrenIntegrationTest { @BeforeMethod(alwaysRun=true) public void setup() { - app = ApplicationBuilder.newManagedApp(TestApplication.class); + app = TestApplication.Factory.newManagedInstanceForTests(); localhost = app.getManagementContext().getLocationRegistry().resolve("localhost"); } diff --git a/software/base/src/test/java/brooklyn/entity/software/SoftwareEffectorTest.java b/software/base/src/test/java/brooklyn/entity/software/SoftwareEffectorTest.java index 0c8f2b53b1..6558b3cc7a 100644 --- a/software/base/src/test/java/brooklyn/entity/software/SoftwareEffectorTest.java +++ b/software/base/src/test/java/brooklyn/entity/software/SoftwareEffectorTest.java @@ -28,7 +28,6 @@ import org.testng.annotations.Test; import brooklyn.entity.Effector; -import brooklyn.entity.basic.ApplicationBuilder; import brooklyn.entity.basic.Entities; import brooklyn.entity.effector.Effectors; import brooklyn.entity.software.SshEffectorTasks.SshEffectorBody; @@ -52,7 +51,7 @@ public class SoftwareEffectorTest { @BeforeMethod(alwaysRun=true) public void setup() throws Exception { - app = ApplicationBuilder.newManagedApp(TestApplication.class); + app = TestApplication.Factory.newManagedInstanceForTests(); mgmt = app.getManagementContext(); LocalhostMachineProvisioningLocation lhc = mgmt.getLocationManager().createLocation(LocationSpec.create(LocalhostMachineProvisioningLocation.class)); diff --git a/software/base/src/test/java/brooklyn/entity/software/SshEffectorTasksTest.java b/software/base/src/test/java/brooklyn/entity/software/SshEffectorTasksTest.java index aa25a9d041..b922733a51 100644 --- a/software/base/src/test/java/brooklyn/entity/software/SshEffectorTasksTest.java +++ b/software/base/src/test/java/brooklyn/entity/software/SshEffectorTasksTest.java @@ -60,7 +60,7 @@ public class SshEffectorTasksTest { @BeforeMethod(alwaysRun=true) public void setup() throws Exception { - app = ApplicationBuilder.newManagedApp(TestApplication.class); + app = TestApplication.Factory.newManagedInstanceForTests(); mgmt = app.getManagementContext(); LocalhostMachineProvisioningLocation lhc = mgmt.getLocationManager().createLocation(LocationSpec.create(LocalhostMachineProvisioningLocation.class)); diff --git a/software/base/src/test/java/brooklyn/entity/software/ssh/SshCommandIntegrationTest.java b/software/base/src/test/java/brooklyn/entity/software/ssh/SshCommandIntegrationTest.java index 3a4949231d..09af6c21ed 100644 --- a/software/base/src/test/java/brooklyn/entity/software/ssh/SshCommandIntegrationTest.java +++ b/software/base/src/test/java/brooklyn/entity/software/ssh/SshCommandIntegrationTest.java @@ -28,7 +28,6 @@ import org.testng.annotations.Test; import brooklyn.entity.Effector; -import brooklyn.entity.basic.ApplicationBuilder; import brooklyn.entity.basic.Attributes; import brooklyn.entity.basic.Entities; import brooklyn.entity.basic.EntityLocal; @@ -56,7 +55,7 @@ public class SshCommandIntegrationTest { @BeforeMethod(alwaysRun=true) public void setUp() throws Exception { - app = ApplicationBuilder.newManagedApp(TestApplication.class); + app = TestApplication.Factory.newManagedInstanceForTests(); entity = app.createAndManageChild(EntitySpec.create(TestEntity.class).location(app.newLocalhostProvisioningLocation().obtain())); app.start(ImmutableList.of()); } diff --git a/software/base/src/test/java/brooklyn/event/feed/jmx/JmxFeedTest.java b/software/base/src/test/java/brooklyn/event/feed/jmx/JmxFeedTest.java index 00fd235d9f..9b8c9169cd 100644 --- a/software/base/src/test/java/brooklyn/event/feed/jmx/JmxFeedTest.java +++ b/software/base/src/test/java/brooklyn/event/feed/jmx/JmxFeedTest.java @@ -131,7 +131,7 @@ public void setUp() throws Exception { jmxObjectName = new ObjectName(objectName); // Create an entity and configure it with the above JMX service - app = ApplicationBuilder.newManagedApp(TestApplication.class); + app = TestApplication.Factory.newManagedInstanceForTests(); entity = app.createAndManageChild(EntitySpec.create(TestEntity.class).impl(TestEntityWithJmx.class)); app.start(ImmutableList.of(new SimulatedLocation())); diff --git a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/AbstractYamlTest.java b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/AbstractYamlTest.java index beb012945f..d9186a3be0 100644 --- a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/AbstractYamlTest.java +++ b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/AbstractYamlTest.java @@ -25,14 +25,11 @@ import java.io.StringReader; import java.util.Set; -import org.codehaus.groovy.util.StringUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; -import com.google.common.base.Joiner; - import brooklyn.entity.Entity; import brooklyn.entity.basic.BrooklynTaskTags; import brooklyn.entity.basic.Entities; @@ -42,6 +39,8 @@ import brooklyn.test.entity.LocalManagementContextForTests; import brooklyn.util.ResourceUtils; +import com.google.common.base.Joiner; + public abstract class AbstractYamlTest { private static final Logger LOG = LoggerFactory.getLogger(AbstractYamlTest.class); @@ -70,7 +69,8 @@ protected LocalManagementContext newMgmtContext() { } protected LocalManagementContext newTestManagementContext() { - return new LocalManagementContextForTests(); + // TODO they don't all need osgi, just a few do, so could speed it up by specifying when they do + return LocalManagementContextForTests.newInstanceWithOsgi(); } @AfterMethod(alwaysRun = true) From c4ecdb271a7dfe3b656644f7be53348d252c796b Mon Sep 17 00:00:00 2001 From: Alex Heneveld Date: Thu, 7 Aug 2014 19:55:48 -0400 Subject: [PATCH 4/8] fix ha split brain test problem, and better logging for ha --- .../ha/HighAvailabilityManagerImpl.java | 26 +++++++--- ...HighAvailabilityManagerSplitBrainTest.java | 49 ++++++++++++------- 2 files changed, 51 insertions(+), 24 deletions(-) diff --git a/core/src/main/java/brooklyn/management/ha/HighAvailabilityManagerImpl.java b/core/src/main/java/brooklyn/management/ha/HighAvailabilityManagerImpl.java index c205ebe020..e92a171d92 100644 --- a/core/src/main/java/brooklyn/management/ha/HighAvailabilityManagerImpl.java +++ b/core/src/main/java/brooklyn/management/ha/HighAvailabilityManagerImpl.java @@ -142,8 +142,10 @@ public ManagementPlaneSyncRecordPersister getPersister() { public HighAvailabilityManagerImpl setPollPeriod(Duration val) { this.pollPeriod = checkNotNull(val, "pollPeriod"); - if (running && pollingTask != null) { - pollingTask.cancel(true); + if (running) { + if (pollingTask!=null) { + pollingTask.cancel(true); + } registerPollTask(); } return this; @@ -244,6 +246,7 @@ public void start(HighAvailabilityMode startMode) { @Override public void stop() { + LOG.debug("Stopping "+this); boolean wasRunning = running; // ensure idempotent running = false; @@ -294,6 +297,7 @@ protected void registerPollTask() { } }; + LOG.debug("Registering poll task for "+this+", period "+pollPeriod); if (pollPeriod==null || pollPeriod.equals(Duration.PRACTICALLY_FOREVER)) { // don't schedule - used for tests // (scheduling fires off one initial task in the background before the delay, @@ -369,7 +373,11 @@ protected ManagementNodeState toNodeStateForPersistence(ManagementNodeState node } protected boolean isHeartbeatOk(ManagementNodeSyncRecord masterNode, ManagementNodeSyncRecord meNode) { - if (masterNode==null || meNode==null) return false; + if (masterNode==null) return false; + if (meNode==null) { + // we can't confirm it's healthy, but it appears so as far as we can tell + return true; + } Long timestampMaster = masterNode.getRemoteTimestamp(); Long timestampMe = meNode.getRemoteTimestamp(); if (timestampMaster==null || timestampMe==null) return false; @@ -382,11 +390,12 @@ protected ManagementNodeSyncRecord hasHealthyMaster() { String nodeId = memento.getMasterNodeId(); ManagementNodeSyncRecord masterMemento = (nodeId == null) ? null : memento.getManagementNodes().get(nodeId); + ManagementNodeSyncRecord ourMemento = memento.getManagementNodes().get(ownNodeId); boolean result = masterMemento != null && masterMemento.getStatus() == ManagementNodeState.MASTER - && isHeartbeatOk(masterMemento, memento.getManagementNodes().get(ownNodeId)); + && isHeartbeatOk(masterMemento, ourMemento); - if (LOG.isDebugEnabled()) LOG.debug("Healthy-master check result={}; masterId={}; memento=", - new Object[] {result, nodeId, (masterMemento == null ? "" : masterMemento.toVerboseString())}); + if (LOG.isDebugEnabled()) LOG.debug("Healthy-master check result={}; masterId={}; masterMemento={}; ourMemento={}", + new Object[] {result, nodeId, (masterMemento == null ? "" : masterMemento.toVerboseString()), (ourMemento == null ? "" : ourMemento.toVerboseString())}); return (result ? masterMemento : null); } @@ -663,4 +672,9 @@ public ManagementNodeSyncRecord apply(@Nullable ManagementNodeSyncRecord input) .build(); } } + + @Override + public String toString() { + return super.toString()+"[node:"+ownNodeId+";running="+running+"]"; + } } diff --git a/core/src/test/java/brooklyn/management/ha/HighAvailabilityManagerSplitBrainTest.java b/core/src/test/java/brooklyn/management/ha/HighAvailabilityManagerSplitBrainTest.java index ddf6b73a02..a11e57fdb7 100644 --- a/core/src/test/java/brooklyn/management/ha/HighAvailabilityManagerSplitBrainTest.java +++ b/core/src/test/java/brooklyn/management/ha/HighAvailabilityManagerSplitBrainTest.java @@ -48,10 +48,12 @@ import brooklyn.test.entity.TestApplication; import brooklyn.util.collections.MutableList; import brooklyn.util.collections.MutableMap; +import brooklyn.util.exceptions.Exceptions; import brooklyn.util.repeat.Repeater; import brooklyn.util.time.Duration; import brooklyn.util.time.Time; +import com.google.common.base.Stopwatch; import com.google.common.base.Ticker; import com.google.common.collect.ImmutableList; @@ -303,31 +305,42 @@ protected void doTestConcurrentStartup(int size, final Duration staggerStart) th Thread t = new Thread() { public void run() { if (staggerStart!=null) Time.sleep(staggerStart.multiply(Math.random())); n.ha.start(HighAvailabilityMode.AUTO); + n.ha.setPollPeriod(Duration.millis(20)); } }; spawned.add(t); t.start(); } - Assert.assertTrue(Repeater.create().every(Duration.millis(1)).limitTimeTo(Duration.THIRTY_SECONDS).until(new Callable() { - @Override public Boolean call() throws Exception { - ManagementPlaneSyncRecord memento = nodes.get(0).ha.getManagementPlaneSyncState(); - int masters=0, standbys=0, savedMasters=0, savedStandbys=0; - for (HaMgmtNode n: nodes) { - if (n.ha.getNodeState()==ManagementNodeState.MASTER) masters++; - if (n.ha.getNodeState()==ManagementNodeState.STANDBY) standbys++; - ManagementNodeSyncRecord m = memento.getManagementNodes().get(n.ownNodeId); - if (m!=null) { - if (m.getStatus()==ManagementNodeState.MASTER) savedMasters++; - if (m.getStatus()==ManagementNodeState.STANDBY) savedStandbys++; + try { + final Stopwatch timer = Stopwatch.createStarted(); + Assert.assertTrue(Repeater.create().backoff(Duration.millis(1), 1.2, Duration.millis(50)).limitTimeTo(Duration.THIRTY_SECONDS).until(new Callable() { + @Override public Boolean call() throws Exception { + ManagementPlaneSyncRecord memento = nodes.get(0).ha.getManagementPlaneSyncState(); + int masters=0, standbys=0, savedMasters=0, savedStandbys=0; + for (HaMgmtNode n: nodes) { + if (n.ha.getNodeState()==ManagementNodeState.MASTER) masters++; + if (n.ha.getNodeState()==ManagementNodeState.STANDBY) standbys++; + ManagementNodeSyncRecord m = memento.getManagementNodes().get(n.ownNodeId); + if (m!=null) { + if (m.getStatus()==ManagementNodeState.MASTER) savedMasters++; + if (m.getStatus()==ManagementNodeState.STANDBY) savedStandbys++; + } } - } - log.info("starting "+nodes.size()+" nodes: "+masters+" M + "+standbys+" zzz; " - + memento.getManagementNodes().size()+" saved, " + log.info("while starting "+nodes.size()+" nodes: "+masters+" M + "+standbys+" zzz; " + + memento.getManagementNodes().size()+" saved, " + memento.getMasterNodeId()+" master, "+savedMasters+" M + "+savedStandbys+" zzz"); - - return masters==1 && standbys==nodes.size()-1 && savedMasters==1 && savedStandbys==nodes.size()-1; - } - }).run()); + + if (timer.isRunning() && Duration.of(timer).compareTo(Duration.TEN_SECONDS)>0) { + log.warn("we seem to have a problem stabilizing"); //handy place to set a suspend-VM breakpoint! + timer.stop(); + } + return masters==1 && standbys==nodes.size()-1 && savedMasters==1 && savedStandbys==nodes.size()-1; + } + }).run()); + } catch (Throwable t) { + log.warn("Failed to stabilize (rethrowing): "+t, t); + throw Exceptions.propagate(t); + } for (Thread t: spawned) t.join(Duration.THIRTY_SECONDS.toMilliseconds()); From 0549c5668a1d63d1be96bac213faafa9a9fe4405 Mon Sep 17 00:00:00 2001 From: Alex Heneveld Date: Thu, 7 Aug 2014 23:38:31 -0400 Subject: [PATCH 5/8] restore visibility of static methods used in downstream projects --- .../rest/BrooklynRestApiLauncher.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/usage/rest-server/src/test/java/brooklyn/rest/BrooklynRestApiLauncher.java b/usage/rest-server/src/test/java/brooklyn/rest/BrooklynRestApiLauncher.java index b070f3bdb5..30719d6f57 100644 --- a/usage/rest-server/src/test/java/brooklyn/rest/BrooklynRestApiLauncher.java +++ b/usage/rest-server/src/test/java/brooklyn/rest/BrooklynRestApiLauncher.java @@ -19,6 +19,8 @@ package brooklyn.rest; import static com.google.common.base.Preconditions.checkNotNull; +import io.brooklyn.camp.brooklyn.BrooklynCampPlatformLauncherAbstract; +import io.brooklyn.camp.brooklyn.BrooklynCampPlatformLauncherNoServer; import java.io.File; import java.io.FilenameFilter; @@ -26,6 +28,7 @@ import java.net.InetSocketAddress; import java.util.EnumSet; import java.util.Set; + import javax.servlet.DispatcherType; import javax.servlet.Filter; @@ -63,6 +66,15 @@ import io.brooklyn.camp.brooklyn.BrooklynCampPlatformLauncherAbstract; import io.brooklyn.camp.brooklyn.BrooklynCampPlatformLauncherNoServer; +import com.google.common.annotations.Beta; +import com.google.common.base.Charsets; +import com.google.common.base.Optional; +import com.google.common.collect.Sets; +import com.google.common.io.Files; +import com.sun.jersey.api.core.DefaultResourceConfig; +import com.sun.jersey.api.core.ResourceConfig; +import com.sun.jersey.spi.container.servlet.ServletContainer; + /** Convenience and demo for launching programmatically. Also used for automated tests. *

    * BrooklynLauncher has a more full-featured CLI way to start, @@ -151,6 +163,7 @@ public Server start() { BrooklynCampPlatformLauncherAbstract platform = new BrooklynCampPlatformLauncherNoServer() .useManagementContext(mgmt) .launch(); + log.debug("started "+platform); ContextHandler context; String summary; @@ -239,7 +252,7 @@ private ContextHandler webXmlContextHandler(ManagementContext mgmt) { /** starts a server, on all NICs if security is configured, * otherwise (no security) only on loopback interface */ - private Server startServer(ManagementContext mgmt, ContextHandler context, String summary) { + public static Server startServer(ManagementContext mgmt, ContextHandler context, String summary) { // TODO this repeats code in BrooklynLauncher / WebServer. should merge the two paths. boolean secure = mgmt != null && !BrooklynWebConfig.hasNoSecurityOptions(mgmt.getConfig()); if (secure) { @@ -259,7 +272,7 @@ private Server startServer(ManagementContext mgmt, ContextHandler context, Strin return startServer(context, summary, bindLocation); } - private Server startServer(ContextHandler context, String summary, InetSocketAddress bindLocation) { + public static Server startServer(ContextHandler context, String summary, InetSocketAddress bindLocation) { Server server = new Server(bindLocation); server.setHandler(context); try { @@ -334,9 +347,7 @@ private static void installBrooklynFilters(ServletContextHandler context, Set * otherwise returns null */ + **/ + @Beta // public because used in dependent test projects public static Optional findMatchingFile(String filename) { final File f = new File(filename); if (f.exists()) return Optional.of(filename); From d4d95fc55ec76d2bcdd41549655ba807c6680529 Mon Sep 17 00:00:00 2001 From: Alex Heneveld Date: Fri, 8 Aug 2014 00:39:50 -0400 Subject: [PATCH 6/8] fix backslash in yaml blueprint --- .../src/test/resources/java-web-app-and-db-with-function-2.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usage/camp/src/test/resources/java-web-app-and-db-with-function-2.yaml b/usage/camp/src/test/resources/java-web-app-and-db-with-function-2.yaml index 1aecd35478..9583ac9316 100644 --- a/usage/camp/src/test/resources/java-web-app-and-db-with-function-2.yaml +++ b/usage/camp/src/test/resources/java-web-app-and-db-with-function-2.yaml @@ -29,7 +29,7 @@ services: brooklyn.example.db.url: # alternate syntax $brooklyn:formatString: - - jdbc:%s%s?user=%s\\&password=%s + - jdbc:%s%s?user=%s\&password=%s - $brooklyn:component("db").attributeWhenReady("datastore.url") - visitors - brooklyn From 63fe4b3abaabc64293d72e47e28ea7d5694ab692 Mon Sep 17 00:00:00 2001 From: Alex Heneveld Date: Fri, 8 Aug 2014 02:05:22 -0400 Subject: [PATCH 7/8] prefer 64-bit images (it makes sense, and without this it can sometimes pick a 32-bit os w a 64-bit hw, e.g. minRam 4096 in AWS VA, gives ami c68150ae on m3.large); also include the new ubuntu lts (14.04) as a slightly preferred; and a bit more jclouds template logging (previously we did not log the templateBuilder) --- .../jclouds/BrooklynImageChooser.java | 44 +++++++++++-------- .../location/jclouds/JcloudsLocation.java | 7 ++- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/locations/jclouds/src/main/java/brooklyn/location/jclouds/BrooklynImageChooser.java b/locations/jclouds/src/main/java/brooklyn/location/jclouds/BrooklynImageChooser.java index be934e2dc8..75d761f102 100644 --- a/locations/jclouds/src/main/java/brooklyn/location/jclouds/BrooklynImageChooser.java +++ b/locations/jclouds/src/main/java/brooklyn/location/jclouds/BrooklynImageChooser.java @@ -115,33 +115,39 @@ public double score(Image img) { score += punishmentForOldOsVersions(img, OsFamily.CENTOS, 6); OperatingSystem os = img.getOperatingSystem(); - if (os!=null && os.getFamily()!=null) { - // preference for these open, popular OS (but only wrt versions above) - if (os.getFamily().equals(OsFamily.CENTOS)) score += 2; - else if (os.getFamily().equals(OsFamily.UBUNTU)) { - score += 1; - - // 12.04 is LTS, so prefer it slightly above others - if ("12.04".equals(os.getVersion())) score += 1; - - // NB some 13.10 images take 20m+ before they are sshable on AWS - // with "vesafb: module verification error" showing in the AWS system log - } + if (os!=null) { + if (os.getFamily()!=null) { + // preference for these open, popular OS (but only wrt versions above) + if (os.getFamily().equals(OsFamily.CENTOS)) score += 2; + else if (os.getFamily().equals(OsFamily.UBUNTU)) { + score += 2; + + // prefer these LTS releases slightly above others (including above CentOS) + // (but note in AWS Virginia, at least, version is empty for the 14.04 images for some reason, as of Aug 2014) + if ("14.04".equals(os.getVersion())) score += 0.2; + else if ("12.04".equals(os.getVersion())) score += 0.1; + + // NB some 13.10 images take 20m+ before they are sshable on AWS + // with "vesafb: module verification error" showing in the AWS system log + } - // slight preference for these - else if (os.getFamily().equals(OsFamily.RHEL)) score += 1; - else if (os.getFamily().equals(OsFamily.AMZN_LINUX)) score += 1; - else if (os.getFamily().equals(OsFamily.DEBIAN)) score += 1; + // slight preference for these + else if (os.getFamily().equals(OsFamily.RHEL)) score += 1; + else if (os.getFamily().equals(OsFamily.AMZN_LINUX)) score += 1; + else if (os.getFamily().equals(OsFamily.DEBIAN)) score += 1; - // prefer to take our chances with unknown / unlabelled linux than something explicitly windows - else if (os.getFamily().equals(OsFamily.WINDOWS)) score -= 1; + // prefer to take our chances with unknown / unlabelled linux than something explicitly windows + else if (os.getFamily().equals(OsFamily.WINDOWS)) score -= 1; + } + // prefer 64-bit + if (os.is64Bit()) score += 0.5; } // TODO prefer known providerIds if (log.isTraceEnabled()) log.trace("initial score "+score+" for "+img); - + return score; } diff --git a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java index bc2c45733a..670806c547 100644 --- a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java +++ b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java @@ -998,7 +998,7 @@ public Template buildTemplate(ComputeService computeService, ConfigBag config) { if (templateBuilder==null) { templateBuilder = new PortableTemplateBuilder>(); } else { - LOG.debug("jclouds using templateBuilder {} as base for provisioning in {} for {}", new Object[] { + LOG.debug("jclouds using templateBuilder {} as custom base for provisioning in {} for {}", new Object[] { templateBuilder, this, config.getDescription()}); } if (templateBuilder instanceof PortableTemplateBuilder) { @@ -1040,12 +1040,15 @@ public Template buildTemplate(ComputeService computeService, ConfigBag config) { customizer.customize(this, computeService, templateBuilder); } + LOG.debug("jclouds using templateBuilder {} for provisioning in {} for {}", new Object[] { + templateBuilder, this, config.getDescription()}); + // Finally try to build the template Template template; try { template = templateBuilder.build(); if (template==null) throw new NullPointerException("No template found (templateBuilder.build returned null)"); - LOG.debug(""+this+" got template "+template+" (image "+template.getImage()+")"); + LOG.debug("jclouds found template "+template+" (image "+template.getImage()+") for provisioning in "+this+" for "+config.getDescription()); if (template.getImage()==null) throw new NullPointerException("Template does not contain an image (templateBuilder.build returned invalid template)"); } catch (AuthorizationException e) { LOG.warn("Error resolving template: not authorized (rethrowing: "+e+")"); From 35dad30c7dd8a09d6f86550732b47e713ac7d37f Mon Sep 17 00:00:00 2001 From: Alex Heneveld Date: Mon, 25 Aug 2014 07:35:32 +0100 Subject: [PATCH 8/8] code review comments on #113 --- .../brooklyn/config/BrooklynProperties.java | 1 + .../entity/group/DynamicClusterImpl.java | 8 ++++---- .../src/main/java/brooklyn/util/osgi/Osgis.java | 2 +- .../entity/basic/AbstractEntityLegacyTest.java | 5 ++++- .../location/jclouds/JcloudsLocation.java | 2 +- .../brooklyn/rest/BrooklynRestApiLauncher.java | 17 +++-------------- .../util/exceptions/ReferenceWithError.java | 14 +++++++++----- .../java/brooklyn/util/repeat/Repeater.java | 2 +- 8 files changed, 24 insertions(+), 27 deletions(-) diff --git a/core/src/main/java/brooklyn/config/BrooklynProperties.java b/core/src/main/java/brooklyn/config/BrooklynProperties.java index b5d63bae7d..88e1ac1e63 100644 --- a/core/src/main/java/brooklyn/config/BrooklynProperties.java +++ b/core/src/main/java/brooklyn/config/BrooklynProperties.java @@ -95,6 +95,7 @@ public Builder() { this(true); } + // TODO it's always called with true here, perhaps we don't need the argument? private Builder(boolean setGlobalFileDefaults) { resetDefaultLocationMetadataUrl(); if (setGlobalFileDefaults) { diff --git a/core/src/main/java/brooklyn/entity/group/DynamicClusterImpl.java b/core/src/main/java/brooklyn/entity/group/DynamicClusterImpl.java index b6224a48ec..27ffaf8089 100644 --- a/core/src/main/java/brooklyn/entity/group/DynamicClusterImpl.java +++ b/core/src/main/java/brooklyn/entity/group/DynamicClusterImpl.java @@ -488,7 +488,7 @@ protected Entity replaceMember(Entity member, Location memberLoc, Map extr synchronized (mutex) { ReferenceWithError> added = addInSingleLocation(memberLoc, extraFlags); - if (!added.getMaskingError().isPresent()) { + if (!added.getWithoutError().isPresent()) { String msg = String.format("In %s, failed to grow, to replace %s; not removing", this, member); if (added.hasError()) throw new IllegalStateException(msg, added.getError()); @@ -502,7 +502,7 @@ protected Entity replaceMember(Entity member, Location memberLoc, Map extr throw new StopFailedRuntimeException("replaceMember failed to stop and remove old member "+member.getId(), e); } - return added.getThrowingError().get(); + return added.getWithError().get(); } } @@ -585,7 +585,7 @@ protected Collection grow(int delta) { } // create and start the entities - return addInEachLocation(chosenLocations, ImmutableMap.of()).getThrowingError(); + return addInEachLocation(chosenLocations, ImmutableMap.of()).getWithError(); } /** Note for sub-clases; this method can be called while synchronized on {@link #mutex}. */ @@ -619,7 +619,7 @@ protected Collection shrink(int delta) { protected ReferenceWithError> addInSingleLocation(Location location, Map flags) { ReferenceWithError> added = addInEachLocation(ImmutableList.of(location), flags); - Optional result = Iterables.isEmpty(added.getMaskingError()) ? Optional.absent() : Optional.of(Iterables.getOnlyElement(added.get())); + Optional result = Iterables.isEmpty(added.getWithoutError()) ? Optional.absent() : Optional.of(Iterables.getOnlyElement(added.get())); if (!added.hasError()) { return ReferenceWithError.newInstanceWithoutError( result ); } else { diff --git a/core/src/main/java/brooklyn/util/osgi/Osgis.java b/core/src/main/java/brooklyn/util/osgi/Osgis.java index 418e417f45..d8f20ae5e5 100644 --- a/core/src/main/java/brooklyn/util/osgi/Osgis.java +++ b/core/src/main/java/brooklyn/util/osgi/Osgis.java @@ -198,7 +198,7 @@ private static void installBootBundles(Framework framework) { URL url = resources.nextElement(); ReferenceWithError installResult = installExtensionBundle(bundleContext, url, installedBundles, getVersionedId(framework)); if (installResult.hasError()) { - if (installResult.getMaskingError()) { + if (installResult.getWithoutError()) { // true return code means it was installed or trivially not installed if (LOG.isTraceEnabled()) LOG.trace(installResult.getError().getMessage()); diff --git a/core/src/test/java/brooklyn/entity/basic/AbstractEntityLegacyTest.java b/core/src/test/java/brooklyn/entity/basic/AbstractEntityLegacyTest.java index 723420b37b..344bd061b1 100644 --- a/core/src/test/java/brooklyn/entity/basic/AbstractEntityLegacyTest.java +++ b/core/src/test/java/brooklyn/entity/basic/AbstractEntityLegacyTest.java @@ -106,7 +106,10 @@ public void testLegacyConstructionCallsConfigureMethod() throws Exception { assertEquals(entity.getConfigureCount(), 1); assertEquals(entity.getConfigureDuringConstructionCount(), 1); } - + + // TODO move the testNewStyle methods (several of them) to EntitySpecTest ? + // make sure to keep them when legacy approach removed! + // see https://github.com/apache/incubator-brooklyn/pull/113#discussion-diff-16474353 @Test public void testNewStyleCallsConfigureAfterConstruction() throws Exception { app = TestApplication.Factory.newManagedInstanceForTests(); diff --git a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java index 670806c547..a044710c83 100644 --- a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java +++ b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java @@ -1747,7 +1747,7 @@ public Boolean call() { .limitTimeTo(delayMs, MILLISECONDS) .runKeepingError(); - if (!reachable.getMaskingError()) { + if (!reachable.getWithoutError()) { throw new IllegalStateException("SSH failed for "+ user+"@"+vmIp+" ("+setup.getDescription()+") after waiting "+ Time.makeTimeStringRounded(delayMs), reachable.getError()); diff --git a/usage/rest-server/src/test/java/brooklyn/rest/BrooklynRestApiLauncher.java b/usage/rest-server/src/test/java/brooklyn/rest/BrooklynRestApiLauncher.java index 30719d6f57..b1b8b65ebb 100644 --- a/usage/rest-server/src/test/java/brooklyn/rest/BrooklynRestApiLauncher.java +++ b/usage/rest-server/src/test/java/brooklyn/rest/BrooklynRestApiLauncher.java @@ -42,15 +42,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Charsets; -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Sets; -import com.google.common.io.Files; -import com.sun.jersey.api.core.DefaultResourceConfig; -import com.sun.jersey.api.core.ResourceConfig; -import com.sun.jersey.spi.container.servlet.ServletContainer; - import brooklyn.config.BrooklynProperties; import brooklyn.config.BrooklynServiceAttributes; import brooklyn.management.ManagementContext; @@ -63,12 +54,11 @@ import brooklyn.util.exceptions.Exceptions; import brooklyn.util.net.Networking; import brooklyn.util.text.WildcardGlobs; -import io.brooklyn.camp.brooklyn.BrooklynCampPlatformLauncherAbstract; -import io.brooklyn.camp.brooklyn.BrooklynCampPlatformLauncherNoServer; import com.google.common.annotations.Beta; import com.google.common.base.Charsets; import com.google.common.base.Optional; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; import com.google.common.io.Files; import com.sun.jersey.api.core.DefaultResourceConfig; @@ -127,9 +117,9 @@ public BrooklynRestApiLauncher securityProvider(Class... filters) { this.filters = Sets.newHashSet(filters); return this; @@ -371,7 +361,6 @@ private static String findRestApiWar() { * supports globs in the filename portion only, in which case it returns the _newest_ matching file. *

    * otherwise returns null */ - **/ @Beta // public because used in dependent test projects public static Optional findMatchingFile(String filename) { final File f = new File(filename); diff --git a/utils/common/src/main/java/brooklyn/util/exceptions/ReferenceWithError.java b/utils/common/src/main/java/brooklyn/util/exceptions/ReferenceWithError.java index 9e4fe08fc1..2ffe1198cc 100644 --- a/utils/common/src/main/java/brooklyn/util/exceptions/ReferenceWithError.java +++ b/utils/common/src/main/java/brooklyn/util/exceptions/ReferenceWithError.java @@ -20,9 +20,11 @@ import javax.annotation.Nullable; +import com.google.common.annotations.Beta; import com.google.common.base.Supplier; /** A reference to an object which can carry an object alongside it. */ +@Beta public class ReferenceWithError implements Supplier { private final T object; @@ -57,19 +59,21 @@ public boolean masksErrorIfPresent() { return maskError; } - /** returns the underlying value, throwing if there is an error and {@link #throwsErrorOnAccess()} is set */ + /** returns the underlying value, throwing if there is an error which is not masked (ie {@link #throwsErrorOnAccess()} is set) */ public T get() { if (masksErrorIfPresent()) { - return getMaskingError(); + return getWithoutError(); } - return getThrowingError(); + return getWithError(); } - public T getMaskingError() { + /** returns the object, ignoring any error (even non-masked) */ + public T getWithoutError() { return object; } - public T getThrowingError() { + /** throws error, even if there is one (even if masked), else returns the object */ + public T getWithError() { checkNoError(); return object; } diff --git a/utils/common/src/main/java/brooklyn/util/repeat/Repeater.java b/utils/common/src/main/java/brooklyn/util/repeat/Repeater.java index be0d3f2252..8acbbf943b 100644 --- a/utils/common/src/main/java/brooklyn/util/repeat/Repeater.java +++ b/utils/common/src/main/java/brooklyn/util/repeat/Repeater.java @@ -301,7 +301,7 @@ public Repeater limitTimeTo(Duration duration) { * @return true if the exit condition was satisfied; false if the loop terminated for any other reason. */ public boolean run() { - return runKeepingError().getMaskingError(); + return runKeepingError().getWithoutError(); } public ReferenceWithError runKeepingError() {