summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions/k8s-connection-plugin/src
diff options
context:
space:
mode:
authorGrzegorz Wielgosinski <g.wielgosins@samsung.com>2021-02-23 17:27:58 +0100
committerKAPIL SINGAL <ks220y@att.com>2021-02-24 15:05:00 +0000
commita831c362689ff850f6ed7fff3c57f4b4037b55d8 (patch)
tree107b392b4a99eec82c57ef84340e83adab5db2ab /ms/blueprintsprocessor/functions/k8s-connection-plugin/src
parent01f8b7171467466791262afad5adb60571198dea (diff)
Add rollback and update functionality for config-value component.
Issue-ID: CCSDK-2922 Signed-off-by: Grzegorz Wielgosinski <g.wielgosins@samsung.com> Change-Id: I7384aa3d99fe273454e3acf2f933add0fb07a66c
Diffstat (limited to 'ms/blueprintsprocessor/functions/k8s-connection-plugin/src')
-rw-r--r--ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/definition/template/K8sConfigValueComponent.kt93
-rw-r--r--ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/instance/K8sPluginInstanceApi.kt28
2 files changed, 79 insertions, 42 deletions
diff --git a/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/definition/template/K8sConfigValueComponent.kt b/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/definition/template/K8sConfigValueComponent.kt
index 7e9f407e1..2e7b34e01 100644
--- a/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/definition/template/K8sConfigValueComponent.kt
+++ b/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/definition/template/K8sConfigValueComponent.kt
@@ -40,6 +40,7 @@ open class K8sConfigValueComponent(
const val INPUT_K8S_CONFIG_NAME = "k8s-config-name"
const val INPUT_K8S_INSTANCE_ID = "k8s-instance-id"
const val INPUT_K8S_TEMPLATE_VALUE_SOURCE = "k8s-rb-template-value-source"
+ const val INPUT_K8S_OPERATION_TYPE = "k8s-operation-type"
const val OUTPUT_STATUSES = "statuses"
const val OUTPUT_SKIPPED = "skipped"
@@ -53,6 +54,7 @@ open class K8sConfigValueComponent(
INPUT_K8S_TEMPLATE_NAME,
INPUT_K8S_CONFIG_NAME,
INPUT_K8S_INSTANCE_ID,
+ INPUT_K8S_OPERATION_TYPE,
INPUT_K8S_TEMPLATE_VALUE_SOURCE,
INPUT_ARTIFACT_PREFIX_NAMES
)
@@ -84,31 +86,86 @@ open class K8sConfigValueComponent(
val configName: String? = prefixInputParamsMap[INPUT_K8S_CONFIG_NAME]?.returnNullIfMissing()?.asText()
val instanceId: String? = prefixInputParamsMap[INPUT_K8S_INSTANCE_ID]?.returnNullIfMissing()?.asText()
val valueSource: String? = prefixInputParamsMap[INPUT_K8S_TEMPLATE_VALUE_SOURCE]?.returnNullIfMissing()?.asText()
- if (templateName == null || instanceId == null || valueSource == null) {
- log.warn("$INPUT_K8S_TEMPLATE_NAME or $INPUT_K8S_TEMPLATE_NAME or $INPUT_K8S_TEMPLATE_VALUE_SOURCE or $INPUT_K8S_CONFIG_NAME is null")
- } else if (templateName.isEmpty()) {
- log.warn("$INPUT_K8S_TEMPLATE_NAME is empty")
- } else {
- log.info("Uploading K8s template value..")
- outputPrefixStatuses[prefix] = OUTPUT_ERROR
- val bluePrintContext = bluePrintRuntimeService.bluePrintContext()
- val artifact: ArtifactDefinition = bluePrintContext.nodeTemplateArtifact(nodeTemplateName, valueSource)
- if (artifact.type != BlueprintConstants.MODEL_TYPE_ARTIFACT_K8S_PROFILE)
- throw BlueprintProcessorException(
- "Unexpected profile artifact type for profile source $valueSource. Expecting: $artifact.type"
- )
- // Creating API connector
- val api = K8sPluginInstanceApi(K8sConnectionPluginConfiguration(bluePrintPropertiesService))
+ val operationType = prefixInputParamsMap[INPUT_K8S_TEMPLATE_VALUE_SOURCE]?.returnNullIfMissing()?.asText()?.toUpperCase()
+
+ if (operationType == null || operationType == OperationType.CREATE.toString())
+ createOperation(templateName, instanceId, valueSource, outputPrefixStatuses, prefix, configName)
+ else if (operationType == OperationType.UPDATE.toString())
+ updateOperation(templateName, instanceId, valueSource, outputPrefixStatuses, prefix, configName)
+ else if (operationType == OperationType.ROLLBACK.toString())
+ rollbackOperation(instanceId)
+ else
+ throw BlueprintProcessorException("Unknown operation type: $operationType")
+ }
+ }
+
+ private fun createOperation(templateName: String?, instanceId: String?, valueSource: String?, outputPrefixStatuses: MutableMap<String, String>, prefix: String, configName: String?) {
+ if (templateName == null || configName == null || instanceId == null || valueSource == null) {
+ log.warn("$INPUT_K8S_TEMPLATE_NAME or $INPUT_K8S_INSTANCE_ID or $INPUT_K8S_TEMPLATE_VALUE_SOURCE or $INPUT_K8S_CONFIG_NAME is null")
+ } else if (templateName.isEmpty()) {
+ log.warn("$INPUT_K8S_TEMPLATE_NAME is empty")
+ } else if (configName.isEmpty()) {
+ log.warn("$INPUT_K8S_CONFIG_NAME is empty")
+ } else {
+ log.info("Uploading K8s template value..")
+ outputPrefixStatuses[prefix] = OUTPUT_ERROR
+ val bluePrintContext = bluePrintRuntimeService.bluePrintContext()
+ val artifact: ArtifactDefinition = bluePrintContext.nodeTemplateArtifact(nodeTemplateName, valueSource)
+ if (artifact.type != BlueprintConstants.MODEL_TYPE_ARTIFACT_K8S_PROFILE)
+ throw BlueprintProcessorException(
+ "Unexpected profile artifact type for profile source $valueSource. Expecting: $artifact.type"
+ )
+ // Creating API connector
+ val api = K8sPluginInstanceApi(K8sConnectionPluginConfiguration(bluePrintPropertiesService))
+ val configValueRequest = K8sConfigValueRequest()
+ configValueRequest.templateName = templateName
+ configValueRequest.configName = configName
+ configValueRequest.description = valueSource
+ configValueRequest.values = parseResult(valueSource)
+ api.createConfigurationValues(configValueRequest, instanceId)
+ }
+ }
+
+ private fun updateOperation(templateName: String?, instanceId: String?, valueSource: String?, outputPrefixStatuses: MutableMap<String, String>, prefix: String, configName: String?) {
+ if (templateName == null || configName == null || instanceId == null || valueSource == null) {
+ log.warn("$INPUT_K8S_TEMPLATE_NAME or $INPUT_K8S_INSTANCE_ID or $INPUT_K8S_TEMPLATE_VALUE_SOURCE or $INPUT_K8S_CONFIG_NAME is null")
+ } else if (templateName.isEmpty()) {
+ log.warn("$INPUT_K8S_TEMPLATE_NAME is empty")
+ } else if (configName.isEmpty()) {
+ log.warn("$INPUT_K8S_CONFIG_NAME is empty")
+ } else {
+ log.info("Uploading K8s template value..")
+ outputPrefixStatuses[prefix] = OUTPUT_ERROR
+ val bluePrintContext = bluePrintRuntimeService.bluePrintContext()
+ val artifact: ArtifactDefinition = bluePrintContext.nodeTemplateArtifact(nodeTemplateName, valueSource)
+ if (artifact.type != BlueprintConstants.MODEL_TYPE_ARTIFACT_K8S_PROFILE)
+ throw BlueprintProcessorException(
+ "Unexpected profile artifact type for profile source $valueSource. Expecting: $artifact.type"
+ )
+ // Creating API connector
+ val api = K8sPluginInstanceApi(K8sConnectionPluginConfiguration(bluePrintPropertiesService))
+ if (api.hasConfigurationValues(instanceId, configName)) {
val configValueRequest = K8sConfigValueRequest()
configValueRequest.templateName = templateName
configValueRequest.configName = configName
configValueRequest.description = valueSource
configValueRequest.values = parseResult(valueSource)
- api.createConfigurationValues(configValueRequest, instanceId)
+ api.editConfigurationValues(configValueRequest, instanceId, configName)
+ } else {
+ throw BlueprintProcessorException("Error while getting configuration value")
}
}
}
+ private fun rollbackOperation(instanceId: String?) {
+ if (instanceId != null) {
+ val api = K8sPluginInstanceApi(K8sConnectionPluginConfiguration(bluePrintPropertiesService))
+ api.rollbackConfigurationValues(instanceId)
+ } else {
+ throw BlueprintProcessorException("$INPUT_K8S_INSTANCE_ID is null")
+ }
+ }
+
private fun parseResult(templateValueSource: String): Any {
val ymlSourceFile = getYmlSourceFile(templateValueSource)
val yamlReader = ObjectMapper(YAMLFactory())
@@ -146,4 +203,8 @@ open class K8sConfigValueComponent(
override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
bluePrintRuntimeService.getBlueprintError().addError(runtimeException.message!!)
}
+
+ private enum class OperationType {
+ CREATE, UPDATE, ROLLBACK
+ }
}
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 b312adc8c..7663699aa 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
@@ -267,7 +267,7 @@ class K8sPluginInstanceApi(
}
}
- fun getConfigurationValues(instanceId: String, configName: String): K8sConfigValueResponse? {
+ fun hasConfigurationValues(instanceId: String, configName: String): Boolean {
val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
try {
val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
@@ -276,31 +276,7 @@ class K8sPluginInstanceApi(
""
)
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 get k8s rb instance")
- throw BlueprintProcessorException("${e.message}")
- }
- }
-
- fun deleteConfigurationValues(instanceId: String, configName: String) {
- val rbInstanceService = K8sRbInstanceRestClient(k8sConfiguration, instanceId)
- try {
- val result: BlueprintWebClientService.WebClientResponse<String> = rbInstanceService.exchangeResource(
- DELETE.name,
- "/config/$configName",
- ""
- )
- log.debug(result.toString())
- if (result.status !in 200..299) {
- throw BlueprintProcessorException(result.body)
- }
+ return result.status in 200..299
} catch (e: Exception) {
log.error("Caught exception trying to get k8s rb instance")
throw BlueprintProcessorException("${e.message}")