diff options
author | Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com> | 2019-03-08 14:25:20 -0500 |
---|---|---|
committer | Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com> | 2019-03-08 14:25:20 -0500 |
commit | fc3e34836f7be8eda28a8f996d733e8dfca01450 (patch) | |
tree | 74d19f88ff32919466ed7d1956feb77d63fc6411 /ms/controllerblueprints | |
parent | 3b9237fc576986283b31a1b3761da2093e49f6a9 (diff) |
Change resource definition population
Change-Id: I95d3bcddb6b2027a523ca7411d0c6c7f98fa0f63
Issue-ID: CCSDK-1110
Signed-off-by: Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/controllerblueprints')
4 files changed, 64 insertions, 50 deletions
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt index 1aeda0ba1..69ee1cfd4 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt @@ -85,6 +85,12 @@ object ResourceDictionaryUtils { ?: throw BluePrintProcessorException("couldn't get ResourceAssignment definitions for the file($filePath)") } + fun writeResourceDefinitionTypes(basePath: String, resourceDefinitions: List<ResourceDefinition>) { + val resourceDefinitionMap = resourceDefinitions.map { it.name to it }.toMap() + writeResourceDefinitionTypes(basePath, resourceDefinitionMap) + + } + fun writeResourceDefinitionTypes(basePath: String, resourceDefinitionMap: Map<String, ResourceDefinition>) { val typePath = basePath.plus(File.separator).plus(BluePrintConstants.TOSCA_DEFINITIONS_DIR) .plus(File.separator).plus("${ResourceDictionaryConstants.PATH_RESOURCE_DEFINITION_TYPE}.json") diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt index 63171de6f..fb49dc465 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt @@ -23,9 +23,9 @@ import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintEnhancerService
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.core.utils.BluePrintFileUtils
import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils
import org.springframework.stereotype.Service
import java.util.*
@@ -56,11 +56,15 @@ open class BluePrintEnhancerServiceImpl(private val bluePrintTypeEnhancerService bluePrintTypeEnhancerService.enhanceServiceTemplate(blueprintRuntimeService, "service_template",
blueprintRuntimeService.bluePrintContext().serviceTemplate)
+ log.info("##### Enhancing blueprint Resource Definitions")
+ val resourceDefinitions = resourceDefinitionEnhancerService.enhance(bluePrintTypeEnhancerService,
+ blueprintRuntimeService)
+
// Write the Enhanced Blueprint Definitions
BluePrintFileUtils.writeEnhancedBluePrint(blueprintRuntimeService.bluePrintContext())
- // Enhance Resource Dictionary
- enhanceResourceDefinition(blueprintRuntimeService)
+ // Write the Enhanced Blueprint Resource Definitions
+ ResourceDictionaryUtils.writeResourceDefinitionTypes(basePath, resourceDefinitions)
if (blueprintRuntimeService.getBluePrintError().errors.isNotEmpty()) {
throw BluePrintException(blueprintRuntimeService.getBluePrintError().errors.toString())
@@ -73,10 +77,5 @@ open class BluePrintEnhancerServiceImpl(private val bluePrintTypeEnhancerService return blueprintRuntimeService.bluePrintContext()
}
- private fun enhanceResourceDefinition(blueprintRuntimeService: BluePrintRuntimeService<*>) {
- log.info("##### Enhancing blueprint Resource Definitions")
- resourceDefinitionEnhancerService.enhance(blueprintRuntimeService)
- }
-
}
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTemplateEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTemplateEnhancerImpl.kt index fb6c06afb..0765f9035 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTemplateEnhancerImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTemplateEnhancerImpl.kt @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications 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. @@ -18,15 +19,13 @@ 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.data.NodeTemplate -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.BluePrintNodeTemplateEnhancer 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 @@ -51,7 +50,7 @@ open class BluePrintNodeTemplateEnhancerImpl(private val bluePrintRepoService: B val nodeTypeName = nodeTemplate.type // Get NodeType from Repo and Update Service Template - val nodeType = populateNodeType(nodeTypeName) + val nodeType = BluePrintEnhancerUtils.populateNodeType(bluePrintContext, bluePrintRepoService, nodeTypeName) // Enrich NodeType bluePrintTypeEnhancerService.enhanceNodeType(bluePrintRuntimeService, nodeTypeName, nodeType) @@ -60,16 +59,6 @@ open class BluePrintNodeTemplateEnhancerImpl(private val bluePrintRepoService: B enhanceNodeTemplateArtifactDefinition(name, nodeTemplate) } - - 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 - } - open fun enhanceNodeTemplateArtifactDefinition(nodeTemplateName: String, nodeTemplate: NodeTemplate) { nodeTemplate.artifacts?.forEach { artifactDefinitionName, artifactDefinition -> diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceDefinitionEnhancerService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceDefinitionEnhancerService.kt index 43eb019e2..6171687f2 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceDefinitionEnhancerService.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceDefinitionEnhancerService.kt @@ -23,18 +23,21 @@ import kotlinx.coroutines.Deferred import kotlinx.coroutines.async import kotlinx.coroutines.runBlocking import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +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.resource.dict.ResourceAssignment import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils import org.onap.ccsdk.apps.controllerblueprints.service.ResourceDefinitionRepoService +import org.onap.ccsdk.apps.controllerblueprints.service.utils.BluePrintEnhancerUtils import org.springframework.stereotype.Service interface ResourceDefinitionEnhancerService { @Throws(BluePrintException::class) - fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>) + fun enhance(bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, + bluePrintRuntimeService: BluePrintRuntimeService<*>): List<ResourceDefinition> } @Service @@ -45,7 +48,6 @@ class ResourceDefinitionEnhancerServiceImpl(private val resourceDefinitionRepoSe companion object { const val ARTIFACT_TYPE_MAPPING_SOURCE: String = "artifact-mapping-resource" - const val PROPERTY_DEPENDENCY_NODE_TEMPLATES = "dependency-node-templates" } // Enhance the Resource Definition @@ -53,15 +55,21 @@ class ResourceDefinitionEnhancerServiceImpl(private val resourceDefinitionRepoSe // 2. Get all the Unique Resource assignments from all mapping files // 3. Collect the Resource Definition for Resource Assignment names from database. // 4. Create the Resource Definition under blueprint base path. - override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>) { + override fun enhance(bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, + bluePrintRuntimeService: BluePrintRuntimeService<*>): List<ResourceDefinition> { + + var resourceDefinitions: List<ResourceDefinition> = mutableListOf() val blueprintContext = bluePrintRuntimeService.bluePrintContext() val mappingFiles = getAllResourceMappingFiles(blueprintContext) log.info("resources assignment files ($mappingFiles)") if (mappingFiles != null) { - getResourceDefinition(blueprintContext, mappingFiles) + resourceDefinitions = getResourceDefinition(blueprintContext, mappingFiles) + // Enriching Resource Definition Sources + enrichResourceDefinitionSources(bluePrintRuntimeService.bluePrintContext(), resourceDefinitions) } + return resourceDefinitions } // Get all the Mapping files from all node templates. @@ -80,42 +88,54 @@ class ResourceDefinitionEnhancerServiceImpl(private val resourceDefinitionRepoSe } // Convert file content to ResourceAssignments asynchronously - private fun getResourceDefinition(blueprintContext: BluePrintContext, files: List<String>) { - runBlocking { - val blueprintBasePath = blueprintContext.rootPath - val deferredResourceAssignments = mutableListOf<Deferred<List<ResourceAssignment>>>() - for (file in files) { - log.info("processing file ($file)") - deferredResourceAssignments += async { - ResourceDictionaryUtils.getResourceAssignmentFromFile("$blueprintBasePath/$file") - } - } - - val resourceAssignments = mutableListOf<ResourceAssignment>() - for (deferredResourceAssignment in deferredResourceAssignments) { - resourceAssignments.addAll(deferredResourceAssignment.await()) + private fun getResourceDefinition(blueprintContext: BluePrintContext, files: List<String>) = runBlocking { + val blueprintBasePath = blueprintContext.rootPath + val deferredResourceAssignments = mutableListOf<Deferred<List<ResourceAssignment>>>() + for (file in files) { + log.info("processing file ($file)") + deferredResourceAssignments += async { + ResourceDictionaryUtils.getResourceAssignmentFromFile("$blueprintBasePath/$file") } + } - val distinctResourceAssignments = resourceAssignments.distinctBy { it.name } - generateResourceDictionaryFile(blueprintBasePath, distinctResourceAssignments) - //log.info("distinct Resource assignment ($distinctResourceAssignments)") + val resourceAssignments = mutableListOf<ResourceAssignment>() + for (deferredResourceAssignment in deferredResourceAssignments) { + resourceAssignments.addAll(deferredResourceAssignment.await()) } + + val distinctResourceAssignments = resourceAssignments.distinctBy { it.name } + generateResourceDictionary(blueprintBasePath, distinctResourceAssignments) + //log.info("distinct Resource assignment ($distinctResourceAssignments)") } + // Read the Resource Definitions from the Database and write to type file. - private fun generateResourceDictionaryFile(blueprintBasePath: String, resourceAssignments: List<ResourceAssignment>) { + private fun generateResourceDictionary(blueprintBasePath: String, resourceAssignments: List<ResourceAssignment>) + : List<ResourceDefinition> { val resourceKeys = resourceAssignments.mapNotNull { it.dictionaryName }.distinct().sorted() log.info("distinct resource keys ($resourceKeys)") //TODO("Optimise DB single Query to multiple Query") - // Collect the Resource Definition from database and convert to map to save in file - val resourceDefinitionMap = resourceKeys.map { resourceKey -> + return resourceKeys.map { resourceKey -> getResourceDefinition(resourceKey) - }.map { it.name to it }.toMap() + } + } - // Recreate the Resource Definition File - ResourceDictionaryUtils.writeResourceDefinitionTypes(blueprintBasePath, resourceDefinitionMap) - log.info("resource definition file created successfully") + private fun enrichResourceDefinitionSources(bluePrintContext: BluePrintContext, + resourceDefinitions: List<ResourceDefinition>) { + val sources = resourceDefinitions + .map { it.sources } + .map { + it.values + .map { nodeTemplate -> + nodeTemplate.type + } + } + .flatten().distinct() + log.info("Enriching Resource Definition sources Node Template: $sources") + sources.forEach { + BluePrintEnhancerUtils.populateNodeType(bluePrintContext, resourceDefinitionRepoService, it) + } } // Get the Resource Definition from Database |