summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions
diff options
context:
space:
mode:
authorBrinda Santh <brindasanth@in.ibm.com>2019-07-30 15:16:58 -0400
committerBrinda Santh <brindasanth@in.ibm.com>2019-07-30 15:16:58 -0400
commit5076fafdc89ac883f6da9477821ad82212ec5c86 (patch)
treeb8f1fe901f543dcb705a9bb8f76b7de10e80e324 /ms/blueprintsprocessor/functions
parent307341793d257fd1a673699d97855c9b10f69fcc (diff)
Add resource resolution component DSL
Change-Id: Icd12c87e017d4b8586bb60f63abce6cda3c7751c Issue-ID: CCSDK-1380 Signed-off-by: Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/blueprintsprocessor/functions')
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt17
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSL.kt189
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSLTest.kt60
3 files changed, 266 insertions, 0 deletions
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt
index df7e0482c..875b9ae32 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt
@@ -33,6 +33,23 @@ import org.springframework.stereotype.Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
open class ResourceResolutionComponent(private val resourceResolutionService: ResourceResolutionService) :
AbstractComponentFunction() {
+ companion object{
+ const val INPUT_REQUEST_ID = "request-id"
+ const val INPUT_RESOURCE_ID = "resource-id"
+ const val INPUT_ACTION_NAME = "action-name"
+ const val INPUT_DYNAMIC_PROPERTIES = "dynamic-properties"
+ const val INPUT_RESOURCE_TYPE = "resource-type"
+ const val INPUT_ARTIFACT_PREFIX_NAMES = "artifact-prefix-names"
+ const val INPUT_RESOLUTION_KEY = "resolution-key"
+ const val INPUT_STORE_RESULT = "store-result"
+ const val INPUT_OCCURRENCE = "occurrence"
+
+ const val ATTRIBUTE_ASSIGNMENT_PARAM = "assignment-params"
+ const val ATTRIBUTE_STATUS = "status"
+
+ const val OUTPUT_RESOURCE_ASSIGNMENT_PARAMS = "resource-assignment-params"
+ const val OUTPUT_STATUS = "status"
+ }
override suspend fun processNB(executionRequest: ExecutionServiceInput) {
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSL.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSL.kt
new file mode 100644
index 000000000..c71541efd
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSL.kt
@@ -0,0 +1,189 @@
+/*
+ * 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 com.fasterxml.jackson.databind.JsonNode
+import org.onap.ccsdk.cds.controllerblueprints.core.*
+import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate
+import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType
+import org.onap.ccsdk.cds.controllerblueprints.core.dsl.AbstractNodeTemplateImplBuilder
+import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertiesAssignmentBuilder
+import org.onap.ccsdk.cds.controllerblueprints.core.dsl.nodeType
+
+/** Component Extensions **/
+fun BluePrintTypes.nodeTypeComponentResourceResolution(): NodeType {
+ return nodeType(id = "component-resource-resolution", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
+ derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_COMPONENT,
+ description = "Resource Assignment Component") {
+
+ attribute(ResourceResolutionComponent.ATTRIBUTE_ASSIGNMENT_PARAM, BluePrintConstants.DATA_TYPE_STRING,
+ true)
+ attribute(ResourceResolutionComponent.ATTRIBUTE_STATUS, BluePrintConstants.DATA_TYPE_STRING,
+ true)
+
+ operation("ResourceResolutionComponent", "ResourceResolutionComponent Operation") {
+ inputs {
+ property(ResourceResolutionComponent.INPUT_REQUEST_ID, BluePrintConstants.DATA_TYPE_STRING,
+ true, "Request Id, Unique Id for the request.")
+
+ property(ResourceResolutionComponent.INPUT_RESOURCE_ID, BluePrintConstants.DATA_TYPE_STRING,
+ false, "Resource Id.")
+
+ property(ResourceResolutionComponent.INPUT_ACTION_NAME, BluePrintConstants.DATA_TYPE_STRING,
+ false, "Action Name of the process")
+
+ property(ResourceResolutionComponent.INPUT_DYNAMIC_PROPERTIES, BluePrintConstants.DATA_TYPE_JSON,
+ false, "Dynamic Json Content or DSL Json reference.")
+
+ property(ResourceResolutionComponent.INPUT_RESOLUTION_KEY, BluePrintConstants.DATA_TYPE_STRING,
+ false, "Key for service instance related correlation.")
+
+ property(ResourceResolutionComponent.INPUT_OCCURRENCE, BluePrintConstants.DATA_TYPE_INTEGER,
+ false, "Number of time to perform the resolution.") {
+ defaultValue(1)
+ }
+
+ property(ResourceResolutionComponent.INPUT_STORE_RESULT, BluePrintConstants.DATA_TYPE_BOOLEAN,
+ false, "Whether or not to store the output.")
+
+ property(ResourceResolutionComponent.INPUT_RESOURCE_TYPE, BluePrintConstants.DATA_TYPE_STRING,
+ false, "Request type.")
+
+ property(ResourceResolutionComponent.INPUT_ARTIFACT_PREFIX_NAMES, BluePrintConstants.DATA_TYPE_LIST,
+ true, "Template , Resource Assignment Artifact Prefix names") {
+ entrySchema(BluePrintConstants.DATA_TYPE_STRING)
+ }
+ }
+ outputs {
+ property(ResourceResolutionComponent.OUTPUT_RESOURCE_ASSIGNMENT_PARAMS, BluePrintConstants.DATA_TYPE_STRING,
+ true, "Output Response")
+ property(ResourceResolutionComponent.OUTPUT_STATUS, BluePrintConstants.DATA_TYPE_STRING,
+ true, "Status of the Component Execution ( success or failure )")
+ }
+ }
+ }
+}
+
+/** Component Builder */
+fun BluePrintTypes.nodeTemplateComponentResourceResolution(id: String,
+ description: String,
+ block: ComponentResourceResolutionNodeTemplateImplBuilder.() -> Unit)
+ : NodeTemplate {
+ return ComponentResourceResolutionNodeTemplateImplBuilder(id, description).apply(block).build()
+}
+
+class ComponentResourceResolutionNodeTemplateImplBuilder(id: String, description: String) :
+ AbstractNodeTemplateImplBuilder<ComponentResourceResolutionInputAssignmentBuilder,
+ ComponentResourceResolutionOutputAssignmentBuilder>(id, "component-script-executor",
+ "ComponentResourceResolution",
+ description)
+
+class ComponentResourceResolutionInputAssignmentBuilder : PropertiesAssignmentBuilder() {
+
+ fun requestId(requestId: String) {
+ requestId(requestId.asJsonPrimitive())
+ }
+
+ fun requestId(requestId: JsonNode) {
+ property(ResourceResolutionComponent.INPUT_REQUEST_ID, requestId)
+ }
+
+ fun resourceId(resourceId: String) {
+ resourceId(resourceId.asJsonPrimitive())
+ }
+
+ fun resourceId(resourceId: JsonNode) {
+ property(ResourceResolutionComponent.INPUT_RESOURCE_ID, resourceId)
+ }
+
+ fun actionName(actionName: String) {
+ actionName(actionName.asJsonPrimitive())
+ }
+
+ fun actionName(actionName: JsonNode) {
+ property(ResourceResolutionComponent.INPUT_ACTION_NAME, actionName)
+ }
+
+ fun resolutionKey(resolutionKey: String) {
+ resolutionKey(resolutionKey.asJsonPrimitive())
+ }
+
+ fun resolutionKey(resolutionKey: JsonNode) {
+ property(ResourceResolutionComponent.INPUT_RESOLUTION_KEY, resolutionKey)
+ }
+
+ fun dynamicProperty(dynamicProperty: String) {
+ dynamicProperty(dynamicProperty.asJsonType())
+ }
+
+ fun dynamicProperty(dynamicProperty: JsonNode) {
+ property(ResourceResolutionComponent.INPUT_DYNAMIC_PROPERTIES, dynamicProperty)
+ }
+
+ fun occurrence(occurrence: Int) {
+ occurrence(occurrence.asJsonPrimitive())
+ }
+
+ fun occurrence(resolutionKey: JsonNode) {
+ property(ResourceResolutionComponent.INPUT_OCCURRENCE, resolutionKey)
+ }
+
+ fun storeResult(storeResult: Boolean) {
+ storeResult(storeResult.asJsonPrimitive())
+ }
+
+ fun storeResult(storeResult: JsonNode) {
+ property(ResourceResolutionComponent.INPUT_STORE_RESULT, storeResult)
+ }
+
+ fun resourceType(resourceType: String) {
+ resourceType(resourceType.asJsonPrimitive())
+ }
+
+ fun resourceType(resourceType: JsonNode) {
+ property(ResourceResolutionComponent.INPUT_RESOURCE_TYPE, resourceType)
+ }
+
+ fun artifactPrefixNames(artifactPrefixNames: String) = artifactPrefixNames(artifactPrefixNames.jsonAsJsonType())
+
+ fun artifactPrefixNames(artifactPrefixNameList: List<String>) {
+ artifactPrefixNames(artifactPrefixNameList.asJsonString())
+ }
+
+ fun artifactPrefixNames(artifactPrefixNames: JsonNode) {
+ property(ResourceResolutionComponent.INPUT_ARTIFACT_PREFIX_NAMES, artifactPrefixNames)
+ }
+}
+
+class ComponentResourceResolutionOutputAssignmentBuilder : PropertiesAssignmentBuilder() {
+
+ fun status(status: String) {
+ status(status.asJsonPrimitive())
+ }
+
+ fun status(status: JsonNode) {
+ property(ResourceResolutionComponent.OUTPUT_STATUS, status)
+ }
+
+ fun resourceAssignmentParams(resourceAssignmentParams: String) {
+ resourceAssignmentParams(resourceAssignmentParams.asJsonType())
+ }
+
+ fun resourceAssignmentParams(resourceAssignmentParams: JsonNode) {
+ property(ResourceResolutionComponent.OUTPUT_RESOURCE_ASSIGNMENT_PARAMS, resourceAssignmentParams)
+ }
+} \ 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/ResourceResolutionComponentDSLTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSLTest.kt
new file mode 100644
index 000000000..16052ae74
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSLTest.kt
@@ -0,0 +1,60 @@
+/*
+ * 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 org.onap.ccsdk.cds.controllerblueprints.core.dsl.getAttribute
+import kotlin.test.Test
+import kotlin.test.assertNotNull
+
+class ResourceResolutionComponentDSLTest {
+
+ @Test
+ fun testNodeTypeComponentResourceResolution() {
+ val nodeType = BluePrintTypes.nodeTypeComponentResourceResolution()
+ //println(nodeType.asJsonString(true))
+ assertNotNull(nodeType, "failed to generate nodeTypeComponentResourceResolution")
+ }
+
+ @Test
+ fun testNodeTemplateComponentResourceResolution() {
+ val nodeTemplate = BluePrintTypes.nodeTemplateComponentResourceResolution("resource-resolve", "") {
+ operation("Resolve resources") {
+ inputs {
+ actionName("resolve")
+ requestId("1234")
+ resolutionKey("vnf-1234")
+ occurrence(2)
+ resourceType("vnf")
+ storeResult(false)
+ artifactPrefixNames(arrayListOf("template1", "template2"))
+ dynamicProperty("""{
+ "prop1" : "1234",
+ "prop2" : true,
+ "prop3" : 23
+ }""".trimIndent())
+ }
+ outputs {
+ resourceAssignmentParams(getAttribute("assignment-params"))
+ status("success")
+ }
+ }
+ }
+ //println(nodeTemplate.asJsonString(true))
+ assertNotNull(nodeTemplate, "failed to generate nodeTemplateComponentResourceResolution")
+ }
+} \ No newline at end of file