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;
23 import io.netty.handler.codec.http.HttpHeaders;
24 import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration;
25 import org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AaiHttpClient;
26 import org.onap.dcaegen2.services.sdk.rest.services.model.AaiModel;
27 import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder;
28 import org.onap.dcaegen2.services.sdk.rest.services.uri.URI;
30 import reactor.core.publisher.Mono;
31 import reactor.netty.ByteBufFlux;
32 import reactor.netty.http.client.HttpClient;
34 import java.util.UUID;
35 import java.util.function.Consumer;
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;
41 public final class AaiHttpPatchClient implements AaiHttpClient<Integer> {
43 private HttpClient httpClient;
44 private final AaiClientConfiguration configuration;
45 private final JsonBodyBuilder jsonBodyBuilder;
48 public AaiHttpPatchClient(final AaiClientConfiguration configuration, JsonBodyBuilder jsonBodyBuilder) {
49 this.configuration = configuration;
50 this.jsonBodyBuilder = jsonBodyBuilder;
54 public Mono<Integer> getAaiResponse(AaiModel aaiModel) {
56 .headers(addHeaders())
57 .baseUrl(getUri(aaiModel.getCorrelationId()))
59 .send(ByteBufFlux.fromString(Mono.just(jsonBodyBuilder.createJsonBody(aaiModel))))
60 .responseSingle((res, content) -> Mono.just(res.status().code()));
63 public AaiHttpPatchClient createAaiHttpClient(HttpClient httpClient) {
64 this.httpClient = httpClient;
68 String getUri(String pnfName) {
69 return new URI.URIBuilder()
70 .scheme(configuration.aaiProtocol())
71 .host(configuration.aaiHost())
72 .port(configuration.aaiPort())
73 .path(configuration.aaiBasePath() + configuration.aaiPnfPath() + "/" + pnfName).build().toString();
76 private Consumer<? super HttpHeaders> addHeaders() {
78 h.add(X_ONAP_REQUEST_ID, MDC.get(REQUEST_ID));
79 h.add(X_INVOCATION_ID, UUID.randomUUID().toString());