Update restconf executor to return response 46/101746/7
authordfarrelly <david.farrelly@est.tech>
Fri, 14 Feb 2020 14:46:06 +0000 (14:46 +0000)
committerKAPIL SINGAL <ks220y@att.com>
Thu, 20 Feb 2020 14:54:42 +0000 (14:54 +0000)
*Update restconfApplyDeviceConfig function to return request response
*Modify pnf_config_aai CBA to test new functionality

Issue-ID: CCSDK-2097
Change-Id: Id6109d8c3a8fa4e2ba1b102c4d2697ae6a03f8e2
Signed-off-by: dfarrelly <david.farrelly@est.tech>
components/model-catalog/blueprint-model/uat-blueprints/pnf_config_aai/Scripts/kotlin/RestconfConfigDeploy.kt
components/model-catalog/blueprint-model/uat-blueprints/pnf_config_aai/Tests/uat.yaml
ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restconf/executor/RestconfExecutorExtensions.kt

index 6a034ab..f0190e8 100644 (file)
@@ -31,11 +31,14 @@ import org.onap.ccsdk.cds.blueprintsprocessor.functions.restconf.executor.restco
 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
 import org.onap.ccsdk.cds.controllerblueprints.core.logger
+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"
+    private val mapper = ObjectMapper()
     private val log = logger(AbstractScriptComponentFunction::class.java)
 
     override suspend fun processNB(executionRequest: ExecutionServiceInput) {
@@ -58,9 +61,17 @@ class RestconfConfigDeploy : AbstractScriptComponentFunction() {
                 val currentConfig: Any = restconfDeviceConfig(webclientService, deviceID, CONFIGLET_RESOURCE_PATH)
                 log.info("Current configuration subtree : $currentConfig")
                 //Apply configlet
-                restconfApplyDeviceConfig(webclientService, deviceID, CONFIGLET_RESOURCE_PATH,
+                val result = restconfApplyDeviceConfig(webclientService, deviceID, CONFIGLET_RESOURCE_PATH,
                         storedContentFromResolvedArtifactNB(resolutionKey, CONFIGLET_TEMPLATE_NAME),
-                        mutableMapOf("Content-Type" to "application/yang.patch+json"))
+                        mutableMapOf("Content-Type" to "application/yang.patch+json")) as WebClientResponse<*>
+
+                val jsonResult = mapper.readTree((result.body).toString())
+
+                if(jsonResult.get("ietf-yang-patch:yang-patch-status").get("errors") != null) {
+                    log.error("There was an error configuring device")
+                }  else {
+                    log.info("Device has been configured succesfully")
+                }
 
             } catch (err: Exception) {
                 log.error("an error occurred while configuring device {}", err)
index 0692eea..13e10f3 100644 (file)
@@ -123,6 +123,13 @@ external-services:
                   operation: merge
                   target: /
                   value: { netconflist: { netconf: [ { netconf-id: "30", netconf-param: "3000" }]}}
+        response:
+          body:
+            ietf-yang-patch:yang-patch-status:
+              patch-id: patch-1
+              ok: [
+                null
+              ]
       - request:
           method: DELETE
           path: *configUri
index 906bef9..fc6d5a9 100644 (file)
@@ -69,6 +69,7 @@ suspend fun AbstractScriptComponentFunction.restconfMountDevice(
 
 /**
  * Generic Configure function
+ * @return The WebClientResponse from the request
  */
 suspend fun AbstractScriptComponentFunction.restconfApplyDeviceConfig(
     webClientService: BlueprintWebClientService,
@@ -76,14 +77,12 @@ suspend fun AbstractScriptComponentFunction.restconfApplyDeviceConfig(
     configletResourcePath: String,
     configletToApply: Any,
     additionalHeaders: Map<String, String> = mutableMapOf("Content-Type" to "application/yang.patch+xml")
-) {
-
+): BlueprintWebClientService.WebClientResponse<String> {
     log.debug("headers: $additionalHeaders")
     log.info("configuring device: $deviceId, Configlet: $configletToApply")
     val applyConfigUrl = "restconf/config/network-topology:network-topology/topology/topology-netconf/node/" +
             "$deviceId/$configletResourcePath"
-    val result: Any = webClientService.exchangeResource("PATCH", applyConfigUrl, configletToApply as String, additionalHeaders)
-    log.info("Configuration application result: $result")
+    return webClientService.exchangeResource("PATCH", applyConfigUrl, configletToApply as String, additionalHeaders)
 }
 
 suspend fun AbstractScriptComponentFunction.restconfDeviceConfig(