diff options
author | Lukasz Rajewski <lukasz.rajewski@t-mobile.pl> | 2023-04-07 12:09:21 +0000 |
---|---|---|
committer | Lukasz Rajewski <lukasz.rajewski@t-mobile.pl> | 2023-04-07 12:09:21 +0000 |
commit | 6db73002faffaa35caed91c4d440f694ec074ea1 (patch) | |
tree | a0eb0406741d0b1a41960da1b63cb679ae2c79db /ms/blueprintsprocessor/modules | |
parent | 3a47bb36c7984660054f89f7586f1c03d055878a (diff) |
Add db connection status check as option for readiness healthcheck
Issue-ID: CCSDK-3887
Signed-off-by: Lukasz Rajewski <lukasz.rajewski@t-mobile.pl>
Change-Id: I1e32dedc6abaf829fe82733548cb9c26ea386117
Diffstat (limited to 'ms/blueprintsprocessor/modules')
-rw-r--r-- | ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt index 9e0a7ee71..bed8b80e9 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt @@ -36,10 +36,12 @@ import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogCodes import org.springframework.beans.factory.annotation.Autowired import org.springframework.http.MediaType import org.springframework.http.ResponseEntity +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean import org.springframework.security.access.prepost.PreAuthorize import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RequestMethod +import org.springframework.web.bind.annotation.RequestParam import org.springframework.web.bind.annotation.ResponseBody import org.springframework.web.bind.annotation.RestController import java.util.concurrent.Phaser @@ -60,6 +62,9 @@ open class ExecutionServiceController { @Autowired lateinit var executionServiceHandler: ExecutionServiceHandler + @Autowired + lateinit var primaryEntityManager: LocalContainerEntityManagerFactoryBean + @RequestMapping( path = ["/health-check"], method = [RequestMethod.GET], @@ -67,11 +72,19 @@ open class ExecutionServiceController { ) @ResponseBody @ApiOperation(value = "Health Check", hidden = true) - suspend fun executionServiceControllerHealthCheck(): ResponseEntity<JsonNode> = mdcWebCoroutineScope { + suspend fun executionServiceControllerHealthCheck( + @RequestParam(required = false, defaultValue = "false") checkDependencies: Boolean + ): ResponseEntity<JsonNode> = mdcWebCoroutineScope { var body = mutableMapOf("success" to true) var statusCode = 200 - if (BluePrintConstants.CLUSTER_ENABLED && - BluePrintDependencyService.optionalClusterService()?.clusterJoined() != true + if ( + ( + BluePrintConstants.CLUSTER_ENABLED && + BluePrintDependencyService.optionalClusterService()?.clusterJoined() != true + ) || + ( + checkDependencies && !primaryEntityManager.dataSource.connection.isValid(1) + ) ) { statusCode = 503 body.remove("success") |