From d60057a77e7ac601d3796096f36c4b9ca585d1a5 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 --- .../golden/Scripts/python/DescriptionExample.py | 4 +-- .../golden/Scripts/python/NetconfRpcExample.py | 2 +- .../golden/Scripts/python/Rollback.py | 2 +- .../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 +- .../resource/dict/ResourceDictionaryConstants.kt | 2 +- 14 files changed, 55 insertions(+), 20 deletions(-) diff --git a/components/model-catalog/blueprint-model/test-blueprint/golden/Scripts/python/DescriptionExample.py b/components/model-catalog/blueprint-model/test-blueprint/golden/Scripts/python/DescriptionExample.py index fce7c324..4cf635af 100644 --- a/components/model-catalog/blueprint-model/test-blueprint/golden/Scripts/python/DescriptionExample.py +++ b/components/model-catalog/blueprint-model/test-blueprint/golden/Scripts/python/DescriptionExample.py @@ -42,5 +42,5 @@ class DescriptionExample(AbstractRAProcessor): return None def recover(self, runtime_exception, resource_assignment): - print "NoOp" - return None + print self.addError(runtime_exception.getMessage()) + return None \ No newline at end of file diff --git a/components/model-catalog/blueprint-model/test-blueprint/golden/Scripts/python/NetconfRpcExample.py b/components/model-catalog/blueprint-model/test-blueprint/golden/Scripts/python/NetconfRpcExample.py index ed22989f..2d22f8bb 100644 --- a/components/model-catalog/blueprint-model/test-blueprint/golden/Scripts/python/NetconfRpcExample.py +++ b/components/model-catalog/blueprint-model/test-blueprint/golden/Scripts/python/NetconfRpcExample.py @@ -57,5 +57,5 @@ class NetconfRpcExample(NetconfComponentFunction): log.error("Python Exception in the script {}", err) def recover(self, runtime_exception, execution_request): - print "Recovering calling.." + PROPERTY_BLUEPRINT_BASE_PATH + print self.addError(runtime_exception.getMessage()) return None diff --git a/components/model-catalog/blueprint-model/test-blueprint/golden/Scripts/python/Rollback.py b/components/model-catalog/blueprint-model/test-blueprint/golden/Scripts/python/Rollback.py index 73419d71..deec4700 100644 --- a/components/model-catalog/blueprint-model/test-blueprint/golden/Scripts/python/Rollback.py +++ b/components/model-catalog/blueprint-model/test-blueprint/golden/Scripts/python/Rollback.py @@ -43,5 +43,5 @@ class Rollback(NetconfComponentFunction): log.error("Python Exception in the script {}", err) def recover(self, runtime_exception, execution_request): - print "Recovering calling.." + PROPERTY_BLUEPRINT_BASE_PATH + print self.addError(runtime_exception.getMessage()) return None 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 819fe3f8..98d8c65d 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 335aea1e..620696f8 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 c76bff32..e38a1cca 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 d487eab6..0f51e4bf 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 a6622228..579989a6 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 8e9606c4..3f0c1b4f 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 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