aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules/services/execution-service/src
diff options
context:
space:
mode:
Diffstat (limited to 'ms/blueprintsprocessor/modules/services/execution-service/src')
-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
6 files changed, 146 insertions, 15 deletions
diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt
index be4327bfe..e78e87523 100644
--- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt
+++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt
@@ -54,7 +54,7 @@ abstract class AbstractComponentFunction : BlueprintFunctionNode<ExecutionServic
return stepName
}
- override fun prepareRequest(executionRequest: ExecutionServiceInput): ExecutionServiceInput {
+ override suspend fun prepareRequestNB(executionRequest: ExecutionServiceInput): ExecutionServiceInput {
checkNotNull(bluePrintRuntimeService) { "failed to prepare blueprint runtime" }
check(stepName.isNotEmpty()) { "failed to assign step name" }
@@ -93,7 +93,7 @@ abstract class AbstractComponentFunction : BlueprintFunctionNode<ExecutionServic
return executionRequest
}
- override fun prepareResponse(): ExecutionServiceOutput {
+ override suspend fun prepareResponseNB(): ExecutionServiceOutput {
log.info("Preparing Response...")
executionServiceOutput.commonHeader = executionServiceInput.commonHeader
executionServiceOutput.actionIdentifiers = executionServiceInput.actionIdentifiers
@@ -114,15 +114,15 @@ abstract class AbstractComponentFunction : BlueprintFunctionNode<ExecutionServic
return this.executionServiceOutput
}
- override fun apply(executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput {
+ override suspend fun applyNB(executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput {
try {
- prepareRequest(executionServiceInput)
- process(executionServiceInput)
+ prepareRequestNB(executionServiceInput)
+ processNB(executionServiceInput)
} catch (runtimeException: RuntimeException) {
log.error("failed in ${getName()} : ${runtimeException.message}", runtimeException)
- recover(runtimeException, executionServiceInput)
+ recoverNB(runtimeException, executionServiceInput)
}
- return prepareResponse()
+ return prepareResponseNB()
}
fun getOperationInput(key: String): JsonNode {
diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractScriptComponentFunction.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractScriptComponentFunction.kt
index 789ba9f5f..27cde8a49 100644
--- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractScriptComponentFunction.kt
+++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractScriptComponentFunction.kt
@@ -17,14 +17,22 @@
package org.onap.ccsdk.cds.blueprintsprocessor.services.execution
import com.fasterxml.jackson.databind.JsonNode
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
+import org.slf4j.LoggerFactory
abstract class AbstractScriptComponentFunction : AbstractComponentFunction() {
+ private val log = LoggerFactory.getLogger(AbstractScriptComponentFunction::class.java)!!
companion object {
const val DYNAMIC_PROPERTIES = "dynamic-properties"
}
+ lateinit var scriptType: String
+
/**
* Store Dynamic Script Dependency Instances, Objects present inside won't be persisted or state maintained.
*/
@@ -46,5 +54,73 @@ abstract class AbstractScriptComponentFunction : AbstractComponentFunction() {
return operationInputs[DYNAMIC_PROPERTIES]!!.get(key)
}
+ suspend fun executeScript(executionServiceInput: ExecutionServiceInput) {
+ return when (scriptType) {
+ BluePrintConstants.SCRIPT_JYTHON -> {
+ executeScriptBlocking(executionServiceInput)
+ }
+ else -> {
+ executeScriptNB(executionServiceInput)
+ }
+ }
+ }
+
+ private suspend fun executeScriptNB(executionServiceInput: ExecutionServiceInput) {
+ try {
+ processNB(executionServiceInput)
+ } catch (runtimeException: RuntimeException) {
+ log.error("failed in ${getName()} : ${runtimeException.message}", runtimeException)
+ recoverNB(runtimeException, executionServiceInput)
+ }
+ }
+
+ private fun executeScriptBlocking(executionServiceInput: ExecutionServiceInput) {
+ try {
+ process(executionServiceInput)
+ } catch (runtimeException: RuntimeException) {
+ log.error("failed in ${getName()} : ${runtimeException.message}", runtimeException)
+ recover(runtimeException, executionServiceInput)
+ }
+ }
+
+ /**
+ * If Jython Script, Override Blocking methods(process() and recover())
+ * If Kotlin or Internal Scripts, Override non blocking methods ( processNB() and recoverNB()), so default
+ * blocking
+ * methods will have default implementation,
+ *
+ * Always applyNB() method will be invoked, apply() won't be called from parent
+ */
+
+ final override fun apply(executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput {
+ throw BluePrintException("Not Implemented, use applyNB method")
+ }
+
+ final override fun prepareRequest(executionRequest: ExecutionServiceInput): ExecutionServiceInput {
+ throw BluePrintException("Not Implemented required")
+ }
+
+ final override fun prepareResponse(): ExecutionServiceOutput {
+ throw BluePrintException("Not Implemented required")
+ }
+
+ final override suspend fun applyNB(executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput {
+ throw BluePrintException("Not Implemented required")
+ }
+
+ final override suspend fun prepareRequestNB(executionRequest: ExecutionServiceInput): ExecutionServiceInput {
+ throw BluePrintException("Not Implemented required")
+ }
+
+ final override suspend fun prepareResponseNB(): ExecutionServiceOutput {
+ throw BluePrintException("Not Implemented required")
+ }
+ override fun process(executionRequest: ExecutionServiceInput) {
+ throw BluePrintException("Not Implemented, child class will implement this")
+ }
+
+ override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+ throw BluePrintException("Not Implemented, child class will implement this")
+ }
} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt
index 907aae4cd..b2991be5e 100644
--- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt
+++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt
@@ -33,7 +33,8 @@ class ComponentFunctionScriptingService(private val applicationContext: Applicat
private val log = LoggerFactory.getLogger(ComponentFunctionScriptingService::class.java)
- fun <T : AbstractScriptComponentFunction> scriptInstance(componentFunction: AbstractComponentFunction, scriptType: String,
+ suspend fun <T : AbstractScriptComponentFunction> scriptInstance(componentFunction: AbstractComponentFunction,
+ scriptType: String,
scriptClassReference: String,
instanceDependencies: List<String>): T {
@@ -53,6 +54,7 @@ class ComponentFunctionScriptingService(private val applicationContext: Applicat
scriptComponent.operationName = componentFunction.operationName
scriptComponent.nodeTemplateName = componentFunction.nodeTemplateName
scriptComponent.operationInputs = componentFunction.operationInputs
+ scriptComponent.scriptType = scriptType
// Populate Instance Properties
instanceDependencies.forEach { instanceDependency ->
@@ -63,7 +65,7 @@ class ComponentFunctionScriptingService(private val applicationContext: Applicat
}
- fun <T : BlueprintFunctionNode<*, *>> scriptInstance(bluePrintContext: BluePrintContext, scriptType: String,
+ suspend fun <T : BlueprintFunctionNode<*, *>> scriptInstance(bluePrintContext: BluePrintContext, scriptType: String,
scriptClassReference: String): T {
var scriptComponent: T? = null
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
+