-
Notifications
You must be signed in to change notification settings - Fork 16
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
f4cc099
commit e37a5d0
Showing
18 changed files
with
362 additions
and
42 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
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
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
63 changes: 63 additions & 0 deletions
63
...my/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/config/DependencyHealthScheduler.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,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)) | ||
} | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
...mmy/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/service/DependencyHealthService.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.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 | ||
) | ||
} | ||
} |
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
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
63 changes: 63 additions & 0 deletions
63
bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/config/DependencyHealthScheduler.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,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)) | ||
} | ||
} | ||
|
||
} |
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
42 changes: 42 additions & 0 deletions
42
bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/DependencyHealthService.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,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<String, String> { | ||
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 | ||
) | ||
} | ||
} |
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
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
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
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.