aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>2019-02-20 11:34:23 -0500
committerMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>2019-02-22 18:02:51 -0500
commit39800c759802dd011b8ca0d9508c37df6772d869 (patch)
tree2aca67047fca354af201cbfcbba78e0183ca3e49
parent5ce12a24482427f09cfdfc580fb4b59a6d86f5c2 (diff)
Add dsl model definition
Change-Id: Ic2332e32d142f231cc8a3a25e2528cde455da827 Issue-ID: CCSDK-1095 Signed-off-by: Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com> Signed-off-by: Balazinski <bartosz.balazinski@ibm.com>
-rw-r--r--components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Definitions/activation-blueprint.json9
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt1
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt6
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctions.kt21
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintExpressionData.kt7
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt6
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt7
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionService.kt24
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt48
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt3
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt23
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionServiceTest.kt50
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt14
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtilsTest.kt24
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/test/resources/environments/Environments/environment1.properties2
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/test/resources/environments/Environments/environment2.properties2
16 files changed, 211 insertions, 36 deletions
diff --git a/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Definitions/activation-blueprint.json b/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Definitions/activation-blueprint.json
index c21f4c9d..138260fe 100644
--- a/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Definitions/activation-blueprint.json
+++ b/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Definitions/activation-blueprint.json
@@ -24,6 +24,15 @@
"file": "Definitions/policy_types.json"
}
],
+ "dsl_definitions" : {
+ "dynamic-rest-source": {
+ "type" : "basic-type",
+ "url" : "http://localhost:8080",
+ "userId" : {
+ "get_input": "rest-user-name"
+ }
+ }
+ },
"topology_template": {
"inputs": {
"request-id": {
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt
index d89e9547..2c2e67dc 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt
@@ -132,6 +132,7 @@ object BluePrintConstants {
const val MODEL_TYPE_CAPABILITY_TYPE_SSH = "tosca.capabilities.Ssh"
const val MODEL_TYPE_CAPABILITY_TYPE_SFTP = "tosca.capabilities.Sftp"
+ const val EXPRESSION_DSL_REFERENCE: String = "*"
const val EXPRESSION_GET_INPUT: String = "get_input"
const val EXPRESSION_GET_ATTRIBUTE: String = "get_attribute"
const val EXPRESSION_GET_ARTIFACT: String = "get_artifact"
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt
index 0889fddc..b2f1b727 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt
@@ -32,7 +32,6 @@ object BluePrintTypes {
BluePrintConstants.MODEL_TYPE_NODE_DG,
BluePrintConstants.MODEL_TYPE_NODE_COMPONENT,
BluePrintConstants.MODEL_TYPE_NODE_VNF,
- BluePrintConstants.MODEL_TYPE_NODE_ARTIFACT,
BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE,
BluePrintConstants.MODEL_TYPE_NODES_COMPONENT_JAVA,
BluePrintConstants.MODEL_TYPE_NODES_COMPONENT_BUNDLE,
@@ -54,7 +53,6 @@ object BluePrintTypes {
BluePrintConstants.MODEL_TYPE_DATA_TYPE_DYNAMIC
)
- @Deprecated("This has to move to Relationship Types Model Drive")
@JvmStatic
val validRelationShipDerivedFroms: MutableList<String> = arrayListOf(
BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_ROOT,
@@ -65,7 +63,6 @@ object BluePrintTypes {
BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_ROUTES_TO
)
- @Deprecated("This has to move to Capability Types Model Drive")
@JvmStatic
val validCapabilityTypes: MutableList<String> = arrayListOf(
BluePrintConstants.MODEL_TYPE_CAPABILITIES_ROOT,
@@ -144,7 +141,8 @@ object BluePrintTypes {
@JvmStatic
fun validCommands(): List<String> {
- return listOf(BluePrintConstants.EXPRESSION_GET_INPUT,
+ return listOf(BluePrintConstants.EXPRESSION_DSL_REFERENCE,
+ BluePrintConstants.EXPRESSION_GET_INPUT,
BluePrintConstants.EXPRESSION_GET_ATTRIBUTE,
BluePrintConstants.EXPRESSION_GET_PROPERTY,
BluePrintConstants.EXPRESSION_GET_ARTIFACT,
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctions.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctions.kt
index 0b9c142b..7d98c42d 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctions.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctions.kt
@@ -17,10 +17,7 @@
package org.onap.ccsdk.apps.controllerblueprints.core
import com.fasterxml.jackson.databind.JsonNode
-import com.fasterxml.jackson.databind.node.BooleanNode
-import com.fasterxml.jackson.databind.node.DoubleNode
-import com.fasterxml.jackson.databind.node.IntNode
-import com.fasterxml.jackson.databind.node.TextNode
+import com.fasterxml.jackson.databind.node.*
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
import org.slf4j.helpers.MessageFormatter
import java.io.File
@@ -76,6 +73,22 @@ fun <T : Any> MutableMap<String, *>.castValue(key: String, valueType: KClass<T>)
}
}
+/**
+ * Convert Json to map of json node, the root fields will be map keys
+ */
+fun JsonNode.rootFieldsToMap(): MutableMap<String, JsonNode> {
+ if (this is ObjectNode) {
+ val propertyMap: MutableMap<String, JsonNode> = hashMapOf()
+ this.fields().forEach {
+ propertyMap[it.key] = it.value
+ }
+ return propertyMap
+ } else {
+ throw BluePrintException("json node should be Object Node Type")
+ }
+}
+
+
fun MutableMap<String, JsonNode>.putJsonElement(key: String, value: Any) {
when (value) {
is JsonNode ->
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintExpressionData.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintExpressionData.kt
index 96f549db..6a8df801 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintExpressionData.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintExpressionData.kt
@@ -1,5 +1,6 @@
/*
* 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.
@@ -13,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+@file:Suppress("unused")
package org.onap.ccsdk.apps.controllerblueprints.core.data
@@ -27,6 +29,7 @@ data class ExpressionData(
var isExpression: Boolean = false,
var valueNode: JsonNode,
var expressionNode: ObjectNode? = null,
+ var dslExpression: DSLExpression? = null,
var inputExpression: InputExpression? = null,
var propertyExpression: PropertyExpression? = null,
var attributeExpression: AttributeExpression? = null,
@@ -67,4 +70,8 @@ data class OperationOutputExpression(
val propertyName: String
)
+data class DSLExpression(
+ val propertyName: String
+)
+
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt
index c4376d5e..2647083f 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+@file:Suppress("unused")
package org.onap.ccsdk.apps.controllerblueprints.core.data
@@ -582,7 +583,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.
*/
-@JsonPropertyOrder(value = ["toscaDefinitionsVersion", "description", "metadata", "imports", "topologyTemplate"])
+@JsonPropertyOrder(value = ["toscaDefinitionsVersion", "description", "metadata", "imports", "dsl_definitions",
+ "topologyTemplate"])
class ServiceTemplate : Cloneable {
@get:JsonIgnore
var id: String? = null
@@ -591,7 +593,7 @@ class ServiceTemplate : Cloneable {
var metadata: MutableMap<String, String>? = null
var description: String? = null
@get:JsonProperty("dsl_definitions")
- var dslDefinitions: MutableMap<String, Any>? = null
+ var dslDefinitions: MutableMap<String, JsonNode>? = null
var repositories: MutableMap<String, RepositoryDefinition>? = null
var imports: MutableList<ImportDefinition>? = null
@get:JsonProperty("artifact_types")
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt
index a0bf054b..e2211f7e 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt
@@ -1,5 +1,6 @@
/*
* 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.
@@ -45,6 +46,8 @@ class BluePrintContext(val serviceTemplate: ServiceTemplate) {
val imports: List<ImportDefinition>? = serviceTemplate.imports
+ val dslDefinitions = serviceTemplate.dslDefinitions
+
val metadata: MutableMap<String, String>? = serviceTemplate.metadata
val dataTypes: MutableMap<String, DataType>? = serviceTemplate.dataTypes
@@ -95,6 +98,10 @@ class BluePrintContext(val serviceTemplate: ServiceTemplate) {
?: throw BluePrintException("could't get first callOperation for WorkFlow($workFlowName) ")
}
+ // DSL
+ fun dslPropertiesByName(name: String): JsonNode = dslDefinitions?.get(name)
+ ?: throw BluePrintException("could't get policy type for the dsl($name)")
+
// Data Type
fun dataTypeByName(name: String): DataType? = dataTypes?.get(name)
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionService.kt
index caa02dbc..f23659ce 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionService.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionService.kt
@@ -1,5 +1,6 @@
/*
* 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.
@@ -21,6 +22,7 @@ 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 com.fasterxml.jackson.databind.node.TextNode
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes
@@ -35,11 +37,20 @@ object BluePrintExpressionService {
val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())
@JvmStatic
+ fun checkContainsExpression(propertyAssignmentNode: JsonNode): Boolean {
+ val json = propertyAssignmentNode.toString()
+ // FIXME("Check if any Optimisation needed")
+ return (json.contains(BluePrintConstants.EXPRESSION_GET_INPUT)
+ || json.contains(BluePrintConstants.EXPRESSION_GET_ATTRIBUTE)
+ || json.contains(BluePrintConstants.EXPRESSION_GET_PROPERTY))
+
+ }
+
+ @JvmStatic
fun getExpressionData(propertyAssignmentNode: JsonNode): ExpressionData {
log.trace("Assignment Data/Expression : {}", propertyAssignmentNode)
val expressionData = ExpressionData(valueNode = propertyAssignmentNode)
if (propertyAssignmentNode is ObjectNode) {
-
val commands: Set<String> = propertyAssignmentNode.fieldNames().asSequence().toList().intersect(BluePrintTypes.validCommands())
if (commands.isNotEmpty()) {
expressionData.isExpression = true
@@ -64,11 +75,22 @@ object BluePrintExpressionService {
}
}
}
+ } else if (propertyAssignmentNode is TextNode
+ && propertyAssignmentNode.textValue().startsWith(BluePrintConstants.EXPRESSION_DSL_REFERENCE)) {
+ expressionData.isExpression = true
+ expressionData.command = BluePrintConstants.EXPRESSION_DSL_REFERENCE
+ expressionData.dslExpression = populateDSLExpression(propertyAssignmentNode)
}
return expressionData
}
@JvmStatic
+ fun populateDSLExpression(jsonNode: TextNode): DSLExpression {
+ return DSLExpression(propertyName = jsonNode.textValue()
+ .removePrefix(BluePrintConstants.EXPRESSION_DSL_REFERENCE))
+ }
+
+ @JvmStatic
fun populateInputExpression(jsonNode: JsonNode): InputExpression {
return InputExpression(propertyName = jsonNode.first().textValue())
}
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt
index 5c10f80c..f8ac5d61 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt
@@ -24,13 +24,13 @@ import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.node.NullNode
import com.fasterxml.jackson.databind.node.ObjectNode
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.apps.controllerblueprints.core.*
import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactDefinition
import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate
import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
+import java.io.File
interface BluePrintRuntimeService<T> {
@@ -62,6 +62,8 @@ interface BluePrintRuntimeService<T> {
fun setBluePrintError(bluePrintError: BluePrintError)
+ fun loadEnvironments(fileName: String)
+
fun resolveNodeTemplatePropertyAssignments(nodeTemplateName: String,
propertyDefinitions: MutableMap<String, PropertyDefinition>,
propertyAssignments: MutableMap<String, JsonNode>): MutableMap<String, JsonNode>
@@ -81,6 +83,8 @@ interface BluePrintRuntimeService<T> {
fun resolveNodeTemplateArtifactDefinition(nodeTemplateName: String, artifactName: String): ArtifactDefinition
+ fun resolveDSLExpression(dslPropertyName: String): JsonNode
+
fun setInputValue(propertyName: String, propertyDefinition: PropertyDefinition, value: JsonNode)
fun setWorkflowInputValue(workflowName: String, propertyName: String, propertyDefinition: PropertyDefinition, value: JsonNode)
@@ -129,6 +133,16 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl
private var bluePrintError = BluePrintError()
+ init {
+ /**
+ * Load Default Environments Properties
+ */
+ val absoluteEnvFilePath = bluePrintContext.rootPath.plus(File.separator)
+ .plus(BluePrintConstants.TOSCA_ENVIRONMENTS_DIR)
+ loadEnvironments(absoluteEnvFilePath)
+
+ }
+
override fun id(): String {
return id
}
@@ -190,6 +204,12 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl
this.bluePrintError = bluePrintError
}
+ override fun loadEnvironments(fileName: String) {
+ BluePrintMetadataUtils.environmentFileProperties(fileName).forEach { key, value ->
+ setNodeTemplateAttributeValue("ENV", key.toString(), value.toString().asJsonPrimitive())
+ }
+ }
+
/**
* Resolve any property assignments for the node
*/
@@ -328,6 +348,28 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl
}
+ /**
+ * Read the DSL Property reference, If there is any expression, then resolve those expression and return as Json
+ * Type
+ */
+ override fun resolveDSLExpression(dslPropertyName: String): JsonNode {
+ val propertyAssignments = bluePrintContext.dslPropertiesByName(dslPropertyName)
+ return if (BluePrintExpressionService.checkContainsExpression(propertyAssignments)
+ && propertyAssignments is ObjectNode) {
+
+ val rootKeyMap = propertyAssignments.rootFieldsToMap()
+ val propertyAssignmentValue: MutableMap<String, JsonNode> = hashMapOf()
+ rootKeyMap.forEach { propertyName, propertyValue ->
+ val propertyAssignmentExpression = PropertyAssignmentService(this)
+ propertyAssignmentValue[propertyName] = propertyAssignmentExpression
+ .resolveAssignmentExpression("DSL", propertyName, propertyValue)
+ }
+ propertyAssignmentValue.asJsonNode()
+ } else {
+ propertyAssignments
+ }
+ }
+
override fun setInputValue(propertyName: String, propertyDefinition: PropertyDefinition, value: JsonNode) {
val path = StringBuilder(BluePrintConstants.PATH_INPUTS)
.append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString()
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt
index cb75e2c2..ae4f40b8 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt
@@ -84,6 +84,9 @@ If Property Assignment is Expression.
BluePrintConstants.EXPRESSION_GET_ARTIFACT -> {
valueNode = resolveArtifactExpression(nodeTemplateName, expressionData.artifactExpression!!)
}
+ BluePrintConstants.EXPRESSION_DSL_REFERENCE -> {
+ valueNode = bluePrintRuntimeService.resolveDSLExpression(expressionData.dslExpression!!.propertyName)
+ }
BluePrintConstants.EXPRESSION_GET_NODE_OF_TYPE -> {
}
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt
index 7764bc19..fa5e1647 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt
@@ -1,5 +1,6 @@
/*
* 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.
@@ -30,6 +31,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeSer
import org.onap.ccsdk.apps.controllerblueprints.core.service.DefaultBluePrintRuntimeService
import java.io.File
import java.nio.charset.Charset
+import java.util.*
class BluePrintMetadataUtils {
companion object {
@@ -48,6 +50,27 @@ class BluePrintMetadataUtils {
return toscaMetaDataFromMetaFile(toscaMetaPath).entityDefinitions
}
+ fun bluePrintEnvProperties(basePath: String): Properties {
+ val blueprintsEnvFilePath = basePath.plus(File.separator)
+ .plus(BluePrintConstants.TOSCA_ENVIRONMENTS_DIR)
+ return environmentFileProperties(blueprintsEnvFilePath)
+ }
+
+ fun environmentFileProperties(pathName: String): Properties {
+ val properties = Properties()
+ val envDir = File(pathName)
+ // Verify if the environment directory exists
+ if (envDir.exists() && envDir.isDirectory) {
+ //Find all available environment files
+ envDir.listFiles()
+ .filter { it.name.endsWith(".properties") }
+ .forEach {
+ properties.load(it.inputStream())
+ }
+ }
+ return properties
+ }
+
fun toscaMetaDataFromMetaFile(metaFilePath: String): ToscaMetaData {
val toscaMetaData = ToscaMetaData()
val lines: MutableList<String> = FileUtils.readLines(File(metaFilePath), Charset.defaultCharset())
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionServiceTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionServiceTest.kt
index d68892fc..58910055 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionServiceTest.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionServiceTest.kt
@@ -1,5 +1,6 @@
/*
* 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.
@@ -19,9 +20,11 @@ package org.onap.ccsdk.apps.controllerblueprints.core.service
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import org.junit.Test
+import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive
import org.onap.ccsdk.apps.controllerblueprints.core.data.ExpressionData
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
+
/**
*
*
@@ -30,8 +33,8 @@ import kotlin.test.assertNotNull
class BluePrintExpressionServiceTest {
@Test
fun testInputExpression() {
- val node : JsonNode = jacksonObjectMapper().readTree("{ \"get_input\" : \"input-name\" }")
- val expressionData : ExpressionData = BluePrintExpressionService.getExpressionData(node)
+ val node: JsonNode = jacksonObjectMapper().readTree("{ \"get_input\" : \"input-name\" }")
+ val expressionData: ExpressionData = BluePrintExpressionService.getExpressionData(node)
assertNotNull(expressionData, " Failed to populate expression data")
assertEquals(expressionData.isExpression, true, "Failed to identify as expression")
assertNotNull(expressionData.inputExpression, " Failed to populate input expression data")
@@ -40,49 +43,49 @@ class BluePrintExpressionServiceTest {
@Test
fun testPropertyExpression() {
- val node : JsonNode = jacksonObjectMapper().readTree("{ \"get_property\" : [\"SELF\", \"property-name\"] }")
- val expressionData : ExpressionData = BluePrintExpressionService.getExpressionData(node)
+ val node: JsonNode = jacksonObjectMapper().readTree("{ \"get_property\" : [\"SELF\", \"property-name\"] }")
+ val expressionData: ExpressionData = BluePrintExpressionService.getExpressionData(node)
assertNotNull(expressionData, " Failed to populate expression data")
assertEquals(expressionData.isExpression, true, "Failed to identify as expression")
assertNotNull(expressionData.propertyExpression, " Failed to populate property expression data")
assertEquals("SELF", expressionData.propertyExpression?.modelableEntityName, " Failed to get expected modelableEntityName")
assertEquals("property-name", expressionData.propertyExpression?.propertyName, " Failed to get expected propertyName")
- val node1 : JsonNode = jacksonObjectMapper().readTree("{ \"get_property\" : [\"SELF\", \"\",\"property-name\", \"resource\", \"name\"] }")
- val expressionData1 : ExpressionData = BluePrintExpressionService.getExpressionData(node1)
+ val node1: JsonNode = jacksonObjectMapper().readTree("{ \"get_property\" : [\"SELF\", \"\",\"property-name\", \"resource\", \"name\"] }")
+ val expressionData1: ExpressionData = BluePrintExpressionService.getExpressionData(node1)
assertNotNull(expressionData1, " Failed to populate expression data")
assertEquals(expressionData1.isExpression, true, "Failed to identify as nested property expression")
assertNotNull(expressionData1.propertyExpression, " Failed to populate nested property expression data")
assertEquals("SELF", expressionData1.propertyExpression?.modelableEntityName, " Failed to get expected modelableEntityName")
assertEquals("property-name", expressionData1.propertyExpression?.propertyName, " Failed to get expected propertyName")
- assertEquals("resource/name",expressionData1.propertyExpression?.subPropertyName, " Failed to populate nested subPropertyName expression data")
+ assertEquals("resource/name", expressionData1.propertyExpression?.subPropertyName, " Failed to populate nested subPropertyName expression data")
}
@Test
fun testAttributeExpression() {
- val node : JsonNode = jacksonObjectMapper().readTree("{ \"get_attribute\" : [\"SELF\", \"resource\"] }")
- val expressionData : ExpressionData = BluePrintExpressionService.getExpressionData(node)
+ val node: JsonNode = jacksonObjectMapper().readTree("{ \"get_attribute\" : [\"SELF\", \"resource\"] }")
+ val expressionData: ExpressionData = BluePrintExpressionService.getExpressionData(node)
assertNotNull(expressionData, " Failed to populate expression data")
assertEquals(expressionData.isExpression, true, "Failed to identify as expression")
assertNotNull(expressionData.attributeExpression, " Failed to populate attribute expression data")
assertEquals("SELF", expressionData.attributeExpression?.modelableEntityName, " Failed to get expected modelableEntityName")
assertEquals("resource", expressionData.attributeExpression?.attributeName, " Failed to get expected attributeName")
- val node1 : JsonNode = jacksonObjectMapper().readTree("{ \"get_attribute\" : [\"SELF\", \"\",\"attribute-name\", \"resource\", \"name\"] }")
- val expressionData1 : ExpressionData = BluePrintExpressionService.getExpressionData(node1)
+ val node1: JsonNode = jacksonObjectMapper().readTree("{ \"get_attribute\" : [\"SELF\", \"\",\"attribute-name\", \"resource\", \"name\"] }")
+ val expressionData1: ExpressionData = BluePrintExpressionService.getExpressionData(node1)
assertNotNull(expressionData1, " Failed to populate expression data")
assertEquals(expressionData1.isExpression, true, "Failed to identify as expression")
assertNotNull(expressionData1.attributeExpression, " Failed to populate attribute expression data")
assertEquals("SELF", expressionData1.attributeExpression?.modelableEntityName, " Failed to get expected modelableEntityName")
assertEquals("attribute-name", expressionData1.attributeExpression?.attributeName, " Failed to get expected attributeName")
- assertEquals("resource/name",expressionData1.attributeExpression?.subAttributeName, " Failed to populate nested subAttributeName expression data")
+ assertEquals("resource/name", expressionData1.attributeExpression?.subAttributeName, " Failed to populate nested subAttributeName expression data")
}
@Test
fun testOutputOperationExpression() {
- val node : JsonNode = jacksonObjectMapper().readTree("{ \"get_operation_output\": [\"SELF\", \"interface-name\", \"operation-name\", \"output-property-name\"] }")
- val expressionData : ExpressionData = BluePrintExpressionService.getExpressionData(node)
+ val node: JsonNode = jacksonObjectMapper().readTree("{ \"get_operation_output\": [\"SELF\", \"interface-name\", \"operation-name\", \"output-property-name\"] }")
+ val expressionData: ExpressionData = BluePrintExpressionService.getExpressionData(node)
assertNotNull(expressionData, " Failed to populate expression data")
assertEquals(expressionData.isExpression, true, "Failed to identify as expression")
assertNotNull(expressionData.operationOutputExpression, " Failed to populate output expression data")
@@ -95,8 +98,8 @@ class BluePrintExpressionServiceTest {
@Test
fun testArtifactExpression() {
- val node : JsonNode = jacksonObjectMapper().readTree("{ \"get_artifact\" : [\"SELF\", \"artifact-template\"] }")
- val expressionData : ExpressionData = BluePrintExpressionService.getExpressionData(node)
+ val node: JsonNode = jacksonObjectMapper().readTree("{ \"get_artifact\" : [\"SELF\", \"artifact-template\"] }")
+ val expressionData: ExpressionData = BluePrintExpressionService.getExpressionData(node)
assertNotNull(expressionData, " Failed to populate expression data")
assertEquals(expressionData.isExpression, true, "Failed to identify as expression")
assertNotNull(expressionData.artifactExpression, " Failed to populate Artifact expression data")
@@ -104,8 +107,8 @@ class BluePrintExpressionServiceTest {
assertEquals("artifact-template", expressionData.artifactExpression?.artifactName, " Failed to get expected artifactName")
- val node1 : JsonNode = jacksonObjectMapper().readTree("{ \"get_artifact\" : [\"SELF\", \"artifact-template\", \"location\", true] }")
- val expressionData1 : ExpressionData = BluePrintExpressionService.getExpressionData(node1)
+ val node1: JsonNode = jacksonObjectMapper().readTree("{ \"get_artifact\" : [\"SELF\", \"artifact-template\", \"location\", true] }")
+ val expressionData1: ExpressionData = BluePrintExpressionService.getExpressionData(node1)
assertNotNull(expressionData1, " Failed to populate expression data")
assertEquals(expressionData1.isExpression, true, "Failed to identify as expression")
assertNotNull(expressionData1.artifactExpression, " Failed to populate Artifact expression data")
@@ -114,4 +117,15 @@ class BluePrintExpressionServiceTest {
assertEquals("location", expressionData1.artifactExpression?.location, " Failed to get expected location")
assertEquals(true, expressionData1.artifactExpression?.remove, " Failed to get expected remove")
}
+
+ @Test
+ fun testDSLExpression() {
+ val node: JsonNode = "*dynamic-rest-source".asJsonPrimitive()
+ val expressionData: ExpressionData = BluePrintExpressionService.getExpressionData(node)
+ assertNotNull(expressionData, " Failed to populate expression data")
+ assertEquals(expressionData.isExpression, true, "Failed to identify as expression")
+ assertNotNull(expressionData.dslExpression, " Failed to populate dsl expression data")
+ assertEquals("dynamic-rest-source", expressionData.dslExpression!!.propertyName,
+ " Failed to populate dsl property name")
+ }
} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt
index 92e9247a..c0bfd0f5 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt
@@ -24,6 +24,7 @@ import com.fasterxml.jackson.databind.node.NullNode
import org.junit.Test
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive
+import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition
import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintRuntimeUtils
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
@@ -139,6 +140,19 @@ class BluePrintRuntimeServiceTest {
}
+ @Test
+ fun `test Resolve DSL Properties`() {
+ log.info("************************ resolveDSLExpression **********************")
+
+ val bluePrintRuntimeService = getBluePrintRuntimeService()
+
+ bluePrintRuntimeService.setInputValue("rest-user-name", PropertyDefinition(), "sample-username"
+ .asJsonPrimitive())
+
+ val resolvedJsonNode: JsonNode = bluePrintRuntimeService.resolveDSLExpression("dynamic-rest-source")
+ assertNotNull(resolvedJsonNode, "Failed to populate dsl property values")
+ }
+
private fun getBluePrintRuntimeService(): BluePrintRuntimeService<MutableMap<String, JsonNode>> {
val blueprintBasePath: String = ("./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
val blueprintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath)
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtilsTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtilsTest.kt
index 599bb3be..366ce4a8 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtilsTest.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtilsTest.kt
@@ -20,16 +20,18 @@ package org.onap.ccsdk.apps.controllerblueprints.core.utils
import org.junit.Test
import org.onap.ccsdk.apps.controllerblueprints.core.data.ToscaMetaData
+import kotlin.test.assertEquals
import kotlin.test.assertNotNull
+import kotlin.test.assertNull
class BluePrintMetadataUtilsTest {
-
+
@Test
- fun testToscaMetaData(){
+ fun testToscaMetaData() {
- val basePath : String = "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
+ val basePath: String = "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
- val toscaMetaData : ToscaMetaData = BluePrintMetadataUtils.toscaMetaData(basePath)
+ val toscaMetaData: ToscaMetaData = BluePrintMetadataUtils.toscaMetaData(basePath)
assertNotNull(toscaMetaData, "Missing Tosca Definition Object")
assertNotNull(toscaMetaData.toscaMetaFileVersion, "Missing Tosca Metadata Version")
assertNotNull(toscaMetaData.csarVersion, "Missing CSAR version")
@@ -38,4 +40,18 @@ class BluePrintMetadataUtilsTest {
assertNotNull(toscaMetaData.templateTags, "Missing Template Tags")
}
+
+ @Test
+ fun environmentDataTest() {
+ val environmentPath = "./src/test/resources/environments"
+
+ val properties = BluePrintMetadataUtils.bluePrintEnvProperties(environmentPath)
+
+ assertNotNull(properties, "Could not read the properties")
+ assertEquals(properties.getProperty("blueprintsprocessor.database.alt1.username"), "username1", "failed 1")
+ assertEquals(properties.getProperty("blueprintsprocessor.database.alt1.password"), "password1", "failed 2")
+ assertEquals(properties.getProperty("blueprintsprocessor.database.alt2.username"), "username2", "failed 3")
+ assertEquals(properties.getProperty("blueprintsprocessor.database.alt2.password"), "password2", "failed 4")
+ assertNull(properties.getProperty("blueprintsprocessor.database.alt3.password"), "failed 5")
+ }
} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/environments/Environments/environment1.properties b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/environments/Environments/environment1.properties
new file mode 100644
index 00000000..d735087b
--- /dev/null
+++ b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/environments/Environments/environment1.properties
@@ -0,0 +1,2 @@
+blueprintsprocessor.database.alt1.username=username1
+blueprintsprocessor.database.alt1.password=password1 \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/environments/Environments/environment2.properties b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/environments/Environments/environment2.properties
new file mode 100644
index 00000000..5530a8f8
--- /dev/null
+++ b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/environments/Environments/environment2.properties
@@ -0,0 +1,2 @@
+blueprintsprocessor.database.alt2.username=username2
+blueprintsprocessor.database.alt2.password=password2 \ No newline at end of file