diff options
author | Muthuramalingam, Brinda Santh(bs2796) <bs2796@att.com> | 2018-12-18 08:16:28 -0500 |
---|---|---|
committer | Muthuramalingam, Brinda Santh(bs2796) <bs2796@att.com> | 2018-12-18 08:16:28 -0500 |
commit | 61f774846a79bd63ad5e1f8999740b556ef49aa3 (patch) | |
tree | 4fc4a4fe4c2f7f91a8bd58e6c12703ada973dcaf /components | |
parent | 6439b4c86e4161e0c36a58e6deb2f529e64ffd28 (diff) |
Add attribute definition enhancer.
Change-Id: Ie8ac60910f04dfca477d0276aa451821cfcd8510
Issue-ID: CCSDK-718
Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
Diffstat (limited to 'components')
8 files changed, 169 insertions, 94 deletions
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/ConfigModelConstant.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/ConfigModelConstant.kt index 8bfa2db7e..5461798de 100644 --- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/ConfigModelConstant.kt +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/ConfigModelConstant.kt @@ -26,13 +26,5 @@ object ConfigModelConstant { const val MODEL_CONTENT_TYPE_TOSCA_JSON = "TOSCA_JSON"
const val MODEL_CONTENT_TYPE_TEMPLATE = "TEMPLATE"
-
- const val MODEL_TYPE_DATA_TYPE_DYNAMIC = "tosca.datatypes.Dynamic"
-
- const val MODEL_TYPE_NODE_ARTIFACT = "tosca.nodes.Artifact"
-
const val CAPABILITY_PROPERTY_MAPPING = "mapping"
-
- const val PROPERTY_RECIPE_NAMES = "action-names"
-
}
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt index 9b6fbbf19..19f09432d 100644 --- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt @@ -19,6 +19,7 @@ package org.onap.ccsdk.apps.controllerblueprints.core.data import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.annotation.JsonProperty
+import com.fasterxml.jackson.annotation.JsonPropertyOrder
import com.fasterxml.jackson.databind.JsonNode
import io.swagger.annotations.ApiModelProperty
@@ -183,12 +184,14 @@ class AttributeDefinition { @get:JsonIgnore
var id: String? = null
var description: String? = null
+ var required: Boolean? = null
lateinit var type: String
@JsonProperty("default")
var defaultValue: JsonNode? = null
var status: String? = null
+ var constraints: MutableList<ConstraintClause>? = null
@JsonProperty("entry_schema")
- var entrySchema: String? = null
+ var entrySchema: EntrySchema? = null
}
/*
@@ -579,7 +582,8 @@ class ConditionClause { 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.
*/
-class ServiceTemplate {
+@JsonPropertyOrder(value = ["toscaDefinitionsVersion", "description", "metadata", "imports", "topologyTemplate"])
+class ServiceTemplate : Cloneable {
@get:JsonIgnore
var id: String? = null
@get:JsonProperty("tosca_definitions_version")
@@ -600,6 +604,10 @@ class ServiceTemplate { var policyTypes: MutableMap<String, PolicyType>? = null
@get:JsonProperty("topology_template")
var topologyTemplate: TopologyTemplate? = null
+
+ override public fun clone(): ServiceTemplate {
+ return super.clone() as ServiceTemplate
+ }
}
class ToscaMetaData {
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt index 84af3f988..bc1f4b437 100644 --- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt @@ -36,6 +36,10 @@ class BluePrintContext(val serviceTemplate: ServiceTemplate) { * Blueprint CBA extracted file location
*/
var rootPath = "."
+ /**
+ * Root Definition file path
+ */
+ var entryDefinition = ""
val imports: List<ImportDefinition>? = serviceTemplate.imports
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintFileUtils.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintFileUtils.kt index f9ac87600..67ae39870 100644 --- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintFileUtils.kt +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintFileUtils.kt @@ -22,6 +22,8 @@ import kotlinx.coroutines.runBlocking 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 @@ -79,6 +81,46 @@ class BluePrintFileUtils { } } + 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 @@ -110,10 +152,29 @@ class BluePrintFileUtils { } } + 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})") } 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 9dbe15ef1..5b5561f64 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 @@ -31,109 +31,114 @@ import org.onap.ccsdk.apps.controllerblueprints.core.service.DefaultBluePrintRun import java.io.File
import java.nio.charset.Charset
-object BluePrintMetadataUtils {
- private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())
+class BluePrintMetadataUtils {
+ companion object {
+ private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())
- @JvmStatic
- fun toscaMetaData(basePath: String): ToscaMetaData {
- val toscaMetaPath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus("TOSCA-Metadata/TOSCA.meta")
- return toscaMetaDataFromMetaFile(toscaMetaPath)
- }
- @JvmStatic
- fun toscaMetaDataFromMetaFile(metaFilePath: String): ToscaMetaData {
- val toscaMetaData = ToscaMetaData()
- val lines: MutableList<String> = FileUtils.readLines(File(metaFilePath), Charset.defaultCharset())
- lines.forEach { line ->
- if (line.contains(":")) {
- val keyValue = line.split(":")
- if (keyValue.size == 2) {
- val value: String = keyValue[1].trim()
- when (keyValue[0]) {
- "TOSCA-Meta-File-Version" -> toscaMetaData.toscaMetaFileVersion = value
- "CSAR-Version" -> toscaMetaData.csarVersion = value
- "Created-By" -> toscaMetaData.createdBy = value
- "Entry-Definitions" -> toscaMetaData.entityDefinitions = value
- "Template-Tags" -> toscaMetaData.templateTags = value
+ fun toscaMetaData(basePath: String): ToscaMetaData {
+ val toscaMetaPath = basePath.plus(BluePrintConstants.PATH_DIVIDER)
+ .plus(BluePrintConstants.TOSCA_METADATA_ENTRY_DEFINITION_FILE)
+ return toscaMetaDataFromMetaFile(toscaMetaPath)
+ }
+
+ fun entryDefinitionFile(basePath: String): String {
+ val toscaMetaPath = basePath.plus(BluePrintConstants.PATH_DIVIDER)
+ .plus(BluePrintConstants.TOSCA_METADATA_ENTRY_DEFINITION_FILE)
+ return toscaMetaDataFromMetaFile(toscaMetaPath).entityDefinitions
+ }
+
+ fun toscaMetaDataFromMetaFile(metaFilePath: String): ToscaMetaData {
+ val toscaMetaData = ToscaMetaData()
+ val lines: MutableList<String> = FileUtils.readLines(File(metaFilePath), Charset.defaultCharset())
+ lines.forEach { line ->
+ if (line.contains(":")) {
+ val keyValue = line.split(":")
+ if (keyValue.size == 2) {
+ val value: String = keyValue[1].trim()
+ when (keyValue[0]) {
+ "TOSCA-Meta-File-Version" -> toscaMetaData.toscaMetaFileVersion = value
+ "CSAR-Version" -> toscaMetaData.csarVersion = value
+ "Created-By" -> toscaMetaData.createdBy = value
+ "Entry-Definitions" -> toscaMetaData.entityDefinitions = value
+ "Template-Tags" -> toscaMetaData.templateTags = value
+ }
}
}
- }
+ }
+ return toscaMetaData
}
- return toscaMetaData
- }
- @JvmStatic
- fun getBluePrintRuntime(id: String, blueprintBasePath: String): BluePrintRuntimeService<MutableMap<String, JsonNode>> {
+ fun getBluePrintRuntime(id: String, blueprintBasePath: String): BluePrintRuntimeService<MutableMap<String, JsonNode>> {
- val bluePrintContext: BluePrintContext = getBluePrintContext(blueprintBasePath)
+ val bluePrintContext: BluePrintContext = getBluePrintContext(blueprintBasePath)
- val context: MutableMap<String, JsonNode> = hashMapOf()
- context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = blueprintBasePath.asJsonPrimitive()
- context[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = id.asJsonPrimitive()
+ val context: MutableMap<String, JsonNode> = hashMapOf()
+ context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = blueprintBasePath.asJsonPrimitive()
+ context[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = id.asJsonPrimitive()
- val bluePrintRuntimeService = DefaultBluePrintRuntimeService(id, bluePrintContext)
- bluePrintRuntimeService.setExecutionContext(context)
+ val bluePrintRuntimeService = DefaultBluePrintRuntimeService(id, bluePrintContext)
+ bluePrintRuntimeService.setExecutionContext(context)
- return bluePrintRuntimeService
- }
+ return bluePrintRuntimeService
+ }
- @JvmStatic
- fun getBaseEnhancementBluePrintRuntime(id: String, blueprintBasePath: String): BluePrintRuntimeService<MutableMap<String, JsonNode>> {
+ 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()
+ 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()
- val bluePrintRuntimeService = DefaultBluePrintRuntimeService(id, bluePrintContext)
- bluePrintRuntimeService.setExecutionContext(context)
+ val bluePrintRuntimeService = DefaultBluePrintRuntimeService(id, bluePrintContext)
+ bluePrintRuntimeService.setExecutionContext(context)
- return bluePrintRuntimeService
- }
+ return bluePrintRuntimeService
+ }
- @JvmStatic
- fun getBluePrintRuntime(id: String, blueprintBasePath: String, executionContext: MutableMap<String, JsonNode>): BluePrintRuntimeService<MutableMap<String, JsonNode>> {
- val bluePrintContext: BluePrintContext = getBluePrintContext(blueprintBasePath)
- val bluePrintRuntimeService = DefaultBluePrintRuntimeService(id, bluePrintContext)
- bluePrintRuntimeService.setExecutionContext(executionContext)
- return bluePrintRuntimeService
- }
+ fun getBluePrintRuntime(id: String, blueprintBasePath: String, executionContext: MutableMap<String, JsonNode>): BluePrintRuntimeService<MutableMap<String, JsonNode>> {
+ val bluePrintContext: BluePrintContext = getBluePrintContext(blueprintBasePath)
+ val bluePrintRuntimeService = DefaultBluePrintRuntimeService(id, bluePrintContext)
+ bluePrintRuntimeService.setExecutionContext(executionContext)
+ return bluePrintRuntimeService
+ }
- @JvmStatic
- fun getBluePrintContext(blueprintBasePath: String): BluePrintContext {
+ fun getBluePrintContext(blueprintBasePath: String): BluePrintContext {
- val toscaMetaData: ToscaMetaData = toscaMetaData(blueprintBasePath)
+ val toscaMetaData: ToscaMetaData = toscaMetaData(blueprintBasePath)
- log.info("Processing blueprint base path ($blueprintBasePath) and entry definition file (${toscaMetaData.entityDefinitions})")
+ log.info("Reading blueprint path($blueprintBasePath) and entry definition file (${toscaMetaData.entityDefinitions})")
- return readBlueprintFile(toscaMetaData.entityDefinitions, blueprintBasePath)
- }
+ 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)
+ private 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()
+ // Clean the Import Definitions
+ BluePrintFileUtils.cleanImportTypes(rootServiceTemplate)
- val blueprintContext = BluePrintContext(rootServiceTemplate)
- blueprintContext.rootPath = blueprintBasePath
- return blueprintContext
- }
+ val blueprintContext = BluePrintContext(rootServiceTemplate)
+ blueprintContext.rootPath = blueprintBasePath
+ blueprintContext.entryDefinition = toscaMetaData.entityDefinitions
+ return blueprintContext
+ }
- @JvmStatic
- fun readBlueprintFile(entityDefinitions: String, basePath: String): BluePrintContext {
- val rootFilePath: String = basePath.plus(File.separator).plus(entityDefinitions)
- val rootServiceTemplate = ServiceTemplateUtils.getServiceTemplate(rootFilePath)
- // Recursively Import Template files
- val schemaImportResolverUtils = BluePrintImportService(rootServiceTemplate, basePath)
- val completeServiceTemplate = schemaImportResolverUtils.getImportResolvedServiceTemplate()
- val blueprintContext = BluePrintContext(completeServiceTemplate)
- blueprintContext.rootPath = basePath
- return blueprintContext
+ private fun readBlueprintFile(entityDefinitions: String, basePath: String): BluePrintContext {
+ val rootFilePath: String = basePath.plus(File.separator).plus(entityDefinitions)
+ val rootServiceTemplate = ServiceTemplateUtils.getServiceTemplate(rootFilePath)
+ // Recursively Import Template files
+ val schemaImportResolverUtils = BluePrintImportService(rootServiceTemplate, basePath)
+ val completeServiceTemplate = schemaImportResolverUtils.getImportResolvedServiceTemplate()
+ val blueprintContext = BluePrintContext(completeServiceTemplate)
+ blueprintContext.rootPath = basePath
+ blueprintContext.entryDefinition = entityDefinitions
+ return blueprintContext
+ }
}
}
\ No newline at end of file diff --git a/components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration/Definitions/node_types.json b/components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration/Definitions/node_types.json index 7330663c4..6a156ff16 100644 --- a/components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration/Definitions/node_types.json +++ b/components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration/Definitions/node_types.json @@ -37,9 +37,8 @@ "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" } diff --git a/components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration/Definitions/resources_dictionary_types.json b/components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration/Definitions/resources_definition_types.json index 557f6efce..557f6efce 100644 --- a/components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration/Definitions/resources_dictionary_types.json +++ b/components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration/Definitions/resources_definition_types.json diff --git a/components/model-catalog/definition-type/starter-type/node_type/component-resource-assignment.json b/components/model-catalog/definition-type/starter-type/node_type/component-resource-assignment.json index 51d70ede9..38fc97d70 100644 --- a/components/model-catalog/definition-type/starter-type/node_type/component-resource-assignment.json +++ b/components/model-catalog/definition-type/starter-type/node_type/component-resource-assignment.json @@ -1,6 +1,12 @@ {
"description": "This is Resource Assignment Component API",
"version": "1.0.0",
+ "attributes": {
+ "assignment-params": {
+ "required": true,
+ "type": "string"
+ }
+ },
"capabilities": {
"component-node": {
"type": "tosca.capabilities.Node"
|