diff options
author | Alexis de Talhouët <adetalhouet89@gmail.com> | 2019-03-13 17:39:15 -0400 |
---|---|---|
committer | Alexis de Talhouët <adetalhouet89@gmail.com> | 2019-03-18 16:52:39 +0000 |
commit | b3c5b43df50938d7305b1994795829c27ffa2905 (patch) | |
tree | a98b48e3122e1c2ee18420ebf8bc89b03dac6af1 /ms/blueprintsprocessor/modules/inbounds/selfservice-api | |
parent | 743f1dcbd282cd240cab9b5fdd332711924d4e4b (diff) |
Propagate exceptions correctly
Change-Id: Idaf66eeaa6e57d27c576099fd6ffdeb8b6d8d6c6
Issue-ID: CCSDK-1120
Signed-off-by: Alexis de Talhouët <adetalhouet89@gmail.com>
Diffstat (limited to 'ms/blueprintsprocessor/modules/inbounds/selfservice-api')
-rw-r--r-- | ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt | 36 |
1 files changed, 27 insertions, 9 deletions
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 d8afe1688..05a569cb8 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 @@ -23,7 +23,11 @@ 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.* +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.selfservice.api.utils.toProto import org.onap.ccsdk.apps.controllerblueprints.common.api.EventType @@ -37,6 +41,7 @@ import org.slf4j.LoggerFactory import org.springframework.http.codec.multipart.FilePart import org.springframework.stereotype.Service import reactor.core.publisher.Mono +import java.util.stream.Collectors @Service class ExecutionServiceHandler(private val bluePrintCoreConfiguration: BluePrintCoreConfiguration, @@ -75,8 +80,8 @@ class ExecutionServiceHandler(private val bluePrintCoreConfiguration: BluePrintC responseObserver.onCompleted() } else -> responseObserver.onNext(response(executionServiceInput, - "Failed to process request, 'actionIdentifiers.mode' not specified. Valid value are: 'sync' or 'async'.", - true).toProto()); + "Failed to process request, 'actionIdentifiers.mode' not specified. Valid value are: 'sync' or 'async'.", + true).toProto()); } } @@ -94,8 +99,23 @@ class ExecutionServiceHandler(private val bluePrintCoreConfiguration: BluePrintC val blueprintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(requestId, basePath.toString()) - return bluePrintWorkflowExecutionService.executeBluePrintWorkflow(blueprintRuntimeService, - executionServiceInput, hashMapOf()) + val output = bluePrintWorkflowExecutionService.executeBluePrintWorkflow(blueprintRuntimeService, + executionServiceInput, hashMapOf()) + + val errors = blueprintRuntimeService.getBluePrintError().errors + if (errors.isNotEmpty()) { + val errorMessage = errors.stream().map { it.toString() }.collect(Collectors.joining(", ")) + setErrorStatus(errorMessage, output.status) + } + + return output + } + + private fun setErrorStatus(errorMessage: String, status: Status) { + status.errorMessage = errorMessage + status.eventType = EventType.EVENT_COMPONENT_FAILURE.name + status.code = 500 + status.message = BluePrintConstants.STATUS_FAILURE } private fun response(executionServiceInput: ExecutionServiceInput, errorMessage: String = "", @@ -106,11 +126,8 @@ class ExecutionServiceHandler(private val bluePrintCoreConfiguration: BluePrintC executionServiceOutput.payload = JsonNodeFactory.instance.objectNode() val status = Status() - status.errorMessage = errorMessage if (failure) { - status.eventType = EventType.EVENT_COMPONENT_FAILURE.name - status.code = 500 - status.message = BluePrintConstants.STATUS_FAILURE + setErrorStatus(errorMessage, status) } else { status.eventType = EventType.EVENT_COMPONENT_PROCESSING.name status.code = 200 @@ -121,4 +138,5 @@ class ExecutionServiceHandler(private val bluePrintCoreConfiguration: BluePrintC return executionServiceOutput } + }
\ No newline at end of file |