Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bpdm): added connection to dependencies in readiness check for bpdm services #1164

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ For changes to the BPDM Helm charts please consult the [changelog](charts/bpdm/C
- BPDM Pool: Post endpoint to fetch the BPNL/S/A based on the requested identifiers.([#1052](https://github.com/eclipse-tractusx/bpdm/issues/1052))
- BPDM Gate & Orchestrator: Enhance the error handling mechanism for the orchestrator and gate components by extending the list of available error codes.([#1003](https://github.com/eclipse-tractusx/bpdm/pull/1003#pullrequestreview-2477395867))
- BPDM System Test: Tester module which performs automated end-to-end tests on an existing golden record process.([#1070](https://github.com/eclipse-tractusx/bpdm/pull/1070))
- Apps : Enhanced dependency readiness checks with a scheduler to verify connections to required services every 30 seconds and during startup for Pool, Cleaning Service Dummy, and Gate service. ([#1161](https://github.com/eclipse-tractusx/bpdm/issues/1161))

### Changed

Expand Down
12 changes: 6 additions & 6 deletions DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ maven/mavencentral/io.cucumber/cucumber-spring/7.18.1, MIT, approved, clearlydef
maven/mavencentral/io.cucumber/datatable/7.18.1, Apache-2.0, approved, #15145
maven/mavencentral/io.cucumber/docstring/7.18.1, MIT, approved, clearlydefined
maven/mavencentral/io.cucumber/gherkin/28.0.0, MIT, approved, #14276
maven/mavencentral/io.cucumber/html-formatter/21.4.1, MIT, restricted, clearlydefined
maven/mavencentral/io.cucumber/html-formatter/21.4.1, Apache-2.0 AND MIT, approved, #17770
maven/mavencentral/io.cucumber/junit-xml-formatter/0.5.0, MIT, approved, clearlydefined
maven/mavencentral/io.cucumber/messages/24.1.0, MIT, approved, #14274
maven/mavencentral/io.cucumber/query/12.2.0, MIT, approved, clearlydefined
Expand Down Expand Up @@ -128,7 +128,7 @@ maven/mavencentral/org.apache.tomcat.embed/tomcat-embed-core/10.1.33, Apache-2.0
maven/mavencentral/org.apache.tomcat.embed/tomcat-embed-el/10.1.33, Apache-2.0, approved, #6997
maven/mavencentral/org.apache.tomcat.embed/tomcat-embed-websocket/10.1.33, Apache-2.0, approved, #7920
maven/mavencentral/org.apiguardian/apiguardian-api/1.1.2, Apache-2.0, approved, #17641
maven/mavencentral/org.aspectj/aspectjweaver/1.9.22.1, Apache-2.0 AND BSD-3-Clause AND EPL-1.0 AND BSD-3-Clause AND Apache-1.1, approved, #15252
maven/mavencentral/org.aspectj/aspectjweaver/1.9.22.1, EPL-1.0, approved, tools.aspectj
maven/mavencentral/org.assertj/assertj-core/3.24.2, Apache-2.0, approved, #6161
maven/mavencentral/org.awaitility/awaitility/4.2.2, Apache-2.0, approved, #14178
maven/mavencentral/org.checkerframework/checker-qual/3.42.0, MIT, approved, clearlydefined
Expand All @@ -150,7 +150,7 @@ maven/mavencentral/org.glassfish.jaxb/jaxb-xjc/4.0.5, BSD-3-Clause, approved, ee
maven/mavencentral/org.glassfish.jaxb/txw2/4.0.5, BSD-3-Clause, approved, ee4j.jaxb-impl
maven/mavencentral/org.glassfish.jaxb/xsom/4.0.5, BSD-3-Clause, approved, ee4j.jaxb-impl
maven/mavencentral/org.hamcrest/hamcrest-core/2.2, BSD-3-Clause, approved, clearlydefined
maven/mavencentral/org.hamcrest/hamcrest/2.2, None, restricted, #17677
maven/mavencentral/org.hamcrest/hamcrest/2.2, BSD-3-Clause, approved, #17677
maven/mavencentral/org.hdrhistogram/HdrHistogram/2.2.2, BSD-2-Clause AND CC0-1.0 AND CC0-1.0, approved, #14828
maven/mavencentral/org.hibernate.common/hibernate-commons-annotations/7.0.3.Final, Apache-2.0, approved, clearlydefined
maven/mavencentral/org.hibernate.orm/hibernate-core/6.6.2.Final, (EPL-2.0 OR BSD-3-Clause) AND LGPL-2.1-or-later AND MIT, approved, #17553
Expand All @@ -169,8 +169,8 @@ maven/mavencentral/org.jboss.shrinkwrap/shrinkwrap-spi/1.2.6, Apache-2.0, approv
maven/mavencentral/org.jboss/jandex/2.4.3.Final, Apache-2.0, approved, clearlydefined
maven/mavencentral/org.jetbrains.kotlin/kotlin-reflect/2.1.0, Apache-2.0, approved, #17637
maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib-common/1.8.0, Apache-2.0, approved, #8910
maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib-jdk7/2.1.0, None, restricted, #17633
maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib-jdk8/2.1.0, None, restricted, #17635
maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib-jdk7/2.1.0, Apache-2.0, approved, #17633
maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib-jdk8/2.1.0, Apache-2.0, approved, #17635
maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib/2.1.0, Apache-2.0, approved, #17634
maven/mavencentral/org.jetbrains.kotlinx/kotlinx-coroutines-core-jvm/1.8.1, Apache-2.0, approved, clearlydefined
maven/mavencentral/org.jetbrains.kotlinx/kotlinx-coroutines-core/1.8.1, Apache-2.0, approved, clearlydefined
Expand Down Expand Up @@ -251,7 +251,7 @@ maven/mavencentral/org.testcontainers/jdbc/1.20.4, Apache-2.0, approved, #16621
maven/mavencentral/org.testcontainers/junit-jupiter/1.20.4, MIT, approved, #16552
maven/mavencentral/org.testcontainers/postgresql/1.20.4, MIT, approved, #16627
maven/mavencentral/org.testcontainers/testcontainers/1.20.4, MIT, approved, #15747
maven/mavencentral/org.webjars/swagger-ui/5.18.2, Apache-2.0 AND (Apache-2.0 AND MIT) AND MIT AND DOC AND LicenseRef-scancode-proprietary-license, restricted, #17636
maven/mavencentral/org.webjars/swagger-ui/5.18.2, Apache-2.0, approved, #17636
maven/mavencentral/org.webjars/webjars-locator-lite/1.0.1, MIT, approved, clearlydefined
maven/mavencentral/org.xmlunit/xmlunit-core/2.10.0, Apache-2.0, approved, #14590
maven/mavencentral/org.yaml/snakeyaml/2.3, Apache-2.0 AND (Apache-2.0 OR BSD-3-Clause OR EPL-1.0 OR GPL-2.0-or-later OR LGPL-2.1-or-later), approved, #16046
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@ import org.springframework.boot.context.properties.ConfigurationProperties

@ConfigurationProperties(prefix = PREFIX)
class CleaningServiceConfigProperties (
val step: TaskStep
val step: TaskStep,
val dependencyCheck: DependencyCheckConfig
){
companion object{
const val PREFIX = "bpdm.golden-record-process"
}

data class DependencyCheckConfig(
val cron: String = "-"
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*******************************************************************************
* 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 jakarta.annotation.PostConstruct
import mu.KotlinLogging
import org.eclipse.tractusx.bpdm.cleaning.service.DependencyHealthService
import org.springframework.context.annotation.Configuration
import org.springframework.scheduling.TaskScheduler
import org.springframework.scheduling.support.CronTrigger

@Configuration
class DependencyHealthScheduler(
private val dependencyHealthService: DependencyHealthService,
private val taskScheduler: TaskScheduler,
private val configProperties: CleaningServiceConfigProperties
) {

private val logger = KotlinLogging.logger { }

@PostConstruct
fun scheduleHealthChecks() {
taskScheduler.scheduleIfEnabled(
{ performHealthCheck() },
configProperties.dependencyCheck.cron
)
}

private fun performHealthCheck() {
val healthStatus = dependencyHealthService.checkAllDependencies()
val unhealthyDependencies = healthStatus.filter { it.value == "Down" }

if (unhealthyDependencies.isNotEmpty()) {
logger.error("Dependencies not ready: ${unhealthyDependencies.map { "${it.key}: ${it.value}" }.joinToString(", ")}")
} else {
logger.info("All dependencies are healthy: ${healthStatus.map { "${it.key}: ${it.value}" }.joinToString(", ")}")
}
}

private fun TaskScheduler.scheduleIfEnabled(task: Runnable, cronExpression: String) {
if (cronExpression != "-") {
schedule(task, CronTrigger(cronExpression))
}
}

}
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
@@ -0,0 +1,38 @@
/*******************************************************************************
* 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.service

import org.eclipse.tractusx.bpdm.cleaning.util.OrchestratorHealthIndicator
import org.springframework.boot.actuate.health.Status
import org.springframework.stereotype.Service

@Service
class DependencyHealthService(
private val orchestratorHealthIndicator: OrchestratorHealthIndicator
) {

fun checkAllDependencies(): Map<String, String> {
val orchestratorHealth = if (orchestratorHealthIndicator.health().status == Status.UP) "Healthy" else "Down"

return mapOf(
"Orchestrator Service" to orchestratorHealth
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*******************************************************************************
* 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.util

import org.springframework.boot.actuate.health.Status
import org.springframework.boot.context.event.ApplicationReadyEvent
import org.springframework.context.ApplicationListener
import org.springframework.stereotype.Component

@Component
class CleaningServiceStartupListner(
private val orchestratorHealthIndicator: OrchestratorHealthIndicator
) : ApplicationListener<ApplicationReadyEvent> {

override fun onApplicationEvent(event: ApplicationReadyEvent) {
val orchestratorHealth = orchestratorHealthIndicator.health().status

if (orchestratorHealth != Status.UP) {
throw IllegalStateException("Dependencies not ready: Orchestrator: $orchestratorHealth")
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*******************************************************************************
* 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.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.reactive.function.client.WebClient

@Component("orchestratorHealth")
class OrchestratorHealthIndicator(
private val orchestratorConfigProperties: OrchestratorConfigProperties,
@Qualifier("orchestratorWebClient") private val webClient: WebClient
) : HealthIndicator {

override fun health(): Health {

val orchestratorHealthUrl = "${orchestratorConfigProperties.baseUrl}/actuator/health"

return try {
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()
}
} catch (e: Exception) {
Health.down().withDetail("Orchestrator Service", "Error: ${e.message}").build()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ bpdm:
client-secret: "**********"
golden-record-process:
step: CleanAndSync
dependencyCheck:
# How often the golden record connection dependencies should be checked for being healthy
cron: '*/30 * * * * *'

cleaningService:
# When and how often the cleaning service should poll for golden record tasks in the orchestrator
Expand Down Expand Up @@ -78,6 +81,7 @@ logging:
management:
endpoint:
health:
show-details: always
probes:
# Enable actuator health endpoints for probing
enabled: true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*******************************************************************************
* 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 io.mockk.every
import io.mockk.mockk
import org.eclipse.tractusx.bpdm.cleaning.util.OrchestratorHealthIndicator
import org.springframework.boot.actuate.health.Health
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

@Configuration
class MockHealthIndicatorConfig {

@Bean
fun orchestratorHealthIndicator(): OrchestratorHealthIndicator {
return mockk<OrchestratorHealthIndicator> {
every { health() } returns Health.up().build()
}
}
}
Loading
Loading