-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bpdm): added connection to dependencies in readiness check for b…
…pdm services
- Loading branch information
1 parent
a607f4a
commit f4cc099
Showing
17 changed files
with
542 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...ning-service-dummy/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/config/AppConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
.../src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/util/CleaningServiceStartupListner.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
...my/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/util/OrchestratorHealthIndicator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...my/src/test/kotlin/org/eclipse/tractusx/bpdm/cleaning/config/MockHealthIndicatorConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/config/AppConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/util/GateServiceStartupListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/util/OrchestratorHealthIndicator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/util/PoolHealthIndicator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.