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;
26 import org.onap.bbs.event.processor.config.ApplicationConfiguration;
27 import org.onap.bbs.event.processor.config.ConfigurationChangeObserver;
28 import org.onap.bbs.event.processor.exceptions.DmaapException;
29 import org.onap.bbs.event.processor.model.ControlLoopPublisherDmaapModel;
30 import org.onap.bbs.event.processor.utilities.ControlLoopJsonBodyBuilder;
31 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.producer.DMaaPPublisherReactiveHttpClient;
32 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.producer.DmaaPRestTemplateFactory;
33 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.producer.PublisherReactiveHttpClientFactory;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.http.ResponseEntity;
38 import org.springframework.stereotype.Component;
40 import reactor.core.publisher.Mono;
43 public class DmaapPublisherTaskImpl implements DmaapPublisherTask, ConfigurationChangeObserver {
45 private static final Logger LOGGER = LoggerFactory.getLogger(DmaapPublisherTaskImpl.class);
46 private ApplicationConfiguration configuration;
47 private final PublisherReactiveHttpClientFactory httpClientFactory;
49 private DMaaPPublisherReactiveHttpClient httpClient;
52 DmaapPublisherTaskImpl(ApplicationConfiguration configuration) {
53 this(configuration, new PublisherReactiveHttpClientFactory(new DmaaPRestTemplateFactory(),
54 new ControlLoopJsonBodyBuilder()));
57 DmaapPublisherTaskImpl(ApplicationConfiguration configuration,
58 PublisherReactiveHttpClientFactory httpClientFactory) {
59 this.configuration = configuration;
60 this.httpClientFactory = httpClientFactory;
62 httpClient = httpClientFactory.create(this.configuration.getDmaapPublisherConfiguration());
66 void registerForConfigChanges() {
67 configuration.register(this);
71 void unRegisterForConfigChanges() {
72 configuration.unRegister(this);
76 public synchronized void updateConfiguration() {
77 LOGGER.info("DMaaP Publisher update due to new application configuration");
78 httpClient = httpClientFactory.create(this.configuration.getDmaapPublisherConfiguration());
82 public Mono<ResponseEntity<String>> execute(ControlLoopPublisherDmaapModel controlLoopPublisherDmaapModel) {
83 if (controlLoopPublisherDmaapModel == null) {
84 throw new DmaapException("Cannot invoke a DMaaP Publish task with a null message");
86 LOGGER.info("Executing task for publishing control loop message \n{}", controlLoopPublisherDmaapModel);
87 DMaaPPublisherReactiveHttpClient httpClient = getHttpClient();
88 return httpClient.getDMaaPProducerResponse(controlLoopPublisherDmaapModel);
91 private synchronized DMaaPPublisherReactiveHttpClient getHttpClient() {