Adds SshMachineLocation.SSH_TOOL_CLASS - Deprecates SshTool.PROP_TOOL_CLASS - Adds tests
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/6860e046 Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/6860e046 Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/6860e046 Branch: refs/heads/master Commit: 6860e0460910eb171750193f8970332489bbfdbe Parents: bbecf36 Author: Aled Sage <[email protected]> Authored: Tue Nov 10 00:36:05 2015 +0000 Committer: Aled Sage <[email protected]> Committed: Thu Nov 12 13:11:42 2015 +0000 ---------------------------------------------------------------------- .../core/entity/BrooklynConfigKeys.java | 12 ++- .../location/ssh/SshMachineLocation.java | 77 +++++++++----- .../util/core/internal/ssh/SshTool.java | 14 ++- .../SshMachineLocationReuseIntegrationTest.java | 11 +- .../ssh/SshMachineLocationSshToolTest.java | 96 +++++++++++++++++ .../location/ssh/SshMachineLocationTest.java | 27 ++--- .../brooklyn/entity/java/JavaOptsTest.java | 17 ++- .../entity/software/base/EntitySshToolTest.java | 103 +++++++++++++++++++ .../base/lifecycle/StartStopSshDriverTest.java | 2 + .../nginx/NginxRebindWithHaIntegrationTest.java | 9 +- 10 files changed, 306 insertions(+), 62 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6860e046/core/src/main/java/org/apache/brooklyn/core/entity/BrooklynConfigKeys.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/BrooklynConfigKeys.java b/core/src/main/java/org/apache/brooklyn/core/entity/BrooklynConfigKeys.java index c1ad143..1185791 100644 --- a/core/src/main/java/org/apache/brooklyn/core/entity/BrooklynConfigKeys.java +++ b/core/src/main/java/org/apache/brooklyn/core/entity/BrooklynConfigKeys.java @@ -31,6 +31,7 @@ import org.apache.brooklyn.core.entity.trait.Startable; import org.apache.brooklyn.core.sensor.AttributeSensorAndConfigKey; import org.apache.brooklyn.core.sensor.TemplatedStringAttributeSensorAndConfigKey; import org.apache.brooklyn.core.server.BrooklynServerConfig; +import org.apache.brooklyn.location.ssh.SshMachineLocation; import org.apache.brooklyn.util.core.flags.SetFromFlag; import org.apache.brooklyn.util.core.internal.ssh.ShellTool; import org.apache.brooklyn.util.core.internal.ssh.SshTool; @@ -180,7 +181,16 @@ public class BrooklynConfigKeys { // because they have some funny circular references static { assert BROOKLYN_SSH_CONFIG_KEY_PREFIX.equals(SshTool.BROOKLYN_CONFIG_KEY_PREFIX) : "static final initializer classload ordering problem"; } - public static final ConfigKey<String> SSH_TOOL_CLASS = newConfigKeyWithPrefix(BROOKLYN_SSH_CONFIG_KEY_PREFIX, + public static final ConfigKey<String> SSH_TOOL_CLASS = newStringConfigKey( + BROOKLYN_SSH_CONFIG_KEY_PREFIX + "sshToolClass", + "SshTool implementation to use (or null for default)", + null); + + /** + * @deprecated since 0.9.0; use {@link #SSH_TOOL_CLASS} + */ + @Deprecated + public static final ConfigKey<String> LEGACY_SSH_TOOL_CLASS = newConfigKeyWithPrefix(BROOKLYN_SSH_CONFIG_KEY_PREFIX, Preconditions.checkNotNull(SshTool.PROP_TOOL_CLASS, "static final initializer classload ordering problem")); public static final ConfigKey<String> SSH_CONFIG_HOST = newConfigKeyWithPrefix(BROOKLYN_SSH_CONFIG_KEY_PREFIX, SshTool.PROP_HOST); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6860e046/core/src/main/java/org/apache/brooklyn/location/ssh/SshMachineLocation.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/location/ssh/SshMachineLocation.java b/core/src/main/java/org/apache/brooklyn/location/ssh/SshMachineLocation.java index 2cf1690..7daa523 100644 --- a/core/src/main/java/org/apache/brooklyn/location/ssh/SshMachineLocation.java +++ b/core/src/main/java/org/apache/brooklyn/location/ssh/SshMachineLocation.java @@ -18,6 +18,8 @@ */ package org.apache.brooklyn.location.ssh; +import static org.apache.brooklyn.core.config.ConfigKeys.newConfigKeyWithPrefix; +import static org.apache.brooklyn.core.config.ConfigKeys.newStringConfigKey; import static org.apache.brooklyn.util.groovy.GroovyJavaMethods.truth; import java.io.Closeable; @@ -66,30 +68,6 @@ import org.apache.brooklyn.core.location.BasicOsDetails; import org.apache.brooklyn.core.location.PortRanges; import org.apache.brooklyn.core.location.access.PortForwardManager; import org.apache.brooklyn.core.mgmt.BrooklynTaskTags; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.annotations.Beta; -import com.google.common.base.Function; -import com.google.common.base.Objects; -import com.google.common.base.Preconditions; -import com.google.common.base.Predicate; -import com.google.common.base.Supplier; -import com.google.common.base.Throwables; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; -import com.google.common.cache.RemovalListener; -import com.google.common.cache.RemovalNotification; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; -import com.google.common.net.HostAndPort; -import com.google.common.reflect.TypeToken; - import org.apache.brooklyn.util.collections.MutableMap; import org.apache.brooklyn.util.core.ResourceUtils; import org.apache.brooklyn.util.core.config.ConfigBag; @@ -119,6 +97,29 @@ import org.apache.brooklyn.util.stream.ReaderInputStream; import org.apache.brooklyn.util.stream.StreamGobbler; import org.apache.brooklyn.util.text.Strings; import org.apache.brooklyn.util.time.Duration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.annotations.Beta; +import com.google.common.base.Function; +import com.google.common.base.Objects; +import com.google.common.base.Preconditions; +import com.google.common.base.Predicate; +import com.google.common.base.Supplier; +import com.google.common.base.Throwables; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; +import com.google.common.cache.RemovalListener; +import com.google.common.cache.RemovalNotification; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import com.google.common.net.HostAndPort; +import com.google.common.reflect.TypeToken; import groovy.lang.Closure; @@ -140,6 +141,13 @@ public class SshMachineLocation extends AbstractLocation implements MachineLocat // Use a sane timeout when doing a connectivity test private static final int SSHABLE_CONNECT_TIMEOUT = (int)Duration.minutes(2).toMilliseconds(); + // Note that WinRmTool's implementation class *must* use a different key name. Both may be used + // within a location's configuration to indicate the implementation to use for WinRmTool and + // for SshTool - that will require two different configuration values. + public static final ConfigKey<String> SSH_TOOL_CLASS = ConfigKeys.newConfigKeyWithPrefixRemoved( + BrooklynConfigKeys.BROOKLYN_SSH_CONFIG_KEY_PREFIX, + Preconditions.checkNotNull(BrooklynConfigKeys.SSH_TOOL_CLASS, "static final initializer classload ordering problem")); + public static final ConfigKey<Duration> SSH_CACHE_EXPIRY_DURATION = ConfigKeys.newConfigKey(Duration.class, "sshCacheExpiryDuration", "Expiry time for unused cached ssh connections", Duration.FIVE_MINUTES); @@ -251,6 +259,8 @@ public class SshMachineLocation extends AbstractLocation implements MachineLocat @Nullable private transient LoadingCache<Map<String, ?>, Pool<SshTool>> sshPoolCacheOrNull; + private transient volatile boolean loggedLegcySshToolClassConfig; + public SshMachineLocation() { this(MutableMap.of()); } @@ -598,7 +608,24 @@ public class SshMachineLocation extends AbstractLocation implements MachineLocat } // look up tool class - String sshToolClass = args.get(SshTool.PROP_TOOL_CLASS); + String sshToolClass = args.get(SSH_TOOL_CLASS); + String legacySshToolClass = args.get(SshTool.PROP_TOOL_CLASS); + if (Strings.isNonBlank(legacySshToolClass)) { + String msg; + if (Strings.isNonBlank(sshToolClass)) { + msg = "Ignoring deprecated config "+SshTool.PROP_TOOL_CLASS.getName()+"="+legacySshToolClass + +", preferring "+SSH_TOOL_CLASS.getName()+"="+sshToolClass+" for "+SshMachineLocation.this; + + } else { + sshToolClass = legacySshToolClass; + msg = "Using deprecated config "+SshTool.PROP_TOOL_CLASS.getName()+"="+legacySshToolClass + +", preferring "+SSH_TOOL_CLASS.getName()+"="+sshToolClass+" for "+SshMachineLocation.this; + } + if (!loggedLegcySshToolClassConfig) { + LOG.warn(msg); + loggedLegcySshToolClassConfig = true; + } + } if (sshToolClass==null) sshToolClass = SshjTool.class.getName(); SshTool ssh = (SshTool) Class.forName(sshToolClass).getConstructor(Map.class).newInstance(args.getAllConfig()); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6860e046/core/src/main/java/org/apache/brooklyn/util/core/internal/ssh/SshTool.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/util/core/internal/ssh/SshTool.java b/core/src/main/java/org/apache/brooklyn/util/core/internal/ssh/SshTool.java index 2aa018f..df3947f 100644 --- a/core/src/main/java/org/apache/brooklyn/util/core/internal/ssh/SshTool.java +++ b/core/src/main/java/org/apache/brooklyn/util/core/internal/ssh/SshTool.java @@ -28,6 +28,7 @@ import java.util.Map; import org.apache.brooklyn.config.ConfigKey; import org.apache.brooklyn.core.config.ConfigKeys; +import org.apache.brooklyn.location.ssh.SshMachineLocation; import org.apache.brooklyn.util.stream.KnownSizeInputStream; import org.apache.brooklyn.util.time.Duration; @@ -49,7 +50,18 @@ public interface SshTool extends ShellTool { * These keys are detected from entity/global config and automatically applied to ssh executions. */ public static final String BROOKLYN_CONFIG_KEY_PREFIX = "brooklyn.ssh.config."; - public static final ConfigKey<String> PROP_TOOL_CLASS = newStringConfigKey("tool.class", "SshTool implementation to use", null); + /** + * @deprecated since 0.9.0; use {@link SshMachineLocation#SSH_TOOL_CLASS} + * + * This configuration does not belong on SshTool: all other config here relates to configuration + * used by the SshTool, rather than for instantiating the SshTool. Therefore instead set the + * configuration in SshMachineLocation where the SshTool is instantiated. + */ + @Deprecated + public static final ConfigKey<String> PROP_TOOL_CLASS = newStringConfigKey( + "tool.class", + "SshTool implementation to use (Deprecated - see SshMachineLocation's sshToolClass)", + null); public static final ConfigKey<String> PROP_HOST = newStringConfigKey("host", "Host to connect to (required)", null); public static final ConfigKey<Integer> PROP_PORT = newConfigKey("port", "Port on host to connect to", 22); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6860e046/core/src/test/java/org/apache/brooklyn/location/ssh/SshMachineLocationReuseIntegrationTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/location/ssh/SshMachineLocationReuseIntegrationTest.java b/core/src/test/java/org/apache/brooklyn/location/ssh/SshMachineLocationReuseIntegrationTest.java index 0c1d7eb..cebd2f4 100644 --- a/core/src/test/java/org/apache/brooklyn/location/ssh/SshMachineLocationReuseIntegrationTest.java +++ b/core/src/test/java/org/apache/brooklyn/location/ssh/SshMachineLocationReuseIntegrationTest.java @@ -27,13 +27,9 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; import org.apache.brooklyn.api.location.LocationSpec; import org.apache.brooklyn.core.entity.Entities; import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext; -import org.apache.brooklyn.location.ssh.SshMachineLocation; import org.apache.brooklyn.test.Asserts; import org.apache.brooklyn.util.collections.MutableMap; import org.apache.brooklyn.util.core.internal.ssh.SshTool; @@ -41,6 +37,9 @@ import org.apache.brooklyn.util.core.internal.ssh.sshj.SshjTool; import org.apache.brooklyn.util.net.Networking; import org.apache.brooklyn.util.stream.Streams; import org.apache.brooklyn.util.time.Duration; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; @@ -104,7 +103,7 @@ public class SshMachineLocationReuseIntegrationTest { managementContext = new LocalManagementContext(); host = managementContext.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class) .configure("address", Networking.getLocalHost()) - .configure(SshTool.PROP_TOOL_CLASS, RecordingSshjTool.class.getName())); + .configure(SshMachineLocation.SSH_TOOL_CLASS, RecordingSshjTool.class.getName())); } @AfterMethod(alwaysRun=true) @@ -151,7 +150,7 @@ public class SshMachineLocationReuseIntegrationTest { SshMachineLocation host2 = managementContext.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class) .configure("address", InetAddress.getLocalHost()) .configure(SshMachineLocation.SSH_CACHE_EXPIRY_DURATION, Duration.ONE_SECOND) - .configure(SshTool.PROP_TOOL_CLASS, RecordingSshjTool.class.getName())); + .configure(SshMachineLocation.SSH_TOOL_CLASS, RecordingSshjTool.class.getName())); Map<String, Object> props = customSshConfigKeys(); host2.execScript(props, "mysummary", ImmutableList.of("exit")); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6860e046/core/src/test/java/org/apache/brooklyn/location/ssh/SshMachineLocationSshToolTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/location/ssh/SshMachineLocationSshToolTest.java b/core/src/test/java/org/apache/brooklyn/location/ssh/SshMachineLocationSshToolTest.java new file mode 100644 index 0000000..daa9233 --- /dev/null +++ b/core/src/test/java/org/apache/brooklyn/location/ssh/SshMachineLocationSshToolTest.java @@ -0,0 +1,96 @@ +/* + * 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.location.ssh; + +import static org.testng.Assert.assertTrue; + +import org.apache.brooklyn.api.location.LocationSpec; +import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport; +import org.apache.brooklyn.util.core.internal.ssh.RecordingSshTool; +import org.apache.brooklyn.util.core.internal.ssh.RecordingSshTool.ExecCmd; +import org.apache.brooklyn.util.core.internal.ssh.SshTool; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; + +/** + * Test that the right SshTool is picked up, based on the {@link SshMachineLocation}'s configuration. + */ +public class SshMachineLocationSshToolTest extends BrooklynAppUnitTestSupport { + + // TODO See SshEffectorTasks.getSshFlags, called by AbstractSoftwareProcessSshDriver.getSshFlags. + // That retrieves all the mgmt.config, entity.config and location.config to search for ssh-related + // configuration options. If you *just* instantiate the location directly, then it doesn't get the + // mgmt.config options. + // + // See EntitySshToolTest for an equivalent that configures the SshTool on the management context + // and on the entity. + + @BeforeMethod(alwaysRun=true) + public void setUp() throws Exception { + super.setUp(); + RecordingSshTool.execScriptCmds.clear(); + } + + @AfterMethod(alwaysRun=true) + public void tearDown() throws Exception { + RecordingSshTool.execScriptCmds.clear(); + super.tearDown(); + } + + @Test + public void testCustomSshToolClass() throws Exception { + SshMachineLocation machine = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class) + .configure("address", "localhost") + .configure(SshMachineLocation.SSH_TOOL_CLASS, RecordingSshTool.class.getName())); + runCustomSshToolClass(machine); + } + + @Test + @SuppressWarnings("deprecation") + public void testCustomSshToolClassUsingLegacy() throws Exception { + SshMachineLocation machine = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class) + .configure("address", "localhost") + .configure(SshTool.PROP_TOOL_CLASS.getName(), RecordingSshTool.class.getName())); + runCustomSshToolClass(machine); + } + + @Test + @SuppressWarnings("deprecation") + public void testCustomSshToolClassPrefersNonLegacy() throws Exception { + SshMachineLocation machine = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class) + .configure("address", "localhost") + .configure(SshMachineLocation.SSH_TOOL_CLASS.getName(), RecordingSshTool.class.getName()) + .configure(SshTool.PROP_TOOL_CLASS.getName(), "class.does.not.exist")); + runCustomSshToolClass(machine); + } + + protected void runCustomSshToolClass(SshMachineLocation host2) throws Exception { + host2.execCommands("mySummary", ImmutableList.of("myCommand")); + + boolean found = false; + for (ExecCmd cmd : RecordingSshTool.execScriptCmds) { + found = found || cmd.commands.contains("myCommand"); + } + + assertTrue(found, "cmds="+RecordingSshTool.execScriptCmds); + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6860e046/core/src/test/java/org/apache/brooklyn/location/ssh/SshMachineLocationTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/location/ssh/SshMachineLocationTest.java b/core/src/test/java/org/apache/brooklyn/location/ssh/SshMachineLocationTest.java index 1aa71f1..e7f7c57 100644 --- a/core/src/test/java/org/apache/brooklyn/location/ssh/SshMachineLocationTest.java +++ b/core/src/test/java/org/apache/brooklyn/location/ssh/SshMachineLocationTest.java @@ -42,12 +42,10 @@ import org.apache.brooklyn.api.location.LocationSpec; import org.apache.brooklyn.api.location.MachineDetails; import org.apache.brooklyn.api.location.MachineLocation; import org.apache.brooklyn.api.location.PortRange; -import org.apache.brooklyn.api.mgmt.ManagementContext; import org.apache.brooklyn.core.effector.EffectorBody; import org.apache.brooklyn.core.effector.EffectorTaskTest; import org.apache.brooklyn.core.effector.Effectors; import org.apache.brooklyn.core.entity.BrooklynConfigKeys; -import org.apache.brooklyn.core.entity.Entities; import org.apache.brooklyn.core.entity.EntityInternal; import org.apache.brooklyn.core.entity.factory.ApplicationBuilder; import org.apache.brooklyn.core.location.BasicHardwareDetails; @@ -55,16 +53,14 @@ import org.apache.brooklyn.core.location.BasicMachineDetails; import org.apache.brooklyn.core.location.BasicOsDetails; import org.apache.brooklyn.core.location.Machines; import org.apache.brooklyn.core.location.PortRanges; -import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests; +import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport; import org.apache.brooklyn.core.test.entity.TestApplication; -import org.apache.brooklyn.location.ssh.SshMachineLocation; import org.apache.brooklyn.test.Asserts; import org.apache.brooklyn.util.collections.MutableMap; import org.apache.brooklyn.util.core.config.ConfigBag; import org.apache.brooklyn.util.core.file.ArchiveUtils; import org.apache.brooklyn.util.core.internal.ssh.RecordingSshTool; import org.apache.brooklyn.util.core.internal.ssh.SshException; -import org.apache.brooklyn.util.core.internal.ssh.SshTool; import org.apache.brooklyn.util.core.task.BasicExecutionContext; import org.apache.brooklyn.util.core.task.BasicExecutionManager; import org.apache.brooklyn.util.guava.Maybe; @@ -86,23 +82,28 @@ import com.google.common.io.Files; /** * Test the {@link SshMachineLocation} implementation of the {@link Location} interface. */ -public class SshMachineLocationTest { +public class SshMachineLocationTest extends BrooklynAppUnitTestSupport { private SshMachineLocation host; - private ManagementContext mgmt; @BeforeMethod(alwaysRun=true) public void setUp() throws Exception { - mgmt = LocalManagementContextForTests.newInstance(); - host = new SshMachineLocation(MutableMap.of("address", Networking.getLocalHost())); + super.setUp(); + host = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class) + .configure("address", Networking.getLocalHost())); + RecordingSshTool.execScriptCmds.clear(); } @AfterMethod(alwaysRun=true) public void tearDown() throws Exception { - if (host != null) Streams.closeQuietly(host); - if (mgmt != null) Entities.destroyAll(mgmt); + try { + if (host != null) Streams.closeQuietly(host); + } finally { + RecordingSshTool.execScriptCmds.clear(); + super.tearDown(); + } } - + @Test(groups = "Integration") public void testGetMachineDetails() throws Exception { BasicExecutionManager execManager = new BasicExecutionManager("mycontextid"); @@ -144,7 +145,7 @@ public class SshMachineLocationTest { public void testGetMachineIsInessentialOnFailure() throws Exception { SshMachineLocation host2 = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class) .configure("address", Networking.getLocalHost()) - .configure(SshTool.PROP_TOOL_CLASS, FailingSshTool.class.getName())); + .configure(SshMachineLocation.SSH_TOOL_CLASS, FailingSshTool.class.getName())); final Effector<MachineDetails> GET_MACHINE_DETAILS = Effectors.effector(MachineDetails.class, "getMachineDetails") .impl(new EffectorBody<MachineDetails>() { http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6860e046/software/base/src/test/java/org/apache/brooklyn/entity/java/JavaOptsTest.java ---------------------------------------------------------------------- diff --git a/software/base/src/test/java/org/apache/brooklyn/entity/java/JavaOptsTest.java b/software/base/src/test/java/org/apache/brooklyn/entity/java/JavaOptsTest.java index 7c25a4f..2928f2c 100644 --- a/software/base/src/test/java/org/apache/brooklyn/entity/java/JavaOptsTest.java +++ b/software/base/src/test/java/org/apache/brooklyn/entity/java/JavaOptsTest.java @@ -32,24 +32,19 @@ import org.apache.brooklyn.api.entity.EntitySpec; import org.apache.brooklyn.api.location.LocationSpec; import org.apache.brooklyn.api.location.MachineLocation; import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport; -import org.apache.brooklyn.entity.java.UsesJmx; -import org.apache.brooklyn.entity.java.VanillaJavaApp; -import org.apache.brooklyn.entity.java.VanillaJavaAppImpl; -import org.apache.brooklyn.entity.java.VanillaJavaAppSshDriver; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; import org.apache.brooklyn.location.ssh.SshMachineLocation; import org.apache.brooklyn.util.collections.MutableList; import org.apache.brooklyn.util.collections.MutableMap; import org.apache.brooklyn.util.collections.MutableSet; import org.apache.brooklyn.util.core.internal.ssh.RecordingSshTool; -import org.apache.brooklyn.util.core.internal.ssh.SshTool; import org.apache.brooklyn.util.core.internal.ssh.RecordingSshTool.ExecCmd; import org.apache.brooklyn.util.jmx.jmxmp.JmxmpAgent; import org.apache.brooklyn.util.text.Strings; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -73,7 +68,7 @@ public class JavaOptsTest extends BrooklynAppUnitTestSupport { super.setUp(); loc = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class) .configure("address", "localhost") - .configure(SshTool.PROP_TOOL_CLASS, RecordingSshTool.class.getName())); + .configure(SshMachineLocation.SSH_TOOL_CLASS, RecordingSshTool.class.getName())); } @AfterMethod(alwaysRun=true) http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6860e046/software/base/src/test/java/org/apache/brooklyn/entity/software/base/EntitySshToolTest.java ---------------------------------------------------------------------- diff --git a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/EntitySshToolTest.java b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/EntitySshToolTest.java new file mode 100644 index 0000000..12464ef --- /dev/null +++ b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/EntitySshToolTest.java @@ -0,0 +1,103 @@ +/* + * 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.entity.software.base; + +import static org.testng.Assert.assertTrue; + +import org.apache.brooklyn.api.entity.EntitySpec; +import org.apache.brooklyn.api.location.LocationSpec; +import org.apache.brooklyn.core.entity.BrooklynConfigKeys; +import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport; +import org.apache.brooklyn.entity.machine.MachineEntity; +import org.apache.brooklyn.location.ssh.SshMachineLocation; +import org.apache.brooklyn.util.core.internal.ssh.RecordingSshTool; +import org.apache.brooklyn.util.core.internal.ssh.RecordingSshTool.ExecCmd; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; + +/** + * Test that the right SshTool is picked up, based on the entity's configuration. + */ +public class EntitySshToolTest extends BrooklynAppUnitTestSupport { + + private SshMachineLocation machine; + + @BeforeMethod(alwaysRun=true) + public void setUp() throws Exception { + super.setUp(); + RecordingSshTool.execScriptCmds.clear(); + + machine = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class) + .configure("address", "localhost")); + } + + @AfterMethod(alwaysRun=true) + public void tearDown() throws Exception { + RecordingSshTool.execScriptCmds.clear(); + super.tearDown(); + } + + @Test + public void testCustomSshToolClassConfiguredOnEntityWithPrefix() throws Exception { + MachineEntity entity = app.addChild(EntitySpec.create(MachineEntity.class) + .configure(BrooklynConfigKeys.SSH_TOOL_CLASS, RecordingSshTool.class.getName())); + entity.start(ImmutableList.of(machine)); + runCustomSshToolClass(entity); + } + + @Test + @SuppressWarnings("deprecation") + public void testCustomSshToolClassConfiguredOnEntityUsingLegacy() throws Exception { + MachineEntity entity = app.addChild(EntitySpec.create(MachineEntity.class) + .configure(BrooklynConfigKeys.LEGACY_SSH_TOOL_CLASS, RecordingSshTool.class.getName())); + entity.start(ImmutableList.of(machine)); + runCustomSshToolClass(entity); + } + + @Test + public void testCustomSshToolClassConfiguredOnBrooklynProperties() throws Exception { + mgmt.getBrooklynProperties().put(BrooklynConfigKeys.SSH_TOOL_CLASS, RecordingSshTool.class.getName()); + MachineEntity entity = app.addChild(EntitySpec.create(MachineEntity.class)); + entity.start(ImmutableList.of(machine)); + runCustomSshToolClass(entity); + } + + @Test + @SuppressWarnings("deprecation") + public void testCustomSshToolClassConfiguredOnBrooklynPropertiesUsingLegaacy() throws Exception { + mgmt.getBrooklynProperties().put(BrooklynConfigKeys.LEGACY_SSH_TOOL_CLASS, RecordingSshTool.class.getName()); + MachineEntity entity = app.addChild(EntitySpec.create(MachineEntity.class)); + entity.start(ImmutableList.of(machine)); + runCustomSshToolClass(entity); + } + + protected void runCustomSshToolClass(MachineEntity entity) throws Exception { + entity.execCommand("myCommand"); + + boolean found = false; + for (ExecCmd cmd : RecordingSshTool.execScriptCmds) { + found = found || cmd.commands.contains("myCommand"); + } + + assertTrue(found, "cmds="+RecordingSshTool.execScriptCmds); + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6860e046/software/base/src/test/java/org/apache/brooklyn/entity/software/base/lifecycle/StartStopSshDriverTest.java ---------------------------------------------------------------------- diff --git a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/lifecycle/StartStopSshDriverTest.java b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/lifecycle/StartStopSshDriverTest.java index 33abadd..f7af97b 100644 --- a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/lifecycle/StartStopSshDriverTest.java +++ b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/lifecycle/StartStopSshDriverTest.java @@ -87,6 +87,8 @@ public class StartStopSshDriverTest { SshTool lastTool; public SshMachineLocationWithSshTool(Map flags) { super(flags); } + + @Override public SshTool connectSsh(Map args) { SshTool result = super.connectSsh(args); lastTool = result; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6860e046/software/webapp/src/test/java/org/apache/brooklyn/entity/proxy/nginx/NginxRebindWithHaIntegrationTest.java ---------------------------------------------------------------------- diff --git a/software/webapp/src/test/java/org/apache/brooklyn/entity/proxy/nginx/NginxRebindWithHaIntegrationTest.java b/software/webapp/src/test/java/org/apache/brooklyn/entity/proxy/nginx/NginxRebindWithHaIntegrationTest.java index 51c04c4..4d45fbd 100644 --- a/software/webapp/src/test/java/org/apache/brooklyn/entity/proxy/nginx/NginxRebindWithHaIntegrationTest.java +++ b/software/webapp/src/test/java/org/apache/brooklyn/entity/proxy/nginx/NginxRebindWithHaIntegrationTest.java @@ -40,12 +40,13 @@ import org.apache.brooklyn.core.mgmt.rebind.RebindTestFixtureWithApp; import org.apache.brooklyn.core.mgmt.rebind.RebindTestUtils; import org.apache.brooklyn.core.test.entity.TestApplication; import org.apache.brooklyn.entity.group.DynamicCluster; -import org.apache.brooklyn.entity.proxy.nginx.NginxController; import org.apache.brooklyn.entity.webapp.tomcat.TomcatServer; +import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation; +import org.apache.brooklyn.location.ssh.SshMachineLocation; +import org.apache.brooklyn.location.ssh.SshMachineLocationReuseIntegrationTest.RecordingSshjTool; import org.apache.brooklyn.test.EntityTestUtils; import org.apache.brooklyn.test.WebAppMonitor; import org.apache.brooklyn.test.support.TestResourceUnavailableException; -import org.apache.brooklyn.util.core.internal.ssh.SshTool; import org.apache.brooklyn.util.core.task.BasicExecutionManager; import org.apache.brooklyn.util.net.Networking; import org.apache.brooklyn.util.repeat.Repeater; @@ -56,8 +57,6 @@ import org.testng.Assert; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation; -import org.apache.brooklyn.location.ssh.SshMachineLocationReuseIntegrationTest.RecordingSshjTool; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; @@ -93,7 +92,7 @@ public class NginxRebindWithHaIntegrationTest extends RebindTestFixtureWithApp { super.setUp(); loc = origManagementContext.getLocationManager().createLocation(LocationSpec.create(LocalhostMachineProvisioningLocation.class) .configure("address", Networking.getLocalHost()) - .configure(SshTool.PROP_TOOL_CLASS, RecordingSshjTool.class.getName())); + .configure(SshMachineLocation.SSH_TOOL_CLASS, RecordingSshjTool.class.getName())); executor = Executors.newCachedThreadPool(); feedRegistration = BrooklynFeatureEnablement.isEnabled(BrooklynFeatureEnablement.FEATURE_FEED_REGISTRATION_PROPERTY);
