From 8ed323c15930e519ab4797010e70e3bd643329ac Mon Sep 17 00:00:00 2001 From: SujitMBRDI Date: Thu, 19 Dec 2024 17:33:47 +0530 Subject: [PATCH] feat(bpdm): added connection to dependencies in readiness check for bpdm services --- .../bpdm/cleaning/config/AppConfig.kt | 33 ------------------- .../config/OrchestratorClientConfig.kt | 12 +++++-- .../util/OrchestratorHealthIndicator.kt | 19 ++++++----- .../tractusx/bpdm/pool/config/AppConfig.kt | 33 ------------------- .../pool/config/OrchestratorClientConfig.kt | 11 +++++-- .../pool/util/OrchestratorHealthIndicator.kt | 18 ++++++---- 6 files changed, 41 insertions(+), 85 deletions(-) delete mode 100644 bpdm-cleaning-service-dummy/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/config/AppConfig.kt delete mode 100644 bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/config/AppConfig.kt diff --git a/bpdm-cleaning-service-dummy/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/config/AppConfig.kt b/bpdm-cleaning-service-dummy/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/config/AppConfig.kt deleted file mode 100644 index 255ba347f..000000000 --- a/bpdm-cleaning-service-dummy/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/config/AppConfig.kt +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021,2024 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://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 - ******************************************************************************/ - -package org.eclipse.tractusx.bpdm.cleaning.config - -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.web.client.RestTemplate - -@Configuration -class AppConfig { - - @Bean - fun restTemplate(): RestTemplate { - return RestTemplate() - } -} \ No newline at end of file diff --git a/bpdm-cleaning-service-dummy/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/config/OrchestratorClientConfig.kt b/bpdm-cleaning-service-dummy/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/config/OrchestratorClientConfig.kt index 1e27a9cf9..d0b164964 100644 --- a/bpdm-cleaning-service-dummy/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/config/OrchestratorClientConfig.kt +++ b/bpdm-cleaning-service-dummy/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/config/OrchestratorClientConfig.kt @@ -24,10 +24,12 @@ import org.eclipse.tractusx.bpdm.common.util.BpdmWebClientProvider import org.eclipse.tractusx.bpdm.common.util.ClientConfigurationProperties import org.eclipse.tractusx.orchestrator.api.client.OrchestrationApiClient import org.eclipse.tractusx.orchestrator.api.client.OrchestrationApiClientImpl +import org.springframework.beans.factory.annotation.Qualifier import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties import org.springframework.boot.context.properties.ConfigurationProperties import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration +import org.springframework.web.reactive.function.client.WebClient @ConfigurationProperties(prefix = OrchestratorConfigProperties.PREFIX) data class OrchestratorConfigProperties( @@ -45,8 +47,14 @@ data class OrchestratorConfigProperties( @Configuration class OrchestratorClientConfiguration{ + @Bean - fun orchestratorClient(clientProperties: OrchestratorConfigProperties, webClientProvider: BpdmWebClientProvider): OrchestrationApiClient{ - return OrchestrationApiClientImpl { webClientProvider.builder(clientProperties).build() } + fun orchestratorClient(@Qualifier("orchestratorWebClient") orchestratorWebClient: WebClient ): OrchestrationApiClient{ + return OrchestrationApiClientImpl { orchestratorWebClient } + } + + @Bean(name = ["orchestratorWebClient"]) + fun orchestratorWebClient(clientProperties: OrchestratorConfigProperties, webClientProvider: BpdmWebClientProvider): WebClient{ + return webClientProvider.builder(clientProperties).build() } } diff --git a/bpdm-cleaning-service-dummy/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/util/OrchestratorHealthIndicator.kt b/bpdm-cleaning-service-dummy/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/util/OrchestratorHealthIndicator.kt index d382fe41d..a679bc536 100644 --- a/bpdm-cleaning-service-dummy/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/util/OrchestratorHealthIndicator.kt +++ b/bpdm-cleaning-service-dummy/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/util/OrchestratorHealthIndicator.kt @@ -20,15 +20,16 @@ package org.eclipse.tractusx.bpdm.cleaning.util import org.eclipse.tractusx.bpdm.cleaning.config.OrchestratorConfigProperties +import org.springframework.beans.factory.annotation.Qualifier import org.springframework.boot.actuate.health.Health import org.springframework.boot.actuate.health.HealthIndicator import org.springframework.stereotype.Component -import org.springframework.web.client.RestTemplate +import org.springframework.web.reactive.function.client.WebClient @Component("orchestratorHealth") class OrchestratorHealthIndicator( - private val restTemplate: RestTemplate, - private val orchestratorConfigProperties: OrchestratorConfigProperties + private val orchestratorConfigProperties: OrchestratorConfigProperties, + @Qualifier("orchestratorWebClient") private val webClient: WebClient ) : HealthIndicator { override fun health(): Health { @@ -36,11 +37,13 @@ class OrchestratorHealthIndicator( val orchestratorHealthUrl = "${orchestratorConfigProperties.baseUrl}/actuator/health" return try { - /* - Todo: Create new separate REST api end point for orchestrator service which will enable check on health readiness in authenticated way. - */ - val response = restTemplate.getForEntity(orchestratorHealthUrl, String::class.java) - if (response.statusCode.is2xxSuccessful) { + val response = webClient.get() + .uri(orchestratorHealthUrl) + .retrieve() + .toEntity(String::class.java) + .block() + + if (response?.statusCode?.is2xxSuccessful == true) { Health.up().withDetail("Orchestrator Service", "Available").build() } else { Health.down().withDetail("Orchestrator Service", "Unreachable").build() diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/config/AppConfig.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/config/AppConfig.kt deleted file mode 100644 index 2b1ac04e2..000000000 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/config/AppConfig.kt +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021,2024 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://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 - ******************************************************************************/ - -package org.eclipse.tractusx.bpdm.pool.config - -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.web.client.RestTemplate - -@Configuration -class AppConfig { - - @Bean - fun restTemplate(): RestTemplate { - return RestTemplate() - } -} \ No newline at end of file diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/config/OrchestratorClientConfig.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/config/OrchestratorClientConfig.kt index 08005dfcd..0fff57450 100644 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/config/OrchestratorClientConfig.kt +++ b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/config/OrchestratorClientConfig.kt @@ -24,10 +24,12 @@ import org.eclipse.tractusx.bpdm.common.util.BpdmWebClientProvider import org.eclipse.tractusx.bpdm.common.util.ClientConfigurationProperties import org.eclipse.tractusx.orchestrator.api.client.OrchestrationApiClient import org.eclipse.tractusx.orchestrator.api.client.OrchestrationApiClientImpl +import org.springframework.beans.factory.annotation.Qualifier import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties import org.springframework.boot.context.properties.ConfigurationProperties import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration +import org.springframework.web.reactive.function.client.WebClient @ConfigurationProperties(prefix = OrchestratorClientConfigProperties.PREFIX) @@ -47,8 +49,13 @@ data class OrchestratorClientConfigProperties( @Configuration class OrchestratorClientConfiguration{ @Bean - fun orchestratorClient(clientProperties: OrchestratorClientConfigProperties, webClientProvider: BpdmWebClientProvider): OrchestrationApiClient{ - return OrchestrationApiClientImpl { webClientProvider.builder(clientProperties).build() } + fun orchestratorClient(@Qualifier("orchestratorWebClient") orchestratorWebClient: WebClient): OrchestrationApiClient{ + return OrchestrationApiClientImpl { orchestratorWebClient } + } + + @Bean(name = ["orchestratorWebClient"]) + fun orchestratorWebClient(clientProperties: OrchestratorClientConfigProperties, webClientProvider: BpdmWebClientProvider): WebClient { + return webClientProvider.builder(clientProperties).build() } } diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/util/OrchestratorHealthIndicator.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/util/OrchestratorHealthIndicator.kt index bd036984a..328142fc6 100644 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/util/OrchestratorHealthIndicator.kt +++ b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/util/OrchestratorHealthIndicator.kt @@ -23,16 +23,18 @@ import org.eclipse.tractusx.bpdm.common.dto.PaginationRequest import org.eclipse.tractusx.bpdm.pool.config.OrchestratorClientConfigProperties import org.eclipse.tractusx.orchestrator.api.client.OrchestrationApiClient import org.eclipse.tractusx.orchestrator.api.model.TaskStateRequest +import org.springframework.beans.factory.annotation.Qualifier import org.springframework.boot.actuate.health.Health import org.springframework.boot.actuate.health.HealthIndicator import org.springframework.stereotype.Component import org.springframework.web.client.RestTemplate +import org.springframework.web.reactive.function.client.WebClient import java.time.Instant @Component("orchestratorHealth") class OrchestratorHealthIndicator( - private val restTemplate: RestTemplate, - private val orchestratorConfigProperties: OrchestratorClientConfigProperties + private val orchestratorConfigProperties: OrchestratorClientConfigProperties, + @Qualifier("orchestratorWebClient") private val webClient: WebClient ) : HealthIndicator { override fun health(): Health { @@ -40,11 +42,13 @@ class OrchestratorHealthIndicator( val orchestratorHealthUrl = "${orchestratorConfigProperties.baseUrl}/actuator/health" return try { - /* - Todo: Create new separate REST api end point for orchestrator service which will enable check on health readiness in authenticated way. - */ - val response = restTemplate.getForEntity(orchestratorHealthUrl, String::class.java) - if (response.statusCode.is2xxSuccessful) { + val response = webClient.get() + .uri(orchestratorHealthUrl) + .retrieve() + .toEntity(String::class.java) + .block() + + if (response?.statusCode?.is2xxSuccessful == true) { Health.up().withDetail("Orchestrator Service", "Available").build() } else { Health.down().withDetail("Orchestrator Service", "Unreachable").build()