brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [7/9] incubator-brooklyn git commit: support ProxySslConfig being set from map, so we can configure nginx via yaml
Date Mon, 15 Dec 2014 16:57:34 GMT
support ProxySslConfig being set from map, so we can configure nginx via yaml


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

Branch: refs/heads/master
Commit: ccb9a1b1947725cb9f0e35409990a3a9f14b4673
Parents: ff7126a
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Thu Nov 27 11:43:21 2014 +0000
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Fri Dec 12 13:54:55 2014 +0000

----------------------------------------------------------------------
 .../brooklyn/entity/proxy/ProxySslConfig.java   | 28 ++++++++++---
 .../entity/proxy/ProxySslConfigTest.java        | 42 ++++++++++++++++++++
 2 files changed, 64 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ccb9a1b1/software/webapp/src/main/java/brooklyn/entity/proxy/ProxySslConfig.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/main/java/brooklyn/entity/proxy/ProxySslConfig.java b/software/webapp/src/main/java/brooklyn/entity/proxy/ProxySslConfig.java
index 219bf27..0a61021 100644
--- a/software/webapp/src/main/java/brooklyn/entity/proxy/ProxySslConfig.java
+++ b/software/webapp/src/main/java/brooklyn/entity/proxy/ProxySslConfig.java
@@ -19,6 +19,13 @@
 package brooklyn.entity.proxy;
 
 import java.io.Serializable;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.util.flags.FlagUtils;
+import brooklyn.util.flags.SetFromFlag;
 
 import com.google.common.base.Objects;
 
@@ -26,17 +33,19 @@ public class ProxySslConfig implements Serializable {
 
     private static final long serialVersionUID = -2692754611458939617L;
 
+    private static final Logger log = LoggerFactory.getLogger(ProxySslConfig.class);
+    
     public static Builder builder() {
         return new Builder();
     }
 
     public static class Builder {
-        protected String certificateSourceUrl;
-        protected String keySourceUrl;
-        protected String certificateDestination;
-        protected String keyDestination;
-        protected boolean targetIsSsl = false;
-        protected boolean reuseSessions = false;
+        @SetFromFlag protected String certificateSourceUrl;
+        @SetFromFlag protected String keySourceUrl;
+        @SetFromFlag protected String certificateDestination;
+        @SetFromFlag protected String keyDestination;
+        @SetFromFlag protected boolean targetIsSsl = false;
+        @SetFromFlag protected boolean reuseSessions = false;
 
         public Builder certificateSourceUrl(String val) {
             certificateSourceUrl = val; return this;
@@ -61,6 +70,13 @@ public class ProxySslConfig implements Serializable {
             return result;
         }
     }
+    
+    public static ProxySslConfig fromMap(Map<?,?> map) {
+        Builder b = new Builder();
+        Map<?, ?> unused = FlagUtils.setFieldsFromFlags(map, b);
+        if (!unused.isEmpty()) log.warn("Unused flags when populating "+b+" (ignoring): "+unused);
+        return b.build();
+    }
 
     private String certificateSourceUrl;
     private String keySourceUrl;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ccb9a1b1/software/webapp/src/test/java/brooklyn/entity/proxy/ProxySslConfigTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/proxy/ProxySslConfigTest.java b/software/webapp/src/test/java/brooklyn/entity/proxy/ProxySslConfigTest.java
new file mode 100644
index 0000000..77ea8a5
--- /dev/null
+++ b/software/webapp/src/test/java/brooklyn/entity/proxy/ProxySslConfigTest.java
@@ -0,0 +1,42 @@
+package brooklyn.entity.proxy;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.flags.TypeCoercions;
+
+@Test
+public class ProxySslConfigTest {
+
+    @Test
+    public void testFromMap() {
+        ProxySslConfig config = TypeCoercions.coerce(MutableMap.of(
+            "certificateSourceUrl", "file://tmp/cert.txt", 
+            "keySourceUrl", "file://tmp/key.txt", 
+            "keyDestination", "dest.txt", 
+            "targetIsSsl", true, 
+            "reuseSessions", true), 
+            ProxySslConfig.class);
+        Assert.assertEquals(config.getCertificateSourceUrl(), "file://tmp/cert.txt");
+        Assert.assertEquals(config.getKeySourceUrl(), "file://tmp/key.txt");
+        Assert.assertEquals(config.getKeyDestination(), "dest.txt");
+        Assert.assertEquals(config.getTargetIsSsl(), true);
+        Assert.assertEquals(config.getReuseSessions(), true);
+    }
+    
+    @Test
+    public void testFromMapWithNullsAndDefaults() {
+        ProxySslConfig config = TypeCoercions.coerce(MutableMap.of(
+            "certificateSourceUrl", "file://tmp/cert.txt", 
+            "keySourceUrl", null, 
+            "targetIsSsl", "false"), 
+            ProxySslConfig.class);
+        Assert.assertEquals(config.getCertificateSourceUrl(), "file://tmp/cert.txt");
+        Assert.assertEquals(config.getKeySourceUrl(), null);
+        Assert.assertEquals(config.getKeyDestination(), null);
+        Assert.assertEquals(config.getTargetIsSsl(), false);
+        Assert.assertEquals(config.getReuseSessions(), false);
+    }
+    
+}


Mime
View raw message