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.*
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.AbstractNodeTemplateOperationImplBuilder
24 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertiesAssignmentBuilder
25 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.nodeType
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") {
33 attribute(ResourceResolutionComponent.ATTRIBUTE_ASSIGNMENT_PARAM, BluePrintConstants.DATA_TYPE_STRING,
35 attribute(ResourceResolutionComponent.ATTRIBUTE_STATUS, BluePrintConstants.DATA_TYPE_STRING,
38 operation("ResourceResolutionComponent", "ResourceResolutionComponent Operation") {
40 property(ResourceResolutionComponent.INPUT_REQUEST_ID, BluePrintConstants.DATA_TYPE_STRING,
41 true, "Request Id, Unique Id for the request.")
43 property(ResourceResolutionComponent.INPUT_RESOURCE_ID, BluePrintConstants.DATA_TYPE_STRING,
44 false, "Resource Id.")
46 property(ResourceResolutionComponent.INPUT_ACTION_NAME, BluePrintConstants.DATA_TYPE_STRING,
47 false, "Action Name of the process")
49 property(ResourceResolutionComponent.INPUT_DYNAMIC_PROPERTIES, BluePrintConstants.DATA_TYPE_JSON,
50 false, "Dynamic Json Content or DSL Json reference.")
52 property(ResourceResolutionComponent.INPUT_RESOLUTION_KEY, BluePrintConstants.DATA_TYPE_STRING,
53 false, "Key for service instance related correlation.")
55 property(ResourceResolutionComponent.INPUT_OCCURRENCE, BluePrintConstants.DATA_TYPE_INTEGER,
56 false, "Number of time to perform the resolution.") {
60 property(ResourceResolutionComponent.INPUT_STORE_RESULT, BluePrintConstants.DATA_TYPE_BOOLEAN,
61 false, "Whether or not to store the output.")
63 property(ResourceResolutionComponent.INPUT_RESOURCE_TYPE, BluePrintConstants.DATA_TYPE_STRING,
64 false, "Request type.")
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)
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 )")
81 /** Component Builder */
82 fun BluePrintTypes.nodeTemplateComponentResourceResolution(id: String,
84 block: ComponentResourceResolutionNodeTemplateBuilder.() -> Unit)
86 return ComponentResourceResolutionNodeTemplateBuilder(id, description).apply(block).build()
89 class ComponentResourceResolutionNodeTemplateBuilder(id: String, description: String) :
90 AbstractNodeTemplateOperationImplBuilder<PropertiesAssignmentBuilder,
91 ComponentResourceResolutionNodeTemplateBuilder.InputsBuilder,
92 ComponentResourceResolutionNodeTemplateBuilder.OutputsBuilder>(id, "component-script-executor",
93 "ComponentResourceResolution",
96 class InputsBuilder : PropertiesAssignmentBuilder() {
98 fun requestId(requestId: String) = requestId(requestId.asJsonPrimitive())
100 fun requestId(requestId: JsonNode) {
101 property(ResourceResolutionComponent.INPUT_REQUEST_ID, requestId)
104 fun resourceId(resourceId: String) = resourceId(resourceId.asJsonPrimitive())
106 fun resourceId(resourceId: JsonNode) {
107 property(ResourceResolutionComponent.INPUT_RESOURCE_ID, resourceId)
110 fun actionName(actionName: String) = actionName(actionName.asJsonPrimitive())
112 fun actionName(actionName: JsonNode) {
113 property(ResourceResolutionComponent.INPUT_ACTION_NAME, actionName)
116 fun resolutionKey(resolutionKey: String) = resolutionKey(resolutionKey.asJsonPrimitive())
118 fun resolutionKey(resolutionKey: JsonNode) {
119 property(ResourceResolutionComponent.INPUT_RESOLUTION_KEY, resolutionKey)
122 fun dynamicProperties(dynamicProperties: String) = dynamicProperties(dynamicProperties.asJsonType())
124 fun dynamicProperties(dynamicProperties: JsonNode) {
125 property(ResourceResolutionComponent.INPUT_DYNAMIC_PROPERTIES, dynamicProperties)
128 fun occurrence(occurrence: Int) = occurrence(occurrence.asJsonPrimitive())
130 fun occurrence(resolutionKey: JsonNode) {
131 property(ResourceResolutionComponent.INPUT_OCCURRENCE, resolutionKey)
134 fun storeResult(storeResult: Boolean) = storeResult(storeResult.asJsonPrimitive())
136 fun storeResult(storeResult: JsonNode) {
137 property(ResourceResolutionComponent.INPUT_STORE_RESULT, storeResult)
140 fun resourceType(resourceType: String) = resourceType(resourceType.asJsonPrimitive())
142 fun resourceType(resourceType: JsonNode) {
143 property(ResourceResolutionComponent.INPUT_RESOURCE_TYPE, resourceType)
146 fun artifactPrefixNames(artifactPrefixNames: String) = artifactPrefixNames(artifactPrefixNames.jsonAsJsonType())
148 fun artifactPrefixNames(artifactPrefixNameList: List<String>) =
149 artifactPrefixNames(artifactPrefixNameList.asJsonString())
151 fun artifactPrefixNames(artifactPrefixNames: JsonNode) {
152 property(ResourceResolutionComponent.INPUT_ARTIFACT_PREFIX_NAMES, artifactPrefixNames)
156 class OutputsBuilder : PropertiesAssignmentBuilder() {
158 fun status(status: String) = status(status.asJsonPrimitive())
160 fun status(status: JsonNode) {
161 property(ResourceResolutionComponent.OUTPUT_STATUS, status)
164 fun resourceAssignmentParams(resourceAssignmentParams: String) =
165 resourceAssignmentParams(resourceAssignmentParams.asJsonType())
167 fun resourceAssignmentParams(resourceAssignmentParams: JsonNode) {
168 property(ResourceResolutionComponent.OUTPUT_RESOURCE_ASSIGNMENT_PARAMS, resourceAssignmentParams)