diff options
author | gummar <raj.gumma@est.tech> | 2020-03-04 14:35:07 +0000 |
---|---|---|
committer | gummar <raj.gumma@est.tech> | 2020-03-04 16:12:19 +0000 |
commit | f4ac359d80d043a2d0e6eaf1730813b81f2c837f (patch) | |
tree | 14710c41d82417c2005840d173f5a0f980026755 /components/model-catalog/blueprint-model/uat-blueprints/PNF_CDS_RESTCONF/Scripts | |
parent | 7a8bfb25a92a9400862d70e690313a4e743124da (diff) |
Fix case for all Software upgrade actions
Issue-ID: CCSDK-2145
Signed-off-by: gummar <raj.gumma@est.tech>
Change-Id: Ic29056d100ffba9d6d1c2a6b3f73d6a95f3bee28
Diffstat (limited to 'components/model-catalog/blueprint-model/uat-blueprints/PNF_CDS_RESTCONF/Scripts')
-rw-r--r-- | components/model-catalog/blueprint-model/uat-blueprints/PNF_CDS_RESTCONF/Scripts/kotlin/RestconfSoftwareUpgrade.kt | 36 |
1 files changed, 23 insertions, 13 deletions
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 9d00c60d8..0540efe80 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 @@ -45,11 +45,7 @@ class RestconfSoftwareUpgrade : AbstractScriptComponentFunction() { override suspend fun processNB(executionRequest: ExecutionServiceInput) { // Extract request properties - val properties = requestPayloadActionProperty(executionRequest.actionIdentifiers.actionName + "-properties")!!.get(0) - val model= 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)) + 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}") @@ -61,8 +57,8 @@ class RestconfSoftwareUpgrade : AbstractScriptComponentFunction() { when (model.action) { Action.PRE_CHECK -> processPreCheck(model) - Action.DOWNLOAD_NE_SW -> processDownloadNESW(model) - Action.ACTIVATE_NE_SW -> processActivateNESW(model) + Action.DOWNLOAD_NE_SW -> processDownloadNESw(model) + Action.ACTIVATE_NE_SW -> processActivateNESw(model) Action.POST_CHECK -> processPostCheck(model) Action.CANCEL -> processCancel(model) } @@ -74,6 +70,19 @@ 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(), + BluePrintDependencyService.restClientService(RESTCONF_SERVER_IDENTIFIER), + properties.get("pnf-id").textValue(), properties.get("target-software-version").textValue(), + 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 @@ -82,8 +91,8 @@ class RestconfSoftwareUpgrade : AbstractScriptComponentFunction() { log.info("PNF is Healthy!") } - private suspend fun processDownloadNESW(model: SoftwareUpgradeModel) { - log.debug("In PNF SW upgrade : processDownloadNESW") + private suspend fun processDownloadNESw(model: SoftwareUpgradeModel) { + log.debug("In PNF SW upgrade : processDownloadNESw") //Check if there is existing config for the targeted software version var downloadConfigPayload: String @@ -106,12 +115,13 @@ class RestconfSoftwareUpgrade : AbstractScriptComponentFunction() { checkExecution(model) } - private suspend fun processActivateNESW(model: SoftwareUpgradeModel) { - log.debug("In PNF SW upgrade : processActivateNESW") + private suspend fun processActivateNESw(model: SoftwareUpgradeModel) { + log.debug("In PNF SW upgrade : processActivateNESw") //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, @@ -176,8 +186,8 @@ class RestconfSoftwareUpgrade : AbstractScriptComponentFunction() { enum class Action(val actionName: String, val completionStatus: String) { PRE_CHECK("preCheck", "INITIALIZED"), - DOWNLOAD_NE_SW("downloadNESW", "DOWNLOAD_COMPLETED"), - ACTIVATE_NE_SW("activateNESW", "ACTIVATION_COMPLETED"), + DOWNLOAD_NE_SW("downloadNESw", "DOWNLOAD_COMPLETED"), + ACTIVATE_NE_SW("activateNESw", "ACTIVATION_COMPLETED"), POST_CHECK("postCheck", "ACTIVATION_COMPLETED"), CANCEL("cancel", "CANCELLED") ; |