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 [email protected] or file a JIRA ticket
with INFRA.
---