aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org
diff options
context:
space:
mode:
authorMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>2019-03-27 13:22:51 -0400
committerMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>2019-04-01 10:43:53 -0400
commit40072d3dcc1d0193bba1ea9432c13ac24857be55 (patch)
tree2fe78015e772c4cbab4fd52184530b9e52c8c3af /ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org
parent38300292cbce3bb0500593f3cc44fe129cf5c877 (diff)
Improve function interfaces
Change-Id: I24f45d39ac05491a4217101e00bcbf8d122e4e1a Issue-ID: CCSDK-1137 Signed-off-by: Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org')
-rw-r--r--ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt14
-rw-r--r--ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractScriptComponentFunction.kt76
-rw-r--r--ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt6
3 files changed, 87 insertions, 9 deletions
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<ExecutionServic
return stepName
}
- override fun prepareRequest(executionRequest: ExecutionServiceInput): ExecutionServiceInput {
+ override suspend fun prepareRequestNB(executionRequest: ExecutionServiceInput): ExecutionServiceInput {
checkNotNull(bluePrintRuntimeService) { "failed to prepare blueprint runtime" }
check(stepName.isNotEmpty()) { "failed to assign step name" }
@@ -93,7 +93,7 @@ abstract class AbstractComponentFunction : BlueprintFunctionNode<ExecutionServic
return executionRequest
}
- override fun prepareResponse(): ExecutionServiceOutput {
+ override suspend fun prepareResponseNB(): ExecutionServiceOutput {
log.info("Preparing Response...")
executionServiceOutput.commonHeader = executionServiceInput.commonHeader
executionServiceOutput.actionIdentifiers = executionServiceInput.actionIdentifiers
@@ -114,15 +114,15 @@ abstract class AbstractComponentFunction : BlueprintFunctionNode<ExecutionServic
return this.executionServiceOutput
}
- override fun apply(executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput {
+ override suspend fun applyNB(executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput {
try {
- prepareRequest(executionServiceInput)
- process(executionServiceInput)
+ prepareRequestNB(executionServiceInput)
+ processNB(executionServiceInput)
} catch (runtimeException: RuntimeException) {
log.error("failed in ${getName()} : ${runtimeException.message}", runtimeException)
- recover(runtimeException, executionServiceInput)
+ recoverNB(runtimeException, executionServiceInput)
}
- return prepareResponse()
+ return prepareResponseNB()
}
fun getOperationInput(key: String): JsonNode {
diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractScriptComponentFunction.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractScriptComponentFunction.kt
index 789ba9f5f..27cde8a49 100644
--- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractScriptComponentFunction.kt
+++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractScriptComponentFunction.kt
@@ -17,14 +17,22 @@
package org.onap.ccsdk.cds.blueprintsprocessor.services.execution
import com.fasterxml.jackson.databind.JsonNode
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
+import org.slf4j.LoggerFactory
abstract class AbstractScriptComponentFunction : AbstractComponentFunction() {
+ private val log = LoggerFactory.getLogger(AbstractScriptComponentFunction::class.java)!!
companion object {
const val DYNAMIC_PROPERTIES = "dynamic-properties"
}
+ lateinit var scriptType: String
+
/**
* Store Dynamic Script Dependency Instances, Objects present inside won't be persisted or state maintained.
*/
@@ -46,5 +54,73 @@ abstract class AbstractScriptComponentFunction : AbstractComponentFunction() {
return operationInputs[DYNAMIC_PROPERTIES]!!.get(key)
}
+ suspend fun executeScript(executionServiceInput: ExecutionServiceInput) {
+ return when (scriptType) {
+ BluePrintConstants.SCRIPT_JYTHON -> {
+ 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 <T : AbstractScriptComponentFunction> scriptInstance(componentFunction: AbstractComponentFunction, scriptType: String,
+ suspend fun <T : AbstractScriptComponentFunction> scriptInstance(componentFunction: AbstractComponentFunction,
+ scriptType: String,
scriptClassReference: String,
instanceDependencies: List<String>): 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 <T : BlueprintFunctionNode<*, *>> scriptInstance(bluePrintContext: BluePrintContext, scriptType: String,
+ suspend fun <T : BlueprintFunctionNode<*, *>> scriptInstance(bluePrintContext: BluePrintContext, scriptType: String,
scriptClassReference: String): T {
var scriptComponent: T? = null