summaryrefslogtreecommitdiffstats
path: root/prh-aai-client/src/main/java
diff options
context:
space:
mode:
authormicdzied <michal.1.dziedzic@nokia.com>2018-12-03 11:01:37 +0100
committermicdzied <michal.1.dziedzic@nokia.com>2018-12-03 14:10:04 +0100
commit19ff70fb04bf4fa6fc01d89c4de02e0c4d60300e (patch)
tree3b6821fa639729f1ed4b37b0a56a90ec05a9a217 /prh-aai-client/src/main/java
parent85e1d39b283ffe6c78f8d8175809f285059b92cb (diff)
SDK integration: use aai in PRH
Change-Id: I68c9a5323e05a27de463bef9dd368f8a092559ae Issue-ID: DCAEGEN2-1013 Signed-off-by: micdzied <michal.1.dziedzic@nokia.com>
Diffstat (limited to 'prh-aai-client/src/main/java')
-rw-r--r--prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/config/AaiClientConfiguration.java80
-rw-r--r--prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiReactiveWebClientFactory.java128
-rw-r--r--prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/producer/AaiProducerReactiveHttpClient.java90
3 files changed, 0 insertions, 298 deletions
diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/config/AaiClientConfiguration.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/config/AaiClientConfiguration.java
deleted file mode 100644
index 23e621fe..00000000
--- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/config/AaiClientConfiguration.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PNF-REGISTRATION-HANDLER
- * ================================================================================
- * Copyright (C) 2018 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.prh.config;
-
-import java.io.Serializable;
-import java.util.Map;
-import org.immutables.gson.Gson;
-import org.immutables.value.Value;
-import org.springframework.stereotype.Component;
-
-
-@Component
-@Value.Immutable(prehash = true)
-@Value.Style(builder = "new")
-@Gson.TypeAdapters
-public abstract class AaiClientConfiguration implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- @Value.Parameter
- public abstract String aaiHost();
-
- @Value.Parameter
- public abstract Integer aaiPort();
-
- @Value.Parameter
- public abstract String aaiProtocol();
-
- @Value.Parameter
- public abstract String aaiUserName();
-
- @Value.Parameter
- public abstract String aaiUserPassword();
-
- @Value.Parameter
- public abstract Boolean aaiIgnoreSslCertificateErrors();
-
- @Value.Parameter
- public abstract String aaiBasePath();
-
- @Value.Parameter
- public abstract String aaiPnfPath();
-
- @Value.Parameter
- public abstract Map<String, String> aaiHeaders();
-
- @Value.Parameter
- public abstract String trustStorePath();
-
- @Value.Parameter
- public abstract String trustStorePasswordPath();
-
- @Value.Parameter
- public abstract String keyStorePath();
-
- @Value.Parameter
- public abstract String keyStorePasswordPath();
-
- @Value.Parameter
- public abstract Boolean enableAaiCertAuth();
-
-}
diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiReactiveWebClientFactory.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiReactiveWebClientFactory.java
deleted file mode 100644
index e4f330e0..00000000
--- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiReactiveWebClientFactory.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PNF-REGISTRATION-HANDLER
- * ================================================================================
- * Copyright (C) 2018 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.prh.service;
-
-import static org.onap.dcaegen2.services.prh.model.logging.MdcVariables.RESPONSE_CODE;
-import static org.onap.dcaegen2.services.prh.model.logging.MdcVariables.SERVICE_NAME;
-import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.basicAuthentication;
-
-import io.netty.handler.ssl.SslContext;
-import java.util.Map;
-import javax.net.ssl.SSLException;
-import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration;
-import org.onap.dcaegen2.services.prh.ssl.SslFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.slf4j.MDC;
-import org.springframework.http.client.reactive.ClientHttpConnector;
-import org.springframework.http.client.reactive.ReactorClientHttpConnector;
-import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
-import org.springframework.web.reactive.function.client.WebClient;
-import reactor.core.publisher.Mono;
-import reactor.netty.http.client.HttpClient;
-
-
-public class AaiReactiveWebClientFactory {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(AaiReactiveWebClientFactory.class);
-
- private final String aaiUserName;
- private final String aaiUserPassword;
- private final Map<String, String> aaiHeaders;
- private final Boolean enableAaiCertAuth;
- private final String trustStorePath;
- private final String trustStorePasswordPath;
- private final String keyStorePath;
- private final String keyStorePasswordPath;
- private final SslFactory sslFactory;
-
- /**
- * Creating AaiReactiveWebClientFactory.
- *
- * @param configuration - configuration object
- * @param sslFactory - factory for ssl setup
- */
- public AaiReactiveWebClientFactory(SslFactory sslFactory, AaiClientConfiguration configuration) {
- this.aaiUserName = configuration.aaiUserName();
- this.aaiUserPassword = configuration.aaiUserPassword();
- this.aaiHeaders = configuration.aaiHeaders();
- this.trustStorePath = configuration.trustStorePath();
- this.trustStorePasswordPath = configuration.trustStorePasswordPath();
- this.keyStorePath = configuration.keyStorePath();
- this.keyStorePasswordPath = configuration.keyStorePasswordPath();
- this.enableAaiCertAuth = configuration.enableAaiCertAuth();
- this.sslFactory = sslFactory;
- }
-
- /**
- * Construct Reactive WebClient with appropriate settings.
- *
- * @return WebClient
- */
- public WebClient build() throws SSLException {
- LOGGER.debug("Setting ssl context");
-
- SslContext sslContext = createSslContext();
-
- ClientHttpConnector reactorClientHttpConnector = new ReactorClientHttpConnector(
- HttpClient.create().secure(sslContextSpec -> sslContextSpec.sslContext(sslContext)));
-
- return WebClient.builder()
- .clientConnector(reactorClientHttpConnector)
- .defaultHeaders(httpHeaders -> httpHeaders.setAll(aaiHeaders))
- .filter(basicAuthentication(aaiUserName, aaiUserPassword))
- .filter(logRequest())
- .filter(logResponse())
- .build();
- }
-
- private SslContext createSslContext() throws SSLException {
- if (enableAaiCertAuth) {
- return sslFactory.createSecureContext(
- keyStorePath,
- keyStorePasswordPath,
- trustStorePath,
- trustStorePasswordPath
- );
- }
- return sslFactory.createInsecureContext();
- }
-
- private ExchangeFilterFunction logRequest() {
- return ExchangeFilterFunction.ofRequestProcessor(clientRequest -> {
- MDC.put(SERVICE_NAME, String.valueOf(clientRequest.url()));
- LOGGER.info("Request: {} {}", clientRequest.method(), clientRequest.url());
- clientRequest.headers()
- .forEach((name, values) -> values.forEach(value -> LOGGER.info("{}={}", name, value)));
- MDC.remove(SERVICE_NAME);
- return Mono.just(clientRequest);
- });
- }
-
- private ExchangeFilterFunction logResponse() {
- return ExchangeFilterFunction.ofResponseProcessor(clientResponse -> {
- MDC.put(RESPONSE_CODE, String.valueOf(clientResponse.statusCode()));
- LOGGER.info("Response Status {}", clientResponse.statusCode());
- MDC.remove(RESPONSE_CODE);
- return Mono.just(clientResponse);
- });
- }
-}
diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/producer/AaiProducerReactiveHttpClient.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/producer/AaiProducerReactiveHttpClient.java
deleted file mode 100644
index 43f6ce91..00000000
--- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/producer/AaiProducerReactiveHttpClient.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * PNF-REGISTRATION-HANDLER
- * ================================================================================
- * Copyright (C) 2018 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.prh.service.producer;
-
-import static org.onap.dcaegen2.services.prh.model.CommonFunctions.createJsonBody;
-import static org.onap.dcaegen2.services.prh.model.logging.MdcVariables.REQUEST_ID;
-import static org.onap.dcaegen2.services.prh.model.logging.MdcVariables.X_INVOCATION_ID;
-import static org.onap.dcaegen2.services.prh.model.logging.MdcVariables.X_ONAP_REQUEST_ID;
-
-import java.net.URI;
-import java.util.UUID;
-import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration;
-import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
-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;
-
-
-public class AaiProducerReactiveHttpClient {
-
- private WebClient webClient;
- private final String aaiHost;
- private final String aaiProtocol;
- private final Integer aaiHostPortNumber;
- private final String aaiBasePath;
- private final String aaiPnfPath;
-
- /**
- * Constructor of AaiProducerReactiveHttpClient.
- *
- * @param configuration - AAI producer configuration object
- */
- public AaiProducerReactiveHttpClient(AaiClientConfiguration configuration) {
- this.aaiHost = configuration.aaiHost();
- this.aaiProtocol = configuration.aaiProtocol();
- this.aaiHostPortNumber = configuration.aaiPort();
- this.aaiBasePath = configuration.aaiBasePath();
- this.aaiPnfPath = configuration.aaiPnfPath();
- }
-
- /**
- * Function for calling AAI Http producer - patch request to AAI database.
- *
- * @param consumerDmaapModelMono - object which will be sent to AAI database
- * @return status code of operation
- */
- public Mono<ClientResponse> getAaiProducerResponse(ConsumerDmaapModel consumerDmaapModelMono) {
- return patchAaiRequest(consumerDmaapModelMono);
- }
-
- public AaiProducerReactiveHttpClient createAaiWebClient(WebClient webClient) {
- this.webClient = webClient;
- return this;
- }
-
- private Mono<ClientResponse> patchAaiRequest(ConsumerDmaapModel dmaapModel) {
- return
- webClient.patch()
- .uri(getUri(dmaapModel.getCorrelationId()))
- .header(X_ONAP_REQUEST_ID, MDC.get(REQUEST_ID))
- .header(X_INVOCATION_ID, UUID.randomUUID().toString())
- .body(Mono.just(createJsonBody(dmaapModel)), 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