/*
* Copyright © 2017-2018 AT&T Intellectual Property.
* Modifications Copyright © 2019 IBM.
- * Modifications Copyright © 2021 Orange.
+ * Modifications Copyright © 2022 Orange.
* Modifications Copyright © 2020 Deutsche Telekom AG.
*
* Licensed under the Apache License, Version 2.0 (the "License");
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.K8sRbInstanceRestClient.Companion.getK8sRbInstanceRestClient
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.BluePrintProcessorException
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
import org.slf4j.LoggerFactory
import org.springframework.http.HttpMethod.DELETE
private val log = LoggerFactory.getLogger(K8sPluginInstanceApi::class.java)!!
fun getInstanceList(): List<K8sRbInstance>? {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
GET.name,
} else if (result.status == 500 && result.body.contains("Did not find any objects with tag"))
null
else
- throw BlueprintProcessorException(result.body)
+ throw BluePrintProcessorException(result.body)
} catch (e: Exception) {
log.error("Caught exception trying to get k8s rb instance")
- throw BlueprintProcessorException("${e.message}")
+ throw BluePrintProcessorException("${e.message}")
}
}
fun getInstanceById(instanceId: String): K8sRbInstance? {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
GET.name,
} else if (result.status == 500 && result.body.contains("Error finding master table"))
null
else
- throw BlueprintProcessorException(result.body)
+ throw BluePrintProcessorException(result.body)
} catch (e: Exception) {
log.error("Caught exception trying to get k8s rb instance")
- throw BlueprintProcessorException("${e.message}")
+ throw BluePrintProcessorException("${e.message}")
+ }
+ }
+
+ fun getFullInstanceById(instanceId: String): K8sRbInstanceFull? {
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ try {
+ val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
+ GET.name,
+ "?full=true",
+ ""
+ )
+ log.debug(result.toString())
+ return if (result.status in 200..299) {
+ val parsedObject: K8sRbInstanceFull? = JacksonUtils.readValue(result.body, K8sRbInstanceFull::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 getInstanceStatus(instanceId: String): K8sRbInstanceStatus? {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
GET.name,
} else if (result.status == 500 && result.body.contains("Error finding master table"))
null
else
- throw BlueprintProcessorException(result.body)
+ throw BluePrintProcessorException(result.body)
} catch (e: Exception) {
log.error("Caught exception trying to get k8s rb instance")
- throw BlueprintProcessorException("${e.message}")
+ throw BluePrintProcessorException("${e.message}")
}
}
name: String? = null,
labels: Map<String, String>? = null
): K8sRbInstanceStatus? {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
var path: String = "/query?ApiVersion=$apiVersion&Kind=$kind"
if (name != null)
} else if (result.status == 500 && result.body.contains("Error finding master table"))
null
else
- throw BlueprintProcessorException(result.body)
+ throw BluePrintProcessorException(result.body)
} catch (e: Exception) {
log.error("Caught exception trying to get k8s rb instance")
- throw BlueprintProcessorException("${e.message}")
+ throw BluePrintProcessorException("${e.message}")
}
}
- fun getInstanceHealthCheckList(instanceId: String): List<K8sRbInstanceHealthCheck>? {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ fun getInstanceHealthCheckList(instanceId: String): K8sRbInstanceHealthCheckList? {
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
GET.name,
)
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
else
- throw BlueprintProcessorException(result.body)
+ throw BluePrintProcessorException(result.body)
} catch (e: Exception) {
log.error("Caught exception trying to get k8s rb instance")
- throw BlueprintProcessorException("${e.message}")
+ throw BluePrintProcessorException("${e.message}")
}
}
fun getInstanceHealthCheck(instanceId: String, healthCheckId: String): K8sRbInstanceHealthCheck? {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
GET.name,
} else if (result.status == 500 && result.body.contains("Error finding master table"))
null
else
- throw BlueprintProcessorException(result.body)
+ throw BluePrintProcessorException(result.body)
} catch (e: Exception) {
log.error("Caught exception trying to get k8s rb instance")
- throw BlueprintProcessorException("${e.message}")
+ throw BluePrintProcessorException("${e.message}")
}
}
- fun startInstanceHealthCheck(instanceId: String): K8sRbInstanceHealthCheck? {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ fun startInstanceHealthCheck(instanceId: String): K8sRbInstanceHealthCheckSimple? {
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
POST.name,
)
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"))
null
else
- throw BlueprintProcessorException(result.body)
+ throw BluePrintProcessorException(result.body)
} catch (e: Exception) {
log.error("Caught exception trying to get k8s rb instance")
- throw BlueprintProcessorException("${e.message}")
+ throw BluePrintProcessorException("${e.message}")
}
}
fun createConfigurationValues(configValues: K8sConfigValueRequest, instanceId: String): K8sConfigValueResponse? {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
POST.name,
)
parsedObject
} else
- throw BlueprintProcessorException(result.body)
+ throw BluePrintProcessorException(result.body)
} catch (e: Exception) {
log.error("Caught exception trying to create config instance")
- throw BlueprintProcessorException("${e.message}")
+ throw BluePrintProcessorException("${e.message}")
}
}
fun editConfigurationValues(configValues: K8sConfigValueRequest, instanceId: String, configName: String): K8sConfigValueResponse? {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
PUT.name,
)
parsedObject
} else
- throw BlueprintProcessorException(result.body)
+ throw BluePrintProcessorException(result.body)
} catch (e: Exception) {
log.error("Caught exception trying to edit config instance")
- throw BlueprintProcessorException("${e.message}")
+ throw BluePrintProcessorException("${e.message}")
+ }
+ }
+
+ fun editConfigurationValuesByDelete(instanceId: String, configName: String): K8sConfigValueResponse? {
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ try {
+ val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
+ POST.name,
+ "/config/$configName/delete",
+ ""
+ )
+ 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 delete config instance")
+ throw BluePrintProcessorException("${e.message}")
}
}
fun hasConfigurationValues(instanceId: String, configName: String): Boolean {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
GET.name,
return result.status in 200..299
} catch (e: Exception) {
log.error("Caught exception trying to get k8s rb instance")
- throw BlueprintProcessorException("${e.message}")
+ throw BluePrintProcessorException("${e.message}")
+ }
+ }
+
+ fun hasConfigurationValuesVersion(instanceId: String, configName: String, version: String): Boolean {
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ try {
+ val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
+ GET.name,
+ "/config/$configName/version/$version",
+ ""
+ )
+ log.debug(result.toString())
+ return result.status in 200..299
+ } catch (e: Exception) {
+ log.error("Caught exception trying to get k8s rb instance")
+ throw BluePrintProcessorException("${e.message}")
}
}
fun getConfigurationValues(instanceId: String, configName: String): K8sConfigValueResponse? {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
GET.name,
)
parsedObject
} else
- throw BlueprintProcessorException(result.body)
+ throw BluePrintProcessorException(result.body)
} catch (e: Exception) {
log.error("Caught exception trying to get config instance")
- throw BlueprintProcessorException("${e.message}")
+ throw BluePrintProcessorException("${e.message}")
}
}
- fun deleteConfigurationValues(instanceId: String, configName: String) {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ fun getConfigurationValuesVersion(instanceId: String, configName: String, version: String): K8sConfigValueResponse? {
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
- DELETE.name,
- "/config/$configName",
+ GET.name,
+ "/config/$configName/version/$version",
""
)
log.debug(result.toString())
- if (result.status !in 200..299)
- throw BlueprintProcessorException(result.body)
+ 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 delete config instance")
- throw BlueprintProcessorException("${e.message}")
+ log.error("Caught exception trying to get config instance")
+ throw BluePrintProcessorException("${e.message}")
}
}
- fun rollbackConfigurationValues(instanceId: String): K8sConfigValueResponse? {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ fun getConfigurationValuesVersionByTag(instanceId: String, configName: String, tag: String): K8sConfigValueResponse? {
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
- POST.name,
- "/rollback",
+ GET.name,
+ "/config/$configName/tag/$tag",
""
)
log.debug(result.toString())
)
parsedObject
} else
- throw BlueprintProcessorException(result.body)
+ throw BluePrintProcessorException(result.body)
} catch (e: Exception) {
- log.error("Caught exception trying to get k8s rb instance")
- throw BlueprintProcessorException("${e.message}")
+ log.error("Caught exception trying to get config instance")
+ throw BluePrintProcessorException("${e.message}")
}
}
- fun tagConfigurationValues(instanceId: String): K8sConfigValueResponse? {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ fun getConfigurationValuesList(instanceId: String): List<K8sConfigValueResponse>? {
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
- POST.name,
- "/tagit",
+ GET.name,
+ "/config",
""
)
log.debug(result.toString())
return if (result.status in 200..299) {
- val parsedObject: K8sConfigValueResponse? = JacksonUtils.readValue(
- result.body, K8sConfigValueResponse::class.java
- )
+ val objectMapper = jacksonObjectMapper()
+ val parsedObject: ArrayList<K8sConfigValueResponse>? = objectMapper.readValue(result.body)
parsedObject
- } else
- throw BlueprintProcessorException(result.body)
+ } else if (result.status == 500 && result.body.contains("Did not find any objects with tag"))
+ null
+ else
+ throw BluePrintProcessorException(result.body)
} catch (e: Exception) {
- log.error("Caught exception trying to get k8s rb instance")
- throw BlueprintProcessorException("${e.message}")
+ log.error("Caught exception trying to get k8s config instance list")
+ throw BluePrintProcessorException("${e.message}")
+ }
+ }
+
+ fun getConfigurationValuesVersionList(instanceId: String, configName: String): List<K8sConfigValueResponse>? {
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ try {
+ val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
+ GET.name,
+ "/config/$configName/version",
+ ""
+ )
+ log.debug(result.toString())
+ return if (result.status in 200..299) {
+ val objectMapper = jacksonObjectMapper()
+ val parsedObject: ArrayList<K8sConfigValueResponse>? = objectMapper.readValue(result.body)
+ parsedObject
+ } else if (result.status == 500 && result.body.contains("Did not find any objects with tag"))
+ null
+ else
+ throw BluePrintProcessorException(result.body)
+ } catch (e: Exception) {
+ log.error("Caught exception trying to get k8s config instance version list")
+ throw BluePrintProcessorException("${e.message}")
+ }
+ }
+
+ fun getConfigurationValuesTagList(instanceId: String, configName: String): List<K8sConfigValueTag>? {
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ try {
+ val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
+ GET.name,
+ "/config/$configName/tag",
+ ""
+ )
+ log.debug(result.toString())
+ return if (result.status in 200..299) {
+ val objectMapper = jacksonObjectMapper()
+ val parsedObject: ArrayList<K8sConfigValueTag>? = objectMapper.readValue(result.body)
+ parsedObject
+ } else if (result.status == 500 && result.body.contains("Did not find any objects with tag"))
+ null
+ else
+ throw BluePrintProcessorException(result.body)
+ } catch (e: Exception) {
+ log.error("Caught exception trying to get k8s config instance tag list")
+ throw BluePrintProcessorException("${e.message}")
+ }
+ }
+
+ fun deleteConfigurationValues(instanceId: String, configName: String, deleteConfigOnly: Boolean) {
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ try {
+ var path: String = "/config/$configName"
+ if (deleteConfigOnly)
+ path = path.plus("?deleteConfigOnly=true")
+ val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
+ DELETE.name,
+ path,
+ ""
+ )
+ 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, configName: String, configVersion: String?, configTag: String?) {
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ try {
+ val configValues = hashMapOf<String, String>()
+ if (configVersion != null)
+ configValues["config-version"] = configVersion
+ if (configTag != null)
+ configValues["config-tag"] = configTag
+ val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
+ POST.name,
+ "/config/$configName/rollback",
+ JacksonUtils.getJson(configValues)
+ )
+ log.debug(result.toString())
+ if (result.status !in 200..299)
+ throw BluePrintProcessorException(result.body)
+ } catch (e: Exception) {
+ log.error("Caught exception trying to rollback config instance")
+ throw BluePrintProcessorException("${e.message}")
+ }
+ }
+
+ fun tagConfigurationValues(instanceId: String, configName: String, tagName: String) {
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ try {
+ val configValues = hashMapOf<String, String>()
+ configValues["tag-name"] = tagName
+ val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
+ POST.name,
+ "/config/$configName/tagit",
+ JacksonUtils.getJson(configValues)
+ )
+ log.debug(result.toString())
+ if (result.status !in 200..299)
+ throw BluePrintProcessorException(result.body)
+ } catch (e: Exception) {
+ log.error("Caught exception trying to tag config instance")
+ throw BluePrintProcessorException("${e.message}")
}
}
fun deleteInstanceHealthCheck(instanceId: String, healthCheckId: String) {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
+ val rbInstanceService = getK8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
DELETE.name,
)
log.debug(result.toString())
if (result.status !in 200..299)
- throw BlueprintProcessorException(result.body)
+ throw BluePrintProcessorException(result.body)
} catch (e: Exception) {
log.error("Caught exception trying to get k8s rb instance")
- throw BlueprintProcessorException("${e.message}")
+ throw BluePrintProcessorException("${e.message}")
}
}
}