diff options
author | pwielebs <piotr.wielebski@nokia.com> | 2019-02-19 10:52:18 +0100 |
---|---|---|
committer | pwielebs <piotr.wielebski@nokia.com> | 2019-02-19 11:59:08 +0100 |
commit | fd4b51b83b901a230bd27b5805fe5f7960c4a705 (patch) | |
tree | 86945351d626c79fcc264bda9b984d33e98e8ab6 /rest-services/aai-client/src/main | |
parent | 6dccfdbc73ff779019fc4736a118b7d7b86d446b (diff) |
Add http put AAI client for SDK
Change-Id: I28c563508977162eacb35a09f2a6c3b932535b52
Issue-ID: DCAEGEN2-1246
Signed-off-by: pwielebs <piotr.wielebski@nokia.com>
Diffstat (limited to 'rest-services/aai-client/src/main')
2 files changed, 96 insertions, 1 deletions
diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiReactiveHttpPatchClient.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiReactiveHttpPatchClient.java index fa1248df..841db6e8 100644 --- a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiReactiveHttpPatchClient.java +++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiReactiveHttpPatchClient.java @@ -47,7 +47,6 @@ public class AaiReactiveHttpPatchClient { private final Integer aaiHostPortNumber; private final String aaiBasePath; private final String aaiPnfPath; - private final JsonBodyBuilder jsonBodyBuilder; /** diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiReactiveHttpPutClient.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiReactiveHttpPutClient.java new file mode 100644 index 00000000..bd5271be --- /dev/null +++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiReactiveHttpPutClient.java @@ -0,0 +1,96 @@ +/*- + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * Copyright (C) 2018-2019 NOKIA Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.put; + + +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.model.AaiModel; +import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder; +import org.slf4j.MDC; +import org.springframework.web.reactive.function.client.ClientResponse; +import org.springframework.web.reactive.function.client.WebClient; +import org.springframework.web.util.DefaultUriBuilderFactory; +import reactor.core.publisher.Mono; + +import java.net.URI; +import java.util.UUID; + + +import static org.onap.dcaegen2.services.sdk.rest.services.model.logging.MdcVariables.REQUEST_ID; +import static org.onap.dcaegen2.services.sdk.rest.services.model.logging.MdcVariables.X_INVOCATION_ID; +import static org.onap.dcaegen2.services.sdk.rest.services.model.logging.MdcVariables.X_ONAP_REQUEST_ID; + + +public class AaiReactiveHttpPutClient { + + private WebClient webClient; + private final String aaiHost; + private final String aaiProtocol; + private final Integer aaiHostPortNumber; + private final String aaiBasePath; + private final String aaiPnfPath; + + private final JsonBodyBuilder jsonBodyBuilder; + + /** + * Constructor of AaiProducerReactiveHttpClient. + * + * @param configuration - AAI producer configuration object + */ + public AaiReactiveHttpPutClient(AaiClientConfiguration configuration, JsonBodyBuilder jsonBodyBuilder) { + this.aaiHost = configuration.aaiHost(); + this.aaiProtocol = configuration.aaiProtocol(); + this.aaiHostPortNumber = configuration.aaiPort(); + this.aaiBasePath = configuration.aaiBasePath(); + this.aaiPnfPath = configuration.aaiPnfPath(); + this.jsonBodyBuilder = jsonBodyBuilder; + } + + /** + * Function for calling AAI Http producer - put request to AAI database. + * + * @param aaiModel - object which will be sent to AAI database + * @return status code of operation + */ + public Mono<ClientResponse> getAaiProducerResponse(AaiModel aaiModel) { + return putAaiRequest(aaiModel); + } + + public AaiReactiveHttpPutClient createAaiWebClient(WebClient webClient) { + this.webClient = webClient; + return this; + } + + private Mono<ClientResponse> putAaiRequest(AaiModel aaiModel) { + return + webClient.put() + .uri(getUri(aaiModel.getCorrelationId())) + .header(X_ONAP_REQUEST_ID, MDC.get(REQUEST_ID)) + .header(X_INVOCATION_ID, UUID.randomUUID().toString()) + .body(Mono.just(jsonBodyBuilder.createJsonBody(aaiModel)), String.class) + .exchange(); + } + + URI getUri(String pnfName) { + return new DefaultUriBuilderFactory().builder().scheme(aaiProtocol).host(aaiHost).port(aaiHostPortNumber) + .path(aaiBasePath + aaiPnfPath + "/" + pnfName).build(); + } +}
\ No newline at end of file |