2 * Copyright © 2019 IBM.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution
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
32 /** Component Extensions **/
33 fun BluePrintTypes.nodeTypeComponentResourceResolution(): NodeType {
35 id = "component-resource-resolution", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
36 derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_COMPONENT,
37 description = "Resource Assignment Component"
41 ResourceResolutionComponent.ATTRIBUTE_ASSIGNMENT_PARAM, BluePrintConstants.DATA_TYPE_STRING,
45 ResourceResolutionComponent.ATTRIBUTE_STATUS, BluePrintConstants.DATA_TYPE_STRING,
49 operation("ResourceResolutionComponent", "ResourceResolutionComponent Operation") {
52 ResourceResolutionComponent.INPUT_REQUEST_ID, BluePrintConstants.DATA_TYPE_STRING,
53 true, "Request Id, Unique Id for the request."
57 ResourceResolutionComponent.INPUT_RESOURCE_ID, BluePrintConstants.DATA_TYPE_STRING,
62 ResourceResolutionComponent.INPUT_ACTION_NAME, BluePrintConstants.DATA_TYPE_STRING,
63 false, "Action Name of the process"
67 ResourceResolutionComponent.INPUT_DYNAMIC_PROPERTIES, BluePrintConstants.DATA_TYPE_JSON,
68 false, "Dynamic Json Content or DSL Json reference."
72 ResourceResolutionComponent.INPUT_RESOLUTION_KEY, BluePrintConstants.DATA_TYPE_STRING,
73 false, "Key for service instance related correlation."
77 ResourceResolutionComponent.INPUT_OCCURRENCE, BluePrintConstants.DATA_TYPE_INTEGER,
78 false, "Number of time to perform the resolution."
84 ResourceResolutionComponent.INPUT_STORE_RESULT, BluePrintConstants.DATA_TYPE_BOOLEAN,
85 false, "Whether or not to store the output."
89 ResourceResolutionComponent.INPUT_RESOURCE_TYPE, BluePrintConstants.DATA_TYPE_STRING,
90 false, "Request type."
94 ResourceResolutionComponent.INPUT_ARTIFACT_PREFIX_NAMES, BluePrintConstants.DATA_TYPE_LIST,
95 true, "Template , Resource Assignment Artifact Prefix names"
97 entrySchema(BluePrintConstants.DATA_TYPE_STRING)
102 ResourceResolutionComponent.OUTPUT_RESOURCE_ASSIGNMENT_PARAMS, BluePrintConstants.DATA_TYPE_STRING,
103 true, "Output Response"
106 ResourceResolutionComponent.OUTPUT_STATUS, BluePrintConstants.DATA_TYPE_STRING,
107 true, "Status of the Component Execution ( success or failure )"
114 /** Component Builder */
115 fun BluePrintTypes.nodeTemplateComponentResourceResolution(
118 block: ComponentResourceResolutionNodeTemplateBuilder.() -> Unit
121 return ComponentResourceResolutionNodeTemplateBuilder(id, description).apply(block).build()
124 class ComponentResourceResolutionNodeTemplateBuilder(id: String, description: String) :
125 AbstractNodeTemplateOperationImplBuilder<PropertiesAssignmentBuilder,
126 ComponentResourceResolutionNodeTemplateBuilder.InputsBuilder,
127 ComponentResourceResolutionNodeTemplateBuilder.OutputsBuilder>(
128 id, "component-script-executor",
129 "ComponentResourceResolution",
133 class InputsBuilder : PropertiesAssignmentBuilder() {
135 fun requestId(requestId: String) = requestId(requestId.asJsonPrimitive())
137 fun requestId(requestId: JsonNode) {
138 property(ResourceResolutionComponent.INPUT_REQUEST_ID, requestId)
141 fun resourceId(resourceId: String) = resourceId(resourceId.asJsonPrimitive())
143 fun resourceId(resourceId: JsonNode) {
144 property(ResourceResolutionComponent.INPUT_RESOURCE_ID, resourceId)
147 fun actionName(actionName: String) = actionName(actionName.asJsonPrimitive())
149 fun actionName(actionName: JsonNode) {
150 property(ResourceResolutionComponent.INPUT_ACTION_NAME, actionName)
153 fun resolutionKey(resolutionKey: String) = resolutionKey(resolutionKey.asJsonPrimitive())
155 fun resolutionKey(resolutionKey: JsonNode) {
156 property(ResourceResolutionComponent.INPUT_RESOLUTION_KEY, resolutionKey)
159 fun dynamicProperties(dynamicProperties: String) = dynamicProperties(dynamicProperties.asJsonType())
161 fun dynamicProperties(dynamicProperties: JsonNode) {
162 property(ResourceResolutionComponent.INPUT_DYNAMIC_PROPERTIES, dynamicProperties)
165 fun occurrence(occurrence: Int) = occurrence(occurrence.asJsonPrimitive())
167 fun occurrence(resolutionKey: JsonNode) {
168 property(ResourceResolutionComponent.INPUT_OCCURRENCE, resolutionKey)
171 fun storeResult(storeResult: Boolean) = storeResult(storeResult.asJsonPrimitive())
173 fun storeResult(storeResult: JsonNode) {
174 property(ResourceResolutionComponent.INPUT_STORE_RESULT, storeResult)
177 fun resourceType(resourceType: String) = resourceType(resourceType.asJsonPrimitive())
179 fun resourceType(resourceType: JsonNode) {
180 property(ResourceResolutionComponent.INPUT_RESOURCE_TYPE, resourceType)
183 fun artifactPrefixNames(artifactPrefixNames: String) = artifactPrefixNames(artifactPrefixNames.jsonAsJsonType())
185 fun artifactPrefixNames(artifactPrefixNameList: List<String>) =
186 artifactPrefixNames(artifactPrefixNameList.asJsonString())
188 fun artifactPrefixNames(artifactPrefixNames: JsonNode) {
189 property(ResourceResolutionComponent.INPUT_ARTIFACT_PREFIX_NAMES, artifactPrefixNames)
193 class OutputsBuilder : PropertiesAssignmentBuilder() {
195 fun status(status: String) = status(status.asJsonPrimitive())
197 fun status(status: JsonNode) {
198 property(ResourceResolutionComponent.OUTPUT_STATUS, status)
201 fun resourceAssignmentParams(resourceAssignmentParams: String) =
202 resourceAssignmentParams(resourceAssignmentParams.asJsonType())
204 fun resourceAssignmentParams(resourceAssignmentParams: JsonNode) {
205 property(ResourceResolutionComponent.OUTPUT_RESOURCE_ASSIGNMENT_PARAMS, resourceAssignmentParams)