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.cdap.tca.validator;
\r
23 import org.openecomp.dcae.apod.analytics.cdap.common.validation.CDAPAppSettingsValidator;
\r
24 import org.openecomp.dcae.apod.analytics.cdap.tca.settings.TCAPolicyPreferences;
\r
25 import org.openecomp.dcae.apod.analytics.common.validation.GenericValidationResponse;
\r
26 import org.openecomp.dcae.apod.analytics.model.domain.cef.EventSeverity;
\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.ControlLoopSchemaType;
\r
29 import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.Direction;
\r
30 import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.MetricsPerEventName;
\r
31 import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.Threshold;
\r
32 import org.openecomp.dcae.apod.analytics.tca.utils.TCAUtils;
\r
34 import java.util.List;
\r
36 import static org.openecomp.dcae.apod.analytics.cdap.common.utils.ValidationUtils.isEmpty;
\r
39 * Validates TCA Policy Preferences
\r
42 * @author Rajiv Singla . Creation Date: 11/29/2016.
\r
44 public class TCAPolicyPreferencesValidator implements CDAPAppSettingsValidator<TCAPolicyPreferences,
\r
45 GenericValidationResponse<TCAPolicyPreferences>> {
\r
47 private static final long serialVersionUID = 1L;
\r
50 public GenericValidationResponse<TCAPolicyPreferences> validateAppSettings(
\r
51 final TCAPolicyPreferences tcaPolicyPreferences) {
\r
53 final GenericValidationResponse<TCAPolicyPreferences> validationResponse = new GenericValidationResponse<>();
\r
55 // validate TCA Policy must domain present
\r
56 final String domain = tcaPolicyPreferences.getDomain();
\r
57 if (isEmpty(domain)) {
\r
58 validationResponse.addErrorMessage("domain", "TCA Policy must have only one domain present");
\r
61 // validate TCA Policy must have at least one event name
\r
62 final List<String> policyEventNames = TCAUtils.getPolicyEventNames(tcaPolicyPreferences);
\r
63 if (policyEventNames.isEmpty()) {
\r
64 validationResponse.addErrorMessage("metricsPerEventNames",
\r
65 "TCA Policy must have at least one or more event names");
\r
68 final List<MetricsPerEventName> metricsPerEventNames =
\r
69 tcaPolicyPreferences.getMetricsPerEventName();
\r
71 // validate Metrics Per Event Name
\r
72 for (MetricsPerEventName metricsPerEventName : metricsPerEventNames) {
\r
74 // event name must be present
\r
75 final String eventName = metricsPerEventName.getEventName();
\r
76 if (isEmpty(eventName)) {
\r
77 validationResponse.addErrorMessage("eventName",
\r
78 "TCA Policy eventName is not present for metricsPerEventName:" + metricsPerEventName);
\r
81 // control Loop Schema type must be present
\r
82 final ControlLoopSchemaType controlLoopSchemaType = metricsPerEventName.getControlLoopSchemaType();
\r
83 if (controlLoopSchemaType == null) {
\r
84 validationResponse.addErrorMessage("controlLoopEventType",
\r
85 "TCA Policy controlLoopSchemaType is not present for metricsPerEventName:"
\r
86 + metricsPerEventName);
\r
89 // must have at least 1 threshold defined
\r
90 if (metricsPerEventName.getThresholds() == null || metricsPerEventName.getThresholds().isEmpty()) {
\r
91 validationResponse.addErrorMessage("thresholds",
\r
92 "TCA Policy event Name must have at least one threshold. " +
\r
93 "Event Name causing this validation error:" + metricsPerEventName);
\r
95 // validate each threshold must have non null - fieldPath, thresholdValue, direction and severity
\r
96 final List<Threshold> eventNameThresholds = metricsPerEventName.getThresholds();
\r
97 for (Threshold eventNameThreshold : eventNameThresholds) {
\r
98 final String fieldPath = eventNameThreshold.getFieldPath();
\r
99 final Long thresholdValue = eventNameThreshold.getThresholdValue();
\r
100 final Direction direction = eventNameThreshold.getDirection();
\r
101 final EventSeverity severity = eventNameThreshold.getSeverity();
\r
102 final ClosedLoopEventStatus closedLoopEventStatus = eventNameThreshold.getClosedLoopEventStatus();
\r
103 if (isEmpty(fieldPath) || thresholdValue == null || direction == null || severity == null ||
\r
104 closedLoopEventStatus == null) {
\r
105 validationResponse.addErrorMessage("threshold",
\r
106 "TCA Policy threshold must have fieldPath,thresholdValue,direction, " +
\r
107 "closedLoopEventStatus and severity defined." +
\r
108 "Threshold causing this validation error:" + eventNameThreshold);
\r
113 return validationResponse;
\r