diff options
author | Dan Timoney <dtimoney@att.com> | 2019-03-09 14:02:29 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-03-09 14:02:29 +0000 |
commit | a5d9a4ddb92bad7d3334d8a6f9bc93879b8009ef (patch) | |
tree | ce5dfbe697191447f0d2797403128c4b8452e0b2 /ms/controllerblueprints/modules | |
parent | 5d51986fd1fc4f22d107b2fe6b127a2704278d43 (diff) | |
parent | b2717e28c9e4a2d2531ff05571c04376c3b05bf7 (diff) |
Merge "Change resource definition population"
Diffstat (limited to 'ms/controllerblueprints/modules')
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 1aeda0ba..69ee1cfd 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 63171de6..fb49dc46 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 fb6c06af..0765f903 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 43eb019e..6171687f 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 |