diff options
author | 2021-10-13 19:14:26 -0400 | |
---|---|---|
committer | 2021-10-18 14:58:07 -0400 | |
commit | 0bae36245d468db7232bedc896f7d26681b14e03 (patch) | |
tree | cd5a6099076ac7d86eee113fac87255036083531 /mod2/helm-generator/helmchartgenerator-core/src | |
parent | a494a322554924f6f9c3d6cc79240f54d3a8da0b (diff) |
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 <dd303q@att.com>
Diffstat (limited to 'mod2/helm-generator/helmchartgenerator-core/src')
2 files changed, 24 insertions, 1 deletions
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<String, Object> 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<String, Object> 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<String, Object> applicationConfig = (Map<String, Object>) chartInfo.getValues().get("applicationConfig"); + assertThat(((Map<String,Object>) applicationConfig.get("streams_publishes"))).isInstanceOf(Map.class); assertThat(applicationConfig.size()).isEqualTo(20); } |