Add check for cluster status to readiness endpoint 51/120951/1
authorJozsef Csongvai <jozsef.csongvai@bell.ca>
Wed, 28 Apr 2021 18:49:22 +0000 (14:49 -0400)
committerJozsef Csongvai <jozsef.csongvai@bell.ca>
Wed, 28 Apr 2021 18:58:19 +0000 (18:58 +0000)
When Cluster is enabled, BlueprintsProcessor should not process
any requests until cluster is fully joined.

Issue-ID: CCSDK-3275
Change-Id: I779159346976f7af0c0add69883f27d7f359f413
Signed-off-by: Jozsef Csongvai <jozsef.csongvai@bell.ca>
ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt

index 7628da2..6c6c26c 100644 (file)
@@ -24,11 +24,14 @@ import io.swagger.annotations.ApiParam
 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ACTION_MODE_ASYNC
 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput
+import org.onap.ccsdk.cds.blueprintsprocessor.core.cluster.optionalClusterService
 import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.mdcWebCoroutineScope
 import org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.utils.determineHttpStatusCode
-import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
+import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants
+import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType
 import org.onap.ccsdk.cds.controllerblueprints.core.httpProcessorException
 import org.onap.ccsdk.cds.controllerblueprints.core.logger
+import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintDependencyService
 import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogCodes
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.http.MediaType
@@ -64,8 +67,16 @@ open class ExecutionServiceController {
     )
     @ResponseBody
     @ApiOperation(value = "Health Check", hidden = true)
-    suspend fun executionServiceControllerHealthCheck(): JsonNode = mdcWebCoroutineScope {
-        "Success".asJsonPrimitive()
+    suspend fun executionServiceControllerHealthCheck(): ResponseEntity<JsonNode> = mdcWebCoroutineScope {
+        var body = mutableMapOf("success" to true)
+        var statusCode = 200
+        if (BlueprintConstants.CLUSTER_ENABLED &&
+            BlueprintDependencyService.optionalClusterService()?.clusterJoined() != true
+        ) {
+            statusCode = 503
+            body.remove("success")
+        }
+        ResponseEntity.status(statusCode).body(body.asJsonType())
     }
 
     @RequestMapping(path = ["/process"], method = [RequestMethod.POST], produces = [MediaType.APPLICATION_JSON_VALUE])