aboutsummaryrefslogtreecommitdiffstats
path: root/components/model-catalog/blueprint-model/uat-blueprints/PNF_CDS_RESTCONF
diff options
context:
space:
mode:
Diffstat (limited to 'components/model-catalog/blueprint-model/uat-blueprints/PNF_CDS_RESTCONF')
-rw-r--r--components/model-catalog/blueprint-model/uat-blueprints/PNF_CDS_RESTCONF/Scripts/kotlin/RestconfConfigDeploy.kt21
-rw-r--r--components/model-catalog/blueprint-model/uat-blueprints/PNF_CDS_RESTCONF/Scripts/kotlin/RestconfSoftwareUpgrade.kt100
2 files changed, 70 insertions, 51 deletions
diff --git a/components/model-catalog/blueprint-model/uat-blueprints/PNF_CDS_RESTCONF/Scripts/kotlin/RestconfConfigDeploy.kt b/components/model-catalog/blueprint-model/uat-blueprints/PNF_CDS_RESTCONF/Scripts/kotlin/RestconfConfigDeploy.kt
index 730565959..154792873 100644
--- a/components/model-catalog/blueprint-model/uat-blueprints/PNF_CDS_RESTCONF/Scripts/kotlin/RestconfConfigDeploy.kt
+++ b/components/model-catalog/blueprint-model/uat-blueprints/PNF_CDS_RESTCONF/Scripts/kotlin/RestconfConfigDeploy.kt
@@ -16,10 +16,8 @@
* ============LICENSE_END=========================================================
*/
-
package cba.pnf.config.aai
-
import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.contentFromResolvedArtifactNB
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.storedContentFromResolvedArtifactNB
@@ -35,6 +33,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService.WebClientResponse
class RestconfConfigDeploy : AbstractScriptComponentFunction() {
+
private val CONFIGLET_TEMPLATE_NAME = "config-assign"
private val CONFIGLET_RESOURCE_PATH = "yang-ext:mount/mynetconf:netconflist"
private val RESTCONF_SERVER_IDENTIFIER = "sdnc"
@@ -57,13 +56,15 @@ class RestconfConfigDeploy : AbstractScriptComponentFunction() {
log.debug("Mounting Device : $deviceID")
restconfMountDevice(webclientService, deviceID, mountPayload, mutableMapOf("Content-Type" to "application/json"))
- //Log the current configuration for the subtree
+ // Log the current configuration for the subtree
val currentConfig: Any = restconfDeviceConfig(webclientService, deviceID, CONFIGLET_RESOURCE_PATH)
log.info("Current configuration subtree : $currentConfig")
- //Apply configlet
- val result = restconfApplyDeviceConfig(webclientService, deviceID, CONFIGLET_RESOURCE_PATH,
- storedContentFromResolvedArtifactNB(resolutionKey, CONFIGLET_TEMPLATE_NAME),
- mutableMapOf("Content-Type" to "application/yang.patch+json")) as WebClientResponse<*>
+ // Apply configlet
+ val result = restconfApplyDeviceConfig(
+ webclientService, deviceID, CONFIGLET_RESOURCE_PATH,
+ storedContentFromResolvedArtifactNB(resolutionKey, CONFIGLET_TEMPLATE_NAME),
+ mutableMapOf("Content-Type" to "application/yang.patch+json")
+ ) as WebClientResponse<*>
val jsonResult = mapper.readTree((result.body).toString())
@@ -72,11 +73,10 @@ class RestconfConfigDeploy : AbstractScriptComponentFunction() {
} else {
log.info("Device has been configured succesfully")
}
-
} catch (err: Exception) {
log.error("an error occurred while configuring device {}", err)
} finally {
- //Un mount device
+ // Un mount device
restconfUnMountDevice(webclientService, deviceID, "")
}
} catch (bpe: BluePrintProcessorException) {
@@ -84,10 +84,9 @@ class RestconfConfigDeploy : AbstractScriptComponentFunction() {
}
}
-
override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
log.info("Recover function called!")
log.info("Execution request : $executionRequest")
log.error("Exception", runtimeException)
}
-} \ No newline at end of file
+}
diff --git a/components/model-catalog/blueprint-model/uat-blueprints/PNF_CDS_RESTCONF/Scripts/kotlin/RestconfSoftwareUpgrade.kt b/components/model-catalog/blueprint-model/uat-blueprints/PNF_CDS_RESTCONF/Scripts/kotlin/RestconfSoftwareUpgrade.kt
index 0540efe80..e238c3e25 100644
--- a/components/model-catalog/blueprint-model/uat-blueprints/PNF_CDS_RESTCONF/Scripts/kotlin/RestconfSoftwareUpgrade.kt
+++ b/components/model-catalog/blueprint-model/uat-blueprints/PNF_CDS_RESTCONF/Scripts/kotlin/RestconfSoftwareUpgrade.kt
@@ -16,7 +16,6 @@
* ============LICENSE_END=========================================================
*/
-
package cba.pnf.swug
import com.fasterxml.jackson.databind.node.ObjectNode
@@ -45,10 +44,12 @@ class RestconfSoftwareUpgrade : AbstractScriptComponentFunction() {
override suspend fun processNB(executionRequest: ExecutionServiceInput) {
// Extract request properties
- val model= validatedPayload(executionRequest)
+ val model = validatedPayload(executionRequest)
- log.info("Blueprint invoked for ${model.resolutionKey} for SW Upgrade : " +
- "${model.action} for sw version ${model.targetSwVersion} on pnf: ${model.deviceId}")
+ log.info(
+ "Blueprint invoked for ${model.resolutionKey} for SW Upgrade : " +
+ "${model.action} for sw version ${model.targetSwVersion} on pnf: ${model.deviceId}"
+ )
try {
val mountPayload = contentFromResolvedArtifactNB("mount-node")
@@ -62,7 +63,6 @@ class RestconfSoftwareUpgrade : AbstractScriptComponentFunction() {
Action.POST_CHECK -> processPostCheck(model)
Action.CANCEL -> processCancel(model)
}
-
} catch (err: Exception) {
log.error("an error occurred while configuring device {}", err)
} finally {
@@ -72,62 +72,72 @@ class RestconfSoftwareUpgrade : AbstractScriptComponentFunction() {
private fun validatedPayload(executionRequest: ExecutionServiceInput): SoftwareUpgradeModel {
val properties = requestPayloadActionProperty(executionRequest.actionIdentifiers.actionName + "-properties")!!.get(0)
- if(!properties?.get("pnf-id")?.textValue().isNullOrEmpty() &&
- !properties?.get("target-software-version")?.textValue().isNullOrEmpty()) {
- return SoftwareUpgradeModel(getDynamicProperties("resolution-key").asText(),
+ if (!properties?.get("pnf-id")?.textValue().isNullOrEmpty() &&
+ !properties?.get("target-software-version")?.textValue().isNullOrEmpty()
+ ) {
+ return SoftwareUpgradeModel(
+ getDynamicProperties("resolution-key").asText(),
BluePrintDependencyService.restClientService(RESTCONF_SERVER_IDENTIFIER),
properties.get("pnf-id").textValue(), properties.get("target-software-version").textValue(),
- Action.getEnumFromActionName(executionRequest.actionIdentifiers.actionName))
- }else{
+ Action.getEnumFromActionName(executionRequest.actionIdentifiers.actionName)
+ )
+ } else {
throw BluePrintException("Invalid parameters sent to CDS. Request parameters pnf-id or target-software-version missing")
}
}
private suspend fun processPreCheck(model: SoftwareUpgradeModel) {
log.debug("In PNF SW upgrade : processPreCheck")
- //Log the current configuration for the subtree
+ // Log the current configuration for the subtree
val payloadObject = getCurrentConfig(model)
- log.debug("Current sw version on pnf : ${payloadObject.get("software-upgrade")?.get("upgrade-package")?.get(0)?.get("software-version")?.asText()}")
+ log.debug(
+ "Current sw version on pnf : ${
+ payloadObject.get("software-upgrade")?.get("upgrade-package")?.get(0)?.get("software-version")?.asText()
+ }"
+ )
log.info("PNF is Healthy!")
}
private suspend fun processDownloadNESw(model: SoftwareUpgradeModel) {
log.debug("In PNF SW upgrade : processDownloadNESw")
- //Check if there is existing config for the targeted software version
+ // Check if there is existing config for the targeted software version
var downloadConfigPayload: String
if (checkIfSwReadyToPerformAction(Action.PRE_CHECK, model)) {
downloadConfigPayload = contentFromResolvedArtifactNB("configure")
- downloadConfigPayload =downloadConfigPayload.replace("%id%", model.yangId)
- }
- else {
+ downloadConfigPayload = downloadConfigPayload.replace("%id%", model.yangId)
+ } else {
downloadConfigPayload = contentFromResolvedArtifactNB("download-ne-sw")
- model.yangId=model.targetSwVersion
+ model.yangId = model.targetSwVersion
}
downloadConfigPayload = downloadConfigPayload.replace("%actionName%", Action.DOWNLOAD_NE_SW.name)
log.info("Config Payload to start download : $downloadConfigPayload")
- //Apply configlet
- restconfApplyDeviceConfig(model.client, model.deviceId, CONFIGLET_RESOURCE_PATH, downloadConfigPayload,
- mutableMapOf("Content-Type" to "application/yang.patch+json"))
+ // Apply configlet
+ restconfApplyDeviceConfig(
+ model.client, model.deviceId, CONFIGLET_RESOURCE_PATH, downloadConfigPayload,
+ mutableMapOf("Content-Type" to "application/yang.patch+json")
+ )
- //Poll PNF for Download action's progress
+ // Poll PNF for Download action's progress
checkExecution(model)
}
private suspend fun processActivateNESw(model: SoftwareUpgradeModel) {
log.debug("In PNF SW upgrade : processActivateNESw")
- //Check if the software is downloaded and ready to be activated
+ // Check if the software is downloaded and ready to be activated
if (checkIfSwReadyToPerformAction(Action.DOWNLOAD_NE_SW, model)) {
var activateConfigPayload: String = contentFromResolvedArtifactNB("configure")
activateConfigPayload = activateConfigPayload.replace("%actionName%", Action.ACTIVATE_NE_SW.name)
activateConfigPayload = activateConfigPayload.replace("%id%", model.yangId)
log.info("Config Payload to start activate : $activateConfigPayload")
- //Apply configlet
- restconfApplyDeviceConfig(model.client, model.deviceId, CONFIGLET_RESOURCE_PATH, activateConfigPayload,
- mutableMapOf("Content-Type" to "application/yang.patch+json"))
+ // Apply configlet
+ restconfApplyDeviceConfig(
+ model.client, model.deviceId, CONFIGLET_RESOURCE_PATH, activateConfigPayload,
+ mutableMapOf("Content-Type" to "application/yang.patch+json")
+ )
- //Poll PNF for Activate action's progress
+ // Poll PNF for Activate action's progress
checkExecution(model)
} else {
throw BluePrintRetryException("Software Download not completed for device(${model.deviceId}) to activate sw version: ${model.targetSwVersion}")
@@ -136,21 +146,23 @@ class RestconfSoftwareUpgrade : AbstractScriptComponentFunction() {
private suspend fun processPostCheck(model: SoftwareUpgradeModel) {
log.info("In PNF SW upgrade : processPostCheck")
- //Log the current configuration for the subtree
+ // Log the current configuration for the subtree
if (checkIfSwReadyToPerformAction(Action.POST_CHECK, model)) {
log.info("PNF is healthy post activation!")
}
}
- private fun processCancel(model :SoftwareUpgradeModel) {
- //This is for future implementation of cancel step during software upgrade
+ private fun processCancel(model: SoftwareUpgradeModel) {
+ // This is for future implementation of cancel step during software upgrade
log.info("In PNF SW upgrade : processCancel")
}
- private suspend fun getCurrentConfig(model: SoftwareUpgradeModel) : ObjectNode{
- val currentConfig: BlueprintWebClientService.WebClientResponse<String> = restconfDeviceConfig(model.client, model.deviceId, CONFIGLET_RESOURCE_PATH)
+ private suspend fun getCurrentConfig(model: SoftwareUpgradeModel): ObjectNode {
+ val currentConfig: BlueprintWebClientService.WebClientResponse<String> =
+ restconfDeviceConfig(model.client, model.deviceId, CONFIGLET_RESOURCE_PATH)
return JacksonUtils.jsonNode(currentConfig.body) as ObjectNode
}
+
private suspend fun checkExecution(model: SoftwareUpgradeModel) {
val checkExecutionBlock: suspend (Int) -> String = {
val result = restconfDeviceConfig(model.client, model.deviceId, TARGET_SOFTWARE_PATH.plus(model.yangId))
@@ -162,15 +174,15 @@ class RestconfSoftwareUpgrade : AbstractScriptComponentFunction() {
}
}
model.client.retry<String>(10, 0, 1000, checkExecutionBlock)
-
}
- private suspend fun checkIfSwReadyToPerformAction(action : Action, model: SoftwareUpgradeModel): Boolean {
+ private suspend fun checkIfSwReadyToPerformAction(action: Action, model: SoftwareUpgradeModel): Boolean {
val configBody = getCurrentConfig(model)
configBody.get("software-upgrade")?.get("upgrade-package")?.iterator()?.forEach { item ->
if (model.targetSwVersion == item.get("software-version")?.asText() &&
- action.completionStatus == item?.get("current-status")?.asText()) {
- model.yangId= item.get("id").textValue()
+ action.completionStatus == item?.get("current-status")?.asText()
+ ) {
+ model.yangId = item.get("id").textValue()
return true
}
}
@@ -191,15 +203,23 @@ enum class Action(val actionName: String, val completionStatus: String) {
POST_CHECK("postCheck", "ACTIVATION_COMPLETED"),
CANCEL("cancel", "CANCELLED")
;
- companion object{
+
+ companion object {
+
fun getEnumFromActionName(name: String): Action {
- for(value in values()){
- if (value.actionName==name) return value
+ for (value in values()) {
+ if (value.actionName == name) return value
}
throw BluePrintException("Invalid Action sent to CDS")
}
}
}
-data class SoftwareUpgradeModel(val resolutionKey: String, val client: BlueprintWebClientService, val deviceId: String,
- val targetSwVersion: String, val action: Action, var yangId: String = "") \ No newline at end of file
+data class SoftwareUpgradeModel(
+ val resolutionKey: String,
+ val client: BlueprintWebClientService,
+ val deviceId: String,
+ val targetSwVersion: String,
+ val action: Action,
+ var yangId: String = ""
+)