Bug fixes for config template and config value components
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / k8s-connection-plugin / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / functions / k8s / instance / K8sPluginInstanceApi.kt
index 7663699..7834c05 100644 (file)
@@ -121,14 +121,24 @@ class K8sPluginInstanceApi(
         }
     }
 
-    fun queryInstanceStatus(instanceId: String, kind: String, apiVersion: String, name: String?, labels: String?): K8sRbInstanceStatus? {
+    fun queryInstanceStatus(
+        instanceId: String,
+        kind: String,
+        apiVersion: String,
+        name: String? = null,
+        labels: Map<String, String>? = null
+    ): K8sRbInstanceStatus? {
         val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
         try {
             var path: String = "/query?ApiVersion=$apiVersion&Kind=$kind"
             if (name != null)
                 path = path.plus("&Name=$name")
-            if (labels != null)
-                path = path.plus("&Labels=$labels")
+            if (labels != null && labels.isNotEmpty()) {
+                path = path.plus("&Labels=")
+                for ((name, value) in labels)
+                    path = path.plus("$name%3D$value,")
+                path = path.trimEnd(',')
+            }
             val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
                 GET.name,
                 path,
@@ -240,7 +250,7 @@ class K8sPluginInstanceApi(
             } else
                 throw BlueprintProcessorException(result.body)
         } catch (e: Exception) {
-            log.error("Caught exception trying to get k8s rb instance")
+            log.error("Caught exception trying to create config instance")
             throw BlueprintProcessorException("${e.message}")
         }
     }
@@ -262,7 +272,7 @@ class K8sPluginInstanceApi(
             } else
                 throw BlueprintProcessorException(result.body)
         } catch (e: Exception) {
-            log.error("Caught exception trying to get k8s rb instance")
+            log.error("Caught exception trying to edit config instance")
             throw BlueprintProcessorException("${e.message}")
         }
     }
@@ -283,6 +293,45 @@ class K8sPluginInstanceApi(
         }
     }
 
+    fun getConfigurationValues(instanceId: String, configName: String): K8sConfigValueResponse? {
+        val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+        try {
+            val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
+                GET.name,
+                "/config/$configName",
+                ""
+            )
+            log.debug(result.toString())
+            return if (result.status in 200..299) {
+                val parsedObject: K8sConfigValueResponse? = JacksonUtils.readValue(
+                    result.body, K8sConfigValueResponse::class.java
+                )
+                parsedObject
+            } else
+                throw BlueprintProcessorException(result.body)
+        } catch (e: Exception) {
+            log.error("Caught exception trying to get config instance")
+            throw BlueprintProcessorException("${e.message}")
+        }
+    }
+
+    fun deleteConfigurationValues(instanceId: String, configName: String) {
+        val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+        try {
+            val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
+                DELETE.name,
+                "/config/$configName",
+                ""
+            )
+            log.debug(result.toString())
+            if (result.status !in 200..299)
+                throw BlueprintProcessorException(result.body)
+        } catch (e: Exception) {
+            log.error("Caught exception trying to delete config instance")
+            throw BlueprintProcessorException("${e.message}")
+        }
+    }
+
     fun rollbackConfigurationValues(instanceId: String): K8sConfigValueResponse? {
         val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
         try {
@@ -305,7 +354,7 @@ class K8sPluginInstanceApi(
         }
     }
 
-    fun createConfigurationValues(instanceId: String): K8sConfigValueResponse? {
+    fun tagConfigurationValues(instanceId: String): K8sConfigValueResponse? {
         val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
         try {
             val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(