From 29455ba616f0958f102fec008d4f8e46d7c14bbb Mon Sep 17 00:00:00 2001 From: Lukasz Rajewski Date: Wed, 17 Feb 2021 20:33:21 +0100 Subject: K8sPlugin Healthcheck API and API refactoring K8sPlugin Healthcheck API and API refactoring Issue-ID: CCSDK-3146 Signed-off-by: Lukasz Rajewski Change-Id: Ic3040c888bf78b6d3c91f282200e6f32a3f69816 --- .../functions/k8s/K8sPluginApi.kt | 203 --------------------- .../k8s/definition/K8sPluginDefinitionApi.kt | 202 ++++++++++++++++++++ .../profile/K8sProfileUploadComponent.kt | 4 +- .../template/K8sConfigTemplateComponent.kt | 4 +- .../functions/k8s/instance/K8sPluginInstanceApi.kt | 116 ++++++++++-- .../healthcheck/K8sRbInstanceHealthCheck.kt | 67 +++++++ 6 files changed, 369 insertions(+), 227 deletions(-) delete mode 100644 ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/K8sPluginApi.kt create mode 100644 ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/definition/K8sPluginDefinitionApi.kt create mode 100644 ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/instance/healthcheck/K8sRbInstanceHealthCheck.kt (limited to 'ms/blueprintsprocessor/functions/k8s-connection-plugin') 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/K8sPluginApi.kt deleted file mode 100644 index a36c8e31c..000000000 --- a/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/K8sPluginApi.kt +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2019 IBM. - * Modifications Copyright © 2020 Orange. - * Modifications Copyright © 2020 Deutsche Telekom AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s - -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.definition.template.K8sTemplate -import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService -import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException -import org.slf4j.LoggerFactory -import org.springframework.http.HttpMethod.DELETE -import org.springframework.http.HttpMethod.GET -import org.springframework.http.HttpMethod.POST -import java.nio.file.Path - -class K8sPluginApi( - private val k8sConfiguration: K8sConnectionPluginConfiguration -) { - private val log = LoggerFactory.getLogger(K8sPluginApi::class.java)!! - private val objectMapper = ObjectMapper() - - fun hasDefinition(definition: String, definitionVersion: String): Boolean { - val rbDefinitionService = K8sDefinitionRestClient( - k8sConfiguration, - definition, - definitionVersion - ) - try { - val result: BlueprintWebClientService.WebClientResponse = rbDefinitionService.exchangeResource( - GET.name, - "", - "" - ) - log.debug(result.toString()) - return result.status in 200..299 - } catch (e: Exception) { - log.error("Caught exception trying to get k8s rb definition") - throw BlueprintProcessorException("${e.message}") - } - } - - fun hasProfile(definition: String, definitionVersion: String, profileName: String): Boolean { - val rbDefinitionService = K8sDefinitionRestClient( - k8sConfiguration, - definition, - definitionVersion - ) - try { - val result: BlueprintWebClientService.WebClientResponse = rbDefinitionService.exchangeResource( - GET.name, - "/profile/$profileName", - "" - ) - log.debug(result.toString()) - return result.status in 200..299 - } catch (e: Exception) { - log.error("Caught exception trying to get k8s rb profile") - throw BlueprintProcessorException("${e.message}") - } - } - - fun createProfile(definition: String, definitionVersion: String, profile: K8sProfile) { - val rbDefinitionService = K8sDefinitionRestClient( - k8sConfiguration, - definition, - definitionVersion - ) - val profileJsonString: String = objectMapper.writeValueAsString(profile) - try { - val result: BlueprintWebClientService.WebClientResponse = rbDefinitionService.exchangeResource( - POST.name, - "/profile", - profileJsonString - ) - if (result.status !in 200..299) { - throw Exception(result.body) - } - } catch (e: Exception) { - log.error("Caught exception trying to create k8s rb profile ${profile.profileName}") - throw BlueprintProcessorException("${e.message}") - } - } - - fun uploadProfileContent(definition: String, definitionVersion: String, profile: K8sProfile, filePath: Path) { - val fileUploadService = K8sUploadFileRestClientService( - k8sConfiguration, - definition, - definitionVersion - ) - try { - val result: BlueprintWebClientService.WebClientResponse = fileUploadService.uploadBinaryFile( - "/profile/${profile.profileName}/content", - filePath - ) - if (result.status !in 200..299) { - throw Exception(result.body) - } - } catch (e: Exception) { - log.error("Caught exception trying to upload k8s rb profile ${profile.profileName}") - throw BlueprintProcessorException("${e.message}") - } - } - - fun createTemplate(definition: String, definitionVersion: String, template: K8sTemplate): Boolean { - val rbDefinitionService = K8sDefinitionRestClient(k8sConfiguration, definition, definitionVersion) - val templateJsonString: String = objectMapper.writeValueAsString(template) - try { - val result: BlueprintWebClientService.WebClientResponse = rbDefinitionService.exchangeResource( - POST.name, - "/config-template", - templateJsonString - ) - log.debug(result.toString()) - return result.status in 200..299 - } catch (e: Exception) { - log.error("Caught exception during create template") - throw BlueprintProcessorException("${e.message}") - } - } - - fun uploadTemplate(definition: String, definitionVersion: String, template: K8sTemplate, filePath: Path) { - val fileUploadService = K8sUploadFileRestClientService(k8sConfiguration, definition, definitionVersion) - try { - val result: BlueprintWebClientService.WebClientResponse = fileUploadService.uploadBinaryFile( - "/config-template/${template.templateName}/content", - filePath - ) - if (result.status !in 200..299) { - throw Exception(result.body) - } - } catch (e: Exception) { - log.error("Caught exception trying to upload k8s rb template ${template.templateName}") - throw BlueprintProcessorException("${e.message}") - } - } - - fun deleteTemplate(definition: String, definitionVersion: String, templateName: String) { - val rbDefinitionService = K8sDefinitionRestClient(k8sConfiguration, definition, definitionVersion) - try { - val result: BlueprintWebClientService.WebClientResponse = rbDefinitionService.exchangeResource( - DELETE.name, - "/config-template/$templateName", - "" - ) - log.debug(result.toString()) - } catch (e: Exception) { - log.error("Caught exception during get template") - throw BlueprintProcessorException("${e.message}") - } - } - - fun getTemplate(definition: String, definitionVersion: String, templateName: String): K8sTemplate { - val rbDefinitionService = K8sDefinitionRestClient(k8sConfiguration, definition, definitionVersion) - try { - val result: BlueprintWebClientService.WebClientResponse = getTemplateRequest(rbDefinitionService, templateName) - log.debug(result.toString()) - return objectMapper.readValue(result.body) - } catch (e: Exception) { - log.error("Caught exception during get template") - throw BlueprintProcessorException("${e.message}") - } - } - - fun hasTemplate(definition: String, definitionVersion: String, templateName: String): Boolean { - val rbDefinitionService = K8sDefinitionRestClient(k8sConfiguration, definition, definitionVersion) - try { - val result: BlueprintWebClientService.WebClientResponse = getTemplateRequest(rbDefinitionService, templateName) - log.debug(result.toString()) - return result.status in 200..299 - } catch (e: Exception) { - log.error("Caught exception during get template") - throw BlueprintProcessorException("${e.message}") - } - } - - private fun getTemplateRequest(rbDefinitionService: K8sDefinitionRestClient, templateName: String): BlueprintWebClientService.WebClientResponse { - return rbDefinitionService.exchangeResource( - GET.name, - "/config-template/$templateName", - "" - ) - } -} diff --git a/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/definition/K8sPluginDefinitionApi.kt b/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/definition/K8sPluginDefinitionApi.kt new file mode 100644 index 000000000..05c3021d9 --- /dev/null +++ b/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/definition/K8sPluginDefinitionApi.kt @@ -0,0 +1,202 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 IBM. + * Modifications Copyright © 2020 Orange. + * Modifications Copyright © 2020 Deutsche Telekom AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.definition + +import com.fasterxml.jackson.databind.ObjectMapper +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 +import org.slf4j.LoggerFactory +import org.springframework.http.HttpMethod.DELETE +import org.springframework.http.HttpMethod.GET +import org.springframework.http.HttpMethod.POST +import java.nio.file.Path + +class K8sPluginDefinitionApi( + private val k8sConfiguration: K8sConnectionPluginConfiguration +) { + private val log = LoggerFactory.getLogger(K8sPluginDefinitionApi::class.java)!! + private val objectMapper = ObjectMapper() + + fun hasDefinition(definition: String, definitionVersion: String): Boolean { + val rbDefinitionService = K8sDefinitionRestClient( + k8sConfiguration, + definition, + definitionVersion + ) + try { + val result: BlueprintWebClientService.WebClientResponse = rbDefinitionService.exchangeResource( + GET.name, + "", + "" + ) + log.debug(result.toString()) + return result.status in 200..299 + } catch (e: Exception) { + log.error("Caught exception trying to get k8s rb definition") + throw BlueprintProcessorException("${e.message}") + } + } + + fun hasProfile(definition: String, definitionVersion: String, profileName: String): Boolean { + val rbDefinitionService = K8sDefinitionRestClient( + k8sConfiguration, + definition, + definitionVersion + ) + try { + val result: BlueprintWebClientService.WebClientResponse = rbDefinitionService.exchangeResource( + GET.name, + "/profile/$profileName", + "" + ) + log.debug(result.toString()) + return result.status in 200..299 + } catch (e: Exception) { + log.error("Caught exception trying to get k8s rb profile") + throw BlueprintProcessorException("${e.message}") + } + } + + fun createProfile(definition: String, definitionVersion: String, profile: K8sProfile) { + val rbDefinitionService = K8sDefinitionRestClient( + k8sConfiguration, + definition, + definitionVersion + ) + val profileJsonString: String = objectMapper.writeValueAsString(profile) + try { + val result: BlueprintWebClientService.WebClientResponse = rbDefinitionService.exchangeResource( + POST.name, + "/profile", + profileJsonString + ) + if (result.status !in 200..299) { + throw Exception(result.body) + } + } catch (e: Exception) { + log.error("Caught exception trying to create k8s rb profile ${profile.profileName}") + throw BlueprintProcessorException("${e.message}") + } + } + + fun uploadProfileContent(definition: String, definitionVersion: String, profile: K8sProfile, filePath: Path) { + val fileUploadService = K8sUploadFileRestClientService( + k8sConfiguration, + definition, + definitionVersion + ) + try { + val result: BlueprintWebClientService.WebClientResponse = fileUploadService.uploadBinaryFile( + "/profile/${profile.profileName}/content", + filePath + ) + if (result.status !in 200..299) { + throw Exception(result.body) + } + } catch (e: Exception) { + log.error("Caught exception trying to upload k8s rb profile ${profile.profileName}") + throw BlueprintProcessorException("${e.message}") + } + } + + fun createTemplate(definition: String, definitionVersion: String, template: K8sTemplate): Boolean { + val rbDefinitionService = K8sDefinitionRestClient(k8sConfiguration, definition, definitionVersion) + val templateJsonString: String = objectMapper.writeValueAsString(template) + try { + val result: BlueprintWebClientService.WebClientResponse = rbDefinitionService.exchangeResource( + POST.name, + "/config-template", + templateJsonString + ) + log.debug(result.toString()) + return result.status in 200..299 + } catch (e: Exception) { + log.error("Caught exception during create template") + throw BlueprintProcessorException("${e.message}") + } + } + + fun uploadTemplate(definition: String, definitionVersion: String, template: K8sTemplate, filePath: Path) { + val fileUploadService = K8sUploadFileRestClientService(k8sConfiguration, definition, definitionVersion) + try { + val result: BlueprintWebClientService.WebClientResponse = fileUploadService.uploadBinaryFile( + "/config-template/${template.templateName}/content", + filePath + ) + if (result.status !in 200..299) { + throw Exception(result.body) + } + } catch (e: Exception) { + log.error("Caught exception trying to upload k8s rb template ${template.templateName}") + throw BlueprintProcessorException("${e.message}") + } + } + + fun deleteTemplate(definition: String, definitionVersion: String, templateName: String) { + val rbDefinitionService = K8sDefinitionRestClient(k8sConfiguration, definition, definitionVersion) + try { + val result: BlueprintWebClientService.WebClientResponse = rbDefinitionService.exchangeResource( + DELETE.name, + "/config-template/$templateName", + "" + ) + log.debug(result.toString()) + } catch (e: Exception) { + log.error("Caught exception during get template") + throw BlueprintProcessorException("${e.message}") + } + } + + fun getTemplate(definition: String, definitionVersion: String, templateName: String): K8sTemplate { + val rbDefinitionService = K8sDefinitionRestClient(k8sConfiguration, definition, definitionVersion) + try { + val result: BlueprintWebClientService.WebClientResponse = getTemplateRequest(rbDefinitionService, templateName) + log.debug(result.toString()) + return objectMapper.readValue(result.body) + } catch (e: Exception) { + log.error("Caught exception during get template") + throw BlueprintProcessorException("${e.message}") + } + } + + fun hasTemplate(definition: String, definitionVersion: String, templateName: String): Boolean { + val rbDefinitionService = K8sDefinitionRestClient(k8sConfiguration, definition, definitionVersion) + try { + val result: BlueprintWebClientService.WebClientResponse = getTemplateRequest(rbDefinitionService, templateName) + log.debug(result.toString()) + return result.status in 200..299 + } catch (e: Exception) { + log.error("Caught exception during get template") + throw BlueprintProcessorException("${e.message}") + } + } + + private fun getTemplateRequest(rbDefinitionService: K8sDefinitionRestClient, templateName: String): BlueprintWebClientService.WebClientResponse { + return rbDefinitionService.exchangeResource( + GET.name, + "/config-template/$templateName", + "" + ) + } +} 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? { + fun getInstanceList(): List? { val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration) try { val result: BlueprintWebClientService.WebClientResponse = rbInstanceService.exchangeResource( @@ -42,7 +46,8 @@ class K8sPluginInstanceApi( ) log.debug(result.toString()) return if (result.status in 200..299) { - val parsedObject: List = JacksonUtils.readValue(result.body) + val objectMapper = jacksonObjectMapper() + val parsedObject: ArrayList? = 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? = 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 = rbInstanceService.exchangeResource( GET.name, - "", + "/status", "" ) log.debug(result.toString()) return if (result.status in 200..299) { - val parsedObject: List = 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? { val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId) try { val result: BlueprintWebClientService.WebClientResponse = 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? = 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 = 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 = 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 = 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? = 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() + } +} -- cgit 1.2.3-korg