From 0fa53516c409ac136f654475c1e41c77cad9cf09 Mon Sep 17 00:00:00 2001 From: aribeiro Date: Tue, 15 Sep 2020 08:20:39 +0100 Subject: Allow hot reloading of specific config properties getGlobalCsarImports and getDefaultImports entries are now not static which will allow to get new values if the config file change during runtime. Issue-ID: SDC-3303 Signed-off-by: aribeiro Change-Id: I870c13aec5d386aa3c87d6a335b5fb5948073954 --- .../java/org/openecomp/sdc/be/tosca/CsarUtils.java | 12 ++++------- .../openecomp/sdc/be/tosca/ToscaExportHandler.java | 24 ++++++++++++++-------- 2 files changed, 19 insertions(+), 17 deletions(-) (limited to 'catalog-be/src/main/java/org') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java index e19ea21c74..61068f26a8 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java @@ -22,13 +22,14 @@ package org.openecomp.sdc.be.tosca; import static org.openecomp.sdc.be.tosca.ComponentCache.MergeStrategy.overwriteIfSameVersions; +import static org.openecomp.sdc.be.tosca.FJToVavrHelper.Try0.fromEither; import fj.F; import fj.data.Either; import java.text.SimpleDateFormat; import io.vavr.Tuple2; -import io.vavr.control.Try; import io.vavr.control.Option; +import io.vavr.control.Try; import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; import java.io.File; @@ -68,7 +69,6 @@ import org.apache.commons.lang3.tuple.ImmutableTriple; import org.apache.commons.lang3.tuple.Triple; import org.onap.sdc.tosca.services.YamlUtil; import org.openecomp.sdc.be.components.impl.ImportUtils; -import org.openecomp.sdc.be.components.impl.ImportUtils.Constants; import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.config.ArtifactConfigManager; import org.openecomp.sdc.be.config.ArtifactConfiguration; @@ -96,7 +96,6 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter; import org.openecomp.sdc.be.plugins.CsarEntryGenerator; import org.openecomp.sdc.be.resources.data.DAOArtifactData; -import org.openecomp.sdc.be.tosca.model.ToscaTemplate; import org.openecomp.sdc.be.tosca.utils.OperationArtifactUtil; import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum; import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum; @@ -113,8 +112,6 @@ import org.openecomp.sdc.exception.ResponseFormat; import org.springframework.beans.factory.annotation.Autowired; import org.yaml.snakeyaml.Yaml; -import static org.openecomp.sdc.be.tosca.FJToVavrHelper.Try0.fromEither; - /** * @author tg851x * @@ -139,8 +136,6 @@ public class CsarUtils { @Autowired(required = false) private List generators; - private static final List globalCsarImports = ConfigurationManager.getConfigurationManager() - .getConfiguration().getGlobalCsarImports(); private static final String CONFORMANCE_LEVEL = ConfigurationManager.getConfigurationManager().getConfiguration().getToscaConformanceLevel(); private static final String SDC_VERSION = ExternalConfiguration.getAppVersion(); public static final String ARTIFACTS_PATH = "Artifacts/"; @@ -618,7 +613,8 @@ public class CsarUtils { * @return true if the zip entry should be handled */ private boolean shouldZipEntryBeHandled(final String entryName) { - return globalCsarImports.stream() + return ConfigurationManager.getConfigurationManager().getConfiguration() + .getGlobalCsarImports().stream() .anyMatch(entry -> entry.contains(entryName)); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java index b59930e6c3..533ed7a6f0 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java @@ -166,8 +166,6 @@ public class ToscaExportHandler { public static final String ASSET_TOSCA_TEMPLATE = "assettoscatemplate"; private static final String FAILED_TO_GET_DEFAULT_IMPORTS_CONFIGURATION = "convertToToscaTemplate - failed to get Default Imports section from configuration"; private static final String NOT_SUPPORTED_COMPONENT_TYPE = "Not supported component type {}"; - private static final List>> DEFAULT_IMPORTS = ConfigurationManager - .getConfigurationManager().getConfiguration().getDefaultImports(); private static final String NATIVE_ROOT = "tosca.nodes.Root"; private static YamlUtil yamlUtil = new YamlUtil(); @@ -180,7 +178,8 @@ public class ToscaExportHandler { public Either exportComponentInterface(final Component component, final boolean isAssociatedComponent) { - if (null == DEFAULT_IMPORTS) { + final List>> defaultToscaImportConfig = getDefaultToscaImportConfig(); + if (CollectionUtils.isEmpty(defaultToscaImportConfig)) { log.debug(FAILED_TO_GET_DEFAULT_IMPORTS_CONFIGURATION); return Either.right(ToscaError.GENERAL_ERROR); } @@ -190,7 +189,7 @@ public class ToscaExportHandler { toscaVersion = ((Resource) component).getToscaVersion(); } ToscaTemplate toscaTemplate = new ToscaTemplate(toscaVersion != null ? toscaVersion : TOSCA_VERSION); - toscaTemplate.setImports(new ArrayList<>(DEFAULT_IMPORTS)); + toscaTemplate.setImports(new ArrayList<>(defaultToscaImportConfig)); final Map nodeTypes = new HashMap<>(); final Either toscaTemplateRes = convertInterfaceNodeType(new HashMap<>(), component, toscaTemplate, nodeTypes, isAssociatedComponent); @@ -238,7 +237,8 @@ public class ToscaExportHandler { } public Either convertToToscaTemplate(final Component component) { - if (null == DEFAULT_IMPORTS) { + final List>> defaultToscaImportConfig = getDefaultToscaImportConfig(); + if (CollectionUtils.isEmpty(defaultToscaImportConfig)) { log.debug(FAILED_TO_GET_DEFAULT_IMPORTS_CONFIGURATION); return Either.right(ToscaError.GENERAL_ERROR); } @@ -249,7 +249,7 @@ public class ToscaExportHandler { } final ToscaTemplate toscaTemplate = new ToscaTemplate(toscaVersion != null ? toscaVersion : TOSCA_VERSION); toscaTemplate.setMetadata(convertMetadata(component)); - toscaTemplate.setImports(new ArrayList<>(DEFAULT_IMPORTS)); + toscaTemplate.setImports(new ArrayList<>(defaultToscaImportConfig)); final Map nodeTypes = new HashMap<>(); if (ModelConverter.isAtomicComponent(component)) { log.trace("convert component as node type"); @@ -487,15 +487,17 @@ public class ToscaExportHandler { private Either>, ToscaError> fillImports(Component component, ToscaTemplate toscaTemplate) { - if (null == DEFAULT_IMPORTS) { + final List>> defaultToscaImportConfig = getDefaultToscaImportConfig(); + if (CollectionUtils.isEmpty(defaultToscaImportConfig)) { log.debug(FAILED_TO_GET_DEFAULT_IMPORTS_CONFIGURATION); return Either.right(ToscaError.GENERAL_ERROR); } Map componentCache = new HashMap<>(); if (!ModelConverter.isAtomicComponent(component)) { - List>> additionalImports = toscaTemplate.getImports() == null - ? new ArrayList<>(DEFAULT_IMPORTS) : new ArrayList<>(toscaTemplate.getImports()); + final List>> additionalImports = + toscaTemplate.getImports() == null ? new ArrayList<>(defaultToscaImportConfig) + : new ArrayList<>(toscaTemplate.getImports()); List> dependecies = new ArrayList<>(); @@ -525,6 +527,10 @@ public class ToscaExportHandler { return Either.left(new ImmutablePair<>(toscaTemplate, componentCache)); } + private List>> getDefaultToscaImportConfig() { + return ConfigurationManager.getConfigurationManager().getConfiguration().getDefaultImports(); + } + private void createDependency(final Map componentCache, final List>> imports, final List> dependencies, -- cgit 1.2.3-korg