0210e88ea3462f3f4b7ad14c2ce33e9f82626962
[ccsdk/cds.git] /
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.nodeType
29
30 /** Component Extensions **/
31
32 fun BluePrintTypes.nodeTypeComponentRemoteScriptExecutor(): NodeType {
33     return nodeType(
34         id = "component-remote-script-executor", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
35         derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_COMPONENT,
36         description = "Generic Remote Script Component Executor"
37     ) {
38         /** Attribute definitions */
39         attribute(
40             ComponentRemoteScriptExecutor.ATTRIBUTE_RESPONSE_DATA, BluePrintConstants.DATA_TYPE_JSON, false,
41             "Remote executed response data."
42         )
43         attribute(
44             ComponentRemoteScriptExecutor.ATTRIBUTE_STATUS, BluePrintConstants.DATA_TYPE_STRING, true,
45             "Remote execution status."
46         )
47
48         /** Operation definitions */
49         operation("ComponentRemoteScriptExecutor", "ComponentRemoteScriptExecutor Operation") {
50             inputs {
51                 property(
52                     ComponentRemoteScriptExecutor.INPUT_SELECTOR, BluePrintConstants.DATA_TYPE_JSON,
53                     true, "Remote GRPC selector or DSL reference or GRPC Json config."
54                 )
55                 property(
56                     ComponentRemoteScriptExecutor.INPUT_BLUEPRINT_NAME, BluePrintConstants.DATA_TYPE_STRING,
57                     true, "Blueprint name."
58                 )
59                 property(
60                     ComponentRemoteScriptExecutor.INPUT_BLUEPRINT_VERSION, BluePrintConstants.DATA_TYPE_STRING,
61                     true, "Blueprint version."
62                 )
63                 property(
64                     ComponentRemoteScriptExecutor.INPUT_BLUEPRINT_ACTION, BluePrintConstants.DATA_TYPE_STRING,
65                     true, "Blueprint action name."
66                 )
67                 property(
68                     ComponentRemoteScriptExecutor.INPUT_TIMEOUT, BluePrintConstants.DATA_TYPE_INTEGER,
69                     true, "Remote execution timeout in sec."
70                 ) {
71                     defaultValue(180)
72                 }
73                 property(
74                     ComponentRemoteScriptExecutor.INPUT_REQUEST_DATA, BluePrintConstants.DATA_TYPE_JSON,
75                     false, "Dynamic Json Content or DSL Json reference."
76                 )
77             }
78             outputs {
79                 property(
80                     ComponentRemoteScriptExecutor.OUTPUT_STATUS, BluePrintConstants.DATA_TYPE_STRING,
81                     true, "Status of the Component Execution ( success or failure )"
82                 )
83             }
84         }
85     }
86 }
87
88 /** Component Builder */
89 fun BluePrintTypes.nodeTemplateComponentRemoteScriptExecutor(
90     id: String,
91     description: String,
92     block: ComponentRemoteScriptExecutorNodeTemplateBuilder.() -> Unit
93 ):
94     NodeTemplate {
95     return ComponentRemoteScriptExecutorNodeTemplateBuilder(id, description).apply(block).build()
96 }
97
98 class ComponentRemoteScriptExecutorNodeTemplateBuilder(id: String, description: String) :
99     AbstractNodeTemplateOperationImplBuilder<PropertiesAssignmentBuilder,
100         ComponentRemoteScriptExecutorNodeTemplateBuilder.InputsBuilder,
101         ComponentRemoteScriptExecutorNodeTemplateBuilder.OutputsBuilder>(
102         id, "component-remote-script-executor",
103         "ComponentRemoteScriptExecutor",
104         description
105     ) {
106
107     class InputsBuilder : PropertiesAssignmentBuilder() {
108
109         fun selector(selector: String) = selector(selector.asJsonPrimitive())
110
111         fun selector(selector: JsonNode) = property(ComponentRemoteScriptExecutor.INPUT_SELECTOR, selector)
112
113         fun blueprintName(blueprintName: String) = property(
114             ComponentRemoteScriptExecutor.INPUT_BLUEPRINT_NAME,
115             blueprintName.asJsonPrimitive()
116         )
117
118         fun blueprintVersion(blueprintVersion: String) = property(
119             ComponentRemoteScriptExecutor.INPUT_BLUEPRINT_VERSION,
120             blueprintVersion.asJsonPrimitive()
121         )
122
123         fun blueprintAction(blueprintAction: String) = property(
124             ComponentRemoteScriptExecutor.INPUT_BLUEPRINT_ACTION,
125             blueprintAction.asJsonPrimitive()
126         )
127
128         fun timeout(timeout: Int) = property(
129             ComponentRemoteScriptExecutor.INPUT_TIMEOUT,
130             timeout.asJsonPrimitive()
131         )
132
133         fun requestData(requestData: String) = requestData(requestData.asJsonType())
134
135         fun requestData(requestData: JsonNode) {
136             property(ComponentRemoteScriptExecutor.INPUT_REQUEST_DATA, requestData)
137         }
138     }
139
140     class OutputsBuilder : PropertiesAssignmentBuilder() {
141
142         fun status(status: String) = status(status.asJsonPrimitive())
143
144         fun status(status: JsonNode) {
145             property(ComponentRemoteScriptExecutor.OUTPUT_STATUS, status)
146         }
147     }
148 }