chore: initial commit
Signed-off-by: Alan Brault <alan.brault@visus.io>
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
package io.visus.demos.kotlinapi.domain.model
|
||||
|
||||
data class ComponentHealth(
|
||||
val name: String,
|
||||
val status: ComponentStatus,
|
||||
val message: String? = null,
|
||||
)
|
||||
@@ -0,0 +1,6 @@
|
||||
package io.visus.demos.kotlinapi.domain.model
|
||||
|
||||
enum class ComponentStatus {
|
||||
UP,
|
||||
DOWN,
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package io.visus.demos.kotlinapi.domain.model
|
||||
|
||||
import java.time.Instant
|
||||
|
||||
data class HealthStatus(
|
||||
val status: Status,
|
||||
val timestamp: Instant,
|
||||
val components: Map<String, ComponentHealth> = emptyMap(),
|
||||
) {
|
||||
companion object {
|
||||
fun fromComponents(components: List<ComponentHealth>): HealthStatus {
|
||||
val componentMap = components.associateBy { it.name }
|
||||
val status =
|
||||
when {
|
||||
components.all { it.status == ComponentStatus.UP } -> Status.UP
|
||||
components.all { it.status == ComponentStatus.DOWN } -> Status.DOWN
|
||||
else -> Status.DEGRADED
|
||||
}
|
||||
|
||||
return HealthStatus(
|
||||
status = status,
|
||||
timestamp = Instant.now(),
|
||||
components = componentMap,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package io.visus.demos.kotlinapi.domain.model
|
||||
|
||||
enum class Status {
|
||||
UP,
|
||||
DOWN,
|
||||
DEGRADED,
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package io.visus.demos.kotlinapi.domain.service
|
||||
|
||||
import io.visus.demos.kotlinapi.domain.model.ComponentHealth
|
||||
|
||||
interface HealthService {
|
||||
fun check(): ComponentHealth
|
||||
}
|
||||
Reference in New Issue
Block a user