Revert "Renaming Files having BluePrint to have Blueprint"
[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_STATUS, BluePrintConstants.DATA_TYPE_STRING,
88                     true, "Status of the Component Execution ( success or failure )"
89                 )
90             }
91         }
92     }
93 }
94
95 /** Component Builder */
96 fun TopologyTemplateBuilder.nodeTemplateComponentRemoteScriptExecutor(
97     id: String,
98     description: String,
99     block: ComponentRemoteScriptExecutorNodeTemplateBuilder.() -> Unit
100 ) {
101     val nodeTemplate = BluePrintTypes.nodeTemplateComponentRemoteScriptExecutor(
102         id, description,
103         block
104     )
105     if (nodeTemplates == null) nodeTemplates = hashMapOf()
106     nodeTemplates!![nodeTemplate.id!!] = nodeTemplate
107 }
108
109 fun BluePrintTypes.nodeTemplateComponentRemoteScriptExecutor(
110     id: String,
111     description: String,
112     block: ComponentRemoteScriptExecutorNodeTemplateBuilder.() -> Unit
113 ): NodeTemplate {
114     return ComponentRemoteScriptExecutorNodeTemplateBuilder(id, description).apply(block).build()
115 }
116
117 class ComponentRemoteScriptExecutorNodeTemplateBuilder(id: String, description: String) :
118     AbstractNodeTemplateOperationImplBuilder<PropertiesAssignmentBuilder,
119         ComponentRemoteScriptExecutorNodeTemplateBuilder.InputsBuilder,
120         ComponentRemoteScriptExecutorNodeTemplateBuilder.OutputsBuilder>(
121         id, "component-remote-script-executor",
122         "ComponentRemoteScriptExecutor",
123         description
124     ) {
125
126     class InputsBuilder : PropertiesAssignmentBuilder() {
127
128         fun selector(selector: String) = selector(selector.asJsonPrimitive())
129
130         fun selector(selector: JsonNode) = property(ComponentRemoteScriptExecutor.INPUT_SELECTOR, selector)
131
132         fun blueprintName(blueprintName: String) = property(
133             ComponentRemoteScriptExecutor.INPUT_BLUEPRINT_NAME,
134             blueprintName.asJsonPrimitive()
135         )
136
137         fun blueprintVersion(blueprintVersion: String) = property(
138             ComponentRemoteScriptExecutor.INPUT_BLUEPRINT_VERSION,
139             blueprintVersion.asJsonPrimitive()
140         )
141
142         fun blueprintAction(blueprintAction: String) = property(
143             ComponentRemoteScriptExecutor.INPUT_BLUEPRINT_ACTION,
144             blueprintAction.asJsonPrimitive()
145         )
146
147         fun timeout(timeout: Int) = property(
148             ComponentRemoteScriptExecutor.INPUT_TIMEOUT,
149             timeout.asJsonPrimitive()
150         )
151
152         fun requestData(requestData: String) = requestData(requestData.asJsonType())
153
154         fun requestData(requestData: JsonNode) {
155             property(ComponentRemoteScriptExecutor.INPUT_REQUEST_DATA, requestData)
156         }
157     }
158
159     class OutputsBuilder : PropertiesAssignmentBuilder() {
160
161         fun status(status: String) = status(status.asJsonPrimitive())
162
163         fun status(status: JsonNode) {
164             property(ComponentRemoteScriptExecutor.OUTPUT_STATUS, status)
165         }
166     }
167 }