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 | d60057a77e7ac601d3796096f36c4b9ca585d1a5 (patch) | |
tree | 96f5ee80845da5881dc74a86dcbfb11f8c8deafa /ms/blueprintsprocessor/modules | |
parent | 9a5eb36cf6f51b2ebbb77fe67898ecc899125e6f (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')
2 files changed, 28 insertions, 10 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 d8afe168..05a569cb 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 diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/AbstractComponentFunction.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/AbstractComponentFunction.kt index 8778b1fc..4c381706 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/AbstractComponentFunction.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/AbstractComponentFunction.kt @@ -138,7 +138,7 @@ abstract class AbstractComponentFunction : BlueprintFunctionNode<ExecutionServic }
fun addError(type: String, name: String, error: String) {
- bluePrintRuntimeService.getBluePrintError().addError(type, name, type)
+ bluePrintRuntimeService.getBluePrintError().addError(type, name, error)
}
fun addError(error: String) {
|