0becc00c730f57ac27ae037b777efa8de0c41fe9
[ccsdk/cds.git] /
1 /*\r
2  * Copyright © 2017-2018 AT&T Intellectual Property.\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution\r
18 \r
19 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput\r
20 import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction\r
21 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException\r
22 import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode\r
23 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils\r
24 import org.springframework.beans.factory.annotation.Autowired\r
25 import org.springframework.beans.factory.config.ConfigurableBeanFactory\r
26 import org.springframework.context.ApplicationContext\r
27 import org.springframework.context.annotation.Scope\r
28 import org.springframework.stereotype.Component\r
29 \r
30 @Component("component-resource-resolution")\r
31 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)\r
32 open class ResourceResolutionComponent(private val resourceResolutionService: ResourceResolutionService) : AbstractComponentFunction() {\r
33 \r
34     @Autowired\r
35     private lateinit var applicationContext: ApplicationContext\r
36 \r
37     override fun process(executionRequest: ExecutionServiceInput) {\r
38 \r
39         val artifactPrefixNamesNode = getOperationInput(ResourceResolutionConstants.INPUT_ARTIFACT_PREFIX_NAMES)\r
40 \r
41         val artifactPrefixNames = JacksonUtils.getListFromJsonNode(artifactPrefixNamesNode, String::class.java)\r
42                 ?: throw BluePrintProcessorException("couldn't transform ${artifactPrefixNamesNode.asText()} to string array")\r
43 \r
44         val resolvedParamContents = resourceResolutionService.resolveResources(bluePrintRuntimeService, nodeTemplateName, artifactPrefixNames)\r
45 \r
46         // Set Output Attributes\r
47         bluePrintRuntimeService.setNodeTemplateAttributeValue(nodeTemplateName,\r
48                 ResourceResolutionConstants.OUTPUT_ASSIGNMENT_PARAMS, resolvedParamContents.asJsonNode())\r
49     }\r
50 \r
51     override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {\r
52         TODO("not implemented") //To change body of created functions use File | Settings | File Templates.\r
53     }\r
54 }