Applying license changes to all files
[appc.git] / appc-asdc-listener / appc-asdc-listener-bundle / src / main / java / org / openecomp / appc / sdc / listener / AsdcConfig.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.openecomp.appc.sdc.listener;
26
27 import com.att.eelf.configuration.EELFLogger;
28 import com.att.eelf.configuration.EELFManager;
29 import org.openecomp.sdc.api.consumer.IConfiguration;
30
31 import java.net.URI;
32 import java.util.*;
33
34 public class AsdcConfig implements IConfiguration {
35
36         private String host;
37         private String consumer;
38         private String consumerId;
39         private String env;
40         private String keystorePath;
41         private String keystorePass;
42         private int pollingInterval; // Time between listening sessions
43         private int pollingTimeout; // Time to listen for (dmaap timeout url param)/1000
44         private List<String> types = new ArrayList<>(1);
45         private String user;
46         private String pass;
47
48         private URI storeOp;
49
50         Properties props;
51
52         private final EELFLogger logger = EELFManager.getInstance().getLogger(AsdcConfig.class);
53
54         public AsdcConfig(Properties props) throws Exception {
55                 this.props = props;
56                 init();
57         }
58
59         private void init() throws Exception {
60                 if (props != null) {
61                         // Keystore for ca cert
62                         keystorePath = props.getProperty("appc.asdc.keystore.path");
63                         keystorePass = props.getProperty("appc.asdc.keystore.pass");
64
65                         // ASDC host
66                         host = props.getProperty("appc.asdc.host");
67                         env = props.getProperty("appc.asdc.env");
68                         user = props.getProperty("appc.asdc.user");
69                         pass = props.getProperty("appc.asdc.pass");
70
71                         // DMaaP properties
72                         consumer = props.getProperty("appc.asdc.consumer");
73                         consumerId = props.getProperty("appc.asdc.consumer.id");
74
75                         pollingInterval = Integer.valueOf(props.getProperty("interval", "60"));
76
77                         // Client uses cambriaClient-0.2.4 which throws non relevant (wrong)
78                         // exceptions with times > 30s
79                         pollingTimeout = Integer.valueOf(props.getProperty("timeout", "25"));
80
81                         // Anything less than 60 and we risk 429 Too Many Requests
82                         if (pollingInterval < 60) {
83                                 pollingInterval = 60;
84                         }
85
86                         if (pollingInterval > pollingInterval) {
87                                 logger.warn(String.format(
88                                                 "Message acknowledgement may be delayed by %ds in the ADSC listener. [Listening Time: %s, Poll Period: %s]",
89                                                 pollingInterval - pollingTimeout, pollingTimeout, pollingInterval));
90                         }
91
92                         logParams();
93
94                         // Download type
95                         types.add("APPC_CONFIG");
96                         types.add("VF_LICENSE");
97
98                         storeOp = new URI(props.getProperty("appc.asdc.provider.url"));
99                 }
100         }
101
102         @Override
103         public boolean activateServerTLSAuth() {
104                 return false;
105         }
106
107         //@Override
108         public boolean isFilterInEmptyResources() {
109                 return false;
110         }
111
112         @Override
113         public String getAsdcAddress() {
114                 return host;
115         }
116
117         @Override
118         public String getConsumerGroup() {
119                 return consumer;
120         }
121
122         @Override
123         public String getConsumerID() {
124                 return consumerId;
125         }
126
127         @Override
128         public String getEnvironmentName() {
129                 return env;
130         }
131
132         @Override
133         public String getKeyStorePassword() {
134                 return keystorePass;
135         }
136
137         @Override
138         public String getKeyStorePath() {
139                 return keystorePath;
140         }
141
142         @Override
143         public String getPassword() {
144                 return pass;
145         }
146
147         @Override
148         public int getPollingInterval() {
149                 return pollingInterval;
150         }
151
152         @Override
153         public int getPollingTimeout() {
154                 return pollingTimeout;
155         }
156
157         @Override
158         public List<String> getRelevantArtifactTypes() {
159                 return types;
160         }
161
162         @Override
163         public String getUser() {
164                 return user;
165         }
166
167         public URI getStoreOpURI() {
168                 return storeOp;
169         }
170
171         /**
172          * Logs the relevant parameters
173          */
174         public void logParams() {
175                 Map<String, String> params = new HashMap<String, String>();
176                 params.put("ASDC Host", getAsdcAddress());
177                 params.put("ASDC Environment", getEnvironmentName());
178                 params.put("Consumer Name", getConsumerGroup());
179                 params.put("Consumer ID", getConsumerID());
180                 params.put("Poll Active Wait", String.valueOf(getPollingInterval()));
181                 params.put("Poll Timeout", String.valueOf(getPollingTimeout()));
182
183                 logger.info(String.format("ASDC Params: %s", params));
184         }
185 }