diff options
author | ToineSiebelink <toine.siebelink@est.tech> | 2024-08-26 17:10:03 +0100 |
---|---|---|
committer | ToineSiebelink <toine.siebelink@est.tech> | 2024-08-26 17:10:28 +0100 |
commit | 3a4dcb5af00b85ae3f48709dfa0f9d797e02aabd (patch) | |
tree | 44640185deea0720c6835da7ad962d70b4e3a4c1 | |
parent | 64ff45847a3466cb24a8dab57b65be753ee3cd03 (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>
18 files changed, 449 insertions, 185 deletions
diff --git a/cps-application/src/main/resources/application.yml b/cps-application/src/main/resources/application.yml index f61a09ba17..dd4576ec02 100644 --- a/cps-application/src/main/resources/application.yml +++ b/cps-application/src/main/resources/application.yml @@ -188,22 +188,35 @@ logging: onap: cps: INFO ncmp: - dmi: + policy-executor: + enabled: true + server: + address: "http://localhost" + port: "8785" httpclient: - data-services: + all-services: + maximumInMemorySizeInMegabytes: 16 + maximumConnectionsTotal: 100 + pendingAcquireMaxCount: 50 connectionTimeoutInSeconds: 30 readTimeoutInSeconds: 30 writeTimeoutInSeconds: 30 + dmi: + httpclient: + data-services: + maximumInMemorySizeInMegabytes: 16 maximumConnectionsTotal: 100 pendingAcquireMaxCount: 50 - maximumInMemorySizeInMegabytes: 16 - model-services: connectionTimeoutInSeconds: 30 readTimeoutInSeconds: 30 writeTimeoutInSeconds: 30 + model-services: + maximumInMemorySizeInMegabytes: 16 maximumConnectionsTotal: 100 pendingAcquireMaxCount: 50 - maximumInMemorySizeInMegabytes: 16 + connectionTimeoutInSeconds: 30 + readTimeoutInSeconds: 30 + writeTimeoutInSeconds: 30 auth: username: ${DMI_USERNAME:cpsuser} password: ${DMI_PASSWORD:cpsr0cks!} @@ -244,4 +257,4 @@ otel: exporter: otlp: traces: - protocol: ${ONAP_OTEL_EXPORTER_OTLP_TRACES_PROTOCOL:grpc}
\ No newline at end of file + protocol: ${ONAP_OTEL_EXPORTER_OTLP_TRACES_PROTOCOL:grpc} 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()) diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/config/HttpClientConfigurationSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/config/DmiHttpClientConfigSpec.groovy index 1d3b22fb73..e0ae204c8d 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/config/HttpClientConfigurationSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/config/DmiHttpClientConfigSpec.groovy @@ -28,46 +28,46 @@ import org.springframework.test.context.ContextConfiguration import spock.lang.Specification @SpringBootTest -@ContextConfiguration(classes = [HttpClientConfiguration]) -@EnableConfigurationProperties(HttpClientConfiguration) -class HttpClientConfigurationSpec extends Specification { +@ContextConfiguration(classes = [DmiHttpClientConfig]) +@EnableConfigurationProperties(DmiHttpClientConfig) +class DmiHttpClientConfigSpec extends Specification { @Autowired - HttpClientConfiguration httpClientConfiguration + DmiHttpClientConfig dmiHttpClientConfig def 'Test http client configuration properties of data with custom and default values'() { - expect: 'properties are populated correctly for data' - with(httpClientConfiguration.dataServices) { - assert connectionTimeoutInSeconds == 123 - assert readTimeoutInSeconds == 33 - assert writeTimeoutInSeconds == 30 - assert maximumConnectionsTotal == 100 - assert pendingAcquireMaxCount == 22 - assert maximumInMemorySizeInMegabytes == 7 + expect: 'properties are populated correctly for data services' + with(dmiHttpClientConfig.dataServices) { + assert maximumInMemorySizeInMegabytes == 1 + assert maximumConnectionsTotal == 2 + assert pendingAcquireMaxCount == 3 + assert connectionTimeoutInSeconds == 4 + assert readTimeoutInSeconds == 5 + assert writeTimeoutInSeconds == 6 } } def 'Test http client configuration properties of model with custom and default values'() { - expect: 'properties are populated correctly for model' - with(httpClientConfiguration.modelServices) { - assert connectionTimeoutInSeconds == 456 - assert readTimeoutInSeconds == 30 - assert writeTimeoutInSeconds == 30 - assert maximumConnectionsTotal == 111 - assert pendingAcquireMaxCount == 44 - assert maximumInMemorySizeInMegabytes == 8 + expect: 'properties are populated correctly for model services' + with(dmiHttpClientConfig.modelServices) { + assert maximumInMemorySizeInMegabytes == 11 + assert maximumConnectionsTotal == 12 + assert pendingAcquireMaxCount == 13 + assert connectionTimeoutInSeconds == 14 + assert readTimeoutInSeconds == 15 + assert writeTimeoutInSeconds == 16 } } def 'Test http client configuration properties of health with default values'() { - expect: 'properties are populated correctly for health' - with(httpClientConfiguration.healthCheckServices) { - assert connectionTimeoutInSeconds == 30 - assert readTimeoutInSeconds == 30 - assert writeTimeoutInSeconds == 30 - assert maximumConnectionsTotal == 10 - assert pendingAcquireMaxCount == 5 - assert maximumInMemorySizeInMegabytes == 1 + expect: 'properties are populated correctly for health check services' + with(dmiHttpClientConfig.healthCheckServices) { + assert maximumInMemorySizeInMegabytes == 21 + assert maximumConnectionsTotal == 22 + assert pendingAcquireMaxCount == 23 + assert connectionTimeoutInSeconds == 24 + assert readTimeoutInSeconds == 25 + assert writeTimeoutInSeconds == 26 } } } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/config/PolicyExecutorHttpClientConfigSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/config/PolicyExecutorHttpClientConfigSpec.groovy new file mode 100644 index 0000000000..1946a452b1 --- /dev/null +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/config/PolicyExecutorHttpClientConfigSpec.groovy @@ -0,0 +1,48 @@ +/*- + * ============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 org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.context.properties.EnableConfigurationProperties +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.test.context.ContextConfiguration +import spock.lang.Specification + +@SpringBootTest +@ContextConfiguration(classes = [PolicyExecutorHttpClientConfig]) +@EnableConfigurationProperties +class PolicyExecutorHttpClientConfigSpec extends Specification { + + @Autowired + PolicyExecutorHttpClientConfig policyExecutorHttpClientConfig + + def 'Test http client configuration properties of data with custom and default values'() { + expect: 'properties are populated correctly for all services' + with(policyExecutorHttpClientConfig.allServices) { + assert maximumInMemorySizeInMegabytes == 31 + assert maximumConnectionsTotal == 32 + assert pendingAcquireMaxCount == 33 + assert connectionTimeoutInSeconds == 34 + assert readTimeoutInSeconds == 35 + assert writeTimeoutInSeconds == 36 + } + } +} diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/DmiDataOperationsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/DmiDataOperationsSpec.groovy index 8b369bf549..2324d48a93 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/DmiDataOperationsSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/DmiDataOperationsSpec.groovy @@ -28,6 +28,7 @@ import org.onap.cps.ncmp.api.data.models.DataOperationRequest import org.onap.cps.ncmp.api.exceptions.DmiClientRequestException import org.onap.cps.ncmp.config.CpsApplicationContext import org.onap.cps.ncmp.events.async1_0_0.DataOperationEvent +import org.onap.cps.ncmp.impl.data.policyexecutor.PolicyExecutor import org.onap.cps.ncmp.impl.dmi.DmiOperationsBaseSpec import org.onap.cps.ncmp.impl.dmi.DmiProperties import org.onap.cps.ncmp.impl.dmi.UrlTemplateParameters @@ -37,7 +38,6 @@ import org.onap.cps.ncmp.utils.TestUtils import org.onap.cps.utils.JsonObjectMapper import org.spockframework.spring.SpringBean import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.test.context.SpringBootContextLoader import org.springframework.boot.test.context.SpringBootTest import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/PolicyExecutorSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/PolicyExecutorSpec.groovy index 654206776b..4b09afa2ae 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/PolicyExecutorSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/PolicyExecutorSpec.groovy @@ -4,6 +4,7 @@ import ch.qos.logback.classic.Level import ch.qos.logback.classic.Logger import ch.qos.logback.classic.spi.ILoggingEvent import ch.qos.logback.core.read.ListAppender +import org.onap.cps.ncmp.impl.data.policyexecutor.PolicyExecutor import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/dmi/DmiWebClientConfigurationSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/dmi/DmiWebClientConfigurationSpec.groovy deleted file mode 100644 index fca47d8c24..0000000000 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/dmi/DmiWebClientConfigurationSpec.groovy +++ /dev/null @@ -1,77 +0,0 @@ -/*- - * ============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 org.onap.cps.ncmp.config.HttpClientConfiguration -import org.springframework.boot.context.properties.EnableConfigurationProperties -import org.springframework.boot.test.context.SpringBootTest -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.TestPropertySource -import org.springframework.web.reactive.function.client.WebClient -import spock.lang.Specification - -@SpringBootTest -@ContextConfiguration(classes = [HttpClientConfiguration]) -@TestPropertySource(properties = ['ncmp.dmi.httpclient.data-services.connectionTimeoutInSeconds=1', 'ncmp.dmi.httpclient.model-services.maximumInMemorySizeInMegabytes=1']) -@EnableConfigurationProperties -class DmiWebClientConfigurationSpec extends Specification { - - def webClientBuilder = Mock(WebClient.Builder) { - defaultHeaders(_) >> it - clientConnector(_) >> it - codecs(_) >> it - build() >> Mock(WebClient) - } - - def httpClientConfiguration = Spy(HttpClientConfiguration.class) - - def objectUnderTest = new DmiWebClientConfiguration(httpClientConfiguration) - - def 'Web Client Configuration construction.'() { - expect: 'the system can create an instance' - new DmiWebClientConfiguration(httpClientConfiguration) != null - } - - def 'Creating a web client instance data service.'() { - given: 'Web client configuration is invoked' - def dataServicesWebClient = objectUnderTest.dataServicesWebClient(webClientBuilder) - expect: 'the system can create an instance for data service' - assert dataServicesWebClient != null - assert dataServicesWebClient instanceof WebClient - } - - def 'Creating a web client instance model service.'() { - given: 'Web client configuration invoked' - def modelServicesWebClient = objectUnderTest.modelServicesWebClient(webClientBuilder) - expect: 'the system can create an instance for model service' - assert modelServicesWebClient != null - assert modelServicesWebClient instanceof WebClient - } - - def 'Creating a web client instance health service.'() { - given: 'Web client configuration invoked' - def healthChecksWebClient = objectUnderTest.healthChecksWebClient(webClientBuilder) - expect: 'the system can create an instance for health service' - assert healthChecksWebClient != null - assert healthChecksWebClient instanceof WebClient - } -} diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/dmi/DmiWebClientsConfigurationSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/dmi/DmiWebClientsConfigurationSpec.groovy new file mode 100644 index 0000000000..cb209beef0 --- /dev/null +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/dmi/DmiWebClientsConfigurationSpec.groovy @@ -0,0 +1,70 @@ +/*- + * ============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 org.onap.cps.ncmp.config.DmiHttpClientConfig +import org.springframework.boot.context.properties.EnableConfigurationProperties +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.test.context.ContextConfiguration +import org.springframework.web.reactive.function.client.WebClient +import spock.lang.Specification + +@SpringBootTest +@ContextConfiguration(classes = [DmiHttpClientConfig]) +@EnableConfigurationProperties +class DmiWebClientsConfigurationSpec extends Specification { + + def webClientBuilder = Mock(WebClient.Builder) { + defaultHeaders(_) >> it + clientConnector(_) >> it + codecs(_) >> it + build() >> Mock(WebClient) + } + + def dmiHttpClientConfiguration = Spy(DmiHttpClientConfig.class) + + def objectUnderTest = new DmiWebClientsConfiguration(dmiHttpClientConfiguration) + + def 'Web client for data services.'() { + when: 'creating a web client for dmi data services' + def result = objectUnderTest.dataServicesWebClient(webClientBuilder) + then: 'a web client is created successfully' + assert result != null + assert result instanceof WebClient + } + + def 'Web client model services.'() { + when: 'creating a web client for dmi model services' + def result = objectUnderTest.modelServicesWebClient(webClientBuilder) + then: 'a web client is created successfully' + assert result != null + assert result instanceof WebClient + } + + def 'Web client health check services.'() { + when: 'creating a web client for dmi health check services' + def result = objectUnderTest.healthChecksWebClient(webClientBuilder) + then: 'a web client is created successfully' + assert result != null + assert result instanceof WebClient + } +} diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/policyexecutor/PolicyExecutorWebClientConfigurationSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/policyexecutor/PolicyExecutorWebClientConfigurationSpec.groovy new file mode 100644 index 0000000000..cf5e1a383c --- /dev/null +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/policyexecutor/PolicyExecutorWebClientConfigurationSpec.groovy @@ -0,0 +1,53 @@ +/*- + * ============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 org.onap.cps.ncmp.config.PolicyExecutorHttpClientConfig +import org.springframework.boot.context.properties.EnableConfigurationProperties +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.test.context.ContextConfiguration +import org.springframework.web.reactive.function.client.WebClient +import spock.lang.Specification + +@SpringBootTest +@ContextConfiguration(classes = [PolicyExecutorHttpClientConfig]) +@EnableConfigurationProperties +class PolicyExecutorWebClientConfigurationSpec extends Specification { + + def webClientBuilder = Mock(WebClient.Builder) { + defaultHeaders(_) >> it + clientConnector(_) >> it + codecs(_) >> it + build() >> Mock(WebClient) + } + + def httpClientConfiguration = Spy(PolicyExecutorHttpClientConfig.class) + + def objectUnderTest = new PolicyExecutorWebClientConfiguration(httpClientConfiguration) + + def 'Web client policy executor.'() { + when: 'create a web client for policy executor' + def result = objectUnderTest.policyExecutorWebClient(webClientBuilder) + then: 'a web client is created successfully' + assert result != null + assert result instanceof WebClient + } +} diff --git a/cps-ncmp-service/src/test/resources/application.yml b/cps-ncmp-service/src/test/resources/application.yml index 759de834ab..72d074ab5f 100644 --- a/cps-ncmp-service/src/test/resources/application.yml +++ b/cps-ncmp-service/src/test/resources/application.yml @@ -47,15 +47,26 @@ ncmp: dmi: httpclient: data-services: - pendingAcquireMaxCount: 22 - connectionTimeoutInSeconds: 123 - maximumInMemorySizeInMegabytes: 7 - readTimeoutInSeconds: 33 + maximumInMemorySizeInMegabytes: 1 + maximumConnectionsTotal: 2 + pendingAcquireMaxCount: 3 + connectionTimeoutInSeconds: 4 + readTimeoutInSeconds: 5 + writeTimeoutInSeconds: 6 model-services: - pendingAcquireMaxCount: 44 - connectionTimeoutInSeconds: 456 - maximumInMemorySizeInMegabytes: 8 - maximumConnectionsTotal: 111 + maximumInMemorySizeInMegabytes: 11 + maximumConnectionsTotal: 12 + pendingAcquireMaxCount: 13 + connectionTimeoutInSeconds: 14 + readTimeoutInSeconds: 15 + writeTimeoutInSeconds: 16 + healthCheckServices: + maximumInMemorySizeInMegabytes: 21 + maximumConnectionsTotal: 22 + pendingAcquireMaxCount: 23 + connectionTimeoutInSeconds: 24 + readTimeoutInSeconds: 25 + writeTimeoutInSeconds: 26 auth: username: some-user password: some-password @@ -75,6 +86,14 @@ ncmp: server: address: "http://localhost" port: "8785" + httpclient: + all-services: + maximumInMemorySizeInMegabytes: 31 + maximumConnectionsTotal: 32 + pendingAcquireMaxCount: 33 + connectionTimeoutInSeconds: 34 + readTimeoutInSeconds: 35 + writeTimeoutInSeconds: 36 # Custom Hazelcast Config. hazelcast: diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/DataJobResultServiceSpec.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/DataJobResultServiceSpec.groovy index 241d31a642..4d04eeeb81 100644 --- a/integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/DataJobResultServiceSpec.groovy +++ b/integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/DataJobResultServiceSpec.groovy @@ -39,7 +39,6 @@ class DataJobResultServiceSpec extends CpsIntegrationSpecBase { when: 'the data job status checked' def result = dataJobResultService.getDataJobResult(authorization, dmiServiceName, dataProducerId, dataProducerJobId, destination) then: 'the status is that defined in the mock service.' - assert result != null assert result == '{ "result": "some result"}' } } |