2 * ============LICENSE_START=======================================================
3 * Datafile Collector Service
4 * ================================================================================
5 * Copyright (C) 2018 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.dcaegen2.collectors.datafile.tasks;
23 import org.onap.dcaegen2.collectors.datafile.config.AaiClientConfiguration;
24 import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
25 import org.onap.dcaegen2.collectors.datafile.configuration.Config;
26 import org.onap.dcaegen2.collectors.datafile.exceptions.AaiNotFoundException;
27 import org.onap.dcaegen2.collectors.datafile.exceptions.DmaapNotFoundException;
28 import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
29 import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
30 import org.onap.dcaegen2.collectors.datafile.model.utils.HttpUtils;
31 import org.onap.dcaegen2.collectors.datafile.service.producer.AaiProducerReactiveHttpClient;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.stereotype.Component;
36 import reactor.core.publisher.Mono;
39 * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/13/18
42 public class AaiProducerTaskImpl extends
45 private final Logger logger = LoggerFactory.getLogger(this.getClass());
47 private final Config datafileAppConfig;
48 private AaiProducerReactiveHttpClient aaiProducerReactiveHttpClient;
51 public AaiProducerTaskImpl(AppConfig datafileAppConfig) {
52 this.datafileAppConfig = datafileAppConfig;
56 Mono<ConsumerDmaapModel> publish(Mono<ConsumerDmaapModel> consumerDmaapModel) {
57 logger.info("Sending PNF model to AAI {}", consumerDmaapModel);
58 return aaiProducerReactiveHttpClient.getAaiProducerResponse(consumerDmaapModel)
59 .flatMap(response -> {
60 if (HttpUtils.isSuccessfulResponseCode(response)) {
61 return consumerDmaapModel;
64 .error(new AaiNotFoundException("Incorrect response code for continuation of tasks workflow"));
69 AaiProducerReactiveHttpClient resolveClient() {
70 return aaiProducerReactiveHttpClient == null ? new AaiProducerReactiveHttpClient(resolveConfiguration())
71 .createAaiWebClient(buildWebClient()) : aaiProducerReactiveHttpClient;
75 protected AaiClientConfiguration resolveConfiguration() {
76 return datafileAppConfig.getAaiClientConfiguration();
80 protected Mono<ConsumerDmaapModel> execute(Mono<ConsumerDmaapModel> consumerDmaapModel) throws DatafileTaskException {
81 if (consumerDmaapModel == null) {
82 throw new DmaapNotFoundException("Invoked null object to DMaaP task");
84 aaiProducerReactiveHttpClient = resolveClient();
85 logger.trace("Method called with arg {}", consumerDmaapModel);
86 return publish(consumerDmaapModel);