2 * Copyright © 2019 IBM.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.ccsdk.cds.blueprintsprocessor.functions.python.executor
19 import com.fasterxml.jackson.databind.JsonNode
20 import com.fasterxml.jackson.databind.node.ArrayNode
21 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
22 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
23 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
24 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType
25 import org.onap.ccsdk.cds.controllerblueprints.core.data.DataType
26 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate
27 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType
28 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.AbstractNodeTemplateOperationImplBuilder
29 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertiesAssignmentBuilder
30 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.dataType
31 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.nodeType
32 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
34 /** Component Extensions **/
35 fun BluePrintTypes.nodeTypeComponentRemotePythonExecutor(): NodeType {
37 id = "component-remote-python-executor", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
38 derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_COMPONENT,
39 description = "This is Remote Python Execution Component."
43 ComponentRemotePythonExecutor.ATTRIBUTE_PREPARE_ENV_LOG, BluePrintConstants.DATA_TYPE_STRING,
47 ComponentRemotePythonExecutor.ATTRIBUTE_EXEC_CMD_LOG, BluePrintConstants.DATA_TYPE_LIST,
50 entrySchema(BluePrintConstants.DATA_TYPE_STRING)
53 ComponentRemotePythonExecutor.ATTRIBUTE_RESPONSE_DATA, BluePrintConstants.DATA_TYPE_JSON,
57 operation("ComponentRemotePythonExecutor", "ComponentRemotePythonExecutor Operation") {
60 ComponentRemotePythonExecutor.INPUT_ENDPOINT_SELECTOR, BluePrintConstants.DATA_TYPE_STRING,
61 false, "Remote Container or Server selector name."
63 defaultValue(ComponentRemotePythonExecutor.DEFAULT_SELECTOR)
66 ComponentRemotePythonExecutor.INPUT_DYNAMIC_PROPERTIES, BluePrintConstants.DATA_TYPE_JSON,
67 false, "Dynamic Json Content or DSL Json reference."
71 ComponentRemotePythonExecutor.INPUT_ARGUMENT_PROPERTIES, BluePrintConstants.DATA_TYPE_JSON,
72 false, "Argument Json Content or DSL Json reference."
76 ComponentRemotePythonExecutor.INPUT_COMMAND, BluePrintConstants.DATA_TYPE_STRING,
77 true, "Command to execute."
81 ComponentRemotePythonExecutor.INPUT_PACKAGES, BluePrintConstants.DATA_TYPE_LIST,
82 false, "Packages to install based on type."
84 entrySchema("dt-system-packages")
91 fun BluePrintTypes.dataTypeDtSystemPackages(): DataType {
93 id = "dt-system-packages", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
94 derivedFrom = BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT,
95 description = "This represent System Package Data Type"
97 property("type", BluePrintConstants.DATA_TYPE_LIST, true, "") {
99 entrySchema(BluePrintConstants.DATA_TYPE_STRING)
100 validValues(arrayListOf("ansible_galaxy".asJsonPrimitive(), "pip".asJsonPrimitive()))
103 property("package", BluePrintConstants.DATA_TYPE_LIST, true, "") {
104 entrySchema(BluePrintConstants.DATA_TYPE_STRING)
109 /** Component Builder */
110 fun BluePrintTypes.nodeTemplateComponentRemotePythonExecutor(
113 block: ComponentRemotePythonExecutorNodeTemplateBuilder.() -> Unit
116 return ComponentRemotePythonExecutorNodeTemplateBuilder(id, description).apply(block).build()
119 class DtSystemPackageDataTypeBuilder : PropertiesAssignmentBuilder() {
121 fun type(type: String) = type(type.asJsonPrimitive())
123 fun type(type: JsonNode) {
124 property("type", type)
127 fun packages(packages: String) = packages(packages.asJsonType())
129 fun packages(packages: List<String>) = packages(packages.asJsonType())
131 fun packages(packages: JsonNode) {
132 property("package", packages)
136 class ComponentRemotePythonExecutorNodeTemplateBuilder(id: String, description: String) :
137 AbstractNodeTemplateOperationImplBuilder<PropertiesAssignmentBuilder, ComponentRemotePythonExecutorNodeTemplateBuilder.InputsBuilder,
138 ComponentRemotePythonExecutorNodeTemplateBuilder.OutputsBuilder>(
139 id, "component-remote-python-executor",
140 "ComponentRemotePythonExecutor", description
143 class InputsBuilder : PropertiesAssignmentBuilder() {
145 private var packageList: ArrayNode? = null
147 fun endpointSelector(endpointSelector: String) = endpointSelector(endpointSelector.asJsonPrimitive())
149 fun endpointSelector(endpointSelector: JsonNode) {
150 property(ComponentRemotePythonExecutor.INPUT_ENDPOINT_SELECTOR, endpointSelector)
153 fun dynamicProperties(dynamicProperties: String) = dynamicProperties(dynamicProperties.asJsonType())
155 fun dynamicProperties(dynamicProperties: JsonNode) {
156 property(ComponentRemotePythonExecutor.INPUT_DYNAMIC_PROPERTIES, dynamicProperties)
159 fun argumentProperties(argumentProperties: String) = argumentProperties(argumentProperties.asJsonType())
161 fun argumentProperties(argumentProperties: JsonNode) {
162 property(ComponentRemotePythonExecutor.INPUT_ARGUMENT_PROPERTIES, argumentProperties)
165 fun command(command: String) = command(command.asJsonPrimitive())
167 fun command(command: JsonNode) {
168 property(ComponentRemotePythonExecutor.INPUT_COMMAND, command)
171 fun packages(block: DtSystemPackageDataTypeBuilder.() -> Unit) {
172 if (packageList == null)
173 packageList = JacksonUtils.objectMapper.createArrayNode()
174 val dtSysyemPackagePropertyAssignments = DtSystemPackageDataTypeBuilder().apply(block).build()
175 packageList!!.add(dtSysyemPackagePropertyAssignments.asJsonType())
178 override fun build(): MutableMap<String, JsonNode> {
179 val propertyAssignments = super.build()
180 if (packageList != null) {
181 propertyAssignments[ComponentRemotePythonExecutor.INPUT_PACKAGES] = packageList!!
183 return propertyAssignments
187 class OutputsBuilder : PropertiesAssignmentBuilder()