aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSingla, Rajiv (rs153v) <rs153v@att.com>2017-10-12 13:44:30 -0400
committerSingla, Rajiv (rs153v) <rs153v@att.com>2017-10-12 14:07:49 -0400
commit892e09327045d28d7bb633f9ed37817d75dc9300 (patch)
treebbaa667f01062932782184ed307ea7bd7d88ef6f
parent619add75ea412de8ef331d9ae898412818b203c6 (diff)
TCA:Support for string & decimal policy FieldPath
Change-Id: I37a236be2cb4afccffbcf72e3914fb75dadbbb88 Signed-off-by: Singla, Rajiv (rs153v) <rs153v@att.com> Issue-Id: DCAEGEN2-158
-rw-r--r--dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/policy/tca/Direction.java24
-rw-r--r--dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/policy/tca/Threshold.java4
-rw-r--r--dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/json/mixin/policy/tca/ThresholdMixin.java8
-rw-r--r--dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/processor/TCACEFPolicyThresholdsProcessor.java6
-rw-r--r--dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/utils/TCAUtils.java32
-rw-r--r--dcae-analytics-tca/src/test/java/org/openecomp/dcae/apod/analytics/tca/utils/TCAUtilsTest.java10
6 files changed, 54 insertions, 30 deletions
diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/policy/tca/Direction.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/policy/tca/Direction.java
index 76c8086..0d7203b 100644
--- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/policy/tca/Direction.java
+++ b/dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/policy/tca/Direction.java
@@ -20,6 +20,8 @@
package org.openecomp.dcae.apod.analytics.model.domain.policy.tca;
+import java.math.BigDecimal;
+
import javax.annotation.Nonnull;
/**
@@ -32,32 +34,32 @@ public enum Direction implements TCAPolicyModel {
EQUAL {
@Override
- public Boolean operate(@Nonnull Long value1, @Nonnull Long value2) {
- return value1.equals(value2);
+ public Boolean operate(@Nonnull BigDecimal value1, @Nonnull BigDecimal value2) {
+ return value1.compareTo(value2) == 0;
}
},
LESS {
@Override
- public Boolean operate(@Nonnull Long value1, @Nonnull Long value2) {
- return value1 < value2;
+ public Boolean operate(@Nonnull BigDecimal value1, @Nonnull BigDecimal value2) {
+ return value1.compareTo(value2) < 0;
}
},
LESS_OR_EQUAL {
@Override
- public Boolean operate(@Nonnull Long value1, @Nonnull Long value2) {
- return value1 <= value2;
+ public Boolean operate(@Nonnull BigDecimal value1, @Nonnull BigDecimal value2) {
+ return value1.compareTo(value2) <= 0;
}
},
GREATER {
@Override
- public Boolean operate(@Nonnull Long value1, @Nonnull Long value2) {
- return value1 > value2;
+ public Boolean operate(@Nonnull BigDecimal value1, @Nonnull BigDecimal value2) {
+ return value1.compareTo(value2) > 0;
}
},
GREATER_OR_EQUAL {
@Override
- public Boolean operate(@Nonnull Long value1, @Nonnull Long value2) {
- return value1 >= value2;
+ public Boolean operate(@Nonnull BigDecimal value1, @Nonnull BigDecimal value2) {
+ return value1.compareTo(value2) >= 0;
}
};
@@ -69,6 +71,6 @@ public enum Direction implements TCAPolicyModel {
*
* @return result of operation for the direction logic
*/
- public abstract Boolean operate(@Nonnull Long value1, @Nonnull Long value2);
+ public abstract Boolean operate(@Nonnull BigDecimal value1, @Nonnull BigDecimal value2);
}
diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/policy/tca/Threshold.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/policy/tca/Threshold.java
index 0d6193d..4f98fa5 100644
--- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/policy/tca/Threshold.java
+++ b/dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/policy/tca/Threshold.java
@@ -24,6 +24,8 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import org.openecomp.dcae.apod.analytics.model.domain.cef.EventSeverity;
+import java.math.BigDecimal;
+
/**
*
* @author Rajiv Singla . Creation Date: 11/5/2016.
@@ -100,7 +102,7 @@ public class Threshold extends BaseTCAPolicyModel {
* @param actualFieldValue new value for actual Field value that caused the violation
* @return actual field value that caused the violation
*/
- private Long actualFieldValue;
+ private BigDecimal actualFieldValue;
/**
* Creates a deep copy of give {@link Threshold}
diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/json/mixin/policy/tca/ThresholdMixin.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/json/mixin/policy/tca/ThresholdMixin.java
index 02d4b83..27344f8 100644
--- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/json/mixin/policy/tca/ThresholdMixin.java
+++ b/dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/json/mixin/policy/tca/ThresholdMixin.java
@@ -23,6 +23,8 @@ package org.openecomp.dcae.apod.analytics.model.util.json.mixin.policy.tca;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
+import java.math.BigDecimal;
+
/**
*
* @author Rajiv Singla . Creation Date: 11/5/2016.
@@ -30,15 +32,15 @@ import com.fasterxml.jackson.annotation.JsonProperty;
public abstract class ThresholdMixin extends BaseTCAPolicyModelMixin {
@JsonIgnore
- private Long actualFieldValue;
+ private BigDecimal actualFieldValue;
@JsonIgnore
- public Long getActualFieldValue() {
+ public BigDecimal getActualFieldValue() {
return actualFieldValue;
}
@JsonProperty
- public void setActualFieldValue(Long actualFieldValue) {
+ public void setActualFieldValue(BigDecimal actualFieldValue) {
this.actualFieldValue = actualFieldValue;
}
}
diff --git a/dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/processor/TCACEFPolicyThresholdsProcessor.java b/dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/processor/TCACEFPolicyThresholdsProcessor.java
index 704151d..0a62aa4 100644
--- a/dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/processor/TCACEFPolicyThresholdsProcessor.java
+++ b/dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/processor/TCACEFPolicyThresholdsProcessor.java
@@ -32,6 +32,7 @@ import org.openecomp.dcae.apod.analytics.tca.utils.TCAUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -93,11 +94,12 @@ public class TCACEFPolicyThresholdsProcessor extends AbstractTCAECEFPolicyProces
final Set<String> policyFieldPaths = policyFieldPathsMap.keySet();
// Get Json Values for Policy Fields
- final Map<String, List<Long>> messageFieldValuesMap = TCAUtils.getJsonPathValue(cefMessage, policyFieldPaths);
+ final Map<String, List<BigDecimal>> messageFieldValuesMap =
+ TCAUtils.getJsonPathValue(cefMessage, policyFieldPaths);
// Determine all violated thresholds per message field Path
final Map<String, Threshold> violatedThresholdsMap = new HashMap<>();
- for (Map.Entry<String, List<Long>> messageFieldValuesMapEntry : messageFieldValuesMap.entrySet()) {
+ for (Map.Entry<String, List<BigDecimal>> messageFieldValuesMapEntry : messageFieldValuesMap.entrySet()) {
final String messageFieldPath = messageFieldValuesMapEntry.getKey();
final List<Threshold> messageFieldAssociatedPolicyThresholds = policyFieldPathsMap.get(messageFieldPath);
if (messageFieldAssociatedPolicyThresholds != null) {
diff --git a/dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/utils/TCAUtils.java b/dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/utils/TCAUtils.java
index dd37aa2..4011e52 100644
--- a/dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/utils/TCAUtils.java
+++ b/dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/utils/TCAUtils.java
@@ -43,6 +43,7 @@ import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.openecomp.dcae.apod.analytics.aai.service.AAIEnrichmentClient;
import org.openecomp.dcae.apod.analytics.common.AnalyticsConstants;
+import org.openecomp.dcae.apod.analytics.common.exception.DCAEAnalyticsRuntimeException;
import org.openecomp.dcae.apod.analytics.common.exception.MessageProcessingException;
import org.openecomp.dcae.apod.analytics.common.service.processor.AbstractMessageProcessor;
import org.openecomp.dcae.apod.analytics.common.service.processor.GenericMessageChainProcessor;
@@ -83,6 +84,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
+import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@@ -266,20 +268,30 @@ public abstract class TCAUtils extends AnalyticsModelJsonUtils {
* @param jsonFieldPaths Json Field Paths
* @return Map containing key as json path and values as values associated with that json path
*/
- public static Map<String, List<Long>> getJsonPathValue(@Nonnull String message, @Nonnull Set<String>
+ public static Map<String, List<BigDecimal>> getJsonPathValue(@Nonnull String message, @Nonnull Set<String>
jsonFieldPaths) {
- final Map<String, List<Long>> jsonFieldPathMap = new HashMap<>();
+ final Map<String, List<BigDecimal>> jsonFieldPathMap = new HashMap<>();
final DocumentContext documentContext = JsonPath.parse(message);
for (String jsonFieldPath : jsonFieldPaths) {
- final List<Long> jsonFieldValues = documentContext.read(jsonFieldPath, new TypeRef<List<Long>>() {
- });
+ List<BigDecimal> jsonFieldValues = null;
+
+ try {
+ jsonFieldValues = documentContext.read(jsonFieldPath, new TypeRef<List<BigDecimal>>() {
+ });
+ } catch (Exception e) {
+ final String errorMessage = String.format(
+ "Unable to convert jsonFieldPath: %s value to valid number. " +
+ "Json Path value is not in a valid number format. Incoming message: %s",
+ jsonFieldPath, message);
+ throw new DCAEAnalyticsRuntimeException(errorMessage, LOG, e);
+ }
// If Json Field Values are not or empty
if (jsonFieldValues != null && !jsonFieldValues.isEmpty()) {
// Filter out all null values in the filed values list
- final List<Long> nonNullValues = Lists.newLinkedList(Iterables.filter(jsonFieldValues,
- Predicates.<Long>notNull()));
+ final List<BigDecimal> nonNullValues = Lists.newLinkedList(Iterables.filter(jsonFieldValues,
+ Predicates.<BigDecimal>notNull()));
// If there are non null values put them in the map
if (!nonNullValues.isEmpty()) {
jsonFieldPathMap.put(jsonFieldPath, nonNullValues);
@@ -298,15 +310,17 @@ public abstract class TCAUtils extends AnalyticsModelJsonUtils {
* @param fieldThresholds Policy Thresholds for Field Path
* @return Optional of violated threshold for a field path
*/
- public static Optional<Threshold> thresholdCalculator(final List<Long> messageFieldValues, final List<Threshold>
+ public static Optional<Threshold> thresholdCalculator(final List<BigDecimal> messageFieldValues, final
+ List<Threshold>
fieldThresholds) {
// order thresholds by severity
Collections.sort(fieldThresholds, THRESHOLD_COMPARATOR);
// Now apply each threshold to field values
for (Threshold fieldThreshold : fieldThresholds) {
- for (Long messageFieldValue : messageFieldValues) {
+ for (BigDecimal messageFieldValue : messageFieldValues) {
final Boolean isThresholdViolated =
- fieldThreshold.getDirection().operate(messageFieldValue, fieldThreshold.getThresholdValue());
+ fieldThreshold.getDirection().operate(messageFieldValue, new BigDecimal(fieldThreshold
+ .getThresholdValue()));
if (isThresholdViolated) {
final Threshold violatedThreshold = Threshold.copy(fieldThreshold);
violatedThreshold.setActualFieldValue(messageFieldValue);
diff --git a/dcae-analytics-tca/src/test/java/org/openecomp/dcae/apod/analytics/tca/utils/TCAUtilsTest.java b/dcae-analytics-tca/src/test/java/org/openecomp/dcae/apod/analytics/tca/utils/TCAUtilsTest.java
index 853ac54..426bd1e 100644
--- a/dcae-analytics-tca/src/test/java/org/openecomp/dcae/apod/analytics/tca/utils/TCAUtilsTest.java
+++ b/dcae-analytics-tca/src/test/java/org/openecomp/dcae/apod/analytics/tca/utils/TCAUtilsTest.java
@@ -53,6 +53,7 @@ import org.quartz.Scheduler;
import org.quartz.SimpleTrigger;
import org.quartz.impl.StdSchedulerFactory;
+import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@@ -147,8 +148,9 @@ public class TCAUtilsTest extends BaseAnalyticsTCAUnitTest {
final String jsonPath =
"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated";
final ImmutableSet<String> fieldPaths = ImmutableSet.of(jsonPath);
- final Map<String, List<Long>> jsonPathValueMap = TCAUtils.getJsonPathValue(cefMessageString, fieldPaths);
- assertThat("Json Path value must match", jsonPathValueMap.get(jsonPath).get(0), is(5000L));
+ final Map<String, List<BigDecimal>> jsonPathValueMap = TCAUtils.getJsonPathValue(cefMessageString, fieldPaths);
+ assertThat("Json Path value must match",
+ jsonPathValueMap.get(jsonPath).get(0), is(new BigDecimal(5000)));
}
@@ -157,7 +159,7 @@ public class TCAUtilsTest extends BaseAnalyticsTCAUnitTest {
final String cefMessageString = fromStream(CEF_MESSAGE_JSON_FILE_LOCATION);
final String jsonPath = "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].invalid";
final ImmutableSet<String> fieldPaths = ImmutableSet.of(jsonPath);
- final Map<String, List<Long>> jsonPathValueMap = TCAUtils.getJsonPathValue(cefMessageString, fieldPaths);
+ final Map<String, List<BigDecimal>> jsonPathValueMap = TCAUtils.getJsonPathValue(cefMessageString, fieldPaths);
assertThat("Json path value must be empty", jsonPathValueMap.size(), is(0));
}
@@ -400,7 +402,7 @@ public class TCAUtilsTest extends BaseAnalyticsTCAUnitTest {
violatedThreshold.setSeverity(severity);
violatedThreshold.setDirection(Direction.GREATER);
violatedThreshold.setClosedLoopControlName("violatedThresholdClosedLoopName");
- violatedThreshold.setActualFieldValue(100L);
+ violatedThreshold.setActualFieldValue(new BigDecimal(100L));
violatedThreshold.setFieldPath("violatedThresholdFieldPath");
violatedThreshold.setVersion("violatedThresholdVersion");
violatedThreshold.setClosedLoopEventStatus(ClosedLoopEventStatus.ONSET);