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 java.io.IOException;
24 import java.util.Optional;
26 import org.onap.dcaegen2.collectors.datafile.config.AaiClientConfiguration;
27 import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
28 import org.onap.dcaegen2.collectors.datafile.configuration.Config;
29 import org.onap.dcaegen2.collectors.datafile.exceptions.AaiNotFoundException;
30 import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
31 import org.onap.dcaegen2.collectors.datafile.service.AaiConsumerClient;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.stereotype.Component;
38 public class AaiConsumerTaskImpl extends AaiConsumerTask {
40 private final Logger logger = LoggerFactory.getLogger(this.getClass());
42 private final Config datafileAppConfig;
43 private AaiConsumerClient aaiConsumerClient;
46 public AaiConsumerTaskImpl(AppConfig datafileAppConfig) {
47 this.datafileAppConfig = datafileAppConfig;
51 Optional<String> consume(ConsumerDmaapModel consumerDmaapModel) throws AaiNotFoundException {
52 logger.trace("Method called with arg {}", consumerDmaapModel);
54 return aaiConsumerClient.getHttpResponse(consumerDmaapModel);
55 } catch (IOException e) {
56 logger.warn("Get request not successful", e);
57 throw new AaiNotFoundException("Get request not successful");
62 public String execute(ConsumerDmaapModel consumerDmaapModel) throws AaiNotFoundException {
63 consumerDmaapModel = Optional.ofNullable(consumerDmaapModel)
64 .orElseThrow(() -> new AaiNotFoundException("Invoked null object to AAI task"));
65 logger.trace("Method called with arg {}", consumerDmaapModel);
66 aaiConsumerClient = resolveClient();
67 return consume(consumerDmaapModel).orElseThrow(() -> new AaiNotFoundException("Null response code"));
70 protected AaiClientConfiguration resolveConfiguration() {
71 return datafileAppConfig.getAaiClientConfiguration();
75 AaiConsumerClient resolveClient() {
76 return Optional.ofNullable(aaiConsumerClient).orElseGet(() -> new AaiConsumerClient(resolveConfiguration()));