aboutsummaryrefslogtreecommitdiffstats
path: root/rest-services/aai-client/src
diff options
context:
space:
mode:
Diffstat (limited to 'rest-services/aai-client/src')
-rw-r--r--rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/config/AaiClientConfiguration.java3
-rw-r--r--rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/AaiHttpClient.java11
-rw-r--r--rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiGetServiceInstanceClient.java77
-rw-r--r--rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClient.java7
-rw-r--r--rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClient.java22
-rw-r--r--rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiHttpPutClient.java12
6 files changed, 114 insertions, 18 deletions
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
index 30bf2538..3a6dbc46 100644
--- 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
@@ -59,6 +59,9 @@ public abstract class AaiClientConfiguration implements Serializable {
public abstract String aaiPnfPath();
@Value.Parameter
+ public abstract String aaiServiceInstancePath();
+
+ @Value.Parameter
public abstract Map<String, String> aaiHeaders();
@Value.Parameter
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
index c88ca0ea..317fab2c 100644
--- 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
@@ -20,9 +20,14 @@
package org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http;
-import org.onap.dcaegen2.services.sdk.rest.services.model.AaiModel;
import reactor.core.publisher.Mono;
-public interface AaiHttpClient<T> {
- Mono<T> getAaiResponse(AaiModel aaiModel);
+import java.util.function.Function;
+
+public interface AaiHttpClient<T, U> {
+ Mono<U> getAaiResponse(T aaiModel);
+
+ default <S> AaiHttpClient<T, S> map(final Function<U,S> 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/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
new file mode 100644
index 00000000..f8300eb2
--- /dev/null
+++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiGetServiceInstanceClient.java
@@ -0,0 +1,77 @@
+/*
+ * ============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 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.CloudHttpClient;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse;
+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;
+
+import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.AaiHttpClientFactory.createRequestDiagnosticContext;
+
+public class AaiGetServiceInstanceClient implements
+ AaiHttpClient<AaiServiceInstanceQueryModel, HttpResponse> {
+
+ //variables for query "/business/customers/customer/${customer}/service-subscriptions/service-subscription/${serviceType}/service-instances/service-instance/${serviceInstanceId}"
+ public static final String CUSTOMER = "customer";
+ public static final String SERVICE_TYPE = "serviceType";
+ public static final String SERVICE_INSTANCE_ID = "serviceInstanceId";
+
+ private CloudHttpClient httpGetClient;
+ private final AaiClientConfiguration configuration;
+
+ public AaiGetServiceInstanceClient(final AaiClientConfiguration configuration, final CloudHttpClient httpGetClient) {
+ this.configuration = configuration;
+ this.httpGetClient = httpGetClient;
+ }
+
+ @Override
+ public Mono<HttpResponse> getAaiResponse(AaiServiceInstanceQueryModel aaiModel) {
+ final Map<String, String> 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());
+
+ return httpGetClient.get(
+ getUri(replaced),
+ createRequestDiagnosticContext(),
+ configuration.aaiHeaders());
+ }
+
+ private String getUri(final String endpoint) {
+ return new URI.URIBuilder()
+ .scheme(configuration.aaiProtocol())
+ .host(configuration.aaiHost())
+ .port(configuration.aaiPort())
+ .path(configuration.aaiBasePath() + "/" + endpoint)
+ .build()
+ .toString();
+ }
+} \ 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/AaiHttpGetClient.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClient.java
index dad1c1f1..1c3f20a6 100644
--- 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
@@ -23,13 +23,14 @@ package org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.get
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.CloudHttpClient;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse;
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;
import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.AaiHttpClientFactory.createRequestDiagnosticContext;
-public final class AaiHttpGetClient implements AaiHttpClient<String> {
+public final class AaiHttpGetClient implements AaiHttpClient<AaiModel, HttpResponse> {
private CloudHttpClient httpGetClient;
private final AaiClientConfiguration configuration;
@@ -41,8 +42,8 @@ public final class AaiHttpGetClient implements AaiHttpClient<String> {
}
@Override
- public Mono<String> getAaiResponse(AaiModel aaiModel) {
- return httpGetClient.get(getUri(aaiModel.getCorrelationId()), createRequestDiagnosticContext(), configuration.aaiHeaders(), String.class);
+ public Mono<HttpResponse> getAaiResponse(AaiModel aaiModel) {
+ return httpGetClient.get(getUri(aaiModel.getCorrelationId()), createRequestDiagnosticContext(), configuration.aaiHeaders());
}
private String getUri(String pnfName) {
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
index 18511008..f92dba99 100644
--- 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
@@ -20,18 +20,22 @@
package org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.patch;
+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.CloudHttpClient;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse;
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;
-import reactor.netty.http.client.HttpClientResponse;
+
import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.AaiHttpClientFactory.createRequestDiagnosticContext;
-public final class AaiHttpPatchClient implements AaiHttpClient<HttpClientResponse> {
+public final class AaiHttpPatchClient implements AaiHttpClient<AaiModel, HttpResponse> {
+ private final static Map<String, String> CONTENT_TYPE = HashMap.of("Content-Type", "application/merge-patch+json");
private CloudHttpClient httpPatchClient;
private final AaiClientConfiguration configuration;
@@ -44,9 +48,15 @@ public final class AaiHttpPatchClient implements AaiHttpClient<HttpClientRespons
this.httpPatchClient = httpPatchClient;
}
- public Mono<HttpClientResponse> getAaiResponse(AaiModel aaiModel) {
- return httpPatchClient
- .patch(getUri(aaiModel.getCorrelationId()), createRequestDiagnosticContext(), configuration.aaiHeaders(), jsonBodyBuilder, aaiModel);
+ public Mono<HttpResponse> getAaiResponse(AaiModel aaiModel) {
+ final Map<String, String> headers = CONTENT_TYPE.merge(HashMap.ofAll(configuration.aaiHeaders()));
+
+ return httpPatchClient.patch(
+ getUri(aaiModel.getCorrelationId()),
+ createRequestDiagnosticContext(),
+ headers.toJavaMap(),
+ jsonBodyBuilder,
+ aaiModel);
}
private String getUri(String pnfName) {
@@ -57,4 +67,4 @@ public final class AaiHttpPatchClient implements AaiHttpClient<HttpClientRespons
.path(configuration.aaiBasePath() + configuration.aaiPnfPath() + "/" + pnfName).build().toString();
}
-}
+} \ 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/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
index 33fcfcce..eb1a389f 100644
--- 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
@@ -21,17 +21,17 @@
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.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.CloudHttpClient;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse;
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;
-import reactor.netty.http.client.HttpClientResponse;
-public class AaiHttpPutClient implements AaiHttpClient<HttpClientResponse> {
+import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.AaiHttpClientFactory.createRequestDiagnosticContext;
+
+public class AaiHttpPutClient implements AaiHttpClient<AaiModel, HttpResponse> {
private CloudHttpClient httpPutClient;
private final AaiClientConfiguration configuration;
@@ -46,8 +46,8 @@ public class AaiHttpPutClient implements AaiHttpClient<HttpClientResponse> {
}
@Override
- public Mono<HttpClientResponse> getAaiResponse(AaiModel aaiModel) {
+ public Mono<HttpResponse> getAaiResponse(AaiModel aaiModel) {
return httpPutClient
- .put(uri, createRequestDiagnosticContext(), configuration.aaiHeaders(), jsonBodyBuilder, aaiModel);
+ .put(uri, createRequestDiagnosticContext(), configuration.aaiHeaders(), jsonBodyBuilder, aaiModel);
}
}