Skip to content

Commit

Permalink
feat(bpdm): added connection to dependencies in readiness check for b…
Browse files Browse the repository at this point in the history
…pdm services
  • Loading branch information
SujitMBRDI committed Dec 19, 2024
1 parent 8285474 commit 8ed323c
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 85 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,30 @@
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 {

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()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,32 @@ 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 {

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()
Expand Down

0 comments on commit 8ed323c

Please sign in to comment.