diff options
author | Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com> | 2019-03-27 13:22:51 -0400 |
---|---|---|
committer | Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com> | 2019-04-01 10:43:53 -0400 |
commit | 40072d3dcc1d0193bba1ea9432c13ac24857be55 (patch) | |
tree | 2fe78015e772c4cbab4fd52184530b9e52c8c3af /ms/blueprintsprocessor/functions/python-executor/src | |
parent | 38300292cbce3bb0500593f3cc44fe129cf5c877 (diff) |
Improve function interfaces
Change-Id: I24f45d39ac05491a4217101e00bcbf8d122e4e1a
Issue-ID: CCSDK-1137
Signed-off-by: Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/blueprintsprocessor/functions/python-executor/src')
3 files changed, 68 insertions, 31 deletions
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 |