Merging in bug fixes
[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<>();
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                         types.add("TOSCA_CSAR");
98                         /*
99                         This types seems redundant, as it looks from the code that they are not being used anywhere
100                          */
101
102                         storeOp = new URI(props.getProperty("appc.asdc.provider.url"));
103                 }
104         }
105
106         @Override
107         public boolean activateServerTLSAuth() {
108                 return false;
109         }
110
111         //@Override
112         public boolean isFilterInEmptyResources() {
113                 return false;
114         }
115
116         @Override
117         public String getAsdcAddress() {
118                 return host;
119         }
120
121         @Override
122         public String getConsumerGroup() {
123                 return consumer;
124         }
125
126         @Override
127         public String getConsumerID() {
128                 return consumerId;
129         }
130
131         @Override
132         public String getEnvironmentName() {
133                 return env;
134         }
135
136         @Override
137         public String getKeyStorePassword() {
138                 return keystorePass;
139         }
140
141         @Override
142         public String getKeyStorePath() {
143                 return keystorePath;
144         }
145
146         @Override
147         public String getPassword() {
148                 return pass;
149         }
150
151         @Override
152         public int getPollingInterval() {
153                 return pollingInterval;
154         }
155
156         @Override
157         public int getPollingTimeout() {
158                 return pollingTimeout;
159         }
160
161         @Override
162         public List<String> getRelevantArtifactTypes() {
163                 return types;
164         }
165
166         @Override
167         public String getUser() {
168                 return user;
169         }
170
171         public URI getStoreOpURI() {
172                 return storeOp;
173         }
174
175         /**
176          * Logs the relevant parameters
177          */
178         public void logParams() {
179                 Map<String, String> params = new HashMap<String, String>();
180                 params.put("ASDC Host", getAsdcAddress());
181                 params.put("ASDC Environment", getEnvironmentName());
182                 params.put("Consumer Name", getConsumerGroup());
183                 params.put("Consumer ID", getConsumerID());
184                 params.put("Poll Active Wait", String.valueOf(getPollingInterval()));
185                 params.put("Poll Timeout", String.valueOf(getPollingTimeout()));
186
187                 logger.info(String.format("ASDC Params: %s", params));
188         }
189 }