2 * ===============================LICENSE_START======================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============================LICENSE_END===========================================
21 package org.onap.dcae.apod.analytics.cdap.tca.validator;
23 import org.onap.dcae.apod.analytics.cdap.common.validation.CDAPAppSettingsValidator;
24 import org.onap.dcae.apod.analytics.cdap.tca.settings.TCAAppPreferences;
25 import org.onap.dcae.apod.analytics.common.validation.GenericValidationResponse;
27 import static org.onap.dcae.apod.analytics.cdap.common.utils.ValidationUtils.isEmpty;
31 * @author Rajiv Singla . Creation Date: 11/3/2016.
33 public class TCAPreferencesValidator implements CDAPAppSettingsValidator<TCAAppPreferences,
34 GenericValidationResponse<TCAAppPreferences>> {
36 private static final long serialVersionUID = 1L;
39 public GenericValidationResponse<TCAAppPreferences> validateAppSettings(TCAAppPreferences appPreferences) {
41 final GenericValidationResponse<TCAAppPreferences> validationResponse = new GenericValidationResponse<>();
43 // subscriber validations
44 final String subscriberHostName = appPreferences.getSubscriberHostName();
45 if (isEmpty(subscriberHostName)) {
46 validationResponse.addErrorMessage("subscriberHostName", "Subscriber host name must be present");
48 final String subscriberTopicName = appPreferences.getSubscriberTopicName();
49 if (isEmpty(subscriberTopicName)) {
50 validationResponse.addErrorMessage("subscriberTopicName", "Subscriber topic name must be present");
53 // publisher validations
54 final String publisherHostName = appPreferences.getPublisherHostName();
55 if (isEmpty(publisherHostName)) {
56 validationResponse.addErrorMessage("publisherHostName", "Publisher host name must be present");
58 final String publisherTopicName = appPreferences.getPublisherTopicName();
59 if (isEmpty(publisherTopicName)) {
60 validationResponse.addErrorMessage("publisherTopicName", "Publisher topic name must be present");
63 final Boolean enableAAIEnrichment = appPreferences.getEnableAAIEnrichment();
65 // if aai enrichment is enabled then do some aai validations
66 if (enableAAIEnrichment) {
67 final String aaiEnrichmentHost = appPreferences.getAaiEnrichmentHost();
68 if (isEmpty(aaiEnrichmentHost)) {
69 validationResponse.addErrorMessage("aaiEnrichmentHost", "AAI Enrichment Host must be present");
71 final String aaiVMEnrichmentAPIPath = appPreferences.getAaiVMEnrichmentAPIPath();
72 if (isEmpty(aaiVMEnrichmentAPIPath)) {
73 validationResponse.addErrorMessage("aaiVMEnrichmentAPIPath", "AAI VM Enrichment path must be present");
75 final String aaiVNFEnrichmentAPIPath = appPreferences.getAaiVNFEnrichmentAPIPath();
76 if (isEmpty(aaiVNFEnrichmentAPIPath)) {
77 validationResponse.addErrorMessage("aaiVNFEnrichmentAPIPath", "AAI VNF Enrichment path must be " +
82 final Boolean enableRedisCaching = appPreferences.getEnableRedisCaching();
84 // if redis distributed caching is enabled then redis Hosts must be provided
85 if(enableRedisCaching) {
86 final String redisHosts = appPreferences.getRedisHosts();
87 if(isEmpty(redisHosts)) {
88 validationResponse.addErrorMessage("redisHosts",
89 "Redis Caching is enabled but no redis hosts are provided");
93 return validationResponse;