diff options
Diffstat (limited to 'cps-ncmp-service/src/main/java/org/onap')
10 files changed, 330 insertions, 334 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/client/DmiRestClient.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/client/DmiRestClient.java index 39219bd371..ac7728da92 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/client/DmiRestClient.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/client/DmiRestClient.java @@ -24,20 +24,17 @@ package org.onap.cps.ncmp.api.impl.client; import static org.onap.cps.ncmp.api.NcmpResponseStatus.DMI_SERVICE_NOT_RESPONDING; import static org.onap.cps.ncmp.api.NcmpResponseStatus.UNABLE_TO_READ_RESOURCE_DATA; import static org.onap.cps.ncmp.api.NcmpResponseStatus.UNKNOWN_ERROR; -import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; import static org.springframework.http.HttpStatus.REQUEST_TIMEOUT; import com.fasterxml.jackson.databind.JsonNode; -import java.net.URI; -import java.net.URISyntaxException; import java.util.Locale; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.onap.cps.ncmp.api.data.models.OperationType; import org.onap.cps.ncmp.api.impl.config.DmiProperties; import org.onap.cps.ncmp.api.impl.exception.DmiClientRequestException; -import org.onap.cps.ncmp.api.impl.exception.InvalidDmiResourceUrlException; +import org.onap.cps.ncmp.api.impl.utils.url.builder.UrlTemplateParameters; import org.onap.cps.ncmp.impl.models.RequiredDmiService; import org.onap.cps.utils.JsonObjectMapper; import org.springframework.beans.factory.annotation.Qualifier; @@ -57,7 +54,6 @@ import reactor.core.publisher.Mono; @Slf4j public class DmiRestClient { - private static final String HEALTH_CHECK_URL_EXTENSION = "/actuator/health"; private static final String NOT_SPECIFIED = ""; private static final String NO_AUTHORIZATION = null; @@ -74,7 +70,7 @@ public class DmiRestClient { * Sends a synchronous (blocking) POST operation to the DMI with a JSON body containing module references. * * @param requiredDmiService Determines if the required service is for a data or model operation. - * @param dmiUrl The DMI resource URL. + * @param urlTemplateParameters The DMI resource URL template with variables. * @param requestBodyAsJsonString JSON data body. * @param operationType The type of operation being executed (for error reporting only). * @param authorization Contents of the Authorization header, or null if not present. @@ -82,13 +78,14 @@ public class DmiRestClient { * @throws DmiClientRequestException If there is an error during the DMI request. */ public ResponseEntity<Object> synchronousPostOperationWithJsonData(final RequiredDmiService requiredDmiService, - final String dmiUrl, + final UrlTemplateParameters + urlTemplateParameters, final String requestBodyAsJsonString, final OperationType operationType, final String authorization) { final Mono<ResponseEntity<Object>> responseEntityMono = asynchronousPostOperationWithJsonData(requiredDmiService, - dmiUrl, + urlTemplateParameters, requestBodyAsJsonString, operationType, authorization); @@ -99,22 +96,23 @@ public class DmiRestClient { * Asynchronously performs an HTTP POST operation with the given JSON data. * * @param requiredDmiService The service object required for retrieving or configuring the WebClient. - * @param dmiUrl The URL to which the POST request is sent. + * @param urlTemplateParameters The URL template with variables for the POST request. * @param requestBodyAsJsonString The JSON string that will be sent as the request body. * @param operationType An enumeration or object that holds information about the type of operation * being performed. * @param authorization The authorization token to be added to the request headers. * @return A Mono emitting the response entity containing the server's response. */ - public Mono<ResponseEntity<Object>> asynchronousPostOperationWithJsonData( - final RequiredDmiService requiredDmiService, - final String dmiUrl, - final String requestBodyAsJsonString, - final OperationType operationType, - final String authorization) { + public Mono<ResponseEntity<Object>> asynchronousPostOperationWithJsonData(final RequiredDmiService + requiredDmiService, + final UrlTemplateParameters + urlTemplateParameters, + final String requestBodyAsJsonString, + final OperationType operationType, + final String authorization) { final WebClient webClient = getWebClient(requiredDmiService); return webClient.post() - .uri(toUri(dmiUrl)) + .uri(urlTemplateParameters.urlTemplate(), urlTemplateParameters.urlVariables()) .headers(httpHeaders -> configureHttpHeaders(httpHeaders, authorization)) .body(BodyInserters.fromValue(requestBodyAsJsonString)) .retrieve() @@ -123,25 +121,29 @@ public class DmiRestClient { } /** - * Get DMI plugin health status. + * Retrieves the health status of the DMI plugin. + * This method performs an HTTP GET request to the DMI health check endpoint specified by the URL template + * parameters. If the response status code indicates a client error (4xx) or a server error (5xx), it logs a warning + * and returns an empty Mono. In case of an error during the request, it logs the exception and returns a default + * value of "NOT_SPECIFIED". If the response body contains a JSON node with a "status" field, the value of this + * field is returned. * - * @param dmiUrl the base URL of the dmi-plugin - * @return plugin health status ("UP" is all OK, "" (not-specified) in case of any exception) + * @param urlTemplateParameters the URL template parameters for the DMI health check endpoint + * @return a Mono emitting the health status as a String, or "NOT_SPECIFIED" if an error occurs */ - public String getDmiHealthStatus(final String dmiUrl) { - try { - final URI dmiHealthCheckUri = toUri(dmiUrl + HEALTH_CHECK_URL_EXTENSION); - final JsonNode responseHealthStatus = healthChecksWebClient.get() - .uri(dmiHealthCheckUri) - .headers(httpHeaders -> configureHttpHeaders(httpHeaders, NO_AUTHORIZATION)) - .retrieve() - .bodyToMono(JsonNode.class).block(); - return responseHealthStatus == null ? NOT_SPECIFIED : - responseHealthStatus.path("status").asText(); - } catch (final Exception e) { - log.warn("Failed to retrieve health status from {}. Error Message: {}", dmiUrl, e.getMessage()); - return NOT_SPECIFIED; - } + public Mono<String> getDmiHealthStatus(final UrlTemplateParameters urlTemplateParameters) { + return healthChecksWebClient.get() + .uri(urlTemplateParameters.urlTemplate(), urlTemplateParameters.urlVariables()) + .headers(httpHeaders -> configureHttpHeaders(httpHeaders, NO_AUTHORIZATION)) + .retrieve() + .bodyToMono(JsonNode.class) + .map(responseHealthStatus -> responseHealthStatus.path("status").asText()) + .onErrorResume(Exception.class, ex -> { + log.warn("Failed to retrieve health status from {}. Status: {}", + urlTemplateParameters.urlTemplate(), ex.getMessage()); + return Mono.empty(); + }) + .defaultIfEmpty(NOT_SPECIFIED); } private WebClient getWebClient(final RequiredDmiService requiredDmiService) { @@ -156,14 +158,6 @@ public class DmiRestClient { } } - private static URI toUri(final String dmiResourceUrl) { - try { - return new URI(dmiResourceUrl); - } catch (final URISyntaxException e) { - throw new InvalidDmiResourceUrlException(dmiResourceUrl, BAD_REQUEST.value()); - } - } - private DmiClientRequestException handleDmiClientException(final Throwable throwable, final String operationType) { if (throwable instanceof WebClientResponseException webClientResponseException) { if (webClientResponseException.getStatusCode().isSameCodeAs(REQUEST_TIMEOUT)) { diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/DmiWebClientConfiguration.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/DmiWebClientConfiguration.java index 3a861a68b4..be46105d13 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/DmiWebClientConfiguration.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/DmiWebClientConfiguration.java @@ -47,68 +47,46 @@ import reactor.netty.resources.ConnectionProvider; public class DmiWebClientConfiguration { private final HttpClientConfiguration httpClientConfiguration; - private static final Duration DEFAULT_RESPONSE_TIMEOUT = Duration.ofSeconds(30); /** - * Configures and creates a WebClient bean for DMI data services. + * 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 HttpClientConfiguration.DataServices dataServiceConfig = httpClientConfiguration.getDataServices(); - final ConnectionProvider dataServicesConnectionProvider - = getConnectionProvider(dataServiceConfig.getConnectionProviderName(), - dataServiceConfig.getMaximumConnectionsTotal(), dataServiceConfig.getPendingAcquireMaxCount()); - final HttpClient dataServicesHttpClient = createHttpClient(dataServiceConfig, dataServicesConnectionProvider); - return buildAndGetWebClient(dataServicesHttpClient, dataServiceConfig.getMaximumInMemorySizeInMegabytes()); + public WebClient dataServicesWebClient(final WebClient.Builder webClientBuilder) { + return configureWebClient(webClientBuilder, httpClientConfiguration.getDataServices()); } /** - * Configures and creates a WebClient bean for DMI model services. + * 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 HttpClientConfiguration.ModelServices modelServiceConfig = httpClientConfiguration.getModelServices(); - final ConnectionProvider modelServicesConnectionProvider - = getConnectionProvider(modelServiceConfig.getConnectionProviderName(), - modelServiceConfig.getMaximumConnectionsTotal(), - modelServiceConfig.getPendingAcquireMaxCount()); - final HttpClient modelServicesHttpClient - = createHttpClient(modelServiceConfig, modelServicesConnectionProvider); - return buildAndGetWebClient(modelServicesHttpClient, modelServiceConfig.getMaximumInMemorySizeInMegabytes()); + public WebClient modelServicesWebClient(final WebClient.Builder webClientBuilder) { + return configureWebClient(webClientBuilder, httpClientConfiguration.getModelServices()); } /** - * Configures and creates a WebClient bean for DMI health check services. + * 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 HttpClientConfiguration.HealthCheckServices healthCheckServiceConfig - = httpClientConfiguration.getHealthCheckServices(); - final ConnectionProvider healthChecksConnectionProvider - = getConnectionProvider(healthCheckServiceConfig.getConnectionProviderName(), - healthCheckServiceConfig.getMaximumConnectionsTotal(), - healthCheckServiceConfig.getPendingAcquireMaxCount()); - final HttpClient healthChecksHttpClient - = createHttpClient(healthCheckServiceConfig, healthChecksConnectionProvider); - return buildAndGetWebClient(healthChecksHttpClient, - healthCheckServiceConfig.getMaximumInMemorySizeInMegabytes()); + public WebClient healthChecksWebClient(final WebClient.Builder webClientBuilder) { + return configureWebClient(webClientBuilder, httpClientConfiguration.getHealthCheckServices()); } - /** - * Provides a WebClient.Builder bean for creating WebClient instances. - * - * @return a WebClient.Builder instance. - */ - @Bean - public WebClient.Builder webClientBuilder() { - return WebClient.builder(); + private WebClient configureWebClient(final WebClient.Builder webClientBuilder, + final HttpClientConfiguration.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, @@ -124,18 +102,16 @@ public class DmiWebClientConfiguration { } @SuppressFBWarnings("BC_UNCONFIRMED_CAST_OF_RETURN_VALUE") - private static ConnectionProvider getConnectionProvider(final String connectionProviderName, - final int maximumConnectionsTotal, - final int pendingAcquireMaxCount) { - return ConnectionProvider.builder(connectionProviderName) - .maxConnections(maximumConnectionsTotal) - .pendingAcquireMaxCount(pendingAcquireMaxCount) + private static ConnectionProvider getConnectionProvider(final HttpClientConfiguration.ServiceConfig serviceConfig) { + return ConnectionProvider.builder(serviceConfig.getConnectionProviderName()) + .maxConnections(serviceConfig.getMaximumConnectionsTotal()) + .pendingAcquireMaxCount(serviceConfig.getPendingAcquireMaxCount()) .build(); } - private WebClient buildAndGetWebClient(final HttpClient httpClient, - final int maximumInMemorySizeInMegabytes) { - return webClientBuilder() + private WebClient buildAndGetWebClient(final WebClient.Builder webClientBuilder, final HttpClient httpClient, + final int maximumInMemorySizeInMegabytes) { + return webClientBuilder .defaultHeaders(header -> header.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)) .defaultHeaders(header -> header.set(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)) .clientConnector(new ReactorClientHttpConnector(httpClient)) diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/exception/InvalidDmiResourceUrlException.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/exception/InvalidDmiResourceUrlException.java deleted file mode 100644 index 270988b63b..0000000000 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/exception/InvalidDmiResourceUrlException.java +++ /dev/null @@ -1,37 +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.api.impl.exception; - -import lombok.Getter; - -@Getter -public class InvalidDmiResourceUrlException extends RuntimeException { - - private static final long serialVersionUID = 2928476384584894968L; - - private static final String INVALID_DMI_URL = "Invalid dmi resource url"; - final Integer httpStatus; - - public InvalidDmiResourceUrlException(final String details, final Integer httpStatus) { - super(String.format(INVALID_DMI_URL + ": %s", details)); - this.httpStatus = httpStatus; - } -} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/DmiServiceUrlBuilder.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/DmiServiceUrlBuilder.java deleted file mode 100644 index aeeeb6430f..0000000000 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/DmiServiceUrlBuilder.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2022-2023 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.api.impl.utils; - -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; -import lombok.NoArgsConstructor; -import org.apache.logging.log4j.util.Strings; -import org.springframework.web.util.UriComponentsBuilder; - -@NoArgsConstructor -public class DmiServiceUrlBuilder { - - private static final String FIXED_PATH_SEGMENT = null; - - final UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.newInstance(); - final Map<String, Object> pathSegments = new LinkedHashMap<>(); - - public static DmiServiceUrlBuilder newInstance() { - return new DmiServiceUrlBuilder(); - } - - /** - * Add a fixed pathSegment to the URI. - * - * @param pathSegment the path segment - * @return this builder - */ - public DmiServiceUrlBuilder pathSegment(final String pathSegment) { - pathSegments.put(pathSegment, FIXED_PATH_SEGMENT); - return this; - } - - /** - * Add a variable pathSegment to the URI. - * Do NOT add { } braces. the builder will take care of that - * - * @param pathSegment the name of the variable path segment (with { and } - * @param value the value to be insert in teh URI for the given variable path segment - * @return this builder - */ - public DmiServiceUrlBuilder variablePathSegment(final String pathSegment, final Object value) { - pathSegments.put(pathSegment, value); - return this; - } - - /** - * Add a query parameter to the URI. - * Do NOT encode as the builder wil take care of encoding - * - * @param name the name of the variable - * @param value the value of the variable (only Strings are supported). - * - * @return this builder - */ - public DmiServiceUrlBuilder queryParameter(final String name, final String value) { - if (Strings.isNotBlank(value)) { - uriComponentsBuilder.queryParam(name, value); - } - return this; - } - - /** - * Build the URI as a correctly percentage-encoded String. - * - * @param dmiServiceName the name of the dmi service - * @param dmiBasePath the base path of the dmi service - * - * @return URI as a string - */ - public String build(final String dmiServiceName, final String dmiBasePath) { - uriComponentsBuilder - .path("{dmiServiceName}") - .pathSegment("{dmiBasePath}") - .pathSegment("v1"); - - final Map<String, Object> uriVariables = new HashMap<>(); - uriVariables.put("dmiServiceName", dmiServiceName); - uriVariables.put("dmiBasePath", dmiBasePath); - - pathSegments.forEach((pathSegment, variablePathValue) -> { - if (variablePathValue == FIXED_PATH_SEGMENT) { - uriComponentsBuilder.pathSegment(pathSegment); - } else { - uriComponentsBuilder.pathSegment("{" + pathSegment + "}"); - uriVariables.put(pathSegment, variablePathValue); - } - }); - return uriComponentsBuilder.buildAndExpand(uriVariables).encode().toUriString(); - } - -} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/url/builder/DmiServiceUrlTemplateBuilder.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/url/builder/DmiServiceUrlTemplateBuilder.java new file mode 100644 index 0000000000..b89b7b3221 --- /dev/null +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/url/builder/DmiServiceUrlTemplateBuilder.java @@ -0,0 +1,137 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2022-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.api.impl.utils.url.builder; + +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import lombok.NoArgsConstructor; +import org.apache.commons.lang3.StringUtils; +import org.apache.logging.log4j.util.Strings; +import org.springframework.web.util.UriComponentsBuilder; + +@NoArgsConstructor +public class DmiServiceUrlTemplateBuilder { + + private final UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.newInstance(); + private static final String FIXED_PATH_SEGMENT = null; + private static final String VERSION_SEGMENT = "v1"; + private final Map<String, String> pathSegments = new LinkedHashMap<>(); + private final Map<String, String> queryParameters = new LinkedHashMap<>(); + + /** + * Static factory method to create a new instance of DmiServiceUrlTemplateBuilder. + * + * @return a new instance of DmiServiceUrlTemplateBuilder + */ + public static DmiServiceUrlTemplateBuilder newInstance() { + return new DmiServiceUrlTemplateBuilder(); + } + + /** + * Add a fixed pathSegment to the URL. + * + * @param pathSegment the path segment + * @return this builder instance + */ + public DmiServiceUrlTemplateBuilder fixedPathSegment(final String pathSegment) { + pathSegments.put(pathSegment, FIXED_PATH_SEGMENT); + return this; + } + + /** + * Add a variable pathSegment to the URL. + * Do NOT add { } braces. the builder will take care of that + * + * @param pathSegment the name of the variable path segment (with { and } + * @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) { + pathSegments.put(pathSegment, value); + return this; + } + + /** + * Add a query parameter to the URL. + * Do NOT encode as the builder wil take care of encoding + * + * @param queryParameterName the name of the variable + * @param queryParameterValue the value of the variable (only Strings are supported). + * + * @return this builder instance + */ + public DmiServiceUrlTemplateBuilder queryParameter(final String queryParameterName, + final String queryParameterValue) { + if (Strings.isNotBlank(queryParameterValue)) { + queryParameters.put(queryParameterName, queryParameterValue); + } + return this; + } + + /** + * 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 + * @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) + .pathSegment(VERSION_SEGMENT); + + final Map<String, String> urlTemplateVariables = new HashMap<>(); + + pathSegments.forEach((pathSegmentName, variablePathValue) -> { + if (StringUtils.equals(variablePathValue, FIXED_PATH_SEGMENT)) { + this.uriComponentsBuilder.pathSegment(pathSegmentName); + } else { + this.uriComponentsBuilder.pathSegment("{" + pathSegmentName + "}"); + urlTemplateVariables.put(pathSegmentName, variablePathValue); + } + }); + + queryParameters.forEach((paramName, paramValue) -> { + this.uriComponentsBuilder.queryParam(paramName, "{" + paramName + "}"); + urlTemplateVariables.put(paramName, paramValue); + }); + + final String urlTemplate = dmiServiceBaseUrl + 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". + * @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"); + + final String urlTemplate = dmiServiceBaseUrl + this.uriComponentsBuilder.build().toUriString(); + return new UrlTemplateParameters(urlTemplate, Collections.emptyMap()); + } + +} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/url/builder/UrlTemplateParameters.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/url/builder/UrlTemplateParameters.java new file mode 100644 index 0000000000..edf56197b5 --- /dev/null +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/url/builder/UrlTemplateParameters.java @@ -0,0 +1,30 @@ +/* + * ============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.api.impl.utils.url.builder; + +import java.util.Map; + +/** + * Represents a URL template with associated variables for dynamic substitution. + * This record encapsulates a URL template string and a map of variables used for substitution within the template. + */ +public record UrlTemplateParameters(String urlTemplate, Map<String, String> urlVariables) { +} 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 e6bb712861..efe0335e8c 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 @@ -23,6 +23,8 @@ package org.onap.cps.ncmp.impl.data; import static org.onap.cps.ncmp.api.data.models.DatastoreType.PASSTHROUGH_OPERATIONAL; import static org.onap.cps.ncmp.api.data.models.DatastoreType.PASSTHROUGH_RUNNING; +import static org.onap.cps.ncmp.api.data.models.OperationType.READ; +import static org.onap.cps.ncmp.impl.models.RequiredDmiService.DATA; import io.micrometer.core.annotation.Timed; import java.util.Collection; @@ -38,7 +40,8 @@ import org.onap.cps.ncmp.api.data.models.OperationType; import org.onap.cps.ncmp.api.impl.client.DmiRestClient; import org.onap.cps.ncmp.api.impl.config.DmiProperties; import org.onap.cps.ncmp.api.impl.exception.DmiClientRequestException; -import org.onap.cps.ncmp.api.impl.utils.DmiServiceUrlBuilder; +import org.onap.cps.ncmp.api.impl.utils.url.builder.DmiServiceUrlTemplateBuilder; +import org.onap.cps.ncmp.api.impl.utils.url.builder.UrlTemplateParameters; 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; @@ -47,7 +50,6 @@ 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.models.RequiredDmiService; import org.onap.cps.spi.exceptions.CpsException; import org.onap.cps.utils.JsonObjectMapper; import org.springframework.http.ResponseEntity; @@ -92,11 +94,11 @@ public class DmiDataOperations { final YangModelCmHandle yangModelCmHandle = getYangModelCmHandle(cmResourceAddress.cmHandleId()); final CmHandleState cmHandleState = yangModelCmHandle.getCompositeState().getCmHandleState(); validateIfCmHandleStateReady(yangModelCmHandle, cmHandleState); - final String jsonRequestBody = getDmiRequestBody(OperationType.READ, requestId, null, null, yangModelCmHandle); - final String dmiUrl = getDmiResourceDataUrl(cmResourceAddress.datastoreName(), yangModelCmHandle, - cmResourceAddress.resourceIdentifier(), options, topic); - return dmiRestClient.asynchronousPostOperationWithJsonData(RequiredDmiService.DATA, - dmiUrl, jsonRequestBody, OperationType.READ, authorization); + final String jsonRequestBody = getDmiRequestBody(READ, requestId, null, null, yangModelCmHandle); + final UrlTemplateParameters urlTemplateParameters = getUrlTemplateParameters(cmResourceAddress + .datastoreName(), yangModelCmHandle, cmResourceAddress.resourceIdentifier(), options, topic); + return dmiRestClient.asynchronousPostOperationWithJsonData(DATA, urlTemplateParameters, jsonRequestBody, READ, + authorization); } /** @@ -113,11 +115,12 @@ public class DmiDataOperations { final CmHandleState cmHandleState = yangModelCmHandle.getCompositeState().getCmHandleState(); validateIfCmHandleStateReady(yangModelCmHandle, cmHandleState); - final String jsonRequestBody = getDmiRequestBody(OperationType.READ, requestId, null, null, yangModelCmHandle); - final String dmiUrl = - getDmiResourceDataUrl(PASSTHROUGH_OPERATIONAL.getDatastoreName(), yangModelCmHandle, "/", null, null); - return dmiRestClient.synchronousPostOperationWithJsonData(RequiredDmiService.DATA, dmiUrl, jsonRequestBody, - OperationType.READ, null); + final String jsonRequestBody = getDmiRequestBody(READ, requestId, null, null, yangModelCmHandle); + final UrlTemplateParameters urlTemplateParameters = getUrlTemplateParameters( + PASSTHROUGH_OPERATIONAL.getDatastoreName(), yangModelCmHandle, "/", null, + null); + return dmiRestClient.synchronousPostOperationWithJsonData(DATA, urlTemplateParameters, jsonRequestBody, READ, + null); } /** @@ -135,7 +138,7 @@ public class DmiDataOperations { final String authorization) { final Set<String> cmHandlesIds - = getDistinctCmHandleIdsFromDataOperationRequest(dataOperationRequest); + = getDistinctCmHandleIds(dataOperationRequest); final Collection<YangModelCmHandle> yangModelCmHandles = inventoryPersistence.getYangModelCmHandles(cmHandlesIds); @@ -144,7 +147,7 @@ public class DmiDataOperations { = DmiDataOperationsHelper.processPerDefinitionInDataOperationsRequest(topicParamInQuery, requestId, dataOperationRequest, yangModelCmHandles); - buildDataOperationRequestUrlAndSendToDmiService(requestId, topicParamInQuery, operationsOutPerDmiServiceName, + asyncSendMultipleRequest(requestId, topicParamInQuery, operationsOutPerDmiServiceName, authorization); } @@ -172,10 +175,11 @@ public class DmiDataOperations { final String jsonRequestBody = getDmiRequestBody(operationType, null, requestData, dataType, yangModelCmHandle); - final String dmiUrl = getDmiResourceDataUrl(PASSTHROUGH_RUNNING.getDatastoreName(), - yangModelCmHandle, resourceId, null, null); - return dmiRestClient.synchronousPostOperationWithJsonData(RequiredDmiService.DATA, dmiUrl, jsonRequestBody, - operationType, authorization); + final UrlTemplateParameters urlTemplateParameters = getUrlTemplateParameters( + PASSTHROUGH_RUNNING.getDatastoreName(), yangModelCmHandle, resourceId, null, + null); + return dmiRestClient.synchronousPostOperationWithJsonData(DATA, urlTemplateParameters, jsonRequestBody, + operationType, authorization); } private YangModelCmHandle getYangModelCmHandle(final String cmHandleId) { @@ -198,22 +202,32 @@ public class DmiDataOperations { return jsonObjectMapper.asJsonString(dmiRequestBody); } - private String getDmiResourceDataUrl(final String datastoreName, - final YangModelCmHandle yangModelCmHandle, - final String resourceIdentifier, - final String optionsParamInQuery, - final String topicParamInQuery) { - final String dmiServiceName = yangModelCmHandle.resolveDmiServiceName(RequiredDmiService.DATA); - return DmiServiceUrlBuilder.newInstance() - .pathSegment("ch") - .variablePathSegment("cmHandleId", yangModelCmHandle.getId()) - .pathSegment("data") - .pathSegment("ds") - .variablePathSegment("datastore", datastoreName) - .queryParameter("resourceIdentifier", resourceIdentifier) - .queryParameter("options", optionsParamInQuery) - .queryParameter("topic", topicParamInQuery) - .build(dmiServiceName, dmiProperties.getDmiBasePath()); + private UrlTemplateParameters getUrlTemplateParameters(final String datastoreName, + final YangModelCmHandle yangModelCmHandle, + final String resourceIdentifier, + final String optionsParamInQuery, + final String topicParamInQuery) { + final String dmiServiceName = yangModelCmHandle.resolveDmiServiceName(DATA); + return DmiServiceUrlTemplateBuilder.newInstance() + .fixedPathSegment("ch") + .variablePathSegment("cmHandleId", yangModelCmHandle.getId()) + .fixedPathSegment("data") + .fixedPathSegment("ds") + .variablePathSegment("datastore", datastoreName) + .queryParameter("resourceIdentifier", resourceIdentifier) + .queryParameter("options", optionsParamInQuery) + .queryParameter("topic", topicParamInQuery) + .createUrlTemplateParameters(dmiServiceName, dmiProperties.getDmiBasePath()); + } + + private UrlTemplateParameters getUrlTemplateParameters(final String dmiServiceName, + final String requestId, + final String topicParamInQuery) { + return DmiServiceUrlTemplateBuilder.newInstance() + .fixedPathSegment("data") + .queryParameter("requestId", requestId) + .queryParameter("topic", topicParamInQuery) + .createUrlTemplateParameters(dmiServiceName, dmiProperties.getDmiBasePath()); } private void validateIfCmHandleStateReady(final YangModelCmHandle yangModelCmHandle, @@ -225,51 +239,37 @@ public class DmiDataOperations { } } - private static Set<String> getDistinctCmHandleIdsFromDataOperationRequest(final DataOperationRequest - dataOperationRequest) { + private static Set<String> getDistinctCmHandleIds(final DataOperationRequest dataOperationRequest) { return dataOperationRequest.getDataOperationDefinitions().stream() .flatMap(dataOperationDefinition -> dataOperationDefinition.getCmHandleIds().stream()).collect(Collectors.toSet()); } - private void buildDataOperationRequestUrlAndSendToDmiService(final String requestId, - final String topicParamInQuery, - final Map<String, List<DmiDataOperation>> - groupsOutPerDmiServiceName, - final String authorization) { - - Flux.fromIterable(groupsOutPerDmiServiceName.entrySet()) - .flatMap(dmiDataOperationsByDmiServiceName -> { - final String dmiServiceName = dmiDataOperationsByDmiServiceName.getKey(); - final String dmiUrl = buildDmiServiceUrl(dmiServiceName, requestId, topicParamInQuery); - final List<DmiDataOperation> dmiDataOperationRequestBodies - = dmiDataOperationsByDmiServiceName.getValue(); - return sendDataOperationRequestToDmiService(dmiUrl, dmiDataOperationRequestBodies, authorization); - }) - .subscribe(); - } - - private String buildDmiServiceUrl(final String dmiServiceName, final String requestId, - final String topicParamInQuery) { - return DmiServiceUrlBuilder.newInstance() - .pathSegment("data") - .queryParameter("requestId", requestId) - .queryParameter("topic", topicParamInQuery) - .build(dmiServiceName, dmiProperties.getDmiBasePath()); - } + private void asyncSendMultipleRequest(final String requestId, final String topicParamInQuery, + final Map<String, List<DmiDataOperation>> dmiDataOperationsPerDmi, + final String authorization) { - private Mono<Void> sendDataOperationRequestToDmiService(final String dmiUrl, - final List<DmiDataOperation> dmiDataOperationRequestBodies, - final String authorization) { - final String dmiDataOperationRequestAsJsonString - = createDmiDataOperationRequestAsJsonString(dmiDataOperationRequestBodies); - return dmiRestClient.asynchronousPostOperationWithJsonData(RequiredDmiService.DATA, dmiUrl, - dmiDataOperationRequestAsJsonString, OperationType.READ, authorization) - .then() - .onErrorResume(DmiClientRequestException.class, dmiClientRequestException -> { - handleTaskCompletionException(dmiClientRequestException, dmiUrl, dmiDataOperationRequestBodies); - return Mono.empty(); - }); + Flux.fromIterable(dmiDataOperationsPerDmi.entrySet()) + .flatMap(entry -> { + final String dmiServiceName = entry.getKey(); + final UrlTemplateParameters urlTemplateParameters = getUrlTemplateParameters(dmiServiceName, + requestId, topicParamInQuery); + final List<DmiDataOperation> dmiDataOperations = entry.getValue(); + final String dmiDataOperationRequestAsJsonString + = createDmiDataOperationRequestAsJsonString(dmiDataOperations); + return dmiRestClient.asynchronousPostOperationWithJsonData(DATA, urlTemplateParameters, + dmiDataOperationRequestAsJsonString, READ, authorization) + .then() + .onErrorResume(DmiClientRequestException.class, dmiClientRequestException -> { + final String dataOperationResourceUrl = UriComponentsBuilder + .fromUriString(urlTemplateParameters.urlTemplate()) + .buildAndExpand(urlTemplateParameters.urlVariables()) + .toUriString(); + handleTaskCompletionException(dmiClientRequestException, dataOperationResourceUrl, + dmiDataOperations); + return Mono.empty(); + }); + }).subscribe(); } private String createDmiDataOperationRequestAsJsonString( @@ -282,7 +282,7 @@ public class DmiDataOperations { private void handleTaskCompletionException(final DmiClientRequestException dmiClientRequestException, final String dataOperationResourceUrl, - final List<DmiDataOperation> dmiDataOperationRequestBodies) { + final List<DmiDataOperation> dmiDataOperations) { final MultiValueMap<String, String> dataOperationResourceUrlParameters = UriComponentsBuilder.fromUriString(dataOperationResourceUrl).build().getQueryParams(); final String topicName = dataOperationResourceUrlParameters.get("topic").get(0); @@ -291,7 +291,7 @@ public class DmiDataOperations { final MultiValueMap<DmiDataOperation, Map<NcmpResponseStatus, List<String>>> cmHandleIdsPerResponseCodesPerOperation = new LinkedMultiValueMap<>(); - dmiDataOperationRequestBodies.forEach(dmiDataOperationRequestBody -> { + dmiDataOperations.forEach(dmiDataOperationRequestBody -> { final List<String> cmHandleIds = dmiDataOperationRequestBody.getCmHandles().stream() .map(DmiOperationCmHandle::getId).toList(); cmHandleIdsPerResponseCodesPerOperation.add(dmiDataOperationRequestBody, 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 25144ad974..973a2a9b2d 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,7 +33,8 @@ import org.onap.cps.ncmp.api.datajobs.models.SubJobWriteRequest; import org.onap.cps.ncmp.api.datajobs.models.SubJobWriteResponse; import org.onap.cps.ncmp.api.impl.client.DmiRestClient; import org.onap.cps.ncmp.api.impl.config.DmiProperties; -import org.onap.cps.ncmp.api.impl.utils.DmiServiceUrlBuilder; +import org.onap.cps.ncmp.api.impl.utils.url.builder.DmiServiceUrlTemplateBuilder; +import org.onap.cps.ncmp.api.impl.utils.url.builder.UrlTemplateParameters; import org.onap.cps.ncmp.impl.models.RequiredDmiService; import org.onap.cps.utils.JsonObjectMapper; import org.springframework.http.ResponseEntity; @@ -64,10 +65,10 @@ public class DmiSubJobRequestHandler { final SubJobWriteRequest subJobWriteRequest = new SubJobWriteRequest(dataJobMetadata.dataAcceptType(), dataJobMetadata.dataContentType(), dataJobId, dmi3ggpWriteOperations); - final String dmiResourceUrl = getDmiResourceUrl(dataJobId, producerKey); + final UrlTemplateParameters urlTemplateParameters = getUrlTemplateParameters(dataJobId, producerKey); final ResponseEntity<Object> responseEntity = dmiRestClient.synchronousPostOperationWithJsonData( RequiredDmiService.DATA, - dmiResourceUrl, + urlTemplateParameters, jsonObjectMapper.asJsonString(subJobWriteRequest), OperationType.CREATE, NO_AUTH_HEADER); @@ -78,8 +79,10 @@ public class DmiSubJobRequestHandler { return subJobWriteResponses; } - private String getDmiResourceUrl(final String dataJobId, final ProducerKey producerKey) { - return DmiServiceUrlBuilder.newInstance().pathSegment("writeJob").variablePathSegment("requestId", dataJobId) - .build(producerKey.dmiServiceName(), dmiProperties.getDmiBasePath()); + private UrlTemplateParameters getUrlTemplateParameters(final String dataJobId, final ProducerKey producerKey) { + return DmiServiceUrlTemplateBuilder.newInstance() + .fixedPathSegment("writeJob") + .variablePathSegment("requestId", dataJobId) + .createUrlTemplateParameters(producerKey.dmiServiceName(), dmiProperties.getDmiBasePath()); } } 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 6a49360b9d..7d6677ca38 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 @@ -21,6 +21,9 @@ package org.onap.cps.ncmp.impl.inventory.sync; +import static org.onap.cps.ncmp.api.data.models.OperationType.READ; +import static org.onap.cps.ncmp.impl.models.RequiredDmiService.MODEL; + import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -32,14 +35,13 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import lombok.RequiredArgsConstructor; -import org.onap.cps.ncmp.api.data.models.OperationType; import org.onap.cps.ncmp.api.impl.client.DmiRestClient; import org.onap.cps.ncmp.api.impl.config.DmiProperties; -import org.onap.cps.ncmp.api.impl.utils.DmiServiceUrlBuilder; +import org.onap.cps.ncmp.api.impl.utils.url.builder.DmiServiceUrlTemplateBuilder; +import org.onap.cps.ncmp.api.impl.utils.url.builder.UrlTemplateParameters; import org.onap.cps.ncmp.api.inventory.models.YangResource; import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle; import org.onap.cps.ncmp.impl.models.DmiRequestBody; -import org.onap.cps.ncmp.impl.models.RequiredDmiService; import org.onap.cps.spi.model.ModuleReference; import org.onap.cps.utils.JsonObjectMapper; import org.springframework.http.ResponseEntity; @@ -67,7 +69,7 @@ public class DmiModelOperations { .moduleSetTag(yangModelCmHandle.getModuleSetTag()).build(); dmiRequestBody.asDmiProperties(yangModelCmHandle.getDmiProperties()); final ResponseEntity<Object> dmiFetchModulesResponseEntity = getResourceFromDmiWithJsonData( - yangModelCmHandle.resolveDmiServiceName(RequiredDmiService.MODEL), + yangModelCmHandle.resolveDmiServiceName(MODEL), jsonObjectMapper.asJsonString(dmiRequestBody), yangModelCmHandle.getId(), "modules"); return toModuleReferences((Map) dmiFetchModulesResponseEntity.getBody()); } @@ -87,7 +89,7 @@ public class DmiModelOperations { final String jsonWithDataAndDmiProperties = getRequestBodyToFetchYangResources(newModuleReferences, yangModelCmHandle.getDmiProperties(), yangModelCmHandle.getModuleSetTag()); final ResponseEntity<Object> responseEntity = getResourceFromDmiWithJsonData( - yangModelCmHandle.resolveDmiServiceName(RequiredDmiService.MODEL), + yangModelCmHandle.resolveDmiServiceName(MODEL), jsonWithDataAndDmiProperties, yangModelCmHandle.getId(), "moduleResources"); @@ -107,13 +109,13 @@ public class DmiModelOperations { final String jsonRequestBody, final String cmHandle, final String resourceName) { - final String dmiUrl = DmiServiceUrlBuilder.newInstance() - .pathSegment("ch") + final UrlTemplateParameters urlTemplateParameters = DmiServiceUrlTemplateBuilder.newInstance() + .fixedPathSegment("ch") .variablePathSegment("cmHandleId", cmHandle) - .variablePathSegment("resourceName", resourceName) - .build(dmiServiceName, dmiProperties.getDmiBasePath()); - return dmiRestClient.synchronousPostOperationWithJsonData(RequiredDmiService.MODEL, dmiUrl, jsonRequestBody, - OperationType.READ, null); + .fixedPathSegment(resourceName) + .createUrlTemplateParameters(dmiServiceName, dmiProperties.getDmiBasePath()); + return dmiRestClient.synchronousPostOperationWithJsonData(MODEL, urlTemplateParameters, jsonRequestBody, READ, + null); } private static String getRequestBodyToFetchYangResources(final Collection<ModuleReference> newModuleReferences, 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 19597a205b..8be8ead44c 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 @@ -25,6 +25,8 @@ import java.util.Map; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.onap.cps.ncmp.api.impl.client.DmiRestClient; +import org.onap.cps.ncmp.api.impl.utils.url.builder.DmiServiceUrlTemplateBuilder; +import org.onap.cps.ncmp.api.impl.utils.url.builder.UrlTemplateParameters; import org.onap.cps.ncmp.api.inventory.models.TrustLevel; import org.onap.cps.ncmp.impl.inventory.CmHandleQueryService; import org.springframework.beans.factory.annotation.Qualifier; @@ -50,10 +52,8 @@ public class DmiPluginTrustLevelWatchDog { */ @Scheduled(fixedDelayString = "${ncmp.timers.trust-level.dmi-availability-watchdog-ms:30000}") public void checkDmiAvailability() { - trustLevelPerDmiPlugin.entrySet().forEach(entry -> { + trustLevelPerDmiPlugin.forEach((dmiServiceName, oldDmiTrustLevel) -> { final TrustLevel newDmiTrustLevel; - final TrustLevel oldDmiTrustLevel = entry.getValue(); - final String dmiServiceName = entry.getKey(); final String dmiHealthStatus = getDmiHealthStatus(dmiServiceName); log.debug("The health status for dmi-plugin: {} is {}", dmiServiceName, dmiHealthStatus); @@ -72,7 +72,9 @@ public class DmiPluginTrustLevelWatchDog { }); } - private String getDmiHealthStatus(final String dmiServiceName) { - return dmiRestClient.getDmiHealthStatus(dmiServiceName); + private String getDmiHealthStatus(final String dmiServiceBaseUrl) { + final UrlTemplateParameters urlTemplateParameters = DmiServiceUrlTemplateBuilder.newInstance() + .createUrlTemplateParametersForHealthCheck(dmiServiceBaseUrl); + return dmiRestClient.getDmiHealthStatus(urlTemplateParameters).block(); } } |