2 * Copyright © 2021 Orange
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.services.execution.scripts
19 import com.fasterxml.jackson.databind.JsonNode
20 import com.fasterxml.jackson.databind.node.ObjectNode
21 import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
22 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor.ResourceAssignmentProcessor
23 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
24 import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException
25 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
26 import org.slf4j.LoggerFactory
28 open class ConfigDeploySetup() : ResourceAssignmentProcessor() {
30 private val log = LoggerFactory.getLogger(ConfigDeploySetup::class.java)!!
32 override fun getName(): String {
33 return "ConfigDeploySetup"
36 override suspend fun processNB(resourceAssignment: ResourceAssignment) {
38 var retValue: ObjectNode? = null
41 if (resourceAssignment.name == "config-deploy-setup") {
42 val modulesSdnc = raRuntimeService.getResolutionStore("vf-modules-list-sdnc")["vf-modules"]
43 val modulesAai = raRuntimeService.getResolutionStore("vf-modules-list-aai")["vf-modules"]
44 val objectMapper = jacksonObjectMapper()
45 val result: ObjectNode = objectMapper.createObjectNode()
46 for (module in modulesSdnc) {
47 val modelTopology = module.at("/vf-module-data/vf-module-topology")
48 val moduleParameters = modelTopology.at("/vf-module-parameters/param")
49 val label: String? = getParamValueByName(moduleParameters,"vf_module_label")
51 val modelInfo = modelTopology["onap-model-information"]
52 val moduleData: ObjectNode = objectMapper.createObjectNode()
53 result.put(label, moduleData)
54 moduleData.put("k8s-rb-definition-name", modelInfo["model-invariant-uuid"].asText())
55 moduleData.put("k8s-rb-definition-version", modelInfo["model-uuid"].asText())
56 val templateName: String? = getParamValueByName(moduleParameters,"k8s-rb-config-template-name")
57 val templateSource: String? = getParamValueByName(moduleParameters,"k8s-rb-config-template-source")
58 if (templateName != null)
59 moduleData.put("k8s-rb-config-template-name", templateName)
60 if (templateSource != null)
61 moduleData.put("k8s-rb-config-template-source", templateSource)
62 for (aaiModule in modulesAai) {
63 if (aaiModule["vf-module-id"].asText() == module["vf-module-id"].asText()) {
64 moduleData.put("k8s-instance-id", aaiModule["heat-stack-id"].asText())
72 ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, retValue)
73 } catch (e: Exception) {
74 log.error(e.message, e)
75 ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, "ERROR")
77 throw BlueprintProcessorException("Failed in template key ($resourceAssignment) assignments, cause: ${e.message}", e)
81 private fun getParamValueByName(params: JsonNode, paramName: String): String? {
82 for (param in params) {
83 if (param["name"].asText() == paramName) {
84 return param["value"].asText()
90 override suspend fun recoverNB(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) {
91 this.addError("${runtimeException.message}")