From 0613ae8f927834f7621011fda3f0cb1b7f8e07ad Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh" Date: Mon, 18 Feb 2019 15:10:25 -0500 Subject: Add component function scripting service Change-Id: I7c5b49617823dd623566fb4be4d431012420e17c Issue-ID: CCSDK-959 Signed-off-by: Muthuramalingam, Brinda Santh --- .../netconf/executor/ComponentNetconfExecutor.kt | 35 +++++++++++++++++----- .../netconf/executor/NetconfComponentFunction.kt | 9 ++++-- 2 files changed, 33 insertions(+), 11 deletions(-) (limited to 'ms/blueprintsprocessor/functions/netconf-executor/src/main') 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 = arrayListOf() + scriptDependencies.add(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION) + + instanceDependenciesNode?.forEach { instanceName -> + scriptDependencies.add(instanceName.textValue()) + } + + scriptComponent = componentFunctionScriptingService.scriptInstance(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) } -- cgit 1.2.3-korg