summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrinda Santh <brindasanth@in.ibm.com>2019-07-24 22:34:39 -0400
committerBrinda Santh <brindasanth@in.ibm.com>2019-07-24 22:34:39 -0400
commit88e24883c8e22711062ad451250ff7e3646485b3 (patch)
treedfc52871d9a5884e321ac6e32e239169dfff2603
parentef03bd490adb4483fc0dd0f8726f33ba6187804a (diff)
Fix attribute validation for complex type.
Change-Id: I7a3365c4c26fd44ed0b54bff115b64c52ee7b81e Issue-ID: CCSDK-1046 Signed-off-by: Brinda Santh <brindasanth@in.ibm.com>
-rw-r--r--components/model-catalog/blueprint-model/test-blueprint/capability_cli/Scripts/kotlin/CapabilityCliDefinitions.kt35
-rw-r--r--ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BluePrintSshLibPropertyService.kt3
-rw-r--r--ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutor.kt110
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintServiceDSLBuilder.kt6
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTemplateDSLBuilder.kt24
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTypeDSLBuilder.kt4
-rw-r--r--ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BluePrintAttributeDefinitionValidatorImpl.kt5
7 files changed, 158 insertions, 29 deletions
diff --git a/components/model-catalog/blueprint-model/test-blueprint/capability_cli/Scripts/kotlin/CapabilityCliDefinitions.kt b/components/model-catalog/blueprint-model/test-blueprint/capability_cli/Scripts/kotlin/CapabilityCliDefinitions.kt
index 057030b22..3bf07e79d 100644
--- a/components/model-catalog/blueprint-model/test-blueprint/capability_cli/Scripts/kotlin/CapabilityCliDefinitions.kt
+++ b/components/model-catalog/blueprint-model/test-blueprint/capability_cli/Scripts/kotlin/CapabilityCliDefinitions.kt
@@ -37,14 +37,12 @@ fun CapabilityCliDefinitions.defaultServiceTemplate() =
author = "Brinda Santh Muthuramalingam",
tags = "brinda, tosca") {
- dsl("device-properties", """"
- {
+ dsl("device-properties", """{
"type": "basic-auth",
"host": { "get_input": "hostname" },
"username": { "get_input": "username" },
"password": { "get_input": "password" }
- }
- """.trimIndent())
+ }""".trimIndent())
topologyTemplate {
@@ -56,27 +54,26 @@ fun CapabilityCliDefinitions.defaultServiceTemplate() =
property(id = "data", type = "json", required = true, description = "")
}
outputs {
- property(id = "status", required = true, type = "string", description = "")
+ property(id = "status", required = true, type = "string", description = "") {
+ value("success")
+ }
}
step(id = "check", target = "check", description = "Calling check script node")
-
}
- nodeTemplate(id = "check",
- type = "component-script-executor",
- description = "") {
- operation(interfaceName = "process", description = "") {
- inputs {
- property(id = "script-type", value = "kotlin")
- property(id = "script-class-reference", value = "cba.scripts.capability.cli.Check")
- }
- outputs {
- property(id = "response-data", value = "")
- property(id = "status", value = "success")
- }
+ val checkComponent = componentScriptExecutor(id = "check", description = "") {
+ inputs {
+ type("kotlin")
+ scriptClassReference("cba.scripts.capability.cli.Check")
+ }
+ outputs {
+ status("success")
+ responseData("""{ "data" : "Here I am "}""")
}
- artifact(id = "command-template", type = "artifact-template-velocity", file = "Templates/check-command-template.vtl")
+ artifact(id = "command-template", type = "artifact-template-velocity",
+ file = "Templates/check-command-template.vtl")
}
+ nodeTemplate(checkComponent)
}
artifactType(BluePrintTypes.artifactTypeTemplateVelocity())
diff --git a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BluePrintSshLibPropertyService.kt b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BluePrintSshLibPropertyService.kt
index 1950b71aa..829fdda8e 100644
--- a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BluePrintSshLibPropertyService.kt
+++ b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BluePrintSshLibPropertyService.kt
@@ -52,7 +52,8 @@ open class BluePrintSshLibPropertyService(private var bluePrintProperties: BlueP
}
fun sshClientProperties(jsonNode: JsonNode): SshClientProperties {
- val type = jsonNode.get("type").textValue()
+ val type = jsonNode.get("type")?.textValue()
+ ?: throw BluePrintProcessorException("missing type field in ssh client properties")
return when (type) {
SshLibConstants.TYPE_BASIC_AUTH -> {
JacksonUtils.readValue(jsonNode,
diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutor.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutor.kt
index b5dac5a39..95b2afc4c 100644
--- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutor.kt
+++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutor.kt
@@ -16,13 +16,16 @@
package org.onap.ccsdk.cds.blueprintsprocessor.services.execution
+import com.fasterxml.jackson.databind.JsonNode
import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
-import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
-import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
-import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
+import org.onap.ccsdk.cds.controllerblueprints.core.*
+import org.onap.ccsdk.cds.controllerblueprints.core.data.ArtifactDefinition
+import org.onap.ccsdk.cds.controllerblueprints.core.data.Implementation
+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.ArtifactDefinitionBuilder
+import org.onap.ccsdk.cds.controllerblueprints.core.dsl.nodeTemplate
import org.onap.ccsdk.cds.controllerblueprints.core.dsl.nodeType
-import org.onap.ccsdk.cds.controllerblueprints.core.getAsString
import org.springframework.beans.factory.config.ConfigurableBeanFactory
import org.springframework.context.annotation.Scope
import org.springframework.stereotype.Component
@@ -76,7 +79,7 @@ open class ComponentScriptExecutor(private var componentFunctionScriptingService
fun BluePrintTypes.componentScriptExecutor(): NodeType {
return nodeType(id = "component-script-executor", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
- derivedFrom = BluePrintConstants.MODEL_TYPE_NODES_ROOT,
+ derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_COMPONENT,
description = "Generic Script Component Executor") {
attribute(ComponentScriptExecutor.RESPONSE_DATA, BluePrintConstants.DATA_TYPE_JSON, false)
attribute(ComponentScriptExecutor.STATUS, BluePrintConstants.DATA_TYPE_STRING, true)
@@ -105,4 +108,101 @@ fun BluePrintTypes.componentScriptExecutor(): NodeType {
}
}
}
+}
+
+/** Component Builder */
+
+fun componentScriptExecutor(id: String, description: String,
+ block: ComponentScriptExecutorBuilder.() -> Unit): NodeTemplate {
+ return ComponentScriptExecutorBuilder(id, description).apply(block).build()
+}
+
+class ComponentScriptExecutorBuilder(private val id: String, private val description: String) {
+ private var implementation: Implementation? = null
+ private var inputs: MutableMap<String, JsonNode>? = null
+ private var outputs: MutableMap<String, JsonNode>? = null
+ private var artifacts: MutableMap<String, ArtifactDefinition>? = null
+
+ fun implementation(timeout: Int, operationHost: String? = BluePrintConstants.PROPERTY_SELF) {
+ val implementation = Implementation().apply {
+ this.operationHost = operationHost!!
+ this.timeout = timeout
+ }
+ this.implementation = implementation
+ }
+
+ fun inputs(block: InputAssignmentBuilder.() -> Unit) {
+ this.inputs = InputAssignmentBuilder().apply(block).build()
+ }
+
+ fun outputs(block: OutputAssignmentBuilder.() -> Unit) {
+ this.outputs = OutputAssignmentBuilder().apply(block).build()
+ }
+
+ fun artifact(id: String, type: String, file: String) {
+ if (artifacts == null)
+ artifacts = hashMapOf()
+ artifacts!![id] = ArtifactDefinitionBuilder(id, type, file).build()
+ }
+
+ fun artifact(id: String, type: String, file: String, block: ArtifactDefinitionBuilder.() -> Unit) {
+ if (artifacts == null)
+ artifacts = hashMapOf()
+ artifacts!![id] = ArtifactDefinitionBuilder(id, type, file).apply(block).build()
+ }
+
+ fun build(): NodeTemplate {
+ return nodeTemplate(id, "component-script-executor", description) {
+ operation("ComponentScriptExecutor") {
+ implementation(implementation)
+ inputs(inputs)
+ outputs(outputs)
+ }
+ artifacts(artifacts)
+ }
+ }
+
+ class InputAssignmentBuilder {
+ val properties: MutableMap<String, JsonNode> = hashMapOf()
+
+ fun type(type: String) {
+ properties[ComponentScriptExecutor.SCRIPT_TYPE] = type.asJsonPrimitive()
+ }
+
+ fun scriptClassReference(scriptClassReference: String) {
+ properties[ComponentScriptExecutor.SCRIPT_CLASS_REFERENCE] = scriptClassReference.asJsonPrimitive()
+ }
+
+ fun dynamicProperty(dynamicProperty: Any) {
+ dynamicProperty(dynamicProperty.asJsonType())
+ }
+
+ fun dynamicProperty(dynamicProperty: JsonNode) {
+ properties[ComponentScriptExecutor.DYNAMIC_PROPERTIES] = dynamicProperty
+ }
+
+ fun build(): MutableMap<String, JsonNode> {
+ return properties
+ }
+ }
+
+ class OutputAssignmentBuilder {
+ val properties: MutableMap<String, JsonNode> = hashMapOf()
+
+ fun status(status: String) {
+ properties[ComponentScriptExecutor.STATUS] = status.asJsonPrimitive()
+ }
+
+ fun responseData(responseData: Any) {
+ responseData(responseData.asJsonType())
+ }
+
+ fun responseData(responseData: JsonNode) {
+ properties[ComponentScriptExecutor.RESPONSE_DATA] = responseData
+ }
+
+ fun build(): MutableMap<String, JsonNode> {
+ return properties
+ }
+ }
} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintServiceDSLBuilder.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintServiceDSLBuilder.kt
index 3415be8f3..c9f7d507c 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintServiceDSLBuilder.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintServiceDSLBuilder.kt
@@ -54,14 +54,14 @@ class ServiceTemplateBuilder(private val name: String,
imports.add(importDefinition)
}
- fun dsl(id: String, json: String) {
- dsl(id, json.asJsonType())
+ fun dsl(id: String, content: Any) {
+ dsl(id, content.asJsonType())
}
fun dsl(id: String, json: JsonNode) {
if (dslDefinitions == null)
dslDefinitions = hashMapOf()
- dslDefinitions!![id] = json.asJsonType()
+ dslDefinitions!![id] = json
}
fun dataTypes(dataTypes: MutableMap<String, DataType>) {
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 fd747f09c..93b6f4e4e 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
@@ -32,6 +32,12 @@ class TopologyTemplateBuilder {
nodeTemplates!![id] = NodeTemplateBuilder(id, type, description).apply(block).build()
}
+ fun nodeTemplate(nodeTemplate: NodeTemplate) {
+ if (nodeTemplates == null)
+ nodeTemplates = hashMapOf()
+ nodeTemplates!![nodeTemplate.id!!] = nodeTemplate
+ }
+
fun nodeTemplateOperation(nodeTemplateName: String, type: String, interfaceName: String, description: String,
operationBlock: OperationAssignmentBuilder.() -> Unit) {
if (nodeTemplates == null)
@@ -48,6 +54,12 @@ class TopologyTemplateBuilder {
workflows!![id] = WorkflowBuilder(id, description).apply(block).build()
}
+ fun workflow(workflow: Workflow) {
+ if (workflows == null)
+ workflows = hashMapOf()
+ workflows!![workflow.id!!] = workflow
+ }
+
//TODO("populate inputs, outputs")
fun workflowNodeTemplate(actionName: String,
nodeTemplateType: String, description: String, block: NodeTemplateBuilder.() -> Unit) {
@@ -113,18 +125,30 @@ class NodeTemplateBuilder(private val id: String,
artifacts!![id] = ArtifactDefinitionBuilder(id, type, file).apply(block).build()
}
+ fun artifacts(artifacts: MutableMap<String, ArtifactDefinition>?) {
+ this.artifacts = artifacts
+ }
+
fun capability(id: String, block: CapabilityAssignmentBuilder.() -> Unit) {
if (capabilities == null)
capabilities = hashMapOf()
capabilities!![id] = CapabilityAssignmentBuilder(id).apply(block).build()
}
+ fun capabilities(capabilities: MutableMap<String, CapabilityAssignment>?) {
+ this.capabilities = capabilities
+ }
+
fun requirement(id: String, capability: String, node: String, relationship: String) {
if (requirements == null)
requirements = hashMapOf()
requirements!![id] = RequirementAssignmentBuilder(id, capability, node, relationship).build()
}
+ fun requirements(requirements: MutableMap<String, RequirementAssignment>?) {
+ this.requirements = requirements
+ }
+
fun build(): NodeTemplate {
nodeTemplate.id = id
nodeTemplate.type = type
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTypeDSLBuilder.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTypeDSLBuilder.kt
index 8afe695ca..6dc5647da 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTypeDSLBuilder.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTypeDSLBuilder.kt
@@ -384,6 +384,10 @@ class PropertyDefinitionBuilder(private val id: String,
propertyDefinition.defaultValue = defaultValue
}
+ fun value(value: Any) {
+ value(value.asJsonType())
+ }
+
fun value(value: JsonNode) {
propertyDefinition.value = value
}
diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BluePrintAttributeDefinitionValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BluePrintAttributeDefinitionValidatorImpl.kt
index 3cec5af7b..5a9736bc8 100644
--- a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BluePrintAttributeDefinitionValidatorImpl.kt
+++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BluePrintAttributeDefinitionValidatorImpl.kt
@@ -17,7 +17,6 @@
package org.onap.ccsdk.cds.controllerblueprints.validation
-import org.slf4j.LoggerFactory
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
import org.onap.ccsdk.cds.controllerblueprints.core.data.AttributeDefinition
@@ -25,6 +24,7 @@ import org.onap.ccsdk.cds.controllerblueprints.core.format
import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintAttributeDefinitionValidator
import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeValidatorService
import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
+import org.slf4j.LoggerFactory
import org.springframework.beans.factory.config.ConfigurableBeanFactory
import org.springframework.context.annotation.Scope
import org.springframework.stereotype.Service
@@ -50,6 +50,9 @@ open class BluePrintAttributeDefinitionValidatorImpl(private val bluePrintTypeVa
BluePrintTypes.validPrimitiveTypes().contains(dataType) -> {
// Do Nothing
}
+ BluePrintTypes.validComplexTypes().contains(dataType) -> {
+ // Do Nothing
+ }
BluePrintTypes.validCollectionTypes().contains(dataType) -> {
val entrySchemaType: String = attributeDefinition.entrySchema?.type
?: throw BluePrintException("Entry schema for DataType ($dataType) for the property ($name) not found")