summaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints
diff options
context:
space:
mode:
Diffstat (limited to 'ms/controllerblueprints')
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/interfaces/BluePrintScriptsService.kt4
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/interfaces/BlueprintFunctionNode.kt42
-rw-r--r--ms/controllerblueprints/modules/blueprint-scripts/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/scripts/BluePrintScriptsServiceImpl.kt14
-rw-r--r--ms/controllerblueprints/modules/blueprint-scripts/src/test/resources/scripts1/simple.cba.kts11
-rw-r--r--ms/controllerblueprints/modules/blueprint-scripts/src/test/resources/scripts2/simple.cba.kts11
5 files changed, 59 insertions, 23 deletions
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/interfaces/BluePrintScriptsService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/interfaces/BluePrintScriptsService.kt
index 6db872062..8bb0cd0ce 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/interfaces/BluePrintScriptsService.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/interfaces/BluePrintScriptsService.kt
@@ -21,8 +21,8 @@ import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
interface BluePrintScriptsService {
- fun <T> scriptInstance(blueprintContext: BluePrintContext, scriptClassName: String,
+ suspend fun <T> scriptInstance(blueprintContext: BluePrintContext, scriptClassName: String,
reCompile: Boolean): T
- fun <T> scriptInstance(scriptClassName: String): T
+ suspend fun <T> scriptInstance(scriptClassName: String): T
} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/interfaces/BlueprintFunctionNode.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/interfaces/BlueprintFunctionNode.kt
index a74adf970..932b9a09f 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/interfaces/BlueprintFunctionNode.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/interfaces/BlueprintFunctionNode.kt
@@ -1,5 +1,6 @@
/*
* Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2019 IBM.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +17,7 @@
package org.onap.ccsdk.cds.controllerblueprints.core.interfaces
+import kotlinx.coroutines.runBlocking
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
import java.util.function.Function
@@ -25,15 +27,47 @@ interface BlueprintFunctionNode<T, R> : Function<T, R> {
fun getName(): String
@Throws(BluePrintProcessorException::class)
- fun prepareRequest(executionRequest: T): T
+ fun prepareRequest(executionRequest: T): T = runBlocking {
+ prepareRequestNB(executionRequest)
+ }
@Throws(BluePrintProcessorException::class)
- fun process(executionRequest: T)
+ fun process(executionRequest: T) = runBlocking {
+ processNB(executionRequest)
+ }
@Throws(BluePrintProcessorException::class)
- fun recover(runtimeException: RuntimeException, executionRequest: T)
+ fun recover(runtimeException: RuntimeException, executionRequest: T) = runBlocking {
+ recoverNB(runtimeException, executionRequest)
+ }
@Throws(BluePrintProcessorException::class)
- fun prepareResponse(): R
+ fun prepareResponse(): R = runBlocking {
+ prepareResponseNB()
+ }
+ override fun apply(executionServiceInput: T): R {
+ try {
+ prepareRequest(executionServiceInput)
+ process(executionServiceInput)
+ } catch (runtimeException: RuntimeException) {
+ recover(runtimeException, executionServiceInput)
+ }
+ return prepareResponse()
+ }
+
+ @Throws(BluePrintProcessorException::class)
+ suspend fun prepareRequestNB(executionRequest: T): T
+
+ @Throws(BluePrintProcessorException::class)
+ suspend fun processNB(executionRequest: T)
+
+ @Throws(BluePrintProcessorException::class)
+ suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: T)
+
+ @Throws(BluePrintProcessorException::class)
+ suspend fun prepareResponseNB(): R
+
+ @Throws(BluePrintProcessorException::class)
+ suspend fun applyNB(t: T): R
} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/blueprint-scripts/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/scripts/BluePrintScriptsServiceImpl.kt b/ms/controllerblueprints/modules/blueprint-scripts/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/scripts/BluePrintScriptsServiceImpl.kt
index ce1a6b1af..9438c1f4b 100644
--- a/ms/controllerblueprints/modules/blueprint-scripts/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/scripts/BluePrintScriptsServiceImpl.kt
+++ b/ms/controllerblueprints/modules/blueprint-scripts/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/scripts/BluePrintScriptsServiceImpl.kt
@@ -30,14 +30,14 @@ import kotlin.script.experimental.jvmhost.createJvmCompilationConfigurationFromT
@Service
open class BluePrintScriptsServiceImpl : BluePrintScriptsService {
- override fun <T> scriptInstance(blueprintContext: BluePrintContext, scriptClassName: String,
- reCompile: Boolean): T {
+ override suspend fun <T> scriptInstance(blueprintContext: BluePrintContext, scriptClassName: String,
+ reCompile: Boolean): T {
val kotlinScriptPath = blueprintContext.rootPath.plus(File.separator)
.plus(BluePrintConstants.TOSCA_SCRIPTS_KOTLIN_DIR)
val compiledJar = kotlinScriptPath.plus(File.separator)
- .plus(getBluePrintScriptsJarName(blueprintContext))
+ .plus(bluePrintScriptsJarName(blueprintContext))
val scriptSource = BluePrintSourceCode()
@@ -59,13 +59,13 @@ open class BluePrintScriptsServiceImpl : BluePrintScriptsService {
return returnValue?.value!! as T
}
- override fun <T> scriptInstance(scriptClassName: String): T {
+ override suspend fun <T> scriptInstance(scriptClassName: String): T {
val args = ArrayList<Any?>()
return Thread.currentThread().contextClassLoader.loadClass(scriptClassName).constructors
.single().newInstance(*args.toArray()) as T
}
-}
-fun getBluePrintScriptsJarName(blueprintContext: BluePrintContext): String {
- return "${blueprintContext.name()}-${blueprintContext.version()}-cba-kts.jar"
+ private fun bluePrintScriptsJarName(blueprintContext: BluePrintContext): String {
+ return "${blueprintContext.name()}-${blueprintContext.version()}-cba-kts.jar"
+ }
} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/blueprint-scripts/src/test/resources/scripts1/simple.cba.kts b/ms/controllerblueprints/modules/blueprint-scripts/src/test/resources/scripts1/simple.cba.kts
index 09de439c5..4fffda051 100644
--- a/ms/controllerblueprints/modules/blueprint-scripts/src/test/resources/scripts1/simple.cba.kts
+++ b/ms/controllerblueprints/modules/blueprint-scripts/src/test/resources/scripts1/simple.cba.kts
@@ -1,5 +1,6 @@
/*
* Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2019 IBM.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,23 +28,23 @@ open class SampleComponentFunction : BlueprintFunctionNode<String, String> {
return "my Name"
}
- override fun prepareRequest(executionRequest: String): String {
+ override suspend fun prepareRequestNB(executionRequest: String): String {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
- override fun process(executionRequest: String) {
+ override suspend fun processNB(executionRequest: String) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
- override fun recover(runtimeException: RuntimeException, executionRequest: String) {
+ override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: String) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
- override fun prepareResponse(): String {
+ override suspend fun prepareResponseNB(): String {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
- override fun apply(t: String): String {
+ override suspend fun applyNB(t: String): String {
return "Script 1 response - $t"
}
}
diff --git a/ms/controllerblueprints/modules/blueprint-scripts/src/test/resources/scripts2/simple.cba.kts b/ms/controllerblueprints/modules/blueprint-scripts/src/test/resources/scripts2/simple.cba.kts
index d6134a6cd..4ba56c491 100644
--- a/ms/controllerblueprints/modules/blueprint-scripts/src/test/resources/scripts2/simple.cba.kts
+++ b/ms/controllerblueprints/modules/blueprint-scripts/src/test/resources/scripts2/simple.cba.kts
@@ -1,5 +1,6 @@
/*
* Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2019 IBM.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,23 +28,23 @@ open class SampleComponentFunction : BlueprintFunctionNode<String, String> {
return "my Name"
}
- override fun prepareRequest(executionRequest: String): String {
+ override suspend fun prepareRequestNB(executionRequest: String): String {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
- override fun process(executionRequest: String) {
+ override suspend fun processNB(executionRequest: String) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
- override fun recover(runtimeException: RuntimeException, executionRequest: String) {
+ override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: String) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
- override fun prepareResponse(): String {
+ override suspend fun prepareResponseNB(): String {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
- override fun apply(t: String): String {
+ override suspend fun applyNB(t: String): String {
return "Script 2 response - $t"
}
}