You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sv...@apache.org on 2015/12/03 08:40:19 UTC
[1/3] incubator-brooklyn git commit: WinRM testing: refactor so can
be sub-classed
Repository: incubator-brooklyn
Updated Branches:
refs/heads/master 45690e3de -> 27f2a88bb
WinRM testing: refactor so can be sub-classed
For testing alternative WinRmTool implementations (e.g. in downstream
project), these changes allow WinRmMachineLocationLiveTest to be
subclassed.
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/fea59a4e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/fea59a4e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/fea59a4e
Branch: refs/heads/master
Commit: fea59a4e18fedca16aeabdf4f395bb6f19150843
Parents: 45690e3
Author: Aled Sage <al...@gmail.com>
Authored: Wed Dec 2 23:54:09 2015 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Thu Dec 3 01:37:43 2015 +0000
----------------------------------------------------------------------
.../location/WinRmMachineLocationLiveTest.java | 15 ++++++++++++---
.../base/test/location/WindowsTestFixture.java | 19 +++++++++++++------
2 files changed, 25 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/fea59a4e/software/base/src/test/java/org/apache/brooklyn/entity/software/base/test/location/WinRmMachineLocationLiveTest.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/test/location/WinRmMachineLocationLiveTest.java b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/test/location/WinRmMachineLocationLiveTest.java
index bfca1d8..ad16403 100644
--- a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/test/location/WinRmMachineLocationLiveTest.java
+++ b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/test/location/WinRmMachineLocationLiveTest.java
@@ -79,7 +79,7 @@ public class WinRmMachineLocationLiveTest {
* TODO: Deferred implementing copyFrom or environment variables.
*/
- private static final Logger LOG = LoggerFactory.getLogger(BrooklynAppLiveTestSupport.class);
+ private static final Logger LOG = LoggerFactory.getLogger(WinRmMachineLocationLiveTest.class);
private static final String INVALID_CMD = "thisCommandDoesNotExistAEFafiee3d";
private static final String PS_ERR_ACTION_PREF_EQ_STOP = "$ErrorActionPreference = \"Stop\"";
@@ -88,7 +88,7 @@ public class WinRmMachineLocationLiveTest {
protected TestApplication app;
protected ManagementContextInternal mgmt;
- private WinRmMachineLocation machine;
+ protected WinRmMachineLocation machine;
private ListeningExecutorService executor;
@@ -98,7 +98,7 @@ public class WinRmMachineLocationLiveTest {
mgmt = new LocalManagementContextForTests(BrooklynProperties.Factory.newDefault());
- loc = WindowsTestFixture.setUpWindowsLocation(mgmt);
+ loc = newLoc(mgmt);
machine = loc.obtain(ImmutableMap.of());
LOG.info("PROVISIONED: "+machine.getAddress()+":"+machine.config().get(WinRmMachineLocation.WINRM_PORT)
@@ -119,6 +119,15 @@ public class WinRmMachineLocationLiveTest {
}
}
+ /**
+ * Returns a location for obtaining a single WinRM machine. This method will be called once during
+ * {@code @BeforeClass}, then {@code loc.obtain()} will be called. The obtained machine will be
+ * released in {@code @AfterClass}.
+ */
+ protected MachineProvisioningLocation<WinRmMachineLocation> newLoc(ManagementContextInternal mgmt) throws Exception {
+ return WindowsTestFixture.setUpWindowsLocation(mgmt);
+ }
+
@Test(groups="Live")
public void testCopyTo() throws Exception {
String contents = "abcdef";
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/fea59a4e/software/base/src/test/java/org/apache/brooklyn/entity/software/base/test/location/WindowsTestFixture.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/test/location/WindowsTestFixture.java b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/test/location/WindowsTestFixture.java
index 10aa4b7..597c543 100644
--- a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/test/location/WindowsTestFixture.java
+++ b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/test/location/WindowsTestFixture.java
@@ -26,39 +26,45 @@ import org.apache.brooklyn.api.mgmt.ManagementContext;
import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
import org.apache.brooklyn.location.jclouds.JcloudsLocation;
import org.apache.brooklyn.location.winrm.WinRmMachineLocation;
+import org.apache.brooklyn.util.collections.MutableMap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
public class WindowsTestFixture {
- @SuppressWarnings("unchecked")
public static MachineProvisioningLocation<WinRmMachineLocation> setUpWindowsLocation(ManagementContext mgmt) throws Exception {
+ return setUpWindowsLocation(mgmt, ImmutableMap.<String, Object>of());
+ }
+
+ @SuppressWarnings("unchecked")
+ public static MachineProvisioningLocation<WinRmMachineLocation> setUpWindowsLocation(ManagementContext mgmt, Map<String, ?> props) throws Exception {
// Commented out / unused code included here to make it easy to supply a
// pre-existing Windows VM for use in a bunch of different tests.
// return (MachineProvisioningLocation<WinRmMachineLocation>) newByonLocation((ManagementContextInternal) mgmt);
- return (MachineProvisioningLocation<WinRmMachineLocation>) newJcloudsLocation((ManagementContextInternal) mgmt);
+ return (MachineProvisioningLocation<WinRmMachineLocation>) newJcloudsLocation((ManagementContextInternal) mgmt, props);
}
- private static MachineProvisioningLocation<?> newJcloudsLocation(ManagementContextInternal mgmt) {
+ private static MachineProvisioningLocation<?> newJcloudsLocation(ManagementContextInternal mgmt, Map<String, ?> props) {
// Requires no userMetadata to be set, so that we use WinRmMachineLocation.getDefaultUserMetadataString()
mgmt.getBrooklynProperties().remove("brooklyn.location.jclouds.aws-ec2.userMetadata");
mgmt.getBrooklynProperties().remove("brooklyn.location.jclouds.userMetadata");
mgmt.getBrooklynProperties().remove("brooklyn.location.userMetadata");
- return (JcloudsLocation) mgmt.getLocationRegistry().resolve("jclouds:aws-ec2:us-west-2", ImmutableMap.<String, Object>builder()
+ return (JcloudsLocation) mgmt.getLocationRegistry().resolve("jclouds:aws-ec2:us-west-2", MutableMap.<String, Object>builder()
.put("inboundPorts", ImmutableList.of(5985, 3389))
.put("displayName", "AWS Oregon (Windows)")
.put("imageOwner", "801119661308")
.put("imageNameRegex", "Windows_Server-2012-R2_RTM-English-64Bit-Base-.*")
.put("hardwareId", "m3.medium")
.put("useJcloudsSshInit", false)
+ .putAll(props)
.build());
}
@SuppressWarnings("unused")
- private static MachineProvisioningLocation<?> newByonLocation(ManagementContextInternal mgmt) {
- Map<String, String> config = new LinkedHashMap<>();
+ private static MachineProvisioningLocation<?> newByonLocation(ManagementContextInternal mgmt, Map<String, ?> props) {
+ Map<String, Object> config = new LinkedHashMap<>();
config.put("hosts", "52.12.211.123:5985");
config.put("osFamily", "windows");
config.put("winrm", "52.12.211.123:5985");
@@ -66,6 +72,7 @@ public class WindowsTestFixture {
config.put("password", "pa55w0rd");
config.put("useJcloudsSshInit", "false");
config.put("byonIdentity", "123");
+ config.putAll(props);
return (MachineProvisioningLocation<?>) mgmt.getLocationRegistry().resolve("byon", config);
}
}
[3/3] incubator-brooklyn git commit: Closes #1083
Posted by sv...@apache.org.
Closes #1083
Fix WinRM config, and refactor winrm testing
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/27f2a88b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/27f2a88b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/27f2a88b
Branch: refs/heads/master
Commit: 27f2a88bb7eaf0aaf3d1112ff91babf05a6b8549
Parents: 45690e3 17b6583
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Thu Dec 3 09:39:35 2015 +0200
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Thu Dec 3 09:39:35 2015 +0200
----------------------------------------------------------------------
.../location/WinRmMachineLocationLiveTest.java | 15 ++++-
.../base/test/location/WindowsTestFixture.java | 19 +++++--
.../location/winrm/WinRmMachineLocation.java | 58 ++++++++++++++++----
3 files changed, 71 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
[2/3] incubator-brooklyn git commit: WinRm machine: extract config
for WinRmTool
Posted by sv...@apache.org.
WinRm machine: extract config for WinRmTool
Follows same code pattern as is in SshMachineLocation.
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/17b6583b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/17b6583b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/17b6583b
Branch: refs/heads/master
Commit: 17b6583bae894907eaa146b9618e52dc698dce48
Parents: fea59a4
Author: Aled Sage <al...@gmail.com>
Authored: Thu Dec 3 01:01:12 2015 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Thu Dec 3 01:37:44 2015 +0000
----------------------------------------------------------------------
.../location/winrm/WinRmMachineLocation.java | 58 ++++++++++++++++----
1 file changed, 46 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/17b6583b/software/winrm/src/main/java/org/apache/brooklyn/location/winrm/WinRmMachineLocation.java
----------------------------------------------------------------------
diff --git a/software/winrm/src/main/java/org/apache/brooklyn/location/winrm/WinRmMachineLocation.java b/software/winrm/src/main/java/org/apache/brooklyn/location/winrm/WinRmMachineLocation.java
index 7f2e4ed..8a2a786 100644
--- a/software/winrm/src/main/java/org/apache/brooklyn/location/winrm/WinRmMachineLocation.java
+++ b/software/winrm/src/main/java/org/apache/brooklyn/location/winrm/WinRmMachineLocation.java
@@ -90,6 +90,25 @@ public class WinRmMachineLocation extends AbstractLocation implements MachineLoc
BrooklynConfigKeys.BROOKLYN_WINRM_CONFIG_KEY_PREFIX,
Preconditions.checkNotNull(BrooklynConfigKeys.WINRM_TOOL_CLASS, "static final initializer classload ordering problem"));
+ /**
+ * Prefix for config key:values to be passed to the winrm tool on construction. For example,
+ * one could define the location below. When executing winrm commands, it would instantiate
+ * an instance of {@code com.acme.brooklyn.MyCustomWinrmTool}, calling its constructor with a
+ * {@code Map<String, Object>} that contained the configuration. In this case, the map would
+ * include: {@code address=1.2.3.4}; {@code user=myname}; and {@code myparam=myvalue}.
+ *
+ * <pre>
+ * {@code
+ * brooklyn.location.named.myLocation = byon:(hosts=1.2.3.4,user=myname)
+ * brooklyn.location.named.myLocation.winrmToolClass = com.acme.brooklyn.MyCustomWinrmTool
+ * brooklyn.location.named.myLocation.winrmToolClass.myparam = myvalue
+ * }
+ * }
+ * </pre>
+ * <p>
+ */
+ public static final String WINRM_TOOL_CLASS_PROPERTIES_PREFIX = WINRM_TOOL_CLASS.getName()+".";
+
/**
* @deprecated since 0.9.0; config never read; will be removed in future version.
*/
@@ -102,12 +121,14 @@ public class WinRmMachineLocation extends AbstractLocation implements MachineLoc
// TODO See SshTool#PROP_SSH_TRIES, where it was called "sshTries"; remove duplication? Merge into one well-named thing?
public static final ConfigKey<Integer> EXEC_TRIES = WinRmTool.PROP_EXEC_TRIES;
+ @SuppressWarnings("serial")
public static final ConfigKey<Iterable<String>> PRIVATE_ADDRESSES = ConfigKeys.newConfigKey(
new TypeToken<Iterable<String>>() {},
"privateAddresses",
"Private addresses of this machine, e.g. those within the private network",
null);
+ @SuppressWarnings("serial")
public static final ConfigKey<Map<Integer, String>> TCP_PORT_MAPPINGS = ConfigKeys.newConfigKey(
new TypeToken<Map<Integer, String>>() {},
"tcpPortMappings",
@@ -120,7 +141,7 @@ public class WinRmMachineLocation extends AbstractLocation implements MachineLoc
.addAll(ConfigUtils.getStaticKeysOnClass(WinRmTool.class))
.build();
- public static final Set<String> ALL_SSH_CONFIG_KEY_NAMES =
+ public static final Set<String> ALL_WINRM_CONFIG_KEY_NAMES =
ImmutableSet.copyOf(Iterables.transform(ALL_WINRM_CONFIG_KEYS, new Function<HasConfigKey<?>,String>() {
@Override
public String apply(HasConfigKey<?> input) {
@@ -223,23 +244,36 @@ public class WinRmMachineLocation extends AbstractLocation implements MachineLoc
ConfigBag args = new ConfigBag();
for (Map.Entry<String,Object> entry: config().getBag().getAllConfig().entrySet()) {
+
+ boolean include = false;
String key = entry.getKey();
if (key.startsWith(WinRmTool.BROOKLYN_CONFIG_KEY_PREFIX)) {
key = Strings.removeFromStart(key, WinRmTool.BROOKLYN_CONFIG_KEY_PREFIX);
- args.putStringKey(key, entry.getValue());
+ include = true;
}
- }
-
- for (Map.Entry<String,Object> entry: config().getBag().getAllConfig().entrySet()) {
- String key = entry.getKey();
- if (ALL_SSH_CONFIG_KEY_NAMES.contains(key)) {
- } else {
- // this key is not applicable here; ignore it
- continue;
+
+ if (key.startsWith(WINRM_TOOL_CLASS_PROPERTIES_PREFIX)) {
+ key = Strings.removeFromStart(key, WINRM_TOOL_CLASS_PROPERTIES_PREFIX);
+ include = true;
+ }
+
+ if (ALL_WINRM_CONFIG_KEY_NAMES.contains(entry.getKey())) {
+ // key should be included, and does not need to be changed
+
+ // TODO make this config-setting mechanism more universal
+ // currently e.g. it will not admit a tool-specific property.
+ // thinking either we know about the tool here,
+ // or we don't allow unadorned keys to be set
+ // (require use of BROOKLYN_CONFIG_KEY_PREFIX)
+ include = true;
+ }
+
+
+ if (include) {
+ args.putStringKey(key, entry.getValue());
}
- args.putStringKey(key, entry.getValue());
}
-
+
args.putAll(props);
args.configure(SshTool.PROP_HOST, getAddress().getHostAddress());