From 40072d3dcc1d0193bba1ea9432c13ac24857be55 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh" Date: Wed, 27 Mar 2019 13:22:51 -0400 Subject: Improve function interfaces Change-Id: I24f45d39ac05491a4217101e00bcbf8d122e4e1a Issue-ID: CCSDK-1137 Signed-off-by: Muthuramalingam, Brinda Santh --- .../execution/AbstractComponentFunction.kt | 14 ++-- .../execution/AbstractScriptComponentFunction.kt | 76 ++++++++++++++++++++++ .../execution/ComponentFunctionScriptingService.kt | 6 +- 3 files changed, 87 insertions(+), 9 deletions(-) (limited to 'ms/blueprintsprocessor/modules/services/execution-service/src/main') diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt index be4327bfe..e78e87523 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt @@ -54,7 +54,7 @@ abstract class AbstractComponentFunction : BlueprintFunctionNode { + executeScriptBlocking(executionServiceInput) + } + else -> { + executeScriptNB(executionServiceInput) + } + } + } + + private suspend fun executeScriptNB(executionServiceInput: ExecutionServiceInput) { + try { + processNB(executionServiceInput) + } catch (runtimeException: RuntimeException) { + log.error("failed in ${getName()} : ${runtimeException.message}", runtimeException) + recoverNB(runtimeException, executionServiceInput) + } + } + + private fun executeScriptBlocking(executionServiceInput: ExecutionServiceInput) { + try { + process(executionServiceInput) + } catch (runtimeException: RuntimeException) { + log.error("failed in ${getName()} : ${runtimeException.message}", runtimeException) + recover(runtimeException, executionServiceInput) + } + } + + /** + * If Jython Script, Override Blocking methods(process() and recover()) + * If Kotlin or Internal Scripts, Override non blocking methods ( processNB() and recoverNB()), so default + * blocking + * methods will have default implementation, + * + * Always applyNB() method will be invoked, apply() won't be called from parent + */ + + final override fun apply(executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput { + throw BluePrintException("Not Implemented, use applyNB method") + } + + final override fun prepareRequest(executionRequest: ExecutionServiceInput): ExecutionServiceInput { + throw BluePrintException("Not Implemented required") + } + + final override fun prepareResponse(): ExecutionServiceOutput { + throw BluePrintException("Not Implemented required") + } + + final override suspend fun applyNB(executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput { + throw BluePrintException("Not Implemented required") + } + + final override suspend fun prepareRequestNB(executionRequest: ExecutionServiceInput): ExecutionServiceInput { + throw BluePrintException("Not Implemented required") + } + + final override suspend fun prepareResponseNB(): ExecutionServiceOutput { + throw BluePrintException("Not Implemented required") + } + override fun process(executionRequest: ExecutionServiceInput) { + throw BluePrintException("Not Implemented, child class will implement this") + } + + override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { + throw BluePrintException("Not Implemented, child class will implement this") + } } \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt index 907aae4cd..b2991be5e 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt @@ -33,7 +33,8 @@ class ComponentFunctionScriptingService(private val applicationContext: Applicat private val log = LoggerFactory.getLogger(ComponentFunctionScriptingService::class.java) - fun scriptInstance(componentFunction: AbstractComponentFunction, scriptType: String, + suspend fun scriptInstance(componentFunction: AbstractComponentFunction, + scriptType: String, scriptClassReference: String, instanceDependencies: List): T { @@ -53,6 +54,7 @@ class ComponentFunctionScriptingService(private val applicationContext: Applicat scriptComponent.operationName = componentFunction.operationName scriptComponent.nodeTemplateName = componentFunction.nodeTemplateName scriptComponent.operationInputs = componentFunction.operationInputs + scriptComponent.scriptType = scriptType // Populate Instance Properties instanceDependencies.forEach { instanceDependency -> @@ -63,7 +65,7 @@ class ComponentFunctionScriptingService(private val applicationContext: Applicat } - fun > scriptInstance(bluePrintContext: BluePrintContext, scriptType: String, + suspend fun > scriptInstance(bluePrintContext: BluePrintContext, scriptType: String, scriptClassReference: String): T { var scriptComponent: T? = null -- cgit 1.2.3-korg