diff --git a/CHANGELOG.md b/CHANGELOG.md index 95688f4e2..a492716a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/DEPENDENCIES b/DEPENDENCIES index caf0e9738..305bb42ae 100644 --- a/DEPENDENCIES +++ b/DEPENDENCIES @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/bpdm-cleaning-service-dummy/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/config/CleaningServiceConfigProperties.kt b/bpdm-cleaning-service-dummy/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/config/CleaningServiceConfigProperties.kt index 099b6d163..ef4181b44 100644 --- a/bpdm-cleaning-service-dummy/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/config/CleaningServiceConfigProperties.kt +++ b/bpdm-cleaning-service-dummy/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/config/CleaningServiceConfigProperties.kt @@ -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 = "-" + ) } \ No newline at end of file diff --git a/bpdm-cleaning-service-dummy/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/config/DependencyHealthScheduler.kt b/bpdm-cleaning-service-dummy/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/config/DependencyHealthScheduler.kt new file mode 100644 index 000000000..5043be87c --- /dev/null +++ b/bpdm-cleaning-service-dummy/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/config/DependencyHealthScheduler.kt @@ -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)) + } + } + +} \ 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/service/DependencyHealthService.kt b/bpdm-cleaning-service-dummy/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/service/DependencyHealthService.kt new file mode 100644 index 000000000..8367db893 --- /dev/null +++ b/bpdm-cleaning-service-dummy/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/service/DependencyHealthService.kt @@ -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 { + val orchestratorHealth = if (orchestratorHealthIndicator.health().status == Status.UP) "Healthy" else "Down" + + return mapOf( + "Orchestrator Service" to orchestratorHealth + ) + } +} \ No newline at end of file diff --git a/bpdm-cleaning-service-dummy/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/util/CleaningServiceStartupListner.kt b/bpdm-cleaning-service-dummy/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/util/CleaningServiceStartupListner.kt new file mode 100644 index 000000000..06608d335 --- /dev/null +++ b/bpdm-cleaning-service-dummy/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/util/CleaningServiceStartupListner.kt @@ -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 { + + override fun onApplicationEvent(event: ApplicationReadyEvent) { + val orchestratorHealth = orchestratorHealthIndicator.health().status + + if (orchestratorHealth != Status.UP) { + throw IllegalStateException("Dependencies not ready: Orchestrator: $orchestratorHealth") + } + } + +} \ No newline at end of file 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 new file mode 100644 index 000000000..a679bc536 --- /dev/null +++ b/bpdm-cleaning-service-dummy/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/util/OrchestratorHealthIndicator.kt @@ -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() + } + } +} \ No newline at end of file diff --git a/bpdm-cleaning-service-dummy/src/main/resources/application.yml b/bpdm-cleaning-service-dummy/src/main/resources/application.yml index b44a435f1..93491a004 100644 --- a/bpdm-cleaning-service-dummy/src/main/resources/application.yml +++ b/bpdm-cleaning-service-dummy/src/main/resources/application.yml @@ -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 @@ -78,6 +81,7 @@ logging: management: endpoint: health: + show-details: always probes: # Enable actuator health endpoints for probing enabled: true diff --git a/bpdm-cleaning-service-dummy/src/test/kotlin/org/eclipse/tractusx/bpdm/cleaning/config/MockHealthIndicatorConfig.kt b/bpdm-cleaning-service-dummy/src/test/kotlin/org/eclipse/tractusx/bpdm/cleaning/config/MockHealthIndicatorConfig.kt new file mode 100644 index 000000000..b14a4f474 --- /dev/null +++ b/bpdm-cleaning-service-dummy/src/test/kotlin/org/eclipse/tractusx/bpdm/cleaning/config/MockHealthIndicatorConfig.kt @@ -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 { + every { health() } returns Health.up().build() + } + } +} \ No newline at end of file diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/config/DependencyHealthScheduler.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/config/DependencyHealthScheduler.kt new file mode 100644 index 000000000..5b28b09b4 --- /dev/null +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/config/DependencyHealthScheduler.kt @@ -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.gate.config + +import jakarta.annotation.PostConstruct +import mu.KotlinLogging +import org.eclipse.tractusx.bpdm.gate.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: GoldenRecordTaskConfigProperties +) { + + 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)) + } + } + +} diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/config/GoldenRecordProcessConfigProperties.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/config/GoldenRecordProcessConfigProperties.kt index 4f6d474ed..166ab2457 100644 --- a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/config/GoldenRecordProcessConfigProperties.kt +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/config/GoldenRecordProcessConfigProperties.kt @@ -25,7 +25,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties data class GoldenRecordTaskConfigProperties( val creation: CreationProperties = CreationProperties(), val check: TaskProcessProperties = TaskProcessProperties(), - val healthCheck: TaskProcessProperties = TaskProcessProperties() + val healthCheck: TaskProcessProperties = TaskProcessProperties(), + val dependencyCheck: TaskProcessProperties = TaskProcessProperties() ) { data class CreationProperties( val fromSharingMember: CreationTaskProperties = CreationTaskProperties(), diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/DependencyHealthService.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/DependencyHealthService.kt new file mode 100644 index 000000000..d60d04b0b --- /dev/null +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/DependencyHealthService.kt @@ -0,0 +1,42 @@ +/******************************************************************************* + * 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.gate.service + +import org.eclipse.tractusx.bpdm.gate.util.OrchestratorHealthIndicator +import org.eclipse.tractusx.bpdm.gate.util.PoolHealthIndicator +import org.springframework.boot.actuate.health.Status +import org.springframework.stereotype.Service + +@Service +class DependencyHealthService( + private val poolHealthIndicator: PoolHealthIndicator, + private val orchestratorHealthIndicator: OrchestratorHealthIndicator +) { + + fun checkAllDependencies(): Map { + val poolHealth = if (poolHealthIndicator.health().status == Status.UP) "Healthy" else "Down" + val orchestratorHealth = if (orchestratorHealthIndicator.health().status == Status.UP) "Healthy" else "Down" + + return mapOf( + "Pool Service" to poolHealth, + "Orchestrator Service" to orchestratorHealth + ) + } +} diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/util/GateServiceStartupListener.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/util/GateServiceStartupListener.kt new file mode 100644 index 000000000..0d9c6ce20 --- /dev/null +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/util/GateServiceStartupListener.kt @@ -0,0 +1,47 @@ +/******************************************************************************* + * 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.gate.util + +import mu.KotlinLogging +import org.eclipse.tractusx.bpdm.gate.service.DependencyHealthService +import org.springframework.boot.context.event.ApplicationReadyEvent +import org.springframework.context.ApplicationListener +import org.springframework.stereotype.Component + +@Component +class GateServiceStartupListener( + private val dependencyHealthService: DependencyHealthService +) : ApplicationListener { + + private val logger = KotlinLogging.logger { } + + override fun onApplicationEvent(event: ApplicationReadyEvent) { + val healthStatus = dependencyHealthService.checkAllDependencies() + val unhealthyDependencies = healthStatus.filter { it.value == "Down" } + + if (unhealthyDependencies.isNotEmpty()) { + logger.error("Startup failed. Dependencies not ready: ${unhealthyDependencies.map { "${it.key}: ${it.value}" }.joinToString(", ")}") + throw IllegalStateException("Dependencies not ready: ${unhealthyDependencies.map { "${it.key}: ${it.value}" }.joinToString(", ")}") + } else { + logger.info("All dependencies are healthy on startup: ${healthStatus.map { "${it.key}: ${it.value}" }.joinToString(", ")}") + } + } + +} diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/util/OrchestratorHealthIndicator.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/util/OrchestratorHealthIndicator.kt new file mode 100644 index 000000000..b9057c6c3 --- /dev/null +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/util/OrchestratorHealthIndicator.kt @@ -0,0 +1,52 @@ +/******************************************************************************* + * 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.gate.util + +import org.eclipse.tractusx.bpdm.common.dto.PaginationRequest +import org.eclipse.tractusx.orchestrator.api.client.OrchestrationApiClient +import org.springframework.boot.actuate.health.Health +import org.springframework.boot.actuate.health.HealthIndicator +import org.springframework.stereotype.Component +import java.time.Instant + +@Component("orchestratorHealth") +class OrchestratorHealthIndicator( + private val orchestrationClient: OrchestrationApiClient +) : HealthIndicator { + + override fun health(): Health { + + return try { + /* + We can directly use actuator heath response from Orchestrator service but that will not be an authenticated way. + So, included get finished task events request to achieve the same for now and in future we can create separate REST api endpoint which will provide + health of the service with readiness in authenticated way. + */ + val response = orchestrationClient.finishedTaskEvents.getEvents(Instant.now(), PaginationRequest(page = 0, size = 1)) + if (response.contentSize >= 0) { + 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() + } + } +} diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/util/PoolHealthIndicator.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/util/PoolHealthIndicator.kt new file mode 100644 index 000000000..26b7a034d --- /dev/null +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/util/PoolHealthIndicator.kt @@ -0,0 +1,52 @@ +/******************************************************************************* + * 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.gate.util + +import org.eclipse.tractusx.bpdm.common.dto.PaginationRequest +import org.eclipse.tractusx.bpdm.pool.api.client.PoolApiClient +import org.eclipse.tractusx.bpdm.pool.api.model.request.ChangelogSearchRequest +import org.springframework.boot.actuate.health.Health +import org.springframework.boot.actuate.health.HealthIndicator +import org.springframework.stereotype.Component + +@Component("poolHealth") +class PoolHealthIndicator( + private val poolClient: PoolApiClient, +) : HealthIndicator { + + override fun health(): Health { + + return try { + /* + We can directly use actuator heath response from Pool service but that will not be an authenticated way. + So, included changelog request to achieve the same for now and in future we can create separate REST api endpoint which will provide + health of the service with readiness in authenticated way. + */ + val response = poolClient.changelogs.getChangelogEntries(ChangelogSearchRequest(), PaginationRequest(page = 0, size = 1)) + if (response.contentSize >= 0) { + Health.up().withDetail("Pool Service", "Available").build() + } else { + Health.down().withDetail("Pool Service", "Unreachable").build() + } + } catch (e: Exception) { + Health.down().withDetail("Pool Service", "Error: ${e.message}").build() + } + } +} diff --git a/bpdm-gate/src/main/resources/application.yml b/bpdm-gate/src/main/resources/application.yml index 8010bcff2..7dbfc7573 100644 --- a/bpdm-gate/src/main/resources/application.yml +++ b/bpdm-gate/src/main/resources/application.yml @@ -64,6 +64,9 @@ bpdm: batchSize: 1000 # How often the golden record tasks should be checked for being healthy cron: '0 0 0 * * *' + dependencyCheck: + # How often the golden record connection dependencies should be checked for being healthy + cron: '*/30 * * * * *' # Connection to the pool and orchestrator client: @@ -158,6 +161,7 @@ logging: management: endpoint: health: + show-details: always probes: # Enable actuator health endpoints for probing enabled: true diff --git a/bpdm-gate/src/test/kotlin/org/eclipse/tractusx/bpdm/gate/config/MockHealthIndicatorConfig.kt b/bpdm-gate/src/test/kotlin/org/eclipse/tractusx/bpdm/gate/config/MockHealthIndicatorConfig.kt new file mode 100644 index 000000000..6764c75b2 --- /dev/null +++ b/bpdm-gate/src/test/kotlin/org/eclipse/tractusx/bpdm/gate/config/MockHealthIndicatorConfig.kt @@ -0,0 +1,46 @@ +/******************************************************************************* + * 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.gate.config + +import io.mockk.every +import io.mockk.mockk +import org.eclipse.tractusx.bpdm.gate.util.OrchestratorHealthIndicator +import org.eclipse.tractusx.bpdm.gate.util.PoolHealthIndicator +import org.springframework.boot.actuate.health.Health +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration + +@Configuration +class MockHealthIndicatorConfig { + + @Bean + fun poolHealthIndicator(): PoolHealthIndicator { + return mockk { + every { health() } returns Health.up().build() + } + } + + @Bean + fun orchestratorHealthIndicator(): OrchestratorHealthIndicator { + return mockk { + every { health() } returns Health.up().build() + } + } +} \ No newline at end of file diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/config/DependencyHealthScheduler.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/config/DependencyHealthScheduler.kt new file mode 100644 index 000000000..17a423c46 --- /dev/null +++ b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/config/DependencyHealthScheduler.kt @@ -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.pool.config + +import jakarta.annotation.PostConstruct +import mu.KotlinLogging +import org.eclipse.tractusx.bpdm.pool.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: GoldenRecordTaskConfigProperties +) { + + private val logger = KotlinLogging.logger { } + + @PostConstruct + fun scheduleHealthChecks() { + taskScheduler.scheduleIfEnabled( + { performHealthCheck() }, + configProperties.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)) + } + } + +} \ 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/service/DependencyHealthService.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/DependencyHealthService.kt new file mode 100644 index 000000000..b3a299639 --- /dev/null +++ b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/DependencyHealthService.kt @@ -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.pool.service + +import org.eclipse.tractusx.bpdm.pool.util.OrchestratorHealthIndicator +import org.springframework.boot.actuate.health.Status +import org.springframework.stereotype.Service + +@Service +class DependencyHealthService( + private val orchestratorHealthIndicator: OrchestratorHealthIndicator +) { + + fun checkAllDependencies(): Map { + val orchestratorHealth = if (orchestratorHealthIndicator.health().status == Status.UP) "Healthy" else "Down" + + return mapOf( + "Orchestrator Service" to orchestratorHealth + ) + } +} 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 new file mode 100644 index 000000000..328142fc6 --- /dev/null +++ b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/util/OrchestratorHealthIndicator.kt @@ -0,0 +1,60 @@ +/******************************************************************************* + * 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.util + +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 orchestratorConfigProperties: OrchestratorClientConfigProperties, + @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() + } + } +} \ No newline at end of file diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/util/PoolServiceStartupListner.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/util/PoolServiceStartupListner.kt new file mode 100644 index 000000000..c7a2803d9 --- /dev/null +++ b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/util/PoolServiceStartupListner.kt @@ -0,0 +1,47 @@ +/******************************************************************************* + * 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.util + +import mu.KotlinLogging +import org.eclipse.tractusx.bpdm.pool.service.DependencyHealthService +import org.springframework.boot.context.event.ApplicationReadyEvent +import org.springframework.context.ApplicationListener +import org.springframework.stereotype.Component + +@Component +class PoolServiceStartupListner( + private val dependencyHealthService: DependencyHealthService +) : ApplicationListener { + + private val logger = KotlinLogging.logger { } + + override fun onApplicationEvent(event: ApplicationReadyEvent) { + val healthStatus = dependencyHealthService.checkAllDependencies() + val unhealthyDependencies = healthStatus.filter { it.value == "Down" } + + if (unhealthyDependencies.isNotEmpty()) { + logger.error("Startup failed. Dependencies not ready: ${unhealthyDependencies.map { "${it.key}: ${it.value}" }.joinToString(", ")}") + throw IllegalStateException("Dependencies not ready: ${unhealthyDependencies.map { "${it.key}: ${it.value}" }.joinToString(", ")}") + } else { + logger.info("All dependencies are healthy on startup: ${healthStatus.map { "${it.key}: ${it.value}" }.joinToString(", ")}") + } + } + +} \ No newline at end of file diff --git a/bpdm-pool/src/main/resources/application.yml b/bpdm-pool/src/main/resources/application.yml index 33234726f..b8f0a8c45 100644 --- a/bpdm-pool/src/main/resources/application.yml +++ b/bpdm-pool/src/main/resources/application.yml @@ -141,6 +141,7 @@ logging: management: endpoint: health: + show-details: always probes: # Enable actuator health endpoints for probing enabled: true diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/config/MockHealthIndicatorConfig.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/config/MockHealthIndicatorConfig.kt new file mode 100644 index 000000000..875ba3ed0 --- /dev/null +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/config/MockHealthIndicatorConfig.kt @@ -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.pool.config + +import io.mockk.every +import io.mockk.mockk +import org.eclipse.tractusx.bpdm.pool.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 { + every { health() } returns Health.up().build() + } + } +} \ No newline at end of file diff --git a/charts/bpdm/values.yaml b/charts/bpdm/values.yaml index 53c808632..9f9efc28a 100644 --- a/charts/bpdm/values.yaml +++ b/charts/bpdm/values.yaml @@ -81,3 +81,19 @@ centralidp: enabled: true keycloak: fullnameOverride: bpdm-centralidp + realmSeeding: + # SET client secrets for all non-testing and non-local purposes, default value is autogenerated. + serviceAccounts: + clientSecrets: + - clientId: sa-cl7-cx-1 + clientSecret: "**********" + - clientId: sa-cl7-cx-5 + clientSecret: "**********" + - clientId: sa-cl7-cx-7 + clientSecret: "**********" + - clientId: sa-cl25-cx-1 + clientSecret: "**********" + - clientId: sa-cl25-cx-2 + clientSecret: "**********" + - clientId: sa-cl25-cx-3 + clientSecret: "**********"