Aligned attributes of CDS components
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / services / execution-service / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / services / execution / ComponentRemoteScriptExecutorDSL.kt
1 /*
2  * Copyright © 2018-2019 AT&T Intellectual Property.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.ccsdk.cds.blueprintsprocessor.services.execution
18
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
31
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
37 }
38
39 fun BluePrintTypes.nodeTypeComponentRemoteScriptExecutor(): NodeType {
40     return 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"
44     ) {
45         /** Attribute definitions */
46         attribute(
47             ComponentRemoteScriptExecutor.ATTRIBUTE_RESPONSE_DATA, BluePrintConstants.DATA_TYPE_JSON, false,
48             "Remote executed response data."
49         )
50         attribute(
51             ComponentRemoteScriptExecutor.ATTRIBUTE_STATUS, BluePrintConstants.DATA_TYPE_STRING, true,
52             "Remote execution status."
53         )
54
55         /** Operation definitions */
56         operation("ComponentRemoteScriptExecutor", "ComponentRemoteScriptExecutor Operation") {
57             inputs {
58                 property(
59                     ComponentRemoteScriptExecutor.INPUT_SELECTOR, BluePrintConstants.DATA_TYPE_JSON,
60                     true, "Remote GRPC selector or DSL reference or GRPC Json config."
61                 )
62                 property(
63                     ComponentRemoteScriptExecutor.INPUT_BLUEPRINT_NAME, BluePrintConstants.DATA_TYPE_STRING,
64                     true, "Blueprint name."
65                 )
66                 property(
67                     ComponentRemoteScriptExecutor.INPUT_BLUEPRINT_VERSION, BluePrintConstants.DATA_TYPE_STRING,
68                     true, "Blueprint version."
69                 )
70                 property(
71                     ComponentRemoteScriptExecutor.INPUT_BLUEPRINT_ACTION, BluePrintConstants.DATA_TYPE_STRING,
72                     true, "Blueprint action name."
73                 )
74                 property(
75                     ComponentRemoteScriptExecutor.INPUT_TIMEOUT, BluePrintConstants.DATA_TYPE_INTEGER,
76                     true, "Remote execution timeout in sec."
77                 ) {
78                     defaultValue(180)
79                 }
80                 property(
81                     ComponentRemoteScriptExecutor.INPUT_REQUEST_DATA, BluePrintConstants.DATA_TYPE_JSON,
82                     false, "Dynamic Json Content or DSL Json reference."
83                 )
84             }
85             outputs {
86                 property(
87                     ComponentRemoteScriptExecutor.OUTPUT_RESPONSE_DATA, BluePrintConstants.DATA_TYPE_JSON,
88                     false, "Output Response"
89                 )
90                 property(
91                     ComponentRemoteScriptExecutor.OUTPUT_STATUS, BluePrintConstants.DATA_TYPE_STRING,
92                     true, "Status of the Component Execution ( success or failure )"
93                 )
94             }
95         }
96     }
97 }
98
99 /** Component Builder */
100 fun TopologyTemplateBuilder.nodeTemplateComponentRemoteScriptExecutor(
101     id: String,
102     description: String,
103     block: ComponentRemoteScriptExecutorNodeTemplateBuilder.() -> Unit
104 ) {
105     val nodeTemplate = BluePrintTypes.nodeTemplateComponentRemoteScriptExecutor(
106         id, description,
107         block
108     )
109     if (nodeTemplates == null) nodeTemplates = hashMapOf()
110     nodeTemplates!![nodeTemplate.id!!] = nodeTemplate
111 }
112
113 fun BluePrintTypes.nodeTemplateComponentRemoteScriptExecutor(
114     id: String,
115     description: String,
116     block: ComponentRemoteScriptExecutorNodeTemplateBuilder.() -> Unit
117 ): NodeTemplate {
118     return ComponentRemoteScriptExecutorNodeTemplateBuilder(id, description).apply(block).build()
119 }
120
121 class ComponentRemoteScriptExecutorNodeTemplateBuilder(id: String, description: String) :
122     AbstractNodeTemplateOperationImplBuilder<PropertiesAssignmentBuilder,
123         ComponentRemoteScriptExecutorNodeTemplateBuilder.InputsBuilder,
124         ComponentRemoteScriptExecutorNodeTemplateBuilder.OutputsBuilder>(
125         id, "component-remote-script-executor",
126         "ComponentRemoteScriptExecutor",
127         description
128     ) {
129
130     class InputsBuilder : PropertiesAssignmentBuilder() {
131
132         fun selector(selector: String) = selector(selector.asJsonPrimitive())
133
134         fun selector(selector: JsonNode) = property(ComponentRemoteScriptExecutor.INPUT_SELECTOR, selector)
135
136         fun blueprintName(blueprintName: String) = property(
137             ComponentRemoteScriptExecutor.INPUT_BLUEPRINT_NAME,
138             blueprintName.asJsonPrimitive()
139         )
140
141         fun blueprintVersion(blueprintVersion: String) = property(
142             ComponentRemoteScriptExecutor.INPUT_BLUEPRINT_VERSION,
143             blueprintVersion.asJsonPrimitive()
144         )
145
146         fun blueprintAction(blueprintAction: String) = property(
147             ComponentRemoteScriptExecutor.INPUT_BLUEPRINT_ACTION,
148             blueprintAction.asJsonPrimitive()
149         )
150
151         fun timeout(timeout: Int) = property(
152             ComponentRemoteScriptExecutor.INPUT_TIMEOUT,
153             timeout.asJsonPrimitive()
154         )
155
156         fun requestData(requestData: String) = requestData(requestData.asJsonType())
157
158         fun requestData(requestData: JsonNode) {
159             property(ComponentRemoteScriptExecutor.INPUT_REQUEST_DATA, requestData)
160         }
161     }
162
163     class OutputsBuilder : PropertiesAssignmentBuilder() {
164
165         fun status(status: String) = status(status.asJsonPrimitive())
166
167         fun status(status: JsonNode) {
168             property(ComponentScriptExecutor.OUTPUT_STATUS, status)
169         }
170
171         fun responseData(responseData: String) = responseData(responseData.asJsonType())
172
173         fun responseData(responseData: JsonNode) {
174             property(ComponentScriptExecutor.OUTPUT_RESPONSE_DATA, responseData)
175         }
176     }
177 }