From 0bae36245d468db7232bedc896f7d26681b14e03 Mon Sep 17 00:00:00 2001 From: Dhrumin Desai Date: Wed, 13 Oct 2021 19:14:26 -0400 Subject: Convert streams_publishes and streams_subscribes json strings under applicationConfig to map in helm chart generator Issue-ID: DCAEGEN2-2936 Change-Id: I0ebfa7e615ef53ff12e84551f9847038f92f1724 Signed-off-by: Dhrumin Desai --- mod2/helm-generator/Changelog.md | 5 ++++- mod2/helm-generator/helmchartgenerator-cli/pom.xml | 4 ++-- .../helm-generator/helmchartgenerator-core/pom.xml | 4 ++-- .../chartbuilder/ComponentSpecParser.java | 24 +++++++++++++++++++++- .../ComponentSpecParserTest.java | 1 + mod2/helm-generator/pom.xml | 2 +- 6 files changed, 33 insertions(+), 7 deletions(-) diff --git a/mod2/helm-generator/Changelog.md b/mod2/helm-generator/Changelog.md index fa5463d..130e224 100644 --- a/mod2/helm-generator/Changelog.md +++ b/mod2/helm-generator/Changelog.md @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [1.0.2]- 2021-10-13 +* [DCAEGEN2-2936] Convert streams_publishes and streams_subscribes json strings under applicationConfig to map + ## [1.0.1]- 2021-10-04 * [DCAEGEN2-2911] Refactor the code to make it more testable @@ -16,4 +19,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [1.0.0] -* Helm chart generator seed code introduction \ No newline at end of file +* Helm chart generator seed code introduction diff --git a/mod2/helm-generator/helmchartgenerator-cli/pom.xml b/mod2/helm-generator/helmchartgenerator-cli/pom.xml index d7edca3..f08159e 100644 --- a/mod2/helm-generator/helmchartgenerator-cli/pom.xml +++ b/mod2/helm-generator/helmchartgenerator-cli/pom.xml @@ -8,7 +8,7 @@ 1.0.1-SNAPSHOT helmchartgenerator-cli - 1.0.1-SNAPSHOT + 1.0.2-SNAPSHOT helmchartgenerator-cli UTF-8 @@ -17,7 +17,7 @@ org.onap.dcaegen2.platform helmchartgenerator-core - 1.0.1-SNAPSHOT + 1.0.2-SNAPSHOT diff --git a/mod2/helm-generator/helmchartgenerator-core/pom.xml b/mod2/helm-generator/helmchartgenerator-core/pom.xml index 4dbbd3b..0ced9dd 100644 --- a/mod2/helm-generator/helmchartgenerator-core/pom.xml +++ b/mod2/helm-generator/helmchartgenerator-core/pom.xml @@ -5,10 +5,10 @@ org.onap.dcaegen2.platform helmchartgenerator - 1.0.1-SNAPSHOT + 1.0.2-SNAPSHOT helmchartgenerator-core - 1.0.1-SNAPSHOT + 1.0.2-SNAPSHOT helmchartgenerator-core UTF-8 diff --git a/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/chartbuilder/ComponentSpecParser.java b/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/chartbuilder/ComponentSpecParser.java index b0830d1..9a9f8f1 100644 --- a/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/chartbuilder/ComponentSpecParser.java +++ b/mod2/helm-generator/helmchartgenerator-core/src/main/java/org/onap/dcaegen2/platform/helmchartgenerator/chartbuilder/ComponentSpecParser.java @@ -18,6 +18,9 @@ package org.onap.dcaegen2.platform.helmchartgenerator.chartbuilder; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; import org.onap.dcaegen2.platform.helmchartgenerator.Utils; import org.onap.dcaegen2.platform.helmchartgenerator.models.chartinfo.ChartInfo; import org.onap.dcaegen2.platform.helmchartgenerator.models.chartinfo.Metadata; @@ -39,6 +42,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; @@ -48,6 +52,7 @@ import java.util.Map; * ComponentSpecParser reads a componentspec file and collects useful data for helm chart generation. * @author Dhrumin Desai */ +@Slf4j @Component public class ComponentSpecParser { @@ -117,11 +122,28 @@ public class ComponentSpecParser { Map applicationConfig = new LinkedHashMap<>(); Parameters[] parameters = cs.getParameters(); for(Parameters param : parameters){ - applicationConfig.put(param.getName(), param.getValue()); + if (Arrays.asList("streams_publishes", "streams_subscribes").contains(param.getName())){ + applicationConfig.put(param.getName(), parseStringToMap(param.getValue())); + }else + { + applicationConfig.put(param.getName(), param.getValue()); + } } utils.putIfNotNull(outerValues,"applicationConfig", applicationConfig); } + private Object parseStringToMap(Object value) { + if (value instanceof String){ + try { + return new ObjectMapper().readValue((String)value, Map.class); + } catch (JsonProcessingException e) { + log.error(e.getMessage(), e); + log.warn("could not parse streams_publishes / streams_subscribes. Default value will be used."); + } + } + return value; + } + private void populateReadinessSection(Map outerValues, ComponentSpec cs) { if (!healthCheckExists(cs)) return; diff --git a/mod2/helm-generator/helmchartgenerator-core/src/test/java/org/onap/dcaegen2/platform/helmchartgenerator/ComponentSpecParserTest.java b/mod2/helm-generator/helmchartgenerator-core/src/test/java/org/onap/dcaegen2/platform/helmchartgenerator/ComponentSpecParserTest.java index 0f157d3..f29ea1b 100644 --- a/mod2/helm-generator/helmchartgenerator-core/src/test/java/org/onap/dcaegen2/platform/helmchartgenerator/ComponentSpecParserTest.java +++ b/mod2/helm-generator/helmchartgenerator-core/src/test/java/org/onap/dcaegen2/platform/helmchartgenerator/ComponentSpecParserTest.java @@ -69,6 +69,7 @@ class ComponentSpecParserTest { private void assertApplicationConfigSection(ChartInfo chartInfo) { Map applicationConfig = (Map) chartInfo.getValues().get("applicationConfig"); + assertThat(((Map) applicationConfig.get("streams_publishes"))).isInstanceOf(Map.class); assertThat(applicationConfig.size()).isEqualTo(20); } diff --git a/mod2/helm-generator/pom.xml b/mod2/helm-generator/pom.xml index 7f9801c..8409274 100644 --- a/mod2/helm-generator/pom.xml +++ b/mod2/helm-generator/pom.xml @@ -33,7 +33,7 @@ org.onap.dcaegen2.platform helmchartgenerator - 1.0.1-SNAPSHOT + 1.0.2-SNAPSHOT helm-chart-generator Helm chart generator -- cgit 1.2.3-korg