From 407c7a1a60f4a1f936c54318766f1b3e2b70df82 Mon Sep 17 00:00:00 2001 From: Valentin Aitken Date: Fri, 26 Jun 2015 13:13:21 +0300 Subject: [PATCH 1/3] Fix java version check - if it is used openjdk java -version returns `openjdk version "1.8.0_45"' which wasn't matched correctly previously --- .../java/brooklyn/entity/java/JavaSoftwareProcessSshDriver.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/software/base/src/main/java/brooklyn/entity/java/JavaSoftwareProcessSshDriver.java b/software/base/src/main/java/brooklyn/entity/java/JavaSoftwareProcessSshDriver.java index 08ccfcb9b6..79cef17e1f 100644 --- a/software/base/src/main/java/brooklyn/entity/java/JavaSoftwareProcessSshDriver.java +++ b/software/base/src/main/java/brooklyn/entity/java/JavaSoftwareProcessSshDriver.java @@ -336,7 +336,7 @@ protected Optional getInstalledJavaVersion() { log.debug("Checking Java version at {}@{}", getEntity(), getLocation()); // sed gets stdin like 'java version "1.7.0_45"' ProcessTaskWrapper versionCommand = Entities.submit(getEntity(), SshTasks.newSshExecTaskFactory( - getLocation(), "java -version 2>&1 | grep \"java version\" | sed 's/.*\"\\(.*\\).*\"/\\1/'")); + getLocation(), "java -version 2>&1 | grep \" version\" | sed 's/.*\"\\(.*\\).*\"/\\1/'")); versionCommand.get(); String stdOut = versionCommand.getStdout().trim(); if (!Strings.isBlank(stdOut)) { From dbeef9187d9a5e7907f7bd9e58ac68173c8b0f3d Mon Sep 17 00:00:00 2001 From: Valentin Aitken Date: Fri, 26 Jun 2015 15:52:00 +0300 Subject: [PATCH 2/3] yum fix - Add EPEL if missing - This fixes installation of nodejs for CentOS 7 and the NodeJsWebAppFixtureIntegrationTest respectively --- utils/common/src/main/java/brooklyn/util/ssh/BashCommands.java | 1 + .../src/test/java/brooklyn/util/ssh/IptablesCommandsTest.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/common/src/main/java/brooklyn/util/ssh/BashCommands.java b/utils/common/src/main/java/brooklyn/util/ssh/BashCommands.java index 21b87d15b7..570551dc30 100644 --- a/utils/common/src/main/java/brooklyn/util/ssh/BashCommands.java +++ b/utils/common/src/main/java/brooklyn/util/ssh/BashCommands.java @@ -376,6 +376,7 @@ public static String installPackageOr(Map flags, String packageDefaultName, chainGroup( "echo yum exists, doing update", ok(sudo("yum check-update")), + ok(sudo("yum -y install epel-release")), sudo(yumInstall)))); if (brewInstall != null) commands.add(ifExecutableElse1("brew", brewInstall)); diff --git a/utils/common/src/test/java/brooklyn/util/ssh/IptablesCommandsTest.java b/utils/common/src/test/java/brooklyn/util/ssh/IptablesCommandsTest.java index afec6be078..7d90dbfc82 100644 --- a/utils/common/src/test/java/brooklyn/util/ssh/IptablesCommandsTest.java +++ b/utils/common/src/test/java/brooklyn/util/ssh/IptablesCommandsTest.java @@ -40,7 +40,7 @@ public class IptablesCommandsTest { private static final String saveIptablesRules = "( ( if test \"$UID\" -eq 0; then ( service iptables save ); else sudo -E -n -S -- service iptables save; fi ) || " + "( ( { which zypper && { echo zypper exists, doing refresh && (( if test \"$UID\" -eq 0; then ( zypper --non-interactive --no-gpg-checks refresh ); else sudo -E -n -S -- zypper --non-interactive --no-gpg-checks refresh; fi ) || true) && ( if test \"$UID\" -eq 0; then ( zypper --non-interactive --no-gpg-checks install iptables-persistent ); else sudo -E -n -S -- zypper --non-interactive --no-gpg-checks install iptables-persistent; fi ) ; } ; } || " + "{ which apt-get && { echo apt-get exists, doing update && export DEBIAN_FRONTEND=noninteractive && (( if test \"$UID\" -eq 0; then ( apt-get update ); else sudo -E -n -S -- apt-get update; fi ) || true) && ( if test \"$UID\" -eq 0; then ( apt-get install -y --allow-unauthenticated iptables-persistent ); else sudo -E -n -S -- apt-get install -y --allow-unauthenticated iptables-persistent; fi ) ; } ; } || " + - "{ which yum && { echo yum exists, doing update && (( if test \"$UID\" -eq 0; then ( yum check-update ); else sudo -E -n -S -- yum check-update; fi ) || true) && ( if test \"$UID\" -eq 0; then ( yum -y --nogpgcheck install iptables-persistent ); else sudo -E -n -S -- yum -y --nogpgcheck install iptables-persistent; fi ) ; } ; } || " + + "{ which yum && { echo yum exists, doing update && (( if test \"$UID\" -eq 0; then ( yum check-update ); else sudo -E -n -S -- yum check-update; fi ) || true) && (( if test \"$UID\" -eq 0; then ( yum -y install epel-release ); else sudo -E -n -S -- yum -y install epel-release; fi ) || true) && ( if test \"$UID\" -eq 0; then ( yum -y --nogpgcheck install iptables-persistent ); else sudo -E -n -S -- yum -y --nogpgcheck install iptables-persistent; fi ) ; } ; } || " + "{ which brew && brew install iptables-persistent ; } || " + "{ which port && ( if test \"$UID\" -eq 0; then ( port install iptables-persistent ); else sudo -E -n -S -- port install iptables-persistent; fi ) ; } || " + "(( echo \"WARNING: no known/successful package manager to install iptables-persistent, may fail subsequently\" | tee /dev/stderr ) || true) ) && ( if test \"$UID\" -eq 0; then ( /etc/init.d/iptables-persistent save ); else sudo -E -n -S -- /etc/init.d/iptables-persistent save; fi ) ) )"; From 625bc6fa51dfbc7591a136e957027af322703ca3 Mon Sep 17 00:00:00 2001 From: Valentin Aitken Date: Fri, 26 Jun 2015 17:10:43 +0300 Subject: [PATCH 3/3] Fix NodeJS Integration test to stop the service with the generic stop --- .../AbstractWebAppFixtureIntegrationTest.java | 3 +- .../NodeJsWebAppFixtureIntegrationTest.java | 74 ++++++------------- 2 files changed, 23 insertions(+), 54 deletions(-) diff --git a/software/webapp/src/test/java/brooklyn/entity/webapp/AbstractWebAppFixtureIntegrationTest.java b/software/webapp/src/test/java/brooklyn/entity/webapp/AbstractWebAppFixtureIntegrationTest.java index 7bc175c820..6498c32089 100644 --- a/software/webapp/src/test/java/brooklyn/entity/webapp/AbstractWebAppFixtureIntegrationTest.java +++ b/software/webapp/src/test/java/brooklyn/entity/webapp/AbstractWebAppFixtureIntegrationTest.java @@ -37,6 +37,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import brooklyn.entity.basic.SoftwareProcessDriver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.annotations.AfterClass; @@ -235,7 +236,7 @@ public void testReportsServiceDownWhenKilled(final SoftwareProcess entity) throw * Stop the given underlying entity, but without our entity instance being told! */ protected void killEntityBehindBack(Entity tokill) throws Exception { - ((JavaWebAppDriver)((DriverDependentEntity)Entities.deproxy(entity)).getDriver()).stop(); + ((SoftwareProcessDriver)((DriverDependentEntity) Entities.deproxy(entity)).getDriver()).stop(); // old method of doing this did some dodgy legacy rebind and failed due to too many dangling refs; above is better in any case // but TODO we should have some rebind tests for these! } diff --git a/software/webapp/src/test/java/brooklyn/entity/webapp/nodejs/NodeJsWebAppFixtureIntegrationTest.java b/software/webapp/src/test/java/brooklyn/entity/webapp/nodejs/NodeJsWebAppFixtureIntegrationTest.java index 3221c05890..d567448fbb 100644 --- a/software/webapp/src/test/java/brooklyn/entity/webapp/nodejs/NodeJsWebAppFixtureIntegrationTest.java +++ b/software/webapp/src/test/java/brooklyn/entity/webapp/nodejs/NodeJsWebAppFixtureIntegrationTest.java @@ -18,44 +18,32 @@ */ package brooklyn.entity.webapp.nodejs; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; - -import java.io.File; -import java.util.concurrent.TimeUnit; - -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.entity.Entity; import brooklyn.entity.basic.Entities; -import brooklyn.entity.basic.EntityInternal; -import brooklyn.entity.basic.SoftwareProcess; +import brooklyn.entity.basic.SoftwareProcessDriver; +import brooklyn.entity.drivers.DriverDependentEntity; import brooklyn.entity.proxying.EntitySpec; -import brooklyn.entity.rebind.PersistenceExceptionHandlerImpl; -import brooklyn.entity.rebind.dto.MementosGenerators; -import brooklyn.entity.rebind.persister.BrooklynMementoPersisterToMultiFile; import brooklyn.entity.trait.Startable; import brooklyn.entity.webapp.WebAppService; import brooklyn.location.Location; import brooklyn.location.basic.PortRanges; import brooklyn.management.ManagementContext; -import brooklyn.management.ha.ManagementNodeState; -import brooklyn.management.internal.ManagementContextInternal; -import brooklyn.mementos.BrooklynMemento; 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.collections.MutableMap; import brooklyn.util.net.Urls; -import brooklyn.util.os.Os; - +import brooklyn.util.time.Duration; import com.google.common.collect.ImmutableList; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; /** * Integration tests for NodeJS. @@ -104,7 +92,7 @@ public void setUp() throws Exception { app = TestApplication.Factory.newManagedInstanceForTests(); mgmt = app.getManagementContext(); loc = app.newLocalhostProvisioningLocation(); - + entity = app.createAndManageChild(EntitySpec.create(NodeJsWebAppService.class) .configure(NodeJsWebAppService.HTTP_PORT, PortRanges.fromString(DEFAULT_HTTP_PORT)) .configure("gitRepoUrl", GIT_REPO_URL) @@ -124,7 +112,7 @@ public void tearDown() { @Test(groups = "Integration") public void testCanStartAndStop() { LOG.info("test=canStartAndStop; entity="+entity+"; app="+entity.getApplication()); - + Entities.start(entity.getApplication(), ImmutableList.of(loc)); Asserts.succeedsEventually(MutableMap.of("timeout", 120*1000), new Runnable() { public void run() { @@ -134,7 +122,7 @@ public void run() { entity.stop(); assertFalse(entity.getAttribute(Startable.SERVICE_UP)); } - + /** * Checks an entity can start, set SERVICE_UP to true and shutdown again. */ @@ -143,7 +131,7 @@ public void testReportsServiceDownWhenKilled() throws Exception { LOG.info("test=testReportsServiceDownWithKilled; entity="+entity+"; app="+entity.getApplication()); Entities.start(entity.getApplication(), ImmutableList.of(loc)); - EntityTestUtils.assertAttributeEqualsEventually(MutableMap.of("timeout", 120*1000), entity, Startable.SERVICE_UP, true); + EntityTestUtils.assertAttributeEqualsEventually(MutableMap.of("timeout", Duration.minutes(2)), entity, Startable.SERVICE_UP, true); // Stop the underlying entity, but without our entity instance being told! killEntityBehindBack(entity); @@ -153,36 +141,16 @@ public void testReportsServiceDownWhenKilled() throws Exception { LOG.info("success getting service up false in primary mgmt universe"); } - + /** * Stop the given underlying entity, but without our entity instance being told! */ protected void killEntityBehindBack(Entity tokill) throws Exception { - // Previously was calling entity.getDriver().kill(); but now our entity instance is a proxy so can't do that - ManagementContext newManagementContext = null; - File tempDir = Os.newTempDir(getClass()); - try { - ManagementContext managementContext = ((EntityInternal)tokill).getManagementContext(); - BrooklynMemento brooklynMemento = MementosGenerators.newBrooklynMemento(managementContext); - - BrooklynMementoPersisterToMultiFile oldPersister = new BrooklynMementoPersisterToMultiFile(tempDir , getClass().getClassLoader()); - oldPersister.checkpoint(brooklynMemento, PersistenceExceptionHandlerImpl.builder().build()); - oldPersister.waitForWritesCompleted(30*1000, TimeUnit.MILLISECONDS); - - BrooklynMementoPersisterToMultiFile newPersister = new BrooklynMementoPersisterToMultiFile(tempDir , getClass().getClassLoader()); - newManagementContext = new LocalManagementContextForTests(); - newManagementContext.getRebindManager().setPersister(newPersister, PersistenceExceptionHandlerImpl.builder().build()); - newManagementContext.getRebindManager().rebind(getClass().getClassLoader(), null, ManagementNodeState.MASTER); - newManagementContext.getRebindManager().startPersistence(); - SoftwareProcess entity2 = (SoftwareProcess) newManagementContext.getEntityManager().getEntity(tokill.getId()); - entity2.stop(); - } finally { - if (newManagementContext != null) ((ManagementContextInternal)newManagementContext).terminate(); - Os.deleteRecursively(tempDir.getAbsolutePath()); - } - LOG.info("called to stop {} in parallel mgmt universe", entity); + ((SoftwareProcessDriver)((DriverDependentEntity) Entities.deproxy(tokill)).getDriver()).stop(); + // old method of doing this did some dodgy legacy rebind and failed due to too many dangling refs; above is better in any case + // but TODO we should have some rebind tests for these! } - + @Test(groups = "Integration") public void testInitialNamedDeployments() { final String urlSubPathToWebApp = APP_NAME; @@ -191,7 +159,7 @@ public void testInitialNamedDeployments() { Entities.start(entity.getApplication(), ImmutableList.of(loc)); - Asserts.succeedsEventually(MutableMap.of("timeout", 60*1000), new Runnable() { + Asserts.succeedsEventually(MutableMap.of("timeout", Duration.minutes(1)), new Runnable() { public void run() { // TODO get this URL from a web-app entity of some kind? String url = Urls.mergePaths(entity.getAttribute(WebAppService.ROOT_URL), urlSubPathToWebApp, urlSubPathToPageToQuery);