2 * ===============================LICENSE_START======================================
\r
4 * ================================================================================
\r
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============================LICENSE_END===========================================
\r
21 package org.openecomp.dcae.apod.analytics.tca;
\r
23 import com.fasterxml.jackson.core.type.TypeReference;
\r
24 import com.fasterxml.jackson.databind.ObjectMapper;
\r
25 import com.google.common.base.Suppliers;
\r
26 import org.openecomp.dcae.apod.analytics.model.domain.cef.EventListener;
\r
27 import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.ClosedLoopEventStatus;
\r
28 import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.Direction;
\r
29 import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.TCAPolicy;
\r
30 import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.Threshold;
\r
31 import org.openecomp.dcae.apod.analytics.model.util.AnalyticsModelIOUtils;
\r
32 import org.openecomp.dcae.apod.analytics.model.util.json.AnalyticsModelObjectMapperSupplier;
\r
33 import org.openecomp.dcae.apod.analytics.test.BaseDCAEAnalyticsUnitTest;
\r
35 import java.io.IOException;
\r
36 import java.util.Arrays;
\r
37 import java.util.LinkedHashMap;
\r
38 import java.util.List;
\r
39 import java.util.Map;
\r
40 import java.util.Properties;
\r
43 * @author Rajiv Singla . Creation Date: 10/25/2016.
\r
45 public abstract class BaseAnalyticsTCAUnitTest extends BaseDCAEAnalyticsUnitTest {
\r
48 * Object mapper to be used for all TCA Json Parsing
\r
50 protected static final ObjectMapper ANALYTICS_MODEL_OBJECT_MAPPER =
\r
51 Suppliers.memoize(new AnalyticsModelObjectMapperSupplier()).get();
\r
53 protected static final String TCA_POLICY_JSON_FILE_LOCATION = "data/json/policy/tca_policy.json";
\r
54 protected static final String CEF_MESSAGES_JSON_FILE_LOCATION = "data/json/cef/cef_messages.json";
\r
55 protected static final String CEF_MESSAGE_JSON_FILE_LOCATION = "data/json/cef/cef_message.json";
\r
56 protected static final String CEF_MESSAGE_WITH_THRESHOLD_VIOLATION_JSON_FILE_LOCATION =
\r
57 "data/json/cef/cef_message_with_threshold_violation.json";
\r
59 protected static final String TCA_CONTROLLER_POLICY_FILE_LOCATION =
\r
60 "data/properties/tca_controller_policy.properties";
\r
62 protected static final String TCA_AAI_VNF_ENRICHMENT_FILE_LOCATION = "data/json/aai/aai_vnf_enrichment.json";
\r
64 protected static final String TCA_TEST_APP_CONFIG_NAME = "testTCAAppName";
\r
65 protected static final String TCA_TEST_APP_CONFIG_DESCRIPTION = "testTCAAppDescription";
\r
66 protected static final String TCA_TEST_APP_CONFIG_SUBSCRIBER_OUTPUT_STREAM_NAME =
\r
67 "testTcaSubscriberOutputStreamName";
\r
68 protected static final String TCA_TEST_APP_CONFIG_VES_ALERT_TABLE_NAME = "testTcaVESAlertsTableName";
\r
69 protected static final String TCA_TEST_APP_CONFIG_VES_MESSAGE_STATUS_TABLE_NAME =
\r
70 "testTcaVESMessageStatusTableName";
\r
74 * Provides TCA Policy that can be used for testing
\r
76 * @return test TCA Policy Object
\r
78 protected TCAPolicy getSampleTCAPolicy() {
\r
80 return ANALYTICS_MODEL_OBJECT_MAPPER.readValue(fromStream(TCA_POLICY_JSON_FILE_LOCATION), TCAPolicy.class);
\r
81 } catch (IOException e) {
\r
82 LOG.error("Error while parsing policy: {}", e);
\r
83 throw new RuntimeException("Error while parsing policy", e);
\r
88 * Provides list containing 350 CEF messages
\r
90 * @return CEF Test Message
\r
91 * @throws Exception Exception
\r
93 protected List<EventListener> getCEFMessages() throws Exception {
\r
94 final String cefMessageAsString = fromStream(CEF_MESSAGES_JSON_FILE_LOCATION);
\r
95 final TypeReference<List<EventListener>> eventListenerListTypeReference =
\r
96 new TypeReference<List<EventListener>>() {
\r
98 return ANALYTICS_MODEL_OBJECT_MAPPER.readValue(cefMessageAsString, eventListenerListTypeReference);
\r
102 * Provides 1 valid CEF messages which does not violate Threshold as String
\r
104 * @return CEF Test Message String
\r
105 * @throws Exception Exception
\r
107 protected String getValidCEFMessage() throws Exception {
\r
108 return fromStream(CEF_MESSAGE_JSON_FILE_LOCATION);
\r
113 * Provides single CEF Test Message
\r
115 * @return CEF Test Message
\r
116 * @throws Exception Exception
\r
118 protected EventListener getCEFEventListener() throws Exception {
\r
119 final String cefMessageAsString = fromStream(CEF_MESSAGE_JSON_FILE_LOCATION);
\r
120 return ANALYTICS_MODEL_OBJECT_MAPPER.readValue(cefMessageAsString, EventListener.class);
\r
123 protected static List<Threshold> getThresholds() {
\r
124 Threshold majorThreshold = new Threshold();
\r
125 majorThreshold.setClosedLoopControlName("CL-LBAL-LOW-TRAFFIC-SIG-FB480F95-A453-6F24-B767-FD703241AB1A");
\r
126 majorThreshold.setFieldPath("$.event.measurementsForVfScalingFields.vNicUsageArray[*].packetsIn");
\r
127 majorThreshold.setVersion("Test Version");
\r
128 majorThreshold.setThresholdValue(500L);
\r
129 majorThreshold.setClosedLoopEventStatus(ClosedLoopEventStatus.ONSET);
\r
130 majorThreshold.setDirection(Direction.LESS_OR_EQUAL);
\r
132 Threshold criticalThreshold = new Threshold();
\r
133 criticalThreshold.setClosedLoopControlName("CL-LBAL-LOW-TRAFFIC-SIG-FB480F95-A453-6F24-B767-FD703241AB1A");
\r
134 criticalThreshold.setThresholdValue(5000L);
\r
135 criticalThreshold.setFieldPath("$.event.measurementsForVfScalingFields.vNicUsageArray[*].packetsIn");
\r
136 criticalThreshold.setClosedLoopEventStatus(ClosedLoopEventStatus.ONSET);
\r
137 criticalThreshold.setDirection(Direction.GREATER_OR_EQUAL);
\r
138 return Arrays.asList(majorThreshold, criticalThreshold);
\r
141 protected static Threshold getCriticalThreshold() {
\r
142 Threshold criticalThreshold = new Threshold();
\r
143 criticalThreshold.setClosedLoopControlName("CL-LBAL-LOW-TRAFFIC-SIG-FB480F95-A453-6F24-B767-FD703241AB1A");
\r
144 criticalThreshold.setThresholdValue(5000L);
\r
145 criticalThreshold.setFieldPath("$.event.measurementsForVfScalingFields.vNicUsageArray[*].packetsIn");
\r
146 criticalThreshold.setDirection(Direction.GREATER_OR_EQUAL);
\r
147 return criticalThreshold;
\r
150 protected static Map<String, String> getControllerRuntimeArguments() {
\r
151 final Properties controllerProperties =
\r
152 AnalyticsModelIOUtils.loadPropertiesFile(TCA_CONTROLLER_POLICY_FILE_LOCATION, new Properties());
\r
154 final Map<String, String> runtimeArgs = new LinkedHashMap<>();
\r
155 for (Map.Entry<Object, Object> property : controllerProperties.entrySet()) {
\r
156 runtimeArgs.put(property.getKey().toString(), property.getValue().toString());
\r
159 return runtimeArgs;
\r