2 * ============LICENSE_START=======================================================
3 * PNF-REGISTRATION-HANDLER
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.services.prh.service.producer;
23 import org.apache.http.client.utils.URIBuilder;
24 import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration;
25 import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 import org.springframework.web.reactive.function.client.ClientResponse;
30 import org.springframework.web.reactive.function.client.WebClient;
31 import reactor.core.publisher.Mono;
34 import java.net.URISyntaxException;
35 import java.util.UUID;
37 import static org.onap.dcaegen2.services.prh.model.CommonFunctions.createJsonBody;
38 import static org.onap.dcaegen2.services.prh.model.logging.MDCVariables.*;
41 public class AaiProducerReactiveHttpClient {
43 private WebClient webClient;
44 private final String aaiHost;
45 private final String aaiProtocol;
46 private final Integer aaiHostPortNumber;
47 private final String aaiBasePath;
48 private final String aaiPnfPath;
51 * Constructor of AaiProducerReactiveHttpClient.
53 * @param configuration - AAI producer configuration object
55 public AaiProducerReactiveHttpClient(AaiClientConfiguration configuration) {
56 this.aaiHost = configuration.aaiHost();
57 this.aaiProtocol = configuration.aaiProtocol();
58 this.aaiHostPortNumber = configuration.aaiPort();
59 this.aaiBasePath = configuration.aaiBasePath();
60 this.aaiPnfPath = configuration.aaiPnfPath();
64 * Function for calling AAI Http producer - patch request to AAI database.
66 * @param consumerDmaapModelMono - object which will be sent to AAI database
67 * @return status code of operation
69 public Mono<ClientResponse> getAaiProducerResponse(ConsumerDmaapModel consumerDmaapModelMono) {
71 return patchAaiRequest(consumerDmaapModelMono);
72 } catch (URISyntaxException e) {
77 public AaiProducerReactiveHttpClient createAaiWebClient(WebClient webClient) {
78 this.webClient = webClient;
82 private Mono<ClientResponse> patchAaiRequest(ConsumerDmaapModel dmaapModel) throws URISyntaxException {
85 .uri(getUri(dmaapModel.getSourceName()))
86 .header(X_ONAP_REQUEST_ID, MDC.get(REQUEST_ID))
87 .header(X_INVOCATION_ID, UUID.randomUUID().toString())
88 .body(Mono.just(createJsonBody(dmaapModel)), String.class)
92 URI getUri(String pnfName) throws URISyntaxException {
93 return new URIBuilder()
94 .setScheme(aaiProtocol)
96 .setPort(aaiHostPortNumber)
97 .setPath(aaiBasePath + aaiPnfPath + "/" + pnfName)