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