aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>2018-12-14 16:41:37 -0500
committerMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>2018-12-14 16:41:37 -0500
commit5045877d046ebcddc80a8b83c14351a0d9fe6a49 (patch)
treec197485e2949705caef23c7825b1ecc7ff3dc77c
parent72066bf5f27870a6bd009b920452a77d57fd8af3 (diff)
Add blueprint resource definition enrichment.
Change-Id: I01234093028ffdc8bf1688e41baba20fae7da5ce Issue-ID: CCSDK-747 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
-rw-r--r--components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt43
-rw-r--r--components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt2
-rw-r--r--components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt20
-rw-r--r--ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerService.java174
-rw-r--r--ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt31
-rw-r--r--ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceDefinitionEnhancerService.kt124
-rw-r--r--ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.java4
-rw-r--r--ms/controllerblueprints/modules/service/src/test/resources/logback.xml2
8 files changed, 204 insertions, 196 deletions
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt
index 0092b702..9dbe15ef 100644
--- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt
+++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt
@@ -64,20 +64,24 @@ object BluePrintMetadataUtils {
}
@JvmStatic
- fun getBluePrintContext(blueprintBasePath: String): BluePrintContext {
+ fun getBluePrintRuntime(id: String, blueprintBasePath: String): BluePrintRuntimeService<MutableMap<String, JsonNode>> {
- val toscaMetaData: ToscaMetaData = toscaMetaData(blueprintBasePath)
+ val bluePrintContext: BluePrintContext = getBluePrintContext(blueprintBasePath)
- log.info("Processing blueprint base path ($blueprintBasePath) and entry definition file (${toscaMetaData.entityDefinitions})")
+ val context: MutableMap<String, JsonNode> = hashMapOf()
+ context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = blueprintBasePath.asJsonPrimitive()
+ context[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = id.asJsonPrimitive()
- return readBlueprintFile(toscaMetaData.entityDefinitions, blueprintBasePath)
+ val bluePrintRuntimeService = DefaultBluePrintRuntimeService(id, bluePrintContext)
+ bluePrintRuntimeService.setExecutionContext(context)
+
+ return bluePrintRuntimeService
}
@JvmStatic
- fun getBluePrintRuntime(id: String, blueprintBasePath: String): BluePrintRuntimeService<MutableMap<String, JsonNode>> {
-
- val bluePrintContext: BluePrintContext = getBluePrintContext(blueprintBasePath)
+ fun getBaseEnhancementBluePrintRuntime(id: String, blueprintBasePath: String): BluePrintRuntimeService<MutableMap<String, JsonNode>> {
+ val bluePrintContext: BluePrintContext = getBaseEnhancementBluePrintContext(blueprintBasePath)
val context: MutableMap<String, JsonNode> = hashMapOf()
context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = blueprintBasePath.asJsonPrimitive()
context[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = id.asJsonPrimitive()
@@ -97,6 +101,31 @@ object BluePrintMetadataUtils {
}
@JvmStatic
+ fun getBluePrintContext(blueprintBasePath: String): BluePrintContext {
+
+ val toscaMetaData: ToscaMetaData = toscaMetaData(blueprintBasePath)
+
+ log.info("Processing blueprint base path ($blueprintBasePath) and entry definition file (${toscaMetaData.entityDefinitions})")
+
+ return readBlueprintFile(toscaMetaData.entityDefinitions, blueprintBasePath)
+ }
+
+ fun getBaseEnhancementBluePrintContext(blueprintBasePath: String): BluePrintContext {
+ val toscaMetaData: ToscaMetaData = toscaMetaData(blueprintBasePath)
+ // Clean Type files
+ BluePrintFileUtils.deleteBluePrintTypes(blueprintBasePath)
+ val rootFilePath: String = blueprintBasePath.plus(File.separator).plus(toscaMetaData.entityDefinitions)
+ val rootServiceTemplate = ServiceTemplateUtils.getServiceTemplate(rootFilePath)
+
+ // Clean the Import Definitions
+ rootServiceTemplate.imports?.clear()
+
+ val blueprintContext = BluePrintContext(rootServiceTemplate)
+ blueprintContext.rootPath = blueprintBasePath
+ return blueprintContext
+ }
+
+ @JvmStatic
fun readBlueprintFile(entityDefinitions: String, basePath: String): BluePrintContext {
val rootFilePath: String = basePath.plus(File.separator).plus(entityDefinitions)
val rootServiceTemplate = ServiceTemplateUtils.getServiceTemplate(rootFilePath)
diff --git a/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt
index aa6a9fb6..a39139ed 100644
--- a/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt
+++ b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt
@@ -31,4 +31,6 @@ object ResourceDictionaryConstants {
const val PROPERTY_INPUT_KEY_MAPPING = "input-key-mapping"
const val PROPERTY_OUTPUT_KEY_MAPPING = "output-key-mapping"
const val PROPERTY_KEY_DEPENDENCIES = "key-dependencies"
+
+ const val PATH_RESOURCE_DEFINITION_TYPE = "resource_definition_types"
} \ No newline at end of file
diff --git a/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt
index a3456cd4..1aeda0ba 100644
--- a/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt
+++ b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt
@@ -17,16 +17,20 @@
package org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils
import com.att.eelf.configuration.EELFLogger
+import com.att.eelf.configuration.EELFManager
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.node.NullNode
import org.apache.commons.collections.MapUtils
import org.apache.commons.lang3.StringUtils
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
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.ResourceDictionaryConstants
-import com.att.eelf.configuration.EELFManager
+import java.io.File
object ResourceDictionaryUtils {
@@ -49,7 +53,7 @@ object ResourceDictionaryUtils {
resourceAssignment.dictionarySource = ResourceDictionaryConstants.SOURCE_INPUT
}
log.info("auto map resourceAssignment : {}", resourceAssignment)
- }else {
+ } else {
resourceAssignment.dictionarySource = ResourceDictionaryConstants.SOURCE_INPUT
}
}
@@ -75,4 +79,16 @@ object ResourceDictionaryUtils {
context[path] = valueNode
}
}
+
+ fun getResourceAssignmentFromFile(filePath: String): List<ResourceAssignment> {
+ return JacksonUtils.getListFromFile(filePath, ResourceAssignment::class.java)
+ ?: throw BluePrintProcessorException("couldn't get ResourceAssignment definitions for the file($filePath)")
+ }
+
+ 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")
+ val resourceDefinitionContent = JacksonUtils.getJson(resourceDefinitionMap.toSortedMap(), true)
+ BluePrintFileUtils.writeDefinitionFile(typePath, resourceDefinitionContent)
+ }
} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerService.java
deleted file mode 100644
index 930c88d8..00000000
--- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerService.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * Copyright © 2017-2018 AT&T Intellectual Property.
- * Modifications Copyright © 2018 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.controllerblueprints.service;
-
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.google.common.base.Preconditions;
-import org.apache.commons.collections.MapUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.jetbrains.annotations.NotNull;
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
-import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant;
-import org.onap.ccsdk.apps.controllerblueprints.core.data.*;
-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.enhancer.ResourceAssignmentEnhancerService;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * BluePrintEnhancerService
- *
- * @author Brinda Santh DATE : 8/8/2018
- */
-
-@Deprecated
-public class BluePrintEnhancerService {
-
- private static EELFLogger log = EELFManager.getInstance().getLogger(BluePrintEnhancerService.class);
-
- private ResourceAssignmentEnhancerService resourceAssignmentEnhancerService;
-
- private Map<String, DataType> recipeDataTypes = new HashMap<>();
-
-
- private void populateArtifactTemplateMappingDataType(@NotNull String nodeTemplateName, @NotNull NodeTemplate nodeTemplate)
- throws BluePrintException {
- log.info("****** Processing Artifact Node Template : {}", nodeTemplateName);
-
- if (nodeTemplate.getProperties() != null) {
-
- if (!nodeTemplate.getProperties().containsKey(ConfigModelConstant.PROPERTY_RECIPE_NAMES)) {
- throw new BluePrintException("Node Template (" + nodeTemplateName + ") doesn't have "
- + ConfigModelConstant.PROPERTY_RECIPE_NAMES + " property.");
- }
-
- // Modified for ONAP converted Object to JsonNode
- JsonNode recipeNames = nodeTemplate.getProperties().get(ConfigModelConstant.PROPERTY_RECIPE_NAMES);
-
- log.info("Processing Recipe Names : {} ", recipeNames);
-
- if (recipeNames != null && recipeNames.isArray() && recipeNames.size() > 0) {
-
- Map<String, PropertyDefinition> mappingProperties =
- getCapabilityMappingProperties(nodeTemplateName, nodeTemplate);
-
- for (JsonNode recipeNameNode : recipeNames) {
- String recipeName = recipeNameNode.textValue();
- processRecipe(nodeTemplateName, mappingProperties, recipeName);
- }
- }
- }
- }
-
- private void processRecipe(@NotNull String nodeTemplateName, Map<String, PropertyDefinition> mappingProperties, String recipeName) {
- if (StringUtils.isNotBlank(recipeName)) {
- DataType recipeDataType = this.recipeDataTypes.get(recipeName);
- if (recipeDataType == null) {
- log.info("DataType not present for the recipe({})", recipeName);
- recipeDataType = new DataType();
- recipeDataType.setVersion("1.0.0");
- recipeDataType.setDescription(
- "This is Dynamic Data type definition generated from resource mapping for the config template name "
- + nodeTemplateName + ".");
- recipeDataType.setDerivedFrom(ConfigModelConstant.MODEL_TYPE_DATA_TYPE_DYNAMIC);
- Map<String, PropertyDefinition> dataTypeProperties = new HashMap<>();
- recipeDataType.setProperties(dataTypeProperties);
- } else {
- log.info("DataType Already present for the recipe({})", recipeName);
- }
-
- // Merge all the Recipe Properties
- mergeDataTypeProperties(recipeDataType, mappingProperties);
-
- // Overwrite Recipe DataType
- this.recipeDataTypes.put(recipeName, recipeDataType);
-
- }
- }
-
- private Map<String, PropertyDefinition> getCapabilityMappingProperties(String nodeTemplateName,
- NodeTemplate nodeTemplate) throws BluePrintException {
-
- Map<String, PropertyDefinition> dataTypeProperties = null;
- if (nodeTemplate != null && MapUtils.isNotEmpty(nodeTemplate.getCapabilities())) {
- CapabilityAssignment capability =
- nodeTemplate.getCapabilities().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING);
-
- if (capability != null && capability.getProperties() != null) {
-
- String resourceAssignmentContent = JacksonUtils
- .getJson(capability.getProperties().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING));
-
- List<ResourceAssignment> resourceAssignments =
- JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment.class);
-
- Preconditions.checkNotNull(resourceAssignments, "Failed to Processing Resource Mapping " + resourceAssignmentContent);
- // Enhance Resource Assignment TODO("Plug Resource Assignment Enhancer Service")
- //resourceAssignmentEnhancerService.enhanceBluePrint(this, resourceAssignments);
-
- dataTypeProperties = new HashMap<>();
-
- for (ResourceAssignment resourceAssignment : resourceAssignments) {
- if (resourceAssignment != null
- // && Boolean.valueOf(resourceAssignment.getInputParameter())
- && resourceAssignment.getProperty() != null
- && StringUtils.isNotBlank(resourceAssignment.getName())) {
-
- dataTypeProperties.put(resourceAssignment.getName(), resourceAssignment.getProperty());
-
- }
- }
-
- }
- }
- return dataTypeProperties;
- }
-
- private void mergeDataTypeProperties(DataType dataType, Map<String, PropertyDefinition> mergeProperties) {
- if (dataType != null && dataType.getProperties() != null && mergeProperties != null) {
- // Add the Other Template Properties
- mergeProperties.forEach((mappingKey, propertyDefinition) -> dataType.getProperties().put(mappingKey, propertyDefinition));
- }
- }
-
- private void populateRecipeInputs(ServiceTemplate serviceTemplate) {
- if (serviceTemplate.getTopologyTemplate() != null
- && MapUtils.isNotEmpty(serviceTemplate.getTopologyTemplate().getInputs())
- && MapUtils.isNotEmpty(this.recipeDataTypes)
- && MapUtils.isNotEmpty(serviceTemplate.getDataTypes())) {
- this.recipeDataTypes.forEach((recipeName, recipeDataType) -> {
- String dataTypePrefix = recipeName.replace("-action", "") + "-request";
- String dataTypeName = "dt-" + dataTypePrefix;
-
- serviceTemplate.getDataTypes().put(dataTypeName, recipeDataType);
-
- PropertyDefinition customInputProperty = new PropertyDefinition();
- customInputProperty.setDescription("This is Dynamic Data type for the receipe " + recipeName + ".");
- customInputProperty.setRequired(Boolean.FALSE);
- customInputProperty.setType(dataTypeName);
- serviceTemplate.getTopologyTemplate().getInputs().put(dataTypePrefix, customInputProperty);
-
- });
- }
- }
-}
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 0b42a26e..6c7b6e08 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
@@ -24,6 +24,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintEnhance
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.core.utils.BluePrintFileUtils
import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
import org.springframework.stereotype.Service
@@ -31,37 +32,42 @@ import java.util.*
@Service
open class BluePrintEnhancerServiceImpl(private val bluePrintRepoService: BluePrintRepoService,
- private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) : BluePrintEnhancerService {
+ private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService,
+ private val resourceDefinitionEnhancerService: ResourceDefinitionEnhancerService) : BluePrintEnhancerService {
private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintEnhancerServiceImpl::class.toString())
override fun enhance(basePath: String, enrichedBasePath: String): BluePrintContext {
+
// Copy the Blueprint Content to Target Location
BluePrintFileUtils.copyBluePrint(basePath, enrichedBasePath)
// Enhance the Blueprint
- val enhancedBluePrintContext = enhance(enrichedBasePath)
-
- // Delete the Old Type files
- BluePrintFileUtils.deleteBluePrintTypes(enrichedBasePath)
-
- // Write the Type File Definitions
- BluePrintFileUtils.writeBluePrintTypes(enhancedBluePrintContext)
- return enhancedBluePrintContext
+ return enhance(enrichedBasePath)
}
@Throws(BluePrintException::class)
override fun enhance(basePath: String): BluePrintContext {
+
log.info("Enhancing blueprint($basePath)")
- val blueprintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(UUID.randomUUID().toString(), basePath)
+ val blueprintRuntimeService = BluePrintMetadataUtils
+ .getBaseEnhancementBluePrintRuntime(UUID.randomUUID().toString(), basePath)
+
try {
bluePrintTypeEnhancerService.enhanceServiceTemplate(blueprintRuntimeService, "service_template",
blueprintRuntimeService.bluePrintContext().serviceTemplate)
+ // Write the Type File Definitions
+ BluePrintFileUtils.writeBluePrintTypes(blueprintRuntimeService.bluePrintContext())
+
+ // Enhance Resource Dictionary
+ enhanceResourceDefinition(blueprintRuntimeService)
+
if (blueprintRuntimeService.getBluePrintError().errors.isNotEmpty()) {
throw BluePrintException(blueprintRuntimeService.getBluePrintError().errors.toString())
}
+
} catch (e: Exception) {
log.error("failed in blueprint enhancement", e)
}
@@ -69,5 +75,10 @@ open class BluePrintEnhancerServiceImpl(private val bluePrintRepoService: BluePr
return blueprintRuntimeService.bluePrintContext()
}
+ private fun enhanceResourceDefinition(blueprintRuntimeService: BluePrintRuntimeService<*>) {
+
+ resourceDefinitionEnhancerService.enhance(blueprintRuntimeService)
+ }
+
}
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
new file mode 100644
index 00000000..ab5ca74c
--- /dev/null
+++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceDefinitionEnhancerService.kt
@@ -0,0 +1,124 @@
+/*
+ * 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.enhancer
+
+import com.att.eelf.configuration.EELFLogger
+import com.att.eelf.configuration.EELFManager
+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.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.springframework.stereotype.Service
+
+interface ResourceDefinitionEnhancerService {
+
+ @Throws(BluePrintException::class)
+ fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>)
+}
+
+@Service
+class ResourceDefinitionEnhancerServiceImpl(private val resourceDefinitionRepoService: ResourceDefinitionRepoService) :
+ ResourceDefinitionEnhancerService {
+
+ private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceDefinitionEnhancerService::class.toString())
+
+ 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
+ // 1. Get the Resource Mapping files from all NodeTemplates.
+ // 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<*>) {
+
+ val blueprintContext = bluePrintRuntimeService.bluePrintContext()
+
+ val mappingFiles = getAllResourceMappingFiles(blueprintContext)
+ log.info("resources assignment files ($mappingFiles)")
+ if (mappingFiles != null) {
+ getResourceDefinition(blueprintContext, mappingFiles)
+ }
+ }
+
+ // Get all the Mapping files from all node templates.
+ private fun getAllResourceMappingFiles(blueprintContext: BluePrintContext): List<String>? {
+
+ return blueprintContext.nodeTemplates?.mapNotNull { nodeTemplateMap ->
+
+ // Return only Mapping Artifact File Names
+ nodeTemplateMap.value.artifacts?.filter { artifactDefinitionMap ->
+ artifactDefinitionMap.value.type == ARTIFACT_TYPE_MAPPING_SOURCE
+ }?.mapNotNull { artifactDefinitionMap ->
+ artifactDefinitionMap.value.file
+ }
+
+ }?.single { it.isNotEmpty() }?.distinct()
+ }
+
+ // 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())
+ }
+
+ val distinctResourceAssignments = resourceAssignments.distinctBy { it.name }
+ generateResourceDictionaryFile(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>) {
+ val resourcekeys = resourceAssignments.mapNotNull { it.dictionaryName }.distinct()
+ 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 ->
+ getResourceDefinition(resourceKey)
+ }.map { it.name to it }.toMap()
+
+ // Recreate the Resource Definition File
+ ResourceDictionaryUtils.writeResourceDefinitionTypes(blueprintBasePath, resourceDefinitionMap)
+ log.info("resource definition file created successfully")
+ }
+
+ // Get the Resource Definition from Database
+ private fun getResourceDefinition(name: String): ResourceDefinition {
+ return resourceDefinitionRepoService.getResourceDefinition(name)
+ }
+} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.java
index 7d9c2e1a..06f2f908 100644
--- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.java
+++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.java
@@ -67,7 +67,7 @@ public class BluePrintEnhancerServiceImplTest {
Assert.assertNotNull("failed to get blueprintContext ", bluePrintContext);
// Validate the Generated BluePrints
-
- bluePrintValidatorService.validateBluePrints(targetPath);
+ Boolean valid = bluePrintValidatorService.validateBluePrints(targetPath);
+ Assert.assertTrue("blueprint validation failed ", valid);
}
} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/service/src/test/resources/logback.xml b/ms/controllerblueprints/modules/service/src/test/resources/logback.xml
index 7b7ef756..fc1f6698 100644
--- a/ms/controllerblueprints/modules/service/src/test/resources/logback.xml
+++ b/ms/controllerblueprints/modules/service/src/test/resources/logback.xml
@@ -17,7 +17,7 @@
<configuration>
- <property name="localPattern" value="%d{HH:mm:ss.SSS} %-5level %logger{100} - %msg%n" />
+ <property name="localPattern" value="[%-8thread] %d{HH:mm:ss.SSS} %-5level %logger{100} - %msg%n" />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type