aboutsummaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>2018-11-11 17:41:48 -0500
committerMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>2018-11-11 17:41:48 -0500
commit3aea511293d7c5a61ad5895012b057bd589528b9 (patch)
tree63b5d8ce7a8d7597771b91bc2e723500df644b97 /components
parent9a85b3d441c11813d3dbe7ed487d475993c2e0a3 (diff)
Controller Blueprints Component Core
Implement Blueprint context, run time service, metadata utils. Change-Id: Ifc3aa1e1b04b326778e431e972e5d997275c013b Issue-ID: CCSDK-670 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
Diffstat (limited to 'components')
-rw-r--r--components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintProcessorException.kt3
-rw-r--r--components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctions.kt69
-rw-r--r--components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt14
-rw-r--r--components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt111
-rw-r--r--components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt215
-rw-r--r--components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt11
-rw-r--r--components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt60
-rw-r--r--components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintRuntimeUtils.kt16
-rw-r--r--components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/TopologicalSortingUtils.kt4
-rw-r--r--components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt58
-rw-r--r--components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtilsTest.kt2
-rw-r--r--components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtilsTest.kt2
-rw-r--r--components/core/src/test/resources/properties/convert.json65
13 files changed, 412 insertions, 218 deletions
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintProcessorException.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintProcessorException.kt
index 50717031..00006213 100644
--- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintProcessorException.kt
+++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintProcessorException.kt
@@ -16,12 +16,13 @@
*/
package org.onap.ccsdk.apps.controllerblueprints.core
+
/**
*
*
* @author Brinda Santh
*/
-class BluePrintProcessorException : Exception {
+class BluePrintProcessorException : RuntimeException {
var code: Int = 100
constructor(message: String, cause: Throwable) : super(message, cause)
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctions.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctions.kt
index 7302f2b9..c32e15f8 100644
--- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctions.kt
+++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctions.kt
@@ -16,6 +16,12 @@
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 org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
import org.slf4j.helpers.MessageFormatter
import java.io.File
import java.io.InputStream
@@ -27,14 +33,30 @@ import kotlin.reflect.KClass
* @author Brinda Santh
*/
-fun format(message: String, vararg args: Any?) : String{
- if(args != null && args.isNotEmpty()){
+fun String.asJsonPrimitive(): TextNode {
+ return TextNode(this)
+}
+
+fun Boolean.asJsonPrimitive(): BooleanNode {
+ return BooleanNode.valueOf(this)
+}
+
+fun Int.asJsonPrimitive(): IntNode {
+ return IntNode.valueOf(this)
+}
+
+fun Double.asJsonPrimitive(): DoubleNode {
+ return DoubleNode.valueOf(this)
+}
+
+fun format(message: String, vararg args: Any?): String {
+ if (args != null && args.isNotEmpty()) {
return MessageFormatter.arrayFormat(message, args).message
}
- return message
+ return message
}
-fun <T : Any> MutableMap<String, *>.getCastOptionalValue(key: String, valueType: KClass<T>): T? {
+fun <T : Any> MutableMap<String, *>.castOptionalValue(key: String, valueType: KClass<T>): T? {
if (containsKey(key)) {
return get(key) as? T
} else {
@@ -42,27 +64,54 @@ fun <T : Any> MutableMap<String, *>.getCastOptionalValue(key: String, valueType:
}
}
-fun <T : Any> MutableMap<String, *>.getCastValue(key: String, valueType: KClass<T>): T {
+fun <T : Any> MutableMap<String, *>.castValue(key: String, valueType: KClass<T>): T {
if (containsKey(key)) {
return get(key) as T
} else {
- throw BluePrintException("couldn't find the key " + key)
+ throw BluePrintException("couldn't find the key $key")
}
}
-fun checkNotEmpty(value : String?) : Boolean{
+fun MutableMap<String, JsonNode>.putJsonElement(key: String, value: Any) {
+ when (value) {
+ is JsonNode ->
+ this.put(key, value)
+ is String ->
+ this.put(key, TextNode(value))
+ is Boolean ->
+ this.put(key, BooleanNode.valueOf(value))
+ is Int ->
+ this.put(key, IntNode.valueOf(value.toInt()))
+ is Double ->
+ this.put(key, DoubleNode.valueOf(value.toDouble()))
+ else ->
+ this.put(key, JacksonUtils.jsonNodeFromObject(value))
+ }
+}
+
+fun MutableMap<String, JsonNode>.getAsString(key: String): String {
+ return this[key]?.asText() ?: throw BluePrintException("couldn't find value for key($key)")
+}
+
+fun MutableMap<String, JsonNode>.getAsBoolean(key: String): Boolean {
+ return this[key]?.asBoolean() ?: throw BluePrintException("couldn't find value for key($key)")
+}
+
+// Checks
+
+fun checkNotEmpty(value: String?): Boolean {
return value != null && value.isNotEmpty()
}
-fun checkNotEmptyNThrow(value : String?, message : String? = value.plus(" is null/empty ")) : Boolean{
+fun checkNotEmptyNThrow(value: String?, message: String? = value.plus(" is null/empty ")): Boolean {
val notEmpty = value != null && value.isNotEmpty()
- if(!notEmpty){
+ if (!notEmpty) {
throw BluePrintException(message!!)
}
return notEmpty
}
-fun InputStream.toFile(path: String) : File {
+fun InputStream.toFile(path: String): File {
val file = File(path)
file.outputStream().use { this.copyTo(it) }
return file
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 70f3c556..9b6fbbf1 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
@@ -91,7 +91,7 @@ A node filter definition defines criteria for selection of a TOSCA Node Template
class NodeFilterDefinition {
var properties: MutableMap<String, PropertyDefinition>? = null
- var capabilities : MutableList<String>? = null
+ var capabilities: MutableList<String>? = null
}
/*
@@ -348,7 +348,7 @@ class ArtifactType : EntityType() {
A Data Type definition defines the schema for new named datatypes in TOSCA.
*/
-class DataType : EntityType(){
+class DataType : EntityType() {
var constraints: MutableList<ConstraintClause>? = null
}
@@ -410,7 +410,7 @@ class GroupType : EntityType() {
topology at some stage of its lifecycle, but is not explicitly part of the topology itself
(i.e., it does not prevent the application or service from being deployed or run if it did not exist).
*/
-class PolicyType : EntityType(){
+class PolicyType : EntityType() {
lateinit var targets: MutableList<String>
}
@@ -434,10 +434,10 @@ class GroupDefinition {
var id: String? = null
lateinit var type: String
var description: String? = null
- var metadata : MutableMap<String, String>? = null
- var properties : MutableMap<String, JsonNode>? = null
+ var metadata: MutableMap<String, String>? = null
+ var properties: MutableMap<String, JsonNode>? = null
var members = ArrayList<String>()
- var interfaces : MutableMap<String, InterfaceDefinition>?= null
+ var interfaces: MutableMap<String, InterfaceDefinition>? = null
}
/*
@@ -597,7 +597,7 @@ class ServiceTemplate {
@get:JsonProperty("node_types")
var nodeTypes: MutableMap<String, NodeType>? = null
@get:JsonProperty("policy_types")
- var policyTypes: PolicyType? = null
+ var policyTypes: MutableMap<String, PolicyType>? = null
@get:JsonProperty("topology_template")
var topologyTemplate: TopologyTemplate? = null
}
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 46da9d95..4764479a 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
@@ -22,17 +22,16 @@ import com.fasterxml.jackson.databind.JsonNode
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
import org.onap.ccsdk.apps.controllerblueprints.core.data.*
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
+
/**
*
*
* @author Brinda Santh
*/
-class BluePrintContext(serviceTemplate: ServiceTemplate) {
+class BluePrintContext(val serviceTemplate: ServiceTemplate) {
private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())
- val serviceTemplate: ServiceTemplate = serviceTemplate
-
val imports: List<ImportDefinition>? = serviceTemplate.imports
val metadata: MutableMap<String, String>? = serviceTemplate.metadata
@@ -41,18 +40,33 @@ class BluePrintContext(serviceTemplate: ServiceTemplate) {
val inputs: MutableMap<String, PropertyDefinition>? = serviceTemplate.topologyTemplate?.inputs
- val workflows: MutableMap<String, Workflow>? = serviceTemplate.topologyTemplate?.workflows
-
fun blueprintJson(pretty: Boolean = false): String = print("json", pretty)
- fun blueprintYaml(pretty: Boolean = false): String = print("yaml", pretty)
-
private fun print(type: String? = "json", pretty: Boolean = false): String {
return JacksonUtils.getJson(serviceTemplate, pretty)
}
// Workflow
- fun workflowByName(name: String): Workflow? = workflows?.get(name)
+ val workflows: MutableMap<String, Workflow>? = serviceTemplate.topologyTemplate?.workflows
+
+ fun workflowByName(workFlowName: String): Workflow = workflows?.get(workFlowName)
+ ?: throw BluePrintException("could't get workflow($workFlowName)")
+
+ fun workflowStepByName(workFlowName: String, stepName: String): Step {
+ return workflowByName(workFlowName).steps?.get(stepName)
+ ?: throw BluePrintException("could't get step($stepName) for workflow($workFlowName)")
+ }
+
+ fun workflowStepNodeTemplate(workFlowName: String, stepName: String): NodeTemplate {
+ val nodeTemplateName = workflowStepByName(workFlowName, stepName).target
+ ?: throw BluePrintException("could't get node template name for workflow($workFlowName)'s step($stepName)")
+ return nodeTemplateByName(nodeTemplateName)
+ }
+
+ fun workflowStepFirstCallOperation(workFlowName: String, stepName: String): String {
+ return workflowStepByName(workFlowName, stepName).activities?.filter { it.callOperation != null }?.single()?.callOperation
+ ?: throw BluePrintException("could't get first callOperation for WorkFlow($workFlowName) ")
+ }
// Data Type
fun dataTypeByName(name: String): DataType? = dataTypes?.get(name)
@@ -60,41 +74,65 @@ class BluePrintContext(serviceTemplate: ServiceTemplate) {
// Artifact Type
val artifactTypes: MutableMap<String, ArtifactType>? = serviceTemplate.artifactTypes
+ // Policy Types
+ val policyTypes: MutableMap<String, PolicyType>? = serviceTemplate.policyTypes
+
+ fun policyTypeByName(policyName: String) = policyTypes?.get(policyName)
+ ?: throw BluePrintException("could't get policy type for the name($policyName)")
+
+ fun policyTypesDerivedFrom(name: String): MutableMap<String, PolicyType>? {
+ return policyTypes?.filterValues { policyType -> policyType.derivedFrom == name }?.toMutableMap()
+ }
+
+ fun policyTypesTarget(target: String): MutableMap<String, PolicyType>? {
+ return policyTypes?.filterValues { it.targets.contains(target) }?.toMutableMap()
+ }
+
+ fun policyTypesTargetNDerivedFrom(target: String, derivedFrom: String): MutableMap<String, PolicyType>? {
+ return policyTypesDerivedFrom(derivedFrom)?.filterValues {
+ it.targets.contains(target)
+ }?.toMutableMap()
+ }
+
// Node Type Methods
val nodeTypes: MutableMap<String, NodeType>? = serviceTemplate.nodeTypes
fun nodeTypeByName(name: String): NodeType =
- nodeTypes?.get(name) ?: throw BluePrintException(String.format("Failed to get node type for the name : %s", name))
+ nodeTypes?.get(name)
+ ?: throw BluePrintException("could't get node type for the name($name)")
fun nodeTypeDerivedFrom(name: String): MutableMap<String, NodeType>? {
return nodeTypes?.filterValues { nodeType -> nodeType.derivedFrom == name }?.toMutableMap()
}
- fun nodeTypeInterface(nodeTypeName: String, interfaceName: String): InterfaceDefinition? {
+ fun nodeTypeInterface(nodeTypeName: String, interfaceName: String): InterfaceDefinition {
return nodeTypeByName(nodeTypeName).interfaces?.get(interfaceName)
+ ?: throw BluePrintException("could't get node type($nodeTypeName)'s interface definition($interfaceName)")
}
- fun nodeTypeInterfaceOperation(nodeTypeName: String, interfaceName: String, operationName: String): OperationDefinition? {
- return nodeTypeInterface(nodeTypeName, interfaceName)?.operations?.get(operationName)
+ fun nodeTypeInterfaceOperation(nodeTypeName: String, interfaceName: String, operationName: String): OperationDefinition {
+ return nodeTypeInterface(nodeTypeName, interfaceName).operations?.get(operationName)
+ ?: throw BluePrintException("could't get node type($nodeTypeName)'s interface definition($interfaceName) operation definition($operationName)")
}
- fun interfaceNameForNodeType(nodeTypeName: String): String? {
+ fun interfaceNameForNodeType(nodeTypeName: String): String {
return nodeTypeByName(nodeTypeName).interfaces?.keys?.first()
+ ?: throw BluePrintException("could't get NodeType($nodeTypeName)'s first InterfaceDefinition name")
}
fun nodeTypeInterfaceOperationInputs(nodeTypeName: String, interfaceName: String, operationName: String): MutableMap<String, PropertyDefinition>? {
- return nodeTypeInterfaceOperation(nodeTypeName, interfaceName, operationName)?.inputs
+ return nodeTypeInterfaceOperation(nodeTypeName, interfaceName, operationName).inputs
}
fun nodeTypeInterfaceOperationOutputs(nodeTypeName: String, interfaceName: String, operationName: String): MutableMap<String, PropertyDefinition>? {
- return nodeTypeInterfaceOperation(nodeTypeName, interfaceName, operationName)?.outputs
+ return nodeTypeInterfaceOperation(nodeTypeName, interfaceName, operationName).outputs
}
// Node Template Methods
val nodeTemplates: MutableMap<String, NodeTemplate>? = serviceTemplate.topologyTemplate?.nodeTemplates
fun nodeTemplateByName(name: String): NodeTemplate =
- nodeTemplates?.get(name) ?: throw BluePrintException("Failed to get node template for the name " + name)
+ nodeTemplates?.get(name) ?: throw BluePrintException("could't get node template for the name($name) ")
fun nodeTemplateForNodeType(name: String): MutableMap<String, NodeTemplate>? {
return nodeTemplates?.filterValues { nodeTemplate -> nodeTemplate.type == name }?.toMutableMap()
@@ -113,55 +151,62 @@ class BluePrintContext(serviceTemplate: ServiceTemplate) {
return nodeTemplateByName(nodeTemplateName).artifacts
}
- fun nodeTemplateArtifact(nodeTemplateName: String, artifactName: String): ArtifactDefinition? {
+ fun nodeTemplateArtifact(nodeTemplateName: String, artifactName: String): ArtifactDefinition {
return nodeTemplateArtifacts(nodeTemplateName)?.get(artifactName)
+ ?: throw BluePrintException("could't get NodeTemplate($nodeTemplateName)'s ArtifactDefinition($artifactName)")
}
- fun nodeTemplateFirstInterface(nodeTemplateName: String): InterfaceAssignment? {
+ fun nodeTemplateFirstInterface(nodeTemplateName: String): InterfaceAssignment {
return nodeTemplateByName(nodeTemplateName).interfaces?.values?.first()
+ ?: throw BluePrintException("could't get NodeTemplate($nodeTemplateName)'s first InterfaceAssignment")
}
- fun nodeTemplateFirstInterfaceName(nodeTemplateName: String): String? {
+ fun nodeTemplateFirstInterfaceName(nodeTemplateName: String): String {
return nodeTemplateByName(nodeTemplateName).interfaces?.keys?.first()
+ ?: throw BluePrintException("could't get NodeTemplate($nodeTemplateName)'s first InterfaceAssignment name")
}
- fun nodeTemplateFirstInterfaceFirstOperationName(nodeTemplateName: String): String? {
- return nodeTemplateFirstInterface(nodeTemplateName)?.operations?.keys?.first()
+ fun nodeTemplateFirstInterfaceFirstOperationName(nodeTemplateName: String): String {
+ return nodeTemplateFirstInterface(nodeTemplateName).operations?.keys?.first()
+ ?: throw BluePrintException("could't get NodeTemplate($nodeTemplateName)'s first InterfaceAssignment's first OperationAssignment name")
}
fun nodeTemplateInterfaceOperationInputs(nodeTemplateName: String, interfaceName: String, operationName: String): MutableMap<String, JsonNode>? {
- return nodeTemplateByName(nodeTemplateName).interfaces?.get(interfaceName)?.operations?.get(operationName)?.inputs
+ return nodeTemplateInterfaceOperation(nodeTemplateName, interfaceName, operationName).inputs
}
fun nodeTemplateInterfaceOperationOutputs(nodeTemplateName: String, interfaceName: String, operationName: String): MutableMap<String, JsonNode>? {
- return nodeTemplateByName(nodeTemplateName).interfaces?.get(interfaceName)?.operations?.get(operationName)?.outputs
+ return nodeTemplateInterfaceOperation(nodeTemplateName, interfaceName, operationName).outputs
}
- fun nodeTemplateInterface(nodeTemplateName: String, interfaceName: String): InterfaceAssignment? {
+ fun nodeTemplateInterface(nodeTemplateName: String, interfaceName: String): InterfaceAssignment {
return nodeTemplateByName(nodeTemplateName).interfaces?.get(interfaceName)
+ ?: throw BluePrintException("could't get NodeTemplate($nodeTemplateName)'s InterfaceAssignment($interfaceName)")
}
-
- fun nodeTemplateInterfaceOperation(nodeTemplateName: String, interfaceName: String, operationName: String): OperationAssignment? {
- return nodeTemplateInterface(nodeTemplateName, interfaceName)?.operations?.get(operationName)
+ fun nodeTemplateInterfaceOperation(nodeTemplateName: String, interfaceName: String, operationName: String): OperationAssignment {
+ return nodeTemplateInterface(nodeTemplateName, interfaceName).operations?.get(operationName)
+ ?: throw BluePrintException("could't get NodeTemplate($nodeTemplateName)'s InterfaceAssignment($interfaceName) OperationAssignment($operationName)")
}
- fun nodeTemplateCapability(nodeTemplateName: String, capabilityName: String): CapabilityAssignment? {
+ fun nodeTemplateCapability(nodeTemplateName: String, capabilityName: String): CapabilityAssignment {
return nodeTemplateByName(nodeTemplateName).capabilities?.get(capabilityName)
+ ?: throw BluePrintException("could't get NodeTemplate($nodeTemplateName)'s CapabilityAssignment($capabilityName)")
}
- fun nodeTemplateRequirement(nodeTemplateName: String, requirementName: String): RequirementAssignment? {
+ fun nodeTemplateRequirement(nodeTemplateName: String, requirementName: String): RequirementAssignment {
return nodeTemplateByName(nodeTemplateName).requirements?.get(requirementName)
+ ?: throw BluePrintException("could't get NodeTemplate($nodeTemplateName)'s first RequirementAssignment($requirementName)")
}
fun nodeTemplateRequirementNode(nodeTemplateName: String, requirementName: String): NodeTemplate {
- val requirementNodeTemplateName: String = nodeTemplateByName(nodeTemplateName).requirements?.get(requirementName)?.node
- ?: throw BluePrintException(String.format("failed to get node name for node template's (%s) requirement's (%s) " + nodeTemplateName, requirementName))
- return nodeTemplateByName(requirementNodeTemplateName)
+ val filteredNodeTemplateName: String = nodeTemplateByName(nodeTemplateName).requirements?.get(requirementName)?.node
+ ?: throw BluePrintException("could't NodeTemplate for NodeTemplate's($nodeTemplateName) requirement's ($requirementName) ")
+ return nodeTemplateByName(filteredNodeTemplateName)
}
fun nodeTemplateCapabilityProperty(nodeTemplateName: String, capabilityName: String, propertyName: String): Any? {
- return nodeTemplateCapability(nodeTemplateName, capabilityName)?.properties?.get(propertyName)
+ return nodeTemplateCapability(nodeTemplateName, capabilityName).properties?.get(propertyName)
}
// Chained Functions
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 2485abdb..f84b2c56 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
@@ -18,8 +18,12 @@
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.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.BluePrintException
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
@@ -27,31 +31,123 @@ 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.JacksonUtils
-import com.att.eelf.configuration.EELFLogger
-import com.att.eelf.configuration.EELFManager
-import com.fasterxml.jackson.databind.node.ObjectNode
-import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
+
+interface BluePrintRuntimeService<T> {
+
+ fun id(): String
+
+ fun bluePrintContext(): BluePrintContext
+
+ fun getExecutionContext(): T
+
+ fun setExecutionContext(executionContext: T)
+
+ fun put(key: String, value: JsonNode)
+
+ fun get(key: String): JsonNode?
+
+ fun cleanRuntime()
+
+ /*
+ Get the Node Type Definition for the Node Template, Then iterate Node Type Properties and resolve the expressing
+ */
+ fun resolveNodeTemplateProperties(nodeTemplateName: 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>
+
+ fun resolveNodeTemplateArtifact(nodeTemplateName: String, artifactName: String): String
+
+ fun setInputValue(propertyName: String, propertyDefinition: PropertyDefinition, value: JsonNode)
+
+ fun setWorkflowInputValue(workflowName: String, propertyName: String, propertyDefinition: PropertyDefinition, value: JsonNode)
+
+ fun setNodeTemplatePropertyValue(nodeTemplateName: String, propertyName: String, value: JsonNode)
+
+ fun setNodeTemplateAttributeValue(nodeTemplateName: String, attributeName: String, value: JsonNode)
+
+ fun setNodeTemplateOperationPropertyValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String, value: JsonNode)
+
+ fun setNodeTemplateOperationInputValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String, value: JsonNode)
+
+ fun setNodeTemplateOperationOutputValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String, value: JsonNode)
+
+ fun getInputValue(propertyName: String): JsonNode
+
+ fun getNodeTemplateOperationOutputValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String): JsonNode
+
+ fun getNodeTemplatePropertyValue(nodeTemplateName: String, propertyName: String): JsonNode?
+
+ fun getNodeTemplateAttributeValue(nodeTemplateName: String, attributeName: String): JsonNode?
+
+ fun getNodeTemplateRequirementPropertyValue(nodeTemplateName: String, requirementName: String, propertyName: String): JsonNode?
+
+ fun getNodeTemplateCapabilityPropertyValue(nodeTemplateName: String, capabilityName: String, propertyName: String): JsonNode?
+
+ fun assignInputs(jsonNode: JsonNode)
+
+ fun assignWorkflowInputs(workflowName: String, jsonNode: JsonNode)
+
+ fun getJsonForNodeTemplateAttributeProperties(nodeTemplateName: String, keys: List<String>): JsonNode
+}
/**
*
*
* @author Brinda Santh
*/
-open class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var context: MutableMap<String, Any> = hashMapOf()) {
+open class DefaultBluePrintRuntimeService(private var id: String, private var bluePrintContext: BluePrintContext)
+ : BluePrintRuntimeService<MutableMap<String, JsonNode>> {
private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintRuntimeService::class.toString())
+ private var store: MutableMap<String, JsonNode> = hashMapOf()
+
+ override fun id(): String {
+ return id
+ }
+
+ override fun bluePrintContext(): BluePrintContext {
+ return bluePrintContext
+ }
+
+ override fun getExecutionContext(): MutableMap<String, JsonNode> {
+ return store
+ }
+
+ @Suppress("UNCHECKED_CAST")
+ override fun setExecutionContext(executionContext: MutableMap<String, JsonNode>) {
+ this.store = executionContext
+ }
+
+ override fun put(key: String, value: JsonNode) {
+ store[key] = value
+ }
+
+ override fun get(key: String): JsonNode {
+ return store[key] ?: throw BluePrintProcessorException("failed to get execution property($key)")
+ }
+
+ override fun cleanRuntime() {
+ store.clear()
+ }
+
+ private fun getJsonNode(key: String): JsonNode {
+ return get(key)
+ }
+
/*
Get the Node Type Definition for the Node Template, Then iterate Node Type Properties and resolve the expressing
*/
- open fun resolveNodeTemplateProperties(nodeTemplateName: String): MutableMap<String, Any?> {
+ override fun resolveNodeTemplateProperties(nodeTemplateName: String): MutableMap<String, JsonNode> {
log.info("resolveNodeTemplatePropertyValues for node template ({})", nodeTemplateName)
- val propertyAssignmentValue: MutableMap<String, Any?> = hashMapOf()
+ val propertyAssignmentValue: MutableMap<String, JsonNode> = hashMapOf()
val nodeTemplate: NodeTemplate = bluePrintContext.nodeTemplateByName(nodeTemplateName)
- val propertyAssignments: MutableMap<String, Any?> =
- nodeTemplate.properties as MutableMap<String, Any?>
+ val propertyAssignments: MutableMap<String, JsonNode> =
+ nodeTemplate.properties as MutableMap<String, JsonNode>
// Get the Node Type Definitions
val nodeTypeProperties: MutableMap<String, PropertyDefinition> =
@@ -65,7 +161,7 @@ open class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var c
var resolvedValue: JsonNode = NullNode.getInstance()
if (propertyAssignment != null) {
// Resolve the Expressing
- val propertyAssignmentExpression = PropertyAssignmentService(context, this)
+ val propertyAssignmentExpression = PropertyAssignmentService(this)
resolvedValue = propertyAssignmentExpression.resolveAssignmentExpression(nodeTemplateName, nodeTypePropertyName, propertyAssignment)
} else {
// Assign default value to the Operation
@@ -80,12 +176,12 @@ open class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var c
return propertyAssignmentValue
}
- open fun resolveNodeTemplateInterfaceOperationInputs(nodeTemplateName: String,
- interfaceName: String, operationName: String): MutableMap<String, Any?> {
+ override fun resolveNodeTemplateInterfaceOperationInputs(nodeTemplateName: String,
+ interfaceName: String, operationName: String): MutableMap<String, JsonNode> {
log.info("resolveNodeTemplateInterfaceOperationInputs for node template ({}),interface name ({}), " +
"operationName({})", nodeTemplateName, interfaceName, operationName)
- val propertyAssignmentValue: MutableMap<String, Any?> = hashMapOf()
+ val propertyAssignmentValue: MutableMap<String, JsonNode> = hashMapOf()
val propertyAssignments: MutableMap<String, Any> =
bluePrintContext.nodeTemplateInterfaceOperationInputs(nodeTemplateName, interfaceName, operationName) as? MutableMap<String, Any>
@@ -109,7 +205,7 @@ open class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var c
var resolvedValue: JsonNode = NullNode.getInstance()
if (propertyAssignment != null) {
// Resolve the Expressing
- val propertyAssignmentExpression = PropertyAssignmentService(context, this)
+ val propertyAssignmentExpression = PropertyAssignmentService(this)
resolvedValue = propertyAssignmentExpression.resolveAssignmentExpression(nodeTemplateName, nodeTypePropertyName, propertyAssignment)
} else {
// Assign default value to the Operation
@@ -127,12 +223,12 @@ open class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var c
}
- open fun resolveNodeTemplateInterfaceOperationOutputs(nodeTemplateName: String,
- interfaceName: String, operationName: String): MutableMap<String, Any?> {
+ override fun resolveNodeTemplateInterfaceOperationOutputs(nodeTemplateName: String,
+ interfaceName: String, operationName: String): MutableMap<String, JsonNode> {
log.info("resolveNodeTemplateInterfaceOperationOutputs for node template ({}),interface name ({}), " +
"operationName({})", nodeTemplateName, interfaceName, operationName)
- val propertyAssignmentValue: MutableMap<String, Any?> = hashMapOf()
+ val propertyAssignmentValue: MutableMap<String, JsonNode> = hashMapOf()
val propertyAssignments: MutableMap<String, Any> =
bluePrintContext.nodeTemplateInterfaceOperationOutputs(nodeTemplateName, interfaceName, operationName) as? MutableMap<String, Any>
@@ -155,7 +251,7 @@ open class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var c
var resolvedValue: JsonNode = NullNode.getInstance()
if (propertyAssignment != null) {
// Resolve the Expressing
- val propertyAssignmentExpression = PropertyAssignmentService(context, this)
+ val propertyAssignmentExpression = PropertyAssignmentService(this)
resolvedValue = propertyAssignmentExpression.resolveAssignmentExpression(nodeTemplateName, nodeTypePropertyName, propertyAssignment)
} else {
// Assign default value to the Operation
@@ -173,131 +269,131 @@ open class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var c
return propertyAssignmentValue
}
- open fun resolveNodeTemplateArtifact(nodeTemplateName: String,
- artifactName: String): String {
+ override fun resolveNodeTemplateArtifact(nodeTemplateName: String,
+ artifactName: String): String {
val nodeTemplate = bluePrintContext.nodeTemplateByName(nodeTemplateName)
val artifactDefinition: ArtifactDefinition = nodeTemplate.artifacts?.get(artifactName)
?: throw BluePrintProcessorException(String.format("failed to get artifat definition {} from the node template"
, artifactName))
- val propertyAssignmentExpression = PropertyAssignmentService(context, this)
+ val propertyAssignmentExpression = PropertyAssignmentService(this)
return propertyAssignmentExpression.artifactContent(artifactDefinition)
}
- open fun setInputValue(propertyName: String, propertyDefinition: PropertyDefinition, value: JsonNode) {
+ override fun setInputValue(propertyName: String, propertyDefinition: PropertyDefinition, value: JsonNode) {
val path = StringBuilder(BluePrintConstants.PATH_INPUTS)
.append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString()
log.trace("setting input path ({}), values ({})", path, value)
- context[path] = value
+ put(path, value)
}
- open fun setWorkflowInputValue(workflowName: String, propertyName: String, value: JsonNode) {
+ override fun setWorkflowInputValue(workflowName: String, propertyName: String, propertyDefinition: PropertyDefinition, value: JsonNode) {
val path: String = StringBuilder(BluePrintConstants.PATH_NODE_WORKFLOWS).append(BluePrintConstants.PATH_DIVIDER).append(workflowName)
.append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INPUTS)
.append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES)
.append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString()
- context[path] = value
+ put(path, value)
}
- open fun setNodeTemplatePropertyValue(nodeTemplateName: String, propertyName: String, value: JsonNode) {
+ override fun setNodeTemplatePropertyValue(nodeTemplateName: String, propertyName: String, value: JsonNode) {
val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName)
.append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES)
.append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString()
- context[path] = value
+ put(path, value)
}
- open fun setNodeTemplateAttributeValue(nodeTemplateName: String, attributeName: String, value: JsonNode) {
+ override fun setNodeTemplateAttributeValue(nodeTemplateName: String, attributeName: String, value: JsonNode) {
val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName)
.append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_ATTRIBUTES)
.append(BluePrintConstants.PATH_DIVIDER).append(attributeName).toString()
- context[path] = value
+ put(path, value)
}
- open fun setNodeTemplateOperationPropertyValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String,
- value: JsonNode) {
+ override fun setNodeTemplateOperationPropertyValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String,
+ value: JsonNode) {
val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName)
.append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES).append(BluePrintConstants.PATH_DIVIDER).append(interfaceName)
.append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS).append(BluePrintConstants.PATH_DIVIDER).append(operationName)
.append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES)
.append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString()
log.trace("setting operation property path ({}), values ({})", path, value)
- context[path] = value
+ put(path, value)
}
- open fun setNodeTemplateOperationInputValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String,
- value: JsonNode) {
+ override fun setNodeTemplateOperationInputValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String,
+ value: JsonNode) {
val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName)
.append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES).append(BluePrintConstants.PATH_DIVIDER).append(interfaceName)
.append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS).append(BluePrintConstants.PATH_DIVIDER).append(operationName)
.append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INPUTS)
.append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES)
.append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString()
- context[path] = value
+ put(path, value)
}
- open fun setNodeTemplateOperationOutputValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String,
- value: JsonNode) {
+ override fun setNodeTemplateOperationOutputValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String,
+ value: JsonNode) {
val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName)
.append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES).append(BluePrintConstants.PATH_DIVIDER).append(interfaceName)
.append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS).append(BluePrintConstants.PATH_DIVIDER).append(operationName)
.append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OUTPUTS)
.append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES)
.append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString()
- context[path] = value
+ put(path, value)
}
- open fun getInputValue(propertyName: String): JsonNode {
+ override fun getInputValue(propertyName: String): JsonNode {
val path = StringBuilder(BluePrintConstants.PATH_INPUTS)
.append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString()
- return context[path] as? JsonNode ?: NullNode.instance
+ return getJsonNode(path)
}
- open fun getNodeTemplateOperationOutputValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String): JsonNode {
+ override fun getNodeTemplateOperationOutputValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String): JsonNode {
val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName)
.append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES).append(BluePrintConstants.PATH_DIVIDER).append(interfaceName)
.append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS).append(BluePrintConstants.PATH_DIVIDER).append(operationName)
.append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OUTPUTS).append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES)
.append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString()
- return context[path] as JsonNode
+ return getJsonNode(path)
}
- open fun getNodeTemplatePropertyValue(nodeTemplateName: String, propertyName: String): JsonNode? {
+ override fun getNodeTemplatePropertyValue(nodeTemplateName: String, propertyName: String): JsonNode {
val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName)
.append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES)
.append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString()
- return context[path] as JsonNode
+ return getJsonNode(path)
}
- open fun getNodeTemplateAttributeValue(nodeTemplateName: String, attributeName: String): JsonNode? {
+ override fun getNodeTemplateAttributeValue(nodeTemplateName: String, attributeName: String): JsonNode {
val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName)
.append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_ATTRIBUTES)
.append(BluePrintConstants.PATH_DIVIDER).append(attributeName).toString()
- return context[path] as JsonNode
+ return getJsonNode(path)
}
- open fun getNodeTemplateRequirementPropertyValue(nodeTemplateName: String, requirementName: String, propertyName:
- String): JsonNode? {
+ override fun getNodeTemplateRequirementPropertyValue(nodeTemplateName: String, requirementName: String, propertyName:
+ String): JsonNode {
val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName)
.append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_REQUIREMENTS).append(requirementName)
.append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES)
.append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString()
- return context[path] as JsonNode
+ return getJsonNode(path)
}
- open fun getNodeTemplateCapabilityPropertyValue(nodeTemplateName: String, capabilityName: String, propertyName:
- String): JsonNode? {
+ override fun getNodeTemplateCapabilityPropertyValue(nodeTemplateName: String, capabilityName: String, propertyName:
+ String): JsonNode {
val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName)
.append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_CAPABILITIES).append(capabilityName)
.append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES)
.append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString()
- return context[path] as JsonNode
+ return getJsonNode(path)
}
- open fun assignInputs(jsonNode: JsonNode) {
+ override fun assignInputs(jsonNode: JsonNode) {
log.info("assignInputs from input JSON ({})", jsonNode.toString())
bluePrintContext.inputs?.forEach { propertyName, property ->
val valueNode: JsonNode = jsonNode.at(BluePrintConstants.PATH_DIVIDER + propertyName)
@@ -306,27 +402,28 @@ open class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var c
}
}
- open fun assignWorkflowInputs(workflowName: String, jsonNode: JsonNode) {
+ override fun assignWorkflowInputs(workflowName: String, jsonNode: JsonNode) {
log.info("assign workflow {} input value ({})", workflowName, jsonNode.toString())
- bluePrintContext.workflowByName(workflowName)?.inputs?.forEach { propertyName, _ ->
+
+ bluePrintContext.workflowByName(workflowName).inputs?.forEach { propertyName, property ->
val valueNode: JsonNode = jsonNode.at(BluePrintConstants.PATH_DIVIDER + propertyName)
?: NullNode.getInstance()
- setWorkflowInputValue(workflowName, propertyName, valueNode)
+ setInputValue(propertyName, property, valueNode)
}
}
- open fun getJsonForNodeTemplateAttributeProperties(nodeTemplateName: String, keys: List<String>): JsonNode {
+ override fun getJsonForNodeTemplateAttributeProperties(nodeTemplateName: String, keys: List<String>): JsonNode {
val jsonNode: ObjectNode = jacksonObjectMapper().createObjectNode()
val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName)
.append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_ATTRIBUTES)
.append(BluePrintConstants.PATH_DIVIDER).toString()
- context.keys.filter {
+ store.keys.filter {
it.startsWith(path)
}.map {
val key = it.replace(path, "")
if (keys.contains(key)) {
- val value = context[it] as JsonNode
+ val value = store[it] as JsonNode
jsonNode.set(key, value)
}
}
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 131bb30a..5b511f15 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
@@ -18,6 +18,8 @@
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.NullNode
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
@@ -26,19 +28,16 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.*
import org.onap.ccsdk.apps.controllerblueprints.core.format
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
import org.onap.ccsdk.apps.controllerblueprints.core.utils.ResourceResolverUtils
-import com.att.eelf.configuration.EELFLogger
-import com.att.eelf.configuration.EELFManager
/**
*
*
* @author Brinda Santh
*/
-class PropertyAssignmentService(var context: MutableMap<String, Any>,
- var bluePrintRuntimeService: BluePrintRuntimeService) {
+class PropertyAssignmentService(var bluePrintRuntimeService: BluePrintRuntimeService<MutableMap<String, JsonNode>>) {
private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())
- private var bluePrintContext: BluePrintContext = bluePrintRuntimeService.bluePrintContext
+ private var bluePrintContext: BluePrintContext = bluePrintRuntimeService.bluePrintContext()
/*
@@ -198,7 +197,7 @@ If Property Assignment is Expression.
}
fun artifactContent(artifactDefinition: ArtifactDefinition): String {
- val bluePrintBasePath: String = context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] as? String
+ val bluePrintBasePath: String = bluePrintRuntimeService.get(BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH) as? String
?: throw BluePrintException(format("failed to get property (%s) from context", BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH))
if (artifactDefinition.repository != null) {
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 b7f9fc7e..43d55fea 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
@@ -17,11 +17,16 @@
package org.onap.ccsdk.apps.controllerblueprints.core.utils
+import com.att.eelf.configuration.EELFLogger
+import com.att.eelf.configuration.EELFManager
+import com.fasterxml.jackson.databind.JsonNode
import org.apache.commons.io.FileUtils
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive
import org.onap.ccsdk.apps.controllerblueprints.core.data.ToscaMetaData
-import com.att.eelf.configuration.EELFLogger
-import com.att.eelf.configuration.EELFManager
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
+import org.onap.ccsdk.apps.controllerblueprints.core.service.DefaultBluePrintRuntimeService
import java.io.File
import java.nio.charset.Charset
@@ -57,39 +62,46 @@ object BluePrintMetadataUtils {
return toscaMetaData
}
- /*
+ @JvmStatic
fun getBluePrintContext(blueprintBasePath: String): BluePrintContext {
- val metaDataFile = StringBuilder().append(blueprintBasePath).append(File.separator)
- .append(BluePrintConstants.DEFAULT_TOSCA_METADATA_ENTRY_DEFINITION_FILE).toString()
-
- val toscaMetaData: ToscaMetaData = BluePrintMetadataUtils.toscaMetaData(metaDataFile)
+ val toscaMetaData: ToscaMetaData = toscaMetaData(blueprintBasePath)
- log.info("Processing blueprint base path ({}) and entry definition file ({})", blueprintBasePath, toscaMetaData.entityDefinitions)
+ log.info("Processing blueprint base path ($blueprintBasePath) and entry definition file (${toscaMetaData.entityDefinitions})")
- return BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!!
- .readBlueprintFile(toscaMetaData.entityDefinitions!!, blueprintBasePath)
+ return readBlueprintFile(toscaMetaData.entityDefinitions, blueprintBasePath)
}
- fun getBluePrintRuntime(requestId: String, blueprintBasePath: String): BluePrintRuntimeService {
-
- val metaDataFile = StringBuilder().append(blueprintBasePath).append(File.separator)
- .append(BluePrintConstants.DEFAULT_TOSCA_METADATA_ENTRY_DEFINITION_FILE).toString()
-
- val toscaMetaData: ToscaMetaData = BluePrintMetadataUtils.toscaMetaData(metaDataFile)
+ @JvmStatic
+ fun getBluePrintRuntime(id: String, blueprintBasePath: String): BluePrintRuntimeService<MutableMap<String, JsonNode>> {
- log.info("Processing blueprint base path ({}) and entry definition file ({})", blueprintBasePath, toscaMetaData.entityDefinitions)
+ val bluePrintContext: BluePrintContext = getBluePrintContext(blueprintBasePath)
- val bluePrintContext: BluePrintContext = BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!!
- .readBlueprintFile(toscaMetaData.entityDefinitions!!, 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, Any> = hashMapOf()
- context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = blueprintBasePath
- context[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = requestId
+ val bluePrintRuntimeService = DefaultBluePrintRuntimeService(id, bluePrintContext)
+ bluePrintRuntimeService.setExecutionContext(context)
- val bluePrintRuntimeService: BluePrintRuntimeService = BluePrintRuntimeService(bluePrintContext, context)
+ 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
}
- */
+
+ @JvmStatic
+ fun readBlueprintFile(entityDefinitions: String, basePath: String): BluePrintContext {
+ val rootFilePath: String = basePath.plus(File.separator).plus(entityDefinitions)
+ val rootServiceTemplate = ServiceTemplateUtils.getServiceTemplate(rootFilePath)
+ // TODO ("Fix for Multiple Service Template file definitions")
+// val schemaImportResolverUtils = BluePrintResolverService(rootServiceTemplate, basePath)
+// val completeServiceTemplate = schemaImportResolverUtils.getImportResolvedServiceTemplate()
+ return BluePrintContext(rootServiceTemplate)
+ }
} \ No newline at end of file
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintRuntimeUtils.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintRuntimeUtils.kt
index 0e4c3e3e..4501275c 100644
--- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintRuntimeUtils.kt
+++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintRuntimeUtils.kt
@@ -16,12 +16,12 @@
package org.onap.ccsdk.apps.controllerblueprints.core.utils
+import com.att.eelf.configuration.EELFLogger
+import com.att.eelf.configuration.EELFManager
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.node.NullNode
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
-import com.att.eelf.configuration.EELFLogger
-import com.att.eelf.configuration.EELFManager
/**
*
@@ -31,17 +31,23 @@ import com.att.eelf.configuration.EELFManager
object BluePrintRuntimeUtils {
private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())
- fun assignInputsFromFile(bluePrintContext: BluePrintContext, fileName: String, context: MutableMap<String, Any>) {
+ fun assignInputsFromFile(bluePrintContext: BluePrintContext, fileName: String, context: MutableMap<String, JsonNode>) {
val jsonNode: JsonNode = JacksonUtils.jsonNodeFromFile(fileName)
return assignInputs(bluePrintContext, jsonNode, context)
}
- fun assignInputsFromContent(bluePrintContext: BluePrintContext, content: String, context: MutableMap<String, Any>) {
+ fun assignInputsFromClassPathFile(bluePrintContext: BluePrintContext, fileName: String, context: MutableMap<String,
+ JsonNode>) {
+ val jsonNode = JacksonUtils.jsonNodeFromClassPathFile(fileName)
+ return assignInputs(bluePrintContext, jsonNode, context)
+ }
+
+ fun assignInputsFromContent(bluePrintContext: BluePrintContext, content: String, context: MutableMap<String, JsonNode>) {
val jsonNode: JsonNode = JacksonUtils.jsonNode(content)
return assignInputs(bluePrintContext, jsonNode, context)
}
- fun assignInputs(bluePrintContext: BluePrintContext, jsonNode: JsonNode, context: MutableMap<String, Any>) {
+ fun assignInputs(bluePrintContext: BluePrintContext, jsonNode: JsonNode, context: MutableMap<String, JsonNode>) {
log.info("assignInputs from input JSON ({})", jsonNode.toString())
bluePrintContext.inputs?.forEach { propertyName, _ ->
val valueNode: JsonNode = jsonNode.at("/".plus(propertyName)) ?: NullNode.getInstance()
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/TopologicalSortingUtils.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/TopologicalSortingUtils.kt
index dcafa974..9d6fe084 100644
--- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/TopologicalSortingUtils.kt
+++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/TopologicalSortingUtils.kt
@@ -64,7 +64,7 @@ class TopologicalSortingUtils<V> {
}
fun outDegree(): Map<V, Int> {
- var result: MutableMap<V, Int> = hashMapOf()
+ val result: MutableMap<V, Int> = hashMapOf()
for (v in neighbors.keys)
result[v] = neighbors[v]!!.size
return result
@@ -108,7 +108,7 @@ class TopologicalSortingUtils<V> {
fun bfsDistance(start: V): Map<*, *> {
- var distance: MutableMap<V, Int> = hashMapOf()
+ val distance: MutableMap<V, Int> = hashMapOf()
// Initially, all distance are infinity, except start node
for (v in neighbors.keys)
distance[v] = -1
diff --git a/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt
index f1980d27..68031d29 100644
--- a/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt
+++ b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt
@@ -17,16 +17,16 @@
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 org.junit.Before
import org.junit.Test
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
-import org.onap.ccsdk.apps.controllerblueprints.core.factory.BluePrintParserFactory
+import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive
+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.jsonNodeFromFile
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils.jsonNodeFromObject
-import com.att.eelf.configuration.EELFLogger
-import com.att.eelf.configuration.EELFManager
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
@@ -37,13 +37,6 @@ import kotlin.test.assertNotNull
*/
class BluePrintRuntimeServiceTest {
private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())
- val basepath = "load/blueprints"
-
-
- @Before
- fun setUp(): Unit {
-
- }
@Test
fun testResolveNodeTemplateProperties() {
@@ -56,40 +49,32 @@ class BluePrintRuntimeServiceTest {
val inputNode: JsonNode = jsonNodeFromFile(inputDataPath)
bluePrintRuntimeService.assignInputs(inputNode)
- val propContext: MutableMap<String, Any?> = bluePrintRuntimeService.resolveNodeTemplateProperties("resource-assignment-action")
- log.info("Context {}", bluePrintRuntimeService.context)
+ val propContext: MutableMap<String, JsonNode> = bluePrintRuntimeService.resolveNodeTemplateProperties("resource-assignment-action")
assertNotNull(propContext, "Failed to populate interface property values")
- assertEquals(propContext.get("mode"), jsonNodeFromObject("sync"), "Failed to populate parameter process-name")
- assertEquals(propContext.get("version"), jsonNodeFromObject("1.0.0"), "Failed to populate parameter version")
+ assertEquals(propContext.get("mode"), "sync".asJsonPrimitive(), "Failed to populate parameter process-name")
+ assertEquals(propContext.get("version"), "1.0.0".asJsonPrimitive(), "Failed to populate parameter version")
}
@Test
fun testResolveNodeTemplateInterfaceOperationInputs() {
log.info("************************ testResolveNodeTemplateInterfaceOperationInputs **********************")
- val bluePrintContext: BluePrintContext = BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!!
- .readBlueprintFile("baseconfiguration/Definitions/activation-blueprint.json", basepath)
- assertNotNull(bluePrintContext, "Failed to populate Blueprint context")
-
- val context: MutableMap<String, Any> = hashMapOf()
- context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = basepath.plus("/simple-baseconfig")
-
- val inputDataPath = "src/test/resources/data/default-context.json"
- BluePrintRuntimeUtils.assignInputsFromFile(bluePrintContext, inputDataPath, context)
+ val bluePrintRuntimeService = getBluePrintRuntimeService()
- val bluePrintRuntimeService = BluePrintRuntimeService(bluePrintContext, context)
+ val executionContext = bluePrintRuntimeService.getExecutionContext()
- log.info("Prepared Context {}", context)
+ BluePrintRuntimeUtils.assignInputsFromClassPathFile(bluePrintRuntimeService.bluePrintContext(),
+ "data/default-context.json", executionContext)
- val inContext: MutableMap<String, Any?> = bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationInputs("resource-assignment-ra-component",
+ val inContext: MutableMap<String, JsonNode> = bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationInputs("resource-assignment-ra-component",
"org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode", "process")
log.info("In Context {}", inContext)
assertNotNull(inContext, "Failed to populate interface input property values")
- assertEquals(inContext.get("action-name"), jsonNodeFromObject("sample-action"), "Failed to populate parameter action-name")
- assertEquals(inContext.get("request-id"), jsonNodeFromObject("12345"), "Failed to populate parameter action-name")
+ assertEquals(inContext.get("action-name"), "sample-action".asJsonPrimitive(), "Failed to populate parameter action-name")
+ assertEquals(inContext.get("request-id"), "12345".asJsonPrimitive(), "Failed to populate parameter action-name")
}
@Test
@@ -129,8 +114,6 @@ class BluePrintRuntimeServiceTest {
bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment-ra-component", "context2",
jsonNodeFromObject("context2-value"))
- log.info("Context {}", bluePrintRuntimeService.context)
-
val keys = listOf("context1", "context2")
val jsonValueNode = bluePrintRuntimeService.getJsonForNodeTemplateAttributeProperties("resource-assignment-ra-component", keys)
@@ -139,15 +122,14 @@ class BluePrintRuntimeServiceTest {
}
- private fun getBluePrintRuntimeService(): BluePrintRuntimeService {
- val bluePrintContext: BluePrintContext = BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!!
- .readBlueprintFile("baseconfiguration/Definitions/activation-blueprint.json", basepath)
- assertNotNull(bluePrintContext, "Failed to populate Blueprint context")
+ private fun getBluePrintRuntimeService(): BluePrintRuntimeService<MutableMap<String, JsonNode>> {
+ val blueprintBasePath: String = ("load/blueprints/baseconfiguration")
+ val blueprintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath)
+ val checkBasePath = blueprintRuntime.get(BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH)
- val context: MutableMap<String, Any> = hashMapOf()
- context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = basepath.plus("/simple-baseconfig")
+ assertEquals(blueprintBasePath.asJsonPrimitive(), checkBasePath, "Failed to get base path after runtime creation")
- return BluePrintRuntimeService(bluePrintContext, context)
+ return blueprintRuntime
}
} \ No newline at end of file
diff --git a/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtilsTest.kt b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtilsTest.kt
index d13caa52..c5f451ea 100644
--- a/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtilsTest.kt
+++ b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtilsTest.kt
@@ -35,7 +35,7 @@ class JacksonReactorUtilsTest {
assertNotNull(serviceTemplate, "Failed to simple transform Service Template")
assertEquals(true, serviceTemplate is ServiceTemplate, "failed to get Service Template instance")
- val jsonContent = JacksonReactorUtils.getJson(serviceTemplate!!, true).block()
+ val jsonContent = JacksonReactorUtils.getJson(serviceTemplate, true).block()
assertNotNull(jsonContent, "Failed to get json content")
val jsonNode = JacksonReactorUtils.jsonNodeFromFile("load/blueprints/baseconfiguration/Definitions/activation-blueprint.json")
diff --git a/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtilsTest.kt b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtilsTest.kt
index a5a630e3..c3718b27 100644
--- a/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtilsTest.kt
+++ b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtilsTest.kt
@@ -44,7 +44,7 @@ class JacksonUtilsTest {
assertNotNull(serviceTemplate, "Failed to simple transform Service Template")
assertEquals(true, serviceTemplate is ServiceTemplate, "failed to get Service Template instance")
- val jsonContent = JacksonUtils.getJson(serviceTemplate!!, true)
+ val jsonContent = JacksonUtils.getJson(serviceTemplate, true)
assertNotNull(jsonContent, "Failed to get json content")
}
diff --git a/components/core/src/test/resources/properties/convert.json b/components/core/src/test/resources/properties/convert.json
index af79915f..966b0253 100644
--- a/components/core/src/test/resources/properties/convert.json
+++ b/components/core/src/test/resources/properties/convert.json
@@ -1,33 +1,36 @@
{
- "type": "sdnc-component-getResourceAssignment",
- "interfaces": {
- "ResourceAssignmentService": {
- "operations": {
- "getResourceAssignment": {
- "inputs": {
- "assignment-mappings": [
- {
- "name": "service-name",
- "mapping-field": "service",
- "mapping-category": "SDN",
- "required": true
- },
- {
- "name": "region-name",
- "mapping-field": "region",
- "mapping-category": "SDN",
- "required": true
- }
- ],
- "pre-data": { "get_input" : "get-resource-assignment.config-params" },
- "prifix": "get-resource-assignment"
- },
- "outputs": {
- "resource-assignment-status": "success",
- "resource-assignment-params": "{ \"set_value\" : \"get-resource-assignment.config-params" }
- }
- }
- }
- }
- }
+ "type": "sdnc-component-getResourceAssignment",
+ "interfaces": {
+ "ResourceAssignmentService": {
+ "operations": {
+ "getResourceAssignment": {
+ "inputs": {
+ "assignment-mappings": [
+ {
+ "name": "service-name",
+ "mapping-field": "service",
+ "mapping-category": "SDN",
+ "required": true
+ },
+ {
+ "name": "region-name",
+ "mapping-field": "region",
+ "mapping-category": "SDN",
+ "required": true
+ }
+ ],
+ "pre-data": {
+ "get_input": "get-resource-assignment.config-params"
+ },
+ "prifix": "get-resource-assignment"
+ },
+ "outputs": {
+ "resource-assignment-status": "success",
+ "resource-assignment-params": "{ \"set_value\" : \"get-resource-assignment.config-params"
+ }
+ }
+ }
+ }
+ }
}
+