Improve scripting component. 40/82440/1
authorMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Fri, 15 Mar 2019 16:04:07 +0000 (12:04 -0400)
committerMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Fri, 15 Mar 2019 16:04:07 +0000 (12:04 -0400)
Change-Id: I1e0c319e4117553695fa9161e7ffcd91f605be05
Issue-ID: CCSDK-1137
Signed-off-by: Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt
ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfComponentFunction.kt
ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutor.kt
ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/RestconfComponentFunction.kt
ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/AbstractComponentFunction.kt
ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/AbstractScriptComponentFunction.kt [new file with mode: 0644]
ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt

index 60f1e4f..c2ccdaf 100644 (file)
@@ -64,15 +64,6 @@ open class ComponentNetconfExecutor(private var componentFunctionScriptingServic
 
         checkNotNull(scriptComponent) { "failed to get netconf script component" }
 
-        scriptComponent.bluePrintRuntimeService = bluePrintRuntimeService
-        scriptComponent.processId = processId
-        scriptComponent.workflowName = workflowName
-        scriptComponent.stepName = stepName
-        scriptComponent.interfaceName = interfaceName
-        scriptComponent.operationName = operationName
-        scriptComponent.nodeTemplateName = nodeTemplateName
-        scriptComponent.operationInputs = operationInputs
-
         scriptComponent.process(executionServiceInput)
     }
 
index 05a97c3..fe8ba54 100644 (file)
@@ -20,13 +20,13 @@ 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.blueprintsprocessor.services.execution.AbstractScriptComponentFunction
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
 
-abstract class NetconfComponentFunction : AbstractComponentFunction() {
+abstract class NetconfComponentFunction : AbstractScriptComponentFunction() {
 
     open fun resourceResolutionService(): ResourceResolutionService =
-        functionDependencyInstanceAsType(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION)
+            functionDependencyInstanceAsType(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION)
 
     // Called from python script
     fun initializeNetconfConnection(requirementName: String): NetconfDevice {
@@ -38,22 +38,18 @@ abstract class NetconfComponentFunction : AbstractComponentFunction() {
         return bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactName)
     }
 
-    fun getDynamicProperties(key: String): JsonNode {
-        return operationInputs["dynamic-properties"]!!.get(key)
-    }
-
     fun resolveFromDatabase(resolutionKey: String, artifactName: String): String {
         return resourceResolutionService().resolveFromDatabase(bluePrintRuntimeService, artifactName, resolutionKey)
     }
 
     fun resolveAndGenerateMessage(artifactMapping: String, artifactTemplate: String): String {
         return resourceResolutionService().resolveResources(bluePrintRuntimeService, nodeTemplateName,
-            artifactMapping, artifactTemplate)
+                artifactMapping, artifactTemplate)
     }
 
     fun resolveAndGenerateMessage(artifactPrefix: String): String {
         return resourceResolutionService().resolveResources(bluePrintRuntimeService, nodeTemplateName,
-            artifactPrefix, mapOf())
+                artifactPrefix, mapOf())
     }
 
     private fun deviceProperties(requirementName: String): DeviceInfo {
@@ -63,7 +59,7 @@ abstract class NetconfComponentFunction : AbstractComponentFunction() {
         val requirement = blueprintContext.nodeTemplateRequirement(nodeTemplateName, requirementName)
 
         val capabilityProperties = bluePrintRuntimeService.resolveNodeTemplateCapabilityProperties(requirement
-            .node!!, requirement.capability!!)
+                .node!!, requirement.capability!!)
 
         return deviceProperties(capabilityProperties)
     }
index 742fef4..7166ec2 100644 (file)
@@ -64,15 +64,6 @@ open class ComponentRestconfExecutor(private var componentFunctionScriptingServi
 
         checkNotNull(scriptComponent) { "failed to get restconf script component" }
 
-        scriptComponent.bluePrintRuntimeService = bluePrintRuntimeService
-        scriptComponent.processId = processId
-        scriptComponent.workflowName = workflowName
-        scriptComponent.stepName = stepName
-        scriptComponent.interfaceName = interfaceName
-        scriptComponent.operationName = operationName
-        scriptComponent.nodeTemplateName = nodeTemplateName
-        scriptComponent.operationInputs = operationInputs
-
         scriptComponent.process(executionServiceInput)
     }
 
index c3f2253..1914616 100644 (file)
 
 package org.onap.ccsdk.apps.blueprintsprocessor.functions.restconf.executor
 
-import com.fasterxml.jackson.databind.JsonNode
 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.rest.RestLibConstants
 import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
 import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BlueprintWebClientService
-import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractScriptComponentFunction
 
 
-abstract class RestconfComponentFunction : AbstractComponentFunction() {
+abstract class RestconfComponentFunction : AbstractScriptComponentFunction() {
 
     open fun bluePrintRestLibPropertyService(): BluePrintRestLibPropertyService =
             functionDependencyInstanceAsType(RestLibConstants.SERVICE_BLUEPRINT_REST_LIB_PROPERTY)
@@ -39,10 +38,6 @@ abstract class RestconfComponentFunction : AbstractComponentFunction() {
         return bluePrintRestLibPropertyService().blueprintWebClientService(selector)
     }
 
-    fun getDynamicProperties(key: String): JsonNode {
-        return operationInputs["dynamic-properties"]!!.get(key)
-    }
-
     fun resolveFromDatabase(resolutionKey: String, artifactName: String): String {
         return resourceResolutionService().resolveFromDatabase(bluePrintRuntimeService, artifactName, resolutionKey)
     }
index f2b6e3f..8778b1f 100644 (file)
@@ -51,13 +51,6 @@ abstract class AbstractComponentFunction : BlueprintFunctionNode<ExecutionServic
     lateinit var nodeTemplateName: String\r
     var operationInputs: MutableMap<String, JsonNode> = hashMapOf()\r
 \r
-    //FIXME("Move to Script abstract class")\r
-    /**\r
-     * Store Dynamic Script Dependency Instances, Objects present inside won't be persisted or state maintained.\r
-     * Later it will be moved to ScriptComponentFunction class, sub class for abstract class\r
-     */\r
-    var functionDependencyInstances: MutableMap<String, Any> = hashMapOf()\r
-\r
     override fun getName(): String {\r
         return stepName\r
     }\r
@@ -144,12 +137,12 @@ abstract class AbstractComponentFunction : BlueprintFunctionNode<ExecutionServic
         bluePrintRuntimeService.setNodeTemplateAttributeValue(nodeTemplateName, key, value)\r
     }\r
 \r
-    //FIXME("Move to Script abstract class")\r
-    /**\r
-     * This will be called from the scripts to serve instance from runtime to scripts.\r
-     */\r
-    open fun <T> functionDependencyInstanceAsType(name: String): T {\r
-        return functionDependencyInstances[name] as? T\r
-                ?: throw BluePrintProcessorException("couldn't get script property instance ($name)")\r
+    fun addError(type: String, name: String, error: String) {\r
+        bluePrintRuntimeService.getBluePrintError().addError(type, name, type)\r
+    }\r
+\r
+    fun addError(error: String) {\r
+        bluePrintRuntimeService.getBluePrintError().addError(error)\r
     }\r
+\r
 }
\ No newline at end of file
diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/AbstractScriptComponentFunction.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/AbstractScriptComponentFunction.kt
new file mode 100644 (file)
index 0000000..811ee4a
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ *  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.apps.blueprintsprocessor.services.execution
+
+import com.fasterxml.jackson.databind.JsonNode
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
+
+abstract class AbstractScriptComponentFunction : AbstractComponentFunction() {
+
+    companion object {
+        const val DYNAMIC_PROPERTIES = "dynamic-properties"
+    }
+
+    /**
+     * Store Dynamic Script Dependency Instances, Objects present inside won't be persisted or state maintained.
+     */
+    var functionDependencyInstances: MutableMap<String, Any> = hashMapOf()
+
+    /**
+     * This will be called from the scripts to serve instance from runtime to scripts.
+     */
+    open fun <T> functionDependencyInstanceAsType(name: String): T {
+        return functionDependencyInstances[name] as? T
+                ?: throw BluePrintProcessorException("couldn't get script property instance ($name)")
+    }
+
+    fun checkDynamicProperties(key: String): Boolean {
+        return operationInputs[DYNAMIC_PROPERTIES]?.has(key) ?: false
+    }
+
+    fun getDynamicProperties(key: String): JsonNode {
+        return operationInputs[DYNAMIC_PROPERTIES]!!.get(key)
+    }
+
+
+}
\ No newline at end of file
index 9bae4eb..2cf2232 100644 (file)
@@ -33,18 +33,30 @@ class ComponentFunctionScriptingService(private val applicationContext: Applicat
 
     private val log = LoggerFactory.getLogger(ComponentFunctionScriptingService::class.java)
 
-    fun <T : AbstractComponentFunction> scriptInstance(componentFunction: AbstractComponentFunction, scriptType: String,
-                                                       scriptClassReference: String,
-                                                       instanceDependencies: List<String>): T {
+    fun <T : AbstractScriptComponentFunction> scriptInstance(componentFunction: AbstractComponentFunction, scriptType: String,
+                                                             scriptClassReference: String,
+                                                             instanceDependencies: List<String>): T {
 
         log.info("creating component function of script type($scriptType), reference name($scriptClassReference) and " +
                 "instanceDependencies($instanceDependencies)")
 
         val scriptComponent: T = scriptInstance(componentFunction.bluePrintRuntimeService.bluePrintContext(),
                 scriptType, scriptClassReference)
-       // Populate Instance Properties
+
+        checkNotNull(scriptComponent) { "failed to initialize script component" }
+
+        scriptComponent.bluePrintRuntimeService = componentFunction.bluePrintRuntimeService
+        scriptComponent.processId = componentFunction.processId
+        scriptComponent.workflowName = componentFunction.workflowName
+        scriptComponent.stepName = componentFunction.stepName
+        scriptComponent.interfaceName = componentFunction.interfaceName
+        scriptComponent.operationName = componentFunction.operationName
+        scriptComponent.nodeTemplateName = componentFunction.nodeTemplateName
+        scriptComponent.operationInputs = componentFunction.operationInputs
+
+        // Populate Instance Properties
         instanceDependencies.forEach { instanceDependency ->
-            componentFunction.functionDependencyInstances[instanceDependency] = applicationContext
+            scriptComponent.functionDependencyInstances[instanceDependency] = applicationContext
                     .getBean(instanceDependency)
         }
         return scriptComponent