2 * ============LICENSE_START=======================================================
3 * DCAEGEN2-SERVICES-SDK
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.sdk.rest.services.aai.client.service.http.patch;
24 import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration;
25 import org.onap.dcaegen2.services.sdk.rest.services.model.ConsumerDmaapModel;
27 import org.springframework.web.reactive.function.client.ClientResponse;
28 import org.springframework.web.reactive.function.client.WebClient;
29 import org.springframework.web.util.DefaultUriBuilderFactory;
30 import reactor.core.publisher.Mono;
33 import java.util.UUID;
36 import static org.onap.dcaegen2.services.sdk.rest.services.model.CommonFunctions.createJsonBody;
37 import static org.onap.dcaegen2.services.sdk.rest.services.model.logging.MdcVariables.REQUEST_ID;
38 import static org.onap.dcaegen2.services.sdk.rest.services.model.logging.MdcVariables.X_INVOCATION_ID;
39 import static org.onap.dcaegen2.services.sdk.rest.services.model.logging.MdcVariables.X_ONAP_REQUEST_ID;
42 public class AaiReactiveHttpPatchClient {
44 private WebClient webClient;
45 private final String aaiHost;
46 private final String aaiProtocol;
47 private final Integer aaiHostPortNumber;
48 private final String aaiBasePath;
49 private final String aaiPnfPath;
52 * Constructor of AaiProducerReactiveHttpClient.
54 * @param configuration - AAI producer configuration object
56 public AaiReactiveHttpPatchClient(AaiClientConfiguration configuration) {
57 this.aaiHost = configuration.aaiHost();
58 this.aaiProtocol = configuration.aaiProtocol();
59 this.aaiHostPortNumber = configuration.aaiPort();
60 this.aaiBasePath = configuration.aaiBasePath();
61 this.aaiPnfPath = configuration.aaiPnfPath();
65 * Function for calling AAI Http producer - patch request to AAI database.
67 * @param consumerDmaapModelMono - object which will be sent to AAI database
68 * @return status code of operation
70 public Mono<ClientResponse> getAaiProducerResponse(ConsumerDmaapModel consumerDmaapModelMono) {
71 return patchAaiRequest(consumerDmaapModelMono);
74 public AaiReactiveHttpPatchClient createAaiWebClient(WebClient webClient) {
75 this.webClient = webClient;
79 private Mono<ClientResponse> patchAaiRequest(ConsumerDmaapModel dmaapModel) {
82 .uri(getUri(dmaapModel.getCorrelationId()))
83 .header(X_ONAP_REQUEST_ID, MDC.get(REQUEST_ID))
84 .header(X_INVOCATION_ID, UUID.randomUUID().toString())
85 .body(Mono.just(createJsonBody(dmaapModel)), String.class)
89 URI getUri(String pnfName) {
90 return new DefaultUriBuilderFactory().builder().scheme(aaiProtocol).host(aaiHost).port(aaiHostPortNumber)
91 .path(aaiBasePath + aaiPnfPath + "/" + pnfName).build();