aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukasz Rajewski <lukasz.rajewski@orange.com>2021-02-17 20:33:21 +0100
committerLukasz Rajewski <lukasz.rajewski@orange.com>2021-02-17 20:34:07 +0100
commit29455ba616f0958f102fec008d4f8e46d7c14bbb (patch)
tree2a6cc7f57500081f0738b910bfc6a1905ad3cd8e
parentb85d065c68fe2893e03a391768b91a630dce5988 (diff)
K8sPlugin Healthcheck API and API refactoring
K8sPlugin Healthcheck API and API refactoring Issue-ID: CCSDK-3146 Signed-off-by: Lukasz Rajewski <lukasz.rajewski@orange.com> Change-Id: Ic3040c888bf78b6d3c91f282200e6f32a3f69816
-rw-r--r--ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/definition/K8sPluginDefinitionApi.kt (renamed from ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/K8sPluginApi.kt)9
-rw-r--r--ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/definition/profile/K8sProfileUploadComponent.kt4
-rw-r--r--ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/definition/template/K8sConfigTemplateComponent.kt4
-rw-r--r--ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/instance/K8sPluginInstanceApi.kt116
-rw-r--r--ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/instance/healthcheck/K8sRbInstanceHealthCheck.kt67
5 files changed, 171 insertions, 29 deletions
diff --git a/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/K8sPluginApi.kt b/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/definition/K8sPluginDefinitionApi.kt
index a36c8e31c..05c3021d9 100644
--- a/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/K8sPluginApi.kt
+++ b/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/definition/K8sPluginDefinitionApi.kt
@@ -17,13 +17,12 @@
* limitations under the License.
*/
-package org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s
+package org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.definition
import com.fasterxml.jackson.databind.ObjectMapper
-import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.definition.K8sDefinitionRestClient
-import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.definition.K8sUploadFileRestClientService
import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.definition.profile.K8sProfile
import com.fasterxml.jackson.module.kotlin.readValue
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.K8sConnectionPluginConfiguration
import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.definition.template.K8sTemplate
import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService
import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException
@@ -33,10 +32,10 @@ import org.springframework.http.HttpMethod.GET
import org.springframework.http.HttpMethod.POST
import java.nio.file.Path
-class K8sPluginApi(
+class K8sPluginDefinitionApi(
private val k8sConfiguration: K8sConnectionPluginConfiguration
) {
- private val log = LoggerFactory.getLogger(K8sPluginApi::class.java)!!
+ private val log = LoggerFactory.getLogger(K8sPluginDefinitionApi::class.java)!!
private val objectMapper = ObjectMapper()
fun hasDefinition(definition: String, definitionVersion: String): Boolean {
diff --git a/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/definition/profile/K8sProfileUploadComponent.kt b/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/definition/profile/K8sProfileUploadComponent.kt
index 47fe6d957..db549f334 100644
--- a/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/definition/profile/K8sProfileUploadComponent.kt
+++ b/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/definition/profile/K8sProfileUploadComponent.kt
@@ -26,7 +26,7 @@ import org.apache.commons.io.FileUtils
import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertiesService
import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.K8sConnectionPluginConfiguration
-import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.K8sPluginApi
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.definition.K8sPluginDefinitionApi
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionService
@@ -125,7 +125,7 @@ open class K8sProfileUploadComponent(
val k8sProfileUploadConfiguration = K8sConnectionPluginConfiguration(bluePrintPropertiesService)
// Creating API connector
- var api = K8sPluginApi(k8sProfileUploadConfiguration)
+ var api = K8sPluginDefinitionApi(k8sProfileUploadConfiguration)
if ((profileName == null) || (definitionName == null) || (definitionVersion == null)) {
log.warn("Prefix $prefix does not have required data for us to continue.")
diff --git a/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/definition/template/K8sConfigTemplateComponent.kt b/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/definition/template/K8sConfigTemplateComponent.kt
index 1156e1bfd..4e20dcb03 100644
--- a/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/definition/template/K8sConfigTemplateComponent.kt
+++ b/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/definition/template/K8sConfigTemplateComponent.kt
@@ -26,7 +26,7 @@ import org.apache.commons.io.FileUtils
import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertiesService
import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.K8sConnectionPluginConfiguration
-import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.K8sPluginApi
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.definition.K8sPluginDefinitionApi
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionService
import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction
@@ -122,7 +122,7 @@ open class K8sConfigTemplateComponent(
val k8sConnectionPluginConfiguration = K8sConnectionPluginConfiguration(bluePrintPropertiesService)
// Creating API connector
- val api = K8sPluginApi(k8sConnectionPluginConfiguration)
+ val api = K8sPluginDefinitionApi(k8sConnectionPluginConfiguration)
if ((templateName == null) || (definitionName == null) || (definitionVersion == null)) {
log.warn("Prefix $prefix does not have required data for us to continue.")
} else if (!api.hasDefinition(definitionName, definitionVersion)) {
diff --git a/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/instance/K8sPluginInstanceApi.kt b/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/instance/K8sPluginInstanceApi.kt
index 3faaac00d..120c38044 100644
--- a/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/instance/K8sPluginInstanceApi.kt
+++ b/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/instance/K8sPluginInstanceApi.kt
@@ -19,20 +19,24 @@
package org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.instance
-import com.fasterxml.jackson.databind.JsonNode
+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.rest.service.BlueprintWebClientService
import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
import org.slf4j.LoggerFactory
+import org.springframework.http.HttpMethod.DELETE
import org.springframework.http.HttpMethod.GET
+import org.springframework.http.HttpMethod.POST
class K8sPluginInstanceApi(
private val k8sConfiguration: K8sConnectionPluginConfiguration
) {
private val log = LoggerFactory.getLogger(K8sPluginInstanceApi::class.java)!!
- fun getAllInstances(): List<K8sRbInstance>? {
+ fun getInstanceList(): List<K8sRbInstance>? {
val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
@@ -42,7 +46,8 @@ class K8sPluginInstanceApi(
)
log.debug(result.toString())
return if (result.status in 200..299) {
- val parsedObject: List<K8sRbInstance> = JacksonUtils.readValue(result.body)
+ val objectMapper = jacksonObjectMapper()
+ val parsedObject: ArrayList<K8sRbInstance>? = objectMapper.readValue(result.body)
parsedObject
} else if (result.status == 500 && result.body.contains("Did not find any objects with tag"))
null
@@ -64,7 +69,6 @@ class K8sPluginInstanceApi(
)
log.debug(result.toString())
return if (result.status in 200..299) {
- val instance: JsonNode = JacksonUtils.jsonNode(result.body)
val parsedObject: K8sRbInstance? = JacksonUtils.readValue(result.body, K8sRbInstance::class.java)
parsedObject
} else if (result.status == 500 && result.body.contains("Error finding master table"))
@@ -82,25 +86,31 @@ class K8sPluginInstanceApi(
rbDefinitionVersion: String,
rbProfileName: String
): K8sRbInstance? {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration)
+ val instances: List<K8sRbInstance>? = this.getInstanceList()
+ instances?.forEach {
+ if (it.request?.rbName == rbDefinitionName && it.request?.rbVersion == rbDefinitionVersion &&
+ it.request?.profileName == rbProfileName
+ )
+ return it
+ }
+ return null
+ }
+
+ fun getInstanceStatus(instanceId: String): K8sRbInstanceStatus? {
+ val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
GET.name,
- "",
+ "/status",
""
)
log.debug(result.toString())
return if (result.status in 200..299) {
- val parsedObject: List<K8sRbInstance> = JacksonUtils.readValue(result.body)
- var instance: K8sRbInstance? = null
- parsedObject.forEach {
- if (it.request?.rbName == rbDefinitionName && it.request?.rbVersion == rbDefinitionVersion &&
- it.request?.profileName == rbProfileName
- )
- instance = it
- }
- instance
- } else if (result.status == 500 && result.body.contains("Did not find any objects with tag"))
+ val parsedObject: K8sRbInstanceStatus? = JacksonUtils.readValue(
+ result.body, K8sRbInstanceStatus::class.java
+ )
+ parsedObject
+ } else if (result.status == 500 && result.body.contains("Error finding master table"))
null
else
throw BlueprintProcessorException(result.body)
@@ -110,18 +120,42 @@ class K8sPluginInstanceApi(
}
}
- fun getInstanceStatus(instanceId: String): K8sRbInstanceStatus? {
+ fun getInstanceHealthCheckList(instanceId: String): List<K8sRbInstanceHealthCheck>? {
val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
GET.name,
- "/status",
+ "/healthcheck",
""
)
log.debug(result.toString())
return if (result.status in 200..299) {
- val parsedObject: K8sRbInstanceStatus? = JacksonUtils.readValue(
- result.body, K8sRbInstanceStatus::class.java
+ val objectMapper = jacksonObjectMapper()
+ val parsedObject: ArrayList<K8sRbInstanceHealthCheck>? = objectMapper.readValue(result.body)
+ parsedObject
+ } else if (result.status == 500 && result.body.contains("Error finding master table"))
+ null
+ else
+ throw BlueprintProcessorException(result.body)
+ } catch (e: Exception) {
+ log.error("Caught exception trying to get k8s rb instance")
+ throw BlueprintProcessorException("${e.message}")
+ }
+ }
+
+ fun getInstanceHealthCheck(instanceId: String, healthCheckId: String): K8sRbInstanceHealthCheck? {
+ val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ try {
+ val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
+ GET.name,
+ "/healthcheck/$healthCheckId",
+ ""
+ )
+ log.debug(result.toString())
+ return if (result.status in 200..299) {
+ val parsedObject: K8sRbInstanceHealthCheck? = JacksonUtils.readValue(
+ result.body,
+ K8sRbInstanceHealthCheck::class.java
)
parsedObject
} else if (result.status == 500 && result.body.contains("Error finding master table"))
@@ -133,4 +167,46 @@ class K8sPluginInstanceApi(
throw BlueprintProcessorException("${e.message}")
}
}
+
+ fun startInstanceHealthCheck(instanceId: String): K8sRbInstanceHealthCheck? {
+ val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ try {
+ val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
+ POST.name,
+ "/healthcheck",
+ ""
+ )
+ log.debug(result.toString())
+ return if (result.status in 200..299) {
+ val parsedObject: K8sRbInstanceHealthCheck? = JacksonUtils.readValue(
+ result.body,
+ K8sRbInstanceHealthCheck::class.java
+ )
+ parsedObject
+ } else if (result.status == 500 && result.body.contains("Error finding master table"))
+ null
+ else
+ throw BlueprintProcessorException(result.body)
+ } catch (e: Exception) {
+ log.error("Caught exception trying to get k8s rb instance")
+ throw BlueprintProcessorException("${e.message}")
+ }
+ }
+
+ fun deleteInstanceHealthCheck(instanceId: String, healthCheckId: String) {
+ val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ try {
+ val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
+ DELETE.name,
+ "/healthcheck/$healthCheckId",
+ ""
+ )
+ log.debug(result.toString())
+ if (result.status !in 200..299)
+ throw BlueprintProcessorException(result.body)
+ } catch (e: Exception) {
+ log.error("Caught exception trying to get k8s rb instance")
+ throw BlueprintProcessorException("${e.message}")
+ }
+ }
}
diff --git a/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/instance/healthcheck/K8sRbInstanceHealthCheck.kt b/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/instance/healthcheck/K8sRbInstanceHealthCheck.kt
new file mode 100644
index 000000000..b8e7e835e
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/instance/healthcheck/K8sRbInstanceHealthCheck.kt
@@ -0,0 +1,67 @@
+package org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.instance.healthcheck
+
+import com.fasterxml.jackson.annotation.JsonProperty
+
+class K8sRbInstanceHealthCheck {
+
+ @get:JsonProperty("Id")
+ var id: String? = null
+
+ @get:JsonProperty("StartedAt")
+ var startedAt: String? = null
+
+ @get:JsonProperty("CompletedAt")
+ var completedAt: String? = null
+
+ @get:JsonProperty("Status")
+ var status: String? = null
+
+ @get:JsonProperty("Tests")
+ var tests: List<K8sHealthCheckTest>? = 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 K8sHealthCheckTest {
+
+ @get:JsonProperty("Name")
+ var name: String? = null
+
+ @get:JsonProperty("StartedAt")
+ var startedAt: String? = null
+
+ @get:JsonProperty("CompletedAt")
+ var completedAt: String? = null
+
+ @get:JsonProperty("Status")
+ var status: String? = null
+
+ @get:JsonProperty("Info")
+ var info: String? = null
+
+ override fun toString(): String {
+ return "$name:$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()
+ }
+}