2 * ============LICENSE_START=======================================================
3 * BBS-RELOCATION-CPE-AUTHENTICATION-HANDLER
4 * ================================================================================
5 * Copyright (C) 2019 NOKIA 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.bbs.event.processor.tasks;
23 import javax.annotation.PostConstruct;
24 import javax.annotation.PreDestroy;
25 import javax.net.ssl.SSLException;
27 import org.onap.bbs.event.processor.config.ApplicationConfiguration;
28 import org.onap.bbs.event.processor.config.ConfigurationChangeObserver;
29 import org.onap.bbs.event.processor.exceptions.EmptyDmaapResponseException;
30 import org.onap.bbs.event.processor.model.ReRegistrationConsumerDmaapModel;
31 import org.onap.bbs.event.processor.utilities.ReRegistrationDmaapConsumerJsonParser;
32 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.consumer.ConsumerReactiveHttpClientFactory;
33 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.consumer.DMaaPConsumerReactiveHttpClient;
34 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.consumer.DMaaPReactiveWebClientFactory;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.stereotype.Component;
40 import reactor.core.publisher.Flux;
41 import reactor.core.publisher.Mono;
44 public class DmaapReRegistrationConsumerTaskImpl implements DmaapReRegistrationConsumerTask,
45 ConfigurationChangeObserver {
47 private static final Logger LOGGER = LoggerFactory.getLogger(DmaapReRegistrationConsumerTaskImpl.class);
48 private ApplicationConfiguration configuration;
49 private final ReRegistrationDmaapConsumerJsonParser reRegistrationDmaapConsumerJsonParser;
50 private final ConsumerReactiveHttpClientFactory httpClientFactory;
52 private static final EmptyDmaapResponseException EMPTY_DMAAP_EXCEPTION =
53 new EmptyDmaapResponseException("PNF Re-Registration: Got an empty response from DMaaP");
55 private DMaaPConsumerReactiveHttpClient httpClient;
58 public DmaapReRegistrationConsumerTaskImpl(ApplicationConfiguration configuration) throws SSLException {
59 this(configuration, new ReRegistrationDmaapConsumerJsonParser(),
60 new ConsumerReactiveHttpClientFactory(new DMaaPReactiveWebClientFactory()));
63 DmaapReRegistrationConsumerTaskImpl(ApplicationConfiguration configuration,
64 ReRegistrationDmaapConsumerJsonParser reRegDmaapConsumerJsonParser,
65 ConsumerReactiveHttpClientFactory httpClientFactory)
67 this.configuration = configuration;
68 this.reRegistrationDmaapConsumerJsonParser = reRegDmaapConsumerJsonParser;
69 this.httpClientFactory = httpClientFactory;
71 httpClient = httpClientFactory.create(this.configuration.getDmaapReRegistrationConsumerConfiguration());
75 void registerForConfigChanges() {
76 configuration.register(this);
80 void unRegisterForConfigChanges() {
81 configuration.unRegister(this);
85 public synchronized void updateConfiguration() {
87 LOGGER.info("DMaaP PNF reregistration consumer update due to new application configuration");
88 httpClient = httpClientFactory.create(this.configuration.getDmaapReRegistrationConsumerConfiguration());
89 } catch (SSLException e) {
90 LOGGER.error("Error while updating HTTP Client after a config update: SSL exception");
95 public Flux<ReRegistrationConsumerDmaapModel> execute(String taskName) {
96 LOGGER.debug("Executing task for Re-Registration with name \"{}\"", taskName);
97 DMaaPConsumerReactiveHttpClient httpClient = getHttpClient();
98 Mono<String> response = httpClient.getDMaaPConsumerResponse();
99 return reRegistrationDmaapConsumerJsonParser.extractModelFromDmaap(response)
100 .switchIfEmpty(Flux.error(EMPTY_DMAAP_EXCEPTION))
102 if (!(e instanceof EmptyDmaapResponseException)) {
103 LOGGER.error("DMaaP Consumption Exception: {}", e.getMessage());
108 private synchronized DMaaPConsumerReactiveHttpClient getHttpClient() {