Fixes: manual integration test of CDS
authorAlexis de Talhouët <adetalhouet89@gmail.com>
Mon, 11 Feb 2019 22:23:48 +0000 (17:23 -0500)
committerAlexis de Talhouët <adetalhouet89@gmail.com>
Tue, 12 Feb 2019 19:12:44 +0000 (14:12 -0500)
- support to overwrite cba
- fix map to json
- finish meshing
- fix python context not having the bluePrintRuntimeService injected
- load all properties in the properties store

Issue-ID: CCSDK-414
Change-Id: I6b65201529d0ffd9c3e18023a33e0081236b01de
Signed-off-by: Alexis de Talhouët <adetalhouet89@gmail.com>
13 files changed:
ms/blueprintsprocessor/application/pom.xml
ms/blueprintsprocessor/application/src/main/resources/application.properties
ms/blueprintsprocessor/application/src/test/resources/application.properties
ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/BlueprintPythonService.kt
ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt
ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/plugin/BlueprintPythonHost.kt
ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/plugin/BlueprintPythonInterpreterProxy.kt
ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutorTest.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt
ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt
ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt
ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/mock/MockComponentFunction.kt

index 9ad2ccb..b02e9e9 100755 (executable)
             <groupId>org.onap.ccsdk.apps.blueprintsprocessor</groupId>
             <artifactId>resource-api</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.onap.ccsdk.apps.blueprintsprocessor.functions</groupId>
+            <artifactId>python-executor</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.onap.ccsdk.apps.blueprintsprocessor</groupId>
             <artifactId>selfservice-api</artifactId>
index d48aba5..e5c928d 100755 (executable)
@@ -30,11 +30,10 @@ blueprintsprocessor.db.primary.url=jdbc:mysql://db:3306/sdnctl
 blueprintsprocessor.db.primary.username=sdnctl
 blueprintsprocessor.db.primary.password=sdnctl
 blueprintsprocessor.db.primary.driverClassName=org.mariadb.jdbc.Driver
-blueprintsprocessor.db.primary.hibernateHbm2ddlAuto=none
-blueprintsprocessor.db.primary.hibernateDDLAuto=none
+blueprintsprocessor.db.primary.hibernateHbm2ddlAuto=update
+blueprintsprocessor.db.primary.hibernateDDLAuto=update
 blueprintsprocessor.db.primary.hibernateNamingStrategy=org.hibernate.cfg.ImprovedNamingStrategy
 blueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.MySQL5InnoDBDialect
-
 # Python executor
 blueprints.processor.functions.python.executor.executionPath=/opt/app/onap/scripts/jython
 blueprints.processor.functions.python.executor.modulePaths=/opt/app/onap/scripts/jython
\ No newline at end of file
index bfbf458..2b5bea1 100644 (file)
@@ -29,7 +29,6 @@ blueprintsprocessor.db.primary.hibernateHbm2ddlAuto=create-drop
 blueprintsprocessor.db.primary.hibernateDDLAuto=update
 blueprintsprocessor.db.primary.hibernateNamingStrategy=org.hibernate.cfg.ImprovedNamingStrategy
 blueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.H2Dialect
-
 # Python executor
 blueprints.processor.functions.python.executor.executionPath=/opt/app/onap/scripts/jython
-blueprints.processor.functions.python.executor.modulePaths=/opt/app/onap/scripts/jython
\ No newline at end of file
+blueprints.processor.functions.python.executor.modulePaths=/opt/app/onap/scripts/jython
index cea02fb..21adcd5 100644 (file)
@@ -34,10 +34,10 @@ class BlueprintPythonService(val pythonExecutorProperty: PythonExecutorProperty)
         pythonPath.add(blueprintBasePath)
         pythonPath.addAll(pythonExecutorProperty.modulePaths)
 
-        var blueprintPythonConfigurations = BluePrintPython(pythonExecutorProperty.executionPath, pythonPath, arrayListOf())
+        val blueprintPythonConfigurations = BluePrintPython(pythonExecutorProperty.executionPath, pythonPath, arrayListOf())
 
         val blueprintPythonHost = BlueprintPythonHost(blueprintPythonConfigurations)
-        var pyObject = blueprintPythonHost.getPythonComponent(content, pythonClassName, dependencyInstanceNames)
+        val pyObject = blueprintPythonHost.getPythonComponent(content, pythonClassName, dependencyInstanceNames)
 
         log.info("Component Object {}", pyObject)
 
index 4a3ad6b..ba55638 100644 (file)
@@ -26,6 +26,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
 import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyOrThrow
 import org.onap.ccsdk.apps.controllerblueprints.core.data.OperationAssignment
 import org.slf4j.LoggerFactory
+import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.beans.factory.config.ConfigurableBeanFactory
 import org.springframework.context.ApplicationContext
 import org.springframework.context.annotation.Scope
@@ -40,7 +41,25 @@ open class ComponentJythonExecutor(private var applicationContext: ApplicationCo
 
     private var componentFunction: AbstractComponentFunction? = null
 
-    fun populateJythonComponentInstance(executionServiceInput: ExecutionServiceInput) {
+    override fun prepareRequest(executionRequest: ExecutionServiceInput): ExecutionServiceInput {
+        val request = super.prepareRequest(executionRequest)
+        // Populate Component Instance
+        populateJythonComponentInstance()
+        return request
+    }
+
+    override fun process(executionRequest: ExecutionServiceInput) {
+        log.info("Processing : $operationInputs")
+        // Invoke Jython Component Script
+        componentFunction!!.process(executionServiceInput)
+
+    }
+
+    override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+        componentFunction!!.recover(runtimeException, executionRequest)
+    }
+
+    private fun populateJythonComponentInstance() {
         val bluePrintContext = bluePrintRuntimeService.bluePrintContext()
 
         val operationAssignment: OperationAssignment = bluePrintContext
@@ -63,36 +82,23 @@ open class ComponentJythonExecutor(private var applicationContext: ApplicationCo
         val instanceDependenciesNode: ArrayNode = operationInputs[PythonExecutorConstants.INPUT_INSTANCE_DEPENDENCIES] as? ArrayNode
                 ?: throw BluePrintProcessorException("Failed to get property(${PythonExecutorConstants.INPUT_INSTANCE_DEPENDENCIES})")
 
-        val jythonContextInstance: MutableMap<String, Any> = hashMapOf()
-        jythonContextInstance["log"] = LoggerFactory.getLogger(pythonClassName)
-        jythonContextInstance["bluePrintRuntimeService"] = bluePrintRuntimeService
-        instanceDependenciesNode?.forEach { instanceName ->
-            val instance = instanceName.textValue()
-            val value = applicationContext.getBean(instance)
-                    ?: throw BluePrintProcessorException("couldn't get the dependency instance($instance)")
-            jythonContextInstance[instance] = value
+        val jythonInstance: MutableMap<String, Any> = hashMapOf()
+        jythonInstance["log"] = LoggerFactory.getLogger(pythonClassName)
+        jythonInstance["bluePrintRuntimeService"] = bluePrintRuntimeService
+
+        instanceDependenciesNode.forEach { instanceName ->
+            jythonInstance[instanceName.textValue()] = applicationContext.getBean(instanceName.textValue())
         }
 
+        // Setup componentFunction
         componentFunction = blueprintPythonService.jythonInstance(bluePrintContext, pythonClassName,
-                content!!, jythonContextInstance)
-    }
-
-
-    override fun process(executionServiceInput: ExecutionServiceInput) {
-
-        log.info("Processing : $operationInputs")
-        checkNotNull(bluePrintRuntimeService) { "failed to get bluePrintRuntimeService" }
-
-        // Populate Component Instance
-        populateJythonComponentInstance(executionServiceInput)
-
-        // Invoke Jython Component Script
-        componentFunction!!.process(executionServiceInput)
-
+                content!!, jythonInstance)
+        componentFunction?.bluePrintRuntimeService = bluePrintRuntimeService
+        componentFunction?.executionServiceInput = executionServiceInput
+        componentFunction?.stepName = stepName
+        componentFunction?.interfaceName = interfaceName
+        componentFunction?.operationName = operationName
+        componentFunction?.processId = processId
+        componentFunction?.workflowName = workflowName
     }
-
-    override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
-        componentFunction!!.recover(runtimeException, executionRequest)
-    }
-
 }
\ No newline at end of file
index ca0a715..7278ced 100644 (file)
@@ -38,7 +38,7 @@ open class BlueprintPythonHost(private val bluePrintPython: BluePrintPython){
     fun getPythonComponent(content: String?, interfaceName: String, properties: MutableMap<String, Any>?): PyObject {
         bluePrintPython.content = content!!
         bluePrintPython.pythonClassName = interfaceName
-        bluePrintPython.moduleName = "Blueprint Python Scripting [Class Name = $interfaceName]"
+        bluePrintPython.moduleName = "Blueprint Python Script [Class Name = $interfaceName]"
 
         return blueprintPythonInterpreterProxy.getPythonInstance(properties)
     }
index 34d5119..67a3d95 100644 (file)
@@ -42,7 +42,6 @@ class ComponentJythonExecutorTest {
 
     @Test
     fun testPythonComponentInjection() {
-
         val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-activate-request.json",
                 ExecutionServiceInput::class.java)!!
 
@@ -51,7 +50,7 @@ class ComponentJythonExecutorTest {
 
         val stepMetaData: MutableMap<String, JsonNode> = hashMapOf()
         stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "activate-jython")
-        stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "JythonExecutorComponent")
+        stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ComponentJythonExecutor")
         stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process")
         bluePrintRuntimeService.put("activate-jython-step-inputs", stepMetaData.asJsonNode())
 
index 38e5c95..ce0f060 100644 (file)
 \r
 package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution\r
 \r
+import com.fasterxml.jackson.databind.node.JsonNodeFactory
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.ResourceAssignmentProcessor\r
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils\r
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants\r
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException\r
 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService\r
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintTemplateService
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils\r
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment\r
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition\r
@@ -89,25 +91,22 @@ class ResourceResolutionService {
         val resourceDictionaries: MutableMap<String, ResourceDefinition> = JacksonUtils.getMapFromFile(dictionaryFile, ResourceDefinition::class.java)\r
                 ?: throw BluePrintProcessorException("couldn't get Dictionary Definitions")\r
 \r
+        // Resolve resources
         executeProcessors(bluePrintRuntimeService, resourceDictionaries, resourceAssignments, templateArtifactName)\r
 \r
         // Check Template is there\r
-        val templateContent = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, mappingArtifactName)\r
+        val templateContent = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, templateArtifactName)
 \r
-        // TODO ("Generate Param JSON from Resource Assignment")\r
-        val resolvedParamJsonContent = "{}"\r
+        val resolvedParamJsonContent = ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignments.toList())
 \r
         if (templateContent.isNotEmpty()) {\r
-            // TODO ( "Mash Data and Content")\r
-            resolvedContent = "Mashed Content"\r
-\r
+            resolvedContent = BluePrintTemplateService.generateContent(templateContent, resolvedParamJsonContent)
         } else {\r
             resolvedContent = resolvedParamJsonContent\r
         }\r
         return resolvedContent\r
     }\r
 \r
-\r
     private fun executeProcessors(blueprintRuntimeService: BluePrintRuntimeService<*>,\r
                                   resourceDictionaries: MutableMap<String, ResourceDefinition>,\r
                                   resourceAssignments: MutableList<ResourceAssignment>,\r
index ee8911e..93b93fe 100644 (file)
@@ -128,11 +128,7 @@ class ResourceAssignmentUtils {
                                     BluePrintConstants.DATA_TYPE_INTEGER -> (root as ObjectNode).put(rName, value as Int)
                                     BluePrintConstants.DATA_TYPE_FLOAT -> (root as ObjectNode).put(rName, value as Float)
                                     else -> {
-                                        if (JacksonUtils.getJsonNode(value) != null) {
-                                            (root as ObjectNode).set(rName, JacksonUtils.getJsonNode(value))
-                                        } else {
-                                            (root as ObjectNode).set(rName, null)
-                                        }
+                                        (root as ObjectNode).set(rName, JacksonUtils.getJsonNode(value))
                                     }
                                 }
                             }
index 4cfa652..bb54fcb 100644 (file)
@@ -68,7 +68,7 @@ class ResourceResolutionComponentTest {
 
         val stepMetaData: MutableMap<String, JsonNode> = hashMapOf()
         stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "resource-assignment")
-        stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ResourceAssignmentComponent")
+        stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ResourceResolutionComponent")
         stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process")
         bluePrintRuntimeService.put("resource-assignment-step-inputs", stepMetaData.asJsonNode())
 
index dee7ae8..33d0d96 100755 (executable)
@@ -79,10 +79,9 @@ class BlueprintProcessorCatalogServiceImpl(bluePrintValidatorService: BluePrintV
         val artifactName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME]
         val artifactVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION]
 
-        log.isDebugEnabled.apply {
-            blueprintModelRepository.findByArtifactNameAndArtifactVersion(artifactName!!, artifactVersion!!)?.let {
-                log.debug("Overwriting blueprint model :$artifactName::$artifactVersion")
-            }
+        blueprintModelRepository.findByArtifactNameAndArtifactVersion(artifactName!!, artifactVersion!!)?.let {
+            log.info("Overwriting blueprint model :$artifactName::$artifactVersion")
+            blueprintModelRepository.deleteByArtifactNameAndArtifactVersion(artifactName, artifactVersion)
         }
 
         val blueprintModel = BlueprintProcessorModel()
index 7b9a35e..4c12456 100644 (file)
@@ -29,7 +29,7 @@ import org.springframework.stereotype.Component
 @Configuration
 open class MockComponentConfiguration {
 
-    @Bean(name = ["component-resource-assignment", "component-netconf-executor", "component-jython-executor"])
+    @Bean(name = ["component-resource-resolution", "component-netconf-executor", "component-jython-executor"])
     open fun createComponentFunction(): AbstractComponentFunction {
         return MockComponentFunction()
     }