From c96644c5d07d5634916db30f01c9ed5279791b38 Mon Sep 17 00:00:00 2001 From: Alexis de Talhouët Date: Tue, 15 Jan 2019 16:17:17 -0500 Subject: Add support for async REST MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ieb53cbd75c2e21355b153611f6490c1b2af6053b Issue-ID: CCSDK-662 Signed-off-by: Alexis de Talhouët --- .../selfservice/api/ExecutionServiceController.kt | 6 ++-- .../selfservice/api/ExecutionServiceHandler.kt | 42 ++++++++++++++++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) (limited to 'ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin') diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt index 35d4e67c5..e4734c441 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt @@ -38,7 +38,6 @@ class ExecutionServiceController { @Autowired lateinit var executionServiceHandler: ExecutionServiceHandler - @RequestMapping(path = ["/ping"], method = [RequestMethod.GET], produces = [MediaType.APPLICATION_JSON_VALUE]) @ResponseBody fun ping(): Mono { @@ -58,8 +57,7 @@ class ExecutionServiceController { @RequestMapping(path = ["/process"], method = [RequestMethod.POST], produces = [MediaType.APPLICATION_JSON_VALUE]) @ApiOperation(value = "Resolve Resource Mappings", notes = "Takes the blueprint information and process as per the payload") @ResponseBody - fun process(@RequestBody executionServiceInput: ExecutionServiceInput): Mono { - val executionServiceOutput = executionServiceHandler.process(executionServiceInput) - return Mono.just(executionServiceOutput) + fun process(@RequestBody executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput { + return executionServiceHandler.process(executionServiceInput) } } diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt index 56903745d..0b361d8ae 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt @@ -16,11 +16,18 @@ package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintCoreConfiguration +import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ACTION_MODE_ASYNC +import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ACTION_MODE_SYNC import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceOutput +import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Status import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.utils.saveCBAFile import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.BlueprintDGExecutionService +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils @@ -50,7 +57,20 @@ class ExecutionServiceHandler(private val bluePrintCoreConfiguration: BluePrintC } fun process(executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput { + return when { + executionServiceInput.actionIdentifiers.mode == ACTION_MODE_ASYNC -> { + GlobalScope.launch(Dispatchers.Default) { + // TODO post result in DMaaP + val executionServiceOutput = doProcess(executionServiceInput) + } + response(executionServiceInput) + } + executionServiceInput.actionIdentifiers.mode == ACTION_MODE_SYNC -> doProcess(executionServiceInput) + else -> response(executionServiceInput, true) + } + } + fun doProcess(executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput { val requestId = executionServiceInput.commonHeader.requestId log.info("processing request id $requestId") @@ -66,4 +86,26 @@ class ExecutionServiceHandler(private val bluePrintCoreConfiguration: BluePrintC return blueprintDGExecutionService.executeDirectedGraph(blueprintRuntimeService, executionServiceInput) } + + fun response(executionServiceInput: ExecutionServiceInput, failure: Boolean = false): ExecutionServiceOutput { + val executionServiceOutput = ExecutionServiceOutput() + executionServiceOutput.commonHeader = executionServiceInput.commonHeader + executionServiceOutput.actionIdentifiers = executionServiceInput.actionIdentifiers + executionServiceOutput.payload = executionServiceInput.payload + + val status = Status() + if (failure) { + status.eventType = "EVENT-COMPONENT-FAILURE" + status.code = 500 + status.message = BluePrintConstants.STATUS_FAILURE + } else { + status.eventType = "EVENT-COMPONENT-PROCESSING" + status.code = 200 + status.message = BluePrintConstants.STATUS_PROCESSING + } + + executionServiceOutput.status = status + + return executionServiceOutput + } } \ No newline at end of file -- cgit 1.2.3-korg