From 19bb7116409b4eaa546b48b7d7389e4de04e4f03 Mon Sep 17 00:00:00 2001 From: Joanna Jeremicz Date: Wed, 2 Oct 2019 07:15:16 +0200 Subject: Restructure aai-client and get rid of common-dependency module Issue-ID: DCAEGEN2-1792 Change-Id: Ifcc69a917b2aec02615df93d10979d6c38a25ff2 Signed-off-by: Joanna Jeremicz --- pom.xml | 2 +- rest-services/aai-client/pom.xml | 2 +- .../aai/client/api/AaiClientConfiguration.java | 88 +++++++++++ .../services/aai/client/api/AaiHttpClient.java | 33 +++++ .../sdk/rest/services/aai/client/api/Request.java | 28 ++++ .../rest/services/aai/client/api/Transaction.java | 50 +++++++ .../rest/services/aai/client/api/Transactions.java | 52 +++++++ .../api/get/AaiGetServiceInstanceClient.java | 73 +++++++++ .../aai/client/api/get/AaiHttpGetClient.java | 58 ++++++++ .../aai/client/api/patch/AaiHttpPatchClient.java | 71 +++++++++ .../aai/client/api/put/AaiHttpPutClient.java | 57 +++++++ .../aai/client/config/AaiClientConfiguration.java | 88 ----------- .../rest/services/aai/client/impl/AaiRequests.java | 84 +++++++++++ .../aai/client/main/AaiHttpClientFactory.java | 71 +++++++++ .../rest/services/aai/client/model/AaiModel.java | 27 ++++ .../client/model/AaiServiceInstanceQueryModel.java | 31 ++++ .../services/aai/client/model/ClientModel.java | 24 +++ .../rest/services/aai/client/model/DmaapModel.java | 24 +++ .../services/aai/client/model/JsonBodyBuilder.java | 34 +++++ .../aai/client/service/AaiHttpClientFactory.java | 71 --------- .../aai/client/service/http/AaiHttpClient.java | 33 ----- .../aai/client/service/http/AaiRequests.java | 84 ----------- .../services/aai/client/service/http/Request.java | 28 ---- .../aai/client/service/http/Transaction.java | 49 ------ .../aai/client/service/http/Transactions.java | 52 ------- .../http/get/AaiGetServiceInstanceClient.java | 73 --------- .../client/service/http/get/AaiHttpGetClient.java | 58 -------- .../service/http/patch/AaiHttpPatchClient.java | 71 --------- .../client/service/http/put/AaiHttpPutClient.java | 57 ------- .../aai/client/AaiClientConfigurations.java | 59 -------- .../aai/client/api/AaiClientConfigurations.java | 59 ++++++++ .../aai/client/api/AbstractHttpClientTest.java | 42 ++++++ .../services/aai/client/api/TransactionsTest.java | 67 +++++++++ .../api/get/AaiGetServiceInstanceClientTest.java | 70 +++++++++ .../aai/client/api/get/AaiHttpGetClientTest.java | 81 ++++++++++ .../client/api/patch/AaiHttpPatchClientTest.java | 94 ++++++++++++ .../aai/client/api/put/AaiHttpPutClientTest.java | 80 ++++++++++ .../service/http/AbstractHttpClientTest.java | 42 ------ .../aai/client/service/http/TransactionsTest.java | 67 --------- .../http/get/AaiGetServiceInstanceClientTest.java | 70 --------- .../service/http/get/AaiHttpGetClientTest.java | 81 ---------- .../service/http/patch/AaiHttpPatchClientTest.java | 99 ------------- .../service/http/put/AaiHttpPutClientTest.java | 80 ---------- rest-services/cbs-client/pom.xml | 2 +- .../cbs/client/annotations/ExperimentalApi.java | 41 ++++++ rest-services/common-dependency/pom.xml | 74 ---------- .../rest/services/annotations/ExperimentalApi.java | 41 ------ .../services/sdk/rest/services/model/AaiModel.java | 27 ---- .../model/AaiServiceInstanceQueryModel.java | 31 ---- .../sdk/rest/services/model/ClientModel.java | 24 --- .../sdk/rest/services/model/DmaapModel.java | 24 --- .../sdk/rest/services/model/JsonBodyBuilder.java | 34 ----- .../model/logging/GlobalDiagnosticContext.java | 71 --------- .../rest/services/model/logging/MdcVariables.java | 65 -------- .../model/logging/RequestDiagnosticContext.java | 108 -------------- .../services/sdk/rest/services/uri/URI.java | 164 --------------------- .../services/model/logging/MdcVariablesTest.java | 36 ----- .../services/sdk/rest/services/uri/URITest.java | 45 ------ rest-services/dmaap-client/pom.xml | 2 +- .../dmaap/client/api/MessageRouterPublisher.java | 1 - .../dmaap/client/api/MessageRouterSubscriber.java | 1 - .../services/dmaap/client/model/DmaapRequest.java | 1 - .../services/dmaap/client/model/DmaapResponse.java | 1 - .../client/model/MessageRouterPublishRequest.java | 1 - .../client/model/MessageRouterPublishResponse.java | 1 - .../model/MessageRouterSubscribeRequest.java | 1 - rest-services/http-client/pom.xml | 11 +- .../sdk/rest/services/adapters/http/URI.java | 164 +++++++++++++++++++++ .../http/logging/GlobalDiagnosticContext.java | 71 +++++++++ .../adapters/http/logging/MdcVariables.java | 65 ++++++++ .../http/logging/RequestDiagnosticContext.java | 108 ++++++++++++++ .../sdk/rest/services/adapters/http/URITest.java | 45 ++++++ .../adapters/http/logging/MdcVariablesTest.java | 36 +++++ rest-services/model/pom.xml | 2 +- rest-services/pom.xml | 3 +- security/crypt-password/pom.xml | 2 +- security/pom.xml | 2 +- security/ssl/pom.xml | 2 +- services/hv-ves-client/pom.xml | 2 +- services/hv-ves-client/producer/api/pom.xml | 2 +- services/hv-ves-client/producer/ct/pom.xml | 2 +- services/hv-ves-client/producer/impl/pom.xml | 2 +- services/hv-ves-client/producer/pom.xml | 2 +- services/hv-ves-client/protobuf/pom.xml | 2 +- services/pom.xml | 2 +- standardization/api-custom-header/pom.xml | 2 +- standardization/moher-api/healthstate/pom.xml | 2 +- standardization/moher-api/metrics/pom.xml | 2 +- standardization/moher-api/pom.xml | 2 +- standardization/moher-api/server-adapters/pom.xml | 2 +- .../server-adapters/reactor-netty/pom.xml | 2 +- .../server-adapters/spring-webflux/pom.xml | 2 +- standardization/pom.xml | 2 +- version.properties | 2 +- 94 files changed, 1858 insertions(+), 1945 deletions(-) create mode 100644 rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/AaiClientConfiguration.java create mode 100644 rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/AaiHttpClient.java create mode 100644 rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/Request.java create mode 100644 rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/Transaction.java create mode 100644 rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/Transactions.java create mode 100644 rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/get/AaiGetServiceInstanceClient.java create mode 100644 rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/get/AaiHttpGetClient.java create mode 100644 rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/patch/AaiHttpPatchClient.java create mode 100644 rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/put/AaiHttpPutClient.java delete mode 100644 rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/config/AaiClientConfiguration.java create mode 100644 rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/impl/AaiRequests.java create mode 100644 rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/main/AaiHttpClientFactory.java create mode 100644 rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/model/AaiModel.java create mode 100644 rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/model/AaiServiceInstanceQueryModel.java create mode 100644 rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/model/ClientModel.java create mode 100644 rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/model/DmaapModel.java create mode 100644 rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/model/JsonBodyBuilder.java delete mode 100644 rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiHttpClientFactory.java delete mode 100644 rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/AaiHttpClient.java delete mode 100644 rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/AaiRequests.java delete mode 100644 rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/Request.java delete mode 100644 rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/Transaction.java delete mode 100644 rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/Transactions.java delete mode 100644 rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiGetServiceInstanceClient.java delete mode 100644 rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClient.java delete mode 100644 rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClient.java delete mode 100644 rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiHttpPutClient.java delete mode 100644 rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/AaiClientConfigurations.java create mode 100644 rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/AaiClientConfigurations.java create mode 100644 rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/AbstractHttpClientTest.java create mode 100644 rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/TransactionsTest.java create mode 100644 rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/get/AaiGetServiceInstanceClientTest.java create mode 100644 rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/get/AaiHttpGetClientTest.java create mode 100644 rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/patch/AaiHttpPatchClientTest.java create mode 100644 rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/put/AaiHttpPutClientTest.java delete mode 100644 rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/AbstractHttpClientTest.java delete mode 100644 rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/TransactionsTest.java delete mode 100644 rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiGetServiceInstanceClientTest.java delete mode 100644 rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClientTest.java delete mode 100644 rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClientTest.java delete mode 100644 rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiHttpPutClientTest.java create mode 100644 rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/annotations/ExperimentalApi.java delete mode 100644 rest-services/common-dependency/pom.xml delete mode 100644 rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/annotations/ExperimentalApi.java delete mode 100644 rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/AaiModel.java delete mode 100644 rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/AaiServiceInstanceQueryModel.java delete mode 100644 rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/ClientModel.java delete mode 100644 rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/DmaapModel.java delete mode 100644 rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/JsonBodyBuilder.java delete mode 100644 rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/logging/GlobalDiagnosticContext.java delete mode 100644 rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/logging/MdcVariables.java delete mode 100644 rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/logging/RequestDiagnosticContext.java delete mode 100644 rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/uri/URI.java delete mode 100644 rest-services/common-dependency/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/model/logging/MdcVariablesTest.java delete mode 100644 rest-services/common-dependency/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/uri/URITest.java create mode 100644 rest-services/http-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/URI.java create mode 100644 rest-services/http-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/logging/GlobalDiagnosticContext.java create mode 100644 rest-services/http-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/logging/MdcVariables.java create mode 100644 rest-services/http-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/logging/RequestDiagnosticContext.java create mode 100644 rest-services/http-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/URITest.java create mode 100644 rest-services/http-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/logging/MdcVariablesTest.java diff --git a/pom.xml b/pom.xml index 03bbf998..ff95cd5e 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ org.onap.dcaegen2.services sdk - 1.3.1-SNAPSHOT + 1.3.2-SNAPSHOT dcaegen2-services-sdk Common SDK repo for all DCAE Services diff --git a/rest-services/aai-client/pom.xml b/rest-services/aai-client/pom.xml index 5413fd7c..6cea5af1 100644 --- a/rest-services/aai-client/pom.xml +++ b/rest-services/aai-client/pom.xml @@ -7,7 +7,7 @@ org.onap.dcaegen2.services.sdk dcaegen2-services-sdk-rest-services - 1.3.1-SNAPSHOT + 1.3.2-SNAPSHOT org.onap.dcaegen2.services.sdk.rest.services diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/AaiClientConfiguration.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/AaiClientConfiguration.java new file mode 100644 index 00000000..ce8c155c --- /dev/null +++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/AaiClientConfiguration.java @@ -0,0 +1,88 @@ +/* + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * 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.sdk.rest.services.aai.client.api; + +import java.io.Serializable; +import java.util.Map; +import org.immutables.gson.Gson; +import org.immutables.value.Value; + +@Value.Immutable(prehash = true) +@Value.Style(builder = "new") +@Gson.TypeAdapters +public abstract class AaiClientConfiguration implements Serializable { + + private static final String PNF_PATH = "/network/pnfs/pnf"; + private static final String SERVICE_INSTANCE_PATH = "/business/customers/customer/${customer}/service-subscriptions/service-subscription/${serviceType}/service-instances/service-instance/${serviceInstanceId}"; + + private static final long serialVersionUID = 1L; + + @Value.Parameter + @Value.Default + public String baseUrl() { + return ""; + } + + /** + * Please use baseUrl() instead + */ + @Deprecated + @Value.Default + public String pnfUrl() { + return baseUrl() + PNF_PATH; + } + + @Value.Parameter + public abstract String aaiUserName(); + + @Value.Parameter + public abstract String aaiUserPassword(); + + @Value.Parameter + public abstract Boolean aaiIgnoreSslCertificateErrors(); + + /** + * Please use baseUrl() instead + */ + @Deprecated + @Value.Default + public String aaiServiceInstancePath() { + return SERVICE_INSTANCE_PATH; + } + + @Value.Parameter + public abstract Map 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(); +} \ No newline at end of file diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/AaiHttpClient.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/AaiHttpClient.java new file mode 100644 index 00000000..442eea22 --- /dev/null +++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/AaiHttpClient.java @@ -0,0 +1,33 @@ +/* + * ============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.api; + +import reactor.core.publisher.Mono; + +import java.util.function.Function; + +public interface AaiHttpClient { + Mono getAaiResponse(T aaiModel); + + default AaiHttpClient map(final Function fn) { + return aaiModel -> AaiHttpClient.this.getAaiResponse(aaiModel).map(fn); + } +} diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/Request.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/Request.java new file mode 100644 index 00000000..3c0e55e6 --- /dev/null +++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/Request.java @@ -0,0 +1,28 @@ +/* + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * Copyright (C) 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.api; + +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpMethod; + +public interface Request { + HttpMethod method(); + String uri(); +} \ No newline at end of file diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/Transaction.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/Transaction.java new file mode 100644 index 00000000..a32132bf --- /dev/null +++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/Transaction.java @@ -0,0 +1,50 @@ +/* + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * Copyright (C) 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.api; + +import com.google.gson.JsonObject; +import com.google.gson.annotations.SerializedName; +import org.immutables.gson.Gson; +import org.immutables.value.Value; +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.api.Transactions; + +/** + * @see Transactions + */ +@Value.Immutable +@Gson.TypeAdapters(fieldNamingStrategy = true) +public interface Transaction { + + enum Action { + @SerializedName("put") PUT, + @SerializedName("patch") PATCH, + @SerializedName("delete") DELETE + } + + Action action(); + + String uri(); + + @Value.Default + default JsonObject body() { + return new JsonObject(); + } +} \ No newline at end of file diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/Transactions.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/Transactions.java new file mode 100644 index 00000000..e4058ef7 --- /dev/null +++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/Transactions.java @@ -0,0 +1,52 @@ +/* + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * Copyright (C) 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.api; + +import static org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpMethod.POST; + +import com.google.gson.annotations.SerializedName; +import java.util.List; +import org.immutables.gson.Gson; +import org.immutables.value.Value; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpMethod; + +/** + * @see Transaction + * @see AAI + * Bulk API + */ +@Value.Immutable +@Gson.TypeAdapters(fieldNamingStrategy = true) +public interface Transactions extends Request { + + String BULK_SINGLE_TRANSACTION = "/bulk/single-transaction"; + + @SerializedName("operations") + List operations(); + + default HttpMethod method() { + return POST; + } + + default String uri() { + return BULK_SINGLE_TRANSACTION; + } +} \ No newline at end of file diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/get/AaiGetServiceInstanceClient.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/get/AaiGetServiceInstanceClient.java new file mode 100644 index 00000000..dd53bfc2 --- /dev/null +++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/get/AaiGetServiceInstanceClient.java @@ -0,0 +1,73 @@ +/* + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * 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.sdk.rest.services.aai.client.api.get; + +import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.impl.AaiRequests.createAaiGetRequest; +import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.main.AaiHttpClientFactory.createRequestDiagnosticContext; + +import io.vavr.collection.HashMap; +import io.vavr.collection.Map; +import org.apache.commons.text.StringSubstitutor; +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.api.AaiClientConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.api.AaiHttpClient; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient; +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.model.AaiServiceInstanceQueryModel; +import org.onap.dcaegen2.services.sdk.rest.services.uri.URI; +import reactor.core.publisher.Mono; + +public class AaiGetServiceInstanceClient implements + AaiHttpClient { + + private static final String CUSTOMER = "customer"; + private static final String SERVICE_TYPE = "serviceType"; + private static final String SERVICE_INSTANCE_ID = "serviceInstanceId"; + + private final RxHttpClient httpClient; + private final AaiClientConfiguration configuration; + + public AaiGetServiceInstanceClient(final AaiClientConfiguration configuration, + final RxHttpClient httpClient) { + this.configuration = configuration; + this.httpClient = httpClient; + } + + @Override + public Mono getAaiResponse(AaiServiceInstanceQueryModel aaiModel) { + final Map mapping = HashMap.of( + CUSTOMER, aaiModel.customerId(), + SERVICE_TYPE, aaiModel.serviceType(), + SERVICE_INSTANCE_ID, aaiModel.serviceInstanceId()); + + final StringSubstitutor substitutor = new StringSubstitutor(mapping.toJavaMap()); + final String replaced = substitutor.replace(configuration.aaiServiceInstancePath()); + + final HttpRequest getRequest = createAaiGetRequest(getUri(replaced), + createRequestDiagnosticContext(), configuration.aaiHeaders()); + + return httpClient.call(getRequest); + } + + private String getUri(final String endpoint) { + return new URI.URIBuilder().path(configuration.baseUrl() + endpoint).build().toString(); + } +} diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/get/AaiHttpGetClient.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/get/AaiHttpGetClient.java new file mode 100644 index 00000000..6041a7c1 --- /dev/null +++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/get/AaiHttpGetClient.java @@ -0,0 +1,58 @@ +/* + * ============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.api.get; + +import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.impl.AaiRequests.createAaiGetRequest; +import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.main.AaiHttpClientFactory.createRequestDiagnosticContext; + +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.api.AaiClientConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.api.AaiHttpClient; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient; +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.model.AaiModel; +import org.onap.dcaegen2.services.sdk.rest.services.uri.URI; +import reactor.core.publisher.Mono; + +public final class AaiHttpGetClient implements AaiHttpClient { + + private final RxHttpClient httpClient; + private final AaiClientConfiguration configuration; + + + public AaiHttpGetClient(AaiClientConfiguration configuration, RxHttpClient httpClient) { + this.configuration = configuration; + this.httpClient = httpClient; + } + + @Override + public Mono getAaiResponse(AaiModel aaiModel) { + final HttpRequest getRequest = createAaiGetRequest(getUri(aaiModel.getCorrelationId()), + createRequestDiagnosticContext(), configuration.aaiHeaders()); + + return httpClient.call(getRequest); + } + + + private String getUri(String pnfName) { + return new URI.URIBuilder().path(configuration.pnfUrl() + "/" + pnfName).build().toString(); + } +} diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/patch/AaiHttpPatchClient.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/patch/AaiHttpPatchClient.java new file mode 100644 index 00000000..4979855e --- /dev/null +++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/patch/AaiHttpPatchClient.java @@ -0,0 +1,71 @@ +/*- + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * 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.sdk.rest.services.aai.client.api.patch; + +import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.impl.AaiRequests.createAaiPatchRequest; +import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.main.AaiHttpClientFactory.createRequestDiagnosticContext; + +import io.vavr.collection.HashMap; +import io.vavr.collection.Map; +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.api.AaiClientConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.api.AaiHttpClient; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient; +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.model.AaiModel; +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.model.JsonBodyBuilder; +import org.onap.dcaegen2.services.sdk.rest.services.uri.URI; +import reactor.core.publisher.Mono; + +public final class AaiHttpPatchClient implements AaiHttpClient { + + private final static Map CONTENT_TYPE = HashMap.of("Content-Type", "application/merge-patch+json"); + + private RxHttpClient httpClient; + private final AaiClientConfiguration configuration; + private final JsonBodyBuilder jsonBodyBuilder; + + + public AaiHttpPatchClient(final AaiClientConfiguration configuration, JsonBodyBuilder jsonBodyBuilder, + RxHttpClient httpClient) { + this.configuration = configuration; + this.jsonBodyBuilder = jsonBodyBuilder; + this.httpClient = httpClient; + } + + public Mono getAaiResponse(AaiModel aaiModel) { + final Map headers = CONTENT_TYPE.merge(HashMap.ofAll(configuration.aaiHeaders())); + + final HttpRequest aaiPatchRequest = createAaiPatchRequest( + getUri(aaiModel.getCorrelationId()), + createRequestDiagnosticContext(), + headers.toJavaMap(), + jsonBodyBuilder, + aaiModel); + + return httpClient.call(aaiPatchRequest); + } + + private String getUri(String pnfName) { + return new URI.URIBuilder() + .path(configuration.pnfUrl() + "/" + pnfName).build().toString(); + } +} diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/put/AaiHttpPutClient.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/put/AaiHttpPutClient.java new file mode 100644 index 00000000..a33370c2 --- /dev/null +++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/put/AaiHttpPutClient.java @@ -0,0 +1,57 @@ +/*- + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * Copyright (C) 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.api.put; + +import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.impl.AaiRequests.createAaiPutRequest; +import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.main.AaiHttpClientFactory.createRequestDiagnosticContext; + +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.api.AaiClientConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.api.AaiHttpClient; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient; +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.model.AaiModel; +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.model.JsonBodyBuilder; +import reactor.core.publisher.Mono; + +public class AaiHttpPutClient implements AaiHttpClient { + + private RxHttpClient httpClient; + private final AaiClientConfiguration configuration; + private final JsonBodyBuilder jsonBodyBuilder; + private final String uri; + + public AaiHttpPutClient(final AaiClientConfiguration configuration, JsonBodyBuilder jsonBodyBuilder, String uri, + RxHttpClient httpClient) { + this.configuration = configuration; + this.jsonBodyBuilder = jsonBodyBuilder; + this.uri = uri; + this.httpClient = httpClient; + } + + @Override + public Mono getAaiResponse(AaiModel aaiModel) { + final HttpRequest aaiPutRequest = createAaiPutRequest(uri, createRequestDiagnosticContext(), + configuration.aaiHeaders(), jsonBodyBuilder, aaiModel); + return httpClient.call(aaiPutRequest); + } +} diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/config/AaiClientConfiguration.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/config/AaiClientConfiguration.java deleted file mode 100644 index ff74f9b7..00000000 --- a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/config/AaiClientConfiguration.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * DCAEGEN2-SERVICES-SDK - * ================================================================================ - * 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.sdk.rest.services.aai.client.config; - -import java.io.Serializable; -import java.util.Map; -import org.immutables.gson.Gson; -import org.immutables.value.Value; - -@Value.Immutable(prehash = true) -@Value.Style(builder = "new") -@Gson.TypeAdapters -public abstract class AaiClientConfiguration implements Serializable { - - private static final String PNF_PATH = "/network/pnfs/pnf"; - private static final String SERVICE_INSTANCE_PATH = "/business/customers/customer/${customer}/service-subscriptions/service-subscription/${serviceType}/service-instances/service-instance/${serviceInstanceId}"; - - private static final long serialVersionUID = 1L; - - @Value.Parameter - @Value.Default - public String baseUrl() { - return ""; - } - - /** - * Please use baseUrl() instead - */ - @Deprecated - @Value.Default - public String pnfUrl() { - return baseUrl() + PNF_PATH; - } - - @Value.Parameter - public abstract String aaiUserName(); - - @Value.Parameter - public abstract String aaiUserPassword(); - - @Value.Parameter - public abstract Boolean aaiIgnoreSslCertificateErrors(); - - /** - * Please use baseUrl() instead - */ - @Deprecated - @Value.Default - public String aaiServiceInstancePath() { - return SERVICE_INSTANCE_PATH; - } - - @Value.Parameter - public abstract Map 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(); -} \ No newline at end of file diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/impl/AaiRequests.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/impl/AaiRequests.java new file mode 100644 index 00000000..d46873aa --- /dev/null +++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/impl/AaiRequests.java @@ -0,0 +1,84 @@ +/* + * ============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.impl; + +import io.vavr.collection.HashMap; +import java.util.Map; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpMethod; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.ImmutableHttpRequest; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RequestBody; +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.model.ClientModel; +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.model.JsonBodyBuilder; +import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext; + +public final class AaiRequests { + + private AaiRequests(){} + + public static HttpRequest createAaiPatchRequest(String url, + RequestDiagnosticContext context, + Map customHeaders, + JsonBodyBuilder jsonBodyBuilder, + ClientModel clientModel) { + + return buildAaiRequestWithBody(url, context, customHeaders, + jsonBodyBuilder, clientModel, HttpMethod.PATCH); + } + + public static HttpRequest createAaiPutRequest(String url, + RequestDiagnosticContext context, + Map customHeaders, + JsonBodyBuilder jsonBodyBuilder, + ClientModel clientModel) { + + return buildAaiRequestWithBody(url, context, customHeaders, + jsonBodyBuilder, clientModel, HttpMethod.PUT); + } + + private static HttpRequest buildAaiRequestWithBody(String url, + RequestDiagnosticContext context, + Map customHeaders, + JsonBodyBuilder jsonBodyBuilder, + ClientModel clientModel, + HttpMethod method) { + + String jsonBody = jsonBodyBuilder.createJsonBody(clientModel); + + return ImmutableHttpRequest.builder() + .url(url) + .customHeaders(HashMap.ofAll(customHeaders)) + .diagnosticContext(context) + .body(RequestBody.fromString(jsonBody)) + .method(method) + .build(); + } + + public static HttpRequest createAaiGetRequest(String url, + RequestDiagnosticContext context, + Map customHeaders) { + return ImmutableHttpRequest.builder() + .method(HttpMethod.GET) + .url(url) + .customHeaders(HashMap.ofAll(customHeaders)) + .diagnosticContext(context) + .build(); + } +} diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/main/AaiHttpClientFactory.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/main/AaiHttpClientFactory.java new file mode 100644 index 00000000..743fa44d --- /dev/null +++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/main/AaiHttpClientFactory.java @@ -0,0 +1,71 @@ +/* + * ============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.main; + +import java.nio.file.Paths; +import java.util.UUID; +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.api.AaiClientConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClientFactory; +import org.onap.dcaegen2.services.sdk.rest.services.model.logging.ImmutableRequestDiagnosticContext; +import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext; +import org.onap.dcaegen2.services.sdk.security.ssl.ImmutableSecurityKeys; +import org.onap.dcaegen2.services.sdk.security.ssl.ImmutableSecurityKeysStore; +import org.onap.dcaegen2.services.sdk.security.ssl.Passwords; +import org.onap.dcaegen2.services.sdk.security.ssl.SecurityKeys; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AaiHttpClientFactory { + + private static final Logger LOGGER = LoggerFactory.getLogger(AaiHttpClientFactory.class); + + private final AaiClientConfiguration configuration; + + public AaiHttpClientFactory(AaiClientConfiguration configuration) { + this.configuration = configuration; + } + + public RxHttpClient build() { + LOGGER.debug("Setting ssl context"); + + if (configuration.enableAaiCertAuth()) { + return RxHttpClientFactory.create(createSslKeys()); + } else { + return RxHttpClientFactory.createInsecure(); + } + } + + private SecurityKeys createSslKeys() { + return ImmutableSecurityKeys.builder() + .keyStore(ImmutableSecurityKeysStore.of(Paths.get(configuration.keyStorePath()))) + .keyStorePassword(Passwords.fromPath(Paths.get(configuration.keyStorePasswordPath()))) + .trustStore(ImmutableSecurityKeysStore.of(Paths.get(configuration.trustStorePath()))) + .trustStorePassword(Passwords.fromPath(Paths.get(configuration.trustStorePasswordPath()))) + .build(); + } + + public static RequestDiagnosticContext createRequestDiagnosticContext() { + return ImmutableRequestDiagnosticContext.builder() + .invocationId(UUID.randomUUID()).requestId(UUID.randomUUID()).build(); + } + +} diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/model/AaiModel.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/model/AaiModel.java new file mode 100644 index 00000000..eb96031e --- /dev/null +++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/model/AaiModel.java @@ -0,0 +1,27 @@ +/* + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * 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.sdk.rest.services.aai.client.model; + +@FunctionalInterface +public interface AaiModel extends ClientModel { + + String getCorrelationId(); +} diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/model/AaiServiceInstanceQueryModel.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/model/AaiServiceInstanceQueryModel.java new file mode 100644 index 00000000..a0135a99 --- /dev/null +++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/model/AaiServiceInstanceQueryModel.java @@ -0,0 +1,31 @@ +/* + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * 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.sdk.rest.services.aai.client.model; + +import org.immutables.value.Value; + +@Value.Style(stagedBuilder = true) +@Value.Immutable +public interface AaiServiceInstanceQueryModel extends ClientModel { + String customerId(); + String serviceType(); + String serviceInstanceId(); +} diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/model/ClientModel.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/model/ClientModel.java new file mode 100644 index 00000000..d4457c6f --- /dev/null +++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/model/ClientModel.java @@ -0,0 +1,24 @@ +/* + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * 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.sdk.rest.services.aai.client.model; + +public interface ClientModel { +} diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/model/DmaapModel.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/model/DmaapModel.java new file mode 100644 index 00000000..7cae908d --- /dev/null +++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/model/DmaapModel.java @@ -0,0 +1,24 @@ +/* + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * 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.sdk.rest.services.aai.client.model; + +public interface DmaapModel extends ClientModel { +} diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/model/JsonBodyBuilder.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/model/JsonBodyBuilder.java new file mode 100644 index 00000000..4b674aaf --- /dev/null +++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/model/JsonBodyBuilder.java @@ -0,0 +1,34 @@ +/* + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * 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.sdk.rest.services.aai.client.model; + +@FunctionalInterface +public interface JsonBodyBuilder { + + /** + * Method for serialization object by GSON. + * + * @param t - object which will be serialized + * @return string from serialization + */ + + String createJsonBody(T t); +} \ No newline at end of file diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiHttpClientFactory.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiHttpClientFactory.java deleted file mode 100644 index 4d0d952c..00000000 --- a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiHttpClientFactory.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * ============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; - -import java.nio.file.Paths; -import java.util.UUID; -import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClientFactory; -import org.onap.dcaegen2.services.sdk.rest.services.model.logging.ImmutableRequestDiagnosticContext; -import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext; -import org.onap.dcaegen2.services.sdk.security.ssl.ImmutableSecurityKeys; -import org.onap.dcaegen2.services.sdk.security.ssl.ImmutableSecurityKeysStore; -import org.onap.dcaegen2.services.sdk.security.ssl.Passwords; -import org.onap.dcaegen2.services.sdk.security.ssl.SecurityKeys; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class AaiHttpClientFactory { - - private static final Logger LOGGER = LoggerFactory.getLogger(AaiHttpClientFactory.class); - - private final AaiClientConfiguration configuration; - - public AaiHttpClientFactory(AaiClientConfiguration configuration) { - this.configuration = configuration; - } - - public RxHttpClient build() { - LOGGER.debug("Setting ssl context"); - - if (configuration.enableAaiCertAuth()) { - return RxHttpClientFactory.create(createSslKeys()); - } else { - return RxHttpClientFactory.createInsecure(); - } - } - - private SecurityKeys createSslKeys() { - return ImmutableSecurityKeys.builder() - .keyStore(ImmutableSecurityKeysStore.of(Paths.get(configuration.keyStorePath()))) - .keyStorePassword(Passwords.fromPath(Paths.get(configuration.keyStorePasswordPath()))) - .trustStore(ImmutableSecurityKeysStore.of(Paths.get(configuration.trustStorePath()))) - .trustStorePassword(Passwords.fromPath(Paths.get(configuration.trustStorePasswordPath()))) - .build(); - } - - public static RequestDiagnosticContext createRequestDiagnosticContext() { - return ImmutableRequestDiagnosticContext.builder() - .invocationId(UUID.randomUUID()).requestId(UUID.randomUUID()).build(); - } - -} diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/AaiHttpClient.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/AaiHttpClient.java deleted file mode 100644 index 317fab2c..00000000 --- a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/AaiHttpClient.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * ============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; - -import reactor.core.publisher.Mono; - -import java.util.function.Function; - -public interface AaiHttpClient { - Mono getAaiResponse(T aaiModel); - - default AaiHttpClient map(final Function fn) { - return aaiModel -> AaiHttpClient.this.getAaiResponse(aaiModel).map(fn); - } -} diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/AaiRequests.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/AaiRequests.java deleted file mode 100644 index 9a40dc57..00000000 --- a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/AaiRequests.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * ============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; - -import io.vavr.collection.HashMap; -import java.util.Map; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpMethod; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.ImmutableHttpRequest; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RequestBody; -import org.onap.dcaegen2.services.sdk.rest.services.model.ClientModel; -import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder; -import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext; - -public final class AaiRequests { - - private AaiRequests(){} - - public static HttpRequest createAaiPatchRequest(String url, - RequestDiagnosticContext context, - Map customHeaders, - JsonBodyBuilder jsonBodyBuilder, - ClientModel clientModel) { - - return buildAaiRequestWithBody(url, context, customHeaders, - jsonBodyBuilder, clientModel, HttpMethod.PATCH); - } - - public static HttpRequest createAaiPutRequest(String url, - RequestDiagnosticContext context, - Map customHeaders, - JsonBodyBuilder jsonBodyBuilder, - ClientModel clientModel) { - - return buildAaiRequestWithBody(url, context, customHeaders, - jsonBodyBuilder, clientModel, HttpMethod.PUT); - } - - private static HttpRequest buildAaiRequestWithBody(String url, - RequestDiagnosticContext context, - Map customHeaders, - JsonBodyBuilder jsonBodyBuilder, - ClientModel clientModel, - HttpMethod method) { - - String jsonBody = jsonBodyBuilder.createJsonBody(clientModel); - - return ImmutableHttpRequest.builder() - .url(url) - .customHeaders(HashMap.ofAll(customHeaders)) - .diagnosticContext(context) - .body(RequestBody.fromString(jsonBody)) - .method(method) - .build(); - } - - public static HttpRequest createAaiGetRequest(String url, - RequestDiagnosticContext context, - Map customHeaders) { - return ImmutableHttpRequest.builder() - .method(HttpMethod.GET) - .url(url) - .customHeaders(HashMap.ofAll(customHeaders)) - .diagnosticContext(context) - .build(); - } -} diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/Request.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/Request.java deleted file mode 100644 index cbe3b205..00000000 --- a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/Request.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * DCAEGEN2-SERVICES-SDK - * ================================================================================ - * Copyright (C) 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; - -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpMethod; - -public interface Request { - HttpMethod method(); - String uri(); -} \ No newline at end of file diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/Transaction.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/Transaction.java deleted file mode 100644 index 902282be..00000000 --- a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/Transaction.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * DCAEGEN2-SERVICES-SDK - * ================================================================================ - * Copyright (C) 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; - -import com.google.gson.JsonObject; -import com.google.gson.annotations.SerializedName; -import org.immutables.gson.Gson; -import org.immutables.value.Value; - -/** - * @see Transactions - */ -@Value.Immutable -@Gson.TypeAdapters(fieldNamingStrategy = true) -public interface Transaction { - - enum Action { - @SerializedName("put") PUT, - @SerializedName("patch") PATCH, - @SerializedName("delete") DELETE - } - - Action action(); - - String uri(); - - @Value.Default - default JsonObject body() { - return new JsonObject(); - } -} \ No newline at end of file diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/Transactions.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/Transactions.java deleted file mode 100644 index a21c5617..00000000 --- a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/Transactions.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * DCAEGEN2-SERVICES-SDK - * ================================================================================ - * Copyright (C) 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; - -import static org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpMethod.POST; - -import com.google.gson.annotations.SerializedName; -import java.util.List; -import org.immutables.gson.Gson; -import org.immutables.value.Value; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpMethod; - -/** - * @see Transaction - * @see AAI - * Bulk API - */ -@Value.Immutable -@Gson.TypeAdapters(fieldNamingStrategy = true) -public interface Transactions extends Request { - - String BULK_SINGLE_TRANSACTION = "/bulk/single-transaction"; - - @SerializedName("operations") - List operations(); - - default HttpMethod method() { - return POST; - } - - default String uri() { - return BULK_SINGLE_TRANSACTION; - } -} \ No newline at end of file diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiGetServiceInstanceClient.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiGetServiceInstanceClient.java deleted file mode 100644 index 6d623ff5..00000000 --- a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiGetServiceInstanceClient.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * DCAEGEN2-SERVICES-SDK - * ================================================================================ - * 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.sdk.rest.services.aai.client.service.http.get; - -import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AaiRequests.createAaiGetRequest; -import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.AaiHttpClientFactory.createRequestDiagnosticContext; - -import io.vavr.collection.HashMap; -import io.vavr.collection.Map; -import org.apache.commons.text.StringSubstitutor; -import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration; -import org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AaiHttpClient; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient; -import org.onap.dcaegen2.services.sdk.rest.services.model.AaiServiceInstanceQueryModel; -import org.onap.dcaegen2.services.sdk.rest.services.uri.URI; -import reactor.core.publisher.Mono; - -public class AaiGetServiceInstanceClient implements - AaiHttpClient { - - private static final String CUSTOMER = "customer"; - private static final String SERVICE_TYPE = "serviceType"; - private static final String SERVICE_INSTANCE_ID = "serviceInstanceId"; - - private final RxHttpClient httpClient; - private final AaiClientConfiguration configuration; - - public AaiGetServiceInstanceClient(final AaiClientConfiguration configuration, - final RxHttpClient httpClient) { - this.configuration = configuration; - this.httpClient = httpClient; - } - - @Override - public Mono getAaiResponse(AaiServiceInstanceQueryModel aaiModel) { - final Map mapping = HashMap.of( - CUSTOMER, aaiModel.customerId(), - SERVICE_TYPE, aaiModel.serviceType(), - SERVICE_INSTANCE_ID, aaiModel.serviceInstanceId()); - - final StringSubstitutor substitutor = new StringSubstitutor(mapping.toJavaMap()); - final String replaced = substitutor.replace(configuration.aaiServiceInstancePath()); - - final HttpRequest getRequest = createAaiGetRequest(getUri(replaced), - createRequestDiagnosticContext(), configuration.aaiHeaders()); - - return httpClient.call(getRequest); - } - - private String getUri(final String endpoint) { - return new URI.URIBuilder().path(configuration.baseUrl() + endpoint).build().toString(); - } -} diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClient.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClient.java deleted file mode 100644 index 8fa59543..00000000 --- a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClient.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * ============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.get; - -import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AaiRequests.createAaiGetRequest; -import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.AaiHttpClientFactory.createRequestDiagnosticContext; - -import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration; -import org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AaiHttpClient; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient; -import org.onap.dcaegen2.services.sdk.rest.services.model.AaiModel; -import org.onap.dcaegen2.services.sdk.rest.services.uri.URI; -import reactor.core.publisher.Mono; - -public final class AaiHttpGetClient implements AaiHttpClient { - - private final RxHttpClient httpClient; - private final AaiClientConfiguration configuration; - - - public AaiHttpGetClient(AaiClientConfiguration configuration, RxHttpClient httpClient) { - this.configuration = configuration; - this.httpClient = httpClient; - } - - @Override - public Mono getAaiResponse(AaiModel aaiModel) { - final HttpRequest getRequest = createAaiGetRequest(getUri(aaiModel.getCorrelationId()), - createRequestDiagnosticContext(), configuration.aaiHeaders()); - - return httpClient.call(getRequest); - } - - - private String getUri(String pnfName) { - return new URI.URIBuilder().path(configuration.pnfUrl() + "/" + pnfName).build().toString(); - } -} diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClient.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClient.java deleted file mode 100644 index 63e4e2b4..00000000 --- a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClient.java +++ /dev/null @@ -1,71 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * DCAEGEN2-SERVICES-SDK - * ================================================================================ - * 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.sdk.rest.services.aai.client.service.http.patch; - -import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AaiRequests.createAaiPatchRequest; -import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.AaiHttpClientFactory.createRequestDiagnosticContext; - -import io.vavr.collection.HashMap; -import io.vavr.collection.Map; -import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration; -import org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AaiHttpClient; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient; -import org.onap.dcaegen2.services.sdk.rest.services.model.AaiModel; -import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder; -import org.onap.dcaegen2.services.sdk.rest.services.uri.URI; -import reactor.core.publisher.Mono; - -public final class AaiHttpPatchClient implements AaiHttpClient { - - private final static Map CONTENT_TYPE = HashMap.of("Content-Type", "application/merge-patch+json"); - - private RxHttpClient httpClient; - private final AaiClientConfiguration configuration; - private final JsonBodyBuilder jsonBodyBuilder; - - - public AaiHttpPatchClient(final AaiClientConfiguration configuration, JsonBodyBuilder jsonBodyBuilder, - RxHttpClient httpClient) { - this.configuration = configuration; - this.jsonBodyBuilder = jsonBodyBuilder; - this.httpClient = httpClient; - } - - public Mono getAaiResponse(AaiModel aaiModel) { - final Map headers = CONTENT_TYPE.merge(HashMap.ofAll(configuration.aaiHeaders())); - - final HttpRequest aaiPatchRequest = createAaiPatchRequest( - getUri(aaiModel.getCorrelationId()), - createRequestDiagnosticContext(), - headers.toJavaMap(), - jsonBodyBuilder, - aaiModel); - - return httpClient.call(aaiPatchRequest); - } - - private String getUri(String pnfName) { - return new URI.URIBuilder() - .path(configuration.pnfUrl() + "/" + pnfName).build().toString(); - } -} diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiHttpPutClient.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiHttpPutClient.java deleted file mode 100644 index 821d07ef..00000000 --- a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiHttpPutClient.java +++ /dev/null @@ -1,57 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * DCAEGEN2-SERVICES-SDK - * ================================================================================ - * Copyright (C) 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 static org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AaiRequests.createAaiPutRequest; -import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.AaiHttpClientFactory.createRequestDiagnosticContext; - -import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration; -import org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AaiHttpClient; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient; -import org.onap.dcaegen2.services.sdk.rest.services.model.AaiModel; -import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder; -import reactor.core.publisher.Mono; - -public class AaiHttpPutClient implements AaiHttpClient { - - private RxHttpClient httpClient; - private final AaiClientConfiguration configuration; - private final JsonBodyBuilder jsonBodyBuilder; - private final String uri; - - public AaiHttpPutClient(final AaiClientConfiguration configuration, JsonBodyBuilder jsonBodyBuilder, String uri, - RxHttpClient httpClient) { - this.configuration = configuration; - this.jsonBodyBuilder = jsonBodyBuilder; - this.uri = uri; - this.httpClient = httpClient; - } - - @Override - public Mono getAaiResponse(AaiModel aaiModel) { - final HttpRequest aaiPutRequest = createAaiPutRequest(uri, createRequestDiagnosticContext(), - configuration.aaiHeaders(), jsonBodyBuilder, aaiModel); - return httpClient.call(aaiPutRequest); - } -} diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/AaiClientConfigurations.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/AaiClientConfigurations.java deleted file mode 100644 index 8e27b2f4..00000000 --- a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/AaiClientConfigurations.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * DCAEGEN2-SERVICES-SDK - * ================================================================================ - * Copyright (C) 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; - -import java.util.HashMap; -import java.util.Map; -import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration; -import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.ImmutableAaiClientConfiguration; - -public final class AaiClientConfigurations { - - private AaiClientConfigurations() { - } - - public static AaiClientConfiguration secureConfiguration() { - return secureConfiguration(new HashMap<>()); - } - - public static AaiClientConfiguration secureConfiguration(Map headers) { - return validConfiguration(headers, true); - } - - public static AaiClientConfiguration insecureConfiguration() { - return validConfiguration(new HashMap<>(), false); - } - - private static AaiClientConfiguration validConfiguration(Map headers, boolean secure) { - return new ImmutableAaiClientConfiguration.Builder() - .baseUrl("https://aai.onap.svc.cluster.local:8443/aai/v12") - .aaiUserName("sample-username") - .aaiUserPassword("sample-password") - .aaiIgnoreSslCertificateErrors(false) - .trustStorePath("/trust.pkcs12") - .trustStorePasswordPath("/trust.pass") - .keyStorePath("/server.pkcs12") - .keyStorePasswordPath("/server.pass") - .enableAaiCertAuth(secure) - .aaiHeaders(headers) - .aaiServiceInstancePath("/business/customers/customer/${customer}/service-subscriptions/service-subscription/${serviceType}/service-instances/service-instance/${serviceInstanceId}") - .build(); - } -} \ No newline at end of file diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/AaiClientConfigurations.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/AaiClientConfigurations.java new file mode 100644 index 00000000..096f3fca --- /dev/null +++ b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/AaiClientConfigurations.java @@ -0,0 +1,59 @@ +/* + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * Copyright (C) 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.api; + +import java.util.HashMap; +import java.util.Map; +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.api.AaiClientConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.api.ImmutableAaiClientConfiguration; + +public final class AaiClientConfigurations { + + private AaiClientConfigurations() { + } + + public static AaiClientConfiguration secureConfiguration() { + return secureConfiguration(new HashMap<>()); + } + + public static AaiClientConfiguration secureConfiguration(Map headers) { + return validConfiguration(headers, true); + } + + public static AaiClientConfiguration insecureConfiguration() { + return validConfiguration(new HashMap<>(), false); + } + + private static AaiClientConfiguration validConfiguration(Map headers, boolean secure) { + return new ImmutableAaiClientConfiguration.Builder() + .baseUrl("https://aai.onap.svc.cluster.local:8443/aai/v12") + .aaiUserName("sample-username") + .aaiUserPassword("sample-password") + .aaiIgnoreSslCertificateErrors(false) + .trustStorePath("/trust.pkcs12") + .trustStorePasswordPath("/trust.pass") + .keyStorePath("/server.pkcs12") + .keyStorePasswordPath("/server.pass") + .enableAaiCertAuth(secure) + .aaiHeaders(headers) + .aaiServiceInstancePath("/business/customers/customer/${customer}/service-subscriptions/service-subscription/${serviceType}/service-instances/service-instance/${serviceInstanceId}") + .build(); + } +} \ No newline at end of file diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/AbstractHttpClientTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/AbstractHttpClientTest.java new file mode 100644 index 00000000..9fd46edc --- /dev/null +++ b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/AbstractHttpClientTest.java @@ -0,0 +1,42 @@ +/* + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * Copyright (C) 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.api; + +import static org.mockito.Mockito.mock; + +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.api.AaiClientConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient; +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.model.AaiModel; +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.model.JsonBodyBuilder; +import org.onap.dcaegen2.services.sdk.rest.services.uri.URI; + +public class AbstractHttpClientTest { + + protected final AaiModel aaiModel = () -> "test-id"; + protected final RxHttpClient httpClient = mock(RxHttpClient.class); + protected final JsonBodyBuilder bodyBuilder = mock(JsonBodyBuilder.class); + protected final HttpResponse response = mock(HttpResponse.class); + + + protected String constructAaiUri(AaiClientConfiguration configuration, String pnfName) { + return new URI.URIBuilder().path(configuration.pnfUrl() + "/" + pnfName).build().toString(); + } +} diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/TransactionsTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/TransactionsTest.java new file mode 100644 index 00000000..de8ca370 --- /dev/null +++ b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/TransactionsTest.java @@ -0,0 +1,67 @@ +/* + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * Copyright (C) 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.api; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.api.Transaction.Action.PUT; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Objects; +import java.util.stream.Collectors; +import org.junit.jupiter.api.Test; + +class TransactionsTest { + + @Test + void shouldBuildTransactionRequest() throws IOException { + // given + JsonObject payload = new JsonObject(); + payload.addProperty("link-name", "foo"); + + ImmutableTransactions transactions = ImmutableTransactions + .builder() + .addOperations(ImmutableTransaction.builder() + .action(PUT) + .uri("/network/logical-links/logical-link/foo") + .body(payload) + .build()) + .build(); + + // when + Gson gson = new Gson().newBuilder().create(); + String transaction = gson.toJson(transactions); + + // then + String expectedJson = getJsonFromFile("transaction.json"); + assertThat(transaction).isEqualToIgnoringWhitespace(expectedJson); + } + + private String getJsonFromFile(String file) throws IOException { + try (BufferedReader br = new BufferedReader(new InputStreamReader( + Objects.requireNonNull(TransactionsTest.class.getClassLoader().getResourceAsStream(file))))) { + return br.lines().collect(Collectors.joining(System.lineSeparator())); + } + } +} \ No newline at end of file diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/get/AaiGetServiceInstanceClientTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/get/AaiGetServiceInstanceClientTest.java new file mode 100644 index 00000000..142bf593 --- /dev/null +++ b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/get/AaiGetServiceInstanceClientTest.java @@ -0,0 +1,70 @@ +/* + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * Copyright (C) 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.api.get; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.api.AaiClientConfigurations.secureConfiguration; + +import io.vavr.collection.HashMap; +import io.vavr.collection.Map; +import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.api.AbstractHttpClientTest; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest; +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.model.AaiServiceInstanceQueryModel; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; + +class AaiGetServiceInstanceClientTest extends AbstractHttpClientTest { + + public static final String SERVICE_INSTANCE_PATH = "https://aai.onap.svc.cluster.local:8443/aai/v12/business/customers/customer/Demonstration/" + + "service-subscriptions/service-subscription/VCPE/service-instances/service-instance/df018f76-7fc8-46ab-8444-7d67e1efc284"; + + @Test + void getAaiResponse_shouldCallGetMethod_withGivenAaiHeaders() { + + // given + AaiServiceInstanceQueryModel model = mock(AaiServiceInstanceQueryModel.class); + Map headers = HashMap.of("sample-key", "sample-value"); + AaiGetServiceInstanceClient cut = new AaiGetServiceInstanceClient(secureConfiguration(headers.toJavaMap()), + httpClient); + + given(model.customerId()).willReturn("Demonstration"); + given(model.serviceInstanceId()).willReturn("df018f76-7fc8-46ab-8444-7d67e1efc284"); + given(model.serviceType()).willReturn("VCPE"); + + given(httpClient.call(any(HttpRequest.class))) + .willReturn(Mono.just(response)); + + // when + StepVerifier + .create(cut.getAaiResponse(model)) + .expectNext(response) + .verifyComplete(); + + //then + verify(httpClient) + .call(argThat(httpRequest -> httpRequest.customHeaders().equals(headers) && + httpRequest.url().equals(SERVICE_INSTANCE_PATH))); + } +} diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/get/AaiHttpGetClientTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/get/AaiHttpGetClientTest.java new file mode 100644 index 00000000..49fbf8c5 --- /dev/null +++ b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/get/AaiHttpGetClientTest.java @@ -0,0 +1,81 @@ +/* + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * Copyright (C) 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.api.get; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.verify; +import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.api.AaiClientConfigurations.secureConfiguration; + +import io.vavr.collection.HashMap; +import io.vavr.collection.Map; +import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.api.AaiClientConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.api.AbstractHttpClientTest; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; + +class AaiHttpGetClientTest extends AbstractHttpClientTest { + + @Test + void getAaiResponse_shouldCallGetMethod_withGivenAaiHeaders() { + + // given + Map headers = HashMap.of("sample-key", "sample-value"); + AaiHttpGetClient cut = new AaiHttpGetClient(secureConfiguration(headers.toJavaMap()), httpClient); + + given(httpClient.call(any(HttpRequest.class))) + .willReturn(Mono.just(response)); + + // when + StepVerifier + .create(cut.getAaiResponse(aaiModel)) + .expectNext(response) + .verifyComplete(); + + //then + verify(httpClient) + .call(argThat(httpRequest -> httpRequest.customHeaders().equals(headers))); + } + + @Test + void getAaiResponse_shouldCallGetMethod_withProperUri() { + + // given + AaiClientConfiguration configuration = secureConfiguration(); + String uri = constructAaiUri(configuration, aaiModel.getCorrelationId()); + AaiHttpGetClient cut = new AaiHttpGetClient(configuration, httpClient); + + given(httpClient.call(any(HttpRequest.class))) + .willReturn(Mono.just(response)); + + // when + StepVerifier + .create(cut.getAaiResponse(aaiModel)) + .expectNext(response) + .verifyComplete(); + + // then + verify(httpClient) + .call(argThat(httpRequest -> httpRequest.url().equals(uri))); + } +} diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/patch/AaiHttpPatchClientTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/patch/AaiHttpPatchClientTest.java new file mode 100644 index 00000000..7d28ec1e --- /dev/null +++ b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/patch/AaiHttpPatchClientTest.java @@ -0,0 +1,94 @@ +/* + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * Copyright (C) 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.api.patch; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.verify; +import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.api.AaiClientConfigurations.secureConfiguration; + +import io.vavr.collection.HashMap; +import io.vavr.collection.Map; +import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.api.AaiClientConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.api.AbstractHttpClientTest; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; + +class AaiHttpPatchClientTest extends AbstractHttpClientTest { + + private final Map DEFAULT_PATCH_HEADERS = + HashMap.of("Content-Type", "application/merge-patch+json"); + + @Test + void getAaiResponse_shouldCallPatchMethod_withGivenHeaders_combinedWithContentType() { + + // given + Map headers = HashMap.of("sample-key", "sample-value"); + Map expectedHeaders = DEFAULT_PATCH_HEADERS.merge(headers); + + AaiHttpPatchClient cut = + new AaiHttpPatchClient(secureConfiguration(headers.toJavaMap()), bodyBuilder, httpClient); + + given(bodyBuilder.createJsonBody(eq(aaiModel))) + .willReturn("test-body"); + + given(httpClient.call(any(HttpRequest.class))) + .willReturn(Mono.just(response)); + + // when + StepVerifier + .create(cut.getAaiResponse(aaiModel)) + .expectNext(response) + .verifyComplete(); + + // then + verify(httpClient) + .call(argThat(httpRequest -> httpRequest.customHeaders().equals(expectedHeaders))); + } + + @Test + void getAaiResponse_shouldCallPatchMethod_withProperUri() { + + // given + AaiClientConfiguration configuration = secureConfiguration(); + String uri = constructAaiUri(configuration, aaiModel.getCorrelationId()); + AaiHttpPatchClient cut = new AaiHttpPatchClient(configuration, bodyBuilder, httpClient); + + given(bodyBuilder.createJsonBody(eq(aaiModel))) + .willReturn("test-body"); + + given(httpClient.call(any(HttpRequest.class))) + .willReturn(Mono.just(response)); + + // when + StepVerifier + .create(cut.getAaiResponse(aaiModel)) + .expectNext(response) + .verifyComplete(); + + // then + verify(httpClient) + .call(argThat(httpRequest -> httpRequest.url().equals(uri))); + } +} diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/put/AaiHttpPutClientTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/put/AaiHttpPutClientTest.java new file mode 100644 index 00000000..f50c53c1 --- /dev/null +++ b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/api/put/AaiHttpPutClientTest.java @@ -0,0 +1,80 @@ +/* + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * Copyright (C) 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.api.put; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.verify; +import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.api.AaiClientConfigurations.secureConfiguration; + +import io.vavr.collection.HashMap; +import io.vavr.collection.Map; +import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.api.AbstractHttpClientTest; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; + +class AaiHttpPutClientTest extends AbstractHttpClientTest { + + @Test + void getAaiResponse_shouldCallPutMethod_withGivenAaiHeaders() { + Map headers = HashMap.of("sample-key", "sample-value"); + AaiHttpPutClient cut = new AaiHttpPutClient(secureConfiguration(headers.toJavaMap()), bodyBuilder, "", + httpClient); + + given(bodyBuilder.createJsonBody(eq(aaiModel))) + .willReturn("test-body"); + + given(httpClient.call(any(HttpRequest.class))) + .willReturn(Mono.just(response)); + + StepVerifier + .create(cut.getAaiResponse(aaiModel)) + .expectNext(response) + .verifyComplete(); + + verify(httpClient) + .call(argThat(httpRequest -> httpRequest.customHeaders().equals(headers))); + } + + @Test + void getAaiResponse_shouldCallPutMethod_withProperUri() { + String uri = "test-uri"; + AaiHttpPutClient cut = new AaiHttpPutClient(secureConfiguration(), bodyBuilder, uri, httpClient); + + given(bodyBuilder.createJsonBody(eq(aaiModel))) + .willReturn("test-body"); + + given(httpClient.call(any(HttpRequest.class))) + .willReturn(Mono.just(response)); + + StepVerifier + .create(cut.getAaiResponse(aaiModel)) + .expectNext(response) + .verifyComplete(); + + verify(httpClient) + .call(argThat(httpRequest -> httpRequest.url().equals(uri))); + + } +} diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/AbstractHttpClientTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/AbstractHttpClientTest.java deleted file mode 100644 index 097c5d3a..00000000 --- a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/AbstractHttpClientTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * DCAEGEN2-SERVICES-SDK - * ================================================================================ - * Copyright (C) 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; - -import static org.mockito.Mockito.mock; - -import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient; -import org.onap.dcaegen2.services.sdk.rest.services.model.AaiModel; -import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder; -import org.onap.dcaegen2.services.sdk.rest.services.uri.URI; - -public class AbstractHttpClientTest { - - protected final AaiModel aaiModel = () -> "test-id"; - protected final RxHttpClient httpClient = mock(RxHttpClient.class); - protected final JsonBodyBuilder bodyBuilder = mock(JsonBodyBuilder.class); - protected final HttpResponse response = mock(HttpResponse.class); - - - protected String constructAaiUri(AaiClientConfiguration configuration, String pnfName) { - return new URI.URIBuilder().path(configuration.pnfUrl() + "/" + pnfName).build().toString(); - } -} diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/TransactionsTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/TransactionsTest.java deleted file mode 100644 index 70d3653b..00000000 --- a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/TransactionsTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * DCAEGEN2-SERVICES-SDK - * ================================================================================ - * Copyright (C) 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; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.Transaction.Action.PUT; - -import com.google.gson.Gson; -import com.google.gson.JsonObject; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.Objects; -import java.util.stream.Collectors; -import org.junit.jupiter.api.Test; - -class TransactionsTest { - - @Test - void shouldBuildTransactionRequest() throws IOException { - // given - JsonObject payload = new JsonObject(); - payload.addProperty("link-name", "foo"); - - ImmutableTransactions transactions = ImmutableTransactions - .builder() - .addOperations(ImmutableTransaction.builder() - .action(PUT) - .uri("/network/logical-links/logical-link/foo") - .body(payload) - .build()) - .build(); - - // when - Gson gson = new Gson().newBuilder().create(); - String transaction = gson.toJson(transactions); - - // then - String expectedJson = getJsonFromFile("transaction.json"); - assertThat(transaction).isEqualToIgnoringWhitespace(expectedJson); - } - - private String getJsonFromFile(String file) throws IOException { - try (BufferedReader br = new BufferedReader(new InputStreamReader( - Objects.requireNonNull(TransactionsTest.class.getClassLoader().getResourceAsStream(file))))) { - return br.lines().collect(Collectors.joining(System.lineSeparator())); - } - } -} \ No newline at end of file diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiGetServiceInstanceClientTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiGetServiceInstanceClientTest.java deleted file mode 100644 index ae26404e..00000000 --- a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiGetServiceInstanceClientTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * DCAEGEN2-SERVICES-SDK - * ================================================================================ - * Copyright (C) 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.get; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.argThat; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.AaiClientConfigurations.secureConfiguration; - -import io.vavr.collection.HashMap; -import io.vavr.collection.Map; -import org.junit.jupiter.api.Test; -import org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AbstractHttpClientTest; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest; -import org.onap.dcaegen2.services.sdk.rest.services.model.AaiServiceInstanceQueryModel; -import reactor.core.publisher.Mono; -import reactor.test.StepVerifier; - -class AaiGetServiceInstanceClientTest extends AbstractHttpClientTest { - - public static final String SERVICE_INSTANCE_PATH = "https://aai.onap.svc.cluster.local:8443/aai/v12/business/customers/customer/Demonstration/" - + "service-subscriptions/service-subscription/VCPE/service-instances/service-instance/df018f76-7fc8-46ab-8444-7d67e1efc284"; - - @Test - void getAaiResponse_shouldCallGetMethod_withGivenAaiHeaders() { - - // given - AaiServiceInstanceQueryModel model = mock(AaiServiceInstanceQueryModel.class); - Map headers = HashMap.of("sample-key", "sample-value"); - AaiGetServiceInstanceClient cut = new AaiGetServiceInstanceClient(secureConfiguration(headers.toJavaMap()), - httpClient); - - given(model.customerId()).willReturn("Demonstration"); - given(model.serviceInstanceId()).willReturn("df018f76-7fc8-46ab-8444-7d67e1efc284"); - given(model.serviceType()).willReturn("VCPE"); - - given(httpClient.call(any(HttpRequest.class))) - .willReturn(Mono.just(response)); - - // when - StepVerifier - .create(cut.getAaiResponse(model)) - .expectNext(response) - .verifyComplete(); - - //then - verify(httpClient) - .call(argThat(httpRequest -> httpRequest.customHeaders().equals(headers) && - httpRequest.url().equals(SERVICE_INSTANCE_PATH))); - } -} diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClientTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClientTest.java deleted file mode 100644 index 758ef601..00000000 --- a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClientTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * DCAEGEN2-SERVICES-SDK - * ================================================================================ - * Copyright (C) 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.get; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.argThat; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.verify; -import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.AaiClientConfigurations.secureConfiguration; - -import io.vavr.collection.HashMap; -import io.vavr.collection.Map; -import org.junit.jupiter.api.Test; -import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration; -import org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AbstractHttpClientTest; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest; -import reactor.core.publisher.Mono; -import reactor.test.StepVerifier; - -class AaiHttpGetClientTest extends AbstractHttpClientTest { - - @Test - void getAaiResponse_shouldCallGetMethod_withGivenAaiHeaders() { - - // given - Map headers = HashMap.of("sample-key", "sample-value"); - AaiHttpGetClient cut = new AaiHttpGetClient(secureConfiguration(headers.toJavaMap()), httpClient); - - given(httpClient.call(any(HttpRequest.class))) - .willReturn(Mono.just(response)); - - // when - StepVerifier - .create(cut.getAaiResponse(aaiModel)) - .expectNext(response) - .verifyComplete(); - - //then - verify(httpClient) - .call(argThat(httpRequest -> httpRequest.customHeaders().equals(headers))); - } - - @Test - void getAaiResponse_shouldCallGetMethod_withProperUri() { - - // given - AaiClientConfiguration configuration = secureConfiguration(); - String uri = constructAaiUri(configuration, aaiModel.getCorrelationId()); - AaiHttpGetClient cut = new AaiHttpGetClient(configuration, httpClient); - - given(httpClient.call(any(HttpRequest.class))) - .willReturn(Mono.just(response)); - - // when - StepVerifier - .create(cut.getAaiResponse(aaiModel)) - .expectNext(response) - .verifyComplete(); - - // then - verify(httpClient) - .call(argThat(httpRequest -> httpRequest.url().equals(uri))); - } -} diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClientTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClientTest.java deleted file mode 100644 index 2def498c..00000000 --- a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClientTest.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * DCAEGEN2-SERVICES-SDK - * ================================================================================ - * Copyright (C) 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.patch; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyMap; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.argThat; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.verify; -import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.AaiClientConfigurations.secureConfiguration; - -import io.vavr.collection.HashMap; -import io.vavr.collection.Map; -import org.junit.jupiter.api.Test; -import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration; -import org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AbstractHttpClientTest; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest; -import org.onap.dcaegen2.services.sdk.rest.services.model.AaiModel; -import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder; -import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext; -import reactor.core.publisher.Mono; -import reactor.test.StepVerifier; - -class AaiHttpPatchClientTest extends AbstractHttpClientTest { - - private final Map DEFAULT_PATCH_HEADERS = - HashMap.of("Content-Type", "application/merge-patch+json"); - - @Test - void getAaiResponse_shouldCallPatchMethod_withGivenHeaders_combinedWithContentType() { - - // given - Map headers = HashMap.of("sample-key", "sample-value"); - Map expectedHeaders = DEFAULT_PATCH_HEADERS.merge(headers); - - AaiHttpPatchClient cut = - new AaiHttpPatchClient(secureConfiguration(headers.toJavaMap()), bodyBuilder, httpClient); - - given(bodyBuilder.createJsonBody(eq(aaiModel))) - .willReturn("test-body"); - - given(httpClient.call(any(HttpRequest.class))) - .willReturn(Mono.just(response)); - - // when - StepVerifier - .create(cut.getAaiResponse(aaiModel)) - .expectNext(response) - .verifyComplete(); - - // then - verify(httpClient) - .call(argThat(httpRequest -> httpRequest.customHeaders().equals(expectedHeaders))); - } - - @Test - void getAaiResponse_shouldCallPatchMethod_withProperUri() { - - // given - AaiClientConfiguration configuration = secureConfiguration(); - String uri = constructAaiUri(configuration, aaiModel.getCorrelationId()); - AaiHttpPatchClient cut = new AaiHttpPatchClient(configuration, bodyBuilder, httpClient); - - given(bodyBuilder.createJsonBody(eq(aaiModel))) - .willReturn("test-body"); - - given(httpClient.call(any(HttpRequest.class))) - .willReturn(Mono.just(response)); - - // when - StepVerifier - .create(cut.getAaiResponse(aaiModel)) - .expectNext(response) - .verifyComplete(); - - // then - verify(httpClient) - .call(argThat(httpRequest -> httpRequest.url().equals(uri))); - } -} diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiHttpPutClientTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiHttpPutClientTest.java deleted file mode 100644 index d14eca18..00000000 --- a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiHttpPutClientTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * DCAEGEN2-SERVICES-SDK - * ================================================================================ - * Copyright (C) 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 static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.argThat; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.verify; -import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.AaiClientConfigurations.secureConfiguration; - -import io.vavr.collection.HashMap; -import io.vavr.collection.Map; -import org.junit.jupiter.api.Test; -import org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AbstractHttpClientTest; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest; -import reactor.core.publisher.Mono; -import reactor.test.StepVerifier; - -class AaiHttpPutClientTest extends AbstractHttpClientTest { - - @Test - void getAaiResponse_shouldCallPutMethod_withGivenAaiHeaders() { - Map headers = HashMap.of("sample-key", "sample-value"); - AaiHttpPutClient cut = new AaiHttpPutClient(secureConfiguration(headers.toJavaMap()), bodyBuilder, "", - httpClient); - - given(bodyBuilder.createJsonBody(eq(aaiModel))) - .willReturn("test-body"); - - given(httpClient.call(any(HttpRequest.class))) - .willReturn(Mono.just(response)); - - StepVerifier - .create(cut.getAaiResponse(aaiModel)) - .expectNext(response) - .verifyComplete(); - - verify(httpClient) - .call(argThat(httpRequest -> httpRequest.customHeaders().equals(headers))); - } - - @Test - void getAaiResponse_shouldCallPutMethod_withProperUri() { - String uri = "test-uri"; - AaiHttpPutClient cut = new AaiHttpPutClient(secureConfiguration(), bodyBuilder, uri, httpClient); - - given(bodyBuilder.createJsonBody(eq(aaiModel))) - .willReturn("test-body"); - - given(httpClient.call(any(HttpRequest.class))) - .willReturn(Mono.just(response)); - - StepVerifier - .create(cut.getAaiResponse(aaiModel)) - .expectNext(response) - .verifyComplete(); - - verify(httpClient) - .call(argThat(httpRequest -> httpRequest.url().equals(uri))); - - } -} diff --git a/rest-services/cbs-client/pom.xml b/rest-services/cbs-client/pom.xml index c8aa2ad2..8c081417 100644 --- a/rest-services/cbs-client/pom.xml +++ b/rest-services/cbs-client/pom.xml @@ -7,7 +7,7 @@ org.onap.dcaegen2.services.sdk dcaegen2-services-sdk-rest-services - 1.3.1-SNAPSHOT + 1.3.2-SNAPSHOT org.onap.dcaegen2.services.sdk.rest.services diff --git a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/annotations/ExperimentalApi.java b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/annotations/ExperimentalApi.java new file mode 100644 index 00000000..9b577688 --- /dev/null +++ b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/annotations/ExperimentalApi.java @@ -0,0 +1,41 @@ +/* + * ============LICENSE_START==================================== + * DCAEGEN2-SERVICES-SDK + * ========================================================= + * Copyright (C) 2019 Nokia. 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.annotations; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotate experimental API. + * + * @author Piotr Jaszczyk + * @since 1.1.2 + */ +@Documented +@Target({ElementType.METHOD, ElementType.TYPE, ElementType.PACKAGE}) +@Retention(RetentionPolicy.SOURCE) +public @interface ExperimentalApi { + String value() default "Experimental API. Might be deleted or changed in the future SDK versions."; + String expectedInVersion() default "unknown"; +} diff --git a/rest-services/common-dependency/pom.xml b/rest-services/common-dependency/pom.xml deleted file mode 100644 index 16f6a09d..00000000 --- a/rest-services/common-dependency/pom.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - - 4.0.0 - - - org.onap.dcaegen2.services.sdk - dcaegen2-services-sdk-rest-services - 1.3.1-SNAPSHOT - - - org.onap.dcaegen2.services.sdk.rest.services - common-dependency - - dcaegen2-services-sdk-rest-services-common-dependency - Common functionality in the project - jar - - - - io.projectreactor.netty - reactor-netty - - - org.immutables - gson - - - org.immutables - value - - - io.vavr - vavr - - - org.jetbrains - annotations - - - ch.qos.logback - logback-classic - - - org.slf4j - jul-to-slf4j - - - org.slf4j - log4j-over-slf4j - - - org.junit.jupiter - junit-jupiter-engine - test - - - org.mockito - mockito-core - test - - - org.assertj - assertj-core - - - io.projectreactor - reactor-test - test - - - \ No newline at end of file diff --git a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/annotations/ExperimentalApi.java b/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/annotations/ExperimentalApi.java deleted file mode 100644 index 9b577688..00000000 --- a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/annotations/ExperimentalApi.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * ============LICENSE_START==================================== - * DCAEGEN2-SERVICES-SDK - * ========================================================= - * Copyright (C) 2019 Nokia. 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.annotations; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotate experimental API. - * - * @author Piotr Jaszczyk - * @since 1.1.2 - */ -@Documented -@Target({ElementType.METHOD, ElementType.TYPE, ElementType.PACKAGE}) -@Retention(RetentionPolicy.SOURCE) -public @interface ExperimentalApi { - String value() default "Experimental API. Might be deleted or changed in the future SDK versions."; - String expectedInVersion() default "unknown"; -} diff --git a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/AaiModel.java b/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/AaiModel.java deleted file mode 100644 index 781aabee..00000000 --- a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/AaiModel.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * DCAEGEN2-SERVICES-SDK - * ================================================================================ - * 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.sdk.rest.services.model; - -@FunctionalInterface -public interface AaiModel extends ClientModel { - - String getCorrelationId(); -} diff --git a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/AaiServiceInstanceQueryModel.java b/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/AaiServiceInstanceQueryModel.java deleted file mode 100644 index bb4493e8..00000000 --- a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/AaiServiceInstanceQueryModel.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * DCAEGEN2-SERVICES-SDK - * ================================================================================ - * 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.sdk.rest.services.model; - -import org.immutables.value.Value; - -@Value.Style(stagedBuilder = true) -@Value.Immutable -public interface AaiServiceInstanceQueryModel extends ClientModel { - String customerId(); - String serviceType(); - String serviceInstanceId(); -} diff --git a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/ClientModel.java b/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/ClientModel.java deleted file mode 100644 index f94985be..00000000 --- a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/ClientModel.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * DCAEGEN2-SERVICES-SDK - * ================================================================================ - * 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.sdk.rest.services.model; - -public interface ClientModel { -} diff --git a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/DmaapModel.java b/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/DmaapModel.java deleted file mode 100644 index 6c5731d8..00000000 --- a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/DmaapModel.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * DCAEGEN2-SERVICES-SDK - * ================================================================================ - * 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.sdk.rest.services.model; - -public interface DmaapModel extends ClientModel { -} diff --git a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/JsonBodyBuilder.java b/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/JsonBodyBuilder.java deleted file mode 100644 index e33f914f..00000000 --- a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/JsonBodyBuilder.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * DCAEGEN2-SERVICES-SDK - * ================================================================================ - * 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.sdk.rest.services.model; - -@FunctionalInterface -public interface JsonBodyBuilder { - - /** - * Method for serialization object by GSON. - * - * @param t - object which will be serialized - * @return string from serialization - */ - - String createJsonBody(T t); -} \ No newline at end of file diff --git a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/logging/GlobalDiagnosticContext.java b/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/logging/GlobalDiagnosticContext.java deleted file mode 100644 index db4a0fd6..00000000 --- a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/logging/GlobalDiagnosticContext.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * ============LICENSE_START==================================== - * DCAEGEN2-SERVICES-SDK - * ========================================================= - * Copyright (C) 2019 Nokia. 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.model.logging; - -import io.vavr.collection.HashMap; -import io.vavr.collection.Map; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.UUID; -import org.immutables.value.Value; -import org.jetbrains.annotations.Nullable; -import org.slf4j.MDC; - -/** - * @author Piotr Jaszczyk - * @since 1.1.2 - */ -@Value.Immutable(singleton = true) -public interface GlobalDiagnosticContext { - - @Value.Default - default String instanceId() { - return UUID.randomUUID().toString(); - } - - @Value.Default - default String serverFqdn() { - try { - return InetAddress.getLocalHost().toString(); - } catch (UnknownHostException ex) { - return InetAddress.getLoopbackAddress().toString(); - } - } - - @Value.Default - default String serviceName() { - return System.getenv().getOrDefault("HOSTNAME", "unknown_service"); - } - - @Value.Derived - default Map asMap() { - return HashMap.of( - MdcVariables.INSTANCE_ID, instanceId(), - MdcVariables.SERVER_FQDN, serverFqdn(), - MdcVariables.SERVICE_NAME, serviceName()); - } - - static GlobalDiagnosticContext instance() { - return ImmutableGlobalDiagnosticContext.of(); - } -} - - diff --git a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/logging/MdcVariables.java b/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/logging/MdcVariables.java deleted file mode 100644 index 652e3541..00000000 --- a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/logging/MdcVariables.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * DCAEGEN2-SERVICES-SDK - * ================================================================================ - * 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.sdk.rest.services.model.logging; - -import org.slf4j.MDC; - -import java.util.Map; - -public final class MdcVariables { - - @Deprecated - public static final String X_ONAP_REQUEST_ID = "X-ONAP-RequestID"; - @Deprecated - public static final String X_INVOCATION_ID = "X-InvocationID"; - - public static final String INSTANCE_UUID = "InstanceUUID"; - public static final String RESPONSE_CODE = "ResponseCode"; - public static final String REQUEST_ID = "RequestID"; - public static final String CLIENT_NAME = "PartnerName"; - public static final String CLIENT_IP = "ClientIPAddress"; - public static final String INVOCATION_ID = "InvocationID"; - public static final String INVOCATION_TIMESTAMP = "InvokeTimestamp"; - public static final String STATUS_CODE = "StatusCode"; - public static final String INSTANCE_ID = "InstanceID"; - public static final String SERVER_FQDN = "ServerFQDN"; - public static final String SERVICE_NAME = "ServiceName"; - - private static final String HTTP_HEADER_PREFIX = "X-"; - - private MdcVariables() { - } - - public static String httpHeader(String mdcName) { - return HTTP_HEADER_PREFIX + mdcName; - } - - /** - * @deprecated use {@link RequestDiagnosticContext#withSlf4jMdc(Runnable)}. - * @param mdcContextMap - */ - @Deprecated - public static void setMdcContextMap(Map mdcContextMap) { - if (mdcContextMap != null) { - MDC.setContextMap(mdcContextMap); - } - } -} diff --git a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/logging/RequestDiagnosticContext.java b/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/logging/RequestDiagnosticContext.java deleted file mode 100644 index 0c4a4b1f..00000000 --- a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/logging/RequestDiagnosticContext.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * ============LICENSE_START==================================== - * DCAEGEN2-SERVICES-SDK - * ========================================================= - * Copyright (C) 2019 Nokia. 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.model.logging; - -import io.vavr.collection.HashMap; -import io.vavr.collection.Map; -import java.util.UUID; -import org.immutables.value.Value; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.slf4j.MDC; - -/** - * @author Piotr Jaszczyk - * @since 1.1.2 - */ -@Value.Immutable -public interface RequestDiagnosticContext { - - UUID requestId(); - - @Nullable UUID invocationId(); - - @Value.Default - default GlobalDiagnosticContext global() { - return GlobalDiagnosticContext.instance(); - } - - @Value.Derived - default Map remoteCallHttpHeaders() { - java.util.Map result = new java.util.HashMap<>(); - - result.put(MdcVariables.httpHeader(MdcVariables.REQUEST_ID), requestId().toString()); - - if (invocationId() != null) { - result.put(MdcVariables.httpHeader(MdcVariables.INVOCATION_ID), invocationId().toString()); - } - - return HashMap.ofAll(result); - } - - @Value.Derived - default Map asMap() { - java.util.Map result = new java.util.HashMap<>(); - - if (requestId() != null) { - result.put(MdcVariables.REQUEST_ID, requestId().toString()); - } - - if (invocationId() != null) { - result.put(MdcVariables.INVOCATION_ID, invocationId().toString()); - } - - return global().asMap().merge(HashMap.ofAll(result)); - } - - default void withSlf4jMdc(Runnable runnable) { - withSlf4jMdc(true, runnable); - } - - default void withSlf4jMdc(boolean loglevelEnabled, Runnable runnable) { - if (loglevelEnabled) { - final java.util.Map ctxBefore = MDC.getCopyOfContextMap(); - try { - MDC.setContextMap(asMap().toJavaMap()); - runnable.run(); - } finally { - if (ctxBefore == null) { - MDC.clear(); - } else { - MDC.setContextMap(ctxBefore); - } - } - } - } - - default @NotNull RequestDiagnosticContext withNewInvocationId() { - return ImmutableRequestDiagnosticContext.copyOf(this) - .withInvocationId(UUID.randomUUID()); - } - - static ImmutableRequestDiagnosticContext create() { - return ImmutableRequestDiagnosticContext.builder() - .requestId(UUID.randomUUID()) - .invocationId(UUID.randomUUID()) - .build(); - } -} - - diff --git a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/uri/URI.java b/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/uri/URI.java deleted file mode 100644 index 6b74a82a..00000000 --- a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/uri/URI.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * DCAEGEN2-SERVICES-SDK - * ================================================================================ - * Copyright (C) 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.uri; - -public final class URI { - private String scheme; - private String host; - private int port; - private String path; - private String fragment; - private String authority; - private String userInfo; - private String query; - private String schemeSpecificPart; - private String string; - - private URI() { - } - - public static final class URIBuilder { - private String scheme; - private String host; - private int port; - private String path; - private String fragment; - private String authority; - private String userInfo; - private String query; - private String schemeSpecificPart; - - public URIBuilder scheme(String scheme) { - this.scheme = scheme; - return this; - } - - public URIBuilder host(String host) { - this.host = host; - return this; - } - - public URIBuilder port(int port) { - this.port = port; - return this; - } - - public URIBuilder path(String path) { - this.path = path; - return this; - } - - public URIBuilder fragment(String fragment) { - this.fragment = fragment; - return this; - } - - public URIBuilder authority(String authority) { - this.authority = authority; - return this; - } - - public URIBuilder userInfo(String userInfo) { - this.userInfo = userInfo; - return this; - } - - public URIBuilder query(String query) { - this.query = query; - return this; - } - - public URIBuilder schemeSpecificPart(String schemeSpecificPart) { - this.schemeSpecificPart = schemeSpecificPart; - return this; - } - - public URI build() { - URI uri = new URI(); - uri.scheme = this.scheme; - uri.host = this.host; - uri.port = this.port; - uri.path = this.path; - uri.fragment = this.fragment; - uri.authority = this.authority; - uri.userInfo = this.userInfo; - uri.query = this.query; - uri.schemeSpecificPart = this.schemeSpecificPart; - return uri; - } - } - - @Override - public String toString() { - defineString(); - return string; - } - - private void defineString() { - if (string != null) return; - - StringBuffer sb = new StringBuffer(); - if (scheme != null) { - sb.append(scheme); - sb.append(':'); - } - if (isOpaque()) { - sb.append(schemeSpecificPart); - } else { - if (host != null) { - sb.append("//"); - if (userInfo != null) { - sb.append(userInfo); - sb.append('@'); - } - boolean needBrackets = ((host.indexOf(':') >= 0) - && !host.startsWith("[") - && !host.endsWith("]")); - if (needBrackets) sb.append('['); - sb.append(host); - if (needBrackets) sb.append(']'); - if (port != -1) { - sb.append(':'); - sb.append(port); - } - } else if (authority != null) { - sb.append("//"); - sb.append(authority); - } - if (path != null) - sb.append(path); - if (query != null) { - sb.append('?'); - sb.append(query); - } - } - if (fragment != null) { - sb.append('#'); - sb.append(fragment); - } - string = sb.toString(); - } - - private boolean isOpaque() { - return path == null; - } -} \ No newline at end of file diff --git a/rest-services/common-dependency/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/model/logging/MdcVariablesTest.java b/rest-services/common-dependency/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/model/logging/MdcVariablesTest.java deleted file mode 100644 index bb0cc6cf..00000000 --- a/rest-services/common-dependency/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/model/logging/MdcVariablesTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * DCAEGEN2-SERVICES-SDK - * ================================================================================ - * 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.sdk.rest.services.model.logging; - -import static org.junit.jupiter.api.Assertions.*; - -import org.junit.jupiter.api.Test; - -class MdcVariablesTest { - - @Test - void shouldReturnProperHttpHeader() { - String expectedValue = "X-header"; - String returnedValue = MdcVariables.httpHeader("header"); - - assertEquals(expectedValue, returnedValue); - } -} \ No newline at end of file diff --git a/rest-services/common-dependency/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/uri/URITest.java b/rest-services/common-dependency/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/uri/URITest.java deleted file mode 100644 index b4a59638..00000000 --- a/rest-services/common-dependency/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/uri/URITest.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * DCAEGEN2-SERVICES-SDK - * ================================================================================ - * Copyright (C) 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.uri; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.junit.jupiter.api.Test; - -class URITest { - - @Test - void buildProperUri() { - String expectedValue = "http://user@localhost:8080path?query#fragment"; - URI uri = new URI.URIBuilder().scheme("http") - .host("localhost") - .port(8080) - .path("path") - .fragment("fragment") - .authority("authority") - .userInfo("user") - .query("query") - .build(); - - assertEquals(expectedValue, uri.toString()); - } -} \ No newline at end of file diff --git a/rest-services/dmaap-client/pom.xml b/rest-services/dmaap-client/pom.xml index c638e63b..a4c46d41 100644 --- a/rest-services/dmaap-client/pom.xml +++ b/rest-services/dmaap-client/pom.xml @@ -7,7 +7,7 @@ org.onap.dcaegen2.services.sdk dcaegen2-services-sdk-rest-services - 1.3.1-SNAPSHOT + 1.3.2-SNAPSHOT org.onap.dcaegen2.services.sdk.rest.services diff --git a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/MessageRouterPublisher.java b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/MessageRouterPublisher.java index e37bdcdf..08825b4c 100644 --- a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/MessageRouterPublisher.java +++ b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/MessageRouterPublisher.java @@ -21,7 +21,6 @@ package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api; import com.google.gson.JsonElement; -import org.onap.dcaegen2.services.sdk.rest.services.annotations.ExperimentalApi; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterPublishRequest; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterPublishResponse; import reactor.core.publisher.Flux; diff --git a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/MessageRouterSubscriber.java b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/MessageRouterSubscriber.java index c1fadbfa..d91535d3 100644 --- a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/MessageRouterSubscriber.java +++ b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/MessageRouterSubscriber.java @@ -22,7 +22,6 @@ package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api; import com.google.gson.JsonElement; import java.time.Duration; -import org.onap.dcaegen2.services.sdk.rest.services.annotations.ExperimentalApi; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterSubscribeRequest; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterSubscribeResponse; import reactor.core.publisher.Flux; diff --git a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/DmaapRequest.java b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/DmaapRequest.java index 6b3e2c4a..212d8f2a 100644 --- a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/DmaapRequest.java +++ b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/DmaapRequest.java @@ -21,7 +21,6 @@ package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model; import org.immutables.value.Value; -import org.onap.dcaegen2.services.sdk.rest.services.annotations.ExperimentalApi; import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext; /** diff --git a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/DmaapResponse.java b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/DmaapResponse.java index c3e37263..663974ce 100644 --- a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/DmaapResponse.java +++ b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/DmaapResponse.java @@ -22,7 +22,6 @@ package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model; import org.immutables.value.Value; import org.jetbrains.annotations.Nullable; -import org.onap.dcaegen2.services.sdk.rest.services.annotations.ExperimentalApi; /** * @author Piotr Jaszczyk diff --git a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/MessageRouterPublishRequest.java b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/MessageRouterPublishRequest.java index 29904138..314756d8 100644 --- a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/MessageRouterPublishRequest.java +++ b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/MessageRouterPublishRequest.java @@ -22,7 +22,6 @@ package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model; import org.immutables.value.Value; import org.onap.dcaegen2.services.sdk.model.streams.dmaap.MessageRouterSink; -import org.onap.dcaegen2.services.sdk.rest.services.annotations.ExperimentalApi; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.ContentType; /** diff --git a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/MessageRouterPublishResponse.java b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/MessageRouterPublishResponse.java index 8dcf17b7..6e292350 100644 --- a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/MessageRouterPublishResponse.java +++ b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/MessageRouterPublishResponse.java @@ -24,7 +24,6 @@ package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model; import com.google.gson.JsonElement; import io.vavr.collection.List; import org.immutables.value.Value; -import org.onap.dcaegen2.services.sdk.rest.services.annotations.ExperimentalApi; /** * @author Piotr Jaszczyk diff --git a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/MessageRouterSubscribeRequest.java b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/MessageRouterSubscribeRequest.java index 23284877..a2c370af 100644 --- a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/MessageRouterSubscribeRequest.java +++ b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/MessageRouterSubscribeRequest.java @@ -23,7 +23,6 @@ import java.time.Duration; import org.immutables.value.Value; import org.jetbrains.annotations.Nullable; import org.onap.dcaegen2.services.sdk.model.streams.dmaap.MessageRouterSource; -import org.onap.dcaegen2.services.sdk.rest.services.annotations.ExperimentalApi; /** * @author Piotr Jaszczyk diff --git a/rest-services/http-client/pom.xml b/rest-services/http-client/pom.xml index dd5be34e..d3b8f124 100644 --- a/rest-services/http-client/pom.xml +++ b/rest-services/http-client/pom.xml @@ -28,7 +28,7 @@ org.onap.dcaegen2.services.sdk dcaegen2-services-sdk-rest-services - 1.3.1-SNAPSHOT + 1.3.2-SNAPSHOT org.onap.dcaegen2.services.sdk.rest.services @@ -44,11 +44,6 @@ ssl ${project.version} - - org.onap.dcaegen2.services.sdk.rest.services - common-dependency - ${project.version} - io.projectreactor.netty reactor-netty @@ -61,6 +56,10 @@ org.immutables value + + org.immutables + gson + org.jetbrains annotations diff --git a/rest-services/http-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/URI.java b/rest-services/http-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/URI.java new file mode 100644 index 00000000..6b74a82a --- /dev/null +++ b/rest-services/http-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/URI.java @@ -0,0 +1,164 @@ +/* + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * Copyright (C) 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.uri; + +public final class URI { + private String scheme; + private String host; + private int port; + private String path; + private String fragment; + private String authority; + private String userInfo; + private String query; + private String schemeSpecificPart; + private String string; + + private URI() { + } + + public static final class URIBuilder { + private String scheme; + private String host; + private int port; + private String path; + private String fragment; + private String authority; + private String userInfo; + private String query; + private String schemeSpecificPart; + + public URIBuilder scheme(String scheme) { + this.scheme = scheme; + return this; + } + + public URIBuilder host(String host) { + this.host = host; + return this; + } + + public URIBuilder port(int port) { + this.port = port; + return this; + } + + public URIBuilder path(String path) { + this.path = path; + return this; + } + + public URIBuilder fragment(String fragment) { + this.fragment = fragment; + return this; + } + + public URIBuilder authority(String authority) { + this.authority = authority; + return this; + } + + public URIBuilder userInfo(String userInfo) { + this.userInfo = userInfo; + return this; + } + + public URIBuilder query(String query) { + this.query = query; + return this; + } + + public URIBuilder schemeSpecificPart(String schemeSpecificPart) { + this.schemeSpecificPart = schemeSpecificPart; + return this; + } + + public URI build() { + URI uri = new URI(); + uri.scheme = this.scheme; + uri.host = this.host; + uri.port = this.port; + uri.path = this.path; + uri.fragment = this.fragment; + uri.authority = this.authority; + uri.userInfo = this.userInfo; + uri.query = this.query; + uri.schemeSpecificPart = this.schemeSpecificPart; + return uri; + } + } + + @Override + public String toString() { + defineString(); + return string; + } + + private void defineString() { + if (string != null) return; + + StringBuffer sb = new StringBuffer(); + if (scheme != null) { + sb.append(scheme); + sb.append(':'); + } + if (isOpaque()) { + sb.append(schemeSpecificPart); + } else { + if (host != null) { + sb.append("//"); + if (userInfo != null) { + sb.append(userInfo); + sb.append('@'); + } + boolean needBrackets = ((host.indexOf(':') >= 0) + && !host.startsWith("[") + && !host.endsWith("]")); + if (needBrackets) sb.append('['); + sb.append(host); + if (needBrackets) sb.append(']'); + if (port != -1) { + sb.append(':'); + sb.append(port); + } + } else if (authority != null) { + sb.append("//"); + sb.append(authority); + } + if (path != null) + sb.append(path); + if (query != null) { + sb.append('?'); + sb.append(query); + } + } + if (fragment != null) { + sb.append('#'); + sb.append(fragment); + } + string = sb.toString(); + } + + private boolean isOpaque() { + return path == null; + } +} \ No newline at end of file diff --git a/rest-services/http-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/logging/GlobalDiagnosticContext.java b/rest-services/http-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/logging/GlobalDiagnosticContext.java new file mode 100644 index 00000000..db4a0fd6 --- /dev/null +++ b/rest-services/http-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/logging/GlobalDiagnosticContext.java @@ -0,0 +1,71 @@ +/* + * ============LICENSE_START==================================== + * DCAEGEN2-SERVICES-SDK + * ========================================================= + * Copyright (C) 2019 Nokia. 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.model.logging; + +import io.vavr.collection.HashMap; +import io.vavr.collection.Map; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.UUID; +import org.immutables.value.Value; +import org.jetbrains.annotations.Nullable; +import org.slf4j.MDC; + +/** + * @author Piotr Jaszczyk + * @since 1.1.2 + */ +@Value.Immutable(singleton = true) +public interface GlobalDiagnosticContext { + + @Value.Default + default String instanceId() { + return UUID.randomUUID().toString(); + } + + @Value.Default + default String serverFqdn() { + try { + return InetAddress.getLocalHost().toString(); + } catch (UnknownHostException ex) { + return InetAddress.getLoopbackAddress().toString(); + } + } + + @Value.Default + default String serviceName() { + return System.getenv().getOrDefault("HOSTNAME", "unknown_service"); + } + + @Value.Derived + default Map asMap() { + return HashMap.of( + MdcVariables.INSTANCE_ID, instanceId(), + MdcVariables.SERVER_FQDN, serverFqdn(), + MdcVariables.SERVICE_NAME, serviceName()); + } + + static GlobalDiagnosticContext instance() { + return ImmutableGlobalDiagnosticContext.of(); + } +} + + diff --git a/rest-services/http-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/logging/MdcVariables.java b/rest-services/http-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/logging/MdcVariables.java new file mode 100644 index 00000000..652e3541 --- /dev/null +++ b/rest-services/http-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/logging/MdcVariables.java @@ -0,0 +1,65 @@ +/* + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * 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.sdk.rest.services.model.logging; + +import org.slf4j.MDC; + +import java.util.Map; + +public final class MdcVariables { + + @Deprecated + public static final String X_ONAP_REQUEST_ID = "X-ONAP-RequestID"; + @Deprecated + public static final String X_INVOCATION_ID = "X-InvocationID"; + + public static final String INSTANCE_UUID = "InstanceUUID"; + public static final String RESPONSE_CODE = "ResponseCode"; + public static final String REQUEST_ID = "RequestID"; + public static final String CLIENT_NAME = "PartnerName"; + public static final String CLIENT_IP = "ClientIPAddress"; + public static final String INVOCATION_ID = "InvocationID"; + public static final String INVOCATION_TIMESTAMP = "InvokeTimestamp"; + public static final String STATUS_CODE = "StatusCode"; + public static final String INSTANCE_ID = "InstanceID"; + public static final String SERVER_FQDN = "ServerFQDN"; + public static final String SERVICE_NAME = "ServiceName"; + + private static final String HTTP_HEADER_PREFIX = "X-"; + + private MdcVariables() { + } + + public static String httpHeader(String mdcName) { + return HTTP_HEADER_PREFIX + mdcName; + } + + /** + * @deprecated use {@link RequestDiagnosticContext#withSlf4jMdc(Runnable)}. + * @param mdcContextMap + */ + @Deprecated + public static void setMdcContextMap(Map mdcContextMap) { + if (mdcContextMap != null) { + MDC.setContextMap(mdcContextMap); + } + } +} diff --git a/rest-services/http-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/logging/RequestDiagnosticContext.java b/rest-services/http-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/logging/RequestDiagnosticContext.java new file mode 100644 index 00000000..0c4a4b1f --- /dev/null +++ b/rest-services/http-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/logging/RequestDiagnosticContext.java @@ -0,0 +1,108 @@ +/* + * ============LICENSE_START==================================== + * DCAEGEN2-SERVICES-SDK + * ========================================================= + * Copyright (C) 2019 Nokia. 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.model.logging; + +import io.vavr.collection.HashMap; +import io.vavr.collection.Map; +import java.util.UUID; +import org.immutables.value.Value; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.slf4j.MDC; + +/** + * @author Piotr Jaszczyk + * @since 1.1.2 + */ +@Value.Immutable +public interface RequestDiagnosticContext { + + UUID requestId(); + + @Nullable UUID invocationId(); + + @Value.Default + default GlobalDiagnosticContext global() { + return GlobalDiagnosticContext.instance(); + } + + @Value.Derived + default Map remoteCallHttpHeaders() { + java.util.Map result = new java.util.HashMap<>(); + + result.put(MdcVariables.httpHeader(MdcVariables.REQUEST_ID), requestId().toString()); + + if (invocationId() != null) { + result.put(MdcVariables.httpHeader(MdcVariables.INVOCATION_ID), invocationId().toString()); + } + + return HashMap.ofAll(result); + } + + @Value.Derived + default Map asMap() { + java.util.Map result = new java.util.HashMap<>(); + + if (requestId() != null) { + result.put(MdcVariables.REQUEST_ID, requestId().toString()); + } + + if (invocationId() != null) { + result.put(MdcVariables.INVOCATION_ID, invocationId().toString()); + } + + return global().asMap().merge(HashMap.ofAll(result)); + } + + default void withSlf4jMdc(Runnable runnable) { + withSlf4jMdc(true, runnable); + } + + default void withSlf4jMdc(boolean loglevelEnabled, Runnable runnable) { + if (loglevelEnabled) { + final java.util.Map ctxBefore = MDC.getCopyOfContextMap(); + try { + MDC.setContextMap(asMap().toJavaMap()); + runnable.run(); + } finally { + if (ctxBefore == null) { + MDC.clear(); + } else { + MDC.setContextMap(ctxBefore); + } + } + } + } + + default @NotNull RequestDiagnosticContext withNewInvocationId() { + return ImmutableRequestDiagnosticContext.copyOf(this) + .withInvocationId(UUID.randomUUID()); + } + + static ImmutableRequestDiagnosticContext create() { + return ImmutableRequestDiagnosticContext.builder() + .requestId(UUID.randomUUID()) + .invocationId(UUID.randomUUID()) + .build(); + } +} + + diff --git a/rest-services/http-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/URITest.java b/rest-services/http-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/URITest.java new file mode 100644 index 00000000..b4a59638 --- /dev/null +++ b/rest-services/http-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/URITest.java @@ -0,0 +1,45 @@ +/* + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * Copyright (C) 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.uri; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +class URITest { + + @Test + void buildProperUri() { + String expectedValue = "http://user@localhost:8080path?query#fragment"; + URI uri = new URI.URIBuilder().scheme("http") + .host("localhost") + .port(8080) + .path("path") + .fragment("fragment") + .authority("authority") + .userInfo("user") + .query("query") + .build(); + + assertEquals(expectedValue, uri.toString()); + } +} \ No newline at end of file diff --git a/rest-services/http-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/logging/MdcVariablesTest.java b/rest-services/http-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/logging/MdcVariablesTest.java new file mode 100644 index 00000000..bb0cc6cf --- /dev/null +++ b/rest-services/http-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/logging/MdcVariablesTest.java @@ -0,0 +1,36 @@ +/* + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * 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.sdk.rest.services.model.logging; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + +class MdcVariablesTest { + + @Test + void shouldReturnProperHttpHeader() { + String expectedValue = "X-header"; + String returnedValue = MdcVariables.httpHeader("header"); + + assertEquals(expectedValue, returnedValue); + } +} \ No newline at end of file diff --git a/rest-services/model/pom.xml b/rest-services/model/pom.xml index 873fff6b..74d0556f 100644 --- a/rest-services/model/pom.xml +++ b/rest-services/model/pom.xml @@ -27,7 +27,7 @@ org.onap.dcaegen2.services.sdk dcaegen2-services-sdk-rest-services - 1.3.1-SNAPSHOT + 1.3.2-SNAPSHOT org.onap.dcaegen2.services.sdk.rest.services diff --git a/rest-services/pom.xml b/rest-services/pom.xml index 1cb83877..0b434e3a 100644 --- a/rest-services/pom.xml +++ b/rest-services/pom.xml @@ -7,7 +7,7 @@ org.onap.dcaegen2.services sdk - 1.3.1-SNAPSHOT + 1.3.2-SNAPSHOT org.onap.dcaegen2.services.sdk @@ -19,7 +19,6 @@ model - common-dependency http-client aai-client cbs-client diff --git a/security/crypt-password/pom.xml b/security/crypt-password/pom.xml index e21a587d..5e3152b7 100644 --- a/security/crypt-password/pom.xml +++ b/security/crypt-password/pom.xml @@ -6,7 +6,7 @@ org.onap.dcaegen2.services.sdk.security dcaegen2-services-sdk-security - 1.3.1-SNAPSHOT + 1.3.2-SNAPSHOT 4.0.0 diff --git a/security/pom.xml b/security/pom.xml index dde9d8d2..7ba50abc 100644 --- a/security/pom.xml +++ b/security/pom.xml @@ -7,7 +7,7 @@ org.onap.dcaegen2.services sdk - 1.3.1-SNAPSHOT + 1.3.2-SNAPSHOT org.onap.dcaegen2.services.sdk.security diff --git a/security/ssl/pom.xml b/security/ssl/pom.xml index 3f3a5451..98b9b99e 100644 --- a/security/ssl/pom.xml +++ b/security/ssl/pom.xml @@ -6,7 +6,7 @@ org.onap.dcaegen2.services.sdk.security dcaegen2-services-sdk-security - 1.3.1-SNAPSHOT + 1.3.2-SNAPSHOT ssl diff --git a/services/hv-ves-client/pom.xml b/services/hv-ves-client/pom.xml index 58096c61..abd77a25 100644 --- a/services/hv-ves-client/pom.xml +++ b/services/hv-ves-client/pom.xml @@ -26,7 +26,7 @@ org.onap.dcaegen2.services.sdk dcaegen2-services-sdk-services - 1.3.1-SNAPSHOT + 1.3.2-SNAPSHOT dcaegen2-services-sdk-services-hvvesclient diff --git a/services/hv-ves-client/producer/api/pom.xml b/services/hv-ves-client/producer/api/pom.xml index fa69a2ec..9311a339 100644 --- a/services/hv-ves-client/producer/api/pom.xml +++ b/services/hv-ves-client/producer/api/pom.xml @@ -26,7 +26,7 @@ org.onap.dcaegen2.services.sdk hvvesclient-producer - 1.3.1-SNAPSHOT + 1.3.2-SNAPSHOT hvvesclient-producer-api diff --git a/services/hv-ves-client/producer/ct/pom.xml b/services/hv-ves-client/producer/ct/pom.xml index c687b61e..a92a1b96 100644 --- a/services/hv-ves-client/producer/ct/pom.xml +++ b/services/hv-ves-client/producer/ct/pom.xml @@ -26,7 +26,7 @@ org.onap.dcaegen2.services.sdk hvvesclient-producer - 1.3.1-SNAPSHOT + 1.3.2-SNAPSHOT hvvesclient-producer-ct diff --git a/services/hv-ves-client/producer/impl/pom.xml b/services/hv-ves-client/producer/impl/pom.xml index 1b5ba865..6d3abbc6 100644 --- a/services/hv-ves-client/producer/impl/pom.xml +++ b/services/hv-ves-client/producer/impl/pom.xml @@ -26,7 +26,7 @@ org.onap.dcaegen2.services.sdk hvvesclient-producer - 1.3.1-SNAPSHOT + 1.3.2-SNAPSHOT hvvesclient-producer-impl diff --git a/services/hv-ves-client/producer/pom.xml b/services/hv-ves-client/producer/pom.xml index 36479021..164ebc80 100644 --- a/services/hv-ves-client/producer/pom.xml +++ b/services/hv-ves-client/producer/pom.xml @@ -26,7 +26,7 @@ org.onap.dcaegen2.services.sdk dcaegen2-services-sdk-services-hvvesclient - 1.3.1-SNAPSHOT + 1.3.2-SNAPSHOT hvvesclient-producer diff --git a/services/hv-ves-client/protobuf/pom.xml b/services/hv-ves-client/protobuf/pom.xml index d0a230b3..8bf9b7d8 100644 --- a/services/hv-ves-client/protobuf/pom.xml +++ b/services/hv-ves-client/protobuf/pom.xml @@ -26,7 +26,7 @@ dcaegen2-services-sdk-services-hvvesclient org.onap.dcaegen2.services.sdk - 1.3.1-SNAPSHOT + 1.3.2-SNAPSHOT High Volume VES Collector Client :: Protobuf diff --git a/services/pom.xml b/services/pom.xml index a9f24f22..c1a7190a 100644 --- a/services/pom.xml +++ b/services/pom.xml @@ -26,7 +26,7 @@ org.onap.dcaegen2.services sdk - 1.3.1-SNAPSHOT + 1.3.2-SNAPSHOT org.onap.dcaegen2.services.sdk diff --git a/standardization/api-custom-header/pom.xml b/standardization/api-custom-header/pom.xml index 0506c780..1f7b40b9 100644 --- a/standardization/api-custom-header/pom.xml +++ b/standardization/api-custom-header/pom.xml @@ -7,7 +7,7 @@ org.onap.dcaegen2.services.sdk dcaegen2-services-sdk-standardization - 1.3.1-SNAPSHOT + 1.3.2-SNAPSHOT .. diff --git a/standardization/moher-api/healthstate/pom.xml b/standardization/moher-api/healthstate/pom.xml index 15306e2c..ef39b798 100644 --- a/standardization/moher-api/healthstate/pom.xml +++ b/standardization/moher-api/healthstate/pom.xml @@ -25,7 +25,7 @@ dcaegen2-sdk-moher-api org.onap.dcaegen2.services.sdk - 1.3.1-SNAPSHOT + 1.3.2-SNAPSHOT Monitoring and Healthcheck :: Health state diff --git a/standardization/moher-api/metrics/pom.xml b/standardization/moher-api/metrics/pom.xml index 97a63c3d..52b4d4e9 100644 --- a/standardization/moher-api/metrics/pom.xml +++ b/standardization/moher-api/metrics/pom.xml @@ -26,7 +26,7 @@ dcaegen2-sdk-moher-api org.onap.dcaegen2.services.sdk - 1.3.1-SNAPSHOT + 1.3.2-SNAPSHOT Monitoring and Healthcheck :: Metrics diff --git a/standardization/moher-api/pom.xml b/standardization/moher-api/pom.xml index 7807bf40..1af5a3c4 100644 --- a/standardization/moher-api/pom.xml +++ b/standardization/moher-api/pom.xml @@ -26,7 +26,7 @@ dcaegen2-services-sdk-standardization org.onap.dcaegen2.services.sdk - 1.3.1-SNAPSHOT + 1.3.2-SNAPSHOT Monitoring and Healthcheck diff --git a/standardization/moher-api/server-adapters/pom.xml b/standardization/moher-api/server-adapters/pom.xml index 93c8ab67..ae8a1521 100644 --- a/standardization/moher-api/server-adapters/pom.xml +++ b/standardization/moher-api/server-adapters/pom.xml @@ -25,7 +25,7 @@ dcaegen2-sdk-moher-api org.onap.dcaegen2.services.sdk - 1.3.1-SNAPSHOT + 1.3.2-SNAPSHOT Monitoring and Healthcheck :: Server Adapters diff --git a/standardization/moher-api/server-adapters/reactor-netty/pom.xml b/standardization/moher-api/server-adapters/reactor-netty/pom.xml index cb589e45..24d9031f 100644 --- a/standardization/moher-api/server-adapters/reactor-netty/pom.xml +++ b/standardization/moher-api/server-adapters/reactor-netty/pom.xml @@ -25,7 +25,7 @@ dcaegen2-sdk-moher-server-adapters org.onap.dcaegen2.services.sdk - 1.3.1-SNAPSHOT + 1.3.2-SNAPSHOT Monitoring and Healthcheck :: Server Adapters :: Reactor Netty diff --git a/standardization/moher-api/server-adapters/spring-webflux/pom.xml b/standardization/moher-api/server-adapters/spring-webflux/pom.xml index a9b5f7aa..6efa37b4 100644 --- a/standardization/moher-api/server-adapters/spring-webflux/pom.xml +++ b/standardization/moher-api/server-adapters/spring-webflux/pom.xml @@ -25,7 +25,7 @@ dcaegen2-sdk-moher-server-adapters org.onap.dcaegen2.services.sdk - 1.3.1-SNAPSHOT + 1.3.2-SNAPSHOT Monitoring and Healthcheck :: Server Adapters :: Spring Webflux diff --git a/standardization/pom.xml b/standardization/pom.xml index 05dce1ee..2ecd3311 100644 --- a/standardization/pom.xml +++ b/standardization/pom.xml @@ -8,7 +8,7 @@ org.onap.dcaegen2.services sdk - 1.3.1-SNAPSHOT + 1.3.2-SNAPSHOT .. diff --git a/version.properties b/version.properties index fee49286..ef20baaf 100644 --- a/version.properties +++ b/version.properties @@ -1,6 +1,6 @@ major=1 minor=3 -patch=1 +patch=2 base_version=${major}.${minor}.${patch} release_version=${base_version} snapshot_version=${base_version}-SNAPSHOT -- cgit 1.2.3-korg