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_STATUS, BluePrintConstants.DATA_TYPE_STRING,
88 true, "Status of the Component Execution ( success or failure )"
95 /** Component Builder */
96 fun TopologyTemplateBuilder.nodeTemplateComponentRemoteScriptExecutor(
99 block: ComponentRemoteScriptExecutorNodeTemplateBuilder.() -> Unit
101 val nodeTemplate = BluePrintTypes.nodeTemplateComponentRemoteScriptExecutor(
105 if (nodeTemplates == null) nodeTemplates = hashMapOf()
106 nodeTemplates!![nodeTemplate.id!!] = nodeTemplate
109 fun BluePrintTypes.nodeTemplateComponentRemoteScriptExecutor(
112 block: ComponentRemoteScriptExecutorNodeTemplateBuilder.() -> Unit
114 return ComponentRemoteScriptExecutorNodeTemplateBuilder(id, description).apply(block).build()
117 class ComponentRemoteScriptExecutorNodeTemplateBuilder(id: String, description: String) :
118 AbstractNodeTemplateOperationImplBuilder<PropertiesAssignmentBuilder,
119 ComponentRemoteScriptExecutorNodeTemplateBuilder.InputsBuilder,
120 ComponentRemoteScriptExecutorNodeTemplateBuilder.OutputsBuilder>(
121 id, "component-remote-script-executor",
122 "ComponentRemoteScriptExecutor",
126 class InputsBuilder : PropertiesAssignmentBuilder() {
128 fun selector(selector: String) = selector(selector.asJsonPrimitive())
130 fun selector(selector: JsonNode) = property(ComponentRemoteScriptExecutor.INPUT_SELECTOR, selector)
132 fun blueprintName(blueprintName: String) = property(
133 ComponentRemoteScriptExecutor.INPUT_BLUEPRINT_NAME,
134 blueprintName.asJsonPrimitive()
137 fun blueprintVersion(blueprintVersion: String) = property(
138 ComponentRemoteScriptExecutor.INPUT_BLUEPRINT_VERSION,
139 blueprintVersion.asJsonPrimitive()
142 fun blueprintAction(blueprintAction: String) = property(
143 ComponentRemoteScriptExecutor.INPUT_BLUEPRINT_ACTION,
144 blueprintAction.asJsonPrimitive()
147 fun timeout(timeout: Int) = property(
148 ComponentRemoteScriptExecutor.INPUT_TIMEOUT,
149 timeout.asJsonPrimitive()
152 fun requestData(requestData: String) = requestData(requestData.asJsonType())
154 fun requestData(requestData: JsonNode) {
155 property(ComponentRemoteScriptExecutor.INPUT_REQUEST_DATA, requestData)
159 class OutputsBuilder : PropertiesAssignmentBuilder() {
161 fun status(status: String) = status(status.asJsonPrimitive())
163 fun status(status: JsonNode) {
164 property(ComponentRemoteScriptExecutor.OUTPUT_STATUS, status)