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