diff options
Diffstat (limited to 'components/core/src/main')
7 files changed, 89 insertions, 90 deletions
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt index fd6a8db1..102e2ebd 100644 --- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt @@ -45,17 +45,13 @@ object BluePrintConstants { const val USER_SYSTEM: String = "System"
- const val MODEL_CONTENT_TYPE_JSON: String = "JSON"
- const val MODEL_CONTENT_TYPE_YAML: String = "YAML"
- const val MODEL_CONTENT_TYPE_YANG: String = "YANG"
- const val MODEL_CONTENT_TYPE_SCHEMA: String = "SCHEMA"
-
const val PATH_DIVIDER: String = "/"
const val PATH_SERVICE_TEMPLATE: String = "service_template"
const val PATH_TOPOLOGY_TEMPLATE: String = "topology_template"
const val PATH_METADATA: String = "metadata"
const val PATH_NODE_TYPES: String = "node_types"
const val PATH_POLICY_TYPES: String = "policy_types"
+ const val PATH_RELATIONSHIP_TYPES: String = "relationship_types"
const val PATH_ARTIFACT_TYPES: String = "artifact_types"
const val PATH_DATA_TYPES: String = "data_types"
const val PATH_INPUTS: String = "inputs"
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 19f09432..9767b2e1 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 @@ -598,6 +598,8 @@ class ServiceTemplate : Cloneable { var artifactTypes: MutableMap<String, ArtifactType>? = null
@get:JsonProperty("data_types")
var dataTypes: MutableMap<String, DataType>? = null
+ @get:JsonProperty("relationship_types")
+ var relationshipTypes: MutableMap<String, RelationshipType>? = null
@get:JsonProperty("node_types")
var nodeTypes: MutableMap<String, NodeType>? = null
@get:JsonProperty("policy_types")
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionService.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionService.kt index 6a50680e..8caec75f 100644 --- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionService.kt +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionService.kt @@ -16,15 +16,15 @@ package org.onap.ccsdk.apps.controllerblueprints.core.service
+import com.att.eelf.configuration.EELFLogger
+import com.att.eelf.configuration.EELFManager
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.node.ArrayNode
import com.fasterxml.jackson.databind.node.ObjectNode
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes
import org.onap.ccsdk.apps.controllerblueprints.core.data.*
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
-import com.att.eelf.configuration.EELFLogger
-import com.att.eelf.configuration.EELFManager
/**
*
@@ -35,12 +35,6 @@ object BluePrintExpressionService { val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())
@JvmStatic
- fun getExpressionData(propertyAssignment: Any): ExpressionData {
- val propertyAssignmentNode: JsonNode = JacksonUtils.jsonNodeFromObject(propertyAssignment)
- return getExpressionData(propertyAssignmentNode)
- }
-
- @JvmStatic
fun getExpressionData(propertyAssignmentNode: JsonNode): ExpressionData {
log.trace("Assignment Data/Expression : {}", propertyAssignmentNode)
val expressionData = ExpressionData(valueNode = propertyAssignmentNode)
@@ -53,19 +47,19 @@ object BluePrintExpressionService { expressionData.expressionNode = propertyAssignmentNode
when (expressionData.command) {
- org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_INPUT -> {
+ BluePrintConstants.EXPRESSION_GET_INPUT -> {
expressionData.inputExpression = populateInputExpression(propertyAssignmentNode)
}
- org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_ATTRIBUTE -> {
+ BluePrintConstants.EXPRESSION_GET_ATTRIBUTE -> {
expressionData.attributeExpression = populateAttributeExpression(propertyAssignmentNode)
}
- org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_PROPERTY -> {
+ BluePrintConstants.EXPRESSION_GET_PROPERTY -> {
expressionData.propertyExpression = populatePropertyExpression(propertyAssignmentNode)
}
- org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_OPERATION_OUTPUT -> {
+ BluePrintConstants.EXPRESSION_GET_OPERATION_OUTPUT -> {
expressionData.operationOutputExpression = populateOperationOutputExpression(propertyAssignmentNode)
}
- org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_ARTIFACT -> {
+ BluePrintConstants.EXPRESSION_GET_ARTIFACT -> {
expressionData.artifactExpression = populateArtifactExpression(propertyAssignmentNode)
}
}
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintImportService.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintImportService.kt index fce06f3f..26eb19de 100644 --- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintImportService.kt +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintImportService.kt @@ -28,11 +28,13 @@ import java.net.URLDecoder import java.nio.charset.Charset class BluePrintImportService(private val parentServiceTemplate: ServiceTemplate, private val blueprintBasePath: String) { + companion object { + private const val PARENT_SERVICE_TEMPLATE: String = "parent" + } private val log: Logger = LoggerFactory.getLogger(this::class.toString()) - val PARENT_SERVICE_TEMPLATE: String = "parent" - var importServiceTemplateMap: MutableMap<String, ServiceTemplate> = hashMapOf() + private var importServiceTemplateMap: MutableMap<String, ServiceTemplate> = hashMapOf() fun getImportResolvedServiceTemplate(): ServiceTemplate { diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt index 5540047c..bd19ae47 100644 --- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt @@ -67,6 +67,12 @@ interface BluePrintRuntimeService<T> { */
fun resolveNodeTemplateProperties(nodeTemplateName: String): MutableMap<String, JsonNode>
+ fun resolveNodeTemplateCapabilityProperties(nodeTemplateName: String, capability: String): MutableMap<String,
+ JsonNode>
+
+ fun resolveNodeTemplateRequirementProperties(nodeTemplateName: String, requirementName: String): MutableMap<String,
+ JsonNode>
+
fun resolveNodeTemplateInterfaceOperationInputs(nodeTemplateName: String, interfaceName: String, operationName: String): MutableMap<String, JsonNode>
fun resolveNodeTemplateInterfaceOperationOutputs(nodeTemplateName: String, interfaceName: String, operationName: String): MutableMap<String, JsonNode>
@@ -193,17 +199,15 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl val nodeTemplate: NodeTemplate = bluePrintContext.nodeTemplateByName(nodeTemplateName)
- val propertyAssignments: MutableMap<String, JsonNode> =
- nodeTemplate.properties as MutableMap<String, JsonNode>
+ val propertyAssignments: MutableMap<String, JsonNode> = nodeTemplate.properties!!
// Get the Node Type Definitions
- val nodeTypeProperties: MutableMap<String, PropertyDefinition> =
- bluePrintContext.nodeTypeChainedProperties(nodeTemplate.type)!!
+ val nodeTypeProperties: MutableMap<String, PropertyDefinition> = bluePrintContext.nodeTypeChainedProperties(nodeTemplate.type)!!
// Iterate Node Type Properties
nodeTypeProperties.forEach { nodeTypePropertyName, nodeTypeProperty ->
// Get the Express or Value for the Node Template
- val propertyAssignment: Any? = propertyAssignments[nodeTypePropertyName]
+ val propertyAssignment: JsonNode? = propertyAssignments[nodeTypePropertyName]
var resolvedValue: JsonNode = NullNode.getInstance()
if (propertyAssignment != null) {
@@ -223,6 +227,18 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl return propertyAssignmentValue
}
+ override fun resolveNodeTemplateCapabilityProperties(nodeTemplateName: String, capabilityName: String):
+ MutableMap<String, JsonNode> {
+ log.info("resolveNodeTemplateCapabilityProperties for node template($nodeTemplateName) capability " +
+ "($capabilityName)")
+ TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ }
+
+ override fun resolveNodeTemplateRequirementProperties(nodeTemplateName: String, requirementName: String): MutableMap<String, JsonNode> {
+ log.info("resolveNodeTemplateRequirementProperties for node template($nodeTemplateName) requirement ($requirementName)")
+ TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ }
+
override fun resolveNodeTemplateInterfaceOperationInputs(nodeTemplateName: String,
interfaceName: String, operationName: String): MutableMap<String, JsonNode> {
log.info("resolveNodeTemplateInterfaceOperationInputs for node template ({}),interface name ({}), " +
@@ -230,8 +246,8 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl val propertyAssignmentValue: MutableMap<String, JsonNode> = hashMapOf()
- val propertyAssignments: MutableMap<String, Any> =
- bluePrintContext.nodeTemplateInterfaceOperationInputs(nodeTemplateName, interfaceName, operationName) as? MutableMap<String, Any>
+ val propertyAssignments: MutableMap<String, JsonNode> =
+ bluePrintContext.nodeTemplateInterfaceOperationInputs(nodeTemplateName, interfaceName, operationName)
?: hashMapOf()
val nodeTypeName = bluePrintContext.nodeTemplateByName(nodeTemplateName).type
@@ -245,7 +261,7 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl // Iterate Node Type Properties
nodeTypeInterfaceOperationInputs.forEach { nodeTypePropertyName, nodeTypeProperty ->
// Get the Express or Value for the Node Template
- val propertyAssignment: Any? = propertyAssignments[nodeTypePropertyName]
+ val propertyAssignment: JsonNode? = propertyAssignments[nodeTypePropertyName]
var resolvedValue: JsonNode = NullNode.getInstance()
if (propertyAssignment != null) {
@@ -275,8 +291,8 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl val propertyAssignmentValue: MutableMap<String, JsonNode> = hashMapOf()
- val propertyAssignments: MutableMap<String, Any> =
- bluePrintContext.nodeTemplateInterfaceOperationOutputs(nodeTemplateName, interfaceName, operationName) as? MutableMap<String, Any>
+ val propertyAssignments: MutableMap<String, JsonNode> =
+ bluePrintContext.nodeTemplateInterfaceOperationOutputs(nodeTemplateName, interfaceName, operationName)
?: hashMapOf()
val nodeTypeName = bluePrintContext.nodeTemplateByName(nodeTemplateName).type
@@ -289,7 +305,7 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl nodeTypeInterfaceOperationOutputs.forEach { nodeTypePropertyName, nodeTypeProperty ->
// Get the Express or Value for the Node Template
- val propertyAssignment: Any? = propertyAssignments[nodeTypePropertyName]
+ val propertyAssignment: JsonNode? = propertyAssignments[nodeTypePropertyName]
var resolvedValue: JsonNode = NullNode.getInstance()
if (propertyAssignment != null) {
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt index 36c141f5..17380fc0 100644 --- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt @@ -47,7 +47,7 @@ If Property Assignment is Expression. */
fun resolveAssignmentExpression(nodeTemplateName: String, assignmentName: String,
- assignment: Any): JsonNode {
+ assignment: JsonNode): JsonNode {
val valueNode: JsonNode
log.trace("Assignment ({})", assignment)
val expressionData = BluePrintExpressionService.getExpressionData(assignment)
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 18896f51..5a10e43f 100755 --- 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 @@ -33,12 +33,6 @@ import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths import java.nio.file.StandardOpenOption -import java.text.MessageFormat -import java.time.Instant -import java.time.temporal.ChronoUnit -import java.time.ZoneId -import java.time.format.DateTimeFormatter - class BluePrintFileUtils { @@ -56,8 +50,9 @@ class BluePrintFileUtils { val metaDataDir = File(blueprintDir.absolutePath.plus(File.separator).plus(BluePrintConstants.TOSCA_METADATA_DIR)) Files.createDirectories(metaDataDir.toPath()) - val metafile = File(blueprintDir.absolutePath.plus(File.separator).plus(BluePrintConstants.TOSCA_METADATA_ENTRY_DEFINITION_FILE)) - Files.write(metafile.toPath(), getMetaDataContent().toByteArray(), StandardOpenOption.CREATE_NEW) + val metaFile = File(blueprintDir.absolutePath.plus(File.separator).plus(BluePrintConstants + .TOSCA_METADATA_ENTRY_DEFINITION_FILE)) + Files.write(metaFile.toPath(), getMetaDataContent().toByteArray(), StandardOpenOption.CREATE_NEW) val definitionsDir = File(blueprintDir.absolutePath.plus(File.separator).plus(BluePrintConstants.TOSCA_DEFINITIONS_DIR)) Files.createDirectories(definitionsDir.toPath()) @@ -92,35 +87,6 @@ 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 @@ -147,6 +113,11 @@ class BluePrintFileUtils { writeTypeFile(definitionDir.absolutePath, BluePrintConstants.PATH_DATA_TYPES, dataTypesContent) } + blueprintContext.serviceTemplate.relationshipTypes?.let { + val nodeTypesContent = JacksonUtils.getWrappedJson(BluePrintConstants.PATH_RELATIONSHIP_TYPES, it.toSortedMap(), true) + writeTypeFile(definitionDir.absolutePath, BluePrintConstants.PATH_RELATIONSHIP_TYPES, nodeTypesContent) + } + blueprintContext.serviceTemplate.artifactTypes?.let { val artifactTypesContent = JacksonUtils.getWrappedJson(BluePrintConstants.PATH_ARTIFACT_TYPES, it.toSortedMap(), true) writeTypeFile(definitionDir.absolutePath, BluePrintConstants.PATH_ARTIFACT_TYPES, artifactTypesContent) @@ -163,7 +134,40 @@ class BluePrintFileUtils { } } - fun writeEntryDefinitionFile(blueprintContext: BluePrintContext) { + private fun populateDefaultImports(blueprintContext: BluePrintContext) { + // Get the Default Types + val types = arrayListOf(BluePrintConstants.PATH_DATA_TYPES, BluePrintConstants.PATH_RELATIONSHIP_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) + } + } + + /** + * Re Generate the Blueprint Service Template Definition file based on BluePrint Context. + */ + private fun writeEntryDefinitionFile(blueprintContext: BluePrintContext) { val absoluteEntryDefinitionFile = blueprintContext.rootPath.plus(File.separator).plus(blueprintContext.entryDefinition) @@ -174,14 +178,15 @@ class BluePrintFileUtils { writeServiceTemplate.dataTypes = null writeServiceTemplate.artifactTypes = null writeServiceTemplate.policyTypes = null + writeServiceTemplate.relationshipTypes = null writeServiceTemplate.nodeTypes = null - // Write the Serivice Template + // Write the Service Template writeDefinitionFile(absoluteEntryDefinitionFile, JacksonUtils.getJson(writeServiceTemplate, true)) } - fun writeDefinitionFile(definitionFile: String, content: String) = runBlocking { - val definitionFile = File(definitionFile) + fun writeDefinitionFile(definitionFileName: String, content: String) = runBlocking { + val definitionFile = File(definitionFileName) // Delete the File If exists Files.deleteIfExists(definitionFile.toPath()) @@ -207,22 +212,6 @@ class BluePrintFileUtils { "\nEntry-Definitions: Definitions/<BLUEPRINT_NAME>.json" + "\nTemplate-Tags: <TAGS>" } - - fun getBluePrintFile(fileName: String, targetPath: Path) : File { - val filePath = targetPath.resolve(fileName).toString() - val file = File(filePath) - check(file.exists()) { - throw BluePrintException("couldn't get definition file under path(${file.absolutePath})") - } - return file - } - - fun getCBAGeneratedFileName(fileName: String, prefix: String): String { - val DATE_FORMAT = "yyyyMMddHHmmss" - val formatter = DateTimeFormatter.ofPattern(DATE_FORMAT) - val datePrefix = Instant.now().atZone(ZoneId.systemDefault()).toLocalDateTime().format(formatter) - return MessageFormat.format(prefix, datePrefix, fileName) - } fun getCbaStorageDirectory(path: String): Path { check(StringUtils.isNotBlank(path)) { |