http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6f58ef3e/usage/launcher/src/main/java/org/apache/brooklyn/launcher/config/BrooklynGlobalConfig.java ---------------------------------------------------------------------- diff --git a/usage/launcher/src/main/java/org/apache/brooklyn/launcher/config/BrooklynGlobalConfig.java b/usage/launcher/src/main/java/org/apache/brooklyn/launcher/config/BrooklynGlobalConfig.java new file mode 100644 index 0000000..9ae0504 --- /dev/null +++ b/usage/launcher/src/main/java/org/apache/brooklyn/launcher/config/BrooklynGlobalConfig.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.brooklyn.launcher.config; + +import brooklyn.config.BrooklynServiceAttributes; +import brooklyn.config.ConfigKey; +import brooklyn.entity.basic.BrooklynConfigKeys; +import brooklyn.location.cloud.CloudLocationConfig; +import brooklyn.management.internal.BrooklynGarbageCollector; +import brooklyn.rest.BrooklynWebConfig; +import brooklyn.util.internal.BrooklynSystemProperties; +import brooklyn.util.internal.StringSystemProperty; +import brooklyn.util.time.Duration; + +/** + * Convenience collection of popular global configuration values. + * (Also a handy way to recall where config keys are set.) + * <p> + * These can typically be set in brooklyn.properties for global applicability. + * In some cases (eg SSH_CONFIG_* keys) they can also be set on entities/locations + * for behaviour specific to that entity. + * <p> + * Also see: + * <li> {@link BrooklynSystemProperties} + * <li> {@link BrooklynServiceAttributes} + * <li> {@link CloudLocationConfig} and classes in that hierarchy. + */ +public class BrooklynGlobalConfig { + + public static final ConfigKey<Boolean> REQUIRE_HTTPS = BrooklynWebConfig.HTTPS_REQUIRED; + + public static final ConfigKey<Duration> GC_PERIOD = BrooklynGarbageCollector.GC_PERIOD; + public static final ConfigKey<Boolean> DO_SYSTEM_GC = BrooklynGarbageCollector.DO_SYSTEM_GC; + public static final ConfigKey<Integer> MAX_TASKS_PER_TAG = BrooklynGarbageCollector.MAX_TASKS_PER_TAG; + public static final ConfigKey<Integer> MAX_TASKS_PER_ENTITY = BrooklynGarbageCollector.MAX_TASKS_PER_ENTITY; + public static final ConfigKey<Integer> MAX_TASKS_GLOBAL = BrooklynGarbageCollector.MAX_TASKS_GLOBAL; + public static final ConfigKey<Duration> MAX_TASK_AGE = BrooklynGarbageCollector.MAX_TASK_AGE; + + public static final StringSystemProperty LOCALHOST_IP_ADDRESS = BrooklynServiceAttributes.LOCALHOST_IP_ADDRESS; + + // brooklyn.ssh.config.noDeleteAfterExec = true will cause scripts to be left in situ for debugging + public static final ConfigKey<Boolean> SSH_CONFIG_NO_DELETE_SCRIPT = BrooklynConfigKeys.SSH_CONFIG_NO_DELETE_SCRIPT; + + public static final ConfigKey<String> SSH_CONFIG_SCRIPT_DIR = BrooklynConfigKeys.SSH_CONFIG_SCRIPT_DIR; + public static final ConfigKey<String> SSH_CONFIG_SCRIPT_HEADER = BrooklynConfigKeys.SSH_CONFIG_SCRIPT_HEADER; + public static final ConfigKey<String> SSH_CONFIG_DIRECT_HEADER = BrooklynConfigKeys.SSH_CONFIG_DIRECT_HEADER; + + // TODO other constants from elsewhere + +}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6f58ef3e/usage/launcher/src/main/java/org/apache/brooklyn/launcher/config/CustomResourceLocator.java ---------------------------------------------------------------------- diff --git a/usage/launcher/src/main/java/org/apache/brooklyn/launcher/config/CustomResourceLocator.java b/usage/launcher/src/main/java/org/apache/brooklyn/launcher/config/CustomResourceLocator.java new file mode 100644 index 0000000..78ad7c6 --- /dev/null +++ b/usage/launcher/src/main/java/org/apache/brooklyn/launcher/config/CustomResourceLocator.java @@ -0,0 +1,127 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.brooklyn.launcher.config; + +import java.io.File; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import brooklyn.BrooklynVersion; +import brooklyn.config.ConfigMap; +import brooklyn.util.ResourceUtils; +import brooklyn.util.exceptions.Exceptions; +import brooklyn.util.os.Os; + +/** class which allows non-standard locators to be registered for URL's being loaded */ +public class CustomResourceLocator { + + private static final Logger log = LoggerFactory.getLogger(CustomResourceLocator.class); + + protected final ResourceUtils r; + private ConfigMap config; + + public interface ResourceLocator { + public boolean isApplicable(String url, ConfigMap config); + public InputStream locate(String url, ConfigMap config, ResourceUtils r); + } + + private static List<ResourceLocator> locators = new ArrayList<ResourceLocator>(); + + public CustomResourceLocator(ConfigMap config, ResourceUtils r) { + this.config = config; + this.r = r; + } + + public static void registerAlternateLocator(ResourceLocator locator) { + locators.add(0, locator); + } + + /** returns the first known locator for the given url/config pair */ + public static ResourceLocator getLocatorFor(String url, ConfigMap config) { + for (ResourceLocator l: locators) { + if (l.isApplicable(url, config)) return l; + } + return null; + } + + /** finds the file indicated at the URL, using some rewrites if necessary to work around some known issues. + * <p> + * in particular, eclipse often does not copy WAR files as instructed by maven, so brooklyn.war might not be found */ + public InputStream getResourceFromUrl(String url) { + // TODO we could allow the source to be overridden from config, + // by allowing configuration e.g. + // brooklyn.path.override.brooklyn.war=classpath://brooklyn-replacement-webapp.war + // (not sure if this is a good idea or not) + + try { + return r.getResourceFromUrl(url); + } catch (Exception e) { + ResourceLocator locator = getLocatorFor(url, config); + if (locator!=null) { + log.debug("Unable to load resource from "+url+"; attempting with locator "+locator); + try { + InputStream result = locator.locate(url, config, r); + if (result!=null) return result; + if (result==null) + log.warn("Unable to load resource from "+url+", even with custom locator; rethrowing original exception"); + } catch (Exception e2) { + log.warn("Unable to load resource from "+url+", even with custom locator; rethrowing original exception, new exception is: "+e2); + } + } + throw Exceptions.propagate(e); + } + } + + public static class SearchingClassPathInDevMode implements ResourceLocator { + private final String urlToSearchFor; + private final String classpathSuffixToSearchFor; + private final String classpathSuffixToUse; + + public SearchingClassPathInDevMode(String urlToSearchFor, String classpathSuffixToSearchFor, String classpathSuffixToUse) { + this.urlToSearchFor = urlToSearchFor; + this.classpathSuffixToSearchFor = Os.nativePath(classpathSuffixToSearchFor); + this.classpathSuffixToUse = classpathSuffixToUse; + } + + @Override + public boolean isApplicable(String url, ConfigMap config) { + return BrooklynVersion.isDevelopmentEnvironment() && urlToSearchFor.equals(url); + } + + @Override + public InputStream locate(String url, ConfigMap config, ResourceUtils r) { + String cp = System.getProperty("java.class.path"); + int cpi = cp.indexOf(classpathSuffixToSearchFor); + if (cpi==-1) return null; + String path = cp.substring(0, cpi); + int lps = path.lastIndexOf(File.pathSeparatorChar); + if (lps>=0) path = path.substring(lps+1); + path = path + classpathSuffixToUse; + log.debug("Looking for "+url+" in revised location "+path); + InputStream result = r.getResourceFromUrl(path); + log.info("Using "+url+" from revised location "+path); + return result; + } + } + +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6f58ef3e/usage/launcher/src/main/java/org/apache/brooklyn/launcher/config/StopWhichAppsOnShutdown.java ---------------------------------------------------------------------- diff --git a/usage/launcher/src/main/java/org/apache/brooklyn/launcher/config/StopWhichAppsOnShutdown.java b/usage/launcher/src/main/java/org/apache/brooklyn/launcher/config/StopWhichAppsOnShutdown.java new file mode 100644 index 0000000..e5851f7 --- /dev/null +++ b/usage/launcher/src/main/java/org/apache/brooklyn/launcher/config/StopWhichAppsOnShutdown.java @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.brooklyn.launcher.config; + +public enum StopWhichAppsOnShutdown { + ALL, ALL_IF_NOT_PERSISTED, NONE, THESE, THESE_IF_NOT_PERSISTED +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6f58ef3e/usage/launcher/src/main/java/org/apache/brooklyn/util/web/ContextHandlerCollectionHotSwappable.java ---------------------------------------------------------------------- diff --git a/usage/launcher/src/main/java/org/apache/brooklyn/util/web/ContextHandlerCollectionHotSwappable.java b/usage/launcher/src/main/java/org/apache/brooklyn/util/web/ContextHandlerCollectionHotSwappable.java new file mode 100644 index 0000000..4a69adf --- /dev/null +++ b/usage/launcher/src/main/java/org/apache/brooklyn/util/web/ContextHandlerCollectionHotSwappable.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.brooklyn.util.web; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.jetty.server.Handler; +import org.eclipse.jetty.server.handler.ContextHandlerCollection; +import org.eclipse.jetty.webapp.WebAppContext; + +public class ContextHandlerCollectionHotSwappable extends ContextHandlerCollection { + + public synchronized void updateHandler(WebAppContext context) throws Exception { + Handler[] hl0 = getHandlers(); + List<Handler> hl = hl0!=null ? new ArrayList<Handler>(Arrays.asList(hl0)) : new ArrayList<Handler>(); + // remove any previous version + removeContextFromList(hl, context.getContextPath()); + // have to add before the root war (remove root war then add back) + Handler oldRoot = removeContextFromList(hl, "/"); + // now add and add back any root + hl.add(context); + if (oldRoot!=null) hl.add(oldRoot); + setHandlers(hl.toArray(new Handler[0])); + + // and if we are already running, start the new context + if (isRunning()) { + context.start(); + } + } + + public static Handler removeContextFromList(List<Handler> hl, String contextPath) { + Iterator<Handler> hi = hl.iterator(); + while (hi.hasNext()) { + Handler h = hi.next(); + if ((h instanceof WebAppContext) && ((WebAppContext)h).getContextPath().equals(contextPath)) { + hi.remove(); + return h; + } + } + return null; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6f58ef3e/usage/launcher/src/test/java/brooklyn/entity/basic/VanillaSoftwareYamlTest.java ---------------------------------------------------------------------- diff --git a/usage/launcher/src/test/java/brooklyn/entity/basic/VanillaSoftwareYamlTest.java b/usage/launcher/src/test/java/brooklyn/entity/basic/VanillaSoftwareYamlTest.java deleted file mode 100644 index 8fbca64..0000000 --- a/usage/launcher/src/test/java/brooklyn/entity/basic/VanillaSoftwareYamlTest.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * 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.entity.basic; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.Assert; -import org.testng.annotations.Test; - -import brooklyn.entity.Application; -import brooklyn.entity.Entity; -import brooklyn.entity.trait.Startable; -import brooklyn.launcher.SimpleYamlLauncherForTests; -import brooklyn.launcher.camp.SimpleYamlLauncher; -import brooklyn.test.Asserts; -import brooklyn.util.ResourceUtils; -import brooklyn.util.os.Os; -import brooklyn.util.text.Strings; - -import com.google.common.collect.Iterables; - -public class VanillaSoftwareYamlTest { - - private static final Logger log = LoggerFactory.getLogger(VanillaSoftwareYamlTest.class); - - @Test(groups="Integration") - public void testVanillaSoftwareYaml() { - SimpleYamlLauncher l = new SimpleYamlLauncherForTests(); - try { - Application app = l.launchAppYaml("vanilla-software-blueprint.yaml"); - log.info("started "+app); - - String runDir = Iterables.getOnlyElement(app.getChildren()).getAttribute(SoftwareProcess.RUN_DIR); - final String filePath = Os.mergePaths(runDir, "DATE"); - - String fileContents = new ResourceUtils(this).getResourceAsString(filePath); - Long d1 = Long.parseLong( Strings.getFirstWordAfter(fileContents, "utc") ); - Assert.assertTrue( Math.abs(d1*1000-System.currentTimeMillis())<15000, "Time UTC does not match system; "+d1+" v "+System.currentTimeMillis() ); - - Asserts.succeedsEventually(new Runnable() { - public void run() { - String fileContents = new ResourceUtils(this).getResourceAsString(filePath); - Assert.assertTrue(fileContents.contains("checkRunning")); - } - }); - - app.invoke(Startable.STOP, null).getUnchecked(); - Asserts.succeedsEventually(new Runnable() { - public void run() { - String fileContents = new ResourceUtils(this).getResourceAsString(filePath); - Assert.assertTrue(fileContents.contains("stop")); - } - }); - - } finally { - l.destroyAll(); - } - log.info("DONE"); - } - - /** yaml variant of VanillaSoftwareProcessAndChildrenIntegrationTest */ - @Test(groups="Integration") - public void testVanillaSoftwareYamlWithChildStartedAfter() { - SimpleYamlLauncher l = new SimpleYamlLauncherForTests(); - try { - Application app = l.launchAppYaml("vanilla-software-with-child-blueprint.yaml"); - log.info("started "+app); - - Entity p1 = Iterables.getOnlyElement( app.getChildren() ); - Long d1 = Long.parseLong( Strings.getFirstWordAfter(new ResourceUtils(this).getResourceAsString(Os.mergePaths(p1.getAttribute(SoftwareProcess.RUN_DIR), "DATE")), "utc") ); - - Entity p2 = Iterables.getOnlyElement( p1.getChildren() ); - Long d2 = Long.parseLong( Strings.getFirstWordAfter(new ResourceUtils(this).getResourceAsString(Os.mergePaths(p2.getAttribute(SoftwareProcess.RUN_DIR), "DATE")), "utc") ); - Assert.assertTrue( d2-d1 > 2 && d2-d1 < 10, "p2 should have started 3s after parent, but it did not ("+(d2-d1)+"s difference" ); - } finally { - l.destroyAll(); - } - log.info("DONE"); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6f58ef3e/usage/launcher/src/test/java/brooklyn/entity/brooklynnode/BrooklynEntityMirrorIntegrationTest.java ---------------------------------------------------------------------- diff --git a/usage/launcher/src/test/java/brooklyn/entity/brooklynnode/BrooklynEntityMirrorIntegrationTest.java b/usage/launcher/src/test/java/brooklyn/entity/brooklynnode/BrooklynEntityMirrorIntegrationTest.java deleted file mode 100644 index a523019..0000000 --- a/usage/launcher/src/test/java/brooklyn/entity/brooklynnode/BrooklynEntityMirrorIntegrationTest.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * 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.entity.brooklynnode; - -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import brooklyn.entity.Entity; -import brooklyn.entity.basic.ApplicationBuilder; -import brooklyn.entity.basic.Entities; -import brooklyn.entity.basic.EntityInternal; -import brooklyn.entity.proxying.EntitySpec; -import brooklyn.launcher.BrooklynWebServer; -import brooklyn.management.ManagementContext; -import brooklyn.management.ha.HighAvailabilityMode; -import brooklyn.rest.filter.BrooklynPropertiesSecurityFilter; -import brooklyn.test.Asserts; -import brooklyn.test.EntityTestUtils; -import brooklyn.test.HttpTestUtils; -import brooklyn.test.entity.LocalManagementContextForTests; -import brooklyn.test.entity.TestApplication; -import brooklyn.util.exceptions.Exceptions; -import brooklyn.util.time.Duration; - -/** - * Test for EntityMirror, launching an in-memory server and ensuring we can mirror. - * Here so that we can access the REST server. - * <p> - * May require <code>-Dbrooklyn.localhost.address=127.0.0.1</code> so that the console which binds to localhost is addressible. - * (That and the time it takes to run are the only reasons this is Integration.) - */ -@Test -public class BrooklynEntityMirrorIntegrationTest { - - private static final Logger log = LoggerFactory.getLogger(BrooklynEntityMirrorIntegrationTest.class); - - private BrooklynWebServer server; - private TestApplication serverApp; - private ManagementContext serverMgmt; - - private TestApplication localApp; - private ManagementContext localMgmt; - - @BeforeMethod(alwaysRun=true) - public void setUp() throws Exception { - localApp = TestApplication.Factory.newManagedInstanceForTests(); - localMgmt = localApp.getManagementContext(); - } - - @AfterMethod(alwaysRun=true) - public void tearDown() throws Exception { - if (serverMgmt!=null) Entities.destroyAll(serverMgmt); - if (server!=null) server.stop(); - if (localMgmt!=null) Entities.destroyAll(localMgmt); - - serverMgmt = null; - } - - - protected void setUpServer() { - setUpServer(new LocalManagementContextForTests(), false); - } - protected void setUpServer(ManagementContext mgmt, boolean useSecurityFilter) { - try { - if (serverMgmt!=null) throw new IllegalStateException("server already set up"); - - serverMgmt = mgmt; - server = new BrooklynWebServer(mgmt); - if (useSecurityFilter) server.setSecurityFilter(BrooklynPropertiesSecurityFilter.class); - server.start(); - - serverMgmt.getHighAvailabilityManager().disabled(); - serverApp = ApplicationBuilder.newManagedApp(TestApplication.class, serverMgmt); - - ((LocalManagementContextForTests)serverMgmt).noteStartupComplete(); - } catch (Exception e) { - throw Exceptions.propagate(e); - } - } - - protected String getBaseUri() { - return server.getRootUrl(); - } - - @Test(groups="Integration") - public void testServiceMirroring() throws Exception { - setUpServer(); - - String catalogItemId = "test-catalog-item:1.0"; - String catalogItemIdGA = "test-catalog-item:1.0-GA"; - serverApp.setAttribute(TestApplication.MY_ATTRIBUTE, "austria"); - serverApp.setCatalogItemId(catalogItemId); - - String serviceId = serverApp.getId(); - Entity mirror = localApp.addChild(EntitySpec.create(BrooklynEntityMirror.class) - .configure(BrooklynEntityMirror.POLL_PERIOD, Duration.millis(100)) - .configure(BrooklynEntityMirror.MIRRORED_ENTITY_ID, serviceId) - .configure(BrooklynEntityMirror.MIRRORED_ENTITY_URL, - getBaseUri()+"/v1/applications/"+serviceId+"/entities/"+serviceId) - ); - - EntityTestUtils.assertAttributeEqualsEventually(mirror, TestApplication.MY_ATTRIBUTE, "austria"); - EntityTestUtils.assertAttributeEqualsEventually(mirror, BrooklynEntityMirror.MIRROR_CATALOG_ITEM_ID, catalogItemId); - assertTrue(mirror.getAttribute(BrooklynEntityMirror.MIRROR_SUMMARY) != null, "entity summary is null"); - log.info("Sensors mirrored are: "+((EntityInternal)mirror).getAllAttributes()); - - serverApp.setAttribute(TestApplication.MY_ATTRIBUTE, "bermuda"); - serverApp.setCatalogItemId(catalogItemIdGA); - EntityTestUtils.assertAttributeEqualsEventually(mirror, TestApplication.MY_ATTRIBUTE, "bermuda"); - EntityTestUtils.assertAttributeEqualsEventually(mirror, BrooklynEntityMirror.MIRROR_CATALOG_ITEM_ID, catalogItemIdGA); - - serverApp.stop(); - assertUnmanagedEventually(mirror); - } - - @Test(groups="Integration") - public void testServiceMirroringHttps() throws Exception { - LocalManagementContextForTests mgmtHttps = new LocalManagementContextForTests(); - mgmtHttps.getBrooklynProperties().put("brooklyn.webconsole.security.https.required", true); - mgmtHttps.getBrooklynProperties().put("brooklyn.webconsole.security.users", "admin"); - mgmtHttps.getBrooklynProperties().put("brooklyn.webconsole.security.user.admin.password", "P5ssW0rd"); - - setUpServer(mgmtHttps, true); - Assert.assertTrue(getBaseUri().startsWith("https:"), "URL is not https: "+getBaseUri()); - // check auth is required - HttpTestUtils.assertHttpStatusCodeEquals(getBaseUri(), 401); - - serverApp.setAttribute(TestApplication.MY_ATTRIBUTE, "austria"); - - String serviceId = serverApp.getId(); - Entity mirror = localApp.addChild(EntitySpec.create(BrooklynEntityMirror.class) - .configure(BrooklynEntityMirror.POLL_PERIOD, Duration.millis(100)) - .configure(BrooklynEntityMirror.MANAGEMENT_USER, "admin") - .configure(BrooklynEntityMirror.MANAGEMENT_PASSWORD, "P5ssW0rd") - .configure(BrooklynEntityMirror.MIRRORED_ENTITY_ID, serviceId) - .configure(BrooklynEntityMirror.MIRRORED_ENTITY_URL, - getBaseUri()+"/v1/applications/"+serviceId+"/entities/"+serviceId) - ); - - EntityTestUtils.assertAttributeEqualsEventually(mirror, TestApplication.MY_ATTRIBUTE, "austria"); - log.info("Sensors mirrored are: "+((EntityInternal)mirror).getAllAttributes()); - - serverApp.setAttribute(TestApplication.MY_ATTRIBUTE, "bermuda"); - EntityTestUtils.assertAttributeEqualsEventually(mirror, TestApplication.MY_ATTRIBUTE, "bermuda"); - - serverApp.stop(); - assertUnmanagedEventually(mirror); - } - - private static void assertUnmanagedEventually(final Entity entity) { - Asserts.succeedsEventually(new Runnable() { - @Override public void run() { - assertFalse(Entities.isManaged(entity)); - }}); - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6f58ef3e/usage/launcher/src/test/java/brooklyn/entity/brooklynnode/BrooklynNodeRestTest.java ---------------------------------------------------------------------- diff --git a/usage/launcher/src/test/java/brooklyn/entity/brooklynnode/BrooklynNodeRestTest.java b/usage/launcher/src/test/java/brooklyn/entity/brooklynnode/BrooklynNodeRestTest.java deleted file mode 100644 index 34d7b07..0000000 --- a/usage/launcher/src/test/java/brooklyn/entity/brooklynnode/BrooklynNodeRestTest.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * 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.entity.brooklynnode; - -import java.net.URI; -import java.util.concurrent.Callable; - -import org.apache.http.client.HttpClient; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.Assert; -import org.testng.annotations.Test; - -import brooklyn.entity.Application; -import brooklyn.entity.basic.ApplicationBuilder; -import brooklyn.entity.basic.Attributes; -import brooklyn.entity.basic.Entities; -import brooklyn.entity.basic.EntityInternal; -import brooklyn.entity.proxying.EntitySpec; -import brooklyn.event.basic.BasicConfigKey; -import brooklyn.launcher.SimpleYamlLauncherForTests; -import brooklyn.launcher.camp.SimpleYamlLauncher; -import brooklyn.location.Location; -import brooklyn.management.Task; -import brooklyn.test.EntityTestUtils; -import brooklyn.test.HttpTestUtils; -import brooklyn.test.entity.TestApplication; -import brooklyn.test.entity.TestEntity; -import brooklyn.util.collections.Jsonya; -import brooklyn.util.collections.MutableMap; -import brooklyn.util.collections.MutableSet; -import brooklyn.util.config.ConfigBag; -import brooklyn.util.http.HttpTool; -import brooklyn.util.http.HttpToolResponse; -import brooklyn.util.net.Urls; -import brooklyn.util.repeat.Repeater; -import brooklyn.util.time.Duration; - -import com.google.common.collect.Iterables; - -/** REST-accessible extension of {@link BrooklynNodeTest} */ -public class BrooklynNodeRestTest { - - private static final Logger log = LoggerFactory.getLogger(BrooklynNodeRestTest.class); - - // takes a while when run on its own, because initializing war and making some requests; - // but there are no waits (beyond 10ms), the delay is all classloading; - // and this tests a lot of things, REST API, Brooklyn Node, yaml deployment, - // so feels worth it to have as a unit test - // FIXME[BROOKLYN-43]: Test fails if security is configured in brooklyn.properties. - @Test(groups = "WIP") - public void testBrooklynNodeRestDeployAndMirror() { - final SimpleYamlLauncher l = new SimpleYamlLauncherForTests(); - try { - TestApplication app = ApplicationBuilder.newManagedApp(TestApplication.class, l.getManagementContext()); - - BrooklynNode bn = app.createAndManageChild(EntitySpec.create(BrooklynNode.class, SameBrooklynNodeImpl.class)); - bn.start(MutableSet.<Location>of()); - - URI uri = bn.getAttribute(BrooklynNode.WEB_CONSOLE_URI); - Assert.assertNotNull(uri); - EntityTestUtils.assertAttributeEqualsEventually(bn, Attributes.SERVICE_UP, true); - log.info("Created BrooklynNode: "+bn); - - // deploy - Task<?> t = bn.invoke(BrooklynNode.DEPLOY_BLUEPRINT, ConfigBag.newInstance() - .configure(BrooklynNode.DeployBlueprintEffector.BLUEPRINT_TYPE, TestApplication.class.getName()) - .configure(BrooklynNode.DeployBlueprintEffector.BLUEPRINT_CONFIG, MutableMap.<String,Object>of("x", 1, "y", "Y")) - .getAllConfig()); - log.info("Deployment result: "+t.getUnchecked()); - - MutableSet<Application> apps = MutableSet.copyOf( l.getManagementContext().getApplications() ); - Assert.assertEquals(apps.size(), 2); - apps.remove(app); - - Application newApp = Iterables.getOnlyElement(apps); - Entities.dumpInfo(newApp); - - Assert.assertEquals(newApp.getConfig(new BasicConfigKey<Integer>(Integer.class, "x")), (Integer)1); - - // check mirror - String newAppId = newApp.getId(); - BrooklynEntityMirror mirror = app.createAndManageChild(EntitySpec.create(BrooklynEntityMirror.class) - .configure(BrooklynEntityMirror.MIRRORED_ENTITY_URL, - Urls.mergePaths(uri.toString(), "/v1/applications/"+newAppId+"/entities/"+newAppId)) - .configure(BrooklynEntityMirror.MIRRORED_ENTITY_ID, newAppId) - .configure(BrooklynEntityMirror.POLL_PERIOD, Duration.millis(10))); - - Entities.dumpInfo(mirror); - - EntityTestUtils.assertAttributeEqualsEventually(mirror, Attributes.SERVICE_UP, true); - - ((EntityInternal)newApp).setAttribute(TestEntity.NAME, "foo"); - EntityTestUtils.assertAttributeEqualsEventually(mirror, TestEntity.NAME, "foo"); - log.info("Mirror successfully validated"); - - // also try deploying by invoking deploy through json - // (catch issues when effector params are map) - HttpClient client = HttpTool.httpClientBuilder().build(); - HttpToolResponse result = HttpTool.httpPost(client, URI.create(Urls.mergePaths(uri.toString(), "/v1/applications/"+app.getId()+"/entities/"+bn.getId() - +"/effectors/deployBlueprint")), - MutableMap.of(com.google.common.net.HttpHeaders.CONTENT_TYPE, "application/json"), - Jsonya.newInstance() - .put("blueprintType", TestApplication.class.getName()) - .put("blueprintConfig", MutableMap.of(TestEntity.CONF_NAME.getName(), "foo")) - .toString().getBytes()); - log.info("Deploy effector invoked, result: "+result); - HttpTestUtils.assertHealthyStatusCode( result.getResponseCode() ); - - Repeater.create().every(Duration.millis(10)).until(new Callable<Boolean>() { - @Override - public Boolean call() throws Exception { - return l.getManagementContext().getApplications().size() == 3; - } - }).limitTimeTo(Duration.TEN_SECONDS).runRequiringTrue(); - - apps = MutableSet.copyOf( l.getManagementContext().getApplications() ); - apps.removeAll( MutableSet.of(app, newApp) ); - Application newApp2 = Iterables.getOnlyElement(apps); - Entities.dumpInfo(newApp2); - - EntityTestUtils.assertAttributeEqualsEventually(newApp2, Attributes.SERVICE_UP, true); - Assert.assertEquals(newApp2.getConfig(TestEntity.CONF_NAME), "foo"); - - } finally { - l.destroyAll(); - } - log.info("DONE"); - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6f58ef3e/usage/launcher/src/test/java/brooklyn/entity/database/mssql/MssqlBlueprintLiveTest.java ---------------------------------------------------------------------- diff --git a/usage/launcher/src/test/java/brooklyn/entity/database/mssql/MssqlBlueprintLiveTest.java b/usage/launcher/src/test/java/brooklyn/entity/database/mssql/MssqlBlueprintLiveTest.java deleted file mode 100644 index f5ef36f..0000000 --- a/usage/launcher/src/test/java/brooklyn/entity/database/mssql/MssqlBlueprintLiveTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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.entity.database.mssql; - -import java.io.StringReader; -import java.util.Map; - -import org.testng.annotations.Test; - -import brooklyn.launcher.blueprints.AbstractBlueprintTest; -import brooklyn.util.ResourceUtils; -import brooklyn.util.text.TemplateProcessor; - -import com.google.common.collect.ImmutableMap; - -/** - * Assumes that brooklyn.properties contains something like the following (but with real values!): - * - * {@code - * test.mssql.download.url = http://myserver.com/sql2012.iso - * test.mssql.download.user = myname - * test.mssql.download.password = mypassword - * test.mssql.sa.password = mypassword - * test.mssql.instance.name = MYNAME - * } - */ -public class MssqlBlueprintLiveTest extends AbstractBlueprintTest { - - // TODO Needs further testing - - @Test(groups={"Live"}) - public void testMssql() throws Exception { - Map<String, String> substitutions = ImmutableMap.of( - "mssql.download.url", mgmt.getConfig().getFirst("test.mssql.download.url"), - "mssql.download.user", mgmt.getConfig().getFirst("test.mssql.download.user"), - "mssql.download.password", mgmt.getConfig().getFirst("test.mssql.download.password"), - "mssql.sa.password", mgmt.getConfig().getFirst("test.mssql.sa.password"), - "mssql.instance.name", mgmt.getConfig().getFirst("test.mssql.instance.name")); - - String rawYaml = new ResourceUtils(this).getResourceAsString("mssql-test.yaml"); - String yaml = TemplateProcessor.processTemplateContents(rawYaml, substitutions); - runTest(new StringReader(yaml)); - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6f58ef3e/usage/launcher/src/test/java/brooklyn/launcher/BrooklynLauncherHighAvailabilityTest.java ---------------------------------------------------------------------- diff --git a/usage/launcher/src/test/java/brooklyn/launcher/BrooklynLauncherHighAvailabilityTest.java b/usage/launcher/src/test/java/brooklyn/launcher/BrooklynLauncherHighAvailabilityTest.java deleted file mode 100644 index c20cae8..0000000 --- a/usage/launcher/src/test/java/brooklyn/launcher/BrooklynLauncherHighAvailabilityTest.java +++ /dev/null @@ -1,257 +0,0 @@ -/* - * 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.launcher; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.fail; - -import java.io.File; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import brooklyn.config.BrooklynProperties; -import brooklyn.entity.Application; -import brooklyn.entity.proxying.EntitySpec; -import brooklyn.entity.rebind.RebindTestUtils; -import brooklyn.entity.rebind.persister.PersistMode; -import brooklyn.management.ManagementContext; -import brooklyn.management.ha.HighAvailabilityMode; -import brooklyn.management.ha.ManagementPlaneSyncRecordPersister; -import brooklyn.management.internal.ManagementContextInternal; -import brooklyn.test.Asserts; -import brooklyn.test.entity.LocalManagementContextForTests; -import brooklyn.test.entity.TestApplication; -import brooklyn.util.os.Os; -import brooklyn.util.time.Duration; - -import com.google.common.base.Predicates; -import com.google.common.collect.Iterables; -import com.google.common.io.Files; - -public class BrooklynLauncherHighAvailabilityTest { - - private static final Logger log = LoggerFactory.getLogger(BrooklynLauncherHighAvailabilityTest.class); - - private static final Duration TIMEOUT = Duration.THIRTY_SECONDS; - - private BrooklynLauncher primary; - private BrooklynLauncher secondary; - private BrooklynLauncher tertiary; - private File persistenceDir; - - @BeforeMethod(alwaysRun=true) - public void setUp() throws Exception { - persistenceDir = Files.createTempDir(); - Os.deleteOnExitRecursively(persistenceDir); - } - - @AfterMethod(alwaysRun=true) - public void tearDown() throws Exception { - if (primary != null) primary.terminate(); - primary = null; - if (secondary != null) secondary.terminate(); - secondary = null; - if (tertiary != null) tertiary.terminate(); - tertiary = null; - if (persistenceDir != null) RebindTestUtils.deleteMementoDir(persistenceDir); - persistenceDir = null; - } - - @Test - public void testStandbyTakesOverWhenPrimaryTerminatedGracefully() throws Exception { - doTestStandbyTakesOver(true); - } - - @Test(invocationCount=10, groups="Integration") - /** test issues with termination and promotion; - * previously we got FileNotFound errors, though these should be fixed with - * the various PersistenceObjectStore prepare methods */ - public void testStandbyTakesOverWhenPrimaryTerminatedGracefullyManyTimes() throws Exception { - testStandbyTakesOverWhenPrimaryTerminatedGracefully(); - } - - @Test(groups="Integration") // because slow waiting for timeouts to promote standbys - public void testStandbyTakesOverWhenPrimaryFails() throws Exception { - doTestStandbyTakesOver(false); - } - - protected void doTestStandbyTakesOver(boolean stopGracefully) throws Exception { - log.info("STARTING standby takeover test"); - primary = BrooklynLauncher.newInstance(); - primary.webconsole(false) - .brooklynProperties(LocalManagementContextForTests.setEmptyCatalogAsDefault(BrooklynProperties.Factory.newEmpty())) - .highAvailabilityMode(HighAvailabilityMode.AUTO) - .persistMode(PersistMode.AUTO) - .persistenceDir(persistenceDir) - .persistPeriod(Duration.millis(10)) - .haHeartbeatPeriod(Duration.millis(10)) - .haHeartbeatTimeout(Duration.millis(1000)) - .application(EntitySpec.create(TestApplication.class)) - .start(); - ManagementContext primaryManagementContext = primary.getServerDetails().getManagementContext(); - log.info("started mgmt primary "+primaryManagementContext); - - assertOnlyApp(primary.getServerDetails().getManagementContext(), TestApplication.class); - primaryManagementContext.getRebindManager().getPersister().waitForWritesCompleted(TIMEOUT); - - // Secondary will come up as standby - secondary = BrooklynLauncher.newInstance(); - secondary.webconsole(false) - .brooklynProperties(LocalManagementContextForTests.setEmptyCatalogAsDefault(BrooklynProperties.Factory.newEmpty())) - .highAvailabilityMode(HighAvailabilityMode.AUTO) - .persistMode(PersistMode.AUTO) - .persistenceDir(persistenceDir) - .persistPeriod(Duration.millis(10)) - .haHeartbeatPeriod(Duration.millis(10)) - .haHeartbeatTimeout(Duration.millis(1000)) - .start(); - ManagementContext secondaryManagementContext = secondary.getServerDetails().getManagementContext(); - log.info("started mgmt secondary "+secondaryManagementContext); - - // TODO can assert it sees the apps read only -// assertNoApps(secondary.getServerDetails().getManagementContext()); - - // Terminate primary; expect secondary to take over - if (stopGracefully) { - ((ManagementContextInternal)primaryManagementContext).terminate(); - } else { - ManagementPlaneSyncRecordPersister planePersister = ((ManagementContextInternal)primaryManagementContext).getHighAvailabilityManager().getPersister(); - planePersister.stop(); // can no longer write heartbeats - ((ManagementContextInternal)primaryManagementContext).terminate(); - } - - assertOnlyAppEventually(secondaryManagementContext, TestApplication.class); - - // Start tertiary (force up as standby) - tertiary = BrooklynLauncher.newInstance(); - tertiary.webconsole(false) - .brooklynProperties(LocalManagementContextForTests.setEmptyCatalogAsDefault(BrooklynProperties.Factory.newEmpty())) - .highAvailabilityMode(HighAvailabilityMode.STANDBY) - .persistMode(PersistMode.AUTO) - .persistenceDir(persistenceDir) - .persistPeriod(Duration.millis(10)) - .haHeartbeatPeriod(Duration.millis(10)) - .haHeartbeatTimeout(Duration.millis(1000)) - .start(); - ManagementContext tertiaryManagementContext = tertiary.getServerDetails().getManagementContext(); - log.info("started mgmt tertiary "+primaryManagementContext); - - assertNoApps(tertiary.getServerDetails().getManagementContext()); - - // Terminate secondary; expect tertiary to take over - if (stopGracefully) { - ((ManagementContextInternal)secondaryManagementContext).terminate(); - } else { - ManagementPlaneSyncRecordPersister planePersister = ((ManagementContextInternal)secondaryManagementContext).getHighAvailabilityManager().getPersister(); - planePersister.stop(); // can no longer write heartbeats - ((ManagementContextInternal)secondaryManagementContext).terminate(); - } - - assertOnlyAppEventually(tertiaryManagementContext, TestApplication.class); - } - - public void testHighAvailabilityMasterModeFailsIfAlreadyHasMaster() throws Exception { - primary = BrooklynLauncher.newInstance(); - primary.webconsole(false) - .brooklynProperties(LocalManagementContextForTests.setEmptyCatalogAsDefault(BrooklynProperties.Factory.newEmpty())) - .highAvailabilityMode(HighAvailabilityMode.AUTO) - .persistMode(PersistMode.AUTO) - .persistenceDir(persistenceDir) - .persistPeriod(Duration.millis(10)) - .application(EntitySpec.create(TestApplication.class)) - .start(); - - try { - // Secondary will come up as standby - secondary = BrooklynLauncher.newInstance(); - secondary.webconsole(false) - .brooklynProperties(LocalManagementContextForTests.setEmptyCatalogAsDefault(BrooklynProperties.Factory.newEmpty())) - .highAvailabilityMode(HighAvailabilityMode.MASTER) - .persistMode(PersistMode.AUTO) - .persistenceDir(persistenceDir) - .persistPeriod(Duration.millis(10)) - .start(); - fail(); - } catch (IllegalStateException e) { - // success - } - } - - @Test - public void testHighAvailabilityStandbyModeFailsIfNoExistingMaster() throws Exception { - try { - primary = BrooklynLauncher.newInstance(); - primary.webconsole(false) - .brooklynProperties(LocalManagementContextForTests.setEmptyCatalogAsDefault(BrooklynProperties.Factory.newEmpty())) - .highAvailabilityMode(HighAvailabilityMode.STANDBY) - .persistMode(PersistMode.AUTO) - .persistenceDir(persistenceDir) - .persistPeriod(Duration.millis(10)) - .ignorePersistenceErrors(false) - .application(EntitySpec.create(TestApplication.class)) - .start(); - fail(); - } catch (IllegalStateException e) { - // success - } - } - - @Test - public void testHighAvailabilityHotStandbyModeFailsIfNoExistingMaster() throws Exception { - try { - primary = BrooklynLauncher.newInstance(); - primary.webconsole(false) - .brooklynProperties(LocalManagementContextForTests.setEmptyCatalogAsDefault(BrooklynProperties.Factory.newEmpty())) - .highAvailabilityMode(HighAvailabilityMode.HOT_STANDBY) - .persistMode(PersistMode.AUTO) - .persistenceDir(persistenceDir) - .persistPeriod(Duration.millis(10)) - .ignorePersistenceErrors(false) - .application(EntitySpec.create(TestApplication.class)) - .start(); - fail(); - } catch (IllegalStateException e) { - // success - } - } - - private void assertOnlyApp(ManagementContext managementContext, Class<? extends Application> expectedType) { - assertEquals(managementContext.getApplications().size(), 1, "apps="+managementContext.getApplications()); - assertNotNull(Iterables.find(managementContext.getApplications(), Predicates.instanceOf(TestApplication.class), null), "apps="+managementContext.getApplications()); - } - - private void assertNoApps(ManagementContext managementContext) { - if (!managementContext.getApplications().isEmpty()) - log.warn("FAILED assertion (rethrowing), apps="+managementContext.getApplications()); - assertTrue(managementContext.getApplications().isEmpty(), "apps="+managementContext.getApplications()); - } - - private void assertOnlyAppEventually(final ManagementContext managementContext, final Class<? extends Application> expectedType) { - Asserts.succeedsEventually(new Runnable() { - @Override public void run() { - assertOnlyApp(managementContext, expectedType); - }}); - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6f58ef3e/usage/launcher/src/test/java/brooklyn/launcher/BrooklynLauncherRebindCatalogTest.java ---------------------------------------------------------------------- diff --git a/usage/launcher/src/test/java/brooklyn/launcher/BrooklynLauncherRebindCatalogTest.java b/usage/launcher/src/test/java/brooklyn/launcher/BrooklynLauncherRebindCatalogTest.java deleted file mode 100644 index 7d84d6b..0000000 --- a/usage/launcher/src/test/java/brooklyn/launcher/BrooklynLauncherRebindCatalogTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * 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.launcher; - -import java.io.File; -import java.util.List; - -import javax.annotation.Nullable; - -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.Test; - -import com.google.common.base.Function; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; -import com.google.common.io.Files; - -import org.apache.brooklyn.catalog.BrooklynCatalog; -import org.apache.brooklyn.catalog.CatalogItem; -import brooklyn.catalog.internal.CatalogInitialization; -import brooklyn.entity.rebind.persister.PersistMode; -import brooklyn.test.entity.LocalManagementContextForTests; -import brooklyn.util.ResourceUtils; -import brooklyn.util.os.Os; - -public class BrooklynLauncherRebindCatalogTest { - - private static final String TEST_VERSION = "test-version"; - private static final String CATALOG_INITIAL = "classpath://rebind-test-catalog.bom"; - private static final String CATALOG_ADDITIONS = "rebind-test-catalog-additions.bom"; - private static final Iterable<String> EXPECTED_DEFAULT_IDS = ImmutableSet.of("one:" + TEST_VERSION, "two:" + TEST_VERSION); - private static final Iterable<String> EXPECTED_ADDED_IDS = ImmutableSet.of("three:" + TEST_VERSION, "four:" + TEST_VERSION); - - private List<BrooklynLauncher> launchers = Lists.newCopyOnWriteArrayList(); - - @AfterMethod(alwaysRun=true) - public void tearDown() throws Exception { - for (BrooklynLauncher launcher : launchers) { - launcher.terminate(); - } - launchers.clear(); - } - - private BrooklynLauncher newLauncherForTests(String persistenceDir) { - CatalogInitialization catalogInitialization = new CatalogInitialization(CATALOG_INITIAL, false, null, false); - BrooklynLauncher launcher = BrooklynLauncher.newInstance() - .brooklynProperties(LocalManagementContextForTests.builder(true).buildProperties()) - .catalogInitialization(catalogInitialization) - .persistMode(PersistMode.AUTO) - .persistenceDir(persistenceDir) - .webconsole(false); - launchers.add(launcher); - return launcher; - } - - @Test - public void testRebindDoesNotEffectCatalog() { - String persistenceDir = newTempPersistenceContainerName(); - - BrooklynLauncher launcher = newLauncherForTests(persistenceDir); - launcher.start(); - BrooklynCatalog catalog = launcher.getServerDetails().getManagementContext().getCatalog(); - - assertCatalogConsistsOfIds(catalog.getCatalogItems(), EXPECTED_DEFAULT_IDS); - - catalog.deleteCatalogItem("one", TEST_VERSION); - catalog.deleteCatalogItem("two", TEST_VERSION); - - Assert.assertEquals(Iterables.size(catalog.getCatalogItems()), 0); - - catalog.addItems(new ResourceUtils(this).getResourceAsString(CATALOG_ADDITIONS)); - - assertCatalogConsistsOfIds(catalog.getCatalogItems(), EXPECTED_ADDED_IDS); - - launcher.terminate(); - - BrooklynLauncher newLauncher = newLauncherForTests(persistenceDir); - newLauncher.start(); - assertCatalogConsistsOfIds(newLauncher.getServerDetails().getManagementContext().getCatalog().getCatalogItems(), EXPECTED_ADDED_IDS); - } - - private void assertCatalogConsistsOfIds(Iterable<CatalogItem<Object, Object>> catalogItems, Iterable<String> ids) { - Iterable<String> idsFromItems = Iterables.transform(catalogItems, new Function<CatalogItem<?,?>, String>() { - @Nullable - @Override - public String apply(CatalogItem<?, ?> catalogItem) { - return catalogItem.getCatalogItemId(); - } - }); - Assert.assertTrue(Iterables.elementsEqual(ids, idsFromItems), String.format("Expected %s, found %s", ids, idsFromItems)); - } - - protected String newTempPersistenceContainerName() { - File persistenceDirF = Files.createTempDir(); - Os.deleteOnExitRecursively(persistenceDirF); - return persistenceDirF.getAbsolutePath(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6f58ef3e/usage/launcher/src/test/java/brooklyn/launcher/BrooklynLauncherRebindTestFixture.java ---------------------------------------------------------------------- diff --git a/usage/launcher/src/test/java/brooklyn/launcher/BrooklynLauncherRebindTestFixture.java b/usage/launcher/src/test/java/brooklyn/launcher/BrooklynLauncherRebindTestFixture.java deleted file mode 100644 index 426f939..0000000 --- a/usage/launcher/src/test/java/brooklyn/launcher/BrooklynLauncherRebindTestFixture.java +++ /dev/null @@ -1,256 +0,0 @@ -/* - * 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.launcher; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; - -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import brooklyn.config.BrooklynProperties; -import brooklyn.config.BrooklynServerConfig; -import brooklyn.entity.Application; -import brooklyn.entity.basic.EntityPredicates; -import brooklyn.entity.basic.StartableApplication; -import brooklyn.entity.proxying.EntitySpec; -import brooklyn.entity.rebind.persister.BrooklynMementoPersisterToObjectStore; -import brooklyn.entity.rebind.persister.PersistMode; -import brooklyn.entity.rebind.persister.PersistenceObjectStore; -import brooklyn.location.Location; -import brooklyn.management.ManagementContext; -import brooklyn.management.ha.HighAvailabilityMode; -import brooklyn.test.Asserts; -import brooklyn.test.entity.LocalManagementContextForTests; -import brooklyn.test.entity.TestApplication; -import brooklyn.util.collections.MutableList; -import brooklyn.util.exceptions.FatalConfigurationRuntimeException; -import brooklyn.util.time.Duration; - -import com.google.common.base.Predicates; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Iterables; - -public abstract class BrooklynLauncherRebindTestFixture { - - @SuppressWarnings("unused") - private static final Logger log = LoggerFactory.getLogger(BrooklynLauncherRebindTestFixture.class); - - protected String persistenceDir; - protected String persistenceLocationSpec; - protected List<BrooklynLauncher> launchers = MutableList.of(); - - @BeforeMethod(alwaysRun=true) - public void setUp() throws Exception { - persistenceDir = newTempPersistenceContainerName(); - } - - protected abstract String newTempPersistenceContainerName(); - - @AfterMethod(alwaysRun=true) - public void tearDown() throws Exception { - for (BrooklynLauncher l: launchers) { - if (l.isStarted()) { - l.terminate(); - PersistenceObjectStore store = getPersistenceStore(l.getServerDetails().getManagementContext()); - if (store!=null) store.deleteCompletely(); - } - } - } - - protected BrooklynLauncher newLauncherBase() { - BrooklynLauncher l = BrooklynLauncher.newInstance() - .webconsole(false); - launchers.add(l); - return l; - } - protected BrooklynLauncher newLauncherDefault(PersistMode mode) { - return newLauncherBase() - .managementContext(newManagementContextForTests(null)) - .persistMode(mode) - .persistenceDir(persistenceDir) - .persistPeriod(Duration.millis(10)); - } - protected LocalManagementContextForTests newManagementContextForTests(BrooklynProperties props) { - if (props==null) - return new LocalManagementContextForTests(); - else - return new LocalManagementContextForTests(props); - } - - protected ManagementContext lastMgmt() { - return Iterables.getLast(launchers).getServerDetails().getManagementContext(); - } - - @Test - public void testRebindsToExistingApp() throws Exception { - populatePersistenceDir(persistenceDir, EntitySpec.create(TestApplication.class).displayName("myorig")); - - // Rebind to the app we just started last time - - newLauncherDefault(PersistMode.REBIND).start(); - - assertOnlyApp(lastMgmt(), TestApplication.class); - assertNotNull(Iterables.find(lastMgmt().getApplications(), EntityPredicates.displayNameEqualTo("myorig"), null), "apps="+lastMgmt().getApplications()); - } - - @Test - public void testRebindCanAddNewApps() throws Exception { - populatePersistenceDir(persistenceDir, EntitySpec.create(TestApplication.class).displayName("myorig")); - - // Rebind to the app we started last time - newLauncherDefault(PersistMode.REBIND) - .application(EntitySpec.create(TestApplication.class).displayName("mynew")) - .start(); - - // New app was added, and orig app was rebound - assertEquals(lastMgmt().getApplications().size(), 2, "apps="+lastMgmt().getApplications()); - assertNotNull(Iterables.find(lastMgmt().getApplications(), EntityPredicates.displayNameEqualTo("mynew"), null), "apps="+lastMgmt().getApplications()); - - // And subsequently can create new apps - StartableApplication app3 = lastMgmt().getEntityManager().createEntity( - EntitySpec.create(TestApplication.class).displayName("mynew2")); - app3.start(ImmutableList.<Location>of()); - } - - @Test - public void testAutoRebindsToExistingApp() throws Exception { - EntitySpec<TestApplication> appSpec = EntitySpec.create(TestApplication.class); - populatePersistenceDir(persistenceDir, appSpec); - - // Auto will rebind if the dir exists - newLauncherDefault(PersistMode.AUTO).start(); - - assertOnlyApp(lastMgmt(), TestApplication.class); - } - - @Test - public void testCleanDoesNotRebindToExistingApp() throws Exception { - EntitySpec<TestApplication> appSpec = EntitySpec.create(TestApplication.class); - populatePersistenceDir(persistenceDir, appSpec); - - // Auto will rebind if the dir exists - newLauncherDefault(PersistMode.CLEAN).start(); - - assertTrue(lastMgmt().getApplications().isEmpty(), "apps="+lastMgmt().getApplications()); - } - - @Test - public void testAutoRebindCreatesNewIfEmptyDir() throws Exception { - // Auto will rebind if the dir exists - newLauncherDefault(PersistMode.AUTO) - .application(EntitySpec.create(TestApplication.class)) - .start(); - - assertOnlyApp(lastMgmt(), TestApplication.class); - assertMementoContainerNonEmptyForTypeEventually("entities"); - } - - @Test - public void testRebindRespectsPersistenceDirSetInProperties() throws Exception { - String persistenceDir2 = newTempPersistenceContainerName(); - - BrooklynProperties brooklynProperties = BrooklynProperties.Factory.newDefault(); - brooklynProperties.put(BrooklynServerConfig.PERSISTENCE_DIR, persistenceDir2); - LocalManagementContextForTests mgmt = newManagementContextForTests(brooklynProperties); - - // Rebind to the app we started last time - newLauncherBase() - .persistMode(PersistMode.AUTO) - .persistPeriod(Duration.millis(10)) - .managementContext(mgmt) - .start(); - - checkPersistenceContainerNameIs(persistenceDir2); - } - - // assumes default persistence dir is rebindable - @Test(groups="Integration") - public void testRebindRespectsDefaultPersistenceDir() throws Exception { - newLauncherDefault(PersistMode.AUTO) - .persistenceDir((String)null) - .start(); - - checkPersistenceContainerNameIsDefault(); - } - - protected abstract void checkPersistenceContainerNameIsDefault(); - protected abstract void checkPersistenceContainerNameIs(String expected); - - @Test - public void testPersistenceFailsIfNoDir() throws Exception { - runRebindFails(PersistMode.REBIND, badContainerName(), "does not exist"); - } - - protected abstract String badContainerName(); - - @Test - public void testExplicitRebindFailsIfEmpty() throws Exception { - runRebindFails(PersistMode.REBIND, persistenceDir, "directory is empty"); - } - - protected void runRebindFails(PersistMode persistMode, String dir, String errmsg) throws Exception { - try { - newLauncherDefault(persistMode) - .persistenceDir(dir) - .start(); - } catch (FatalConfigurationRuntimeException e) { - if (!e.toString().contains(errmsg)) { - throw e; - } - } - } - - protected void populatePersistenceDir(String dir, EntitySpec<? extends StartableApplication> appSpec) throws Exception { - BrooklynLauncher launcher = newLauncherDefault(PersistMode.CLEAN) - .highAvailabilityMode(HighAvailabilityMode.MASTER) - .persistenceDir(dir) - .application(appSpec) - .start(); - launcher.terminate(); - assertMementoContainerNonEmptyForTypeEventually("entities"); - } - - protected void assertOnlyApp(ManagementContext managementContext, Class<? extends Application> expectedType) { - assertEquals(managementContext.getApplications().size(), 1, "apps="+managementContext.getApplications()); - assertNotNull(Iterables.find(managementContext.getApplications(), Predicates.instanceOf(TestApplication.class), null), "apps="+managementContext.getApplications()); - } - - protected void assertMementoContainerNonEmptyForTypeEventually(final String type) { - Asserts.succeedsEventually(ImmutableMap.of("timeout", Duration.TEN_SECONDS), new Runnable() { - @Override public void run() { - getPersistenceStore(lastMgmt()).listContentsWithSubPath(type); - }}); - } - - static PersistenceObjectStore getPersistenceStore(ManagementContext managementContext) { - if (managementContext==null) return null; - BrooklynMementoPersisterToObjectStore persister = (BrooklynMementoPersisterToObjectStore)managementContext.getRebindManager().getPersister(); - if (persister==null) return null; - return persister.getObjectStore(); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6f58ef3e/usage/launcher/src/test/java/brooklyn/launcher/BrooklynLauncherRebindTestToFiles.java ---------------------------------------------------------------------- diff --git a/usage/launcher/src/test/java/brooklyn/launcher/BrooklynLauncherRebindTestToFiles.java b/usage/launcher/src/test/java/brooklyn/launcher/BrooklynLauncherRebindTestToFiles.java deleted file mode 100644 index 57b8682..0000000 --- a/usage/launcher/src/test/java/brooklyn/launcher/BrooklynLauncherRebindTestToFiles.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * 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.launcher; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotEquals; -import static org.testng.Assert.assertTrue; - -import java.io.File; - -import org.testng.annotations.Test; - -import brooklyn.config.BrooklynProperties; -import brooklyn.config.BrooklynServerPaths; -import brooklyn.entity.proxying.EntitySpec; -import brooklyn.entity.rebind.persister.BrooklynMementoPersisterToObjectStore; -import brooklyn.entity.rebind.persister.FileBasedObjectStore; -import brooklyn.entity.rebind.persister.PersistMode; -import brooklyn.management.ManagementContext; -import brooklyn.management.ha.HighAvailabilityMode; -import brooklyn.test.entity.TestApplication; -import brooklyn.util.javalang.JavaClassNames; -import brooklyn.util.os.Os; -import brooklyn.util.text.Identifiers; - -import com.google.common.base.Joiner; -import com.google.common.io.Files; - -public class BrooklynLauncherRebindTestToFiles extends BrooklynLauncherRebindTestFixture { - - protected String newTempPersistenceContainerName() { - File persistenceDirF = Files.createTempDir(); - Os.deleteOnExitRecursively(persistenceDirF); - return persistenceDirF.getAbsolutePath(); - } - - protected String badContainerName() { - return "/path/does/not/exist/"+Identifiers.makeRandomId(4); - } - - protected void checkPersistenceContainerNameIs(String expected) { - String expectedFqp = new File(Os.tidyPath(expected)).getAbsolutePath(); - assertEquals(getPersistenceDir(lastMgmt()).getAbsolutePath(), expectedFqp); - } - - static File getPersistenceDir(ManagementContext managementContext) { - BrooklynMementoPersisterToObjectStore persister = (BrooklynMementoPersisterToObjectStore)managementContext.getRebindManager().getPersister(); - FileBasedObjectStore store = (FileBasedObjectStore)persister.getObjectStore(); - return store.getBaseDir(); - } - - protected void checkPersistenceContainerNameIsDefault() { - String expected = BrooklynServerPaths.newMainPersistencePathResolver(BrooklynProperties.Factory.newEmpty()).location(null).dir(null).resolve(); - checkPersistenceContainerNameIs(expected); - } - - @Test - public void testPersistenceFailsIfIsFile() throws Exception { - File tempF = File.createTempFile("test-"+JavaClassNames.niceClassAndMethod(), ".not_dir"); - tempF.deleteOnExit(); - String tempFileName = tempF.getAbsolutePath(); - - try { - runRebindFails(PersistMode.AUTO, tempFileName, "must not be a file"); - runRebindFails(PersistMode.REBIND, tempFileName, "must not be a file"); - runRebindFails(PersistMode.CLEAN, tempFileName, "must not be a file"); - } finally { - new File(tempFileName).delete(); - } - } - - @Test - public void testPersistenceFailsIfNotWritable() throws Exception { - EntitySpec<TestApplication> appSpec = EntitySpec.create(TestApplication.class); - populatePersistenceDir(persistenceDir, appSpec); - new File(persistenceDir).setWritable(false); - try { - runRebindFails(PersistMode.AUTO, persistenceDir, "not writable"); - runRebindFails(PersistMode.REBIND, persistenceDir, "not writable"); - runRebindFails(PersistMode.CLEAN, persistenceDir, "not writable"); - } finally { - new File(persistenceDir).setWritable(true); - } - } - - @Test - public void testPersistenceFailsIfNotReadable() throws Exception { - EntitySpec<TestApplication> appSpec = EntitySpec.create(TestApplication.class); - populatePersistenceDir(persistenceDir, appSpec); - new File(persistenceDir).setReadable(false); - try { - runRebindFails(PersistMode.AUTO, persistenceDir, "not readable"); - runRebindFails(PersistMode.REBIND, persistenceDir, "not readable"); - runRebindFails(PersistMode.CLEAN, persistenceDir, "not readable"); - } finally { - new File(persistenceDir).setReadable(true); - } - } - - @Test(groups="Integration") - public void testCopyPersistedState() throws Exception { - EntitySpec<TestApplication> appSpec = EntitySpec.create(TestApplication.class); - populatePersistenceDir(persistenceDir, appSpec); - - File destinationDir = Files.createTempDir(); - String destination = destinationDir.getAbsolutePath(); - String destinationLocation = null; // i.e. file system, rather than object store - try { - // Auto will rebind if the dir exists - BrooklynLauncher launcher = newLauncherDefault(PersistMode.AUTO) - .highAvailabilityMode(HighAvailabilityMode.MASTER) - .webconsole(false); - launcher.copyPersistedState(destination, destinationLocation); - launcher.terminate(); - - File entities = new File(Os.mergePaths(destination), "entities"); - assertTrue(entities.isDirectory(), "entities directory should exist"); - assertEquals(entities.listFiles().length, 1, "entities directory should contain one file (contained: "+ - Joiner.on(", ").join(entities.listFiles()) +")"); - - File nodes = new File(Os.mergePaths(destination, "nodes")); - assertTrue(nodes.isDirectory(), "nodes directory should exist"); - assertNotEquals(nodes.listFiles().length, 0, "nodes directory should not be empty"); - - // Should now have a usable copy in the destinationDir - // Auto will rebind if the dir exists - newLauncherDefault(PersistMode.AUTO) - .webconsole(false) - .persistenceDir(destinationDir) - .start(); - assertOnlyApp(lastMgmt(), TestApplication.class); - - } finally { - Os.deleteRecursively(destinationDir); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6f58ef3e/usage/launcher/src/test/java/brooklyn/launcher/BrooklynLauncherRebindToCloudObjectStoreTest.java ---------------------------------------------------------------------- diff --git a/usage/launcher/src/test/java/brooklyn/launcher/BrooklynLauncherRebindToCloudObjectStoreTest.java b/usage/launcher/src/test/java/brooklyn/launcher/BrooklynLauncherRebindToCloudObjectStoreTest.java deleted file mode 100644 index 258ba5b..0000000 --- a/usage/launcher/src/test/java/brooklyn/launcher/BrooklynLauncherRebindToCloudObjectStoreTest.java +++ /dev/null @@ -1,174 +0,0 @@ -/* - * 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.launcher; - -import static org.testng.Assert.assertEquals; - -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import brooklyn.config.BrooklynProperties; -import brooklyn.config.BrooklynServerPaths; -import brooklyn.entity.proxying.EntitySpec; -import brooklyn.entity.rebind.persister.BrooklynMementoPersisterToObjectStore; -import brooklyn.entity.rebind.persister.PersistMode; -import brooklyn.entity.rebind.persister.jclouds.BlobStoreTest; -import brooklyn.entity.rebind.persister.jclouds.JcloudsBlobStoreBasedObjectStore; -import brooklyn.management.ManagementContext; -import brooklyn.mementos.BrooklynMementoRawData; -import brooklyn.test.entity.LocalManagementContextForTests; -import brooklyn.test.entity.TestApplication; -import brooklyn.util.javalang.JavaClassNames; -import brooklyn.util.os.Os; -import brooklyn.util.text.Identifiers; - -@Test(groups="Live") -public class BrooklynLauncherRebindToCloudObjectStoreTest extends BrooklynLauncherRebindTestFixture { - - // FIXME BrooklynLauncherRebindToCloudObjectStoreTest.testCleanDoesNotRebindToExistingApp failed: - // apps=[Application[mDNfOA7w]] expected [true] but found [false] - // Should it really delete everything in the bucket?! Only if we can back up first! - - // FIXME brooklyn.util.exceptions.FatalRuntimeException: Error rebinding to persisted state: Writes not allowed in brooklyn.entity.rebind.persister.BrooklynMementoPersisterToObjectStore@7d2f7563 - // at brooklyn.launcher.BrooklynLauncher.persistState(BrooklynLauncher.java:502) - // at brooklyn.launcher.BrooklynLauncherRebindToCloudObjectStoreTest.testCopyPersistedState(BrooklynLauncherRebindToCloudObjectStoreTest.java:144) - // Presumably a previous run wasn't tearing down properly, so it joined as a standby rather than being master?! - - { persistenceLocationSpec = BlobStoreTest.PERSIST_TO_OBJECT_STORE_FOR_TEST_SPEC; } - - @BeforeMethod(alwaysRun=true) - public void setUp() throws Exception { - persistenceDir = newTempPersistenceContainerName(); - } - - @Override - protected BrooklynLauncher newLauncherBase() { - return super.newLauncherBase().persistenceLocation(persistenceLocationSpec); - } - - protected LocalManagementContextForTests newManagementContextForTests(BrooklynProperties props) { - BrooklynProperties p2 = BrooklynProperties.Factory.newDefault(); - if (props!=null) p2.putAll(props); - return new LocalManagementContextForTests(p2); - } - - @Override - protected String newTempPersistenceContainerName() { - return "test-"+JavaClassNames.callerStackElement(0).getClassName()+"-"+Identifiers.makeRandomId(4); - } - - protected String badContainerName() { - return "container-does-not-exist-"+Identifiers.makeRandomId(4); - } - - protected void checkPersistenceContainerNameIs(String expected) { - assertEquals(getPersistenceContainerName(lastMgmt()), expected); - } - - static String getPersistenceContainerName(ManagementContext managementContext) { - BrooklynMementoPersisterToObjectStore persister = (BrooklynMementoPersisterToObjectStore)managementContext.getRebindManager().getPersister(); - JcloudsBlobStoreBasedObjectStore store = (JcloudsBlobStoreBasedObjectStore)persister.getObjectStore(); - return store.getContainerName(); - } - - protected void checkPersistenceContainerNameIsDefault() { - checkPersistenceContainerNameIs(BrooklynServerPaths.DEFAULT_PERSISTENCE_CONTAINER_NAME); - } - - @Override @Test(groups="Live") - public void testRebindsToExistingApp() throws Exception { - super.testRebindsToExistingApp(); - } - - @Override @Test(groups="Live") - public void testRebindCanAddNewApps() throws Exception { - super.testRebindCanAddNewApps(); - } - - @Override @Test(groups="Live") - public void testAutoRebindsToExistingApp() throws Exception { - super.testAutoRebindsToExistingApp(); - } - - // TODO Marked as work-in-progress because "clean" does not backup and then clean out the existing - // object store's bucket. Unclear what best behaviour there should be: should we really delete - // the data?! We better be confident about our backup! - @Override @Test(groups={"Live", "WIP"}) - public void testCleanDoesNotRebindToExistingApp() throws Exception { - super.testCleanDoesNotRebindToExistingApp(); - } - - @Override @Test(groups="Live") - public void testAutoRebindCreatesNewIfEmptyDir() throws Exception { - super.testAutoRebindCreatesNewIfEmptyDir(); - } - - @Override @Test(groups="Live") - public void testRebindRespectsPersistenceDirSetInProperties() throws Exception { - super.testRebindRespectsPersistenceDirSetInProperties(); - } - - @Override @Test(groups="Live") - public void testRebindRespectsDefaultPersistenceDir() throws Exception { - super.testRebindRespectsDefaultPersistenceDir(); - } - - @Override @Test(groups="Live") - public void testPersistenceFailsIfNoDir() throws Exception { - super.testPersistenceFailsIfNoDir(); - } - - @Override @Test(groups="Live") - public void testExplicitRebindFailsIfEmpty() throws Exception { - super.testExplicitRebindFailsIfEmpty(); - } - - // TODO Remove duplication from BrooklynLauncherRebindTestToFiles.testCopyPersistedState() - @Test(groups="Live") - public void testCopyPersistedState() throws Exception { - EntitySpec<TestApplication> appSpec = EntitySpec.create(TestApplication.class); - populatePersistenceDir(persistenceDir, appSpec); - - String destinationDir = newTempPersistenceContainerName(); - String destinationLocation = persistenceLocationSpec; - try { - // Auto will rebind if the dir exists - BrooklynLauncher launcher = newLauncherDefault(PersistMode.AUTO) - .webconsole(false) - .persistenceLocation(persistenceLocationSpec); - BrooklynMementoRawData memento = launcher.retrieveState(); - launcher.persistState(memento, destinationDir, destinationLocation); - launcher.terminate(); - - assertEquals(memento.getEntities().size(), 1, "entityMementos="+memento.getEntities().keySet()); - - // Should now have a usable copy in the destionationDir - // Auto will rebind if the dir exists - newLauncherDefault(PersistMode.AUTO) - .webconsole(false) - .persistenceDir(destinationDir) - .persistenceLocation(destinationLocation) - .start(); - assertOnlyApp(lastMgmt(), TestApplication.class); - - } finally { - Os.deleteRecursively(destinationDir); - } - } -}
