\r
package org.openecomp.dcae.apod.analytics.model.domain.policy.tca;\r
\r
+import java.math.BigDecimal;\r
+\r
import javax.annotation.Nonnull;\r
\r
/**\r
\r
EQUAL {\r
@Override\r
- public Boolean operate(@Nonnull Long value1, @Nonnull Long value2) {\r
- return value1.equals(value2);\r
+ public Boolean operate(@Nonnull BigDecimal value1, @Nonnull BigDecimal value2) {\r
+ return value1.compareTo(value2) == 0;\r
}\r
},\r
LESS {\r
@Override\r
- public Boolean operate(@Nonnull Long value1, @Nonnull Long value2) {\r
- return value1 < value2;\r
+ public Boolean operate(@Nonnull BigDecimal value1, @Nonnull BigDecimal value2) {\r
+ return value1.compareTo(value2) < 0;\r
}\r
},\r
LESS_OR_EQUAL {\r
@Override\r
- public Boolean operate(@Nonnull Long value1, @Nonnull Long value2) {\r
- return value1 <= value2;\r
+ public Boolean operate(@Nonnull BigDecimal value1, @Nonnull BigDecimal value2) {\r
+ return value1.compareTo(value2) <= 0;\r
}\r
},\r
GREATER {\r
@Override\r
- public Boolean operate(@Nonnull Long value1, @Nonnull Long value2) {\r
- return value1 > value2;\r
+ public Boolean operate(@Nonnull BigDecimal value1, @Nonnull BigDecimal value2) {\r
+ return value1.compareTo(value2) > 0;\r
}\r
},\r
GREATER_OR_EQUAL {\r
@Override\r
- public Boolean operate(@Nonnull Long value1, @Nonnull Long value2) {\r
- return value1 >= value2;\r
+ public Boolean operate(@Nonnull BigDecimal value1, @Nonnull BigDecimal value2) {\r
+ return value1.compareTo(value2) >= 0;\r
}\r
};\r
\r
*\r
* @return result of operation for the direction logic\r
*/\r
- public abstract Boolean operate(@Nonnull Long value1, @Nonnull Long value2);\r
+ public abstract Boolean operate(@Nonnull BigDecimal value1, @Nonnull BigDecimal value2);\r
\r
}\r
import lombok.EqualsAndHashCode;\r
import org.openecomp.dcae.apod.analytics.model.domain.cef.EventSeverity;\r
\r
+import java.math.BigDecimal;\r
+\r
/**\r
*\r
* @author Rajiv Singla . Creation Date: 11/5/2016.\r
* @param actualFieldValue new value for actual Field value that caused the violation\r
* @return actual field value that caused the violation\r
*/\r
- private Long actualFieldValue;\r
+ private BigDecimal actualFieldValue;\r
\r
/**\r
* Creates a deep copy of give {@link Threshold}\r
import com.fasterxml.jackson.annotation.JsonIgnore;\r
import com.fasterxml.jackson.annotation.JsonProperty;\r
\r
+import java.math.BigDecimal;\r
+\r
/**\r
*\r
* @author Rajiv Singla . Creation Date: 11/5/2016.\r
public abstract class ThresholdMixin extends BaseTCAPolicyModelMixin {\r
\r
@JsonIgnore\r
- private Long actualFieldValue;\r
+ private BigDecimal actualFieldValue;\r
\r
@JsonIgnore\r
- public Long getActualFieldValue() {\r
+ public BigDecimal getActualFieldValue() {\r
return actualFieldValue;\r
}\r
\r
@JsonProperty\r
- public void setActualFieldValue(Long actualFieldValue) {\r
+ public void setActualFieldValue(BigDecimal actualFieldValue) {\r
this.actualFieldValue = actualFieldValue;\r
}\r
}\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
\r
+import java.math.BigDecimal;\r
import java.util.HashMap;\r
import java.util.List;\r
import java.util.Map;\r
final Set<String> policyFieldPaths = policyFieldPathsMap.keySet();\r
\r
// Get Json Values for Policy Fields\r
- final Map<String, List<Long>> messageFieldValuesMap = TCAUtils.getJsonPathValue(cefMessage, policyFieldPaths);\r
+ final Map<String, List<BigDecimal>> messageFieldValuesMap =\r
+ TCAUtils.getJsonPathValue(cefMessage, policyFieldPaths);\r
\r
// Determine all violated thresholds per message field Path\r
final Map<String, Threshold> violatedThresholdsMap = new HashMap<>();\r
- for (Map.Entry<String, List<Long>> messageFieldValuesMapEntry : messageFieldValuesMap.entrySet()) {\r
+ for (Map.Entry<String, List<BigDecimal>> messageFieldValuesMapEntry : messageFieldValuesMap.entrySet()) {\r
final String messageFieldPath = messageFieldValuesMapEntry.getKey();\r
final List<Threshold> messageFieldAssociatedPolicyThresholds = policyFieldPathsMap.get(messageFieldPath);\r
if (messageFieldAssociatedPolicyThresholds != null) {\r
import org.apache.commons.lang3.tuple.Pair;\r
import org.openecomp.dcae.apod.analytics.aai.service.AAIEnrichmentClient;\r
import org.openecomp.dcae.apod.analytics.common.AnalyticsConstants;\r
+import org.openecomp.dcae.apod.analytics.common.exception.DCAEAnalyticsRuntimeException;\r
import org.openecomp.dcae.apod.analytics.common.exception.MessageProcessingException;\r
import org.openecomp.dcae.apod.analytics.common.service.processor.AbstractMessageProcessor;\r
import org.openecomp.dcae.apod.analytics.common.service.processor.GenericMessageChainProcessor;\r
import org.slf4j.LoggerFactory;\r
\r
import java.io.IOException;\r
+import java.math.BigDecimal;\r
import java.util.ArrayList;\r
import java.util.Collections;\r
import java.util.Comparator;\r
* @param jsonFieldPaths Json Field Paths\r
* @return Map containing key as json path and values as values associated with that json path\r
*/\r
- public static Map<String, List<Long>> getJsonPathValue(@Nonnull String message, @Nonnull Set<String>\r
+ public static Map<String, List<BigDecimal>> getJsonPathValue(@Nonnull String message, @Nonnull Set<String>\r
jsonFieldPaths) {\r
\r
- final Map<String, List<Long>> jsonFieldPathMap = new HashMap<>();\r
+ final Map<String, List<BigDecimal>> jsonFieldPathMap = new HashMap<>();\r
final DocumentContext documentContext = JsonPath.parse(message);\r
\r
for (String jsonFieldPath : jsonFieldPaths) {\r
- final List<Long> jsonFieldValues = documentContext.read(jsonFieldPath, new TypeRef<List<Long>>() {\r
- });\r
+ List<BigDecimal> jsonFieldValues = null;\r
+\r
+ try {\r
+ jsonFieldValues = documentContext.read(jsonFieldPath, new TypeRef<List<BigDecimal>>() {\r
+ });\r
+ } catch (Exception e) {\r
+ final String errorMessage = String.format(\r
+ "Unable to convert jsonFieldPath: %s value to valid number. " +\r
+ "Json Path value is not in a valid number format. Incoming message: %s",\r
+ jsonFieldPath, message);\r
+ throw new DCAEAnalyticsRuntimeException(errorMessage, LOG, e);\r
+ }\r
// If Json Field Values are not or empty\r
if (jsonFieldValues != null && !jsonFieldValues.isEmpty()) {\r
// Filter out all null values in the filed values list\r
- final List<Long> nonNullValues = Lists.newLinkedList(Iterables.filter(jsonFieldValues,\r
- Predicates.<Long>notNull()));\r
+ final List<BigDecimal> nonNullValues = Lists.newLinkedList(Iterables.filter(jsonFieldValues,\r
+ Predicates.<BigDecimal>notNull()));\r
// If there are non null values put them in the map\r
if (!nonNullValues.isEmpty()) {\r
jsonFieldPathMap.put(jsonFieldPath, nonNullValues);\r
* @param fieldThresholds Policy Thresholds for Field Path\r
* @return Optional of violated threshold for a field path\r
*/\r
- public static Optional<Threshold> thresholdCalculator(final List<Long> messageFieldValues, final List<Threshold>\r
+ public static Optional<Threshold> thresholdCalculator(final List<BigDecimal> messageFieldValues, final\r
+ List<Threshold>\r
fieldThresholds) {\r
// order thresholds by severity\r
Collections.sort(fieldThresholds, THRESHOLD_COMPARATOR);\r
// Now apply each threshold to field values\r
for (Threshold fieldThreshold : fieldThresholds) {\r
- for (Long messageFieldValue : messageFieldValues) {\r
+ for (BigDecimal messageFieldValue : messageFieldValues) {\r
final Boolean isThresholdViolated =\r
- fieldThreshold.getDirection().operate(messageFieldValue, fieldThreshold.getThresholdValue());\r
+ fieldThreshold.getDirection().operate(messageFieldValue, new BigDecimal(fieldThreshold\r
+ .getThresholdValue()));\r
if (isThresholdViolated) {\r
final Threshold violatedThreshold = Threshold.copy(fieldThreshold);\r
violatedThreshold.setActualFieldValue(messageFieldValue);\r
import org.quartz.SimpleTrigger;\r
import org.quartz.impl.StdSchedulerFactory;\r
\r
+import java.math.BigDecimal;\r
import java.util.Arrays;\r
import java.util.HashMap;\r
import java.util.List;\r
final String jsonPath =\r
"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated";\r
final ImmutableSet<String> fieldPaths = ImmutableSet.of(jsonPath);\r
- final Map<String, List<Long>> jsonPathValueMap = TCAUtils.getJsonPathValue(cefMessageString, fieldPaths);\r
- assertThat("Json Path value must match", jsonPathValueMap.get(jsonPath).get(0), is(5000L));\r
+ final Map<String, List<BigDecimal>> jsonPathValueMap = TCAUtils.getJsonPathValue(cefMessageString, fieldPaths);\r
+ assertThat("Json Path value must match",\r
+ jsonPathValueMap.get(jsonPath).get(0), is(new BigDecimal(5000)));\r
\r
}\r
\r
final String cefMessageString = fromStream(CEF_MESSAGE_JSON_FILE_LOCATION);\r
final String jsonPath = "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].invalid";\r
final ImmutableSet<String> fieldPaths = ImmutableSet.of(jsonPath);\r
- final Map<String, List<Long>> jsonPathValueMap = TCAUtils.getJsonPathValue(cefMessageString, fieldPaths);\r
+ final Map<String, List<BigDecimal>> jsonPathValueMap = TCAUtils.getJsonPathValue(cefMessageString, fieldPaths);\r
assertThat("Json path value must be empty", jsonPathValueMap.size(), is(0));\r
\r
}\r
violatedThreshold.setSeverity(severity);\r
violatedThreshold.setDirection(Direction.GREATER);\r
violatedThreshold.setClosedLoopControlName("violatedThresholdClosedLoopName");\r
- violatedThreshold.setActualFieldValue(100L);\r
+ violatedThreshold.setActualFieldValue(new BigDecimal(100L));\r
violatedThreshold.setFieldPath("violatedThresholdFieldPath");\r
violatedThreshold.setVersion("violatedThresholdVersion");\r
violatedThreshold.setClosedLoopEventStatus(ClosedLoopEventStatus.ONSET);\r