From: aribeiro Date: Tue, 15 Sep 2020 07:20:39 +0000 (+0100) Subject: Allow hot reloading of specific config properties X-Git-Tag: 1.7.2~15 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F61%2F113361%2F1;p=sdc.git 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 --- 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, diff --git a/common-app-api/src/main/java/org/openecomp/sdc/be/config/Configuration.java b/common-app-api/src/main/java/org/openecomp/sdc/be/config/Configuration.java index 2841dfd123..4ec7a16a5c 100644 --- a/common-app-api/src/main/java/org/openecomp/sdc/be/config/Configuration.java +++ b/common-app-api/src/main/java/org/openecomp/sdc/be/config/Configuration.java @@ -23,10 +23,12 @@ package org.openecomp.sdc.be.config; import static java.lang.String.format; import static java.util.Collections.emptyMap; +import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Map; import java.util.Set; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.map.CaseInsensitiveMap; import org.openecomp.sdc.common.api.BasicConfiguration; @@ -1598,6 +1600,9 @@ public class Configuration extends BasicConfiguration { } public List getGlobalCsarImports() { + if (CollectionUtils.isEmpty(globalCsarImports)) { + return Collections.emptyList(); + } return globalCsarImports; }