2 * Copyright © 2018-2019 AT&T Intellectual Property.
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.services.execution
19 import com.fasterxml.jackson.databind.JsonNode
20 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
21 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
22 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
23 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType
24 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate
25 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType
26 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.AbstractNodeTemplateOperationImplBuilder
27 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertiesAssignmentBuilder
28 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.ServiceTemplateBuilder
29 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.TopologyTemplateBuilder
30 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.nodeType
32 /** Component Extensions **/
33 fun ServiceTemplateBuilder.nodeTypeComponentRemoteScriptExecutor() {
34 val nodeType = BluePrintTypes.nodeTypeComponentRemoteScriptExecutor()
35 if (this.nodeTypes == null) this.nodeTypes = hashMapOf()
36 this.nodeTypes!![nodeType.id!!] = nodeType
39 fun BluePrintTypes.nodeTypeComponentRemoteScriptExecutor(): NodeType {
41 id = "component-remote-script-executor", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
42 derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_COMPONENT,
43 description = "Generic Remote Script Component Executor"
45 /** Attribute definitions */
47 ComponentRemoteScriptExecutor.ATTRIBUTE_RESPONSE_DATA, BluePrintConstants.DATA_TYPE_JSON, false,
48 "Remote executed response data."
51 ComponentRemoteScriptExecutor.ATTRIBUTE_STATUS, BluePrintConstants.DATA_TYPE_STRING, true,
52 "Remote execution status."
55 /** Operation definitions */
56 operation("ComponentRemoteScriptExecutor", "ComponentRemoteScriptExecutor Operation") {
59 ComponentRemoteScriptExecutor.INPUT_SELECTOR, BluePrintConstants.DATA_TYPE_JSON,
60 true, "Remote GRPC selector or DSL reference or GRPC Json config."
63 ComponentRemoteScriptExecutor.INPUT_BLUEPRINT_NAME, BluePrintConstants.DATA_TYPE_STRING,
64 true, "Blueprint name."
67 ComponentRemoteScriptExecutor.INPUT_BLUEPRINT_VERSION, BluePrintConstants.DATA_TYPE_STRING,
68 true, "Blueprint version."
71 ComponentRemoteScriptExecutor.INPUT_BLUEPRINT_ACTION, BluePrintConstants.DATA_TYPE_STRING,
72 true, "Blueprint action name."
75 ComponentRemoteScriptExecutor.INPUT_TIMEOUT, BluePrintConstants.DATA_TYPE_INTEGER,
76 true, "Remote execution timeout in sec."
81 ComponentRemoteScriptExecutor.INPUT_REQUEST_DATA, BluePrintConstants.DATA_TYPE_JSON,
82 false, "Dynamic Json Content or DSL Json reference."
87 ComponentRemoteScriptExecutor.OUTPUT_RESPONSE_DATA, BluePrintConstants.DATA_TYPE_JSON,
88 false, "Output Response"
91 ComponentRemoteScriptExecutor.OUTPUT_STATUS, BluePrintConstants.DATA_TYPE_STRING,
92 true, "Status of the Component Execution ( success or failure )"
99 /** Component Builder */
100 fun TopologyTemplateBuilder.nodeTemplateComponentRemoteScriptExecutor(
103 block: ComponentRemoteScriptExecutorNodeTemplateBuilder.() -> Unit
105 val nodeTemplate = BluePrintTypes.nodeTemplateComponentRemoteScriptExecutor(
109 if (nodeTemplates == null) nodeTemplates = hashMapOf()
110 nodeTemplates!![nodeTemplate.id!!] = nodeTemplate
113 fun BluePrintTypes.nodeTemplateComponentRemoteScriptExecutor(
116 block: ComponentRemoteScriptExecutorNodeTemplateBuilder.() -> Unit
118 return ComponentRemoteScriptExecutorNodeTemplateBuilder(id, description).apply(block).build()
121 class ComponentRemoteScriptExecutorNodeTemplateBuilder(id: String, description: String) :
122 AbstractNodeTemplateOperationImplBuilder<PropertiesAssignmentBuilder,
123 ComponentRemoteScriptExecutorNodeTemplateBuilder.InputsBuilder,
124 ComponentRemoteScriptExecutorNodeTemplateBuilder.OutputsBuilder>(
125 id, "component-remote-script-executor",
126 "ComponentRemoteScriptExecutor",
130 class InputsBuilder : PropertiesAssignmentBuilder() {
132 fun selector(selector: String) = selector(selector.asJsonPrimitive())
134 fun selector(selector: JsonNode) = property(ComponentRemoteScriptExecutor.INPUT_SELECTOR, selector)
136 fun blueprintName(blueprintName: String) = property(
137 ComponentRemoteScriptExecutor.INPUT_BLUEPRINT_NAME,
138 blueprintName.asJsonPrimitive()
141 fun blueprintVersion(blueprintVersion: String) = property(
142 ComponentRemoteScriptExecutor.INPUT_BLUEPRINT_VERSION,
143 blueprintVersion.asJsonPrimitive()
146 fun blueprintAction(blueprintAction: String) = property(
147 ComponentRemoteScriptExecutor.INPUT_BLUEPRINT_ACTION,
148 blueprintAction.asJsonPrimitive()
151 fun timeout(timeout: Int) = property(
152 ComponentRemoteScriptExecutor.INPUT_TIMEOUT,
153 timeout.asJsonPrimitive()
156 fun requestData(requestData: String) = requestData(requestData.asJsonType())
158 fun requestData(requestData: JsonNode) {
159 property(ComponentRemoteScriptExecutor.INPUT_REQUEST_DATA, requestData)
163 class OutputsBuilder : PropertiesAssignmentBuilder() {
165 fun status(status: String) = status(status.asJsonPrimitive())
167 fun status(status: JsonNode) {
168 property(ComponentScriptExecutor.OUTPUT_STATUS, status)
171 fun responseData(responseData: String) = responseData(responseData.asJsonType())
173 fun responseData(responseData: JsonNode) {
174 property(ComponentScriptExecutor.OUTPUT_RESPONSE_DATA, responseData)