Add remote python executor DSL properties
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / resource-resolution / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / functions / resource / resolution / ResourceResolutionComponentDSL.kt
1 /*
2  *  Copyright © 2019 IBM.
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.functions.resource.resolution
18
19 import com.fasterxml.jackson.databind.JsonNode
20 import org.onap.ccsdk.cds.controllerblueprints.core.*
21 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate
22 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType
23 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.AbstractNodeTemplateImplBuilder
24 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertiesAssignmentBuilder
25 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.nodeType
26
27 /** Component Extensions **/
28 fun BluePrintTypes.nodeTypeComponentResourceResolution(): NodeType {
29     return nodeType(id = "component-resource-resolution", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
30             derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_COMPONENT,
31             description = "Resource Assignment Component") {
32
33         attribute(ResourceResolutionComponent.ATTRIBUTE_ASSIGNMENT_PARAM, BluePrintConstants.DATA_TYPE_STRING,
34                 true)
35         attribute(ResourceResolutionComponent.ATTRIBUTE_STATUS, BluePrintConstants.DATA_TYPE_STRING,
36                 true)
37
38         operation("ResourceResolutionComponent", "ResourceResolutionComponent Operation") {
39             inputs {
40                 property(ResourceResolutionComponent.INPUT_REQUEST_ID, BluePrintConstants.DATA_TYPE_STRING,
41                         true, "Request Id, Unique Id for the request.")
42
43                 property(ResourceResolutionComponent.INPUT_RESOURCE_ID, BluePrintConstants.DATA_TYPE_STRING,
44                         false, "Resource Id.")
45
46                 property(ResourceResolutionComponent.INPUT_ACTION_NAME, BluePrintConstants.DATA_TYPE_STRING,
47                         false, "Action Name of the process")
48
49                 property(ResourceResolutionComponent.INPUT_DYNAMIC_PROPERTIES, BluePrintConstants.DATA_TYPE_JSON,
50                         false, "Dynamic Json Content or DSL Json reference.")
51
52                 property(ResourceResolutionComponent.INPUT_RESOLUTION_KEY, BluePrintConstants.DATA_TYPE_STRING,
53                         false, "Key for service instance related correlation.")
54
55                 property(ResourceResolutionComponent.INPUT_OCCURRENCE, BluePrintConstants.DATA_TYPE_INTEGER,
56                         false, "Number of time to perform the resolution.") {
57                     defaultValue(1)
58                 }
59
60                 property(ResourceResolutionComponent.INPUT_STORE_RESULT, BluePrintConstants.DATA_TYPE_BOOLEAN,
61                         false, "Whether or not to store the output.")
62
63                 property(ResourceResolutionComponent.INPUT_RESOURCE_TYPE, BluePrintConstants.DATA_TYPE_STRING,
64                         false, "Request type.")
65
66                 property(ResourceResolutionComponent.INPUT_ARTIFACT_PREFIX_NAMES, BluePrintConstants.DATA_TYPE_LIST,
67                         true, "Template , Resource Assignment Artifact Prefix names") {
68                     entrySchema(BluePrintConstants.DATA_TYPE_STRING)
69                 }
70             }
71             outputs {
72                 property(ResourceResolutionComponent.OUTPUT_RESOURCE_ASSIGNMENT_PARAMS, BluePrintConstants.DATA_TYPE_STRING,
73                         true, "Output Response")
74                 property(ResourceResolutionComponent.OUTPUT_STATUS, BluePrintConstants.DATA_TYPE_STRING,
75                         true, "Status of the Component Execution ( success or failure )")
76             }
77         }
78     }
79 }
80
81 /** Component Builder */
82 fun BluePrintTypes.nodeTemplateComponentResourceResolution(id: String,
83                                                            description: String,
84                                                            block: ComponentResourceResolutionNodeTemplateImplBuilder.() -> Unit)
85         : NodeTemplate {
86     return ComponentResourceResolutionNodeTemplateImplBuilder(id, description).apply(block).build()
87 }
88
89 class ComponentResourceResolutionNodeTemplateImplBuilder(id: String, description: String) :
90         AbstractNodeTemplateImplBuilder<ComponentResourceResolutionInputAssignmentBuilder,
91                 ComponentResourceResolutionOutputAssignmentBuilder>(id, "component-script-executor",
92                 "ComponentResourceResolution",
93                 description)
94
95 class ComponentResourceResolutionInputAssignmentBuilder : PropertiesAssignmentBuilder() {
96
97     fun requestId(requestId: String) = requestId(requestId.asJsonPrimitive())
98
99     fun requestId(requestId: JsonNode) {
100         property(ResourceResolutionComponent.INPUT_REQUEST_ID, requestId)
101     }
102
103     fun resourceId(resourceId: String) = resourceId(resourceId.asJsonPrimitive())
104
105     fun resourceId(resourceId: JsonNode) {
106         property(ResourceResolutionComponent.INPUT_RESOURCE_ID, resourceId)
107     }
108
109     fun actionName(actionName: String) = actionName(actionName.asJsonPrimitive())
110
111     fun actionName(actionName: JsonNode) {
112         property(ResourceResolutionComponent.INPUT_ACTION_NAME, actionName)
113     }
114
115     fun resolutionKey(resolutionKey: String) = resolutionKey(resolutionKey.asJsonPrimitive())
116
117     fun resolutionKey(resolutionKey: JsonNode) {
118         property(ResourceResolutionComponent.INPUT_RESOLUTION_KEY, resolutionKey)
119     }
120
121     fun dynamicProperties(dynamicProperties: String) = dynamicProperties(dynamicProperties.asJsonType())
122
123     fun dynamicProperties(dynamicProperties: JsonNode) {
124         property(ResourceResolutionComponent.INPUT_DYNAMIC_PROPERTIES, dynamicProperties)
125     }
126
127     fun occurrence(occurrence: Int) = occurrence(occurrence.asJsonPrimitive())
128
129     fun occurrence(resolutionKey: JsonNode) {
130         property(ResourceResolutionComponent.INPUT_OCCURRENCE, resolutionKey)
131     }
132
133     fun storeResult(storeResult: Boolean) = storeResult(storeResult.asJsonPrimitive())
134
135     fun storeResult(storeResult: JsonNode) {
136         property(ResourceResolutionComponent.INPUT_STORE_RESULT, storeResult)
137     }
138
139     fun resourceType(resourceType: String) = resourceType(resourceType.asJsonPrimitive())
140
141     fun resourceType(resourceType: JsonNode) {
142         property(ResourceResolutionComponent.INPUT_RESOURCE_TYPE, resourceType)
143     }
144
145     fun artifactPrefixNames(artifactPrefixNames: String) = artifactPrefixNames(artifactPrefixNames.jsonAsJsonType())
146
147     fun artifactPrefixNames(artifactPrefixNameList: List<String>) {
148         artifactPrefixNames(artifactPrefixNameList.asJsonString())
149     }
150
151     fun artifactPrefixNames(artifactPrefixNames: JsonNode) {
152         property(ResourceResolutionComponent.INPUT_ARTIFACT_PREFIX_NAMES, artifactPrefixNames)
153     }
154 }
155
156 class ComponentResourceResolutionOutputAssignmentBuilder : PropertiesAssignmentBuilder() {
157
158     fun status(status: String) = status(status.asJsonPrimitive())
159
160     fun status(status: JsonNode) {
161         property(ResourceResolutionComponent.OUTPUT_STATUS, status)
162     }
163
164     fun resourceAssignmentParams(resourceAssignmentParams: String) = resourceAssignmentParams(resourceAssignmentParams.asJsonType())
165
166     fun resourceAssignmentParams(resourceAssignmentParams: JsonNode) {
167         property(ResourceResolutionComponent.OUTPUT_RESOURCE_ASSIGNMENT_PARAMS, resourceAssignmentParams)
168     }
169 }