1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
|
/*
* ============LICENSE_START=======================================================
* BBS-RELOCATION-CPE-AUTHENTICATION-HANDLER
* ================================================================================
* Copyright (C) 2019 NOKIA Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
*/
package org.onap.bbs.event.processor.config;
import static org.onap.bbs.event.processor.config.ApplicationConstants.STREAMS_TYPE;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.jetbrains.annotations.NotNull;
import org.onap.bbs.event.processor.exceptions.ApplicationEnvironmentException;
import org.onap.bbs.event.processor.exceptions.ConfigurationParsingException;
import org.onap.bbs.event.processor.model.GeneratedAppConfigObject;
import org.onap.bbs.event.processor.utilities.LoggingUtil;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapConsumerConfiguration;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.ImmutableDmaapConsumerConfiguration;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.ImmutableDmaapPublisherConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ApplicationConfiguration implements ConfigurationChangeObservable {
private final AaiClientProperties aaiClientProperties;
private final DmaapReRegistrationConsumerProperties dmaapReRegistrationConsumerProperties;
private final DmaapCpeAuthenticationConsumerProperties dmaapCpeAuthenticationConsumerProperties;
private final DmaapProducerProperties dmaapProducerProperties;
private final SecurityProperties securityProperties;
private final GenericProperties genericProperties;
private DmaapConsumerConfiguration dmaapReRegistrationConsumerConfiguration;
private DmaapConsumerConfiguration dmaapCpeAuthenticationConsumerConfiguration;
private DmaapPublisherConfiguration dmaapPublisherConfiguration;
private AaiClientConfiguration aaiClientConfiguration;
private Set<ConfigurationChangeObserver> observers;
private int cbsPollingInterval;
/**
* Construct BBS event processor application configuration object.
* @param aaiClientProperties Properties for AAI client setup
* @param dmaapReRegistrationConsumerProperties Properties for DMaaP client setup (PNF re-registration)
* @param dmaapCpeAuthenticationConsumerProperties Properties for DMaaP client setup (CPE authentication)
* @param dmaapProducerProperties Properties for DMaaP client setup (Close Loop)
* @param securityProperties General security properties
* @param genericProperties General application properties
*/
@Autowired
public ApplicationConfiguration(AaiClientProperties aaiClientProperties,
DmaapReRegistrationConsumerProperties dmaapReRegistrationConsumerProperties,
DmaapCpeAuthenticationConsumerProperties dmaapCpeAuthenticationConsumerProperties,
DmaapProducerProperties dmaapProducerProperties,
SecurityProperties securityProperties,
GenericProperties genericProperties) {
this.aaiClientProperties = aaiClientProperties;
this.dmaapReRegistrationConsumerProperties = dmaapReRegistrationConsumerProperties;
this.dmaapCpeAuthenticationConsumerProperties = dmaapCpeAuthenticationConsumerProperties;
this.dmaapProducerProperties = dmaapProducerProperties;
this.securityProperties = securityProperties;
this.genericProperties = genericProperties;
observers = new HashSet<>();
constructConfigurationObjects();
}
@Override
public synchronized void register(ConfigurationChangeObserver observer) {
observers.add(observer);
}
@Override
public synchronized void unRegister(ConfigurationChangeObserver observer) {
observers.remove(observer);
}
@Override
public synchronized void notifyObservers() {
observers.forEach(ConfigurationChangeObserver::updateConfiguration);
}
public synchronized DmaapConsumerConfiguration getDmaapReRegistrationConsumerConfiguration() {
return dmaapReRegistrationConsumerConfiguration;
}
public synchronized DmaapConsumerConfiguration getDmaapCpeAuthenticationConsumerConfiguration() {
return dmaapCpeAuthenticationConsumerConfiguration;
}
public synchronized DmaapPublisherConfiguration getDmaapPublisherConfiguration() {
return dmaapPublisherConfiguration;
}
public synchronized AaiClientConfiguration getAaiClientConfiguration() {
return aaiClientConfiguration;
}
public synchronized int getPipelinesPollingIntervalInSeconds() {
return genericProperties.getPipelinesPollingIntervalSec();
}
public synchronized int getPipelinesTimeoutInSeconds() {
return genericProperties.getPipelinesTimeoutSec();
}
public synchronized String getPolicyVersion() {
return genericProperties.getPolicyVersion();
}
public synchronized String getCloseLoopTargetType() {
return genericProperties.getClTargetType();
}
public synchronized String getCloseLoopEventStatus() {
return genericProperties.getClEventStatus();
}
public synchronized String getCloseLoopVersion() {
return genericProperties.getClVersion();
}
public synchronized String getCloseLoopTarget() {
return genericProperties.getClTarget();
}
public String getCloseLoopOriginator() {
return genericProperties.getClOriginator();
}
public synchronized int getCbsPollingInterval() {
return cbsPollingInterval;
}
public synchronized String getReRegistrationCloseLoopPolicyScope() {
return genericProperties.getReRegistration().getPolicyScope();
}
public synchronized String getReRegistrationCloseLoopControlName() {
return genericProperties.getReRegistration().getClControlName();
}
public synchronized String getCpeAuthenticationCloseLoopPolicyScope() {
return genericProperties.getCpeAuthentication().getPolicyScope();
}
public synchronized String getCpeAuthenticationCloseLoopControlName() {
return genericProperties.getCpeAuthentication().getClControlName();
}
/**
* Update current configuration based on the new configuration object fetched from Consul via CBS service of DCAE.
* @param newConfiguration updated configuration object
*/
public void updateCurrentConfiguration(GeneratedAppConfigObject newConfiguration) {
synchronized (this) {
cbsPollingInterval = newConfiguration.cbsPollingIntervalSec();
securityProperties.setEnableAaiCertAuth(newConfiguration.enableAaiCertAuth());
securityProperties.setEnableDmaapCertAuth(newConfiguration.enableDmaapCertAuth());
securityProperties.setKeyStorePath(newConfiguration.keyStorePath());
securityProperties.setKeyStorePasswordPath(newConfiguration.keyStorePasswordPath());
securityProperties.setTrustStorePath(newConfiguration.trustStorePath());
securityProperties.setTrustStorePasswordPath(newConfiguration.trustStorePasswordPath());
GeneratedAppConfigObject.StreamsObject reRegObject =
getStreamsObject(newConfiguration.streamSubscribesMap(), newConfiguration.reRegConfigKey(),
"PNF Re-Registration");
TopicUrlInfo topicUrlInfo = parseTopicUrl(reRegObject.dmaapInfo().topicUrl());
dmaapReRegistrationConsumerProperties.setDmaapHostName(topicUrlInfo.getHost());
dmaapReRegistrationConsumerProperties.setDmaapPortNumber(topicUrlInfo.getPort());
dmaapReRegistrationConsumerProperties.setDmaapProtocol(newConfiguration.dmaapProtocol());
dmaapReRegistrationConsumerProperties.setDmaapUserName(reRegObject.aafUsername());
dmaapReRegistrationConsumerProperties.setDmaapUserPassword(reRegObject.aafPassword());
dmaapReRegistrationConsumerProperties.setDmaapContentType(newConfiguration.dmaapContentType());
dmaapReRegistrationConsumerProperties.setDmaapTopicName(topicUrlInfo.getTopicName());
dmaapReRegistrationConsumerProperties.setConsumerId(newConfiguration.dmaapConsumerConsumerId());
dmaapReRegistrationConsumerProperties.setConsumerGroup(newConfiguration.dmaapConsumerConsumerGroup());
dmaapReRegistrationConsumerProperties.setMessageLimit(newConfiguration.dmaapMessageLimit());
dmaapReRegistrationConsumerProperties.setTimeoutMs(newConfiguration.dmaapTimeoutMs());
constructDmaapReRegistrationConfiguration();
GeneratedAppConfigObject.StreamsObject cpeAuthObject =
getStreamsObject(newConfiguration.streamSubscribesMap(), newConfiguration.cpeAuthConfigKey(),
"CPE Authentication");
topicUrlInfo = parseTopicUrl(cpeAuthObject.dmaapInfo().topicUrl());
dmaapCpeAuthenticationConsumerProperties.setDmaapHostName(topicUrlInfo.getHost());
dmaapCpeAuthenticationConsumerProperties.setDmaapPortNumber(topicUrlInfo.getPort());
dmaapCpeAuthenticationConsumerProperties.setDmaapProtocol(newConfiguration.dmaapProtocol());
dmaapCpeAuthenticationConsumerProperties.setDmaapUserName(cpeAuthObject.aafUsername());
dmaapCpeAuthenticationConsumerProperties.setDmaapUserPassword(cpeAuthObject.aafPassword());
dmaapCpeAuthenticationConsumerProperties.setDmaapContentType(newConfiguration.dmaapContentType());
dmaapCpeAuthenticationConsumerProperties.setDmaapTopicName(topicUrlInfo.getTopicName());
dmaapCpeAuthenticationConsumerProperties.setConsumerId(newConfiguration.dmaapConsumerConsumerId());
dmaapCpeAuthenticationConsumerProperties.setConsumerGroup(newConfiguration.dmaapConsumerConsumerGroup());
dmaapCpeAuthenticationConsumerProperties.setMessageLimit(newConfiguration.dmaapMessageLimit());
dmaapCpeAuthenticationConsumerProperties.setTimeoutMs(newConfiguration.dmaapTimeoutMs());
constructDmaapCpeAuthenticationConfiguration();
GeneratedAppConfigObject.StreamsObject closeLoopObject =
getStreamsObject(newConfiguration.streamPublishesMap(), newConfiguration.closeLoopConfigKey(),
"Close Loop");
topicUrlInfo = parseTopicUrl(closeLoopObject.dmaapInfo().topicUrl());
dmaapProducerProperties.setDmaapHostName(topicUrlInfo.getHost());
dmaapProducerProperties.setDmaapPortNumber(topicUrlInfo.getPort());
dmaapProducerProperties.setDmaapProtocol(newConfiguration.dmaapProtocol());
dmaapProducerProperties.setDmaapUserName(closeLoopObject.aafUsername());
dmaapProducerProperties.setDmaapUserPassword(closeLoopObject.aafPassword());
dmaapProducerProperties.setDmaapContentType(newConfiguration.dmaapContentType());
dmaapProducerProperties.setDmaapTopicName(topicUrlInfo.getTopicName());
constructDmaapProducerConfiguration();
aaiClientProperties.setAaiHost(newConfiguration.aaiHost());
aaiClientProperties.setAaiPort(newConfiguration.aaiPort());
aaiClientProperties.setAaiProtocol(newConfiguration.aaiProtocol());
aaiClientProperties.setAaiUserName(newConfiguration.aaiUsername());
aaiClientProperties.setAaiUserPassword(newConfiguration.aaiPassword());
aaiClientProperties.setAaiIgnoreSslCertificateErrors(newConfiguration.aaiIgnoreSslCertificateErrors());
constructAaiConfiguration();
genericProperties.setPipelinesPollingIntervalSec(newConfiguration.pipelinesPollingIntervalSec());
genericProperties.setPipelinesTimeoutSec(newConfiguration.pipelinesTimeoutSec());
genericProperties.setPolicyVersion(newConfiguration.policyVersion());
genericProperties.setClTargetType(newConfiguration.closeLoopTargetType());
genericProperties.setClEventStatus(newConfiguration.closeLoopEventStatus());
genericProperties.setClVersion(newConfiguration.closeLoopVersion());
genericProperties.setClTarget(newConfiguration.closeLoopTarget());
genericProperties.setClOriginator(newConfiguration.closeLoopOriginator());
genericProperties.getReRegistration().setPolicyScope(newConfiguration.reRegistrationPolicyScope());
genericProperties.getReRegistration().setClControlName(newConfiguration.reRegistrationClControlName());
genericProperties.getCpeAuthentication().setPolicyScope(newConfiguration.cpeAuthPolicyScope());
genericProperties.getCpeAuthentication().setClControlName(newConfiguration.cpeAuthClControlName());
LoggingUtil.changeLoggingLevel(newConfiguration.loggingLevel());
}
notifyObservers();
}
@NotNull
private GeneratedAppConfigObject.StreamsObject getStreamsObject(
Map<String, GeneratedAppConfigObject.StreamsObject> map, String configKey, String messageName) {
GeneratedAppConfigObject.StreamsObject streamsObject = map.get(configKey);
if (!STREAMS_TYPE.equals(streamsObject.type())) {
throw new ApplicationEnvironmentException(String.format("%s requires information about"
+ " message-router topic in ONAP", messageName));
}
return streamsObject;
}
private void constructConfigurationObjects() {
constructDmaapReRegistrationConfiguration();
constructDmaapCpeAuthenticationConfiguration();
constructDmaapProducerConfiguration();
constructAaiConfiguration();
}
private void constructDmaapReRegistrationConfiguration() {
dmaapReRegistrationConsumerConfiguration = new ImmutableDmaapConsumerConfiguration.Builder()
.dmaapHostName(dmaapReRegistrationConsumerProperties.getDmaapHostName())
.dmaapPortNumber(dmaapReRegistrationConsumerProperties.getDmaapPortNumber())
.dmaapProtocol(dmaapReRegistrationConsumerProperties.getDmaapProtocol())
.dmaapTopicName(dmaapReRegistrationConsumerProperties.getDmaapTopicName())
.dmaapUserName(
dmaapReRegistrationConsumerProperties.getDmaapUserName() == null ? "" :
dmaapReRegistrationConsumerProperties.getDmaapUserName())
.dmaapUserPassword(
dmaapReRegistrationConsumerProperties.getDmaapUserPassword() == null ? "" :
dmaapReRegistrationConsumerProperties.getDmaapUserPassword())
.dmaapContentType(dmaapReRegistrationConsumerProperties.getDmaapContentType())
.consumerId(dmaapReRegistrationConsumerProperties.getConsumerId())
.consumerGroup(dmaapReRegistrationConsumerProperties.getConsumerGroup())
.timeoutMs(dmaapReRegistrationConsumerProperties.getTimeoutMs())
.messageLimit(dmaapReRegistrationConsumerProperties.getMessageLimit())
.enableDmaapCertAuth(securityProperties.isEnableDmaapCertAuth())
.keyStorePath(securityProperties.getKeyStorePath())
.keyStorePasswordPath(securityProperties.getKeyStorePasswordPath())
.trustStorePath(securityProperties.getTrustStorePath())
.trustStorePasswordPath(securityProperties.getTrustStorePasswordPath())
.build();
}
private void constructDmaapCpeAuthenticationConfiguration() {
dmaapCpeAuthenticationConsumerConfiguration = new ImmutableDmaapConsumerConfiguration.Builder()
.dmaapHostName(dmaapCpeAuthenticationConsumerProperties.getDmaapHostName())
.dmaapPortNumber(dmaapCpeAuthenticationConsumerProperties.getDmaapPortNumber())
.dmaapProtocol(dmaapCpeAuthenticationConsumerProperties.getDmaapProtocol())
.dmaapTopicName(dmaapCpeAuthenticationConsumerProperties.getDmaapTopicName())
.dmaapUserName(
dmaapCpeAuthenticationConsumerProperties.getDmaapUserName() == null ? "" :
dmaapCpeAuthenticationConsumerProperties.getDmaapUserName())
.dmaapUserPassword(
dmaapCpeAuthenticationConsumerProperties.getDmaapUserPassword() == null ? "" :
dmaapCpeAuthenticationConsumerProperties.getDmaapUserPassword())
.dmaapContentType(dmaapCpeAuthenticationConsumerProperties.getDmaapContentType())
.consumerId(dmaapCpeAuthenticationConsumerProperties.getConsumerId())
.consumerGroup(dmaapCpeAuthenticationConsumerProperties.getConsumerGroup())
.timeoutMs(dmaapCpeAuthenticationConsumerProperties.getTimeoutMs())
.messageLimit(dmaapCpeAuthenticationConsumerProperties.getMessageLimit())
.enableDmaapCertAuth(securityProperties.isEnableDmaapCertAuth())
.keyStorePath(securityProperties.getKeyStorePath())
.keyStorePasswordPath(securityProperties.getKeyStorePasswordPath())
.trustStorePath(securityProperties.getTrustStorePath())
.trustStorePasswordPath(securityProperties.getTrustStorePasswordPath())
.build();
}
private void constructDmaapProducerConfiguration() {
dmaapPublisherConfiguration = new ImmutableDmaapPublisherConfiguration.Builder()
.dmaapHostName(dmaapProducerProperties.getDmaapHostName())
.dmaapPortNumber(dmaapProducerProperties.getDmaapPortNumber())
.dmaapProtocol(dmaapProducerProperties.getDmaapProtocol())
.dmaapTopicName(dmaapProducerProperties.getDmaapTopicName())
.dmaapUserName(
dmaapProducerProperties.getDmaapUserName() == null ? "" :
dmaapProducerProperties.getDmaapUserName())
.dmaapUserPassword(
dmaapProducerProperties.getDmaapUserPassword() == null ? "" :
dmaapProducerProperties.getDmaapUserPassword())
.dmaapContentType(dmaapProducerProperties.getDmaapContentType())
.enableDmaapCertAuth(securityProperties.isEnableDmaapCertAuth())
.keyStorePath(securityProperties.getKeyStorePath())
.keyStorePasswordPath(securityProperties.getKeyStorePasswordPath())
.trustStorePath(securityProperties.getTrustStorePath())
.trustStorePasswordPath(securityProperties.getTrustStorePasswordPath())
.build();
}
private void constructAaiConfiguration() {
aaiClientConfiguration = new ImmutableAaiClientConfiguration.Builder()
.aaiHost(aaiClientProperties.getAaiHost())
.aaiPort(aaiClientProperties.getAaiPort())
.aaiProtocol(aaiClientProperties.getAaiProtocol())
.aaiUserName(aaiClientProperties.getAaiUserName())
.aaiUserPassword(aaiClientProperties.getAaiUserPassword())
.aaiHeaders(aaiClientProperties.getAaiHeaders())
.aaiIgnoreSslCertificateErrors(aaiClientProperties.isAaiIgnoreSslCertificateErrors())
.enableAaiCertAuth(securityProperties.isEnableAaiCertAuth())
.keyStorePath(securityProperties.getKeyStorePath())
.keyStorePasswordPath(securityProperties.getKeyStorePasswordPath())
.trustStorePath(securityProperties.getTrustStorePath())
.trustStorePasswordPath(securityProperties.getTrustStorePasswordPath())
.build();
}
private TopicUrlInfo parseTopicUrl(String topicUrl) {
String[] urlTokens = topicUrl.split(":");
if (urlTokens.length != 3) {
throw new ConfigurationParsingException("Wrong topic URL format");
}
TopicUrlInfo topicUrlInfo = new TopicUrlInfo();
topicUrlInfo.setHost(urlTokens[1].replace("/", ""));
String[] tokensAfterHost = urlTokens[2].split("/events/");
if (tokensAfterHost.length != 2) {
throw new ConfigurationParsingException("Wrong topic name structure");
}
topicUrlInfo.setPort(Integer.valueOf(tokensAfterHost[0]));
topicUrlInfo.setTopicName("events/" + tokensAfterHost[1]);
return topicUrlInfo;
}
private static class TopicUrlInfo {
private String host;
private int port;
private String topicName;
String getHost() {
return host;
}
void setHost(String host) {
this.host = host;
}
int getPort() {
return port;
}
void setPort(int port) {
this.port = port;
}
String getTopicName() {
return topicName;
}
void setTopicName(String topicName) {
this.topicName = topicName;
}
}
}
|