From b3c5b43df50938d7305b1994795829c27ffa2905 Mon Sep 17 00:00:00 2001 From: Alexis de Talhouët Date: Wed, 13 Mar 2019 17:39:15 -0400 Subject: Propagate exceptions correctly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Idaf66eeaa6e57d27c576099fd6ffdeb8b6d8d6c6 Issue-ID: CCSDK-1120 Signed-off-by: Alexis de Talhouët --- .../resolution/ResourceResolutionComponent.kt | 2 +- .../resolution/ResourceResolutionService.kt | 3 ++ .../DatabaseResourceAssignmentProcessor.kt | 1 + .../DefaultResourceResolutionProcessor.kt | 1 + .../processor/InputResourceResolutionProcessor.kt | 1 + .../processor/ResourceAssignmentProcessor.kt | 16 +++++++--- .../processor/RestResourceResolutionProcessor.kt | 1 + .../CapabilityResourceResolutionProcessorTest.kt | 2 ++ .../selfservice/api/ExecutionServiceHandler.kt | 36 ++++++++++++++++------ .../execution/AbstractComponentFunction.kt | 2 +- 10 files changed, 50 insertions(+), 15 deletions(-) (limited to 'ms') diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt index 819fe3f87..98d8c65db 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt @@ -57,6 +57,6 @@ open class ResourceResolutionComponent(private val resourceResolutionService: Re } override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + bluePrintRuntimeService.getBluePrintError().addError(runtimeException.message!!) } } \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt index 335aea1ef..620696f86 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt @@ -182,6 +182,9 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica resourceAssignmentProcessor.resourceDictionaries = resourceDictionaries // Invoke Apply Method resourceAssignmentProcessor.apply(resourceAssignment) + + // Set errors from RA + blueprintRuntimeService.setBluePrintError(resourceAssignmentRuntimeService.getBluePrintError()) } catch (e: RuntimeException) { throw BluePrintProcessorException(e) } diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt index c76bff322..e38a1ccad 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt @@ -170,5 +170,6 @@ open class DatabaseResourceAssignmentProcessor(private val dBLibGenericService: } override fun recover(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) { + raRuntimeService.getBluePrintError().addError(runtimeException.message!!) } } \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt index d487eab69..0f51e4bff 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt @@ -60,5 +60,6 @@ open class DefaultResourceResolutionProcessor : ResourceAssignmentProcessor() { } override fun recover(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) { + raRuntimeService.getBluePrintError().addError(runtimeException.message!!) } } \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt index a66222281..579989a61 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt @@ -63,5 +63,6 @@ open class InputResourceResolutionProcessor : ResourceAssignmentProcessor() { } override fun recover(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) { + raRuntimeService.getBluePrintError().addError(runtimeException.message!!) } } \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt index 8e9606c4e..3f0c1b4ff 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt @@ -30,7 +30,7 @@ import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition import org.slf4j.LoggerFactory import java.util.* -abstract class ResourceAssignmentProcessor : BlueprintFunctionNode { +abstract class ResourceAssignmentProcessor : BlueprintFunctionNode { private val log = LoggerFactory.getLogger(ResourceAssignmentProcessor::class.java) @@ -89,12 +89,12 @@ abstract class ResourceAssignmentProcessor : BlueprintFunctionNode 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 8778b1fcd..4c381706a 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