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 16, 2024
1 parent a607f4a commit f4cc099
Show file tree
Hide file tree
Showing 17 changed files with 542 additions and 5 deletions.
10 changes: 5 additions & 5 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 @@ -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
@@ -0,0 +1,33 @@
/*******************************************************************************
* 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()
}
}
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,48 @@
/*******************************************************************************
* 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.boot.actuate.health.Health
import org.springframework.boot.actuate.health.HealthIndicator
import org.springframework.stereotype.Component
import org.springframework.web.client.RestTemplate

@Component("orchestratorHealth")
class OrchestratorHealthIndicator(
private val restTemplate: RestTemplate,
private val orchestratorConfigProperties: OrchestratorConfigProperties
) : HealthIndicator {

override fun health(): Health {

val orchestratorHealthUrl = "${orchestratorConfigProperties.baseUrl}/actuator/health"
return try {
val response = restTemplate.getForEntity(orchestratorHealthUrl, String::class.java)
if (response.statusCode.is2xxSuccessful) {
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 @@ -78,6 +78,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()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*******************************************************************************
* 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 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()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*******************************************************************************
* 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.springframework.boot.actuate.health.Status
import org.springframework.boot.context.event.ApplicationReadyEvent
import org.springframework.context.ApplicationListener
import org.springframework.stereotype.Component

@Component
class GateServiceStartupListener(
private val poolHealthIndicator: PoolHealthIndicator,
private val orchestratorHealthIndicator: OrchestratorHealthIndicator
) : ApplicationListener<ApplicationReadyEvent> {

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

if (poolHealth != Status.UP || orchestratorHealth != Status.UP) {
throw IllegalStateException("Dependencies not ready: Pool: $poolHealth, Orchestrator: $orchestratorHealth")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*******************************************************************************
* 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.gate.config.OrchestratorClientConfigurationProperties
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

@Component("orchestratorHealth")
class OrchestratorHealthIndicator(
private val restTemplate: RestTemplate,
private val orchestratorClientProperties: OrchestratorClientConfigurationProperties
) : HealthIndicator {

override fun health(): Health {

val orchestratorHealthUrl = "${orchestratorClientProperties.baseUrl}/actuator/health"
return try {
val response = restTemplate.getForEntity(orchestratorHealthUrl, String::class.java)
if (response.statusCode.is2xxSuccessful) {
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
@@ -0,0 +1,48 @@
/*******************************************************************************
* 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.gate.config.PoolClientConfigurationProperties
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

@Component("poolHealth")
class PoolHealthIndicator(
private val restTemplate: RestTemplate,
private val poolClientProperties: PoolClientConfigurationProperties
) : HealthIndicator {

override fun health(): Health {

val poolHealthUrl = "${poolClientProperties.baseUrl}/actuator/health"
return try {
val response = restTemplate.getForEntity(poolHealthUrl, String::class.java)
if (response.statusCode.is2xxSuccessful) {
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()
}
}
}
1 change: 1 addition & 0 deletions bpdm-gate/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ logging:
management:
endpoint:
health:
show-details: always
probes:
# Enable actuator health endpoints for probing
enabled: true
Expand Down
Loading

0 comments on commit f4cc099

Please sign in to comment.