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 2016/07/12 03:25:39 UTC

[GitHub] brooklyn-server pull request #249: Return when PercentageEnricher cannot com...

GitHub user grkvlt opened a pull request:

    https://github.com/apache/brooklyn-server/pull/249

    Return when PercentageEnricher cannot compute result

    Does not pollute `INFO` log with exception stack traces. Also replaces check for zero with a `DoubleMath.fuzzyCompare()` call using an epsilon of 1x10^-12 to allow for floating point inaccuracies.

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

    $ git pull https://github.com/grkvlt/brooklyn-server percentage-enricher-return-not-npe

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

    https://github.com/apache/brooklyn-server/pull/249.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 #249
    
----
commit cf5f6c58e441932797a47de44fb2d924c450f532
Author: Andrew Donald Kennedy <an...@cloudsoftcorp.com>
Date:   2016-07-11T19:17:26Z

    Return when PercentageEnricher cannot compute result instead of throwing exception

----


---
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] brooklyn-server pull request #249: Return when PercentageEnricher cannot com...

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

    https://github.com/apache/brooklyn-server/pull/249


---
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] brooklyn-server pull request #249: Return when PercentageEnricher cannot com...

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

    https://github.com/apache/brooklyn-server/pull/249#discussion_r70419782
  
    --- Diff: core/src/main/java/org/apache/brooklyn/enricher/stock/PercentageEnricher.java ---
    @@ -98,18 +101,27 @@ public void setEntity(EntityLocal entity) {
     
         @Override
         public void onEvent(SensorEvent<Number> event) {
    -        Number current = Preconditions.checkNotNull(producer.sensors().get(sourceCurrentSensor), "Can't calculate Enricher %s value for entity %s as current from producer %s is null", JavaClassNames.simpleClassName(this), entity, producer);
    -        Number total = Preconditions.checkNotNull(producer.sensors().get(sourceTotalSensor),     "Can't calculate Enricher %s value for entity %s as total from producer %s is null", JavaClassNames.simpleClassName(this), entity, producer);
    +        Number current = producer.sensors().get(sourceCurrentSensor);
    +        if (current == null) {
    +            LOG.trace("Can't calculate percentage value for entity {} as current from producer {} is null", entity, producer);
    +            return;
    +        }
    +        Number total = producer.sensors().get(sourceTotalSensor);
    +        if (total == null) {
    +            LOG.trace("Can't calculate percentage value for entity {} as total from producer {} is null",  entity, producer);
    +            return;
    +        }
    +
             Double currentDouble = current.doubleValue();
             Double totalDouble = total.doubleValue();
     
    -        if (totalDouble.compareTo(0d) == 0) {
    -            LOG.debug("Can't calculate Enricher ({}) value for entity ({}) as total from producer ({}) is zero", new Object[]{JavaClassNames.simpleClassName(this), entity, producer});
    +        if (DoubleMath.fuzzyEquals(totalDouble, 0d, EPSILON)) {
    +            LOG.trace("Can't calculate percentage value for entity {} as total from producer {} is zero", entity, producer);
                 return;
             }
    -
    -        if (currentDouble < 0 || totalDouble < 0) {
    -            LOG.debug("Can't calculate Enricher ({}) value for entity ({}) as Current ({})  or total ({}) value from producer ({}) is negative, returning", new Object[]{JavaClassNames.simpleClassName(this), entity, currentDouble, totalDouble, producer});
    +        if (currentDouble < 0d || totalDouble < 0d) {
    --- End diff --
    
    Not sure why we disallow negative percentages, but that was already the case. So your PR looks good.


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