c71541efd3d810f7604f9b107a680c5cb16144bd
[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.*
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) {
98         requestId(requestId.asJsonPrimitive())
99     }
100
101     fun requestId(requestId: JsonNode) {
102         property(ResourceResolutionComponent.INPUT_REQUEST_ID, requestId)
103     }
104
105     fun resourceId(resourceId: String) {
106         resourceId(resourceId.asJsonPrimitive())
107     }
108
109     fun resourceId(resourceId: JsonNode) {
110         property(ResourceResolutionComponent.INPUT_RESOURCE_ID, resourceId)
111     }
112
113     fun actionName(actionName: String) {
114         actionName(actionName.asJsonPrimitive())
115     }
116
117     fun actionName(actionName: JsonNode) {
118         property(ResourceResolutionComponent.INPUT_ACTION_NAME, actionName)
119     }
120
121     fun resolutionKey(resolutionKey: String) {
122         resolutionKey(resolutionKey.asJsonPrimitive())
123     }
124
125     fun resolutionKey(resolutionKey: JsonNode) {
126         property(ResourceResolutionComponent.INPUT_RESOLUTION_KEY, resolutionKey)
127     }
128
129     fun dynamicProperty(dynamicProperty: String) {
130         dynamicProperty(dynamicProperty.asJsonType())
131     }
132
133     fun dynamicProperty(dynamicProperty: JsonNode) {
134         property(ResourceResolutionComponent.INPUT_DYNAMIC_PROPERTIES, dynamicProperty)
135     }
136
137     fun occurrence(occurrence: Int) {
138         occurrence(occurrence.asJsonPrimitive())
139     }
140
141     fun occurrence(resolutionKey: JsonNode) {
142         property(ResourceResolutionComponent.INPUT_OCCURRENCE, resolutionKey)
143     }
144
145     fun storeResult(storeResult: Boolean) {
146         storeResult(storeResult.asJsonPrimitive())
147     }
148
149     fun storeResult(storeResult: JsonNode) {
150         property(ResourceResolutionComponent.INPUT_STORE_RESULT, storeResult)
151     }
152
153     fun resourceType(resourceType: String) {
154         resourceType(resourceType.asJsonPrimitive())
155     }
156
157     fun resourceType(resourceType: JsonNode) {
158         property(ResourceResolutionComponent.INPUT_RESOURCE_TYPE, resourceType)
159     }
160
161     fun artifactPrefixNames(artifactPrefixNames: String) = artifactPrefixNames(artifactPrefixNames.jsonAsJsonType())
162
163     fun artifactPrefixNames(artifactPrefixNameList: List<String>) {
164         artifactPrefixNames(artifactPrefixNameList.asJsonString())
165     }
166
167     fun artifactPrefixNames(artifactPrefixNames: JsonNode) {
168         property(ResourceResolutionComponent.INPUT_ARTIFACT_PREFIX_NAMES, artifactPrefixNames)
169     }
170 }
171
172 class ComponentResourceResolutionOutputAssignmentBuilder : PropertiesAssignmentBuilder() {
173
174     fun status(status: String) {
175         status(status.asJsonPrimitive())
176     }
177
178     fun status(status: JsonNode) {
179         property(ResourceResolutionComponent.OUTPUT_STATUS, status)
180     }
181
182     fun resourceAssignmentParams(resourceAssignmentParams: String) {
183         resourceAssignmentParams(resourceAssignmentParams.asJsonType())
184     }
185
186     fun resourceAssignmentParams(resourceAssignmentParams: JsonNode) {
187         property(ResourceResolutionComponent.OUTPUT_RESOURCE_ASSIGNMENT_PARAMS, resourceAssignmentParams)
188     }
189 }