2 * Copyright © 2017-2018 AT&T Intellectual Property.
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.apps.controllerblueprints.service.enhancer
19 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError
20 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
21 import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType
22 import org.onap.ccsdk.apps.controllerblueprints.core.data.Workflow
23 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService
24 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintWorkflowEnhancer
25 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
26 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService
27 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
28 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
29 import org.springframework.beans.factory.config.ConfigurableBeanFactory
30 import org.springframework.context.annotation.Scope
31 import org.springframework.stereotype.Service
34 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
35 open class BluePrintWorkflowEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService,
36 private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService,
37 private val resourceAssignmentEnhancerService: ResourceAssignmentEnhancerService)
38 : BluePrintWorkflowEnhancer {
40 lateinit var bluePrintContext: BluePrintContext
41 lateinit var error: BluePrintError
43 private val workflowDataTypes: MutableMap<String, DataType> = hashMapOf()
45 override fun enhance(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, workflow: Workflow) {
46 this.bluePrintContext = bluePrintContext
49 // Enrich Only for Resource Assignment and Dynamic Input Properties if any
50 enhanceStepTargets(workflow)
52 // Enrich Workflow Inputs
53 enhanceWorkflowInputs(name, workflow)
56 open fun enhanceWorkflowInputs(name: String, workflow: Workflow) {
57 val dynamicPropertyName = "$name-properties"
58 workflow.inputs?.let { inputs ->
59 // TODO("Filter Dynamic Properties")
60 bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintContext, error, inputs)
64 private fun enhanceStepTargets(workflow: Workflow) {
66 val workflowNodeTemplates = workflowTargets(workflow)
68 workflowNodeTemplates.forEach { nodeTemplate ->
69 val artifactFiles = bluePrintContext.nodeTemplateByName(nodeTemplate).artifacts?.filter {
70 it.value.type == "artifact-mapping-resource"
75 artifactFiles?.let { fileName ->
76 val absoluteFilePath = "${bluePrintContext.rootPath}/$fileName"
77 // Enhance Resource Assignment File
78 enhanceResourceAssignmentFile(absoluteFilePath)
84 private fun workflowTargets(workflow: Workflow): List<String> {
85 return workflow.steps?.map {
87 }?.filterNotNull() ?: arrayListOf()
90 open fun enhanceResourceAssignmentFile(filePath: String) {
91 val resourceAssignments: MutableList<ResourceAssignment> = JacksonUtils.getListFromFile(filePath, ResourceAssignment::class.java)
92 as? MutableList<ResourceAssignment>
93 ?: throw BluePrintProcessorException("couldn't get ResourceAssignment definitions for the file($filePath)")
94 resourceAssignmentEnhancerService.enhanceBluePrint(bluePrintTypeEnhancerService, bluePrintContext, error, resourceAssignments)