Added Redis Support
[dcaegen2/analytics/tca.git] / dcae-analytics-cdap-tca / src / main / java / org / onap / dcae / apod / analytics / cdap / tca / validator / TCAPreferencesValidator.java
1 /*
2  * ===============================LICENSE_START======================================
3  *  dcae-analytics
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
10  *
11  *          http://www.apache.org/licenses/LICENSE-2.0
12  *
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===========================================
19  */
20
21 package org.onap.dcae.apod.analytics.cdap.tca.validator;
22
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;
26
27 import static org.onap.dcae.apod.analytics.cdap.common.utils.ValidationUtils.isEmpty;
28
29 /**
30  *
31  * @author Rajiv Singla . Creation Date: 11/3/2016.
32  */
33 public class TCAPreferencesValidator implements CDAPAppSettingsValidator<TCAAppPreferences,
34         GenericValidationResponse<TCAAppPreferences>> {
35
36     private static final long serialVersionUID = 1L;
37
38     @Override
39     public GenericValidationResponse<TCAAppPreferences> validateAppSettings(TCAAppPreferences appPreferences) {
40
41         final GenericValidationResponse<TCAAppPreferences> validationResponse = new GenericValidationResponse<>();
42
43         // subscriber validations
44         final String subscriberHostName = appPreferences.getSubscriberHostName();
45         if (isEmpty(subscriberHostName)) {
46             validationResponse.addErrorMessage("subscriberHostName", "Subscriber host name must be present");
47         }
48         final String subscriberTopicName = appPreferences.getSubscriberTopicName();
49         if (isEmpty(subscriberTopicName)) {
50             validationResponse.addErrorMessage("subscriberTopicName", "Subscriber topic name must be present");
51         }
52
53         // publisher validations
54         final String publisherHostName = appPreferences.getPublisherHostName();
55         if (isEmpty(publisherHostName)) {
56             validationResponse.addErrorMessage("publisherHostName", "Publisher host name must be present");
57         }
58         final String publisherTopicName = appPreferences.getPublisherTopicName();
59         if (isEmpty(publisherTopicName)) {
60             validationResponse.addErrorMessage("publisherTopicName", "Publisher topic name must be present");
61         }
62
63         final Boolean enableAAIEnrichment = appPreferences.getEnableAAIEnrichment();
64
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");
70             }
71             final String aaiVMEnrichmentAPIPath = appPreferences.getAaiVMEnrichmentAPIPath();
72             if (isEmpty(aaiVMEnrichmentAPIPath)) {
73                 validationResponse.addErrorMessage("aaiVMEnrichmentAPIPath", "AAI VM Enrichment path must be present");
74             }
75             final String aaiVNFEnrichmentAPIPath = appPreferences.getAaiVNFEnrichmentAPIPath();
76             if (isEmpty(aaiVNFEnrichmentAPIPath)) {
77                 validationResponse.addErrorMessage("aaiVNFEnrichmentAPIPath", "AAI VNF Enrichment path must be " +
78                         "present");
79             }
80         }
81
82         final Boolean enableRedisCaching = appPreferences.getEnableRedisCaching();
83
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");
90             }
91         }
92
93         return validationResponse;
94     }
95 }