Merge "Add support for Ansible packages"
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / resource-resolution / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / functions / resource / resolution / ResourceResolutionComponent.kt
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  * Modifications Copyright © 2019 IBM.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution
19
20 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
21 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction
22 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
23 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonNode
24 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
25 import org.springframework.beans.factory.config.ConfigurableBeanFactory
26 import org.springframework.context.annotation.Scope
27 import org.springframework.stereotype.Component
28
29 @Component("component-resource-resolution")
30 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
31 open class ResourceResolutionComponent(private val resourceResolutionService: ResourceResolutionService) :
32     AbstractComponentFunction() {
33
34     override suspend fun processNB(executionRequest: ExecutionServiceInput) {
35
36         val properties: MutableMap<String, Any> = mutableMapOf()
37
38         try {
39             val key = getOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_KEY)
40             val storeResult = getOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT)
41             properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_KEY] = key.asText()
42             properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] = storeResult.asBoolean()
43         } catch (e: BluePrintProcessorException) {
44             // NoOp - these property aren't mandatory, so don't fail the process if not provided.
45         }
46
47         val artifactPrefixNamesNode = getOperationInput(ResourceResolutionConstants.INPUT_ARTIFACT_PREFIX_NAMES)
48         val artifactPrefixNames = JacksonUtils.getListFromJsonNode(artifactPrefixNamesNode, String::class.java)
49
50         val resolvedParamContents = resourceResolutionService.resolveResources(bluePrintRuntimeService,
51             nodeTemplateName,
52             artifactPrefixNames,
53             properties)
54
55         // Set Output Attributes
56         bluePrintRuntimeService.setNodeTemplateAttributeValue(nodeTemplateName,
57             ResourceResolutionConstants.OUTPUT_ASSIGNMENT_PARAMS, resolvedParamContents.asJsonNode())
58     }
59
60     override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
61         bluePrintRuntimeService.getBluePrintError().addError(runtimeException.message!!)
62     }
63 }