Return-Path: X-Original-To: apmail-brooklyn-commits-archive@minotaur.apache.org Delivered-To: apmail-brooklyn-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 703AB113F5 for ; Wed, 3 Sep 2014 14:58:03 +0000 (UTC) Received: (qmail 62356 invoked by uid 500); 3 Sep 2014 14:28:48 -0000 Delivered-To: apmail-brooklyn-commits-archive@brooklyn.apache.org Received: (qmail 62339 invoked by uid 500); 3 Sep 2014 14:28:48 -0000 Mailing-List: contact commits-help@brooklyn.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.incubator.apache.org Delivered-To: mailing list commits@brooklyn.incubator.apache.org Received: (qmail 62324 invoked by uid 99); 3 Sep 2014 14:28:48 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 03 Sep 2014 14:28:48 +0000 X-ASF-Spam-Status: No, hits=-2001.7 required=5.0 tests=ALL_TRUSTED,RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Wed, 03 Sep 2014 14:28:43 +0000 Received: (qmail 95850 invoked by uid 99); 3 Sep 2014 13:33:57 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 03 Sep 2014 13:33:57 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id BF65FA05FDE; Wed, 3 Sep 2014 13:33:56 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: aledsage@apache.org To: commits@brooklyn.incubator.apache.org Date: Wed, 03 Sep 2014 13:33:58 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [3/7] git commit: location-resolver: allow any properties in spec X-Virus-Checked: Checked by ClamAV on apache.org location-resolver: allow any properties in spec - for byob, localhost and jcloudsByon, don't enforce just a few properties; instead accept any property Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/ec835ee7 Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/ec835ee7 Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/ec835ee7 Branch: refs/heads/master Commit: ec835ee7572b53528112cad863edeb1af3888d77 Parents: 1c7482c Author: Aled Sage Authored: Thu Jul 31 13:29:48 2014 +0100 Committer: Aled Sage Committed: Wed Sep 3 14:32:27 2014 +0100 ---------------------------------------------------------------------- .../location/basic/ByonLocationResolver.java | 21 +-- .../location/basic/LocalhostResolver.java | 18 +- .../basic/ByonLocationResolverTest.java | 18 ++ .../basic/LocalhostLocationResolverTest.java | 18 +- .../jclouds/JcloudsByonLocationResolver.java | 10 +- .../JcloudsByonLocationResolverAwsLiveTest.java | 178 +++++++++++++++++++ .../JcloudsByonLocationResolverLiveTest.java | 175 ------------------ ...dsByonLocationResolverSoftlayerLiveTest.java | 105 +++++++++++ .../JcloudsByonLocationResolverTest.java | 6 +- 9 files changed, 339 insertions(+), 210 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ec835ee7/core/src/main/java/brooklyn/location/basic/ByonLocationResolver.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/brooklyn/location/basic/ByonLocationResolver.java b/core/src/main/java/brooklyn/location/basic/ByonLocationResolver.java index 1ba0578..c5428ec 100644 --- a/core/src/main/java/brooklyn/location/basic/ByonLocationResolver.java +++ b/core/src/main/java/brooklyn/location/basic/ByonLocationResolver.java @@ -23,7 +23,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.net.InetAddress; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -42,9 +41,7 @@ import brooklyn.util.text.WildcardGlobs; import brooklyn.util.text.WildcardGlobs.PhraseTreatment; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; -import com.google.common.collect.Sets; /** * Examples of valid specs: @@ -67,8 +64,6 @@ public class ByonLocationResolver implements LocationResolver { private static final Pattern PATTERN = Pattern.compile("(?i)" + BYON + "(?::\\((.*)\\))?$"); - private static final Set ACCEPTABLE_ARGS = ImmutableSet.of("hosts", "name", "user"); - private volatile ManagementContext managementContext; @Override @@ -88,20 +83,22 @@ public class ByonLocationResolver implements LocationResolver { String argsPart = matcher.group(1); Map argsMap = KeyValueParser.parseMap(argsPart); + // If someone tries "byon:(),byon:()" as a single spec, we get weird key-values! + for (String key : argsMap.keySet()) { + if (key.contains(":") || key.contains("{") || key.contains("}") || key.contains("(") || key.contains(")")) { + throw new IllegalArgumentException("Invalid byon spec: "+spec); + } + } + // prefer args map over location flags String namedLocation = (String) locationFlags.get(LocationInternal.NAMED_SPEC_NAME.getName()); - String name = argsMap.containsKey("name") ? argsMap.get("name") : (String)locationFlags.get("name"); Object hosts = argsMap.containsKey("hosts") ? argsMap.get("hosts") : locationFlags.get("hosts"); String user = argsMap.containsKey("user") ? argsMap.get("user") : (String)locationFlags.get("user"); - if (!ACCEPTABLE_ARGS.containsAll(argsMap.keySet())) { - Set illegalArgs = Sets.difference(argsMap.keySet(), ACCEPTABLE_ARGS); - throw new IllegalArgumentException("Invalid location '"+spec+"'; illegal args "+illegalArgs+"; acceptable args are "+ACCEPTABLE_ARGS); - } if (hosts == null || hosts.toString().isEmpty()) { throw new IllegalArgumentException("Invalid location '"+spec+"'; at least one host must be defined"); } @@ -114,7 +111,7 @@ public class ByonLocationResolver implements LocationResolver { if (hosts instanceof String) { hostAddresses = WildcardGlobs.getGlobsAfterBraceExpansion("{"+hosts+"}", true /* numeric */, /* no quote support though */ PhraseTreatment.NOT_A_SPECIAL_CHAR, PhraseTreatment.NOT_A_SPECIAL_CHAR); - } else if (hosts instanceof List) { + } else if (hosts instanceof Iterable) { hostAddresses = ImmutableList.copyOf((List)hosts); } else { throw new IllegalStateException("Illegal parameter for 'hosts'; must be a string or map (but got " + hosts + ")"); @@ -143,7 +140,7 @@ public class ByonLocationResolver implements LocationResolver { } Map filteredProperties = new LocationPropertiesFromBrooklynProperties().getLocationProperties("byon", namedLocation, globalProperties); - ConfigBag flags = ConfigBag.newInstance(locationFlags).putIfAbsent(filteredProperties); + ConfigBag flags = ConfigBag.newInstance(argsMap).putIfAbsent(locationFlags).putIfAbsent(filteredProperties); flags.putStringKey("machines", machines); flags.putIfNotNull(LocationConfigKeys.USER, user); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ec835ee7/core/src/main/java/brooklyn/location/basic/LocalhostResolver.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/brooklyn/location/basic/LocalhostResolver.java b/core/src/main/java/brooklyn/location/basic/LocalhostResolver.java index de6d530..f456424 100644 --- a/core/src/main/java/brooklyn/location/basic/LocalhostResolver.java +++ b/core/src/main/java/brooklyn/location/basic/LocalhostResolver.java @@ -22,7 +22,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.util.Collections; import java.util.Map; -import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -39,9 +38,6 @@ import brooklyn.util.config.ConfigBag; import brooklyn.util.guava.Maybe; import brooklyn.util.text.KeyValueParser; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Sets; - /** * Examples of valid specs: *
    @@ -60,7 +56,6 @@ public class LocalhostResolver implements LocationResolver, EnableableLocationRe public static final String LOCALHOST = "localhost"; private static final Pattern PATTERN = Pattern.compile("("+LOCALHOST+"|"+LOCALHOST.toUpperCase()+")" + "(:\\((.*)\\))?$"); - private static final Set ACCEPTABLE_ARGS = ImmutableSet.of("name"); private ManagementContext managementContext; @@ -92,19 +87,22 @@ public class LocalhostResolver implements LocationResolver, EnableableLocationRe String argsPart = matcher.group(3); Map argsMap = (argsPart != null) ? KeyValueParser.parseMap(argsPart) : Collections.emptyMap(); - String namePart = argsMap.get("name"); - if (!ACCEPTABLE_ARGS.containsAll(argsMap.keySet())) { - Set illegalArgs = Sets.difference(argsMap.keySet(), ACCEPTABLE_ARGS); - throw new IllegalArgumentException("Invalid location '"+spec+"'; illegal args "+illegalArgs+"; acceptable args are "+ACCEPTABLE_ARGS); + // If someone tries "localhost:(),localhost:()" as a single spec, we get weird key-values! + for (String key : argsMap.keySet()) { + if (key.contains(":") || key.contains("{") || key.contains("}") || key.contains("(") || key.contains(")")) { + throw new IllegalArgumentException("Invalid localhost spec: "+spec); + } } + + String namePart = argsMap.get("name"); if (argsMap.containsKey("name") && (namePart == null || namePart.isEmpty())) { throw new IllegalArgumentException("Invalid location '"+spec+"'; if name supplied then value must be non-empty"); } Map filteredProperties = new LocalhostPropertiesFromBrooklynProperties().getLocationProperties("localhost", namedLocation, globalProperties); // TODO filteredProperties stuff above should not be needed as named location items will already be passed in - ConfigBag flags = ConfigBag.newInstance(locationFlags).putIfAbsent(filteredProperties); + ConfigBag flags = ConfigBag.newInstance(argsMap).putIfAbsent(locationFlags).putIfAbsent(filteredProperties); flags.putStringKey("name", Maybe.fromNullable(namePart).or("localhost")); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ec835ee7/core/src/test/java/brooklyn/location/basic/ByonLocationResolverTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/brooklyn/location/basic/ByonLocationResolverTest.java b/core/src/test/java/brooklyn/location/basic/ByonLocationResolverTest.java index 08d8dca..802c50b 100644 --- a/core/src/test/java/brooklyn/location/basic/ByonLocationResolverTest.java +++ b/core/src/test/java/brooklyn/location/basic/ByonLocationResolverTest.java @@ -41,11 +41,13 @@ import brooklyn.config.BrooklynProperties; import brooklyn.entity.basic.Entities; import brooklyn.location.MachineLocation; import brooklyn.location.MachineProvisioningLocation; +import brooklyn.location.NoMachinesAvailableException; import brooklyn.management.internal.LocalManagementContext; import brooklyn.test.Asserts; import brooklyn.test.entity.LocalManagementContextForTests; import brooklyn.util.collections.MutableMap; import brooklyn.util.os.Os; +import brooklyn.util.net.Networking; import brooklyn.util.text.StringPredicates; import com.google.common.base.Function; @@ -104,6 +106,15 @@ public class ByonLocationResolverTest { } @Test + public void testPropertiesInSpec() throws Exception { + FixedListMachineProvisioningLocation loc = resolve("byon:(privateKeyFile=myprivatekeyfile,hosts=\"1.1.1.1\")"); + SshMachineLocation machine = loc.obtain(); + + assertEquals(machine.getAllConfig(true).get("privateKeyFile"), "myprivatekeyfile"); + assertEquals(machine.getAddress(), Networking.getInetAddressWithFixedName("1.1.1.1")); + } + + @Test public void testPropertyScopePrecedence() throws Exception { brooklynProperties.put("brooklyn.location.named.mynamed", "byon:(hosts=\"1.1.1.1\")"); @@ -137,6 +148,13 @@ public class ByonLocationResolverTest { assertThrowsIllegalArgument("byon:(hosts=\"1.1.1.1\", name=)"); // no value for name } + @Test(expectedExceptions={IllegalArgumentException.class}) + public void testRegistryCommaResolutionInListNotAllowed() throws NoMachinesAvailableException { + // disallowed since 0.7.0 + // fails because it interprets the entire string as a single byon spec, which does not parse + managementContext.getLocationRegistry().resolve(ImmutableList.of("byon:(hosts=\"192.168.0.1\",user=bob),byon:(hosts=\"192.168.0.2\",user=bob2)")); + } + @Test public void testResolvesHosts() throws Exception { assertByonClusterEquals(resolve("byon:(hosts=\"1.1.1.1\")"), ImmutableSet.of("1.1.1.1")); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ec835ee7/core/src/test/java/brooklyn/location/basic/LocalhostLocationResolverTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/brooklyn/location/basic/LocalhostLocationResolverTest.java b/core/src/test/java/brooklyn/location/basic/LocalhostLocationResolverTest.java index ebc7a01..e6fa5c3 100644 --- a/core/src/test/java/brooklyn/location/basic/LocalhostLocationResolverTest.java +++ b/core/src/test/java/brooklyn/location/basic/LocalhostLocationResolverTest.java @@ -179,7 +179,15 @@ public class LocalhostLocationResolverTest { @Test(expectedExceptions={IllegalArgumentException.class}) public void testRegistryCommaResolutionInListNotAllowed2() throws NoMachinesAvailableException { // disallowed since 0.7.0 - getLocationResolver().resolve(ImmutableList.of("byon:(hosts=\"192.168.0.1\",user=bob),byon:(hosts=\"192.168.0.2\",user=bob2)")); + // fails because it interprets the entire string as a single spec, which does not parse + getLocationResolver().resolve(ImmutableList.of("localhost:(),localhost:()")); + } + + @Test(expectedExceptions={IllegalArgumentException.class}) + public void testRegistryCommaResolutionInListNotAllowed3() throws NoMachinesAvailableException { + // disallowed since 0.7.0 + // fails because it interprets the entire string as a single spec, which does not parse + getLocationResolver().resolve(ImmutableList.of("localhost:(name=a),localhost:(name=b)")); } @Test(expectedExceptions={IllegalArgumentException.class}) @@ -195,6 +203,14 @@ public class LocalhostLocationResolverTest { } @Test + public void testResolvesPropertiesInSpec() throws Exception { + Location location = resolve("localhost:(privateKeyFile=myprivatekeyfile,name=myname)"); + assertTrue(location instanceof LocalhostMachineProvisioningLocation); + assertEquals(location.getDisplayName(), "myname"); + assertEquals(location.getAllConfig(true).get("privateKeyFile"), "myprivatekeyfile"); + } + + @Test public void testResolvesDefaultName() throws Exception { Location location = resolve("localhost"); assertTrue(location instanceof LocalhostMachineProvisioningLocation); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ec835ee7/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsByonLocationResolver.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsByonLocationResolver.java b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsByonLocationResolver.java index aa7d575..674d360 100644 --- a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsByonLocationResolver.java +++ b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsByonLocationResolver.java @@ -22,7 +22,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -48,10 +47,8 @@ import brooklyn.util.text.Strings; import brooklyn.util.text.WildcardGlobs; import brooklyn.util.text.WildcardGlobs.PhraseTreatment; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import com.google.common.collect.Sets; /** * Examples of valid specs: @@ -72,8 +69,6 @@ public class JcloudsByonLocationResolver implements LocationResolver { private static final Pattern PATTERN = Pattern.compile("("+BYON+"|"+BYON.toUpperCase()+")" + ":" + "\\((.*)\\)$"); - private static final Set ACCEPTABLE_ARGS = ImmutableSet.of("provider", "region", "endpoint", "hosts", "name", "user", "privateKeyFile"); - private ManagementContext managementContext; @Override @@ -112,10 +107,6 @@ public class JcloudsByonLocationResolver implements LocationResolver { String hosts = argsMap.get("hosts"); - if (!ACCEPTABLE_ARGS.containsAll(argsMap.keySet())) { - Set illegalArgs = Sets.difference(argsMap.keySet(), ACCEPTABLE_ARGS); - throw new IllegalArgumentException("Invalid location '"+spec+"'; illegal args "+illegalArgs+"; acceptable args are "+ACCEPTABLE_ARGS); - } if (Strings.isEmpty(providerOrApi)) { throw new IllegalArgumentException("Invalid location '"+spec+"'; provider must be defined"); } @@ -133,6 +124,7 @@ public class JcloudsByonLocationResolver implements LocationResolver { Map allProperties = getAllProperties(registry, globalProperties); Map jcloudsProperties = new JcloudsPropertiesFromBrooklynProperties().getJcloudsProperties(providerOrApi, regionName, namedLocation, allProperties); jcloudsProperties.putAll(locationFlags); + jcloudsProperties.putAll(argsMap); String jcloudsSpec = "jclouds:"+providerOrApi + (regionName != null ? ":"+regionName : "") + (endpoint != null ? ":"+endpoint : ""); JcloudsLocation jcloudsLocation = (JcloudsLocation) registry.resolve(jcloudsSpec, jcloudsProperties); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ec835ee7/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverAwsLiveTest.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverAwsLiveTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverAwsLiveTest.java new file mode 100644 index 0000000..7e12f5a --- /dev/null +++ b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverAwsLiveTest.java @@ -0,0 +1,178 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package brooklyn.location.jclouds; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import java.net.InetAddress; +import java.util.Map; +import java.util.Set; + +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import brooklyn.location.basic.FixedListMachineProvisioningLocation; +import brooklyn.management.internal.LocalManagementContext; +import brooklyn.util.collections.MutableMap; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Iterables; + +public class JcloudsByonLocationResolverAwsLiveTest extends AbstractJcloudsLiveTest { + + private static final String AWS_REGION = "eu-west-1"; + private static final String AWS_LOCATION_SPEC = "jclouds:aws-ec2:"+AWS_REGION; + + private String awsVmUser; + private String awsVmInstanceId; + private String awsVmIp; + private String awsVmHostname; + + private LocalManagementContext classManagementContext; + private JcloudsLocation classEc2Loc; + private JcloudsSshMachineLocation classEc2Vm; + + @BeforeClass(groups="Live") + public void setUpClass() throws Exception { + classManagementContext = newManagementContext(); + classEc2Loc = (JcloudsLocation) classManagementContext.getLocationRegistry().resolve(AWS_LOCATION_SPEC); + classEc2Vm = classEc2Loc.obtain(MutableMap.builder() + .put("hardwareId", AWS_EC2_SMALL_HARDWARE_ID) + .put("inboundPorts", ImmutableList.of(22)) + .build()); + awsVmUser = classEc2Vm.getUser(); + awsVmInstanceId = classEc2Vm.getNode().getProviderId(); // id without region (e.g. "i-6ff96d2f" instead of "eu-west-1/i-6ff96d2f") + awsVmIp = classEc2Vm.getAddress().getHostAddress(); + awsVmHostname = classEc2Vm.getAddress().getHostName(); + } + + @AfterClass(alwaysRun=true) + public void tearDownClass() throws Exception { + try { + if (classEc2Vm != null) { + classEc2Loc.release(classEc2Vm); + } + } finally { + if (classManagementContext != null) classManagementContext.terminate(); + } + } + + // TODO Requires that a VM already exists; could create that VM first to make test more robust + @Test(groups={"Live"}) + public void testResolvesJcloudsByonAws() throws Exception { + String spec = "jcloudsByon:(provider=\"aws-ec2\",region=\""+AWS_REGION+"\",user=\""+awsVmUser+"\",hosts=\""+awsVmInstanceId+"\",anotherprop=myval)"; + + FixedListMachineProvisioningLocation loc = resolve(spec); + + Set machines = loc.getAllMachines(); + JcloudsSshMachineLocation machine = Iterables.getOnlyElement(machines); + assertEquals(machine.getParent().getProvider(), "aws-ec2"); + assertEquals(machine.getAddress().getHostAddress(), awsVmIp); + assertEquals(machine.getAddress().getHostName(), awsVmHostname); + assertEquals(machine.getUser(), awsVmUser); + assertEquals(machine.getAllConfig(true).get("anotherprop"), "myval"); + + assertTrue(machine.isSshable()); + } + + @Test(groups={"Live"}) + public void testResolvesNamedJcloudsByon() throws Exception { + String spec = "jcloudsByon:(provider=\"aws-ec2\",region=\""+AWS_REGION+"\",user=\""+awsVmUser+"\",hosts=\""+awsVmInstanceId+"\")"; + brooklynProperties.put("brooklyn.location.named.mynamed", spec); + + FixedListMachineProvisioningLocation loc = resolve("named:mynamed"); + assertEquals(loc.obtain().getAddress(), InetAddress.getByName(awsVmHostname)); + } + + @Test(groups={"Live"}) + public void testJcloudsPropertiesPrecedence() throws Exception { + String spec = "jcloudsByon:(provider=\"aws-ec2\",region=\""+AWS_REGION+"\",user=\""+awsVmUser+"\",hosts=\""+awsVmInstanceId+"\")"; + brooklynProperties.put("brooklyn.location.named.mynamed", spec); + + // prefer those in spec string over everything else + brooklynProperties.put("brooklyn.location.named.mynamed.user", "user-inNamed"); + brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.user", "user-inProviderSpecific"); + brooklynProperties.put("brooklyn.jclouds.aws-ec2.user", "user-inProviderSpecificDeprecated"); + brooklynProperties.put("brooklyn.location.jclouds.user", "user-inJcloudsGeneric"); + brooklynProperties.put("brooklyn.jclouds.user", "user-inJcloudsGenericDeprecated"); + brooklynProperties.put("brooklyn.location.user", "user-inLocationGeneric"); + + // prefer those in "named" over everything else (except spec string itself) + brooklynProperties.put("brooklyn.location.named.mynamed.privateKeyFile", "privateKeyFile-inNamed"); + brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.privateKeyFile", "privateKeyFile-inProviderSpecific"); + brooklynProperties.put("brooklyn.jclouds.aws-ec2.privateKeyFile", "privateKeyFile-inProviderSpecificDeprecated"); + brooklynProperties.put("brooklyn.location.jclouds.privateKeyFile", "privateKeyFile-inJcloudsGeneric"); + brooklynProperties.put("brooklyn.jclouds.privateKeyFile", "privateKeyFile-inJcloudsGenericDeprecated"); + brooklynProperties.put("brooklyn.location.privateKeyFile", "privateKeyFile-inLocationGeneric"); + + // prefer those in provider-specific over generic + brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.publicKeyFile", "publicKeyFile-inProviderSpecific"); + brooklynProperties.put("brooklyn.jclouds.aws-ec2.publicKeyFile", "publicKeyFile-inProviderSpecificDeprecated"); + brooklynProperties.put("brooklyn.location.jclouds.publicKeyFile", "publicKeyFile-inJcloudsGeneric"); + brooklynProperties.put("brooklyn.jclouds.publicKeyFile", "publicKeyFile-inJcloudsGenericDeprecated"); + brooklynProperties.put("brooklyn.location.publicKeyFile", "publicKeyFile-inLocationGeneric"); + + // prefer those in provider-specific (deprecated scope) over generic + brooklynProperties.put("brooklyn.jclouds.aws-ec2.securityGroups", "securityGroups-inProviderSpecificDeprecated"); + brooklynProperties.put("brooklyn.location.jclouds.securityGroups", "securityGroups-inJcloudsGeneric"); + brooklynProperties.put("brooklyn.jclouds.securityGroups", "securityGroups-inJcloudsGenericDeprecated"); + brooklynProperties.put("brooklyn.location.securityGroups", "securityGroups-inLocationGeneric"); + + // prefer those in jclouds-generic over location-generic + brooklynProperties.put("brooklyn.location.jclouds.loginUser", "loginUser-inJcloudsGeneric"); + brooklynProperties.put("brooklyn.jclouds.loginUser", "loginUser-inJcloudsGenericDeprecated"); + brooklynProperties.put("brooklyn.location.loginUser", "loginUser-inLocationGeneric"); + + // prefer those in jclouds-generic (deprecated) over location-generic + brooklynProperties.put("brooklyn.jclouds.imageId", "imageId-inJcloudsGenericDeprecated"); + brooklynProperties.put("brooklyn.location.imageId", "imageId-inLocationGeneric"); + + // prefer location-generic if nothing else + brooklynProperties.put("brooklyn.location.keyPair", "keyPair-inLocationGeneric"); + + // prefer deprecated properties in "named" over those less specific + brooklynProperties.put("brooklyn.location.named.mynamed.private-key-data", "privateKeyData-inNamed"); + brooklynProperties.put("brooklyn.jclouds.aws-ec2.privateKeyData", "privateKeyData-inProviderSpecific"); + brooklynProperties.put("brooklyn.jclouds.privateKeyData", "privateKeyData-inJcloudsGeneric"); + + // prefer "named" over everything else: confirm deprecated don't get transformed to overwrite it accidentally + brooklynProperties.put("brooklyn.location.named.mynamed.privateKeyPassphrase", "privateKeyPassphrase-inNamed"); + brooklynProperties.put("brooklyn.jclouds.aws-ec2.private-key-passphrase", "privateKeyPassphrase-inProviderSpecific"); + brooklynProperties.put("brooklyn.jclouds.private-key-passphrase", "privateKeyPassphrase-inJcloudsGeneric"); + + Map conf = resolve("named:mynamed").obtain().getAllConfig(true); + + assertEquals(conf.get("user"), awsVmUser); + assertEquals(conf.get("privateKeyFile"), "privateKeyFile-inNamed"); + assertEquals(conf.get("publicKeyFile"), "publicKeyFile-inProviderSpecific"); + assertEquals(conf.get("securityGroups"), "securityGroups-inProviderSpecificDeprecated"); + assertEquals(conf.get("loginUser"), "loginUser-inJcloudsGeneric"); + assertEquals(conf.get("imageId"), "imageId-inJcloudsGenericDeprecated"); + assertEquals(conf.get("keyPair"), "keyPair-inLocationGeneric"); + assertEquals(conf.get("privateKeyData"), "privateKeyData-inNamed"); + assertEquals(conf.get("privateKeyPassphrase"), "privateKeyPassphrase-inNamed"); + } + + @SuppressWarnings("unchecked") + private FixedListMachineProvisioningLocation resolve(String spec) { + return (FixedListMachineProvisioningLocation) managementContext.getLocationRegistry().resolve(spec); + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ec835ee7/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverLiveTest.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverLiveTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverLiveTest.java deleted file mode 100644 index 49e1faa..0000000 --- a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverLiveTest.java +++ /dev/null @@ -1,175 +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.location.jclouds; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; - -import java.net.InetAddress; -import java.util.Map; -import java.util.Set; - -import org.testng.annotations.Test; - -import brooklyn.location.basic.FixedListMachineProvisioningLocation; - -import com.google.common.collect.Iterables; - -public class JcloudsByonLocationResolverLiveTest extends AbstractJcloudsLiveTest { - - // FIXME Expects this VM to exist; how to write this better? - // We should create a VM in @BeforeClass - slower but automated and will work for everyone - private final String awsVm1User = "aled"; - private final String awsVm1InstanceId = "i-72b1b132"; - private final String awsVmIp = "54.195.164.70"; - private final String awsVmHostname = "ec2-54-195-164-70.eu-west-1.compute.amazonaws.com"; - - private final String slVmInstanceId = "4107756"; - private final String slVmIp = "81.95.147.234"; - private final String slVmHostname = "amp"; - - // TODO Requires that a VM already exists; could create that VM first to make test more robust - @Test(groups={"Live","WIP"}) - public void testResolvesJcloudsByonAws() throws Exception { - String spec = "jcloudsByon:(provider=\"aws-ec2\",region=\"eu-west-1\",user=\""+awsVm1User+"\",hosts=\""+awsVm1InstanceId+"\")"; - - FixedListMachineProvisioningLocation loc = resolve(spec); - - Set machines = loc.getAllMachines(); - JcloudsSshMachineLocation machine = Iterables.getOnlyElement(machines); - assertEquals(machine.getParent().getProvider(), "aws-ec2"); - assertEquals(machine.getAddress().getHostAddress(), awsVmIp); - assertEquals(machine.getAddress().getHostName(), awsVmHostname); - assertEquals(machine.getUser(), awsVm1User); - - assertTrue(machine.isSshable()); - } - - // TODO Requires that a VM already exists; could create that VM first to make test more robust - @Test(groups={"Live","WIP"}) - public void testResolvesNamedJcloudsByon() throws Exception { - String spec = "jcloudsByon:(provider=\"aws-ec2\",region=\"eu-west-1\",user=\""+awsVm1User+"\",hosts=\""+awsVm1InstanceId+"\")"; - brooklynProperties.put("brooklyn.location.named.mynamed", spec); - - FixedListMachineProvisioningLocation loc = resolve("named:mynamed"); - assertEquals(loc.obtain().getAddress(), InetAddress.getByName(awsVmHostname)); - } - - // TODO Requires that a VM already exists; could create that VM first to make test more robust - @Test(groups={"Live","WIP"}) - public void testJcloudsPropertiesPrecedence() throws Exception { - String spec = "jcloudsByon:(provider=\"aws-ec2\",region=\"eu-west-1\",user=\""+awsVm1User+"\",hosts=\""+awsVm1InstanceId+"\")"; - brooklynProperties.put("brooklyn.location.named.mynamed", spec); - - // prefer those in spec string over everything else - brooklynProperties.put("brooklyn.location.named.mynamed.user", "user-inNamed"); - brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.user", "user-inProviderSpecific"); - brooklynProperties.put("brooklyn.jclouds.aws-ec2.user", "user-inProviderSpecificDeprecated"); - brooklynProperties.put("brooklyn.location.jclouds.user", "user-inJcloudsGeneric"); - brooklynProperties.put("brooklyn.jclouds.user", "user-inJcloudsGenericDeprecated"); - brooklynProperties.put("brooklyn.location.user", "user-inLocationGeneric"); - - // prefer those in "named" over everything else (except spec string itself) - brooklynProperties.put("brooklyn.location.named.mynamed.privateKeyFile", "privateKeyFile-inNamed"); - brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.privateKeyFile", "privateKeyFile-inProviderSpecific"); - brooklynProperties.put("brooklyn.jclouds.aws-ec2.privateKeyFile", "privateKeyFile-inProviderSpecificDeprecated"); - brooklynProperties.put("brooklyn.location.jclouds.privateKeyFile", "privateKeyFile-inJcloudsGeneric"); - brooklynProperties.put("brooklyn.jclouds.privateKeyFile", "privateKeyFile-inJcloudsGenericDeprecated"); - brooklynProperties.put("brooklyn.location.privateKeyFile", "privateKeyFile-inLocationGeneric"); - - // prefer those in provider-specific over generic - brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.publicKeyFile", "publicKeyFile-inProviderSpecific"); - brooklynProperties.put("brooklyn.jclouds.aws-ec2.publicKeyFile", "publicKeyFile-inProviderSpecificDeprecated"); - brooklynProperties.put("brooklyn.location.jclouds.publicKeyFile", "publicKeyFile-inJcloudsGeneric"); - brooklynProperties.put("brooklyn.jclouds.publicKeyFile", "publicKeyFile-inJcloudsGenericDeprecated"); - brooklynProperties.put("brooklyn.location.publicKeyFile", "publicKeyFile-inLocationGeneric"); - - // prefer those in provider-specific (deprecated scope) over generic - brooklynProperties.put("brooklyn.jclouds.aws-ec2.securityGroups", "securityGroups-inProviderSpecificDeprecated"); - brooklynProperties.put("brooklyn.location.jclouds.securityGroups", "securityGroups-inJcloudsGeneric"); - brooklynProperties.put("brooklyn.jclouds.securityGroups", "securityGroups-inJcloudsGenericDeprecated"); - brooklynProperties.put("brooklyn.location.securityGroups", "securityGroups-inLocationGeneric"); - - // prefer those in jclouds-generic over location-generic - brooklynProperties.put("brooklyn.location.jclouds.loginUser", "loginUser-inJcloudsGeneric"); - brooklynProperties.put("brooklyn.jclouds.loginUser", "loginUser-inJcloudsGenericDeprecated"); - brooklynProperties.put("brooklyn.location.loginUser", "loginUser-inLocationGeneric"); - - // prefer those in jclouds-generic (deprecated) over location-generic - brooklynProperties.put("brooklyn.jclouds.imageId", "imageId-inJcloudsGenericDeprecated"); - brooklynProperties.put("brooklyn.location.imageId", "imageId-inLocationGeneric"); - - // prefer location-generic if nothing else - brooklynProperties.put("brooklyn.location.keyPair", "keyPair-inLocationGeneric"); - - // prefer deprecated properties in "named" over those less specific - brooklynProperties.put("brooklyn.location.named.mynamed.private-key-data", "privateKeyData-inNamed"); - brooklynProperties.put("brooklyn.jclouds.aws-ec2.privateKeyData", "privateKeyData-inProviderSpecific"); - brooklynProperties.put("brooklyn.jclouds.privateKeyData", "privateKeyData-inJcloudsGeneric"); - - // prefer "named" over everything else: confirm deprecated don't get transformed to overwrite it accidentally - brooklynProperties.put("brooklyn.location.named.mynamed.privateKeyPassphrase", "privateKeyPassphrase-inNamed"); - brooklynProperties.put("brooklyn.jclouds.aws-ec2.private-key-passphrase", "privateKeyPassphrase-inProviderSpecific"); - brooklynProperties.put("brooklyn.jclouds.private-key-passphrase", "privateKeyPassphrase-inJcloudsGeneric"); - - Map conf = resolve("named:mynamed").obtain().getAllConfig(true); - - assertEquals(conf.get("user"), awsVm1User); - assertEquals(conf.get("privateKeyFile"), "privateKeyFile-inNamed"); - assertEquals(conf.get("publicKeyFile"), "publicKeyFile-inProviderSpecific"); - assertEquals(conf.get("securityGroups"), "securityGroups-inProviderSpecificDeprecated"); - assertEquals(conf.get("loginUser"), "loginUser-inJcloudsGeneric"); - assertEquals(conf.get("imageId"), "imageId-inJcloudsGenericDeprecated"); - assertEquals(conf.get("keyPair"), "keyPair-inLocationGeneric"); - assertEquals(conf.get("privateKeyData"), "privateKeyData-inNamed"); - assertEquals(conf.get("privateKeyPassphrase"), "privateKeyPassphrase-inNamed"); - } - - // TODO Requires that a VM already exists; could create that VM first to make test more robust - @Test(groups={"Live","WIP"}) - public void testResolvesJcloudsByonSoftlayer() throws Exception { - checkSoftlayer("jcloudsByon:(provider=\"softlayer\",region=\"dal05\",hosts=\""+slVmInstanceId+"\")"); - checkSoftlayer("jcloudsByon:(provider=\"softlayer\",region=\"dal05\",hosts=\""+slVmHostname+"\")"); - checkSoftlayer("jcloudsByon:(provider=\"softlayer\",region=\"dal05\",hosts=\""+slVmIp+"\")"); - checkSoftlayer("jcloudsByon:(provider=\"softlayer\",hosts=\""+slVmIp+"\")"); - } - - private void checkSoftlayer(String spec) { - FixedListMachineProvisioningLocation loc = resolve(spec); - - Set machines = loc.getAllMachines(); - JcloudsSshMachineLocation machine = Iterables.getOnlyElement(machines); - assertEquals(machine.getParent().getProvider(), "softlayer"); - assertEquals(machine.getNode().getId(), slVmInstanceId); - assertEquals(machine.getAddress().getHostAddress(), slVmIp); - assertTrue(slVmHostname.equals(machine.getAddress().getHostName()) || slVmIp.equals(machine.getAddress().getHostName()), - "address hostname is: "+machine.getAddress().getHostName()); - assertTrue(slVmHostname.equals(machine.getNode().getHostname()) || slVmIp.equals(machine.getNode().getHostname()), - "node hostname is: "+machine.getNode().getHostname()); - - // could also assert this, given a user credential, but not currently set up -// assertTrue(machine.isSshable()); - } - - @SuppressWarnings("unchecked") - private FixedListMachineProvisioningLocation resolve(String spec) { - return (FixedListMachineProvisioningLocation) managementContext.getLocationRegistry().resolve(spec); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ec835ee7/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverSoftlayerLiveTest.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverSoftlayerLiveTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverSoftlayerLiveTest.java new file mode 100644 index 0000000..e04d20c --- /dev/null +++ b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverSoftlayerLiveTest.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package brooklyn.location.jclouds; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import java.util.Set; + +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import brooklyn.location.basic.FixedListMachineProvisioningLocation; +import brooklyn.management.internal.LocalManagementContext; +import brooklyn.util.collections.MutableMap; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Iterables; + +public class JcloudsByonLocationResolverSoftlayerLiveTest extends AbstractJcloudsLiveTest { + + private static final String SOFTLAYER_REGION = "dal05"; + private static final String SOFTLAYER_LOCATION_SPEC = "jclouds:softlayer:"+SOFTLAYER_REGION; + + private String slVmUser; + private String slVmInstanceId; + private String slVmIp; + private String slVmHostname; + + private LocalManagementContext classManagementContext; + private JcloudsLocation classEc2Loc; + private JcloudsSshMachineLocation classVm; + + @BeforeClass(groups="Live") + public void setUpClass() throws Exception { + classManagementContext = newManagementContext(); + classEc2Loc = (JcloudsLocation) classManagementContext.getLocationRegistry().resolve(SOFTLAYER_LOCATION_SPEC); + classVm = classEc2Loc.obtain(MutableMap.builder() + .put("inboundPorts", ImmutableList.of(22)) + .build()); + slVmUser = classVm.getUser(); + slVmInstanceId = classVm.getJcloudsId(); + slVmIp = classVm.getAddress().getHostAddress(); + slVmHostname = classVm.getNode().getHostname(); + } + + @AfterClass(alwaysRun=true) + public void tearDownClass() throws Exception { + try { + if (classVm != null) { + classEc2Loc.release(classVm); + } + } finally { + if (classManagementContext != null) classManagementContext.terminate(); + } + } + + @Test(groups={"Live"}) + public void testResolvesJcloudsByonSoftlayer() throws Exception { + checkSoftlayer("jcloudsByon:(provider=\"softlayer\",region=\""+SOFTLAYER_REGION+"\",hosts=\""+slVmInstanceId+"\",user=\""+slVmUser+"\")"); + checkSoftlayer("jcloudsByon:(provider=\"softlayer\",region=\""+SOFTLAYER_REGION+"\",hosts=\""+slVmHostname+"\")"); + checkSoftlayer("jcloudsByon:(provider=\"softlayer\",region=\""+SOFTLAYER_REGION+"\",hosts=\""+slVmIp+"\")"); + checkSoftlayer("jcloudsByon:(provider=\"softlayer\",hosts=\""+slVmIp+"\")"); + } + + private void checkSoftlayer(String spec) { + FixedListMachineProvisioningLocation loc = resolve(spec); + + Set machines = loc.getAllMachines(); + JcloudsSshMachineLocation machine = Iterables.getOnlyElement(machines); + assertEquals(machine.getParent().getProvider(), "softlayer"); + assertEquals(machine.getNode().getId(), slVmInstanceId); + assertEquals(machine.getAddress().getHostAddress(), slVmIp); + assertTrue(slVmHostname.equals(machine.getAddress().getHostName()) || slVmIp.equals(machine.getAddress().getHostName()), + "address hostname is: "+machine.getAddress().getHostName()); + assertTrue(slVmHostname.equals(machine.getNode().getHostname()) || slVmIp.equals(machine.getNode().getHostname()), + "node hostname is: "+machine.getNode().getHostname()); + + // could also assert this, given a user credential, but not currently set up +// assertTrue(machine.isSshable()); + } + + @SuppressWarnings("unchecked") + private FixedListMachineProvisioningLocation resolve(String spec) { + return (FixedListMachineProvisioningLocation) managementContext.getLocationRegistry().resolve(spec); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ec835ee7/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverTest.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverTest.java index 86e790f..77b1e74 100644 --- a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverTest.java +++ b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverTest.java @@ -51,9 +51,9 @@ public class JcloudsByonLocationResolverTest { assertThrowsIllegalArgument("jcloudsByon"); // no hosts assertThrowsIllegalArgument("jcloudsByon:()"); // no hosts assertThrowsIllegalArgument("jcloudsByon:(hosts=\"\")"); // empty hosts - assertThrowsIllegalArgument("jcloudsByon:(hosts=\"1.1.1.1\""); // no closing bracket - assertThrowsIllegalArgument("jcloudsByon:(hosts=\"1.1.1.1\", name)"); // no value for name - assertThrowsIllegalArgument("jcloudsByon:(hosts=\"1.1.1.1\", name=)"); // no value for name + assertThrowsIllegalArgument("jcloudsByon:(hosts=\"i-72b1b132\""); // no closing bracket + assertThrowsIllegalArgument("jcloudsByon:(hosts=\"i-72b1b132\", name)"); // no value for name + assertThrowsIllegalArgument("jcloudsByon:(hosts=\"i-72b1b132\", name=)"); // no value for name } @SuppressWarnings("unchecked")