summaryrefslogtreecommitdiffstats
path: root/ms
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
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')
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt17
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/logback-test.xml2
-rw-r--r--ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt37
-rw-r--r--ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/JythonComponentFunction.kt33
-rw-r--r--ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentJythonExecutorTest.kt29
-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
-rw-r--r--ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutor.kt18
-rw-r--r--ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/scripts/InternalSimpleRestconf.cba.kts24
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/mock/Mock.kt5
-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
-rw-r--r--ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintJythonServiceTest.kt17
-rw-r--r--ms/blueprintsprocessor/modules/services/execution-service/src/test/resources/logback-test.xml34
-rw-r--r--ms/blueprintsprocessor/modules/services/execution-service/src/test/resources/scripts/SamplePythonComponentNode.py14
-rw-r--r--ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/NodeTemplateExecutionService.kt6
-rw-r--r--ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/mock/MockComponentFunction.kt13
-rwxr-xr-xms/blueprintsprocessor/parent/pom.xml2
-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
33 files changed, 474 insertions, 216 deletions
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt
index 2980de98a..663daf54e 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt
@@ -24,7 +24,6 @@ import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.Reso
import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction
import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentFunctionScriptingService
import org.onap.ccsdk.cds.controllerblueprints.core.getAsString
-import org.slf4j.LoggerFactory
import org.springframework.beans.factory.config.ConfigurableBeanFactory
import org.springframework.context.annotation.Scope
import org.springframework.stereotype.Component
@@ -34,18 +33,15 @@ import org.springframework.stereotype.Component
open class ComponentNetconfExecutor(private var componentFunctionScriptingService: ComponentFunctionScriptingService)
: AbstractComponentFunction() {
- private val log = LoggerFactory.getLogger(ComponentNetconfExecutor::class.java)
-
companion object {
const val SCRIPT_TYPE = "script-type"
const val SCRIPT_CLASS_REFERENCE = "script-class-reference"
const val INSTANCE_DEPENDENCIES = "instance-dependencies"
}
-
lateinit var scriptComponent: NetconfComponentFunction
- override fun process(executionRequest: ExecutionServiceInput) {
+ override suspend fun processNB(executionRequest: ExecutionServiceInput) {
val scriptType = operationInputs.getAsString(SCRIPT_TYPE)
val scriptClassReference = operationInputs.getAsString(SCRIPT_CLASS_REFERENCE)
@@ -64,12 +60,13 @@ open class ComponentNetconfExecutor(private var componentFunctionScriptingServic
checkNotNull(scriptComponent) { "failed to get netconf script component" }
- scriptComponent.process(executionServiceInput)
- }
-
- override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
- scriptComponent.recover(runtimeException, executionRequest)
+ // Handles both script processing and error handling
+ scriptComponent.executeScript(executionServiceInput)
}
+ override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+ bluePrintRuntimeService.getBluePrintError()
+ .addError("Failed in ComponentNetconfExecutor : ${runtimeException.message}")
+ }
} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/logback-test.xml b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/logback-test.xml
index 355cd3ace..cc7ac83ad 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/logback-test.xml
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/logback-test.xml
@@ -26,7 +26,9 @@
<logger name="org.springframework.test" level="warn"/>
<logger name="org.springframework" level="warn"/>
<logger name="org.hibernate" level="info"/>
+ <logger name="org.apache.sshd" level="warn"/>
<logger name="org.onap.ccsdk.cds.blueprintsprocessor" level="info"/>
+ <logger name="org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.core" level="warn"/>
<root level="warn">
<appender-ref ref="STDOUT"/>
diff --git a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt
index 527f9dcc0..0a0c0bdf9 100644
--- a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt
+++ b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt
@@ -24,6 +24,7 @@ import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInpu
import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction
import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts.BlueprintJythonService
import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts.PythonExecutorConstants
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmptyOrThrow
import org.onap.ccsdk.cds.controllerblueprints.core.data.OperationAssignment
@@ -40,24 +41,22 @@ open class ComponentJythonExecutor(private var applicationContext: ApplicationCo
private val log = LoggerFactory.getLogger(ComponentJythonExecutor::class.java)
- private var componentFunction: AbstractComponentFunction? = null
+ private lateinit var componentFunction: JythonComponentFunction
- override fun prepareRequest(executionRequest: ExecutionServiceInput): ExecutionServiceInput {
- val request = super.prepareRequest(executionRequest)
+ override suspend fun processNB(executionRequest: ExecutionServiceInput) {
+
+ log.info("Processing : $operationInputs")
// Populate Component Instance
populateJythonComponentInstance()
- return request
- }
- override fun process(executionRequest: ExecutionServiceInput) {
- log.info("Processing : $operationInputs")
// Invoke Jython Component Script
- componentFunction!!.process(executionServiceInput)
+ componentFunction.executeScript(executionServiceInput)
}
- override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
- componentFunction!!.recover(runtimeException, executionRequest)
+ override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+ bluePrintRuntimeService.getBluePrintError()
+ .addError("Failed in ComponentJythonExecutor : ${runtimeException.message}")
}
private fun populateJythonComponentInstance() {
@@ -92,14 +91,14 @@ open class ComponentJythonExecutor(private var applicationContext: ApplicationCo
}
// Setup componentFunction
- componentFunction = blueprintJythonService.jythonInstance(bluePrintContext, pythonClassName,
- content!!, jythonInstance)
- componentFunction?.bluePrintRuntimeService = bluePrintRuntimeService
- componentFunction?.executionServiceInput = executionServiceInput
- componentFunction?.stepName = stepName
- componentFunction?.interfaceName = interfaceName
- componentFunction?.operationName = operationName
- componentFunction?.processId = processId
- componentFunction?.workflowName = workflowName
+ componentFunction = blueprintJythonService.jythonInstance(bluePrintContext, pythonClassName, content!!, jythonInstance)
+ componentFunction.bluePrintRuntimeService = bluePrintRuntimeService
+ componentFunction.executionServiceInput = executionServiceInput
+ componentFunction.stepName = stepName
+ componentFunction.interfaceName = interfaceName
+ componentFunction.operationName = operationName
+ componentFunction.processId = processId
+ componentFunction.workflowName = workflowName
+ componentFunction.scriptType = BluePrintConstants.SCRIPT_JYTHON
}
} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/JythonComponentFunction.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/JythonComponentFunction.kt
new file mode 100644
index 000000000..7e00206ca
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/JythonComponentFunction.kt
@@ -0,0 +1,33 @@
+/*
+ * 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.blueprintsprocessor.functions.python.executor
+
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
+
+open class JythonComponentFunction : AbstractScriptComponentFunction() {
+
+ override suspend fun processNB(executionRequest: ExecutionServiceInput) {
+ throw BluePrintException("Not Implemented required")
+ }
+
+ override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+ throw BluePrintException("Not Implemented required")
+ }
+
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentJythonExecutorTest.kt b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentJythonExecutorTest.kt
index 07aa9a9e7..30a5e7ff2 100644
--- a/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentJythonExecutorTest.kt
+++ b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentJythonExecutorTest.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.
@@ -17,6 +18,7 @@
package org.onap.ccsdk.cds.blueprintsprocessor.functions.python.executor
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.api.data.ExecutionServiceInput
@@ -46,23 +48,26 @@ class ComponentJythonExecutorTest {
@Test
fun testPythonComponentInjection() {
- val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-activate-request.json",
- ExecutionServiceInput::class.java)!!
+ runBlocking {
- val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
- "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+ val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-activate-request.json",
+ ExecutionServiceInput::class.java)!!
- val stepMetaData: MutableMap<String, JsonNode> = hashMapOf()
- stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "activate-jython")
- stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ComponentJythonExecutor")
- stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process")
- bluePrintRuntimeService.put("activate-jython-step-inputs", stepMetaData.asJsonNode())
+ val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
+ "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
- componentJythonExecutor.bluePrintRuntimeService = bluePrintRuntimeService
- componentJythonExecutor.stepName = "activate-jython"
+ val stepMetaData: MutableMap<String, JsonNode> = hashMapOf()
+ stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "activate-jython")
+ stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ComponentJythonExecutor")
+ stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process")
+ bluePrintRuntimeService.put("activate-jython-step-inputs", stepMetaData.asJsonNode())
+ componentJythonExecutor.bluePrintRuntimeService = bluePrintRuntimeService
+ componentJythonExecutor.stepName = "activate-jython"
- componentJythonExecutor.apply(executionServiceInput)
+
+ componentJythonExecutor.applyNB(executionServiceInput)
+ }
}
} \ 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/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")
+ }
}
diff --git a/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutor.kt b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutor.kt
index 0ce0edca5..53828d769 100644
--- a/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutor.kt
+++ b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutor.kt
@@ -23,7 +23,6 @@ import org.onap.ccsdk.cds.blueprintsprocessor.rest.RestLibConstants
import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction
import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentFunctionScriptingService
import org.onap.ccsdk.cds.controllerblueprints.core.getAsString
-import org.slf4j.LoggerFactory
import org.springframework.beans.factory.config.ConfigurableBeanFactory
import org.springframework.context.annotation.Scope
import org.springframework.stereotype.Component
@@ -33,8 +32,6 @@ import org.springframework.stereotype.Component
open class ComponentRestconfExecutor(private var componentFunctionScriptingService: ComponentFunctionScriptingService) :
AbstractComponentFunction() {
- private val log = LoggerFactory.getLogger(ComponentRestconfExecutor::class.java)
-
lateinit var scriptComponent: RestconfComponentFunction
companion object {
@@ -43,7 +40,7 @@ open class ComponentRestconfExecutor(private var componentFunctionScriptingServi
const val INSTANCE_DEPENDENCIES = "instance-dependencies"
}
- override fun process(executionRequest: ExecutionServiceInput) {
+ override suspend fun processNB(executionRequest: ExecutionServiceInput) {
val scriptType = operationInputs.getAsString(SCRIPT_TYPE)
val scriptClassReference = operationInputs.getAsString(SCRIPT_CLASS_REFERENCE)
@@ -59,15 +56,18 @@ open class ComponentRestconfExecutor(private var componentFunctionScriptingServi
/**
* Populate the Script Instance based on the Type
*/
- scriptComponent = componentFunctionScriptingService.scriptInstance<RestconfComponentFunction>(this, scriptType,
- scriptClassReference, scriptDependencies)
+ scriptComponent = componentFunctionScriptingService
+ .scriptInstance<RestconfComponentFunction>(this, scriptType,
+ scriptClassReference, scriptDependencies)
checkNotNull(scriptComponent) { "failed to get restconf script component" }
- scriptComponent.process(executionServiceInput)
+ // Handles both script processing and error handling
+ scriptComponent.executeScript(executionServiceInput)
}
- override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
- scriptComponent.recover(runtimeException, executionRequest)
+ override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+ bluePrintRuntimeService.getBluePrintError()
+ .addError("Failed in ComponentRestconfExecutor : ${runtimeException.message}")
}
} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/scripts/InternalSimpleRestconf.cba.kts b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/scripts/InternalSimpleRestconf.cba.kts
index 88feddf49..4ab7ddc4b 100644
--- a/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/scripts/InternalSimpleRestconf.cba.kts
+++ b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/scripts/InternalSimpleRestconf.cba.kts
@@ -13,15 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-@file:Suppress("unused") //TODO remove this line!
+@file:Suppress("unused")
-
-import com.fasterxml.jackson.databind.node.ObjectNode
-import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ActionIdentifiers
-import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.CommonHeader
import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
import org.onap.ccsdk.cds.blueprintsprocessor.functions.restconf.executor.RestconfComponentFunction
-import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
import org.slf4j.LoggerFactory
open class EditConfigure : RestconfComponentFunction() {
@@ -32,12 +27,12 @@ open class EditConfigure : RestconfComponentFunction() {
return "EditConfigure"
}
- override fun process(executionRequest: ExecutionServiceInput) {
+ override suspend fun processNB(executionRequest: ExecutionServiceInput) {
//val webClientService = restClientService("odlparent")
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
- override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+ override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}
@@ -50,13 +45,12 @@ open class MountNEditConfigure : RestconfComponentFunction() {
return "MountNEditConfigure"
}
- override fun process(executionRequest: ExecutionServiceInput) {
- val webClientService = restClientService("odlparent")
- TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ override suspend fun processNB(executionRequest: ExecutionServiceInput) {
+ log.info("Processing Restconf Request : ${executionRequest.payload}")
}
- override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
- TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+ addError("failed in restconf execution : ${runtimeException.message}")
}
}
@@ -72,11 +66,11 @@ open class TestRestconfConfigure : RestconfComponentFunction() {
return "TestRestconfConfigure"
}
- override fun process(executionRequest: ExecutionServiceInput) {
+ override suspend fun processNB(executionRequest: ExecutionServiceInput) {
log.info("processing request..")
}
- override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+ override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
log.info("recovering..")
}
}
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/mock/Mock.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/mock/Mock.kt
index 85e289ccc..dab2419da 100644
--- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/mock/Mock.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/mock/Mock.kt
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2019 Bell Canada.
+ * 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.
@@ -37,14 +38,14 @@ class MockComponentFunction : AbstractComponentFunction() {
private val log = LoggerFactory.getLogger(MockComponentFunction::class.java)
- override fun process(executionRequest: ExecutionServiceInput) {
+ override suspend fun processNB(executionRequest: ExecutionServiceInput) {
log.info("Processing component : $operationInputs")
bluePrintRuntimeService.setNodeTemplateAttributeValue(nodeTemplateName,
"assignment-params", "params".asJsonPrimitive())
}
- override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+ override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
log.info("Recovering component..")
}
}
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
diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintJythonServiceTest.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintJythonServiceTest.kt
index d6c0cf58b..c8c9f0b6a 100644
--- a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintJythonServiceTest.kt
+++ b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintJythonServiceTest.kt
@@ -1,5 +1,6 @@
/*
* Copyright © 2019 IBM, Bell Canada.
+ * 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.
@@ -15,11 +16,14 @@
*/
package org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts
+import io.mockk.every
+import io.mockk.mockk
import org.junit.Test
import org.junit.runner.RunWith
import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction
-import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
+import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName
+import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.test.context.ContextConfiguration
@@ -39,15 +43,16 @@ class BlueprintJythonServiceTest {
@Test
fun testGetAbstractPythonPlugin() {
- val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(
- "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+ val bluePrintContext = mockk<BluePrintContext>()
+ every { bluePrintContext.rootPath } returns normalizedPathName("target")
val dependencies: MutableMap<String, Any> = hashMapOf()
- val content = JacksonUtils.getContent("./../../../../." +
- "./components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Scripts/python/SamplePythonComponentNode.py")
+ val content = JacksonUtils.getClassPathFileContent("scripts/SamplePythonComponentNode.py")
- val abstractComponentFunction = blueprintJythonService.jythonInstance<AbstractComponentFunction>(bluePrintContext, "SamplePythonComponentNode", content, dependencies)
+ val abstractComponentFunction = blueprintJythonService
+ .jythonInstance<AbstractComponentFunction>(bluePrintContext, "SamplePythonComponentNode",
+ content, dependencies)
assertNotNull(abstractComponentFunction, "failed to get python component")
diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/test/resources/logback-test.xml b/ms/blueprintsprocessor/modules/services/execution-service/src/test/resources/logback-test.xml
new file mode 100644
index 000000000..da1553d2c
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/services/execution-service/src/test/resources/logback-test.xml
@@ -0,0 +1,34 @@
+<!--
+ ~ 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.
+ -->
+
+<configuration>
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <!-- encoders are assigned the type
+ ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} %-5level %logger{100} - %msg%n</pattern>
+ </encoder>
+ </appender>
+
+
+ <logger name="org.springframework" level="warn"/>
+ <logger name="org.hibernate" level="warn"/>
+ <logger name="org.onap.ccsdk.cds.blueprintsprocessor" level="info"/>
+ <root level="warn">
+ <appender-ref ref="STDOUT"/>
+ </root>
+
+</configuration>
diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/test/resources/scripts/SamplePythonComponentNode.py b/ms/blueprintsprocessor/modules/services/execution-service/src/test/resources/scripts/SamplePythonComponentNode.py
new file mode 100644
index 000000000..f1b614a59
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/services/execution-service/src/test/resources/scripts/SamplePythonComponentNode.py
@@ -0,0 +1,14 @@
+from abstract_blueprint_function import AbstractPythonComponentFunction
+from blueprint_constants import *
+
+
+class SamplePythonComponentNode(AbstractPythonComponentFunction):
+
+ def process(self, execution_request):
+ print "Processing calling..." + PROPERTY_BLUEPRINT_BASE_PATH
+ return None
+
+ def recover(self, runtime_exception, execution_request):
+ print "Recovering calling..." + PROPERTY_BLUEPRINT_BASE_PATH
+ return None
+
diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/NodeTemplateExecutionService.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/NodeTemplateExecutionService.kt
index 67be26e6d..8f47a0460 100644
--- a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/NodeTemplateExecutionService.kt
+++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/NodeTemplateExecutionService.kt
@@ -17,8 +17,6 @@
package org.onap.ccsdk.cds.blueprintsprocessor.services.workflow
import com.fasterxml.jackson.databind.JsonNode
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.withContext
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.blueprintsprocessor.services.execution.AbstractComponentFunction
@@ -64,9 +62,7 @@ open class NodeTemplateExecutionService(private val applicationContext: Applicat
plugin.bluePrintRuntimeService.put("$nodeTemplateName-step-inputs", stepInputs.asJsonNode())
// Get the Request from the Context and Set to the Function Input and Invoke the function
- return withContext(Dispatchers.Default) {
- plugin.apply(executionServiceInput)
- }
+ return plugin.apply(executionServiceInput)
}
} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/mock/MockComponentFunction.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/mock/MockComponentFunction.kt
index 1cae01ffa..5dc5b9dba 100644
--- a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/mock/MockComponentFunction.kt
+++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/mock/MockComponentFunction.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.
@@ -39,14 +40,14 @@ class MockComponentFunction : AbstractComponentFunction() {
private val log = LoggerFactory.getLogger(MockComponentFunction::class.java)
- override fun process(executionRequest: ExecutionServiceInput) {
+ override suspend fun processNB(executionRequest: ExecutionServiceInput) {
log.info("Processing component : $operationInputs")
bluePrintRuntimeService.setNodeTemplateAttributeValue(nodeTemplateName,
"assignment-params", "params".asJsonPrimitive())
}
- override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+ override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
log.info("Recovering component..")
}
}
@@ -57,11 +58,11 @@ class SingletonComponentFunction : AbstractComponentFunction() {
private val log = LoggerFactory.getLogger(MockComponentFunction::class.java)
- override fun process(executionRequest: ExecutionServiceInput) {
+ override suspend fun processNB(executionRequest: ExecutionServiceInput) {
log.info("Processing component : $operationInputs")
}
- override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+ override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
log.info("Recovering component..")
}
}
@@ -72,11 +73,11 @@ class PrototypeComponentFunction : AbstractComponentFunction() {
private val log = LoggerFactory.getLogger(MockComponentFunction::class.java)
- override fun process(executionRequest: ExecutionServiceInput) {
+ override suspend fun processNB(executionRequest: ExecutionServiceInput) {
log.info("Processing component : $operationInputs")
}
- override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+ override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
log.info("Recovering component..")
}
} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/parent/pom.xml b/ms/blueprintsprocessor/parent/pom.xml
index 4343ff67d..772c73935 100755
--- a/ms/blueprintsprocessor/parent/pom.xml
+++ b/ms/blueprintsprocessor/parent/pom.xml
@@ -41,7 +41,7 @@
<jsch.version>0.1.55</jsch.version>
<protobuff.java.utils.version>3.6.1</protobuff.java.utils.version>
<eelf.version>1.0.0</eelf.version>
- <sli.version>0.4.1-SNAPSHOT</sli.version>
+ <sli.version>0.4.2-SNAPSHOT</sli.version>
<guava.version>27.0.1-jre</guava.version>
<jython.version>2.7.1</jython.version>
<springfox.swagger2.version>2.9.2</springfox.swagger2.version>
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"
}
}