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/BluePrintProcessorException.kt6
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTemplateDSLBuilder.kt12
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintIOUtils.kt36
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintIOUtilsTest.kt42
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JsonParserUtilsTest.kt3
5 files changed, 98 insertions, 1 deletions
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintProcessorException.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintProcessorException.kt
index 6d11f0349..0a530708f 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintProcessorException.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintProcessorException.kt
@@ -48,3 +48,9 @@ class BluePrintProcessorException : RuntimeException {
}
}
+class BluePrintRetryException : RuntimeException {
+ constructor(message: String, cause: Throwable) : super(message, cause)
+ constructor(message: String) : super(message)
+ constructor(cause: Throwable) : super(cause)
+ constructor(cause: Throwable, message: String, vararg args: Any?) : super(format(message, *args), cause)
+}
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTemplateDSLBuilder.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTemplateDSLBuilder.kt
index eec59d1a7..fd747f09c 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTemplateDSLBuilder.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTemplateDSLBuilder.kt
@@ -227,6 +227,10 @@ class OperationAssignmentBuilder(private val id: String,
private var operationAssignment: OperationAssignment = OperationAssignment()
+ fun implementation(implementation: Implementation?) {
+ operationAssignment.implementation = implementation
+ }
+
fun implementation(timeout: Int, operationHost: String? = BluePrintConstants.PROPERTY_SELF) {
val implementation = Implementation().apply {
this.operationHost = operationHost!!
@@ -235,10 +239,18 @@ class OperationAssignmentBuilder(private val id: String,
operationAssignment.implementation = implementation
}
+ fun inputs(inputs: MutableMap<String, JsonNode>?) {
+ operationAssignment.inputs = inputs
+ }
+
fun inputs(block: PropertiesAssignmentBuilder.() -> Unit) {
operationAssignment.inputs = PropertiesAssignmentBuilder().apply(block).build()
}
+ fun outputs(outputs: MutableMap<String, JsonNode>?) {
+ operationAssignment.outputs = outputs
+ }
+
fun outputs(block: PropertiesAssignmentBuilder.() -> Unit) {
operationAssignment.outputs = PropertiesAssignmentBuilder().apply(block).build()
}
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintIOUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintIOUtils.kt
new file mode 100644
index 000000000..226c62d48
--- /dev/null
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintIOUtils.kt
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.cds.controllerblueprints.core.utils
+
+object BluePrintIOUtils {
+
+ suspend fun <T> retry(times: Int = 1, initialDelay: Long = 0, delay: Long = 1000,
+ block: suspend (Int) -> T, exceptionBlock: (e: Exception) -> Unit): T {
+ var currentDelay = initialDelay
+ val currentTimes = times - 1
+ repeat(currentTimes) { count ->
+ try {
+ return block(count)
+ } catch (e: Exception) {
+ exceptionBlock(e)
+ }
+ kotlinx.coroutines.delay(currentDelay)
+ currentDelay = delay
+ }
+ return block(currentTimes)
+ }
+} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintIOUtilsTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintIOUtilsTest.kt
new file mode 100644
index 000000000..2aea4bc2d
--- /dev/null
+++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintIOUtilsTest.kt
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.cds.controllerblueprints.core.utils
+
+import kotlinx.coroutines.runBlocking
+import org.junit.Test
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintRetryException
+
+
+class BluePrintIOUtilsTest {
+
+ @Test
+ fun testRetry() {
+ runBlocking {
+ val executionBlock: suspend (Int) -> String = { count: Int ->
+ "success"
+ }
+ val exceptionBlock = { e: Exception ->
+ if (e is BluePrintRetryException) {
+ println("this is blueprint error")
+ } else {
+ throw e
+ }
+ }
+ BluePrintIOUtils.retry<String>(4, 0, 500, executionBlock, exceptionBlock)
+ }
+ }
+} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JsonParserUtilsTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JsonParserUtilsTest.kt
index 810dae738..8a37a4b19 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JsonParserUtilsTest.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JsonParserUtilsTest.kt
@@ -22,6 +22,7 @@ import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType
import org.onap.ccsdk.cds.controllerblueprints.core.jsonPathParse
import org.onap.ccsdk.cds.controllerblueprints.core.jsonPaths
import kotlin.test.assertEquals
+import kotlin.test.assertNotNull
class JsonParserUtilsTest {
@@ -52,6 +53,6 @@ class JsonParserUtilsTest {
""".trimIndent()
val jsonNode = json.jsonAsJsonType()
val parsedPath = jsonNode.jsonPaths("$..prop1")
- println(parsedPath)
+ assertNotNull(parsedPath, "failed to get parsed path")
}
} \ No newline at end of file