diff options
author | Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com> | 2019-02-18 15:10:25 -0500 |
---|---|---|
committer | Alexis de Talhouƫt <adetalhouet89@gmail.com> | 2019-02-20 21:02:05 +0000 |
commit | 0613ae8f927834f7621011fda3f0cb1b7f8e07ad (patch) | |
tree | 79010a222bfb62ad2cb61d88cccfea8f76dfc186 /ms/blueprintsprocessor/functions/netconf-executor | |
parent | 183e2b48ceb4ae58b85f76f9bf182a5958fc92e6 (diff) |
Add component function scripting service
Change-Id: I7c5b49617823dd623566fb4be4d431012420e17c
Issue-ID: CCSDK-959
Signed-off-by: Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/blueprintsprocessor/functions/netconf-executor')
3 files changed, 41 insertions, 16 deletions
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt index 06c9b7b2c..60f1e4f82 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt @@ -18,10 +18,12 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor +import com.fasterxml.jackson.databind.node.ArrayNode import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintJythonService -import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionService +import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction +import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.ComponentFunctionScriptingService +import org.onap.ccsdk.apps.controllerblueprints.core.getAsString import org.slf4j.LoggerFactory import org.springframework.beans.factory.config.ConfigurableBeanFactory import org.springframework.context.annotation.Scope @@ -29,23 +31,40 @@ import org.springframework.stereotype.Component @Component("component-netconf-executor") @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -open class ComponentNetconfExecutor(private val blueprintJythonService: BlueprintJythonService, - private var resourceResolutionService: ResourceResolutionService) +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) { - scriptComponent = blueprintJythonService.jythonComponentInstance(this) as NetconfComponentFunction + val scriptType = operationInputs.getAsString(SCRIPT_TYPE) + val scriptClassReference = operationInputs.getAsString(SCRIPT_CLASS_REFERENCE) + val instanceDependenciesNode = operationInputs.get(INSTANCE_DEPENDENCIES) as? ArrayNode + + val scriptDependencies: MutableList<String> = arrayListOf() + scriptDependencies.add(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION) + + instanceDependenciesNode?.forEach { instanceName -> + scriptDependencies.add(instanceName.textValue()) + } + + scriptComponent = componentFunctionScriptingService.scriptInstance<NetconfComponentFunction>(this, scriptType, + scriptClassReference, scriptDependencies) + + checkNotNull(scriptComponent) { "failed to get netconf script component" } - // FIXME("Populate the reference in Abstract Script Instance Injection map") scriptComponent.bluePrintRuntimeService = bluePrintRuntimeService - scriptComponent.resourceResolutionService = resourceResolutionService - scriptComponent.processId = processId scriptComponent.workflowName = workflowName scriptComponent.stepName = stepName diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfComponentFunction.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfComponentFunction.kt index e1160acf5..26e51ec09 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfComponentFunction.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfComponentFunction.kt @@ -18,13 +18,16 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor import com.fasterxml.jackson.databind.JsonNode import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.DeviceInfo +import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionService import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils abstract class NetconfComponentFunction : AbstractComponentFunction() { - lateinit var resourceResolutionService: ResourceResolutionService + + open fun resourceResolutionService(): ResourceResolutionService = + functionDependencyInstanceAsType(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION) // Called from python script fun initializeNetconfConnection(requirementName: String): NetconfDevice { @@ -37,12 +40,12 @@ abstract class NetconfComponentFunction : AbstractComponentFunction() { } fun resolveAndGenerateMessage(artifactMapping: String, artifactTemplate: String): String { - return resourceResolutionService.resolveResources(bluePrintRuntimeService, nodeTemplateName, + return resourceResolutionService().resolveResources(bluePrintRuntimeService, nodeTemplateName, artifactMapping, artifactTemplate) } fun resolveAndGenerateMessage(artifactPrefix: String): String { - return resourceResolutionService.resolveResources(bluePrintRuntimeService, nodeTemplateName, + return resourceResolutionService().resolveResources(bluePrintRuntimeService, nodeTemplateName, artifactPrefix) } diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt index 5b7b14ad0..6ed3a6d9e 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt @@ -22,14 +22,16 @@ import com.fasterxml.jackson.databind.JsonNode import org.junit.Test import org.junit.runner.RunWith import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintJythonService -import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.PythonExecutorProperty import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionServiceImpl +import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.ComponentFunctionScriptingService +import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.BlueprintJythonService +import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.PythonExecutorProperty import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode import org.onap.ccsdk.apps.controllerblueprints.core.putJsonElement import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.apps.controllerblueprints.scripts.BluePrintScriptsServiceImpl import org.springframework.beans.factory.annotation.Autowired import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.TestPropertySource @@ -37,6 +39,7 @@ import org.springframework.test.context.junit4.SpringRunner @RunWith(SpringRunner::class) @ContextConfiguration(classes = [BlueprintJythonService::class, PythonExecutorProperty::class, + BluePrintScriptsServiceImpl::class, ComponentFunctionScriptingService::class, ComponentNetconfExecutor::class, JsonParserService::class, ResourceResolutionServiceImpl::class]) @TestPropertySource(properties = ["blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_netconf,./../../../../components/scripts/python/ccsdk_blueprints", @@ -51,17 +54,17 @@ class ComponentNetconfExecutorTest { fun testComponentNetconfExecutor() { val executionServiceInput = JacksonUtils.readValueFromClassPathFile("requests/sample-activate-request.json", - ExecutionServiceInput::class.java)!! + ExecutionServiceInput::class.java)!! val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234", - "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") + "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") val executionContext = bluePrintRuntimeService.getExecutionContext() componentNetconfExecutor.bluePrintRuntimeService = bluePrintRuntimeService - + //TODO("Set Attribute properties") val stepMetaData: MutableMap<String, JsonNode> = hashMapOf() stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "activate-netconf") stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ComponentNetconfExecutor") |