aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/K8sPluginApi.kt
diff options
context:
space:
mode:
Diffstat (limited to 'ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/K8sPluginApi.kt')
-rw-r--r--ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/K8sPluginApi.kt83
1 files changed, 83 insertions, 0 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/K8sPluginApi.kt
index 211bc5abe..a36c8e31c 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/K8sPluginApi.kt
@@ -23,9 +23,12 @@ 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
@@ -117,4 +120,84 @@ class K8sPluginApi(
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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> {
+ return rbDefinitionService.exchangeResource(
+ GET.name,
+ "/config-template/$templateName",
+ ""
+ )
+ }
}