Add attribute definition enhancer.
authorMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
Tue, 18 Dec 2018 13:16:28 +0000 (08:16 -0500)
committerMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
Tue, 18 Dec 2018 13:16:28 +0000 (08:16 -0500)
Change-Id: Ie8ac60910f04dfca477d0276aa451821cfcd8510
Issue-ID: CCSDK-718
Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
13 files changed:
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java
ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintArtifactDefinitionEnhancerImpl.kt
ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintAttributeDefinitionEnhancerImpl.kt
ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt
ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTypeEnhancerImpl.kt
ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPropertyDefinitionEnhancerImpl.kt
ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintServiceTemplateEnhancerImpl.kt
ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintTopologyTemplateEnhancerImpl.kt
ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt
ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt
ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ModelTypeLoadService.kt
ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt [new file with mode: 0644]
ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtilsTest.java [deleted file]

index 3c6b14b..9693101 100644 (file)
@@ -48,7 +48,7 @@ public class ConfigModelUtils {
 \r
     public static ConfigModel getConfigModel(String blueprintPath) throws Exception {\r
         Preconditions.checkArgument(StringUtils.isNotBlank(blueprintPath), "Blueprint Path is missing");\r
-        ToscaMetaData toscaMetaData = BluePrintMetadataUtils.toscaMetaData(blueprintPath);\r
+        ToscaMetaData toscaMetaData = BluePrintMetadataUtils.Companion.toscaMetaData(blueprintPath);\r
 \r
         Preconditions.checkNotNull(toscaMetaData, "failed to get Blueprint Metadata information");\r
         Preconditions.checkArgument(StringUtils.isNotBlank(toscaMetaData.getEntityDefinitions()), "failed to get Blueprint Definition file");\r
index 986ce98..3b14d82 100644 (file)
@@ -22,7 +22,6 @@ import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
 import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive
 import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactDefinition
-import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactType
 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintArtifactDefinitionEnhancer
 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService
 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService
@@ -30,6 +29,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
+import org.onap.ccsdk.apps.controllerblueprints.service.utils.BluePrintEnhancerUtils
 import org.springframework.stereotype.Service
 
 @Service
@@ -56,10 +56,10 @@ open class BluePrintArtifactDefinitionEnhancerImpl(private val bluePrintRepoServ
         this.bluePrintContext = bluePrintRuntimeService.bluePrintContext()
 
         val artifactTypeName = artifactDefinition.type
-                ?: throw BluePrintException("Artifact type is missing for ArtifactDefinition($name)")
+                ?: throw BluePrintException("artifact type is missing for ArtifactDefinition($name)")
 
         // Populate Artifact Type
-        populateArtifactType(artifactTypeName)
+        BluePrintEnhancerUtils.populateArtifactType(bluePrintContext, bluePrintRepoService, artifactTypeName)
 
         when (artifactTypeName) {
             ARTIFACT_TYPE_MAPPING_SOURCE -> {
@@ -90,12 +90,4 @@ open class BluePrintArtifactDefinitionEnhancerImpl(private val bluePrintRepoServ
         }
     }
 
-    open fun populateArtifactType(artifactTypeName: String): ArtifactType {
-
-        val artifactType = bluePrintContext.serviceTemplate.artifactTypes?.get(artifactTypeName)
-                ?: bluePrintRepoService.getArtifactType(artifactTypeName)
-                ?: throw BluePrintException("couldn't get ArtifactType($artifactTypeName) from repo.")
-        bluePrintContext.serviceTemplate.artifactTypes?.put(artifactTypeName, artifactType)
-        return artifactType
-    }
 }
\ No newline at end of file
index 9f579bc..f69e344 100644 (file)
 
 package org.onap.ccsdk.apps.controllerblueprints.service.enhancer
 
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes
 import org.onap.ccsdk.apps.controllerblueprints.core.data.AttributeDefinition
 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintAttributeDefinitionEnhancer
 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService
 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
+import org.onap.ccsdk.apps.controllerblueprints.service.utils.BluePrintEnhancerUtils
 
 class BluePrintAttributeDefinitionEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService,
                                                private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService)
     : BluePrintAttributeDefinitionEnhancer {
 
-    override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, type: AttributeDefinition) {
-        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+    lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*>
+    lateinit var bluePrintContext: BluePrintContext
+
+    override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, attributeDefinition: AttributeDefinition) {
+        this.bluePrintRuntimeService = bluePrintRuntimeService
+        this.bluePrintContext = bluePrintRuntimeService.bluePrintContext()
+
+        val propertyType = attributeDefinition.type
+        if (BluePrintTypes.validPrimitiveTypes().contains(propertyType)) {
+
+        } else if (BluePrintTypes.validCollectionTypes().contains(propertyType)) {
+            val entrySchema = attributeDefinition.entrySchema
+                    ?: throw BluePrintException("Entry Schema is missing for collection property($name)")
+
+            if (!BluePrintTypes.validPrimitiveTypes().contains(entrySchema.type)) {
+                BluePrintEnhancerUtils.populateDataTypes(bluePrintContext, bluePrintRepoService, entrySchema.type)
+            }
+        } else {
+            BluePrintEnhancerUtils.populateDataTypes(bluePrintContext, bluePrintRepoService, propertyType)
+        }
     }
+
 }
\ No newline at end of file
index 6c7b6e0..d789595 100644 (file)
@@ -58,8 +58,8 @@ open class BluePrintEnhancerServiceImpl(private val bluePrintRepoService: BluePr
             bluePrintTypeEnhancerService.enhanceServiceTemplate(blueprintRuntimeService, "service_template",\r
                     blueprintRuntimeService.bluePrintContext().serviceTemplate)\r
 \r
-            // Write the Type File Definitions\r
-            BluePrintFileUtils.writeBluePrintTypes(blueprintRuntimeService.bluePrintContext())\r
+            // Write the Enhanced Blueprint Definitions\r
+            BluePrintFileUtils.writeEnhancedBluePrint(blueprintRuntimeService.bluePrintContext())\r
 \r
             // Enhance Resource Dictionary\r
             enhanceResourceDefinition(blueprintRuntimeService)\r
index 941be07..4e226b2 100644 (file)
@@ -18,17 +18,16 @@ package org.onap.ccsdk.apps.controllerblueprints.service.enhancer
 
 import com.att.eelf.configuration.EELFLogger
 import com.att.eelf.configuration.EELFManager
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes
 import org.onap.ccsdk.apps.controllerblueprints.core.data.InterfaceDefinition
 import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType
 import org.onap.ccsdk.apps.controllerblueprints.core.data.OperationDefinition
-import org.onap.ccsdk.apps.controllerblueprints.core.format
 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintNodeTypeEnhancer
 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService
 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService
 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
+import org.onap.ccsdk.apps.controllerblueprints.service.utils.BluePrintEnhancerUtils
 import org.springframework.beans.factory.config.ConfigurableBeanFactory
 import org.springframework.context.annotation.Scope
 import org.springframework.stereotype.Service
@@ -52,11 +51,14 @@ open class BluePrintNodeTypeEnhancerImpl(private val bluePrintRepoService: BlueP
         val derivedFrom = nodeType.derivedFrom
 
         if (!BluePrintTypes.rootNodeTypes().contains(derivedFrom)) {
-            val derivedFromNodeType = populateNodeType(name)
+            val derivedFromNodeType = BluePrintEnhancerUtils.populateNodeType(bluePrintContext, bluePrintRepoService, name)
             // Enrich NodeType
             enhance(bluePrintRuntimeService, derivedFrom, derivedFromNodeType)
         }
 
+        // NodeType Attribute Definitions
+        enrichNodeTypeAtributes(name, nodeType)
+
         // NodeType Property Definitions
         enrichNodeTypeProperties(name, nodeType)
 
@@ -71,6 +73,12 @@ open class BluePrintNodeTypeEnhancerImpl(private val bluePrintRepoService: BlueP
 
     }
 
+    open fun enrichNodeTypeAtributes(nodeTypeName: String, nodeType: NodeType) {
+        nodeType.attributes?.let {
+            bluePrintTypeEnhancerService.enhanceAttributeDefinitions(bluePrintRuntimeService, nodeType.attributes!!)
+        }
+    }
+
     open fun enrichNodeTypeProperties(nodeTypeName: String, nodeType: NodeType) {
         nodeType.properties?.let {
             bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, nodeType.properties!!)
@@ -83,7 +91,8 @@ open class BluePrintNodeTypeEnhancerImpl(private val bluePrintRepoService: BlueP
             // Populate Requirement Node
             requirementDefinition.node?.let { requirementNodeTypeName ->
                 // Get Requirement NodeType from Repo and Update Service Template
-                val requirementNodeType = populateNodeType(requirementNodeTypeName)
+                val requirementNodeType = BluePrintEnhancerUtils.populateNodeType(bluePrintContext,
+                        bluePrintRepoService, requirementNodeTypeName)
                 // Enhanypece Node T
                 enhance(bluePrintRuntimeService, requirementNodeTypeName, requirementNodeType)
             }
@@ -127,13 +136,4 @@ open class BluePrintNodeTypeEnhancerImpl(private val bluePrintRepoService: BlueP
         }
     }
 
-    open fun populateNodeType(nodeTypeName: String): NodeType {
-
-        val nodeType = bluePrintContext.serviceTemplate.nodeTypes?.get(nodeTypeName)
-                ?: bluePrintRepoService.getNodeType(nodeTypeName)
-                ?: throw BluePrintException(format("Couldn't get NodeType({}) from repo.", nodeTypeName))
-        bluePrintContext.serviceTemplate.nodeTypes?.put(nodeTypeName, nodeType)
-        return nodeType
-    }
-
 }
\ No newline at end of file
index ee3e6c3..1ae558f 100644 (file)
@@ -18,14 +18,13 @@ package org.onap.ccsdk.apps.controllerblueprints.service.enhancer
 
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes
-import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType
 import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition
-import org.onap.ccsdk.apps.controllerblueprints.core.format
 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintPropertyDefinitionEnhancer
 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService
 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService
 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
+import org.onap.ccsdk.apps.controllerblueprints.service.utils.BluePrintEnhancerUtils
 import org.springframework.beans.factory.config.ConfigurableBeanFactory
 import org.springframework.context.annotation.Scope
 import org.springframework.stereotype.Service
@@ -36,11 +35,9 @@ open class BluePrintPropertyDefinitionEnhancerImpl(private val bluePrintRepoServ
                                                    private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService)
     : BluePrintPropertyDefinitionEnhancer {
 
-
     lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*>
     lateinit var bluePrintContext: BluePrintContext
 
-
     override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, propertyDefinition: PropertyDefinition) {
         this.bluePrintRuntimeService = bluePrintRuntimeService
         this.bluePrintContext = bluePrintRuntimeService.bluePrintContext()
@@ -53,19 +50,11 @@ open class BluePrintPropertyDefinitionEnhancerImpl(private val bluePrintRepoServ
                     ?: throw BluePrintException("Entry Schema is missing for collection property($name)")
 
             if (!BluePrintTypes.validPrimitiveTypes().contains(entrySchema.type)) {
-                populateDataTypes(entrySchema.type)
+                BluePrintEnhancerUtils.populateDataTypes(bluePrintContext, bluePrintRepoService, entrySchema.type)
             }
         } else {
-            populateDataTypes(propertyType)
+            BluePrintEnhancerUtils.populateDataTypes(bluePrintContext, bluePrintRepoService, propertyType)
         }
     }
 
-    open fun populateDataTypes(dataTypeName: String): DataType {
-        val dataType = bluePrintContext.serviceTemplate.dataTypes?.get(dataTypeName)
-                ?: bluePrintRepoService.getDataType(dataTypeName)
-                ?: throw BluePrintException(format("Couldn't get DataType({}) from repo.", dataTypeName))
-        bluePrintContext.serviceTemplate.dataTypes?.put(dataTypeName, dataType)
-        return dataType
-    }
-
 }
\ No newline at end of file
index 2ad0583..51064bb 100644 (file)
@@ -62,7 +62,7 @@ open class BluePrintServiceTemplateEnhancerImpl(private val bluePrintRepoService
 
     open fun enhanceTopologyTemplate() {
         bluePrintContext.serviceTemplate.topologyTemplate?.let { topologyTemplate ->
-            bluePrintTypeEnhancerService.enhanceTopologyTemplate(bluePrintRuntimeService, "default", topologyTemplate)
+            bluePrintTypeEnhancerService.enhanceTopologyTemplate(bluePrintRuntimeService, "topology_template", topologyTemplate)
         }
     }
 }
\ No newline at end of file
index 6b72d42..428d490 100644 (file)
@@ -37,7 +37,7 @@ open class BluePrintTopologyTemplateEnhancerImpl(private val bluePrintRepoServic
 
         enhanceTopologyTemplateInputs(type)
         enhanceTopologyTemplateNodeTemplates(type)
-        enhanceTopologyTemplateWorkflowss(type)
+        enhanceTopologyTemplateWorkflows(type)
     }
 
     open fun enhanceTopologyTemplateInputs(topologyTemplate: TopologyTemplate) {
@@ -52,7 +52,7 @@ open class BluePrintTopologyTemplateEnhancerImpl(private val bluePrintRepoServic
         }
     }
 
-    open fun enhanceTopologyTemplateWorkflowss(topologyTemplate: TopologyTemplate) {
+    open fun enhanceTopologyTemplateWorkflows(topologyTemplate: TopologyTemplate) {
         topologyTemplate.workflows?.forEach { workflowName, workflow ->
             bluePrintTypeEnhancerService.enhanceWorkflow(bluePrintRuntimeService, workflowName, workflow)
         }
index a620e9b..9fbf091 100644 (file)
@@ -18,9 +18,9 @@ package org.onap.ccsdk.apps.controllerblueprints.service.enhancer
 
 import com.att.eelf.configuration.EELFLogger
 import com.att.eelf.configuration.EELFManager
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
-import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant
 import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive
 import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType
 import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition
@@ -169,27 +169,27 @@ open class BluePrintWorkflowEnhancerImpl(private val bluePrintRepoService: BlueP
 
         val dataTypeName = "dt-$workflowName-properties"
 
-        var recipeDataType: DataType? = bluePrintContext.serviceTemplate.dataTypes?.get(dataTypeName)
+        var dynamicDataType: DataType? = bluePrintContext.serviceTemplate.dataTypes?.get(dataTypeName)
 
-        if (recipeDataType == null) {
+        if (dynamicDataType == null) {
             log.info("dataType not present for the recipe({})", dataTypeName)
-            recipeDataType = DataType()
-            recipeDataType.version = "1.0.0"
-            recipeDataType.description = "Dynamic DataType definition for workflow($workflowName)."
-            recipeDataType.derivedFrom = ConfigModelConstant.MODEL_TYPE_DATA_TYPE_DYNAMIC
+            dynamicDataType = DataType()
+            dynamicDataType.version = "1.0.0"
+            dynamicDataType.description = "Dynamic DataType definition for workflow($workflowName)."
+            dynamicDataType.derivedFrom = BluePrintConstants.MODEL_TYPE_DATA_TYPE_DYNAMIC
 
             val dataTypeProperties: MutableMap<String, PropertyDefinition> = hashMapOf()
-            recipeDataType.properties = dataTypeProperties
+            dynamicDataType.properties = dataTypeProperties
 
             // Overwrite WorkFlow DataType
-            bluePrintContext.serviceTemplate.dataTypes?.put(dataTypeName, recipeDataType)
+            bluePrintContext.serviceTemplate.dataTypes?.put(dataTypeName, dynamicDataType)
 
         } else {
             log.info("dynamic dataType($dataTypeName) already present for workflow($workflowName).")
         }
         // Merge all the Recipe Properties
         mappingProperties.forEach { propertyName, propertyDefinition ->
-            recipeDataType.properties?.put(propertyName, propertyDefinition)
+            dynamicDataType.properties?.put(propertyName, propertyDefinition)
         }
     }
 }
\ No newline at end of file
index d6a00ae..4d1f44a 100644 (file)
@@ -20,7 +20,6 @@ import com.att.eelf.configuration.EELFLogger
 import com.att.eelf.configuration.EELFManager\r
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException\r
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes\r
-import org.onap.ccsdk.apps.controllerblueprints.core.format\r
 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService\r
 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService\r
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment\r
@@ -70,8 +69,7 @@ open class ResourceAssignmentEnhancerServiceImpl(private val resourceDefinitionR
         resourceAssignments.map { resourceAssignment ->\r
             val dictionaryName = resourceAssignment.dictionaryName!!\r
             val dictionarySource = resourceAssignment.dictionarySource!!\r
-            log.debug("Enriching Assignment name({}), dictionary name({}), source({})", resourceAssignment.name,\r
-                    dictionaryName, dictionarySource)\r
+            log.debug("Enriching assignment name(${resourceAssignment.name}), dictionary name($dictionaryName), source($dictionarySource)")\r
             val sourceNodeTypeName = ResourceSourceMappingFactory.getRegisterSourceMapping(dictionarySource)\r
 \r
             // Add Unique Node Types\r
@@ -87,7 +85,7 @@ open class ResourceAssignmentEnhancerServiceImpl(private val resourceDefinitionR
                 val resourceDefinition: ResourceDefinition = getResourceDefinition(dictionaryName)\r
 \r
                 val sourceNodeTemplate = resourceDefinition.sources.get(dictionarySource)\r
-                        ?: throw BluePrintException(format("failed to get assigned dictionarySource({}) from resourceDefinition({})", dictionarySource, dictionaryName))\r
+                        ?: throw BluePrintException("failed to get assigned dictionarySource($dictionarySource) from resourceDefinition($dictionaryName)")\r
 \r
                 // Enrich as NodeTemplate\r
                 bluePrintTypeEnhancerService.enhanceNodeTemplate(bluePrintRuntimeService, dictionarySource, sourceNodeTemplate)\r
@@ -101,15 +99,6 @@ open class ResourceAssignmentEnhancerServiceImpl(private val resourceDefinitionR
 \r
     }\r
 \r
-    /*\r
-        override fun enhanceBluePrint(resourceAssignments: List<ResourceAssignment>): ServiceTemplate {\r
-            val bluePrintEnhancerService = BluePrintEnhancerServiceImpl(resourceDefinitionRepoService)\r
-            bluePrintEnhancerService.serviceTemplate = ServiceTemplate()\r
-            bluePrintEnhancerService.initialCleanUp()\r
-            enhanceBluePrint(bluePrintEnhancerService, resourceAssignments)\r
-            return bluePrintEnhancerService.serviceTemplate\r
-        }\r
-    */\r
     private fun checkResourceDefinitionNeeded(resourceAssignment: ResourceAssignment): Boolean {\r
         return !((resourceAssignment.dictionarySource.equals(ResourceDictionaryConstants.SOURCE_INPUT)\r
                 || resourceAssignment.dictionarySource.equals(ResourceDictionaryConstants.SOURCE_DEFAULT))\r
index 1c5276c..31b1a16 100644 (file)
@@ -17,6 +17,7 @@
 package org.onap.ccsdk.apps.controllerblueprints.service.load
 
 import com.att.eelf.configuration.EELFManager
+import kotlinx.coroutines.*
 import org.apache.commons.io.FilenameUtils
 import org.apache.commons.lang3.text.StrBuilder
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
@@ -40,19 +41,39 @@ open class ModelTypeLoadService(private val modelTypeService: ModelTypeService)
         modelTypePaths.forEach { loadPathModelType(it) }
     }
 
-    open fun loadPathModelType(modelTypePath: String) {
+    open fun loadPathModelType(modelTypePath: String) = runBlocking {
         log.info(" *************************** loadModelType **********************")
         try {
             val errorBuilder = StrBuilder()
 
-            val dataTypeFiles = File("$modelTypePath/data_type").listFiles()
-            dataTypeFiles.forEach { loadDataType(it, errorBuilder) }
+            coroutineScope {
+                val dataTypeFiles = File("$modelTypePath/data_type").listFiles()
 
-            val artifactTypefiles = File("$modelTypePath/artifact_type").listFiles()
-            artifactTypefiles.forEach { loadArtifactType(it, errorBuilder) }
+                val deferredResults = mutableListOf<Deferred<Unit>>()
 
-            val nodeTypeFiles = File("$modelTypePath/node_type").listFiles()
-            nodeTypeFiles.forEach { loadNodeType(it, errorBuilder) }
+                for (file in dataTypeFiles) deferredResults += async { loadDataType(file, errorBuilder) }
+
+                deferredResults.awaitAll()
+            }
+
+            coroutineScope {
+                val artifactTypefiles = File("$modelTypePath/artifact_type").listFiles()
+
+                val deferredResults = mutableListOf<Deferred<Unit>>()
+
+                for (file in artifactTypefiles) deferredResults += async { loadArtifactType(file, errorBuilder) }
+
+                deferredResults.awaitAll()
+            }
+
+            coroutineScope {
+                val nodeTypeFiles = File("$modelTypePath/node_type").listFiles()
+
+                val deferredResults = mutableListOf<Deferred<Unit>>()
+
+                for (file in nodeTypeFiles) deferredResults += async { loadNodeType(file, errorBuilder) }
+                deferredResults.awaitAll()
+            }
 
             if (!errorBuilder.isEmpty) {
                 log.error(errorBuilder.toString())
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt
new file mode 100644 (file)
index 0000000..801c22a
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * 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.controllerblueprints.service.utils
+
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactType
+import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType
+import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType
+import org.onap.ccsdk.apps.controllerblueprints.core.format
+import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
+
+
+class BluePrintEnhancerUtils {
+    companion object {
+
+        fun populateDataTypes(bluePrintContext: BluePrintContext, bluePrintRepoService: BluePrintRepoService,
+                              dataTypeName: String): DataType {
+            val dataType = bluePrintContext.serviceTemplate.dataTypes?.get(dataTypeName)
+                    ?: bluePrintRepoService.getDataType(dataTypeName)
+                    ?: throw BluePrintException("couldn't get DataType($dataTypeName) from repo.")
+            bluePrintContext.serviceTemplate.dataTypes?.put(dataTypeName, dataType)
+            return dataType
+        }
+
+
+        fun populateNodeType(bluePrintContext: BluePrintContext, bluePrintRepoService: BluePrintRepoService,
+                             nodeTypeName: String): NodeType {
+
+            val nodeType = bluePrintContext.serviceTemplate.nodeTypes?.get(nodeTypeName)
+                    ?: bluePrintRepoService.getNodeType(nodeTypeName)
+                    ?: throw BluePrintException(format("Couldn't get NodeType({}) from repo.", nodeTypeName))
+            bluePrintContext.serviceTemplate.nodeTypes?.put(nodeTypeName, nodeType)
+            return nodeType
+        }
+
+        fun populateArtifactType(bluePrintContext: BluePrintContext, bluePrintRepoService: BluePrintRepoService,
+                                 artifactTypeName: String): ArtifactType {
+
+            val artifactType = bluePrintContext.serviceTemplate.artifactTypes?.get(artifactTypeName)
+                    ?: bluePrintRepoService.getArtifactType(artifactTypeName)
+                    ?: throw BluePrintException("couldn't get ArtifactType($artifactTypeName) from repo.")
+            bluePrintContext.serviceTemplate.artifactTypes?.put(artifactTypeName, artifactType)
+            return artifactType
+        }
+    }
+}
diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtilsTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtilsTest.java
deleted file mode 100644 (file)
index b38dd6d..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*\r
- * Copyright © 2017-2018 AT&T Intellectual Property.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.onap.ccsdk.apps.controllerblueprints.service.utils;\r
-\r
-import org.apache.commons.collections.CollectionUtils;\r
-import org.junit.Assert;\r
-import org.junit.Test;\r
-import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel;\r
-\r
-public class ConfigModelUtilsTest {\r
-\r
-    @Test\r
-    public void testConfigModel() throws Exception {\r
-\r
-        ConfigModel configModel = ConfigModelUtils.getConfigModel("load/blueprints/vrr-test");\r
-        Assert.assertNotNull("Failed to prepare config model", configModel);\r
-        Assert.assertTrue("Failed to prepare config model contents", CollectionUtils.isNotEmpty(configModel.getConfigModelContents()));\r
-    }\r
-}\r