Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/commonMain/resources/static-content/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,41 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/packageServerStatus"
/health/ready:
get:
tags:
- Health
description: "Readiness probe. Returns 200 OK if all presets have been loaded and the validation service is ready, otherwise returns 503."
operationId: healthReady
responses:
"200":
description: OK
content:
text/plain:
schema:
type: string
example: OK
"503":
description: Service Unavailable
content:
text/plain:
schema:
type: string
example: ValidationService not ready
/health/live:
get:
tags:
- Health
description: "Liveness probe. Always returns OK if the service is running."
operationId: healthLive
responses:
"200":
description: OK
content:
text/plain:
schema:
type: string
example: OK


components:
Expand Down
2 changes: 2 additions & 0 deletions src/jvmMain/kotlin/Module.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import io.ktor.serialization.gson.*
import controller.debug.debugModule
import controller.health.healthModule
import controller.ig.igModule
import controller.terminology.terminologyModule
import controller.uptime.uptimeModule
Expand Down Expand Up @@ -96,6 +97,7 @@ fun Application.setup() {
validationModule()
terminologyModule()
uptimeModule()
healthModule()

get("/") {
call.respondText(
Expand Down
25 changes: 25 additions & 0 deletions src/jvmMain/kotlin/controller/health/HealthModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package controller.health

import controller.validation.ValidationServiceStatus
import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.ktor.http.*

fun Route.healthModule() {
route("/health/ready") {
get {
if (ValidationServiceStatus.isReady()) {
call.respond(HttpStatusCode.OK, "OK")
} else {
call.respond(HttpStatusCode.ServiceUnavailable, "ValidationService not ready")
}
}
}

route("/health/live") {
get {
call.respond(HttpStatusCode.OK, "OK")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,19 @@ class ValidationServiceFactoryImpl : ValidationServiceFactory {
val validationService =
ValidationService(sessionCache);
thread {
presets.forEach {
if (it.key != "CUSTOM") {
println("Loading preset: " + it.key)
try {
validationService.putBaseEngine(it.key, it.validationContext)
} catch (e: Exception) {
println("Error loading preset: " + it.key)
e.printStackTrace()
presets.forEach {
if (it.key != "CUSTOM") {
println("Loading preset: " + it.key)
try {
validationService.putBaseEngine(it.key, it.validationContext)
} catch (e: Exception) {
println("Error loading preset: " + it.key)
e.printStackTrace()
}
println("Preset loaded: " + it.key);
}
println("Preset loaded: " + it.key);
}
}
ValidationServiceStatus.setService(validationService)
}
return validationService
}
Expand Down Expand Up @@ -71,7 +72,7 @@ class ValidationServiceFactoryImpl : ValidationServiceFactory {
return Collections.unmodifiableList(presets)
}

override fun getValidationService() : ValidationService {
override fun getValidationService(): ValidationService {
if (java.lang.Runtime.getRuntime().freeMemory() < validationServiceConfig.engineReloadThreshold) {
println(
"Free memory ${
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package controller.validation

import org.hl7.fhir.validation.service.ValidationService
import java.util.concurrent.atomic.AtomicReference

object ValidationServiceStatus {
private val serviceRef = AtomicReference<ValidationService?>(null)

fun setService(service: ValidationService) {
serviceRef.set(service)
}

fun isReady(): Boolean = serviceRef.get() != null
}