summaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints
diff options
context:
space:
mode:
Diffstat (limited to 'ms/controllerblueprints')
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/AbstractNodeTemplateImplBuilder.kt26
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTemplateDSLBuilder.kt101
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLTest.kt57
3 files changed, 154 insertions, 30 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/AbstractNodeTemplateImplBuilder.kt
new file mode 100644
index 000000000..7ab139070
--- /dev/null
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/AbstractNodeTemplateImplBuilder.kt
@@ -0,0 +1,26 @@
+/*
+ * Copyright © 2019 IBM.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.cds.controllerblueprints.core.dsl
+
+abstract class AbstractNodeTemplateImplBuilder<In : PropertiesAssignmentBuilder, Out : PropertiesAssignmentBuilder>(
+ id: String, type: String, private val interfaceName: String, description: String
+) : NodeTemplateBuilder(id, type, description) {
+
+ open fun operation(description: String, block: OperationAssignmentBuilder<In, Out>.() -> Unit) {
+ typedOperation<In, Out>(interfaceName, description, 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 93b6f4e4e..b3aaabe38 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
@@ -20,6 +20,9 @@ import com.fasterxml.jackson.databind.JsonNode
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType
import org.onap.ccsdk.cds.controllerblueprints.core.data.*
+import kotlin.reflect.KClass
+import kotlin.reflect.full.createInstance
+import kotlin.reflect.jvm.reflect
class TopologyTemplateBuilder {
private var topologyTemplate = TopologyTemplate()
@@ -39,7 +42,8 @@ class TopologyTemplateBuilder {
}
fun nodeTemplateOperation(nodeTemplateName: String, type: String, interfaceName: String, description: String,
- operationBlock: OperationAssignmentBuilder.() -> Unit) {
+ operationBlock: OperationAssignmentBuilder<PropertiesAssignmentBuilder,
+ PropertiesAssignmentBuilder>.() -> Unit) {
if (nodeTemplates == null)
nodeTemplates = hashMapOf()
@@ -84,9 +88,9 @@ class TopologyTemplateBuilder {
}
}
-class NodeTemplateBuilder(private val id: String,
- private val type: String,
- private val description: String? = "") {
+open class NodeTemplateBuilder(private val id: String,
+ private val type: String,
+ private val description: String? = "") {
private var nodeTemplate: NodeTemplate = NodeTemplate()
private var properties: MutableMap<String, JsonNode>? = null
private var interfaces: MutableMap<String, InterfaceAssignment>? = null
@@ -94,14 +98,19 @@ class NodeTemplateBuilder(private val id: String,
private var capabilities: MutableMap<String, CapabilityAssignment>? = null
private var requirements: MutableMap<String, RequirementAssignment>? = null
+ fun properties(properties: MutableMap<String, JsonNode>?) {
+ this.properties = properties
+ }
+
fun properties(block: PropertiesAssignmentBuilder.() -> Unit) {
if (properties == null)
properties = hashMapOf()
properties = PropertiesAssignmentBuilder().apply(block).build()
}
- fun operation(interfaceName: String, description: String? = "",
- block: OperationAssignmentBuilder.() -> Unit) {
+ open fun <In : PropertiesAssignmentBuilder, Out : PropertiesAssignmentBuilder> typedOperation(
+ interfaceName: String, description: String = "",
+ block: OperationAssignmentBuilder<In, Out>.() -> Unit) {
if (interfaces == null)
interfaces = hashMapOf()
@@ -109,10 +118,15 @@ class NodeTemplateBuilder(private val id: String,
val defaultOperationName = BluePrintConstants.DEFAULT_STEP_OPERATION
interfaceAssignment.operations = hashMapOf()
interfaceAssignment.operations!![defaultOperationName] =
- OperationAssignmentBuilder(defaultOperationName, description).apply(block).build()
+ OperationAssignmentBuilder<In, Out>(defaultOperationName, description).apply(block).build()
interfaces!![interfaceName] = interfaceAssignment
}
+ fun operation(interfaceName: String, description: String,
+ block: OperationAssignmentBuilder<PropertiesAssignmentBuilder, PropertiesAssignmentBuilder>.() -> Unit) {
+ typedOperation<PropertiesAssignmentBuilder, PropertiesAssignmentBuilder>(interfaceName, description, block)
+ }
+
fun artifact(id: String, type: String, file: String) {
if (artifacts == null)
artifacts = hashMapOf()
@@ -190,10 +204,10 @@ class ArtifactDefinitionBuilder(private val id: String, private val type: String
}
}
-class CapabilityAssignmentBuilder(private val id: String) {
- private var capabilityAssignment: CapabilityAssignment = CapabilityAssignment()
- private var attributes: MutableMap<String, JsonNode>? = null
- private var properties: MutableMap<String, JsonNode>? = null
+open class CapabilityAssignmentBuilder(private val id: String) {
+ var capabilityAssignment: CapabilityAssignment = CapabilityAssignment()
+ var attributes: MutableMap<String, JsonNode>? = null
+ var properties: MutableMap<String, JsonNode>? = null
fun attributes(block: AttributesAssignmentBuilder.() -> Unit) {
if (attributes == null)
@@ -214,9 +228,9 @@ class CapabilityAssignmentBuilder(private val id: String) {
}
}
-class RequirementAssignmentBuilder(private val id: String, private val capability: String,
- private val node: String,
- private val relationship: String) {
+open class RequirementAssignmentBuilder(private val id: String, private val capability: String,
+ private val node: String,
+ private val relationship: String) {
private var requirementAssignment: RequirementAssignment = RequirementAssignment()
fun build(): RequirementAssignment {
@@ -233,10 +247,12 @@ class InterfaceAssignmentBuilder(private val id: String) {
private var interfaceAssignment: InterfaceAssignment = InterfaceAssignment()
private var operations: MutableMap<String, OperationAssignment>? = null
- fun operation(id: String, description: String? = "", block: OperationAssignmentBuilder.() -> Unit) {
+ fun operation(id: String, description: String? = "",
+ block: OperationAssignmentBuilder<PropertiesAssignmentBuilder, PropertiesAssignmentBuilder>.() -> Unit) {
if (operations == null)
operations = hashMapOf()
- operations!![id] = OperationAssignmentBuilder(id, description).apply(block).build()
+ operations!![id] = OperationAssignmentBuilder<PropertiesAssignmentBuilder, PropertiesAssignmentBuilder>(
+ id, description).apply(block).build()
}
fun build(): InterfaceAssignment {
@@ -246,8 +262,9 @@ class InterfaceAssignmentBuilder(private val id: String) {
}
}
-class OperationAssignmentBuilder(private val id: String,
- private val description: String? = "") {
+class OperationAssignmentBuilder<In : PropertiesAssignmentBuilder, Out : PropertiesAssignmentBuilder>(
+ private val id: String,
+ private val description: String? = "") {
private var operationAssignment: OperationAssignment = OperationAssignment()
@@ -256,27 +273,33 @@ class OperationAssignmentBuilder(private val id: String,
}
fun implementation(timeout: Int, operationHost: String? = BluePrintConstants.PROPERTY_SELF) {
- val implementation = Implementation().apply {
+ operationAssignment.implementation = Implementation().apply {
this.operationHost = operationHost!!
this.timeout = timeout
}
- operationAssignment.implementation = implementation
+ }
+
+ fun implementation(timeout: Int, operationHost: String? = BluePrintConstants.PROPERTY_SELF,
+ block: ImplementationBuilder.() -> Unit) {
+ operationAssignment.implementation = ImplementationBuilder(timeout, operationHost!!).apply(block).build()
}
fun inputs(inputs: MutableMap<String, JsonNode>?) {
operationAssignment.inputs = inputs
}
- fun inputs(block: PropertiesAssignmentBuilder.() -> Unit) {
- operationAssignment.inputs = PropertiesAssignmentBuilder().apply(block).build()
+ fun inputs(block: In.() -> Unit) {
+ val instance: In = (block.reflect()?.parameters?.get(0)?.type?.classifier as KClass<In>).createInstance()
+ operationAssignment.inputs = instance.apply(block).build()
}
fun outputs(outputs: MutableMap<String, JsonNode>?) {
operationAssignment.outputs = outputs
}
- fun outputs(block: PropertiesAssignmentBuilder.() -> Unit) {
- operationAssignment.outputs = PropertiesAssignmentBuilder().apply(block).build()
+ fun outputs(block: Out.() -> Unit) {
+ val instance: Out = (block.reflect()?.parameters?.get(0)?.type?.classifier as KClass<Out>).createInstance()
+ operationAssignment.outputs = instance.apply(block).build()
}
fun build(): OperationAssignment {
@@ -286,8 +309,30 @@ class OperationAssignmentBuilder(private val id: String,
}
}
-class PropertiesAssignmentBuilder {
- private var properties: MutableMap<String, JsonNode> = hashMapOf()
+class ImplementationBuilder(private val timeout: Int, private val operationHost: String) {
+ private val implementation = Implementation()
+
+ fun primary(primary: String) {
+ implementation.primary = primary
+ }
+
+ fun dependencies(vararg dependencies: String) {
+ if (implementation.dependencies == null)
+ implementation.dependencies = arrayListOf()
+ dependencies.forEach {
+ implementation.dependencies!!.add(it)
+ }
+ }
+
+ fun build(): Implementation {
+ implementation.timeout = timeout
+ implementation.operationHost = operationHost
+ return implementation
+ }
+}
+
+open class PropertiesAssignmentBuilder {
+ var properties: MutableMap<String, JsonNode> = hashMapOf()
fun property(id: String, value: Any) {
property(id, value.asJsonType())
@@ -302,8 +347,8 @@ class PropertiesAssignmentBuilder {
}
}
-class AttributesAssignmentBuilder {
- private var attributes: MutableMap<String, JsonNode> = hashMapOf()
+open class AttributesAssignmentBuilder {
+ var attributes: MutableMap<String, JsonNode> = hashMapOf()
fun attribute(id: String, value: String) {
attribute(id, value.asJsonType())
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 c0641be69..e5f1cbf5d 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
@@ -16,9 +16,12 @@
package org.onap.ccsdk.cds.controllerblueprints.core.dsl
+import com.fasterxml.jackson.databind.JsonNode
import org.junit.Test
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
+import org.onap.ccsdk.cds.controllerblueprints.core.asJsonString
+import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate
import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType
import kotlin.test.assertNotNull
@@ -94,6 +97,10 @@ class BluePrintDSLTest {
topologyTemplate {
nodeTemplateOperation(nodeTemplateName = "activate", type = "sample-node-type", interfaceName = "RestconfExecutor",
description = "sample activation") {
+ implementation(360, "SELF") {
+ primary("Scripts/sample.py")
+ dependencies("one", "two")
+ }
inputs {
property("json-content", """{ "name" : "cds"}""")
property("array-content", """["controller", "blueprints"]""")
@@ -150,7 +157,7 @@ class BluePrintDSLTest {
assertNotNull(serviceTemplate.topologyTemplate, "failed to get topology template")
assertNotNull(serviceTemplate.topologyTemplate?.nodeTemplates, "failed to get nodeTypes")
assertNotNull(serviceTemplate.topologyTemplate?.nodeTemplates!!["activate"], "failed to get nodeTypes(activate)")
- //println(serviceTemplate.asJsonString(true))
+ println(serviceTemplate.asJsonString(true))
}
@Test
@@ -185,7 +192,7 @@ class BluePrintDSLTest {
}
}
assertNotNull(nodeType, "failed to get nodeType")
- // println(nodeType.asJsonString(true))
+ // println(nodeType.asJsonString(true))
}
@Test
@@ -207,4 +214,50 @@ class BluePrintDSLTest {
//println(serviceTemplate.asJsonString(true))
}
+ @Test
+ fun testNodeTemplateOperationTypes() {
+
+ val testNodeTemplateInstance = BluePrintTypes.nodeTemplateComponentTestExecutor(id = "test-node-template",
+ description = "") {
+ operation("") {
+ implementation(360)
+ inputs {
+ request("i am request")
+ }
+ outputs {
+ response(getAttribute("attribute1"))
+ }
+ }
+ }
+ assertNotNull(testNodeTemplateInstance, "failed to get test node template")
+ //println(testNodeTemplateInstance.asJsonString(true))
+ }
+}
+
+fun BluePrintTypes.nodeTemplateComponentTestExecutor(id: String,
+ description: String,
+ block: TestNodeTemplateImplBuilder.() -> Unit)
+ : NodeTemplate {
+ return TestNodeTemplateImplBuilder(id, description).apply(block).build()
+}
+
+class TestNodeTemplateImplBuilder(id: String, description: String) :
+ AbstractNodeTemplateImplBuilder<TestInput, TestOutput>(id, "component-test-executor",
+ "ComponentTestExecutor",
+ description)
+
+class TestInput : PropertiesAssignmentBuilder() {
+ fun request(request: String) {
+ property("request", request.asJsonPrimitive())
+ }
+}
+
+class TestOutput : PropertiesAssignmentBuilder() {
+ fun response(response: String) {
+ response(response.asJsonPrimitive())
+ }
+
+ fun response(response: JsonNode) {
+ property("response", response)
+ }
}