Renaming Files having BluePrint to have Blueprint
[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.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.asJsonString
24 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType
25 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate
26 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType
27 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.AbstractNodeTemplateOperationImplBuilder
28 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertiesAssignmentBuilder
29 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.ServiceTemplateBuilder
30 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.TopologyTemplateBuilder
31 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.nodeType
32 import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType
33
34 /** Component Extensions **/
35 fun ServiceTemplateBuilder.nodeTypeComponentResourceResolution() {
36     val nodeType = BlueprintTypes.nodeTypeComponentResourceResolution()
37     if (this.nodeTypes == null) this.nodeTypes = hashMapOf()
38     this.nodeTypes!![nodeType.id!!] = nodeType
39 }
40
41 fun BlueprintTypes.nodeTypeComponentResourceResolution(): NodeType {
42     return nodeType(
43         id = "component-resource-resolution", version = BlueprintConstants.DEFAULT_VERSION_NUMBER,
44         derivedFrom = BlueprintConstants.MODEL_TYPE_NODE_COMPONENT,
45         description = "Resource Assignment Component"
46     ) {
47
48         attribute(
49             ResourceResolutionComponent.ATTRIBUTE_ASSIGNMENT_PARAM, BlueprintConstants.DATA_TYPE_STRING,
50             true
51         )
52         attribute(
53             ResourceResolutionComponent.ATTRIBUTE_STATUS, BlueprintConstants.DATA_TYPE_STRING,
54             true
55         )
56
57         operation("ResourceResolutionComponent", "ResourceResolutionComponent Operation") {
58             inputs {
59                 property(
60                     ResourceResolutionComponent.INPUT_REQUEST_ID, BlueprintConstants.DATA_TYPE_STRING,
61                     true, "Request Id, Unique Id for the request."
62                 )
63
64                 property(
65                     ResourceResolutionComponent.INPUT_RESOURCE_ID, BlueprintConstants.DATA_TYPE_STRING,
66                     false, "Resource Id."
67                 )
68
69                 property(
70                     ResourceResolutionComponent.INPUT_ACTION_NAME, BlueprintConstants.DATA_TYPE_STRING,
71                     false, "Action Name of the process"
72                 )
73
74                 property(
75                     ResourceResolutionComponent.INPUT_DYNAMIC_PROPERTIES, BlueprintConstants.DATA_TYPE_JSON,
76                     false, "Dynamic Json Content or DSL Json reference."
77                 )
78
79                 property(
80                     ResourceResolutionComponent.INPUT_RESOLUTION_KEY, BlueprintConstants.DATA_TYPE_STRING,
81                     false, "Key for service instance related correlation."
82                 )
83
84                 property(
85                     ResourceResolutionComponent.INPUT_RESOLUTION_SUMMARY, BlueprintConstants.DATA_TYPE_BOOLEAN,
86                     false, "Enables ResolutionSummary output"
87                 )
88
89                 property(
90                     ResourceResolutionComponent.INPUT_OCCURRENCE, BlueprintConstants.DATA_TYPE_INTEGER,
91                     false, "Number of time to perform the resolution."
92                 ) {
93                     defaultValue(1)
94                 }
95
96                 property(
97                     ResourceResolutionComponent.INPUT_STORE_RESULT, BlueprintConstants.DATA_TYPE_BOOLEAN,
98                     false, "Whether or not to store the output."
99                 )
100
101                 property(
102                     ResourceResolutionComponent.INPUT_RESOURCE_TYPE, BlueprintConstants.DATA_TYPE_STRING,
103                     false, "Request type."
104                 )
105
106                 property(
107                     ResourceResolutionComponent.INPUT_ARTIFACT_PREFIX_NAMES, BlueprintConstants.DATA_TYPE_LIST,
108                     true, "Template , Resource Assignment Artifact Prefix names"
109                 ) {
110                     entrySchema(BlueprintConstants.DATA_TYPE_STRING)
111                 }
112             }
113             outputs {
114                 property(
115                     ResourceResolutionComponent.OUTPUT_RESOURCE_ASSIGNMENT_PARAMS, BlueprintConstants.DATA_TYPE_STRING,
116                     true, "Output Response"
117                 )
118                 property(
119                     ResourceResolutionComponent.OUTPUT_RESOURCE_ASSIGNMENT_MAP, BlueprintConstants.DATA_TYPE_MAP,
120                     true, "Output Resolved Values"
121                 )
122                 property(
123                     ResourceResolutionComponent.OUTPUT_STATUS, BlueprintConstants.DATA_TYPE_STRING,
124                     true, "Status of the Component Execution ( success or failure )"
125                 )
126             }
127         }
128     }
129 }
130
131 /** Component Builder */
132 fun TopologyTemplateBuilder.nodeTemplateComponentResourceResolution(
133     id: String,
134     description: String,
135     block: ComponentResourceResolutionNodeTemplateBuilder.() -> Unit
136 ) {
137     val nodeTemplate = BlueprintTypes.nodeTemplateComponentResourceResolution(
138         id, description,
139         block
140     )
141     if (nodeTemplates == null) nodeTemplates = hashMapOf()
142     nodeTemplates!![nodeTemplate.id!!] = nodeTemplate
143 }
144
145 fun BlueprintTypes.nodeTemplateComponentResourceResolution(
146     id: String,
147     description: String,
148     block: ComponentResourceResolutionNodeTemplateBuilder.() -> Unit
149 ): NodeTemplate {
150     return ComponentResourceResolutionNodeTemplateBuilder(id, description).apply(block).build()
151 }
152
153 class ComponentResourceResolutionNodeTemplateBuilder(id: String, description: String) :
154     AbstractNodeTemplateOperationImplBuilder<PropertiesAssignmentBuilder,
155         ComponentResourceResolutionNodeTemplateBuilder.InputsBuilder,
156         ComponentResourceResolutionNodeTemplateBuilder.OutputsBuilder>(
157         id, "component-script-executor",
158         "ComponentResourceResolution",
159         description
160     ) {
161
162     class InputsBuilder : PropertiesAssignmentBuilder() {
163
164         fun requestId(requestId: String) = requestId(requestId.asJsonPrimitive())
165
166         fun requestId(requestId: JsonNode) {
167             property(ResourceResolutionComponent.INPUT_REQUEST_ID, requestId)
168         }
169
170         fun resourceId(resourceId: String) = resourceId(resourceId.asJsonPrimitive())
171
172         fun resourceId(resourceId: JsonNode) {
173             property(ResourceResolutionComponent.INPUT_RESOURCE_ID, resourceId)
174         }
175
176         fun actionName(actionName: String) = actionName(actionName.asJsonPrimitive())
177
178         fun actionName(actionName: JsonNode) {
179             property(ResourceResolutionComponent.INPUT_ACTION_NAME, actionName)
180         }
181
182         fun resolutionKey(resolutionKey: String) = resolutionKey(resolutionKey.asJsonPrimitive())
183
184         fun resolutionKey(resolutionKey: JsonNode) {
185             property(ResourceResolutionComponent.INPUT_RESOLUTION_KEY, resolutionKey)
186         }
187
188         fun resolutionSummary(resolutionSummary: Boolean) = resolutionSummary(resolutionSummary.asJsonPrimitive())
189
190         fun resolutionSummary(resolutionSummary: JsonNode) {
191             property(ResourceResolutionComponent.INPUT_RESOLUTION_SUMMARY, resolutionSummary)
192         }
193
194         fun dynamicProperties(dynamicProperties: String) = dynamicProperties(dynamicProperties.asJsonType())
195
196         fun dynamicProperties(dynamicProperties: JsonNode) {
197             property(ResourceResolutionComponent.INPUT_DYNAMIC_PROPERTIES, dynamicProperties)
198         }
199
200         fun occurrence(occurrence: Int) = occurrence(occurrence.asJsonPrimitive())
201
202         fun occurrence(resolutionKey: JsonNode) {
203             property(ResourceResolutionComponent.INPUT_OCCURRENCE, resolutionKey)
204         }
205
206         fun storeResult(storeResult: Boolean) = storeResult(storeResult.asJsonPrimitive())
207
208         fun storeResult(storeResult: JsonNode) {
209             property(ResourceResolutionComponent.INPUT_STORE_RESULT, storeResult)
210         }
211
212         fun resourceType(resourceType: String) = resourceType(resourceType.asJsonPrimitive())
213
214         fun resourceType(resourceType: JsonNode) {
215             property(ResourceResolutionComponent.INPUT_RESOURCE_TYPE, resourceType)
216         }
217
218         fun artifactPrefixNames(artifactPrefixNames: String) = artifactPrefixNames(artifactPrefixNames.jsonAsJsonType())
219
220         fun artifactPrefixNames(artifactPrefixNameList: List<String>) =
221             artifactPrefixNames(artifactPrefixNameList.asJsonString())
222
223         fun artifactPrefixNames(artifactPrefixNames: JsonNode) {
224             property(ResourceResolutionComponent.INPUT_ARTIFACT_PREFIX_NAMES, artifactPrefixNames)
225         }
226     }
227
228     class OutputsBuilder : PropertiesAssignmentBuilder() {
229
230         fun status(status: String) = status(status.asJsonPrimitive())
231
232         fun status(status: JsonNode) {
233             property(ResourceResolutionComponent.OUTPUT_STATUS, status)
234         }
235
236         fun resourceAssignmentMap(resourceAssignmentMap: String) =
237             resourceAssignmentMap(resourceAssignmentMap.asJsonType())
238
239         fun resourceAssignmentMap(resourceAssignmentMap: JsonNode) {
240             property(ResourceResolutionComponent.OUTPUT_RESOURCE_ASSIGNMENT_MAP, resourceAssignmentMap)
241         }
242
243         fun resourceAssignmentParams(resourceAssignmentParams: String) =
244             resourceAssignmentParams(resourceAssignmentParams.asJsonType())
245
246         fun resourceAssignmentParams(resourceAssignmentParams: JsonNode) {
247             property(ResourceResolutionComponent.OUTPUT_RESOURCE_ASSIGNMENT_PARAMS, resourceAssignmentParams)
248         }
249     }
250 }