summaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints/modules/blueprint-core
diff options
context:
space:
mode:
authorBrinda Santh <brindasanth@in.ibm.com>2019-08-01 21:00:05 -0400
committerDan Timoney <dtimoney@att.com>2019-08-09 20:03:06 +0000
commit2d879240396861aa253dd65b2476f35a2ffc0493 (patch)
tree8d21c269942cd4ef708f915c79dc5e3f28a90698 /ms/controllerblueprints/modules/blueprint-core
parentf48dcc232cfd6e7c11c1155a58f6017d3a71c007 (diff)
Add property definition type DSL.
Change-Id: I83a3d1391c60cd426236b55d0d399e273e7c15dc Issue-ID: CCSDK-1577 Signed-off-by: Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/controllerblueprints/modules/blueprint-core')
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/AbstractNodeTemplateOperationImplBuilder.kt (renamed from ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/AbstractNodeTemplateImplBuilder.kt)16
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTemplateDSLBuilder.kt7
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLTest.kt24
3 files changed, 39 insertions, 8 deletions
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/AbstractNodeTemplateImplBuilder.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/AbstractNodeTemplateOperationImplBuilder.kt
index 7ab139070..182d9a050 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/AbstractNodeTemplateImplBuilder.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/AbstractNodeTemplateOperationImplBuilder.kt
@@ -16,11 +16,21 @@
package org.onap.ccsdk.cds.controllerblueprints.core.dsl
-abstract class AbstractNodeTemplateImplBuilder<In : PropertiesAssignmentBuilder, Out : PropertiesAssignmentBuilder>(
+abstract class AbstractNodeTemplateOperationImplBuilder<Prop : PropertiesAssignmentBuilder,
+ In : PropertiesAssignmentBuilder, Out : PropertiesAssignmentBuilder>(
id: String, type: String, private val interfaceName: String, description: String
-) : NodeTemplateBuilder(id, type, description) {
+) : AbstractNodeTemplatePropertyImplBuilder<Prop>(id, type, description) {
- open fun operation(description: String, block: OperationAssignmentBuilder<In, Out>.() -> Unit) {
+ open fun definedOperation(description: String, block: OperationAssignmentBuilder<In, Out>.() -> Unit) {
typedOperation<In, Out>(interfaceName, description, block)
}
}
+
+abstract class AbstractNodeTemplatePropertyImplBuilder<Prop : PropertiesAssignmentBuilder>(
+ id: String, type: String, description: String
+) : NodeTemplateBuilder(id, type, description) {
+
+ open fun definedProperties(block: Prop.() -> Unit) {
+ typedProperties<Prop>(block)
+ }
+}
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTemplateDSLBuilder.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTemplateDSLBuilder.kt
index 685473f08..7f49a99c6 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTemplateDSLBuilder.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTemplateDSLBuilder.kt
@@ -108,6 +108,13 @@ open class NodeTemplateBuilder(private val id: String,
properties = PropertiesAssignmentBuilder().apply(block).build()
}
+ open fun <Prop : PropertiesAssignmentBuilder> typedProperties(block: Prop.() -> Unit) {
+ if (properties == null)
+ properties = hashMapOf()
+ val instance: Prop = (block.reflect()?.parameters?.get(0)?.type?.classifier as KClass<Prop>).createInstance()
+ properties = instance.apply(block).build()
+ }
+
open fun <In : PropertiesAssignmentBuilder, Out : PropertiesAssignmentBuilder> typedOperation(
interfaceName: String, description: String = "",
block: OperationAssignmentBuilder<In, Out>.() -> Unit) {
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLTest.kt
index ba2f07072..ec8f24d85 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLTest.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLTest.kt
@@ -218,7 +218,11 @@ class BluePrintDSLTest {
val testNodeTemplateInstance = BluePrintTypes.nodeTemplateComponentTestExecutor(id = "test-node-template",
description = "") {
- operation("") {
+ definedProperties {
+ prop1("i am property1")
+ prop2("i am property2")
+ }
+ definedOperation("") {
implementation(360)
inputs {
request("i am request")
@@ -235,16 +239,26 @@ class BluePrintDSLTest {
fun BluePrintTypes.nodeTemplateComponentTestExecutor(id: String,
description: String,
- block: TestNodeTemplateImplBuilder.() -> Unit)
+ block: TestNodeTemplateOperationImplBuilder.() -> Unit)
: NodeTemplate {
- return TestNodeTemplateImplBuilder(id, description).apply(block).build()
+ return TestNodeTemplateOperationImplBuilder(id, description).apply(block).build()
}
-class TestNodeTemplateImplBuilder(id: String, description: String) :
- AbstractNodeTemplateImplBuilder<TestInput, TestOutput>(id, "component-test-executor",
+class TestNodeTemplateOperationImplBuilder(id: String, description: String) :
+ AbstractNodeTemplateOperationImplBuilder<TestProperty, TestInput, TestOutput>(id, "component-test-executor",
"ComponentTestExecutor",
description)
+class TestProperty : PropertiesAssignmentBuilder() {
+ fun prop1(prop1: String) {
+ property("prop1", prop1.asJsonPrimitive())
+ }
+
+ fun prop2(prop2: String) {
+ property("prop2", prop2.asJsonPrimitive())
+ }
+}
+
class TestInput : PropertiesAssignmentBuilder() {
fun request(request: String) {
property("request", request.asJsonPrimitive())