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 2016/02/09 09:18:27 UTC

[1/2] brooklyn-server git commit: Improve how properties to pass to jclouds are selected including b.l.j.jclouds.xxx properties (which jclouds understands) and known multi-word

Repository: brooklyn-server
Updated Branches:
  refs/heads/master 5bb87183e -> c21fa6d49


Improve how properties to pass to jclouds are selected
including b.l.j.jclouds.xxx properties (which jclouds understands) and known multi-word


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/1afe5f2d
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/1afe5f2d
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/1afe5f2d

Branch: refs/heads/master
Commit: 1afe5f2dfd27a2a833538ce14d281b0ac792ab2f
Parents: 1298d37
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Fri Feb 5 12:16:54 2016 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Fri Feb 5 12:16:54 2016 +0000

----------------------------------------------------------------------
 ...ocationPropertiesFromBrooklynProperties.java | 10 +++++
 ...JcloudsPropertiesFromBrooklynProperties.java | 34 +++++++++++++++-
 .../jclouds/JcloudsLocationResolverTest.java    | 42 +++++++++++++++++++-
 3 files changed, 83 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/1afe5f2d/core/src/main/java/org/apache/brooklyn/core/location/LocationPropertiesFromBrooklynProperties.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/location/LocationPropertiesFromBrooklynProperties.java b/core/src/main/java/org/apache/brooklyn/core/location/LocationPropertiesFromBrooklynProperties.java
index c6ada78..e2d1cdf 100644
--- a/core/src/main/java/org/apache/brooklyn/core/location/LocationPropertiesFromBrooklynProperties.java
+++ b/core/src/main/java/org/apache/brooklyn/core/location/LocationPropertiesFromBrooklynProperties.java
@@ -30,6 +30,7 @@ import org.apache.brooklyn.util.collections.MutableMap;
 import org.apache.brooklyn.util.core.config.ConfigBag;
 import org.apache.brooklyn.util.core.internal.ssh.SshTool;
 import org.apache.brooklyn.util.os.Os;
+import org.apache.brooklyn.util.text.StringPredicates;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -171,6 +172,15 @@ public class LocationPropertiesFromBrooklynProperties {
     }
 
     /**
+     * Gets all properties that start with the given {@code <firstPrefix>.<secondPrefix>}, stripping off
+     * the {@code firstPrefix} in the returned map.
+     */
+    protected Map<String, Object> getMatchingConcatenatedPrefixesPropertiesFirstPrefixRemoved(String firstPrefix, String secondPrefix, Map<String, ?> properties) {
+        BrooklynProperties filteredProperties = ConfigUtils.filterForPrefixAndStrip(properties, firstPrefix);
+        return ConfigUtils.filterFor(filteredProperties, StringPredicates.startsWith(secondPrefix)).asMapWithStringKeys();
+    }
+
+    /**
      * Gets all single-word properties that start with either of the given prefixes. The {@code fullPreferredPrefix} 
      * properties will override any duplicates in {@code fullDeprecatedPrefix}. If there are any
      * properties that match the {@code fullDeprecatedPrefix}, then a warning will be logged.

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/1afe5f2d/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsPropertiesFromBrooklynProperties.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsPropertiesFromBrooklynProperties.java b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsPropertiesFromBrooklynProperties.java
index acc8d32..b00d004 100644
--- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsPropertiesFromBrooklynProperties.java
+++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsPropertiesFromBrooklynProperties.java
@@ -19,15 +19,20 @@
 package org.apache.brooklyn.location.jclouds;
 
 import java.util.Map;
+import java.util.Set;
 
+import org.apache.brooklyn.config.ConfigKey.HasConfigKey;
 import org.apache.brooklyn.core.config.ConfigUtils;
+import org.apache.brooklyn.core.internal.BrooklynProperties;
 import org.apache.brooklyn.core.location.DeprecatedKeysMappingBuilder;
 import org.apache.brooklyn.core.location.LocationConfigKeys;
 import org.apache.brooklyn.core.location.LocationPropertiesFromBrooklynProperties;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.apache.brooklyn.util.collections.MutableSet;
 import org.apache.brooklyn.util.core.config.ConfigBag;
 import org.apache.brooklyn.util.javalang.JavaClassNames;
+import org.apache.brooklyn.util.text.StringPredicates;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Splitter;
 import com.google.common.base.Strings;
@@ -88,7 +93,10 @@ public class JcloudsPropertiesFromBrooklynProperties extends LocationPropertiesF
         // named properties are preferred over providerOrApi properties
         jcloudsProperties.put(LocationConfigKeys.CLOUD_PROVIDER, provider);
         jcloudsProperties.putAll(transformDeprecated(getGenericLocationSingleWordProperties(properties)));
+        jcloudsProperties.putAll(transformDeprecated(getGenericLocationKnownProperties(properties)));
         jcloudsProperties.putAll(transformDeprecated(getGenericJcloudsSingleWordProperties(providerOrApi, properties)));
+        jcloudsProperties.putAll(transformDeprecated(getGenericJcloudsKnownProperties(properties)));
+        jcloudsProperties.putAll(transformDeprecated(getGenericJcloudsPropertiesPrefixedJclouds(providerOrApi, properties)));
         jcloudsProperties.putAll(transformDeprecated(getProviderOrApiJcloudsProperties(providerOrApi, properties)));
         jcloudsProperties.putAll(transformDeprecated(getRegionJcloudsProperties(providerOrApi, regionOrEndpoint, properties)));
         if (!Strings.isNullOrEmpty(namedLocation)) jcloudsProperties.putAll(transformDeprecated(getNamedJcloudsProperties(namedLocation, properties)));
@@ -121,6 +129,21 @@ public class JcloudsPropertiesFromBrooklynProperties extends LocationPropertiesF
     protected String getProviderFromDefinition(String definition) {
         return Iterables.get(Splitter.on(":").split(definition), 1);
     }
+    
+    private Map<String, ?> getGenericLocationKnownProperties(Map<String, ?> properties) {
+        return getMatchingPropertiesWithoutPrefixInSet("brooklyn.location.", ConfigUtils.getStaticKeysOnClass(JcloudsLocationConfig.class), properties);
+    }
+
+    private Map<String, ?> getGenericJcloudsKnownProperties(Map<String, ?> properties) {
+        return getMatchingPropertiesWithoutPrefixInSet("brooklyn.location.jclouds.", ConfigUtils.getStaticKeysOnClass(JcloudsLocationConfig.class), properties);
+    }
+
+    private Map<String, ?> getMatchingPropertiesWithoutPrefixInSet(String prefix, Set<HasConfigKey<?>> keysToKeep, Map<String, ?> properties) {
+        BrooklynProperties filteredProperties = ConfigUtils.filterForPrefixAndStrip(properties, prefix);
+        Set<String> keysToKeepStrings = MutableSet.of();
+        for (HasConfigKey<?> key: keysToKeep) keysToKeepStrings.add(key.getConfigKey().getName());
+        return ConfigUtils.filterFor(filteredProperties, StringPredicates.equalToAny(keysToKeepStrings)).asMapWithStringKeys();
+    }
 
     protected Map<String, Object> getGenericJcloudsSingleWordProperties(String providerOrApi, Map<String, ?> properties) {
         if (Strings.isNullOrEmpty(providerOrApi)) return Maps.newHashMap();
@@ -129,6 +152,13 @@ public class JcloudsPropertiesFromBrooklynProperties extends LocationPropertiesF
         return getMatchingSingleWordProperties(preferredPrefix, deprecatedPrefix, properties);
     }
 
+    protected Map<String, Object> getGenericJcloudsPropertiesPrefixedJclouds(String providerOrApi, Map<String, ?> properties) {
+        if (Strings.isNullOrEmpty(providerOrApi)) return Maps.newHashMap();
+        String prefixToStrip = "brooklyn.location.jclouds.";
+        String prefixToKeep = "jclouds.";
+        return getMatchingConcatenatedPrefixesPropertiesFirstPrefixRemoved(prefixToStrip, prefixToKeep, properties);
+    }
+
     protected Map<String, Object> getProviderOrApiJcloudsProperties(String providerOrApi, Map<String, ?> properties) {
         if (Strings.isNullOrEmpty(providerOrApi)) return Maps.newHashMap();
         String preferredPrefix = String.format("brooklyn.location.jclouds.%s.", providerOrApi);

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/1afe5f2d/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsLocationResolverTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsLocationResolverTest.java b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsLocationResolverTest.java
index 1ec8cc1..1ef3148 100644
--- a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsLocationResolverTest.java
+++ b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsLocationResolverTest.java
@@ -21,6 +21,7 @@ package org.apache.brooklyn.location.jclouds;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.fail;
 
+import java.util.List;
 import java.util.Map;
 import java.util.NoSuchElementException;
 import java.util.Set;
@@ -32,6 +33,7 @@ import org.apache.brooklyn.core.location.cloud.CloudLocationConfig;
 import org.apache.brooklyn.core.location.internal.LocationInternal;
 import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
 import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
+import org.apache.brooklyn.util.collections.MutableList;
 import org.apache.brooklyn.util.collections.MutableMap;
 import org.apache.brooklyn.util.collections.MutableSet;
 import org.slf4j.Logger;
@@ -79,6 +81,7 @@ public class JcloudsLocationResolverTest {
         brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.privateKeyData", "myprivateKeyData");
         brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.publicKeyData", "myPublicKeyData");
         brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.privateKeyPassphrase", "myprivateKeyPassphrase");
+        brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.multi.prefix.property", "value");
         Map<String, Object> conf = resolve("jclouds:aws-ec2").config().getBag().getAllConfig();
 
         assertEquals(conf.get("privateKeyFile"), "myprivatekeyfile");
@@ -86,15 +89,17 @@ public class JcloudsLocationResolverTest {
         assertEquals(conf.get("privateKeyData"), "myprivateKeyData");
         assertEquals(conf.get("publicKeyData"), "myPublicKeyData");
         assertEquals(conf.get("privateKeyPassphrase"), "myprivateKeyPassphrase");
+        assertEquals(conf.get("multi.prefix.property"), "value");
     }
 
     @Test
-    public void testJcloudsTakesGenericScopedProperties() {
+    public void testJcloudsTakesGenericScopedSingleWordProperties() {
         brooklynProperties.put("brooklyn.location.jclouds.privateKeyFile", "myprivatekeyfile");
         brooklynProperties.put("brooklyn.location.jclouds.publicKeyFile", "mypublickeyfile");
         brooklynProperties.put("brooklyn.location.jclouds.privateKeyData", "myprivateKeyData");
         brooklynProperties.put("brooklyn.location.jclouds.publicKeyData", "myPublicKeyData");
         brooklynProperties.put("brooklyn.location.jclouds.privateKeyPassphrase", "myprivateKeyPassphrase");
+        brooklynProperties.put("brooklyn.location.jclouds.unrecognizedKey", "value");
         Map<String, Object> conf = resolve("jclouds:aws-ec2").config().getBag().getAllConfig();
 
         assertEquals(conf.get("privateKeyFile"), "myprivatekeyfile");
@@ -102,6 +107,25 @@ public class JcloudsLocationResolverTest {
         assertEquals(conf.get("privateKeyData"), "myprivateKeyData");
         assertEquals(conf.get("publicKeyData"), "myPublicKeyData");
         assertEquals(conf.get("privateKeyPassphrase"), "myprivateKeyPassphrase");
+        assertEquals(conf.get("unrecognizedKey"), "value");
+    }
+
+    @Test
+    public void testJcloudsTakesOnlyKnownGenericMultiwordProperties() {
+        brooklynProperties.put("brooklyn.location.multi_word.property", "not-set");
+        brooklynProperties.put("brooklyn.location.loginUser.privateKeyData", "is-set");
+        
+        brooklynProperties.put("brooklyn.location.jclouds.another.multi_word.property", "not-set");
+        brooklynProperties.put("brooklyn.location.jclouds.loginUser.password", "is-set");
+        brooklynProperties.put("brooklyn.location.jclouds.jclouds.multi_word.property", "is-set");
+        
+        Map<String, Object> conf = resolve("jclouds:aws-ec2").config().getBag().getAllConfig();
+        
+        Assert.assertNull(conf.get("multi_word.property"));
+        assertEquals(conf.get("loginUser.privateKeyData"), "is-set");
+        Assert.assertNull(conf.get("another.multi_word.property"));
+        assertEquals(conf.get("loginUser.password"), "is-set");
+        assertEquals(conf.get("jclouds.multi_word.property"), "is-set");
     }
 
     @Test
@@ -350,6 +374,22 @@ public class JcloudsLocationResolverTest {
         resolve("jclouds");
     }
 
+    @Test
+    public void testInheritancePublicKeyDocsExample() {
+        // illustration used in the docs
+        brooklynProperties.put("brooklyn.location.extraSshPublicKeyUrls", "http://me.com/public_key");
+        brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.extraSshPublicKeyUrls", "[ \"http://me.com/public_key\", \"http://me.com/aws_public_key\" ]");
+        brooklynProperties.put("brooklyn.location.named.prod1", "jclouds:aws-ec2");
+        brooklynProperties.put("brooklyn.location.named.prod1.extraSshPublicKeyUrls", "");
+
+        Assert.assertEquals(resolve("jclouds:softlayer").config().get(JcloudsLocationConfig.EXTRA_PUBLIC_KEY_URLS_TO_AUTH),
+            MutableList.of("http://me.com/public_key"));
+        Assert.assertEquals(resolve("jclouds:aws-ec2").config().get(JcloudsLocationConfig.EXTRA_PUBLIC_KEY_URLS_TO_AUTH),
+            MutableList.of("http://me.com/public_key", "http://me.com/aws_public_key"));
+        Assert.assertEquals(resolve("named:prod1").config().get(JcloudsLocationConfig.EXTRA_PUBLIC_KEY_URLS_TO_AUTH),
+            MutableList.of());
+    }
+    
     private JcloudsLocation resolve(String spec) {
         return (JcloudsLocation) managementContext.getLocationRegistry().resolve(spec);
     }


[2/2] brooklyn-server git commit: Closes #7

Posted by sv...@apache.org.
Closes #7

Improve how properties to pass to jclouds are selected


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/c21fa6d4
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/c21fa6d4
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/c21fa6d4

Branch: refs/heads/master
Commit: c21fa6d4989291a70e7fe0a44f4185bd8a19e580
Parents: 5bb8718 1afe5f2
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Tue Feb 9 10:18:17 2016 +0200
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Tue Feb 9 10:18:17 2016 +0200

----------------------------------------------------------------------
 ...ocationPropertiesFromBrooklynProperties.java | 10 +++++
 ...JcloudsPropertiesFromBrooklynProperties.java | 34 +++++++++++++++-
 .../jclouds/JcloudsLocationResolverTest.java    | 42 +++++++++++++++++++-
 3 files changed, 83 insertions(+), 3 deletions(-)
----------------------------------------------------------------------