diff options
author | Lukasz Rajewski <lukasz.rajewski@orange.com> | 2021-03-24 19:15:31 +0100 |
---|---|---|
committer | Lukasz Rajewski <lukasz.rajewski@orange.com> | 2021-03-28 22:21:25 +0200 |
commit | 06bf0ac45889ffe00fc6e27e68ffa15c2f519e6f (patch) | |
tree | ecf4c17542c62ee6c0433edcbccac5707370a8f1 /heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin | |
parent | d2c5f361fa3a246dfa23c2c582ec498322a97282 (diff) |
Real vFW CNF config-assign and config-deploy
Implementation of vFW CNF config-assign and config-deploy with
utilization of CDS native components for configuration API
Change-Id: I016b186e1fcad0bf1285292f2e93e12a1d96b63e
Issue-ID: INT-1868
Signed-off-by: Lukasz Rajewski <lukasz.rajewski@orange.com>
Diffstat (limited to 'heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin')
5 files changed, 125 insertions, 23 deletions
diff --git a/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/CollectorScript.kt b/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/CollectorScript.kt new file mode 100644 index 00000000..a9de1972 --- /dev/null +++ b/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/CollectorScript.kt @@ -0,0 +1,51 @@ +/* + * Copyright © 2021 Bell Canada. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts + +import com.fasterxml.jackson.databind.JsonNode +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction +import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentScriptExecutor +import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonNode +import org.onap.ccsdk.cds.controllerblueprints.core.logger + +open class CollectorScript : AbstractScriptComponentFunction() { + + private val log = logger(CollectorScript::class) + + override suspend fun processNB(executionRequest: ExecutionServiceInput) { + bluePrintRuntimeService.bluePrintContext() + .serviceTemplate.topologyTemplate!!.nodeTemplates!! + .keys.filter { it.startsWith("execute-script") } + .associateWith { responseData(it) } + .let { it.asJsonNode() } + .also { log.info("Collected results: $it") } + .let { setAttribute(ComponentScriptExecutor.ATTRIBUTE_RESPONSE_DATA, it) } + } + + private fun responseData(nodeTemplateName: String): JsonNode? { + return try { + bluePrintRuntimeService.getNodeTemplateAttributeValue(nodeTemplateName, + ComponentScriptExecutor.ATTRIBUTE_RESPONSE_DATA) + } catch (exception: BlueprintProcessorException) { null } + } + + override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { + addError(runtimeException.message ?: "Failed without error message") + } +} diff --git a/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/ConfigDeploy.kt b/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/ConfigDeploy.kt index 861cdf66..96b3c515 100644 --- a/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/ConfigDeploy.kt +++ b/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/ConfigDeploy.kt @@ -30,11 +30,11 @@ open class ConfigDeploy : AbstractScriptComponentFunction() { } override suspend fun processNB(executionRequest: ExecutionServiceInput) { - val resolution_key = getDynamicProperties("resolution-key").asText() - log.info("Got the resolution_key: $resolution_key from config-deploy going to retrieve the data from DB") + val resolutionKey = getDynamicProperties("resolution-key").asText() + log.info("Got the resolution_key: $resolutionKey from config-deploy going to retrieve the data from DB") val prefix = "config-deploy" // used in the config-assign resolution - val payload = storedContentFromResolvedArtifactNB(resolution_key, prefix) + val payload = storedContentFromResolvedArtifactNB(resolutionKey, prefix) log.info("cnf configuration data from DB : \n$payload\n") println("Run config-deploy") diff --git a/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/ConfigDeploySetup.kt b/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/ConfigDeploySetup.kt index 2e6ec816..f04813df 100644 --- a/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/ConfigDeploySetup.kt +++ b/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/ConfigDeploySetup.kt @@ -19,6 +19,8 @@ package org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.node.ObjectNode import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.definition.template.K8sConfigTemplateComponent +import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.definition.template.K8sConfigValueComponent import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor.ResourceAssignmentProcessor import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException @@ -33,12 +35,12 @@ open class ConfigDeploySetup() : ResourceAssignmentProcessor() { return "ConfigDeploySetup" } - override suspend fun processNB(resourceAssignment: ResourceAssignment) { + override suspend fun processNB(executionRequest: ResourceAssignment) { var retValue: ObjectNode? = null try { - if (resourceAssignment.name == "config-deploy-setup") { + if (executionRequest.name == "config-deploy-setup") { val modulesSdnc = raRuntimeService.getResolutionStore("vf-modules-list-sdnc")["vf-modules"] val modulesAai = raRuntimeService.getResolutionStore("vf-modules-list-aai")["vf-modules"] val objectMapper = jacksonObjectMapper() @@ -46,22 +48,30 @@ open class ConfigDeploySetup() : ResourceAssignmentProcessor() { for (module in modulesSdnc) { val modelTopology = module.at("/vf-module-data/vf-module-topology") val moduleParameters = modelTopology.at("/vf-module-parameters/param") - val label: String? = getParamValueByName(moduleParameters,"vf_module_label") + val label: String? = getParamValueByName(moduleParameters, "vf_module_label") if (label != null) { val modelInfo = modelTopology["onap-model-information"] val moduleData: ObjectNode = objectMapper.createObjectNode() result.put(label, moduleData) - moduleData.put("k8s-rb-definition-name", modelInfo["model-invariant-uuid"].asText()) - moduleData.put("k8s-rb-definition-version", modelInfo["model-uuid"].asText()) - val templateName: String? = getParamValueByName(moduleParameters,"k8s-rb-config-template-name") - val templateSource: String? = getParamValueByName(moduleParameters,"k8s-rb-config-template-source") + moduleData.put(K8sConfigTemplateComponent.INPUT_K8S_DEFINITION_NAME, modelInfo["model-invariant-uuid"].asText()) + moduleData.put(K8sConfigTemplateComponent.INPUT_K8S_DEFINITION_VERSION, modelInfo["model-uuid"].asText()) + val templateName: String? = getParamValueByName(moduleParameters, K8sConfigTemplateComponent.INPUT_K8S_TEMPLATE_NAME) + val templateSource: String? = getParamValueByName(moduleParameters, K8sConfigTemplateComponent.INPUT_K8S_TEMPLATE_SOURCE) + val configValueSource: String? = getParamValueByName(moduleParameters, K8sConfigValueComponent.INPUT_K8S_CONFIG_VALUE_SOURCE) + val configName: String? = getParamValueByName(moduleParameters, K8sConfigValueComponent.INPUT_K8S_RB_CONFIG_NAME) + if (templateName != null) - moduleData.put("k8s-rb-config-template-name", templateName) + moduleData.put(K8sConfigTemplateComponent.INPUT_K8S_TEMPLATE_NAME, templateName) if (templateSource != null) - moduleData.put("k8s-rb-config-template-source", templateSource) + moduleData.put(K8sConfigTemplateComponent.INPUT_K8S_TEMPLATE_SOURCE, templateSource) + if (configValueSource != null) + moduleData.put(K8sConfigValueComponent.INPUT_K8S_CONFIG_VALUE_SOURCE, configValueSource) + if (configName != null) + moduleData.put(K8sConfigValueComponent.INPUT_K8S_RB_CONFIG_NAME, configName) + for (aaiModule in modulesAai) { if (aaiModule["vf-module-id"].asText() == module["vf-module-id"].asText()) { - moduleData.put("k8s-instance-id", aaiModule["heat-stack-id"].asText()) + moduleData.put(K8sConfigValueComponent.INPUT_K8S_INSTANCE_ID, aaiModule["heat-stack-id"].asText()) break } } @@ -69,12 +79,12 @@ open class ConfigDeploySetup() : ResourceAssignmentProcessor() { } retValue = result } - ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, retValue) + ResourceAssignmentUtils.setResourceDataValue(executionRequest, raRuntimeService, retValue) } catch (e: Exception) { log.error(e.message, e) - ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, "ERROR") + ResourceAssignmentUtils.setResourceDataValue(executionRequest, raRuntimeService, "ERROR") - throw BlueprintProcessorException("Failed in template key ($resourceAssignment) assignments, cause: ${e.message}", e) + throw BlueprintProcessorException("Failed in template key ($executionRequest) assignments, cause: ${e.message}", e) } } @@ -87,7 +97,7 @@ open class ConfigDeploySetup() : ResourceAssignmentProcessor() { return null } - override suspend fun recoverNB(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) { + override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ResourceAssignment) { this.addError("${runtimeException.message}") } } diff --git a/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/SimpleErrorCheck.kt b/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/SimpleErrorCheck.kt new file mode 100644 index 00000000..8e4a58ab --- /dev/null +++ b/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/SimpleErrorCheck.kt @@ -0,0 +1,41 @@ +/* + * Copyright © 2021 Orange + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts + +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction +import org.slf4j.LoggerFactory + +open class SimpleErrorCheck : AbstractScriptComponentFunction() { + + private val log = LoggerFactory.getLogger(SimpleErrorCheck::class.java)!! + + override fun getName(): String { + return "SimpleErrorCheck" + } + + override suspend fun processNB(executionRequest: ExecutionServiceInput) { + log.info("SIMPLE ERROR CHECK - START") + + log.info("SIMPLE ERROR CHECK - END") + } + + override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { + log.info("Executing Recovery") + this.addError("${runtimeException.message}") + } +} diff --git a/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/SimpleStatusCheck.kt b/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/SimpleStatusCheck.kt index c775bb19..90330644 100644 --- a/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/SimpleStatusCheck.kt +++ b/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/SimpleStatusCheck.kt @@ -44,16 +44,16 @@ open class SimpleStatusCheck : AbstractScriptComponentFunction() { val k8sConfiguration = K8sConnectionPluginConfiguration(bluePrintPropertiesService) - var instanceApi = K8sPluginInstanceApi(k8sConfiguration) + val instanceApi = K8sPluginInstanceApi(k8sConfiguration) var checkCount: Int = 30 // in the future to be read in from the input - while(checkCount > 0) { + while (checkCount > 0) { var continueCheck = false configValueSetup.fields().forEach { it -> val vfModuleName = it.key val instanceName = it.value.get("k8s-instance-id").asText() - var instanceStatus: K8sRbInstanceStatus? = instanceApi.getInstanceStatus(instanceName) + val instanceStatus: K8sRbInstanceStatus? = instanceApi.getInstanceStatus(instanceName) instanceStatus?.resourcesStatus?.forEach { if (it.gvk?.kind == "Pod") { var version = it.gvk?.version!! @@ -61,11 +61,11 @@ open class SimpleStatusCheck : AbstractScriptComponentFunction() { version = "${it.gvk?.group}/$version" // val podStatus = instanceApi.queryInstanceStatus(instanceName, it.gvk?.kind!!, version, it.name, null) // log.info(podStatus.toString()) - var podState = it.status?.get("status") as Map<String, Object> + val podState = it.status?.get("status") as Map<String, Object> - if ((podState?.get("phase") as String) != "Running") { + if ((podState["phase"] as String) != "Running") { continueCheck = true - log.info("Pod ${it?.name} [$vfModuleName] has invalid state ${(podState?.get("phase"))}") + log.info("Pod ${it.name} [$vfModuleName] has invalid state ${(podState["phase"])}") } } } |