aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/main/java
diff options
context:
space:
mode:
authorToineSiebelink <toine.siebelink@est.tech>2024-08-26 17:10:03 +0100
committerToineSiebelink <toine.siebelink@est.tech>2024-08-26 17:10:28 +0100
commit3a4dcb5af00b85ae3f48709dfa0f9d797e02aabd (patch)
tree44640185deea0720c6835da7ad962d70b4e3a4c1 /cps-ncmp-service/src/main/java
parent64ff45847a3466cb24a8dab57b65be753ee3cd03 (diff)
Policy Executor and DMI WebClient configurations
- separated dmi and policy executor http client configuration Issue-ID: CPS-2324 Change-Id: Ib4e757da188673e163abe6078dfd6ddae447eaab Signed-off-by: ToineSiebelink <toine.siebelink@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/main/java')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/config/DmiHttpClientConfig.java (renamed from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/config/HttpClientConfiguration.java)17
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/config/PolicyExecutorHttpClientConfig.java41
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/config/ServiceConfig.java36
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/DmiDataOperations.java1
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/policyexecutor/PolicyExecutor.java (renamed from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/PolicyExecutor.java)2
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/dmi/DmiWebClientsConfiguration.java68
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/policyexecutor/PolicyExecutorWebClientConfiguration.java46
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/WebClientConfiguration.java (renamed from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/dmi/DmiWebClientConfiguration.java)55
8 files changed, 202 insertions, 64 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/config/HttpClientConfiguration.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/config/DmiHttpClientConfig.java
index 583d4bb6ad..8eebb89a0a 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/config/HttpClientConfiguration.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/config/DmiHttpClientConfig.java
@@ -29,7 +29,7 @@ import org.springframework.context.annotation.Configuration;
@Setter
@Configuration
@ConfigurationProperties(prefix = "ncmp.dmi.httpclient")
-public class HttpClientConfiguration {
+public class DmiHttpClientConfig {
private final DataServices dataServices = new DataServices();
private final ModelServices modelServices = new ModelServices();
@@ -54,19 +54,4 @@ public class HttpClientConfiguration {
private int maximumConnectionsTotal = 10;
private int pendingAcquireMaxCount = 5;
}
-
- /**
- * Base configuration properties for all services.
- */
- @Getter
- @Setter
- public static class ServiceConfig {
- private String connectionProviderName = "cpsConnectionPool";
- private int maximumConnectionsTotal = 100;
- private int pendingAcquireMaxCount = 50;
- private Integer connectionTimeoutInSeconds = 30;
- private long readTimeoutInSeconds = 30;
- private long writeTimeoutInSeconds = 30;
- private int maximumInMemorySizeInMegabytes = 1;
- }
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/config/PolicyExecutorHttpClientConfig.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/config/PolicyExecutorHttpClientConfig.java
new file mode 100644
index 0000000000..0903c671b5
--- /dev/null
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/config/PolicyExecutorHttpClientConfig.java
@@ -0,0 +1,41 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2024 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.ncmp.config;
+
+import lombok.Getter;
+import lombok.Setter;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+@Getter
+@Setter
+@Configuration
+@ConfigurationProperties(prefix = "ncmp.policy-executor.httpclient")
+public class PolicyExecutorHttpClientConfig {
+
+ private final AllServices allServices = new AllServices();
+
+ @Getter
+ @Setter
+ public static class AllServices extends ServiceConfig {
+ private String connectionProviderName = "policyExecutorConfig";
+ }
+}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/config/ServiceConfig.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/config/ServiceConfig.java
new file mode 100644
index 0000000000..f1fce0c7c6
--- /dev/null
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/config/ServiceConfig.java
@@ -0,0 +1,36 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2024 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.ncmp.config;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public abstract class ServiceConfig {
+ private String connectionProviderName = "";
+ private int maximumInMemorySizeInMegabytes = 1;
+ private int maximumConnectionsTotal = 1;
+ private int pendingAcquireMaxCount = 1;
+ private Integer connectionTimeoutInSeconds = 1;
+ private long readTimeoutInSeconds = 1;
+ private long writeTimeoutInSeconds = 1;
+}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/DmiDataOperations.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/DmiDataOperations.java
index 90783a829a..8be57fed3d 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/DmiDataOperations.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/DmiDataOperations.java
@@ -41,6 +41,7 @@ import org.onap.cps.ncmp.api.exceptions.DmiClientRequestException;
import org.onap.cps.ncmp.impl.data.models.DmiDataOperation;
import org.onap.cps.ncmp.impl.data.models.DmiDataOperationRequest;
import org.onap.cps.ncmp.impl.data.models.DmiOperationCmHandle;
+import org.onap.cps.ncmp.impl.data.policyexecutor.PolicyExecutor;
import org.onap.cps.ncmp.impl.data.utils.DmiDataOperationsHelper;
import org.onap.cps.ncmp.impl.dmi.DmiProperties;
import org.onap.cps.ncmp.impl.dmi.DmiRestClient;
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/PolicyExecutor.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/policyexecutor/PolicyExecutor.java
index 2b5eb9e792..8e7620ccea 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/PolicyExecutor.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/policyexecutor/PolicyExecutor.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.impl.data;
+package org.onap.cps.ncmp.impl.data.policyexecutor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/dmi/DmiWebClientsConfiguration.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/dmi/DmiWebClientsConfiguration.java
new file mode 100644
index 0000000000..265d284239
--- /dev/null
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/dmi/DmiWebClientsConfiguration.java
@@ -0,0 +1,68 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2024 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.ncmp.impl.dmi;
+
+import lombok.RequiredArgsConstructor;
+import org.onap.cps.ncmp.config.DmiHttpClientConfig;
+import org.onap.cps.ncmp.impl.utils.WebClientConfiguration;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.reactive.function.client.WebClient;
+
+@Configuration
+@RequiredArgsConstructor
+public class DmiWebClientsConfiguration extends WebClientConfiguration {
+
+ private final DmiHttpClientConfig dmiHttpClientConfig;
+
+ /**
+ * Configures and creates a web client bean for DMI data services.
+ *
+ * @param webClientBuilder The builder instance to create the WebClient.
+ * @return a WebClient instance configured for data services.
+ */
+ @Bean
+ public WebClient dataServicesWebClient(final WebClient.Builder webClientBuilder) {
+ return configureWebClient(webClientBuilder, dmiHttpClientConfig.getDataServices());
+ }
+
+ /**
+ * Configures and creates a web client bean for DMI model services.
+ *
+ * @param webClientBuilder The builder instance to create the WebClient.
+ * @return a WebClient instance configured for model services.
+ */
+ @Bean
+ public WebClient modelServicesWebClient(final WebClient.Builder webClientBuilder) {
+ return configureWebClient(webClientBuilder, dmiHttpClientConfig.getModelServices());
+ }
+
+ /**
+ * Configures and creates a web client bean for DMI health check services.
+ *
+ * @param webClientBuilder The builder instance to create the WebClient.
+ * @return a WebClient instance configured for health check services.
+ */
+ @Bean
+ public WebClient healthChecksWebClient(final WebClient.Builder webClientBuilder) {
+ return configureWebClient(webClientBuilder, dmiHttpClientConfig.getHealthCheckServices());
+ }
+}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/policyexecutor/PolicyExecutorWebClientConfiguration.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/policyexecutor/PolicyExecutorWebClientConfiguration.java
new file mode 100644
index 0000000000..a927764825
--- /dev/null
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/policyexecutor/PolicyExecutorWebClientConfiguration.java
@@ -0,0 +1,46 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2024 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.ncmp.impl.policyexecutor;
+
+import lombok.RequiredArgsConstructor;
+import org.onap.cps.ncmp.config.PolicyExecutorHttpClientConfig;
+import org.onap.cps.ncmp.impl.utils.WebClientConfiguration;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.reactive.function.client.WebClient;
+
+@Configuration
+@RequiredArgsConstructor
+public class PolicyExecutorWebClientConfiguration extends WebClientConfiguration {
+
+ private final PolicyExecutorHttpClientConfig policyExecutorHttpClientConfig;
+
+ /**
+ * Configures and creates a web client bean for Policy Executor.
+ *
+ * @param webClientBuilder The builder instance to create the WebClient.
+ * @return a WebClient instance configured for Policy Executor.
+ */
+ @Bean
+ public WebClient policyExecutorWebClient(final WebClient.Builder webClientBuilder) {
+ return configureWebClient(webClientBuilder, policyExecutorHttpClientConfig.getAllServices());
+ }
+}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/dmi/DmiWebClientConfiguration.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/WebClientConfiguration.java
index c176e40226..967f74e942 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/dmi/DmiWebClientConfiguration.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/WebClientConfiguration.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.impl.dmi;
+package org.onap.cps.ncmp.impl.utils;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.netty.channel.ChannelOption;
@@ -27,10 +27,7 @@ import io.netty.handler.timeout.WriteTimeoutHandler;
import io.netty.resolver.DefaultAddressResolverGroup;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
-import lombok.RequiredArgsConstructor;
-import org.onap.cps.ncmp.config.HttpClientConfiguration;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
+import org.onap.cps.ncmp.config.ServiceConfig;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
@@ -39,58 +36,22 @@ import reactor.netty.http.client.HttpClient;
import reactor.netty.resources.ConnectionProvider;
/**
- * Configures and creates WebClient beans for various DMI services including data, model, and health check services.
+ * Configures and creates WebClient beans for various rest services such as DMI and Policy Executor.
* The configuration utilizes Netty-based HttpClient with custom connection settings, read and write timeouts,
* and initializes WebClient with these settings to ensure optimal performance and resource management.
*/
-@Configuration
-@RequiredArgsConstructor
-public class DmiWebClientConfiguration {
+public class WebClientConfiguration {
- private final HttpClientConfiguration httpClientConfiguration;
private static final Duration DEFAULT_RESPONSE_TIMEOUT = Duration.ofSeconds(30);
- /**
- * Configures and creates a web client bean for DMI data services.
- *
- * @param webClientBuilder The builder instance to create the WebClient.
- * @return a WebClient instance configured for data services.
- */
- @Bean
- public WebClient dataServicesWebClient(final WebClient.Builder webClientBuilder) {
- return configureWebClient(webClientBuilder, httpClientConfiguration.getDataServices());
- }
-
- /**
- * Configures and creates a web client bean for DMI model services.
- *
- * @param webClientBuilder The builder instance to create the WebClient.
- * @return a WebClient instance configured for model services.
- */
- @Bean
- public WebClient modelServicesWebClient(final WebClient.Builder webClientBuilder) {
- return configureWebClient(webClientBuilder, httpClientConfiguration.getModelServices());
- }
-
- /**
- * Configures and creates a web client bean for DMI health check services.
- *
- * @param webClientBuilder The builder instance to create the WebClient.
- * @return a WebClient instance configured for health check services.
- */
- @Bean
- public WebClient healthChecksWebClient(final WebClient.Builder webClientBuilder) {
- return configureWebClient(webClientBuilder, httpClientConfiguration.getHealthCheckServices());
- }
-
- private WebClient configureWebClient(final WebClient.Builder webClientBuilder,
- final HttpClientConfiguration.ServiceConfig serviceConfig) {
+ protected WebClient configureWebClient(final WebClient.Builder webClientBuilder,
+ final ServiceConfig serviceConfig) {
final ConnectionProvider connectionProvider = getConnectionProvider(serviceConfig);
final HttpClient httpClient = createHttpClient(serviceConfig, connectionProvider);
return buildAndGetWebClient(webClientBuilder, httpClient, serviceConfig.getMaximumInMemorySizeInMegabytes());
}
- private static HttpClient createHttpClient(final HttpClientConfiguration.ServiceConfig serviceConfig,
+ private static HttpClient createHttpClient(final ServiceConfig serviceConfig,
final ConnectionProvider connectionProvider) {
return HttpClient.create(connectionProvider)
.responseTimeout(DEFAULT_RESPONSE_TIMEOUT)
@@ -103,7 +64,7 @@ public class DmiWebClientConfiguration {
}
@SuppressFBWarnings("BC_UNCONFIRMED_CAST_OF_RETURN_VALUE")
- private static ConnectionProvider getConnectionProvider(final HttpClientConfiguration.ServiceConfig serviceConfig) {
+ private static ConnectionProvider getConnectionProvider(final ServiceConfig serviceConfig) {
return ConnectionProvider.builder(serviceConfig.getConnectionProviderName())
.maxConnections(serviceConfig.getMaximumConnectionsTotal())
.pendingAcquireMaxCount(serviceConfig.getPendingAcquireMaxCount())