aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentRemoteScriptExecutorDSL.kt
blob: 7bb071501cc79ee0dcb61ff7f9a6a8413e9cf7eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
 * Copyright © 2018-2019 AT&T Intellectual Property.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.onap.ccsdk.cds.blueprintsprocessor.services.execution

import com.fasterxml.jackson.databind.JsonNode
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType
import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate
import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType
import org.onap.ccsdk.cds.controllerblueprints.core.dsl.AbstractNodeTemplateOperationImplBuilder
import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertiesAssignmentBuilder
import org.onap.ccsdk.cds.controllerblueprints.core.dsl.ServiceTemplateBuilder
import org.onap.ccsdk.cds.controllerblueprints.core.dsl.TopologyTemplateBuilder
import org.onap.ccsdk.cds.controllerblueprints.core.dsl.nodeType

/** Component Extensions **/
fun ServiceTemplateBuilder.nodeTypeComponentRemoteScriptExecutor() {
    val nodeType = BluePrintTypes.nodeTypeComponentRemoteScriptExecutor()
    if (this.nodeTypes == null) this.nodeTypes = hashMapOf()
    this.nodeTypes!![nodeType.id!!] = nodeType
}

fun BluePrintTypes.nodeTypeComponentRemoteScriptExecutor(): NodeType {
    return nodeType(
        id = "component-remote-script-executor", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
        derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_COMPONENT,
        description = "Generic Remote Script Component Executor"
    ) {
        /** Attribute definitions */
        attribute(
            ComponentRemoteScriptExecutor.ATTRIBUTE_RESPONSE_DATA, BluePrintConstants.DATA_TYPE_JSON, false,
            "Remote executed response data."
        )
        attribute(
            ComponentRemoteScriptExecutor.ATTRIBUTE_STATUS, BluePrintConstants.DATA_TYPE_STRING, true,
            "Remote execution status."
        )

        /** Operation definitions */
        operation("ComponentRemoteScriptExecutor", "ComponentRemoteScriptExecutor Operation") {
            inputs {
                property(
                    ComponentRemoteScriptExecutor.INPUT_SELECTOR, BluePrintConstants.DATA_TYPE_JSON,
                    true, "Remote GRPC selector or DSL reference or GRPC Json config."
                )
                property(
                    ComponentRemoteScriptExecutor.INPUT_BLUEPRINT_NAME, BluePrintConstants.DATA_TYPE_STRING,
                    true, "Blueprint name."
                )
                property(
                    ComponentRemoteScriptExecutor.INPUT_BLUEPRINT_VERSION, BluePrintConstants.DATA_TYPE_STRING,
                    true, "Blueprint version."
                )
                property(
                    ComponentRemoteScriptExecutor.INPUT_BLUEPRINT_ACTION, BluePrintConstants.DATA_TYPE_STRING,
                    true, "Blueprint action name."
                )
                property(
                    ComponentRemoteScriptExecutor.INPUT_TIMEOUT, BluePrintConstants.DATA_TYPE_INTEGER,
                    true, "Remote execution timeout in sec."
                ) {
                    defaultValue(180)
                }
                property(
                    ComponentRemoteScriptExecutor.INPUT_REQUEST_DATA, BluePrintConstants.DATA_TYPE_JSON,
                    false, "Dynamic Json Content or DSL Json reference."
                )
            }
            outputs {
                property(
                    ComponentRemoteScriptExecutor.OUTPUT_STATUS, BluePrintConstants.DATA_TYPE_STRING,
                    true, "Status of the Component Execution ( success or failure )"
                )
            }
        }
    }
}

/** Component Builder */
fun TopologyTemplateBuilder.nodeTemplateComponentRemoteScriptExecutor(
    id: String,
    description: String,
    block: ComponentRemoteScriptExecutorNodeTemplateBuilder.() -> Unit
) {
    val nodeTemplate = BluePrintTypes.nodeTemplateComponentRemoteScriptExecutor(
        id, description,
        block
    )
    if (nodeTemplates == null) nodeTemplates = hashMapOf()
    nodeTemplates!![nodeTemplate.id!!] = nodeTemplate
}

fun BluePrintTypes.nodeTemplateComponentRemoteScriptExecutor(
    id: String,
    description: String,
    block: ComponentRemoteScriptExecutorNodeTemplateBuilder.() -> Unit
): NodeTemplate {
    return ComponentRemoteScriptExecutorNodeTemplateBuilder(id, description).apply(block).build()
}

class ComponentRemoteScriptExecutorNodeTemplateBuilder(id: String, description: String) :
    AbstractNodeTemplateOperationImplBuilder<PropertiesAssignmentBuilder,
        ComponentRemoteScriptExecutorNodeTemplateBuilder.InputsBuilder,
        ComponentRemoteScriptExecutorNodeTemplateBuilder.OutputsBuilder>(
        id, "component-remote-script-executor",
        "ComponentRemoteScriptExecutor",
        description
    ) {

    class InputsBuilder : PropertiesAssignmentBuilder() {

        fun selector(selector: String) = selector(selector.asJsonPrimitive())

        fun selector(selector: JsonNode) = property(ComponentRemoteScriptExecutor.INPUT_SELECTOR, selector)

        fun blueprintName(blueprintName: String) = property(
            ComponentRemoteScriptExecutor.INPUT_BLUEPRINT_NAME,
            blueprintName.asJsonPrimitive()
        )

        fun blueprintVersion(blueprintVersion: String) = property(
            ComponentRemoteScriptExecutor.INPUT_BLUEPRINT_VERSION,
            blueprintVersion.asJsonPrimitive()
        )

        fun blueprintAction(blueprintAction: String) = property(
            ComponentRemoteScriptExecutor.INPUT_BLUEPRINT_ACTION,
            blueprintAction.asJsonPrimitive()
        )

        fun timeout(timeout: Int) = property(
            ComponentRemoteScriptExecutor.INPUT_TIMEOUT,
            timeout.asJsonPrimitive()
        )

        fun requestData(requestData: String) = requestData(requestData.asJsonType())

        fun requestData(requestData: JsonNode) {
            property(ComponentRemoteScriptExecutor.INPUT_REQUEST_DATA, requestData)
        }
    }

    class OutputsBuilder : PropertiesAssignmentBuilder() {

        fun status(status: String) = status(status.asJsonPrimitive())

        fun status(status: JsonNode) {
            property(ComponentRemoteScriptExecutor.OUTPUT_STATUS, status)
        }
    }
}