You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by grkvlt <gi...@git.apache.org> on 2014/08/18 13:22:07 UTC

[GitHub] incubator-brooklyn pull request: Add type coercion from Map to Pro...

GitHub user grkvlt opened a pull request:

    https://github.com/apache/incubator-brooklyn/pull/123

    Add type coercion from Map to ProxySslConfig

    Adds a new type coercion that converts the `Map` data generated from a YAML config into a `ProxySslConfig` object. Expects data like this:
    
    ```JS
    - serviceType: brooklyn.entity.proxy.nginx.NginxController
      id: nginx
      brooklyn.config:
        ssl:
          certificateSourceUrl: "classpath://server.crt"
          keySourceUrl: "classpath://server.key"
    ```

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/grkvlt/incubator-brooklyn enhancement/proxysslconfig-coercion

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-brooklyn/pull/123.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #123
    
----
commit 086fb357eff6b64eaaabe03ed012339649ea74f0
Author: Andrew Kennedy <gr...@apache.org>
Date:   2014-08-18T11:09:59Z

    Add type coercion from Map to ProxySslConfig

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Add type coercion from Map to Pro...

Posted by grkvlt <gi...@git.apache.org>.
Github user grkvlt commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/123#discussion_r16392362
  
    --- Diff: software/webapp/src/main/java/brooklyn/entity/proxy/ProxySslConfig.java ---
    @@ -19,11 +19,48 @@
     package brooklyn.entity.proxy;
     
     import java.io.Serializable;
    +import java.util.Map;
    +import java.util.concurrent.atomic.AtomicBoolean;
     
    +import brooklyn.util.flags.TypeCoercions;
    +
    +import com.google.common.base.Function;
     import com.google.common.base.Objects;
     
     public class ProxySslConfig implements Serializable {
     
    +    private static AtomicBoolean initialized = new AtomicBoolean(false);
    +
    +    /** Setup type coercion. */
    +    @SuppressWarnings("rawtypes")
    +    public static void init() {
    +        if (initialized.getAndSet(true)) return;
    +
    +        TypeCoercions.registerAdapter(Map.class, ProxySslConfig.class, new Function<Map, ProxySslConfig>() {
    +            @Override
    +            public ProxySslConfig apply(final Map input) {
    +                ProxySslConfig sslConfig = new ProxySslConfig();
    +                sslConfig.certificateSourceUrl = (String) input.get("certificateSourceUrl");
    +                sslConfig.keySourceUrl = (String) input.get("keySourceUrl");
    +                sslConfig.certificateDestination = (String) input.get("certificateDestination");
    +                sslConfig.keyDestination = (String) input.get("keyDestination");
    +                Object targetIsSsl = input.get("targetIsSsl");
    +                if (targetIsSsl != null) {
    +                    sslConfig.targetIsSsl = TypeCoercions.coerce(targetIsSsl, Boolean.TYPE);
    +                }
    +                Object reuseSessions = input.get("reuseSessions");
    +                if (reuseSessions != null) {
    +                    sslConfig.reuseSessions = TypeCoercions.coerce(reuseSessions, Boolean.TYPE);
    +                }
    +                return sslConfig;
    +            }
    +        });
    +    }
    +
    +    static {
    --- End diff --
    
    Any `ConfigKey` definition with the `ProxySslConfig` type (for example in
    the `LoadBalancer` interface) causes the class static initialisers to be
    called.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Add type coercion from Map to Pro...

Posted by grkvlt <gi...@git.apache.org>.
Github user grkvlt commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/123#discussion_r16392441
  
    --- Diff: software/webapp/src/main/java/brooklyn/entity/proxy/ProxySslConfig.java ---
    @@ -19,11 +19,48 @@
     package brooklyn.entity.proxy;
     
     import java.io.Serializable;
    +import java.util.Map;
    +import java.util.concurrent.atomic.AtomicBoolean;
     
    +import brooklyn.util.flags.TypeCoercions;
    +
    +import com.google.common.base.Function;
     import com.google.common.base.Objects;
     
     public class ProxySslConfig implements Serializable {
     
    +    private static AtomicBoolean initialized = new AtomicBoolean(false);
    +
    +    /** Setup type coercion. */
    +    @SuppressWarnings("rawtypes")
    +    public static void init() {
    +        if (initialized.getAndSet(true)) return;
    +
    +        TypeCoercions.registerAdapter(Map.class, ProxySslConfig.class, new Function<Map, ProxySslConfig>() {
    +            @Override
    +            public ProxySslConfig apply(final Map input) {
    +                ProxySslConfig sslConfig = new ProxySslConfig();
    +                sslConfig.certificateSourceUrl = (String) input.get("certificateSourceUrl");
    +                sslConfig.keySourceUrl = (String) input.get("keySourceUrl");
    +                sslConfig.certificateDestination = (String) input.get("certificateDestination");
    +                sslConfig.keyDestination = (String) input.get("keyDestination");
    +                Object targetIsSsl = input.get("targetIsSsl");
    +                if (targetIsSsl != null) {
    +                    sslConfig.targetIsSsl = TypeCoercions.coerce(targetIsSsl, Boolean.TYPE);
    +                }
    +                Object reuseSessions = input.get("reuseSessions");
    +                if (reuseSessions != null) {
    +                    sslConfig.reuseSessions = TypeCoercions.coerce(reuseSessions, Boolean.TYPE);
    +                }
    +                return sslConfig;
    --- End diff --
    
    Not sure we should do anything except log any left-over keys, but I'll
    change to do that.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Add type coercion from Map to Pro...

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/123#discussion_r16352221
  
    --- Diff: software/webapp/src/main/java/brooklyn/entity/proxy/ProxySslConfig.java ---
    @@ -19,11 +19,48 @@
     package brooklyn.entity.proxy;
     
     import java.io.Serializable;
    +import java.util.Map;
    +import java.util.concurrent.atomic.AtomicBoolean;
     
    +import brooklyn.util.flags.TypeCoercions;
    +
    +import com.google.common.base.Function;
     import com.google.common.base.Objects;
     
     public class ProxySslConfig implements Serializable {
     
    +    private static AtomicBoolean initialized = new AtomicBoolean(false);
    +
    +    /** Setup type coercion. */
    +    @SuppressWarnings("rawtypes")
    +    public static void init() {
    +        if (initialized.getAndSet(true)) return;
    +
    +        TypeCoercions.registerAdapter(Map.class, ProxySslConfig.class, new Function<Map, ProxySslConfig>() {
    +            @Override
    +            public ProxySslConfig apply(final Map input) {
    +                ProxySslConfig sslConfig = new ProxySslConfig();
    +                sslConfig.certificateSourceUrl = (String) input.get("certificateSourceUrl");
    +                sslConfig.keySourceUrl = (String) input.get("keySourceUrl");
    +                sslConfig.certificateDestination = (String) input.get("certificateDestination");
    +                sslConfig.keyDestination = (String) input.get("keyDestination");
    +                Object targetIsSsl = input.get("targetIsSsl");
    +                if (targetIsSsl != null) {
    +                    sslConfig.targetIsSsl = TypeCoercions.coerce(targetIsSsl, Boolean.TYPE);
    +                }
    +                Object reuseSessions = input.get("reuseSessions");
    +                if (reuseSessions != null) {
    +                    sslConfig.reuseSessions = TypeCoercions.coerce(reuseSessions, Boolean.TYPE);
    +                }
    +                return sslConfig;
    --- End diff --
    
    Can/should we warn if there are config options in the map that were not recognized?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Add type coercion from Map to Pro...

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/123#discussion_r16352171
  
    --- Diff: software/webapp/src/main/java/brooklyn/entity/proxy/ProxySslConfig.java ---
    @@ -19,11 +19,48 @@
     package brooklyn.entity.proxy;
     
     import java.io.Serializable;
    +import java.util.Map;
    +import java.util.concurrent.atomic.AtomicBoolean;
     
    +import brooklyn.util.flags.TypeCoercions;
    +
    +import com.google.common.base.Function;
     import com.google.common.base.Objects;
     
     public class ProxySslConfig implements Serializable {
     
    +    private static AtomicBoolean initialized = new AtomicBoolean(false);
    +
    +    /** Setup type coercion. */
    +    @SuppressWarnings("rawtypes")
    +    public static void init() {
    +        if (initialized.getAndSet(true)) return;
    +
    +        TypeCoercions.registerAdapter(Map.class, ProxySslConfig.class, new Function<Map, ProxySslConfig>() {
    +            @Override
    +            public ProxySslConfig apply(final Map input) {
    +                ProxySslConfig sslConfig = new ProxySslConfig();
    +                sslConfig.certificateSourceUrl = (String) input.get("certificateSourceUrl");
    +                sslConfig.keySourceUrl = (String) input.get("keySourceUrl");
    +                sslConfig.certificateDestination = (String) input.get("certificateDestination");
    +                sslConfig.keyDestination = (String) input.get("keyDestination");
    +                Object targetIsSsl = input.get("targetIsSsl");
    +                if (targetIsSsl != null) {
    +                    sslConfig.targetIsSsl = TypeCoercions.coerce(targetIsSsl, Boolean.TYPE);
    +                }
    +                Object reuseSessions = input.get("reuseSessions");
    +                if (reuseSessions != null) {
    +                    sslConfig.reuseSessions = TypeCoercions.coerce(reuseSessions, Boolean.TYPE);
    +                }
    +                return sslConfig;
    +            }
    +        });
    +    }
    +
    +    static {
    --- End diff --
    
    What will have caused ProxySslConfig class to be loaded, for this static `init()` to be called?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Add type coercion from Map to Pro...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/incubator-brooklyn/pull/123


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---