From 54c3633cadf1cd087efa7af6acdf54ae47a4759a Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Fri, 2 Aug 2019 12:08:54 -0400 Subject: Add resource assignment DSL. Change-Id: I44a3596c05b02faa171f90b9207f774ce34976a6 Issue-ID: CCSDK-1577 Signed-off-by: Brinda Santh --- .../resource/resolution/ResourceDefinitionDSL.kt | 96 ++++++++++++++++-- .../resolution/ResourceDefinitionDSLTest.kt | 111 +++++++++++++++++++++ .../resolution/ResourceDefinitionSDLTest.kt | 78 --------------- 3 files changed, 200 insertions(+), 85 deletions(-) create mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceDefinitionDSLTest.kt delete mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceDefinitionSDLTest.kt (limited to 'ms/blueprintsprocessor/functions/resource-resolution/src') diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceDefinitionDSL.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceDefinitionDSL.kt index 340894f1b..a48762832 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceDefinitionDSL.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceDefinitionDSL.kt @@ -19,15 +19,50 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertyDefinitionBuilder +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition /** Resource Definition DSL **/ -fun BluePrintTypes.resourceDefinition(name: String, +fun BluePrintTypes.resourceDefinitions(block: ResourceDefinitionsBuilder.() -> Unit) + : MutableMap { + return ResourceDefinitionsBuilder().apply(block).build() +} + +fun BluePrintTypes.resourceDefinition(name: String, description: String, block: ResourceDefinitionBuilder.() -> Unit): ResourceDefinition { - return ResourceDefinitionBuilder(name).apply(block).build() + return ResourceDefinitionBuilder(name, description).apply(block).build() +} + +/** Resource Mapping DSL **/ +fun BluePrintTypes.resourceAssignments(block: ResourceAssignmentsBuilder.() -> Unit) + : MutableMap { + return ResourceAssignmentsBuilder().apply(block).build() +} + +fun BluePrintTypes.resourceAssignment(name: String, dictionaryName: String, dictionarySource: String, + block: ResourceAssignmentBuilder.() -> Unit): ResourceAssignment { + return ResourceAssignmentBuilder(name, dictionaryName, dictionarySource).apply(block).build() +} + +class ResourceDefinitionsBuilder() { + private val resourceDefinitions: MutableMap = hashMapOf() + + fun resourceDefinition(name: String, description: String, + block: ResourceDefinitionBuilder.() -> Unit) { + val resourceDefinition = ResourceDefinitionBuilder(name, description).apply(block).build() + resourceDefinitions[resourceDefinition.name] = resourceDefinition + } + + fun resourceDefinition(resourceDefinition: ResourceDefinition) { + resourceDefinitions[resourceDefinition.name] = resourceDefinition + } + + fun build(): MutableMap { + return resourceDefinitions + } } -class ResourceDefinitionBuilder(private val name: String) { +class ResourceDefinitionBuilder(private val name: String, private val description: String) { private val resourceDefinition = ResourceDefinition() fun updatedBy(updatedBy: String) { @@ -38,13 +73,13 @@ class ResourceDefinitionBuilder(private val name: String) { resourceDefinition.tags = tags } - fun property(id: String, type: String, required: Boolean, description: String? = "") { - resourceDefinition.property = PropertyDefinitionBuilder(id, type, required, description).build() + fun property(type: String, required: Boolean) { + resourceDefinition.property = PropertyDefinitionBuilder(name, type, required, description).build() } - fun property(id: String, type: String, required: Boolean, description: String? = "", + fun property(type: String, required: Boolean, block: PropertyDefinitionBuilder.() -> Unit) { - resourceDefinition.property = PropertyDefinitionBuilder(id, type, required, description).apply(block).build() + resourceDefinition.property = PropertyDefinitionBuilder(name, type, required, description).apply(block).build() } fun sources(block: ResourceDefinitionSourcesBuilder.() -> Unit) { @@ -91,4 +126,51 @@ class ResourceDefinitionSourcesBuilder { fun build(): MutableMap { return sources } +} + +class ResourceAssignmentsBuilder() { + private val resourceAssignments: MutableMap = hashMapOf() + + fun resourceAssignment(name: String, dictionaryName: String, dictionarySource: String, + block: ResourceAssignmentBuilder.() -> Unit) { + val resourceAssignment = ResourceAssignmentBuilder(name, dictionaryName, dictionarySource).apply(block).build() + resourceAssignments[resourceAssignment.name] = resourceAssignment + } + + fun resourceAssignment(resourceAssignment: ResourceAssignment) { + resourceAssignments[resourceAssignment.name] = resourceAssignment + } + + fun build(): MutableMap { + return resourceAssignments + } +} + +class ResourceAssignmentBuilder(private val name: String, private val dictionaryName: String, + private val dictionarySource: String) { + private val resourceAssignment = ResourceAssignment() + + fun inputParameter(inputParameter: Boolean) { + resourceAssignment.inputParameter = inputParameter + } + + fun property(type: String, required: Boolean, description: String? = "") { + resourceAssignment.property = PropertyDefinitionBuilder(name, type, required, description).build() + } + + fun property(type: String, required: Boolean, description: String? = "", + block: PropertyDefinitionBuilder.() -> Unit) { + resourceAssignment.property = PropertyDefinitionBuilder(name, type, required, description).apply(block).build() + } + + fun dependencies(dependencies: MutableList) { + resourceAssignment.dependencies = dependencies + } + + fun build(): ResourceAssignment { + resourceAssignment.name = name + resourceAssignment.dictionaryName = dictionaryName + resourceAssignment.dictionarySource = dictionarySource + return resourceAssignment + } } \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceDefinitionDSLTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceDefinitionDSLTest.kt new file mode 100644 index 000000000..f8f0e991e --- /dev/null +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceDefinitionDSLTest.kt @@ -0,0 +1,111 @@ +/* + * 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.blueprintsprocessor.functions.resource.resolution + +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotNull + +class ResourceDefinitionDSLTest { + + @Test + fun testResourceDefinitionDSL() { + val testResourceDefinition = BluePrintTypes.resourceDefinition("service-instance-id", + "VFW Service Instance Name") { + tags("service-instance-name, vfw, resources") + updatedBy("brindasanth@onap.com") + property("string", true) + sources { + sourceInput("input", "") {} + sourceDefault("default", "") {} + sourceDb("sdnctl", "") { + definedProperties { + type("SQL") + query("SELECT name FROM SERVICE_INSTANCE WHERE id = \$id") + endpointSelector("db-source-endpoint") + inputKeyMapping { + map("id", "\$service-instance-id") + } + outputKeyMapping { + map("service-instance-name", "\$name") + } + keyDependencies(arrayListOf("service-instance-id")) + } + } + sourceRest("odl-mdsal", "") { + definedProperties { + type("JSON") + endpointSelector("rest-source-endpoint") + expressionType("JSON_PATH") + urlPath("/service-instance/\$id") + path(".\$name") + verb("GET") + payload("sample payload") + inputKeyMapping { + map("id", "\$service-instance-id") + } + outputKeyMapping { + map("service-instance-name", "\$name") + } + keyDependencies(arrayListOf("service-instance-id")) + } + } + sourceCapability("custom-component", "") { + definedProperties { + type("kotlin") + scriptClassReference("Scripts/ServiceInstance.kt") + keyDependencies(arrayListOf("service-instance-id")) + } + } + } + } + //println(resourceDefinition.asJsonString(true)) + assertNotNull(testResourceDefinition, "failed to generate testResourceDefinition") + + val testResourceDefinitions = BluePrintTypes.resourceDefinitions { + resourceDefinition(testResourceDefinition) + } + assertNotNull(testResourceDefinitions, "failed to generate testResourceDefinitions") + assertEquals(1, testResourceDefinitions.size, "testResourceDefinitions size doesn't match") + } + + @Test + fun testResourceAssignment() { + val testResourceAssignment = BluePrintTypes.resourceAssignment("instance-name", + "service-instance-name", "odl-mdsal") { + inputParameter(true) + property("string", true) + dependencies(arrayListOf("service-instance-id")) + } + //println(resourceAssignment.asJsonString(true)) + assertNotNull(testResourceAssignment, "failed to generate resourceAssignment") + + val testResourceAssignments = BluePrintTypes.resourceAssignments { + resourceAssignment(testResourceAssignment) + resourceAssignment("instance-name1", + "service-instance-name", "odl-mdsal") { + inputParameter(true) + property("string", true) + dependencies(arrayListOf("service-instance-id")) + } + } + //println(testResourceAssignments.asJsonString(true)) + assertNotNull(testResourceAssignments, "failed to generate testResourceAssignments") + assertEquals(2, testResourceAssignments.size, "testResourceAssignments size doesn't match") + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceDefinitionSDLTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceDefinitionSDLTest.kt deleted file mode 100644 index 340b2b324..000000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceDefinitionSDLTest.kt +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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.blueprintsprocessor.functions.resource.resolution - -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes -import kotlin.test.Test -import kotlin.test.assertNotNull - -class ResourceDefinitionSDLTest { - - @Test - fun testResourceDefinitionDSL() { - val resourceDefinition = BluePrintTypes.resourceDefinition("service-instance-id") { - tags("service-instance-name, vfw, resources") - updatedBy("brindasanth@onap.com") - property("service-instance-name", "string", true, "VFW Service Instance Name") - sources { - sourceInput("input", "") {} - sourceDefault("default", "") {} - sourceDb("sdnctl", "") { - definedProperties { - type("SQL") - query("SELECT name FROM SERVICE_INSTANCE WHERE id = \$id") - endpointSelector("db-source-endpoint") - inputKeyMapping { - map("id", "\$service-instance-id") - } - outputKeyMapping { - map("service-instance-name", "\$name") - } - keyDependencies(arrayListOf("service-instance-id")) - } - } - sourceRest("odl-mdsal", "") { - definedProperties { - type("JSON") - endpointSelector("rest-source-endpoint") - expressionType("JSON_PATH") - urlPath("/service-instance/\$id") - path(".\$name") - verb("GET") - payload("sample payload") - inputKeyMapping { - map("id", "\$service-instance-id") - } - outputKeyMapping { - map("service-instance-name", "\$name") - } - keyDependencies(arrayListOf("service-instance-id")) - } - } - sourceCapability("custom-component", "") { - definedProperties { - type("kotlin") - scriptClassReference("Scripts/ServiceInstance.kt") - keyDependencies(arrayListOf("service-instance-id")) - } - } - } - } - //println(resourceDefinition.asJsonString(true)) - assertNotNull(resourceDefinition, "failed to generate resourceDefinition") - } -} \ No newline at end of file -- cgit 1.2.3-korg