You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by mikezaccardo <gi...@git.apache.org> on 2015/11/17 21:35:34 UTC

[GitHub] incubator-brooklyn pull request: Add quorum check enricher and agg...

GitHub user mikezaccardo opened a pull request:

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

    Add quorum check enricher and aggregator

    This addition enables the creation of a sensor, defined in YAML, to set its value based on whether a quorum of entities has has the necessary source sensor value.
    
    Example:
    
    ```
    name: Quorum Check Test
    location: localhost
    services:
      - type: org.apache.brooklyn.entity.group.DynamicCluster
        name: Cluster
        
        brooklyn.config:
          initialSize: 5
        
        memberSpec:
            $brooklyn:entitySpec:
                type: org.apache.brooklyn.entity.software.base.EmptySoftwareProcess
                name: Cluster Member
                
        brooklyn.enrichers:
        - type: org.apache.brooklyn.enricher.stock.Aggregator
          brooklyn.config:
            uniqueTag: service-all-is-up-aggregator
            enricher.transformation.untyped: "isQuorate"
            quorum.check.type: "allAndAtLeastOne"
            quorum.total.size: $brooklyn:config("cluster.initial.size")
            enricher.aggregator.excludeBlank: true
            enricher.aggregating.fromMembers: true
            enricher.sourceSensor: $brooklyn:sensor("service.isUp")
            enricher.targetSensor: $brooklyn:sensor("cluster.isQuorate")
    ```
    
    This creates a `cluster.isQuorate` sensor whose value depends on whether a quorum of cluster members have `service.isUp` equal to true.  In this example, all members must have a true value since `allAndAtLeastOne` is the specified `quorum.check.type`.

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

    $ git pull https://github.com/mikezaccardo/incubator-brooklyn quorum-check-enricher-aggregator

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

    https://github.com/apache/incubator-brooklyn/pull/1037.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 #1037
    
----
commit 2a7eb77ec44ae5ac83850fb4cbff729295806238
Author: Mike Zaccardo <mi...@cloudsoftcorp.com>
Date:   2015-11-17T20:28:26Z

    Add quorum check enricher and aggregator

----


---
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 quorum check enricher and agg...

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

    https://github.com/apache/incubator-brooklyn/pull/1037#discussion_r45765140
  
    --- Diff: core/src/main/java/org/apache/brooklyn/enricher/stock/Enrichers.java ---
    @@ -891,6 +892,39 @@ protected static int count(Iterable<? extends Object> vals, boolean includeNullV
             return result;
         }
         
    +    @Beta
    +    public static class ComputingIsQuorate<T extends Object> implements Function<Collection<T>, T> {
    --- End diff --
    
    I can't escape the generics either. However, I can cast `ComputingIsQuorate` to `(Function<? super Collection<?>, ?>)` in Aggregator! Personally I prefer keeping ComputingIsQuorate simple and the ugliness in `lookupTransformation`.


---
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 quorum check enricher and agg...

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

    https://github.com/apache/incubator-brooklyn/pull/1037#discussion_r45662431
  
    --- Diff: core/src/main/java/org/apache/brooklyn/enricher/stock/Enrichers.java ---
    @@ -891,6 +892,39 @@ protected static int count(Iterable<? extends Object> vals, boolean includeNullV
             return result;
         }
         
    +    @Beta
    +    public static class ComputingIsQuorate<T extends Object> implements Function<Collection<T>, T> {
    --- End diff --
    
    Changing this definition to `public static class ComputingIsQuorate implements Function<Collection<Boolean>, Boolean>` is certainly sensible.
    
    However, doing this causes problems in `Aggregator`.  The return value must ultimately be assigned to `Function<? super Collection<T>, ? extends U> transformation` but I cannot seem to escape compile errors when attempting to cast / assign the value.


---
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 quorum check enricher and agg...

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

    https://github.com/apache/incubator-brooklyn/pull/1037#discussion_r45631366
  
    --- Diff: core/src/main/java/org/apache/brooklyn/enricher/stock/Aggregator.java ---
    @@ -64,6 +65,10 @@
         
         public static final ConfigKey<Boolean> EXCLUDE_BLANK = ConfigKeys.newBooleanConfigKey("enricher.aggregator.excludeBlank", "Whether explicit nulls or blank strings should be excluded (default false); this only applies if no value filter set", false);
     
    +    public static final ConfigKey<String> QUORUM_CHECK_TYPE = ConfigKeys.newStringConfigKey("quorum.check.type", "The requirement to be considered quorate", "allAndAtLeastOne");
    --- End diff --
    
    Worth indicating the possible values in the description? Appreciate there's a chance it could get out of sync with the strings in QuorumCheck.


---
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 quorum check enricher and agg...

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

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


---
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 quorum check enricher and agg...

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

    https://github.com/apache/incubator-brooklyn/pull/1037#discussion_r45632294
  
    --- Diff: core/src/main/java/org/apache/brooklyn/enricher/stock/Enrichers.java ---
    @@ -891,6 +892,39 @@ protected static int count(Iterable<? extends Object> vals, boolean includeNullV
             return result;
         }
         
    +    @Beta
    +    public static class ComputingIsQuorate<T extends Object> implements Function<Collection<T>, T> {
    --- End diff --
    
    Had to compare this to existing enrichers to clock the logic. Why `T extends Object` and not just `Boolean`? You've got `(T) Boolean.valueOf()` in `apply` but the Boolean class is `final` so `T` can't be anything but a Boolean.


---
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 quorum check enricher and agg...

Posted by mikezaccardo <gi...@git.apache.org>.
Github user mikezaccardo commented on the pull request:

    https://github.com/apache/incubator-brooklyn/pull/1037#issuecomment-159396647
  
    @sjcorbett I've updated the signature to `public static class ComputingIsQuorate<T> implements Function<Collection<Boolean>, Boolean>` without any errors.
    
    The generic `T` remains for the `TypeToken` constructor parameter -- we check to see if it is compatible with `Boolean` there.


---
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 quorum check enricher and agg...

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

    https://github.com/apache/incubator-brooklyn/pull/1037#discussion_r45631581
  
    --- Diff: core/src/main/java/org/apache/brooklyn/enricher/stock/Enrichers.java ---
    @@ -891,6 +892,39 @@ protected static int count(Iterable<? extends Object> vals, boolean includeNullV
             return result;
         }
         
    +    @Beta
    +    public static class ComputingIsQuorate<T extends Object> implements Function<Collection<T>, T> {
    +        protected final TypeToken<T> typeToken;
    +        protected final QuorumCheck quorumCheck;
    +        protected final int totalSize;
    +
    +        @SuppressWarnings({ "unchecked", "rawtypes" })
    +        public ComputingIsQuorate(TypeToken<T> typeToken, QuorumCheck quorumCheck, int totalSize) {
    +            this.quorumCheck = quorumCheck;
    +            this.totalSize = totalSize;
    +
    +            if (typeToken!=null && TypeToken.of(Boolean.class).isAssignableFrom(typeToken.getType())) {
    +                this.typeToken = typeToken;
    +            } else if (typeToken==null || typeToken.isAssignableFrom(Boolean.class)) {
    +                this.typeToken = (TypeToken)TypeToken.of(Boolean.class);
    +            } else {
    +                throw new IllegalArgumentException("Type "+typeToken+" is not valid for "+this);
    --- End diff --
    
    Should indicate what was expected.


---
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.
---