Fixed K8s HealthCheck API issue 61/119861/1
authorLukasz Rajewski <lukasz.rajewski@orange.com>
Thu, 25 Mar 2021 16:47:47 +0000 (17:47 +0100)
committerLukasz Rajewski <lukasz.rajewski@orange.com>
Thu, 25 Mar 2021 16:48:50 +0000 (17:48 +0100)
Fixed K8s HealthCheck API issue

Issue-ID: CCSDK-3230
Signed-off-by: Lukasz Rajewski <lukasz.rajewski@orange.com>
Change-Id: Ic341cc7ef36d5fe86cf2b74813bb1f8fc0842f6f

ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/instance/K8sPluginInstanceApi.kt
ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/instance/healthcheck/K8sRbInstanceHealthCheck.kt

index 7834c05..3305481 100644 (file)
@@ -23,6 +23,8 @@ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
 import com.fasterxml.jackson.module.kotlin.readValue
 import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.K8sConnectionPluginConfiguration
 import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.instance.healthcheck.K8sRbInstanceHealthCheck
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.instance.healthcheck.K8sRbInstanceHealthCheckList
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.instance.healthcheck.K8sRbInstanceHealthCheckSimple
 import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService
 import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
@@ -160,7 +162,7 @@ class K8sPluginInstanceApi(
         }
     }
 
-    fun getInstanceHealthCheckList(instanceId: String): List<K8sRbInstanceHealthCheck>? {
+    fun getInstanceHealthCheckList(instanceId: String): K8sRbInstanceHealthCheckList? {
         val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
         try {
             val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
@@ -170,8 +172,10 @@ class K8sPluginInstanceApi(
             )
             log.debug(result.toString())
             return if (result.status in 200..299) {
-                val objectMapper = jacksonObjectMapper()
-                val parsedObject: ArrayList<K8sRbInstanceHealthCheck>? = objectMapper.readValue(result.body)
+                val parsedObject: K8sRbInstanceHealthCheckList? = JacksonUtils.readValue(
+                    result.body,
+                    K8sRbInstanceHealthCheckList::class.java
+                )
                 parsedObject
             } else if (result.status == 500 && result.body.contains("Error finding master table"))
                 null
@@ -208,7 +212,7 @@ class K8sPluginInstanceApi(
         }
     }
 
-    fun startInstanceHealthCheck(instanceId: String): K8sRbInstanceHealthCheck? {
+    fun startInstanceHealthCheck(instanceId: String): K8sRbInstanceHealthCheckSimple? {
         val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
         try {
             val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
@@ -218,9 +222,9 @@ class K8sPluginInstanceApi(
             )
             log.debug(result.toString())
             return if (result.status in 200..299) {
-                val parsedObject: K8sRbInstanceHealthCheck? = JacksonUtils.readValue(
+                val parsedObject: K8sRbInstanceHealthCheckSimple? = JacksonUtils.readValue(
                     result.body,
-                    K8sRbInstanceHealthCheck::class.java
+                    K8sRbInstanceHealthCheckSimple::class.java
                 )
                 parsedObject
             } else if (result.status == 500 && result.body.contains("Error finding master table"))
index b8e7e83..0f1f605 100644 (file)
@@ -2,22 +2,67 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.instance.healthchec
 
 import com.fasterxml.jackson.annotation.JsonProperty
 
+class K8sRbInstanceHealthCheckSimple {
+
+    @get:JsonProperty("healthcheck-id")
+    var id: String? = null
+
+    @get:JsonProperty("status")
+    var status: String? = null
+
+    override fun toString(): String {
+        return "$id:$status"
+    }
+
+    override fun equals(other: Any?): Boolean {
+        if (this === other) return true
+        if (javaClass != other?.javaClass) return false
+        return true
+    }
+
+    override fun hashCode(): Int {
+        return javaClass.hashCode()
+    }
+}
+
+class K8sRbInstanceHealthCheckList {
+
+    @get:JsonProperty("instance-id")
+    var instanceId: String? = null
+
+    @get:JsonProperty("healthcheck-summary")
+    var healthcheckSummary: List<K8sRbInstanceHealthCheckSimple>? = null
+
+    @get:JsonProperty("hooks")
+    var hooks: List<K8sRbInstanceHealthCheckHook>? = null
+
+    override fun equals(other: Any?): Boolean {
+        if (this === other) return true
+        if (javaClass != other?.javaClass) return false
+        return true
+    }
+
+    override fun hashCode(): Int {
+        return javaClass.hashCode()
+    }
+}
+
 class K8sRbInstanceHealthCheck {
 
-    @get:JsonProperty("Id")
+    @get:JsonProperty("healthcheck-id")
     var id: String? = null
 
-    @get:JsonProperty("StartedAt")
-    var startedAt: String? = null
+    @get:JsonProperty("instance-id")
+    var instanceId: String? = null
 
-    @get:JsonProperty("CompletedAt")
-    var completedAt: String? = null
+    @get:JsonProperty("info")
+    var info: String? = null
 
-    @get:JsonProperty("Status")
+    @get:JsonProperty("status")
     var status: String? = null
 
-    @get:JsonProperty("Tests")
-    var tests: List<K8sHealthCheckTest>? = null
+    @get:JsonProperty("test-suite")
+    var testSuite: K8sHealthCheckTest? = null
 
     override fun toString(): String {
         return "$id:$status"
@@ -36,9 +81,6 @@ class K8sRbInstanceHealthCheck {
 
 class K8sHealthCheckTest {
 
-    @get:JsonProperty("Name")
-    var name: String? = null
-
     @get:JsonProperty("StartedAt")
     var startedAt: String? = null
 
@@ -48,12 +90,39 @@ class K8sHealthCheckTest {
     @get:JsonProperty("Status")
     var status: String? = null
 
-    @get:JsonProperty("Info")
-    var info: String? = null
+    @get:JsonProperty("TestManifests")
+    var testManifests: List<String>? = null
 
-    override fun toString(): String {
-        return "$name:$status"
+    @get:JsonProperty("Results")
+    var results: List<Any>? = null
+
+    override fun equals(other: Any?): Boolean {
+        if (this === other) return true
+        if (javaClass != other?.javaClass) return false
+        return true
+    }
+
+    override fun hashCode(): Int {
+        return javaClass.hashCode()
     }
+}
+
+class K8sRbInstanceHealthCheckHook {
+
+    @get:JsonProperty("name")
+    var name: String? = null
+
+    @get:JsonProperty("kind")
+    var kind: String? = null
+
+    @get:JsonProperty("path")
+    var path: String? = null
+
+    @get:JsonProperty("manifest")
+    var manifest: String? = null
+
+    @get:JsonProperty("events")
+    var events: List<Any>? = null
 
     override fun equals(other: Any?): Boolean {
         if (this === other) return true