diff options
Diffstat (limited to 'ms/blueprintsprocessor/modules')
3 files changed, 138 insertions, 151 deletions
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 95b2afc4c..c66c3e913 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,16 +16,8 @@ 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.* -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 @@ -40,19 +32,23 @@ open class ComponentScriptExecutor(private var componentFunctionScriptingService : AbstractComponentFunction() { companion object { - const val SCRIPT_TYPE = "script-type" - const val SCRIPT_CLASS_REFERENCE = "script-class-reference" - const val DYNAMIC_PROPERTIES = "dynamic-properties" - const val RESPONSE_DATA = "response-data" - const val STATUS = "status" + const val INPUT_SCRIPT_TYPE = "script-type" + const val INPUT_SCRIPT_CLASS_REFERENCE = "script-class-reference" + const val INPUT_DYNAMIC_PROPERTIES = "dynamic-properties" + + const val ATTRIBUTE_RESPONSE_DATA = "response-data" + const val ATTRIBUTE_STATUS = "status" + + const val OUTPUT_RESPONSE_DATA = "response-data" + const val OUTPUT_STATUS = "status" } lateinit var scriptComponentFunction: AbstractScriptComponentFunction override suspend fun processNB(executionRequest: ExecutionServiceInput) { - val scriptType = operationInputs.getAsString(SCRIPT_TYPE) - val scriptClassReference = operationInputs.getAsString(SCRIPT_CLASS_REFERENCE) + val scriptType = operationInputs.getAsString(INPUT_SCRIPT_TYPE) + val scriptClassReference = operationInputs.getAsString(INPUT_SCRIPT_CLASS_REFERENCE) val scriptDependencies: MutableList<String> = arrayListOf() populateScriptDependencies(scriptDependencies) @@ -73,136 +69,4 @@ open class ComponentScriptExecutor(private var componentFunctionScriptingService open fun populateScriptDependencies(scriptDependencies: MutableList<String>) { /** Place holder for Child to add extra dependencies */ } -} - -/** Component Extensions **/ - -fun BluePrintTypes.componentScriptExecutor(): NodeType { - return nodeType(id = "component-script-executor", version = BluePrintConstants.DEFAULT_VERSION_NUMBER, - 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) - - operation("ComponentScriptExecutor", "ComponentScriptExecutor Operation") { - inputs { - property(ComponentScriptExecutor.SCRIPT_TYPE, BluePrintConstants.DATA_TYPE_STRING, true, - "Script Type") { - defaultValue(BluePrintConstants.SCRIPT_INTERNAL) - constrain { - validValues(listOf(BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive(), - BluePrintConstants.SCRIPT_JYTHON.asJsonPrimitive(), - BluePrintConstants.SCRIPT_KOTLIN.asJsonPrimitive())) - } - } - property(ComponentScriptExecutor.SCRIPT_CLASS_REFERENCE, BluePrintConstants.DATA_TYPE_STRING, - true, "Kotlin Script class name or jython script name.") - property(ComponentScriptExecutor.DYNAMIC_PROPERTIES, BluePrintConstants.DATA_TYPE_JSON, false, - "Dynamic Json Content or DSL Json reference.") - } - outputs { - property(ComponentScriptExecutor.RESPONSE_DATA, BluePrintConstants.DATA_TYPE_JSON, false, - "Output Response") - property(ComponentScriptExecutor.STATUS, BluePrintConstants.DATA_TYPE_STRING, true, - "Status of the Component Execution ( success or failure )") - } - } - } -} - -/** 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/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutorDSL.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutorDSL.kt new file mode 100644 index 000000000..1b905fa60 --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutorDSL.kt @@ -0,0 +1,123 @@ +/* + * 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.services.execution + +import com.fasterxml.jackson.databind.JsonNode +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.asJsonType +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.nodeTypeComponentScriptExecutor(): NodeType { + return nodeType(id = "component-script-executor", version = BluePrintConstants.DEFAULT_VERSION_NUMBER, + derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_COMPONENT, + description = "Generic Script Component Executor") { + attribute(ComponentScriptExecutor.ATTRIBUTE_RESPONSE_DATA, BluePrintConstants.DATA_TYPE_JSON, false) + attribute(ComponentScriptExecutor.ATTRIBUTE_STATUS, BluePrintConstants.DATA_TYPE_STRING, true) + + operation("ComponentScriptExecutor", "ComponentScriptExecutor Operation") { + inputs { + property(ComponentScriptExecutor.INPUT_SCRIPT_TYPE, BluePrintConstants.DATA_TYPE_STRING, + true, "Script Type") { + defaultValue(BluePrintConstants.SCRIPT_INTERNAL) + constrain { + validValues(listOf(BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive(), + BluePrintConstants.SCRIPT_JYTHON.asJsonPrimitive(), + BluePrintConstants.SCRIPT_KOTLIN.asJsonPrimitive())) + } + } + property(ComponentScriptExecutor.INPUT_SCRIPT_CLASS_REFERENCE, BluePrintConstants.DATA_TYPE_STRING, + true, "Kotlin Script class name or jython script name.") + property(ComponentScriptExecutor.INPUT_DYNAMIC_PROPERTIES, BluePrintConstants.DATA_TYPE_JSON, + false, "Dynamic Json Content or DSL Json reference.") + } + outputs { + property(ComponentScriptExecutor.OUTPUT_RESPONSE_DATA, BluePrintConstants.DATA_TYPE_JSON, + false, "Output Response") + property(ComponentScriptExecutor.OUTPUT_STATUS, BluePrintConstants.DATA_TYPE_STRING, + true, "Status of the Component Execution ( success or failure )") + } + } + } +} + +/** Component Builder */ +fun BluePrintTypes.nodeTemplateComponentScriptExecutor(id: String, + description: String, + block: ComponentScriptExecutorNodeTemplateImplBuilder.() -> Unit) + : NodeTemplate { + return ComponentScriptExecutorNodeTemplateImplBuilder(id, description).apply(block).build() +} + +class ComponentScriptExecutorNodeTemplateImplBuilder(id: String, description: String) : + AbstractNodeTemplateImplBuilder<ComponentScriptExecutorInputAssignmentBuilder, + ComponentScriptExecutorOutputAssignmentBuilder>(id, "component-script-executor", + "ComponentScriptExecutor", + description) + +class ComponentScriptExecutorInputAssignmentBuilder : PropertiesAssignmentBuilder() { + + fun type(type: String) { + type(type.asJsonPrimitive()) + } + + fun type(type: JsonNode) { + property(ComponentScriptExecutor.INPUT_SCRIPT_TYPE, type) + } + + fun scriptClassReference(scriptClassReference: String) { + scriptClassReference(scriptClassReference.asJsonPrimitive()) + } + + fun scriptClassReference(scriptClassReference: JsonNode) { + property(ComponentScriptExecutor.INPUT_SCRIPT_CLASS_REFERENCE, scriptClassReference) + } + + fun dynamicProperty(dynamicProperty: String) { + dynamicProperty(dynamicProperty.asJsonType()) + } + + fun dynamicProperty(dynamicProperty: JsonNode) { + property(ComponentScriptExecutor.INPUT_DYNAMIC_PROPERTIES, dynamicProperty) + } +} + +class ComponentScriptExecutorOutputAssignmentBuilder : PropertiesAssignmentBuilder() { + + fun status(status: String) { + status(status.asJsonPrimitive()) + } + + fun status(status: JsonNode) { + property(ComponentScriptExecutor.OUTPUT_STATUS, status) + } + + fun responseData(responseData: String) { + responseData(responseData.asJsonType()) + } + + fun responseData(responseData: JsonNode) { + property(ComponentScriptExecutor.OUTPUT_RESPONSE_DATA, responseData) + } +}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/AbstractComponentFunctionTest.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/AbstractComponentFunctionTest.kt index 309db9df4..07be8c809 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/AbstractComponentFunctionTest.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/AbstractComponentFunctionTest.kt @@ -34,15 +34,15 @@ import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInpu import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.StepData import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentFunctionScriptingService -import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.componentScriptExecutor +import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.nodeTypeComponentScriptExecutor 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.normalizedPathName +import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintScriptsServiceImpl import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext import org.onap.ccsdk.cds.controllerblueprints.core.service.DefaultBluePrintRuntimeService import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils -import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintScriptsServiceImpl import org.springframework.beans.factory.annotation.Autowired import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.junit4.SpringRunner @@ -187,7 +187,7 @@ class AbstractComponentFunctionTest { @Test fun testComponentScriptExecutorNodeType() { - val componentScriptExecutor = BluePrintTypes.componentScriptExecutor() + val componentScriptExecutor = BluePrintTypes.nodeTypeComponentScriptExecutor() assertNotNull(componentScriptExecutor.interfaces, "failed to get interface operations") } } |