Fix case for all Software upgrade actions 27/103027/1
authorgummar <raj.gumma@est.tech>
Wed, 4 Mar 2020 14:35:07 +0000 (14:35 +0000)
committergummar <raj.gumma@est.tech>
Wed, 4 Mar 2020 16:12:19 +0000 (16:12 +0000)
Issue-ID: CCSDK-2145
Signed-off-by: gummar <raj.gumma@est.tech>
Change-Id: Ic29056d100ffba9d6d1c2a6b3f73d6a95f3bee28

components/model-catalog/blueprint-model/uat-blueprints/PNF_CDS_RESTCONF/Definitions/PNF_CDS_RESTCONF.json
components/model-catalog/blueprint-model/uat-blueprints/PNF_CDS_RESTCONF/Definitions/data_types.json
components/model-catalog/blueprint-model/uat-blueprints/PNF_CDS_RESTCONF/Scripts/kotlin/RestconfSoftwareUpgrade.kt
components/model-catalog/blueprint-model/uat-blueprints/PNF_CDS_RESTCONF/Tests/uat.yaml

index 747fd8c..d84fd81 100644 (file)
         "get_input" : "resolution-key"
       }
     },
-    "downloadNESW-properties" : {
+    "downloadNESw-properties" : {
       "resolution-key" : {
         "get_input" : "resolution-key"
       }
     },
-    "activateNESW-properties" : {
+    "activateNESw-properties" : {
       "resolution-key" : {
         "get_input" : "resolution-key"
       }
           }
         }
       },
-      "downloadNESW" : {
+      "downloadNESw" : {
         "steps" : {
           "activate-process" : {
             "description" : "Trigger download new software for sw upgrade",
-            "target" : "downloadNESW",
+            "target" : "downloadNESw",
             "activities" : [ {
               "call_operation" : ""
             } ]
             "required" : true,
             "type" : "string"
           },
-          "downloadNESW-properties" : {
-            "description" : "Dynamic PropertyDefinition for downloadNESW workflow(software-upgrade).",
+          "downloadNESw-properties" : {
+            "description" : "Dynamic PropertyDefinition for downloadNESw workflow(software-upgrade).",
             "required" : true,
-            "type" : "dt-downloadNESW-properties"
+            "type" : "dt-downloadNESw-properties"
           }
         }
       },
-      "activateNESW" : {
+      "activateNESw" : {
         "steps" : {
           "activate-process" : {
             "description" : "Trigger activation of target software version for pnf upgrade",
-            "target" : "activateNESW",
+            "target" : "activateNESw",
             "activities" : [ {
               "call_operation" : ""
             } ]
             "required" : true,
             "type" : "string"
           },
-          "activateNESW-properties" : {
-            "description" : "Dynamic PropertyDefinition for activateNESW workflow(software-upgrade).",
+          "activateNESw-properties" : {
+            "description" : "Dynamic PropertyDefinition for activateNESw workflow(software-upgrade).",
             "required" : true,
-            "type" : "dt-activateNESW-properties"
+            "type" : "dt-activateNESw-properties"
           }
         }
       },
           }
         }
       },
-      "downloadNESW" : {
+      "downloadNESw" : {
         "type" : "component-script-executor",
         "interfaces" : {
           "ComponentScriptExecutor" : {
                 "inputs" : {
                   "script-type" : "kotlin",
                   "script-class-reference" : "cba.pnf.swug.RestconfSoftwareUpgrade",
-                  "dynamic-properties" : "*downloadNESW-properties"
+                  "dynamic-properties" : "*downloadNESw-properties"
                 },
                 "outputs" : {
                   "response-data" : "",
           }
         }
       },
-      "activateNESW" : {
+      "activateNESw" : {
         "type" : "component-script-executor",
         "interfaces" : {
           "ComponentScriptExecutor" : {
                 "inputs" : {
                   "script-type" : "kotlin",
                   "script-class-reference" : "cba.pnf.swug.RestconfSoftwareUpgrade",
-                  "dynamic-properties" : "*activateNESW-properties"
+                  "dynamic-properties" : "*activateNESw-properties"
                 },
                 "outputs" : {
                   "response-data" : "",
index 2a42ac0..cd91f4b 100644 (file)
@@ -32,8 +32,8 @@
       },
       "derived_from": "tosca.datatypes.Dynamic"
     },
-    "dt-downloadNESW-properties": {
-      "description": "Dynamic DataType definition for the downloadNESW workflow(upgrade-software).",
+    "dt-downloadNESw-properties": {
+      "description": "Dynamic DataType definition for the downloadNESw workflow(upgrade-software).",
       "version": "1.0.0",
       "properties": {
         "pnf-id": {
@@ -45,8 +45,8 @@
       },
       "derived_from": "tosca.datatypes.Dynamic"
     },
-    "dt-activateNESW-properties": {
-      "description": "Dynamic DataType definition for the activateNESW workflow(upgrade-software).",
+    "dt-activateNESw-properties": {
+      "description": "Dynamic DataType definition for the activateNESw workflow(upgrade-software).",
       "version": "1.0.0",
       "properties": {
         "pnf-id": {
index 9d00c60..0540efe 100644 (file)
@@ -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")
     ;
index 7136b1b..c2fd3f7 100644 (file)
@@ -86,18 +86,18 @@ processes:
         message: success
       payload:
         preCheck-response: {}
-  - name: downloadNESW
+  - name: downloadNESw
     request:
       commonHeader: *swugCommonHeader
       actionIdentifiers: &download-ai
         blueprintName: PNF_CDS_RESTCONF
         blueprintVersion: "1.0.0"
-        actionName: downloadNESW
+        actionName: downloadNESw
         mode: sync
       payload:
-        downloadNESW-request:
+        downloadNESw-request:
           resolution-key: *resKey
-          downloadNESW-properties: *actionProps
+          downloadNESw-properties: *actionProps
     expectedResponse:
       commonHeader: *swugCommonHeader
       actionIdentifiers: *download-ai
@@ -107,19 +107,19 @@ processes:
         errorMessage: null
         message: success
       payload:
-        downloadNESW-response: {}
-  - name: activateNESW
+        downloadNESw-response: {}
+  - name: activateNESw
     request:
       commonHeader: *swugCommonHeader
       actionIdentifiers: &activate-ai
         blueprintName: PNF_CDS_RESTCONF
         blueprintVersion: "1.0.0"
-        actionName: activateNESW
+        actionName: activateNESw
         mode: sync
       payload:
-        activateNESW-request:
+        activateNESw-request:
           resolution-key: *resKey
-          activateNESW-properties: *actionProps
+          activateNESw-properties: *actionProps
     expectedResponse:
       commonHeader: *swugCommonHeader
       actionIdentifiers: *activate-ai
@@ -129,7 +129,7 @@ processes:
         errorMessage: null
         message: success
       payload:
-        activateNESW-response: {}
+        activateNESw-response: {}
   - name: postCheck
     request:
       commonHeader: *swugCommonHeader