aboutsummaryrefslogtreecommitdiffstats
path: root/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin')
-rw-r--r--heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/ConfigDeploy.kt27
-rw-r--r--heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/ConfigDeploySetup.kt93
-rw-r--r--heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/SimpleStatusCheck.kt89
3 files changed, 190 insertions, 19 deletions
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 c4849601..861cdf66 100644
--- a/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/ConfigDeploy.kt
+++ b/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/ConfigDeploy.kt
@@ -1,5 +1,5 @@
/*
- * Copyright © 2020 Aarna Networks, Inc.
+ * 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.
@@ -16,44 +16,33 @@
package org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts
-import com.fasterxml.jackson.databind.node.ObjectNode
import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.storedContentFromResolvedArtifactNB
-import org.onap.ccsdk.cds.blueprintsprocessor.rest.BasicAuthRestClientProperties
-import org.onap.ccsdk.cds.blueprintsprocessor.rest.RestClientProperties
-import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BasicAuthRestClientService
-import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService
import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction
-import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
import org.slf4j.LoggerFactory
-import org.springframework.http.HttpMethod
-import org.springframework.web.client.RestTemplate
open class ConfigDeploy : AbstractScriptComponentFunction() {
private val log = LoggerFactory.getLogger(ConfigDeploy::class.java)!!
- override suspend fun processNB(executionRequest: ExecutionServiceInput) {
-
- /*
- * Resolution key will come as part of config-deploy request payload.
- */
+ override fun getName(): String {
+ return "ConfigDeploy"
+ }
+ 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 retrive the data from DB")
+ log.info("Got the resolution_key: $resolution_key from config-deploy going to retrieve the data from DB")
+ val prefix = "config-deploy" // used in the config-assign resolution
- // Read the config-assing data using the resolution key + prefix name for the template
- // We can select the given configuration using the resolution_key
- val prefix = "cnf"
val payload = storedContentFromResolvedArtifactNB(resolution_key, prefix)
log.info("cnf configuration data from DB : \n$payload\n")
println("Run config-deploy")
println("$payload")
-
}
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/ConfigDeploySetup.kt b/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/ConfigDeploySetup.kt
new file mode 100644
index 00000000..2e6ec816
--- /dev/null
+++ b/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/ConfigDeploySetup.kt
@@ -0,0 +1,93 @@
+/*
+ * 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 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.resource.resolution.processor.ResourceAssignmentProcessor
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
+import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException
+import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
+import org.slf4j.LoggerFactory
+
+open class ConfigDeploySetup() : ResourceAssignmentProcessor() {
+
+ private val log = LoggerFactory.getLogger(ConfigDeploySetup::class.java)!!
+
+ override fun getName(): String {
+ return "ConfigDeploySetup"
+ }
+
+ override suspend fun processNB(resourceAssignment: ResourceAssignment) {
+
+ var retValue: ObjectNode? = null
+
+ try {
+ if (resourceAssignment.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()
+ val result: ObjectNode = objectMapper.createObjectNode()
+ 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")
+ 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")
+ if (templateName != null)
+ moduleData.put("k8s-rb-config-template-name", templateName)
+ if (templateSource != null)
+ moduleData.put("k8s-rb-config-template-source", templateSource)
+ 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())
+ break
+ }
+ }
+ }
+ }
+ retValue = result
+ }
+ ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, retValue)
+ } catch (e: Exception) {
+ log.error(e.message, e)
+ ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, "ERROR")
+
+ throw BlueprintProcessorException("Failed in template key ($resourceAssignment) assignments, cause: ${e.message}", e)
+ }
+ }
+
+ private fun getParamValueByName(params: JsonNode, paramName: String): String? {
+ for (param in params) {
+ if (param["name"].asText() == paramName) {
+ return param["value"].asText()
+ }
+ }
+ return null
+ }
+
+ override suspend fun recoverNB(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) {
+ 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
new file mode 100644
index 00000000..c775bb19
--- /dev/null
+++ b/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/SimpleStatusCheck.kt
@@ -0,0 +1,89 @@
+/*
+ * 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 com.fasterxml.jackson.databind.node.ObjectNode
+import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertiesService
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.K8sConnectionPluginConfiguration
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.instance.K8sPluginInstanceApi
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.instance.K8sRbInstanceStatus
+import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction
+import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintException
+import org.slf4j.LoggerFactory
+
+open class SimpleStatusCheck : AbstractScriptComponentFunction() {
+
+ private val log = LoggerFactory.getLogger(SimpleStatusCheck::class.java)!!
+
+ override fun getName(): String {
+ return "SimpleStatusCheck"
+ }
+
+ override suspend fun processNB(executionRequest: ExecutionServiceInput) {
+ log.info("SIMPLE STATUS CHECK - START")
+
+ val configValueSetup: ObjectNode = getDynamicProperties("config-deploy-setup") as ObjectNode
+
+ val bluePrintPropertiesService: BlueprintPropertiesService =
+ this.functionDependencyInstanceAsType("blueprintPropertiesService")
+
+ val k8sConfiguration = K8sConnectionPluginConfiguration(bluePrintPropertiesService)
+
+ var instanceApi = K8sPluginInstanceApi(k8sConfiguration)
+
+ var checkCount: Int = 30 // in the future to be read in from the input
+ 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)
+ instanceStatus?.resourcesStatus?.forEach {
+ if (it.gvk?.kind == "Pod") {
+ var version = it.gvk?.version!!
+ if (it.gvk?.group!! != "")
+ 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>
+
+ if ((podState?.get("phase") as String) != "Running") {
+ continueCheck = true
+ log.info("Pod ${it?.name} [$vfModuleName] has invalid state ${(podState?.get("phase"))}")
+ }
+ }
+ }
+ }
+ if (continueCheck) {
+ checkCount--
+ if (checkCount == 0)
+ throw BlueprintException("Pods State verification failed")
+ Thread.sleep(10000L)
+ } else
+ checkCount = 0
+ }
+
+ log.info("SIMPLE STATUS CHECK - END")
+ }
+
+ override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+ log.info("Executing Recovery")
+ this.addError("${runtimeException.message}")
+ }
+}