diff options
Diffstat (limited to 'dcae-analytics-tca/src')
3 files changed, 33 insertions, 15 deletions
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);
|