aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions/resource-resolution
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/functions/resource-resolution
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/functions/resource-resolution')
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt5
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt9
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt16
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt4
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt4
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt4
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt83
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt12
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/scripts/InternalRAProcessor.cba.kts4
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt31
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt89
11 files changed, 162 insertions, 99 deletions
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt
index 0fe638a04..8191db74e 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.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.
@@ -30,7 +31,7 @@ import org.springframework.stereotype.Component
open class ResourceResolutionComponent(private val resourceResolutionService: ResourceResolutionService) :
AbstractComponentFunction() {
- override fun process(executionRequest: ExecutionServiceInput) {
+ override suspend fun processNB(executionRequest: ExecutionServiceInput) {
val properties: MutableMap<String, Any> = mutableMapOf()
@@ -56,7 +57,7 @@ open class ResourceResolutionComponent(private val resourceResolutionService: Re
ResourceResolutionConstants.OUTPUT_ASSIGNMENT_PARAMS, resolvedParamContents.asJsonNode())
}
- override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+ override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
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/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt
index ce3aa4d84..dad804692 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt
@@ -17,6 +17,7 @@
package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution
+import kotlinx.coroutines.runBlocking
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.ResourceResolutionResultService
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor.ResourceAssignmentProcessor
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
@@ -180,9 +181,11 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica
resourceAssignmentProcessor.raRuntimeService = resourceAssignmentRuntimeService
// Set Resource Dictionaries
resourceAssignmentProcessor.resourceDictionaries = resourceDictionaries
- // Invoke Apply Method
- resourceAssignmentProcessor.apply(resourceAssignment)
-
+ // TODO ("Implement suspend function")
+ runBlocking {
+ // Invoke Apply Method
+ resourceAssignmentProcessor.applyNB(resourceAssignment)
+ }
// Set errors from RA
blueprintRuntimeService.setBluePrintError(resourceAssignmentRuntimeService.getBluePrintError())
} catch (e: RuntimeException) {
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt
index ae08a1cf9..1a7c50676 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt
@@ -44,7 +44,7 @@ open class CapabilityResourceResolutionProcessor(private val applicationContext:
return "${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-capability"
}
- override fun process(resourceAssignment: ResourceAssignment) {
+ override suspend fun processNB(resourceAssignment: ResourceAssignment) {
val resourceDefinition = resourceDictionaries[resourceAssignment.dictionaryName]
?: throw BluePrintProcessorException("couldn't get resource definition for ${resourceAssignment.dictionaryName}")
@@ -71,21 +71,20 @@ open class CapabilityResourceResolutionProcessor(private val applicationContext:
}
// Assign Current Blueprint runtime and ResourceDictionaries
+ componentResourceAssignmentProcessor!!.scriptType = scriptType
componentResourceAssignmentProcessor!!.raRuntimeService = raRuntimeService
componentResourceAssignmentProcessor!!.resourceDictionaries = resourceDictionaries
// Invoke componentResourceAssignmentProcessor
- componentResourceAssignmentProcessor!!.apply(resourceAssignment)
+ componentResourceAssignmentProcessor!!.executeScript(resourceAssignment)
}
- override fun recover(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) {
- log.info("Recovering for : ${resourceAssignment.name} : ${runtimeException.toString()}")
- if (componentResourceAssignmentProcessor != null) {
- componentResourceAssignmentProcessor!!.recover(runtimeException, resourceAssignment)
- }
+ override suspend fun recoverNB(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) {
+ raRuntimeService.getBluePrintError()
+ .addError("Failed in ComponentNetconfExecutor : ${runtimeException.message}")
}
- fun scriptInstance(scriptType: String, scriptClassReference: String, instanceDependencies: List<String>)
+ suspend fun scriptInstance(scriptType: String, scriptClassReference: String, instanceDependencies: List<String>)
: ResourceAssignmentProcessor {
log.info("creating resource resolution of script type($scriptType), reference name($scriptClassReference) and" +
@@ -101,4 +100,5 @@ open class CapabilityResourceResolutionProcessor(private val applicationContext:
}
return scriptComponent
}
+
} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt
index d190ee53c..1d9aed2d2 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt
@@ -52,7 +52,7 @@ open class DatabaseResourceAssignmentProcessor(private val bluePrintDBLibPropert
return "${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-processor-db"
}
- override fun process(resourceAssignment: ResourceAssignment) {
+ override suspend fun processNB(resourceAssignment: ResourceAssignment) {
try {
validate(resourceAssignment)
@@ -184,7 +184,7 @@ open class DatabaseResourceAssignmentProcessor(private val bluePrintDBLibPropert
}
}
- override fun recover(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) {
+ override suspend fun recoverNB(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/cds/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt
index ed9024d25..954b60522 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt
@@ -42,7 +42,7 @@ open class DefaultResourceResolutionProcessor : ResourceAssignmentProcessor() {
return "${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-default"
}
- override fun process(resourceAssignment: ResourceAssignment) {
+ override suspend fun processNB(resourceAssignment: ResourceAssignment) {
try {
var value = getFromInput(resourceAssignment)
if (value == null || value is MissingNode) {
@@ -59,7 +59,7 @@ open class DefaultResourceResolutionProcessor : ResourceAssignmentProcessor() {
}
- override fun recover(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) {
+ override suspend fun recoverNB(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/cds/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt
index 9fa72ca94..ce618af9f 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt
@@ -44,7 +44,7 @@ open class InputResourceResolutionProcessor : ResourceAssignmentProcessor() {
return "${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-input"
}
- override fun process(resourceAssignment: ResourceAssignment) {
+ override suspend fun processNB(resourceAssignment: ResourceAssignment) {
try {
if (checkNotEmpty(resourceAssignment.name)) {
val value = raRuntimeService.getInputValue(resourceAssignment.name)
@@ -62,7 +62,7 @@ open class InputResourceResolutionProcessor : ResourceAssignmentProcessor() {
}
}
- override fun recover(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) {
+ override suspend fun recoverNB(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/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt
index 97e2f2c69..e9bb2ffe4 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt
@@ -21,6 +21,8 @@ import com.fasterxml.jackson.databind.JsonNode
import org.apache.commons.collections.MapUtils
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
+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.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintFunctionNode
import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintTemplateService
@@ -38,13 +40,14 @@ abstract class ResourceAssignmentProcessor : BlueprintFunctionNode<ResourceAssig
lateinit var resourceDictionaries: MutableMap<String, ResourceDefinition>
var scriptPropertyInstances: MutableMap<String, Any> = hashMapOf()
+ lateinit var scriptType: String
/**
* This will be called from the scripts to serve instance from runtime to scripts.
*/
open fun <T> scriptPropertyInstanceType(name: String): T {
return scriptPropertyInstances as? T
- ?: throw BluePrintProcessorException("couldn't get script property instance ($name)")
+ ?: throw BluePrintProcessorException("couldn't get script property instance ($name)")
}
open fun getFromInput(resourceAssignment: ResourceAssignment): JsonNode? {
@@ -60,7 +63,7 @@ abstract class ResourceAssignmentProcessor : BlueprintFunctionNode<ResourceAssig
open fun resourceDefinition(name: String): ResourceDefinition {
return resourceDictionaries[name]
- ?: throw BluePrintProcessorException("couldn't get resource definition for ($name)")
+ ?: throw BluePrintProcessorException("couldn't get resource definition for ($name)")
}
open fun resolveInputKeyMappingVariables(inputKeyMapping: Map<String, String>): Map<String, Any> {
@@ -83,25 +86,80 @@ abstract class ResourceAssignmentProcessor : BlueprintFunctionNode<ResourceAssig
return BluePrintTemplateService.generateContent(valueToResolve, additionalContext = keyMapping)
}
- override fun prepareRequest(resourceAssignment: ResourceAssignment): ResourceAssignment {
- log.info("prepareRequest for ${resourceAssignment.name}, dictionary(${resourceAssignment.dictionaryName})," +
- "source(${resourceAssignment.dictionarySource})")
- return resourceAssignment
+ final override suspend fun applyNB(resourceAssignment: ResourceAssignment): Boolean {
+ try {
+ processNB(resourceAssignment)
+ } catch (runtimeException: RuntimeException) {
+ log.error("failed in ${getName()} : ${runtimeException.message}", runtimeException)
+ recoverNB(runtimeException, resourceAssignment)
+ }
+ return true
}
- override fun prepareResponse(): Boolean {
- log.info("Preparing Response...")
- return true
+ suspend fun executeScript(resourceAssignment: ResourceAssignment) {
+ return when (scriptType) {
+ BluePrintConstants.SCRIPT_JYTHON -> {
+ executeScriptBlocking(resourceAssignment)
+ }
+ else -> {
+ executeScriptNB(resourceAssignment)
+ }
+ }
}
- override fun apply(resourceAssignment: ResourceAssignment): Boolean {
+ private suspend fun executeScriptNB(resourceAssignment: ResourceAssignment) {
+ try {
+ processNB(resourceAssignment)
+ } catch (runtimeException: RuntimeException) {
+ log.error("failed in ${getName()} : ${runtimeException.message}", runtimeException)
+ recoverNB(runtimeException, resourceAssignment)
+ }
+ }
+
+ private fun executeScriptBlocking(resourceAssignment: ResourceAssignment) {
try {
- prepareRequest(resourceAssignment)
process(resourceAssignment)
} catch (runtimeException: RuntimeException) {
+ log.error("failed in ${getName()} : ${runtimeException.message}", runtimeException)
recover(runtimeException, resourceAssignment)
}
- return prepareResponse()
+ }
+
+ /**
+ * 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(resourceAssignment: ResourceAssignment): Boolean {
+ throw BluePrintException("Not Implemented, use applyNB method")
+ }
+
+ final override fun prepareRequest(resourceAssignment: ResourceAssignment): ResourceAssignment {
+ throw BluePrintException("Not Implemented required")
+ }
+
+ final override fun prepareResponse(): Boolean {
+ throw BluePrintException("Not Implemented required")
+ }
+
+ final override suspend fun prepareRequestNB(resourceAssignment: ResourceAssignment): ResourceAssignment {
+ throw BluePrintException("Not Implemented required")
+ }
+
+ final override suspend fun prepareResponseNB(): Boolean {
+ throw BluePrintException("Not Implemented required")
+ }
+
+ override fun process(resourceAssignment: ResourceAssignment) {
+ throw BluePrintException("Not Implemented, child class will implement this")
+ }
+
+ override fun recover(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) {
+ throw BluePrintException("Not Implemented, child class will implement this")
}
fun addError(type: String, name: String, error: String) {
@@ -111,5 +169,4 @@ abstract class ResourceAssignmentProcessor : BlueprintFunctionNode<ResourceAssig
fun addError(error: String) {
raRuntimeService.getBluePrintError().addError(error)
}
-
} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt
index 0c36a1e42..de97b2f83 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt
@@ -25,13 +25,7 @@ import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.Rest
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService
-import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
-import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
-import org.onap.ccsdk.cds.controllerblueprints.core.checkEqualsOrThrow
-import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmpty
-import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmptyOrThrow
-import org.onap.ccsdk.cds.controllerblueprints.core.nullToEmpty
-import org.onap.ccsdk.cds.controllerblueprints.core.returnNotEmptyOrThrow
+import org.onap.ccsdk.cds.controllerblueprints.core.*
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDictionaryConstants
@@ -56,7 +50,7 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
return "${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-rest"
}
- override fun process(resourceAssignment: ResourceAssignment) {
+ override suspend fun processNB(resourceAssignment: ResourceAssignment) {
try {
validate(resourceAssignment)
@@ -196,7 +190,7 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
"resource assignment dictionary name is not defined for template key (${resourceAssignment.name})")
}
- override fun recover(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) {
+ override suspend fun recoverNB(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) {
raRuntimeService.getBluePrintError().addError(runtimeException.message!!)
}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/scripts/InternalRAProcessor.cba.kts b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/scripts/InternalRAProcessor.cba.kts
index e6fc2baf7..32f04e6a0 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/scripts/InternalRAProcessor.cba.kts
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/scripts/InternalRAProcessor.cba.kts
@@ -26,11 +26,11 @@ open class SimpleRAProcessor : ResourceAssignmentProcessor() {
return "ScriptResourceAssignmentProcessor"
}
- override fun process(executionRequest: ResourceAssignment) {
+ override suspend fun processNB(executionRequest: ResourceAssignment) {
log.info("Processing input")
}
- override fun recover(runtimeException: RuntimeException, executionRequest: ResourceAssignment) {
+ override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ResourceAssignment) {
log.info("Recovering input")
}
}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt
index 8a5ffac76..feec74058 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt
@@ -18,6 +18,7 @@
package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution
import com.fasterxml.jackson.databind.JsonNode
+import kotlinx.coroutines.runBlocking
import org.junit.Test
import org.junit.runner.RunWith
import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties
@@ -56,24 +57,26 @@ class ResourceResolutionComponentTest {
@Test
fun testProcess() {
+ runBlocking {
- val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
- "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+ val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
+ "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
- val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
- ExecutionServiceInput::class.java)!!
+ val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
+ ExecutionServiceInput::class.java)!!
- // Prepare Inputs
- PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
+ // Prepare Inputs
+ PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
- val stepMetaData: MutableMap<String, JsonNode> = hashMapOf()
- stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "resource-assignment")
- stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ResourceResolutionComponent")
- stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process")
- bluePrintRuntimeService.put("resource-assignment-step-inputs", stepMetaData.asJsonNode())
+ val stepMetaData: MutableMap<String, JsonNode> = hashMapOf()
+ stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "resource-assignment")
+ stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ResourceResolutionComponent")
+ stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process")
+ bluePrintRuntimeService.put("resource-assignment-step-inputs", stepMetaData.asJsonNode())
- resourceResolutionComponent.bluePrintRuntimeService = bluePrintRuntimeService
- resourceResolutionComponent.stepName = "resource-assignment"
- resourceResolutionComponent.apply(executionServiceInput)
+ resourceResolutionComponent.bluePrintRuntimeService = bluePrintRuntimeService
+ resourceResolutionComponent.stepName = "resource-assignment"
+ resourceResolutionComponent.applyNB(executionServiceInput)
+ }
}
} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt
index 8ab47b910..489d971a5 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt
@@ -18,6 +18,7 @@
package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor
+import kotlinx.coroutines.runBlocking
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
@@ -52,70 +53,74 @@ class CapabilityResourceResolutionProcessorTest {
@Ignore
@Test
fun `test kotlin capability`() {
+ runBlocking {
- val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(
- "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+ val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(
+ "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
- val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext)
+ val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext)
- capabilityResourceResolutionProcessor.raRuntimeService = resourceAssignmentRuntimeService
- capabilityResourceResolutionProcessor.resourceDictionaries = hashMapOf()
+ capabilityResourceResolutionProcessor.raRuntimeService = resourceAssignmentRuntimeService
+ capabilityResourceResolutionProcessor.resourceDictionaries = hashMapOf()
- val scriptPropertyInstances: MutableMap<String, Any> = mutableMapOf()
- scriptPropertyInstances["mock-service1"] = MockCapabilityService()
- scriptPropertyInstances["mock-service2"] = MockCapabilityService()
+ val scriptPropertyInstances: MutableMap<String, Any> = mutableMapOf()
+ scriptPropertyInstances["mock-service1"] = MockCapabilityService()
+ scriptPropertyInstances["mock-service2"] = MockCapabilityService()
- val instanceDependencies: List<String> = listOf()
+ val instanceDependencies: List<String> = listOf()
- val resourceAssignmentProcessor = capabilityResourceResolutionProcessor
- .scriptInstance("kotlin",
- "ResourceAssignmentProcessor_cba\$ScriptResourceAssignmentProcessor", instanceDependencies)
+ val resourceAssignmentProcessor = capabilityResourceResolutionProcessor
+ .scriptInstance("kotlin",
+ "ResourceAssignmentProcessor_cba\$ScriptResourceAssignmentProcessor", instanceDependencies)
- assertNotNull(resourceAssignmentProcessor, "couldn't get kotlin script resource assignment processor")
+ assertNotNull(resourceAssignmentProcessor, "couldn't get kotlin script resource assignment processor")
- val resourceAssignment = ResourceAssignment().apply {
- name = "ra-name"
- dictionaryName = "ra-dict-name"
- dictionarySource = "capability"
- property = PropertyDefinition().apply {
- type = "string"
+ val resourceAssignment = ResourceAssignment().apply {
+ name = "ra-name"
+ dictionaryName = "ra-dict-name"
+ dictionarySource = "capability"
+ property = PropertyDefinition().apply {
+ type = "string"
+ }
}
- }
- val processorName = resourceAssignmentProcessor.apply(resourceAssignment)
- assertNotNull(processorName, "couldn't get kotlin script resource assignment processor name")
- println(processorName)
+ val processorName = resourceAssignmentProcessor.applyNB(resourceAssignment)
+ assertNotNull(processorName, "couldn't get kotlin script resource assignment processor name")
+ println(processorName)
+ }
}
@Test
fun `test jython capability`() {
+ runBlocking {
- val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(
- "./../../../../components/model-catalog/blueprint-model/test-blueprint/capability_python")
+ val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(
+ "./../../../../components/model-catalog/blueprint-model/test-blueprint/capability_python")
- val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext)
+ val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext)
- capabilityResourceResolutionProcessor.raRuntimeService = resourceAssignmentRuntimeService
+ capabilityResourceResolutionProcessor.raRuntimeService = resourceAssignmentRuntimeService
- val resourceDefinition = JacksonUtils
- .readValueFromClassPathFile("mapping/capability/jython-resource-definitions.json",
- ResourceDefinition::class.java)!!
- val resourceDefinitions: MutableMap<String, ResourceDefinition> = mutableMapOf()
- resourceDefinitions[resourceDefinition.name] = resourceDefinition
- capabilityResourceResolutionProcessor.resourceDictionaries = resourceDefinitions
+ val resourceDefinition = JacksonUtils
+ .readValueFromClassPathFile("mapping/capability/jython-resource-definitions.json",
+ ResourceDefinition::class.java)!!
+ val resourceDefinitions: MutableMap<String, ResourceDefinition> = mutableMapOf()
+ resourceDefinitions[resourceDefinition.name] = resourceDefinition
+ capabilityResourceResolutionProcessor.resourceDictionaries = resourceDefinitions
- val resourceAssignment = ResourceAssignment().apply {
- name = "service-instance-id"
- dictionaryName = "service-instance-id"
- dictionarySource = "capability"
- property = PropertyDefinition().apply {
- type = "string"
+ val resourceAssignment = ResourceAssignment().apply {
+ name = "service-instance-id"
+ dictionaryName = "service-instance-id"
+ dictionarySource = "capability"
+ property = PropertyDefinition().apply {
+ type = "string"
+ }
}
- }
- val processorName = capabilityResourceResolutionProcessor.apply(resourceAssignment)
- assertNotNull(processorName, "couldn't get Jython script resource assignment processor name")
+ val processorName = capabilityResourceResolutionProcessor.processNB(resourceAssignment)
+ assertNotNull(processorName, "couldn't get Jython script resource assignment processor name")
+ }
}