\r
const val MODEL_CONTENT_TYPE_TOSCA_JSON = "TOSCA_JSON"\r
const val MODEL_CONTENT_TYPE_TEMPLATE = "TEMPLATE"\r
-\r
- const val MODEL_TYPE_DATA_TYPE_DYNAMIC = "tosca.datatypes.Dynamic"\r
-\r
- const val MODEL_TYPE_NODE_ARTIFACT = "tosca.nodes.Artifact"\r
-\r
const val CAPABILITY_PROPERTY_MAPPING = "mapping"\r
-\r
- const val PROPERTY_RECIPE_NAMES = "action-names"\r
-\r
}\r
\r
import com.fasterxml.jackson.annotation.JsonIgnore\r
import com.fasterxml.jackson.annotation.JsonProperty\r
+import com.fasterxml.jackson.annotation.JsonPropertyOrder\r
import com.fasterxml.jackson.databind.JsonNode\r
import io.swagger.annotations.ApiModelProperty\r
\r
@get:JsonIgnore\r
var id: String? = null\r
var description: String? = null\r
+ var required: Boolean? = null\r
lateinit var type: String\r
@JsonProperty("default")\r
var defaultValue: JsonNode? = null\r
var status: String? = null\r
+ var constraints: MutableList<ConstraintClause>? = null\r
@JsonProperty("entry_schema")\r
- var entrySchema: String? = null\r
+ var entrySchema: EntrySchema? = null\r
}\r
\r
/*\r
A TOSCA Service Template (YAML) document contains element definitions of building blocks for cloud application, or complete models of cloud applications. This section describes the top-level structural elements (TOSCA keynames) along with their grammars, which are allowed to appear in a TOSCA Service Template document.\r
*/\r
\r
-class ServiceTemplate {\r
+@JsonPropertyOrder(value = ["toscaDefinitionsVersion", "description", "metadata", "imports", "topologyTemplate"])\r
+class ServiceTemplate : Cloneable {\r
@get:JsonIgnore\r
var id: String? = null\r
@get:JsonProperty("tosca_definitions_version")\r
var policyTypes: MutableMap<String, PolicyType>? = null\r
@get:JsonProperty("topology_template")\r
var topologyTemplate: TopologyTemplate? = null\r
+\r
+ override public fun clone(): ServiceTemplate {\r
+ return super.clone() as ServiceTemplate\r
+ }\r
}\r
\r
class ToscaMetaData {\r
* Blueprint CBA extracted file location\r
*/\r
var rootPath = "."\r
+ /**\r
+ * Root Definition file path\r
+ */\r
+ var entryDefinition = ""\r
\r
val imports: List<ImportDefinition>? = serviceTemplate.imports\r
\r
import org.apache.commons.io.FileUtils
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.apps.controllerblueprints.core.data.ImportDefinition
+import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate
import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
import java.io.File
import java.io.FileFilter
}
}
+ fun populateDefaultImports(blueprintContext: BluePrintContext) {
+ // Get the Default Types
+ val types = arrayListOf(BluePrintConstants.PATH_DATA_TYPES, BluePrintConstants.PATH_ARTIFACT_TYPES,
+ BluePrintConstants.PATH_NODE_TYPES, BluePrintConstants.PATH_POLICY_TYPES)
+
+ // Clean Type Imports
+ cleanImportTypes(blueprintContext.serviceTemplate)
+
+ val imports = mutableListOf<ImportDefinition>()
+ types.forEach { typeName ->
+ val import = ImportDefinition()
+ import.file = BluePrintConstants.TOSCA_DEFINITIONS_DIR.plus("/$typeName.json")
+ imports.add(import)
+ }
+
+ blueprintContext.serviceTemplate.imports = imports
+ }
+
+ fun cleanImportTypes(serviceTemplate: ServiceTemplate) {
+ // Clean the Type imports
+ val toDeleteTypes = serviceTemplate.imports?.filter {
+ it.file.endsWith("_types.json")
+ }
+
+ if (toDeleteTypes != null && toDeleteTypes.isNotEmpty()) {
+ serviceTemplate.imports?.removeAll(toDeleteTypes)
+ }
+ }
+
+ fun writeEnhancedBluePrint(blueprintContext: BluePrintContext) {
+
+ // Write Blueprint Types
+ writeBluePrintTypes(blueprintContext)
+ // Re Populate the Imports
+ populateDefaultImports(blueprintContext)
+ // Rewrite the Entry Definition Files
+ writeEntryDefinitionFile(blueprintContext)
+
+ }
+
fun writeBluePrintTypes(blueprintContext: BluePrintContext) {
val basePath = blueprintContext.rootPath
}
}
+ fun writeEntryDefinitionFile(blueprintContext: BluePrintContext) {
+
+ val absoluteEntryDefinitionFile = blueprintContext.rootPath.plus(File.separator).plus(blueprintContext.entryDefinition)
+
+ val serviceTemplate = blueprintContext.serviceTemplate
+
+ // Clone the Service Template
+ val writeServiceTemplate = serviceTemplate.clone()
+ writeServiceTemplate.dataTypes = null
+ writeServiceTemplate.artifactTypes = null
+ writeServiceTemplate.policyTypes = null
+ writeServiceTemplate.nodeTypes = null
+
+ // Write the Serivice Template
+ writeDefinitionFile(absoluteEntryDefinitionFile, JacksonUtils.getJson(writeServiceTemplate, true))
+ }
+
fun writeDefinitionFile(definitionFile: String, content: String) = runBlocking {
val definitionFile = File(definitionFile)
+ // Delete the File If exists
+ Files.deleteIfExists(definitionFile.toPath())
- Files.write(definitionFile.toPath(), content.toByteArray(), StandardOpenOption.CREATE)
+ Files.write(definitionFile.toPath(), content.toByteArray(), StandardOpenOption.CREATE_NEW)
check(definitionFile.exists()) {
throw BluePrintException("couldn't write definition file under path(${definitionFile.absolutePath})")
}
import java.io.File\r
import java.nio.charset.Charset\r
\r
-object BluePrintMetadataUtils {\r
- private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())\r
+class BluePrintMetadataUtils {\r
+ companion object {\r
+ private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())\r
\r
- @JvmStatic\r
- fun toscaMetaData(basePath: String): ToscaMetaData {\r
- val toscaMetaPath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus("TOSCA-Metadata/TOSCA.meta")\r
- return toscaMetaDataFromMetaFile(toscaMetaPath)\r
- }\r
\r
- @JvmStatic\r
- fun toscaMetaDataFromMetaFile(metaFilePath: String): ToscaMetaData {\r
- val toscaMetaData = ToscaMetaData()\r
- val lines: MutableList<String> = FileUtils.readLines(File(metaFilePath), Charset.defaultCharset())\r
- lines.forEach { line ->\r
- if (line.contains(":")) {\r
- val keyValue = line.split(":")\r
- if (keyValue.size == 2) {\r
- val value: String = keyValue[1].trim()\r
- when (keyValue[0]) {\r
- "TOSCA-Meta-File-Version" -> toscaMetaData.toscaMetaFileVersion = value\r
- "CSAR-Version" -> toscaMetaData.csarVersion = value\r
- "Created-By" -> toscaMetaData.createdBy = value\r
- "Entry-Definitions" -> toscaMetaData.entityDefinitions = value\r
- "Template-Tags" -> toscaMetaData.templateTags = value\r
+ fun toscaMetaData(basePath: String): ToscaMetaData {\r
+ val toscaMetaPath = basePath.plus(BluePrintConstants.PATH_DIVIDER)\r
+ .plus(BluePrintConstants.TOSCA_METADATA_ENTRY_DEFINITION_FILE)\r
+ return toscaMetaDataFromMetaFile(toscaMetaPath)\r
+ }\r
+\r
+ fun entryDefinitionFile(basePath: String): String {\r
+ val toscaMetaPath = basePath.plus(BluePrintConstants.PATH_DIVIDER)\r
+ .plus(BluePrintConstants.TOSCA_METADATA_ENTRY_DEFINITION_FILE)\r
+ return toscaMetaDataFromMetaFile(toscaMetaPath).entityDefinitions\r
+ }\r
+\r
+ fun toscaMetaDataFromMetaFile(metaFilePath: String): ToscaMetaData {\r
+ val toscaMetaData = ToscaMetaData()\r
+ val lines: MutableList<String> = FileUtils.readLines(File(metaFilePath), Charset.defaultCharset())\r
+ lines.forEach { line ->\r
+ if (line.contains(":")) {\r
+ val keyValue = line.split(":")\r
+ if (keyValue.size == 2) {\r
+ val value: String = keyValue[1].trim()\r
+ when (keyValue[0]) {\r
+ "TOSCA-Meta-File-Version" -> toscaMetaData.toscaMetaFileVersion = value\r
+ "CSAR-Version" -> toscaMetaData.csarVersion = value\r
+ "Created-By" -> toscaMetaData.createdBy = value\r
+ "Entry-Definitions" -> toscaMetaData.entityDefinitions = value\r
+ "Template-Tags" -> toscaMetaData.templateTags = value\r
+ }\r
}\r
}\r
- }\r
\r
+ }\r
+ return toscaMetaData\r
}\r
- return toscaMetaData\r
- }\r
\r
- @JvmStatic\r
- fun getBluePrintRuntime(id: String, blueprintBasePath: String): BluePrintRuntimeService<MutableMap<String, JsonNode>> {\r
+ fun getBluePrintRuntime(id: String, blueprintBasePath: String): BluePrintRuntimeService<MutableMap<String, JsonNode>> {\r
\r
- val bluePrintContext: BluePrintContext = getBluePrintContext(blueprintBasePath)\r
+ val bluePrintContext: BluePrintContext = getBluePrintContext(blueprintBasePath)\r
\r
- val context: MutableMap<String, JsonNode> = hashMapOf()\r
- context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = blueprintBasePath.asJsonPrimitive()\r
- context[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = id.asJsonPrimitive()\r
+ val context: MutableMap<String, JsonNode> = hashMapOf()\r
+ context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = blueprintBasePath.asJsonPrimitive()\r
+ context[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = id.asJsonPrimitive()\r
\r
- val bluePrintRuntimeService = DefaultBluePrintRuntimeService(id, bluePrintContext)\r
- bluePrintRuntimeService.setExecutionContext(context)\r
+ val bluePrintRuntimeService = DefaultBluePrintRuntimeService(id, bluePrintContext)\r
+ bluePrintRuntimeService.setExecutionContext(context)\r
\r
- return bluePrintRuntimeService\r
- }\r
+ return bluePrintRuntimeService\r
+ }\r
\r
- @JvmStatic\r
- fun getBaseEnhancementBluePrintRuntime(id: String, blueprintBasePath: String): BluePrintRuntimeService<MutableMap<String, JsonNode>> {\r
+ fun getBaseEnhancementBluePrintRuntime(id: String, blueprintBasePath: String): BluePrintRuntimeService<MutableMap<String, JsonNode>> {\r
\r
- val bluePrintContext: BluePrintContext = getBaseEnhancementBluePrintContext(blueprintBasePath)\r
- val context: MutableMap<String, JsonNode> = hashMapOf()\r
- context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = blueprintBasePath.asJsonPrimitive()\r
- context[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = id.asJsonPrimitive()\r
+ val bluePrintContext: BluePrintContext = getBaseEnhancementBluePrintContext(blueprintBasePath)\r
+ val context: MutableMap<String, JsonNode> = hashMapOf()\r
+ context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = blueprintBasePath.asJsonPrimitive()\r
+ context[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = id.asJsonPrimitive()\r
\r
- val bluePrintRuntimeService = DefaultBluePrintRuntimeService(id, bluePrintContext)\r
- bluePrintRuntimeService.setExecutionContext(context)\r
+ val bluePrintRuntimeService = DefaultBluePrintRuntimeService(id, bluePrintContext)\r
+ bluePrintRuntimeService.setExecutionContext(context)\r
\r
- return bluePrintRuntimeService\r
- }\r
+ return bluePrintRuntimeService\r
+ }\r
\r
- @JvmStatic\r
- fun getBluePrintRuntime(id: String, blueprintBasePath: String, executionContext: MutableMap<String, JsonNode>): BluePrintRuntimeService<MutableMap<String, JsonNode>> {\r
- val bluePrintContext: BluePrintContext = getBluePrintContext(blueprintBasePath)\r
- val bluePrintRuntimeService = DefaultBluePrintRuntimeService(id, bluePrintContext)\r
- bluePrintRuntimeService.setExecutionContext(executionContext)\r
- return bluePrintRuntimeService\r
- }\r
+ fun getBluePrintRuntime(id: String, blueprintBasePath: String, executionContext: MutableMap<String, JsonNode>): BluePrintRuntimeService<MutableMap<String, JsonNode>> {\r
+ val bluePrintContext: BluePrintContext = getBluePrintContext(blueprintBasePath)\r
+ val bluePrintRuntimeService = DefaultBluePrintRuntimeService(id, bluePrintContext)\r
+ bluePrintRuntimeService.setExecutionContext(executionContext)\r
+ return bluePrintRuntimeService\r
+ }\r
\r
- @JvmStatic\r
- fun getBluePrintContext(blueprintBasePath: String): BluePrintContext {\r
+ fun getBluePrintContext(blueprintBasePath: String): BluePrintContext {\r
\r
- val toscaMetaData: ToscaMetaData = toscaMetaData(blueprintBasePath)\r
+ val toscaMetaData: ToscaMetaData = toscaMetaData(blueprintBasePath)\r
\r
- log.info("Processing blueprint base path ($blueprintBasePath) and entry definition file (${toscaMetaData.entityDefinitions})")\r
+ log.info("Reading blueprint path($blueprintBasePath) and entry definition file (${toscaMetaData.entityDefinitions})")\r
\r
- return readBlueprintFile(toscaMetaData.entityDefinitions, blueprintBasePath)\r
- }\r
+ return readBlueprintFile(toscaMetaData.entityDefinitions, blueprintBasePath)\r
+ }\r
\r
- fun getBaseEnhancementBluePrintContext(blueprintBasePath: String): BluePrintContext {\r
- val toscaMetaData: ToscaMetaData = toscaMetaData(blueprintBasePath)\r
- // Clean Type files\r
- BluePrintFileUtils.deleteBluePrintTypes(blueprintBasePath)\r
- val rootFilePath: String = blueprintBasePath.plus(File.separator).plus(toscaMetaData.entityDefinitions)\r
- val rootServiceTemplate = ServiceTemplateUtils.getServiceTemplate(rootFilePath)\r
+ private fun getBaseEnhancementBluePrintContext(blueprintBasePath: String): BluePrintContext {\r
+ val toscaMetaData: ToscaMetaData = toscaMetaData(blueprintBasePath)\r
+ // Clean Type files\r
+ BluePrintFileUtils.deleteBluePrintTypes(blueprintBasePath)\r
+ val rootFilePath: String = blueprintBasePath.plus(File.separator).plus(toscaMetaData.entityDefinitions)\r
+ val rootServiceTemplate = ServiceTemplateUtils.getServiceTemplate(rootFilePath)\r
\r
- // Clean the Import Definitions\r
- rootServiceTemplate.imports?.clear()\r
+ // Clean the Import Definitions\r
+ BluePrintFileUtils.cleanImportTypes(rootServiceTemplate)\r
\r
- val blueprintContext = BluePrintContext(rootServiceTemplate)\r
- blueprintContext.rootPath = blueprintBasePath\r
- return blueprintContext\r
- }\r
+ val blueprintContext = BluePrintContext(rootServiceTemplate)\r
+ blueprintContext.rootPath = blueprintBasePath\r
+ blueprintContext.entryDefinition = toscaMetaData.entityDefinitions\r
+ return blueprintContext\r
+ }\r
\r
- @JvmStatic\r
- fun readBlueprintFile(entityDefinitions: String, basePath: String): BluePrintContext {\r
- val rootFilePath: String = basePath.plus(File.separator).plus(entityDefinitions)\r
- val rootServiceTemplate = ServiceTemplateUtils.getServiceTemplate(rootFilePath)\r
- // Recursively Import Template files\r
- val schemaImportResolverUtils = BluePrintImportService(rootServiceTemplate, basePath)\r
- val completeServiceTemplate = schemaImportResolverUtils.getImportResolvedServiceTemplate()\r
- val blueprintContext = BluePrintContext(completeServiceTemplate)\r
- blueprintContext.rootPath = basePath\r
- return blueprintContext\r
+ private fun readBlueprintFile(entityDefinitions: String, basePath: String): BluePrintContext {\r
+ val rootFilePath: String = basePath.plus(File.separator).plus(entityDefinitions)\r
+ val rootServiceTemplate = ServiceTemplateUtils.getServiceTemplate(rootFilePath)\r
+ // Recursively Import Template files\r
+ val schemaImportResolverUtils = BluePrintImportService(rootServiceTemplate, basePath)\r
+ val completeServiceTemplate = schemaImportResolverUtils.getImportResolvedServiceTemplate()\r
+ val blueprintContext = BluePrintContext(completeServiceTemplate)\r
+ blueprintContext.rootPath = basePath\r
+ blueprintContext.entryDefinition = entityDefinitions\r
+ return blueprintContext\r
+ }\r
}\r
}
\ No newline at end of file
"component-resource-assignment": {
"description": "This is Resource Assignment Component API",
"version": "1.0.0",
- "properties": {
- "request-id": {
- "description": "Request Id used to store the generated configuration, in the database along with the template-name",
+ "attributes": {
+ "assignment-params": {
"required": true,
"type": "string"
}
{\r
"description": "This is Resource Assignment Component API",\r
"version": "1.0.0",\r
+ "attributes": {\r
+ "assignment-params": {\r
+ "required": true,\r
+ "type": "string"\r
+ }\r
+ },\r
"capabilities": {\r
"component-node": {\r
"type": "tosca.capabilities.Node"\r
const val PREFIX_RESOURCE_ASSIGNMENT_PROCESSOR = "resource-assignment-processor-"
const val INPUT_ARTIFACT_PREFIX_NAMES = "artifact-prefix-names"
const val OUTPUT_ASSIGNMENT_PARAMS = "assignment-params"
- const val FILE_NAME_RESOURCE_DICTIONARY_TYPES = "resources_dictionary_types.json"
+ const val FILE_NAME_RESOURCE_DEFINITION_TYPES = "resources_definition_types.json"
}
}
\ No newline at end of file
// Get the Resource Dictionary Name\r
val dictionaryFile = bluePrintRuntimeService.bluePrintContext().rootPath.plus(File.separator)\r
.plus(BluePrintConstants.TOSCA_DEFINITIONS_DIR).plus(File.separator)\r
- .plus(ResourceResolutionConstants.FILE_NAME_RESOURCE_DICTIONARY_TYPES)\r
+ .plus(ResourceResolutionConstants.FILE_NAME_RESOURCE_DEFINITION_TYPES)\r
\r
val resourceDictionaries: MutableMap<String, ResourceDefinition> = JacksonUtils.getMapFromFile(dictionaryFile, ResourceDefinition::class.java)\r
?: throw BluePrintProcessorException("couldn't get Dictionary Definitions")\r
\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
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
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
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 -> {
}
}
- 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
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
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
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
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)
}
+ 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!!)
// 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)
}
}
}
- 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
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
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()
?: 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
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
enhanceTopologyTemplateInputs(type)
enhanceTopologyTemplateNodeTemplates(type)
- enhanceTopologyTemplateWorkflowss(type)
+ enhanceTopologyTemplateWorkflows(type)
}
open fun enhanceTopologyTemplateInputs(topologyTemplate: TopologyTemplate) {
}
}
- open fun enhanceTopologyTemplateWorkflowss(topologyTemplate: TopologyTemplate) {
+ open fun enhanceTopologyTemplateWorkflows(topologyTemplate: TopologyTemplate) {
topologyTemplate.workflows?.forEach { workflowName, workflow ->
bluePrintTypeEnhancerService.enhanceWorkflow(bluePrintRuntimeService, workflowName, workflow)
}
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
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
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
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
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
\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
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
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())
--- /dev/null
+/*
+ * 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
+ }
+ }
+}
+++ /dev/null
-/*\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