diff options
Diffstat (limited to 'cps-ncmp-service/src/main')
16 files changed, 240 insertions, 102 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..0cedeae0a4 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,15 +41,16 @@ 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; -import org.onap.cps.ncmp.impl.dmi.DmiServiceUrlTemplateBuilder; -import org.onap.cps.ncmp.impl.dmi.UrlTemplateParameters; import org.onap.cps.ncmp.impl.inventory.InventoryPersistence; import org.onap.cps.ncmp.impl.inventory.models.CmHandleState; import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle; import org.onap.cps.ncmp.impl.models.DmiRequestBody; +import org.onap.cps.ncmp.impl.utils.http.RestServiceUrlTemplateBuilder; +import org.onap.cps.ncmp.impl.utils.http.UrlTemplateParameters; import org.onap.cps.spi.exceptions.CpsException; import org.onap.cps.utils.JsonObjectMapper; import org.springframework.http.ResponseEntity; @@ -212,7 +213,7 @@ public class DmiDataOperations { final String optionsParamInQuery, final String topicParamInQuery) { final String dmiServiceName = yangModelCmHandle.resolveDmiServiceName(DATA); - return DmiServiceUrlTemplateBuilder.newInstance() + return RestServiceUrlTemplateBuilder.newInstance() .fixedPathSegment("ch") .variablePathSegment("cmHandleId", yangModelCmHandle.getId()) .fixedPathSegment("data") @@ -227,7 +228,7 @@ public class DmiDataOperations { private UrlTemplateParameters getUrlTemplateParameters(final String dmiServiceName, final String requestId, final String topicParamInQuery) { - return DmiServiceUrlTemplateBuilder.newInstance() + return RestServiceUrlTemplateBuilder.newInstance() .fixedPathSegment("data") .queryParameter("requestId", requestId) .queryParameter("topic", topicParamInQuery) 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/datajobs/DataJobResultServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DataJobResultServiceImpl.java index 031cedc78b..8934c088a1 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DataJobResultServiceImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DataJobResultServiceImpl.java @@ -24,8 +24,8 @@ import lombok.RequiredArgsConstructor; import org.onap.cps.ncmp.api.datajobs.DataJobResultService; import org.onap.cps.ncmp.impl.dmi.DmiProperties; import org.onap.cps.ncmp.impl.dmi.DmiRestClient; -import org.onap.cps.ncmp.impl.dmi.DmiServiceUrlTemplateBuilder; -import org.onap.cps.ncmp.impl.dmi.UrlTemplateParameters; +import org.onap.cps.ncmp.impl.utils.http.RestServiceUrlTemplateBuilder; +import org.onap.cps.ncmp.impl.utils.http.UrlTemplateParameters; import org.springframework.stereotype.Service; @Service @@ -41,7 +41,7 @@ public class DataJobResultServiceImpl implements DataJobResultService { final String dataProducerId, final String dataProducerJobId, final String destination) { - final UrlTemplateParameters urlTemplateParameters = DmiServiceUrlTemplateBuilder.newInstance() + final UrlTemplateParameters urlTemplateParameters = RestServiceUrlTemplateBuilder.newInstance() .fixedPathSegment("cmwriteJob") .fixedPathSegment("dataProducer") .variablePathSegment("dataProducerId", dataProducerId) diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DataJobStatusServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DataJobStatusServiceImpl.java index fb17f066ce..1cfb8a9dff 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DataJobStatusServiceImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DataJobStatusServiceImpl.java @@ -24,8 +24,8 @@ import lombok.RequiredArgsConstructor; import org.onap.cps.ncmp.api.datajobs.DataJobStatusService; import org.onap.cps.ncmp.impl.dmi.DmiProperties; import org.onap.cps.ncmp.impl.dmi.DmiRestClient; -import org.onap.cps.ncmp.impl.dmi.DmiServiceUrlTemplateBuilder; -import org.onap.cps.ncmp.impl.dmi.UrlTemplateParameters; +import org.onap.cps.ncmp.impl.utils.http.RestServiceUrlTemplateBuilder; +import org.onap.cps.ncmp.impl.utils.http.UrlTemplateParameters; import org.springframework.stereotype.Service; /** @@ -54,7 +54,7 @@ public class DataJobStatusServiceImpl implements DataJobStatusService { private UrlTemplateParameters buildUrlParameters(final String dmiServiceName, final String dataProducerId, final String dataProducerJobId) { - return DmiServiceUrlTemplateBuilder.newInstance() + return RestServiceUrlTemplateBuilder.newInstance() .fixedPathSegment("cmwriteJob") .fixedPathSegment("dataProducer") .variablePathSegment("dataProducerId", dataProducerId) diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DmiSubJobRequestHandler.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DmiSubJobRequestHandler.java index 0d14dace5e..a118d53e7e 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DmiSubJobRequestHandler.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DmiSubJobRequestHandler.java @@ -33,9 +33,9 @@ import org.onap.cps.ncmp.api.datajobs.models.SubJobWriteRequest; import org.onap.cps.ncmp.api.datajobs.models.SubJobWriteResponse; import org.onap.cps.ncmp.impl.dmi.DmiProperties; import org.onap.cps.ncmp.impl.dmi.DmiRestClient; -import org.onap.cps.ncmp.impl.dmi.DmiServiceUrlTemplateBuilder; -import org.onap.cps.ncmp.impl.dmi.UrlTemplateParameters; import org.onap.cps.ncmp.impl.models.RequiredDmiService; +import org.onap.cps.ncmp.impl.utils.http.RestServiceUrlTemplateBuilder; +import org.onap.cps.ncmp.impl.utils.http.UrlTemplateParameters; import org.onap.cps.utils.JsonObjectMapper; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; @@ -88,7 +88,7 @@ public class DmiSubJobRequestHandler { } private UrlTemplateParameters getUrlTemplateParameters(final String destination, final ProducerKey producerKey) { - return DmiServiceUrlTemplateBuilder.newInstance() + return RestServiceUrlTemplateBuilder.newInstance() .fixedPathSegment("cmwriteJob") .queryParameter("destination", destination) .createUrlTemplateParameters(producerKey.dmiServiceName(), dmiProperties.getDmiBasePath()); diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/dmi/DmiRestClient.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/dmi/DmiRestClient.java index c10132060d..a177272dff 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/dmi/DmiRestClient.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/dmi/DmiRestClient.java @@ -34,6 +34,7 @@ import lombok.extern.slf4j.Slf4j; import org.onap.cps.ncmp.api.data.models.OperationType; import org.onap.cps.ncmp.api.exceptions.DmiClientRequestException; import org.onap.cps.ncmp.impl.models.RequiredDmiService; +import org.onap.cps.ncmp.impl.utils.http.UrlTemplateParameters; import org.onap.cps.utils.JsonObjectMapper; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.http.HttpHeaders; 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..4134a56ead --- /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.http.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/inventory/sync/DmiModelOperations.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/DmiModelOperations.java index 433c67f100..8ba70b3a31 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/DmiModelOperations.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/DmiModelOperations.java @@ -36,10 +36,10 @@ import lombok.RequiredArgsConstructor; import org.onap.cps.ncmp.api.inventory.models.YangResource; import org.onap.cps.ncmp.impl.dmi.DmiProperties; import org.onap.cps.ncmp.impl.dmi.DmiRestClient; -import org.onap.cps.ncmp.impl.dmi.DmiServiceUrlTemplateBuilder; -import org.onap.cps.ncmp.impl.dmi.UrlTemplateParameters; import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle; import org.onap.cps.ncmp.impl.models.DmiRequestBody; +import org.onap.cps.ncmp.impl.utils.http.RestServiceUrlTemplateBuilder; +import org.onap.cps.ncmp.impl.utils.http.UrlTemplateParameters; import org.onap.cps.spi.model.ModuleReference; import org.onap.cps.utils.JsonObjectMapper; import org.springframework.http.ResponseEntity; @@ -107,7 +107,7 @@ public class DmiModelOperations { final String jsonRequestBody, final String cmHandle, final String resourceName) { - final UrlTemplateParameters urlTemplateParameters = DmiServiceUrlTemplateBuilder.newInstance() + final UrlTemplateParameters urlTemplateParameters = RestServiceUrlTemplateBuilder.newInstance() .fixedPathSegment("ch") .variablePathSegment("cmHandleId", cmHandle) .fixedPathSegment(resourceName) diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/DmiPluginTrustLevelWatchDog.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/DmiPluginTrustLevelWatchDog.java index 94e493d8bf..7581c4af7a 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/DmiPluginTrustLevelWatchDog.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/DmiPluginTrustLevelWatchDog.java @@ -26,9 +26,9 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.onap.cps.ncmp.api.inventory.models.TrustLevel; import org.onap.cps.ncmp.impl.dmi.DmiRestClient; -import org.onap.cps.ncmp.impl.dmi.DmiServiceUrlTemplateBuilder; -import org.onap.cps.ncmp.impl.dmi.UrlTemplateParameters; import org.onap.cps.ncmp.impl.inventory.CmHandleQueryService; +import org.onap.cps.ncmp.impl.utils.http.RestServiceUrlTemplateBuilder; +import org.onap.cps.ncmp.impl.utils.http.UrlTemplateParameters; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; @@ -73,7 +73,7 @@ public class DmiPluginTrustLevelWatchDog { } private String getDmiHealthStatus(final String dmiServiceBaseUrl) { - final UrlTemplateParameters urlTemplateParameters = DmiServiceUrlTemplateBuilder.newInstance() + final UrlTemplateParameters urlTemplateParameters = RestServiceUrlTemplateBuilder.newInstance() .createUrlTemplateParametersForHealthCheck(dmiServiceBaseUrl); return dmiRestClient.getDmiHealthStatus(urlTemplateParameters).block(); } 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..333030ccd2 --- /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.http.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/DmiServiceUrlTemplateBuilder.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/http/RestServiceUrlTemplateBuilder.java index e7dbea83f2..fafb09007d 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/dmi/DmiServiceUrlTemplateBuilder.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/http/RestServiceUrlTemplateBuilder.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.cps.ncmp.impl.dmi; +package org.onap.cps.ncmp.impl.utils.http; import java.util.Collections; import java.util.HashMap; @@ -30,7 +30,7 @@ import org.apache.logging.log4j.util.Strings; import org.springframework.web.util.UriComponentsBuilder; @NoArgsConstructor -public class DmiServiceUrlTemplateBuilder { +public class RestServiceUrlTemplateBuilder { private final UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.newInstance(); private static final String FIXED_PATH_SEGMENT = null; @@ -43,8 +43,8 @@ public class DmiServiceUrlTemplateBuilder { * * @return a new instance of DmiServiceUrlTemplateBuilder */ - public static DmiServiceUrlTemplateBuilder newInstance() { - return new DmiServiceUrlTemplateBuilder(); + public static RestServiceUrlTemplateBuilder newInstance() { + return new RestServiceUrlTemplateBuilder(); } /** @@ -53,7 +53,7 @@ public class DmiServiceUrlTemplateBuilder { * @param pathSegment the path segment * @return this builder instance */ - public DmiServiceUrlTemplateBuilder fixedPathSegment(final String pathSegment) { + public RestServiceUrlTemplateBuilder fixedPathSegment(final String pathSegment) { pathSegments.put(pathSegment, FIXED_PATH_SEGMENT); return this; } @@ -66,7 +66,7 @@ public class DmiServiceUrlTemplateBuilder { * @param value the value to be insert in teh URL for the given variable path segment * @return this builder instance */ - public DmiServiceUrlTemplateBuilder variablePathSegment(final String pathSegment, final String value) { + public RestServiceUrlTemplateBuilder variablePathSegment(final String pathSegment, final String value) { pathSegments.put(pathSegment, value); return this; } @@ -80,8 +80,8 @@ public class DmiServiceUrlTemplateBuilder { * * @return this builder instance */ - public DmiServiceUrlTemplateBuilder queryParameter(final String queryParameterName, - final String queryParameterValue) { + public RestServiceUrlTemplateBuilder queryParameter(final String queryParameterName, + final String queryParameterValue) { if (Strings.isNotBlank(queryParameterValue)) { queryParameters.put(queryParameterName, queryParameterValue); } @@ -91,12 +91,12 @@ public class DmiServiceUrlTemplateBuilder { /** * Constructs a URL template with variables based on the accumulated path segments and query parameters. * - * @param dmiServiceBaseUrl the base URL of the DMI service, e.g., "http://dmi-service.com". - * @param dmiBasePath the base path of the DMI service + * @param serviceBaseUrl the base URL of the service, e.g., "http://dmi-service.com". + * @param basePath the base path of the service * @return a UrlTemplateParameters instance containing the complete URL template and URL variables */ - public UrlTemplateParameters createUrlTemplateParameters(final String dmiServiceBaseUrl, final String dmiBasePath) { - this.uriComponentsBuilder.pathSegment(dmiBasePath) + public UrlTemplateParameters createUrlTemplateParameters(final String serviceBaseUrl, final String basePath) { + this.uriComponentsBuilder.pathSegment(basePath) .pathSegment(VERSION_SEGMENT); final Map<String, String> urlTemplateVariables = new HashMap<>(); @@ -115,22 +115,21 @@ public class DmiServiceUrlTemplateBuilder { urlTemplateVariables.put(paramName, paramValue); }); - final String urlTemplate = dmiServiceBaseUrl + this.uriComponentsBuilder.build().toUriString(); + final String urlTemplate = serviceBaseUrl + this.uriComponentsBuilder.build().toUriString(); return new UrlTemplateParameters(urlTemplate, urlTemplateVariables); } /** * Constructs a URL for DMI health check based on the given base URL. * - * @param dmiServiceBaseUrl the base URL of the DMI service, e.g., "http://dmi-service.com". + * @param serviceBaseUrl the base URL of the service, e.g., "http://dmi-service.com". * @return a {@link UrlTemplateParameters} instance containing the complete URL template and empty URL variables, * suitable for DMI health check. */ - public UrlTemplateParameters createUrlTemplateParametersForHealthCheck(final String dmiServiceBaseUrl) { - this.uriComponentsBuilder.pathSegment("actuator") - .pathSegment("health"); + public UrlTemplateParameters createUrlTemplateParametersForHealthCheck(final String serviceBaseUrl) { + this.uriComponentsBuilder.pathSegment("actuator").pathSegment("health"); - final String urlTemplate = dmiServiceBaseUrl + this.uriComponentsBuilder.build().toUriString(); + final String urlTemplate = serviceBaseUrl + this.uriComponentsBuilder.build().toUriString(); return new UrlTemplateParameters(urlTemplate, Collections.emptyMap()); } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/dmi/UrlTemplateParameters.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/http/UrlTemplateParameters.java index f51511116a..839af71823 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/dmi/UrlTemplateParameters.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/http/UrlTemplateParameters.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.cps.ncmp.impl.dmi; +package org.onap.cps.ncmp.impl.utils.http; import java.util.Map; 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/http/WebClientConfiguration.java index c176e40226..d8e8350345 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/http/WebClientConfiguration.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.cps.ncmp.impl.dmi; +package org.onap.cps.ncmp.impl.utils.http; 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()) |