From 4aa20bc42b7bd98dde15f7594084669eb92412c2 Mon Sep 17 00:00:00 2001 From: "andre.schmid" Date: Wed, 29 Jan 2020 17:38:07 +0000 Subject: Configuration file runtime reload Reloads the backend configuration file when the file listener catches a change. Forces validations errors when the configuration file could not be parsed. Remove not used configurations. Change-Id: Ic6fcb2b557d52ec53074c38ab8e0fcfa96e9be67 Issue-ID: SDC-2758 Signed-off-by: andre.schmid --- .../org/openecomp/sdc/be/config/Configuration.java | 31 +--- .../sdc/be/config/ConfigurationManager.java | 8 +- .../sdc/common/api/ConfigurationSource.java | 4 +- .../sdc/common/api/FileChangeCallback.java | 3 +- .../api/exception/LoadConfigurationException.java | 27 +++ .../sdc/common/impl/ConfigFileChangeListener.java | 100 +++++------ .../sdc/common/impl/FSConfigurationSource.java | 19 +- .../sdc/common/util/YamlToObjectConverter.java | 158 ++++++---------- .../sdc/exception/YamlConversionException.java | 27 +++ .../sdc/common/util/YamlToObjectConverterTest.java | 26 ++- .../sdc/fe/config/WorkspaceConfigurationTest.java | 2 +- .../config/common/workspace-configuration.yaml | 199 --------------------- .../config/fe/workspace-configuration.yaml | 199 +++++++++++++++++++++ 13 files changed, 384 insertions(+), 419 deletions(-) create mode 100644 common-app-api/src/main/java/org/openecomp/sdc/common/api/exception/LoadConfigurationException.java create mode 100644 common-app-api/src/main/java/org/openecomp/sdc/exception/YamlConversionException.java delete mode 100644 common-app-api/src/test/resources/config/common/workspace-configuration.yaml create mode 100644 common-app-api/src/test/resources/config/fe/workspace-configuration.yaml (limited to 'common-app-api/src') 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 5d5afe0c98..711268e6a7 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 @@ -95,7 +95,6 @@ public class Configuration extends BasicConfiguration { private Map serviceDeploymentArtifacts; private Map resourceInstanceDeploymentArtifacts; private Map resourceInformationalArtifacts; - private Map resourceInformationalDeployedArtifacts; private Map serviceApiArtifacts; private List excludeServiceCategory; @@ -144,29 +143,23 @@ public class Configuration extends BasicConfiguration { private CadiFilterParams cadiFilterParams; private Boolean aafAuthNeeded; - private String autoHealingOwner; private boolean enableAutoHealing; - private Map> resourcesForUpgrade; private DmaapConsumerConfiguration dmaapConsumerConfiguration; private DmaapProducerConfiguration dmaapProducerConfiguration; - private boolean skipUpgradeFailedVfs; private boolean skipUpgradeVSPs; private DmeConfiguration dmeConfiguration; - private boolean supportAllottedResourcesAndProxy; private Integer deleteLockTimeoutInSeconds; private Integer maxDeleteComponents; private CookieConfig authCookie; - - private String aafNamespace; private String workloadContext; - private EnvironmentContext environmentContext; - + private List gabConfig; + private EcompPortalConfig ecompPortal; public String getAutoHealingOwner() { return autoHealingOwner; @@ -207,7 +200,6 @@ public class Configuration extends BasicConfiguration { public void setDmaapConsumerConfiguration(DmaapConsumerConfiguration dmaapConsumerConfiguration) { this.dmaapConsumerConfiguration = dmaapConsumerConfiguration; } - public DmeConfiguration getDmeConfiguration() { return dmeConfiguration; } @@ -215,6 +207,7 @@ public class Configuration extends BasicConfiguration { public void setDmeConfiguration(DmeConfiguration dmeConfiguration) { this.dmeConfiguration = dmeConfiguration; } + public void setSkipUpgradeVSPs(boolean skipUpgradeVSPs) { this.skipUpgradeVSPs = skipUpgradeVSPs; } public boolean getSkipUpgradeVSPsFlag() { return skipUpgradeVSPs; } @@ -251,8 +244,6 @@ public class Configuration extends BasicConfiguration { this.artifactGeneratorConfig = artifactGeneratorConfig; } - private List gabConfig; - public Map getGenericAssetNodeTypes() { return genericAssetNodeTypes; } @@ -285,8 +276,6 @@ public class Configuration extends BasicConfiguration { this.applicationL2Cache = applicationL2Cache; } - private EcompPortalConfig ecompPortal; - public CassandrConfig getCassandraConfig() { return cassandraConfig; } @@ -1212,6 +1201,8 @@ public class Configuration extends BasicConfiguration { private Integer port; private String healthCheckUri; private String defaultFunctionalMenu; + private Integer pollingInterval; + private Integer timeoutMs; public void setPollingInterval(Integer pollingInterval) { this.pollingInterval = pollingInterval; @@ -1221,9 +1212,6 @@ public class Configuration extends BasicConfiguration { this.timeoutMs = timeoutMs; } - private Integer pollingInterval; - private Integer timeoutMs; - public String getProtocol() { return protocol; } @@ -1583,15 +1571,6 @@ public class Configuration extends BasicConfiguration { this.artifactsIndex = artifactsIndex; } - public Map getResourceInformationalDeployedArtifacts() { - return resourceInformationalDeployedArtifacts; - } - - public void setResourceInformationalDeployedArtifacts( - Map resourceInformationalDeployedArtifacts) { - this.resourceInformationalDeployedArtifacts = resourceInformationalDeployedArtifacts; - } - public List getResourceTypes() { return resourceTypes; } diff --git a/common-app-api/src/main/java/org/openecomp/sdc/be/config/ConfigurationManager.java b/common-app-api/src/main/java/org/openecomp/sdc/be/config/ConfigurationManager.java index 0e9fd24111..101b60e941 100644 --- a/common-app-api/src/main/java/org/openecomp/sdc/be/config/ConfigurationManager.java +++ b/common-app-api/src/main/java/org/openecomp/sdc/be/config/ConfigurationManager.java @@ -36,6 +36,7 @@ public class ConfigurationManager implements FileChangeCallback, IEcompConfigura ConfigurationSource configurationSource = null; private static ConfigurationManager instance; + final Map configurations = new HashMap<>(); @VisibleForTesting public ConfigurationManager() { @@ -43,7 +44,6 @@ public class ConfigurationManager implements FileChangeCallback, IEcompConfigura instance = this; } - Map configurations = new HashMap<>(); public ConfigurationManager(ConfigurationSource configurationSource) { super(); this.configurationSource = configurationSource; @@ -124,7 +124,11 @@ public class ConfigurationManager implements FileChangeCallback, IEcompConfigura return instance; } - public void reconfigure(BasicConfiguration obj) { } + public void reconfigure(final BasicConfiguration basicConfiguration) { + if (basicConfiguration instanceof Configuration) { + configurations.put(getKey(Configuration.class), basicConfiguration); + } + } /** * FOR TEST ONLY diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/api/ConfigurationSource.java b/common-app-api/src/main/java/org/openecomp/sdc/common/api/ConfigurationSource.java index 5901d1e267..12982caec0 100644 --- a/common-app-api/src/main/java/org/openecomp/sdc/common/api/ConfigurationSource.java +++ b/common-app-api/src/main/java/org/openecomp/sdc/common/api/ConfigurationSource.java @@ -22,7 +22,7 @@ package org.openecomp.sdc.common.api; public interface ConfigurationSource { - public T getAndWatchConfiguration(Class className, ConfigurationListener configurationListener); + T getAndWatchConfiguration(Class className, ConfigurationListener configurationListener); - public void addWatchConfiguration(Class className, ConfigurationListener configurationListener); + void addWatchConfiguration(Class className, ConfigurationListener configurationListener); } diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/api/FileChangeCallback.java b/common-app-api/src/main/java/org/openecomp/sdc/common/api/FileChangeCallback.java index 5c4d3d5926..9684c98bd3 100644 --- a/common-app-api/src/main/java/org/openecomp/sdc/common/api/FileChangeCallback.java +++ b/common-app-api/src/main/java/org/openecomp/sdc/common/api/FileChangeCallback.java @@ -20,8 +20,9 @@ package org.openecomp.sdc.common.api; +@FunctionalInterface public interface FileChangeCallback { - public void reconfigure(BasicConfiguration obj); + void reconfigure(BasicConfiguration obj); } diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/api/exception/LoadConfigurationException.java b/common-app-api/src/main/java/org/openecomp/sdc/common/api/exception/LoadConfigurationException.java new file mode 100644 index 0000000000..dff83c6d6f --- /dev/null +++ b/common-app-api/src/main/java/org/openecomp/sdc/common/api/exception/LoadConfigurationException.java @@ -0,0 +1,27 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.common.api.exception; + +public class LoadConfigurationException extends RuntimeException { + + public LoadConfigurationException(final String s, final Throwable throwable) { + super(s, throwable); + } +} diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/impl/ConfigFileChangeListener.java b/common-app-api/src/main/java/org/openecomp/sdc/common/impl/ConfigFileChangeListener.java index e243bac730..c94db9a3c9 100644 --- a/common-app-api/src/main/java/org/openecomp/sdc/common/impl/ConfigFileChangeListener.java +++ b/common-app-api/src/main/java/org/openecomp/sdc/common/impl/ConfigFileChangeListener.java @@ -20,22 +20,23 @@ package org.openecomp.sdc.common.impl; +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.jci.listeners.FileChangeListener; import org.openecomp.sdc.common.api.BasicConfiguration; import org.openecomp.sdc.common.api.ConfigurationListener; import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode; import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.common.util.YamlToObjectConverter; - -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import org.openecomp.sdc.exception.YamlConversionException; public class ConfigFileChangeListener extends FileChangeListener { - private static Logger log = Logger.getLogger(ConfigFileChangeListener.class.getName()); + private static final Logger LOGGER = Logger.getLogger(ConfigFileChangeListener.class.getName()); private Map> fileChangeToCallBack = new HashMap<>(); @@ -45,45 +46,46 @@ public class ConfigFileChangeListener extends FileChangeListener { @Override public void onFileChange(File pFile) { - super.onFileChange(pFile); - if (pFile != null) { - - if (fileChangeToCallBack != null) { - - String id = findIdFromFileName(pFile.getName()); - - if (id != null) { - - List listeners = fileChangeToCallBack.get(id); - if (listeners != null) { - for (ConfigurationListener configurationListener : listeners) { - - Class configClass = configurationListener.getType(); - - BasicConfiguration basicConfiguration = yamlToObjectConverter.convert(pFile.getAbsolutePath(), configClass); - - if (basicConfiguration == null) { - log.warn(EcompLoggerErrorCode.UNKNOWN_ERROR,"","","Cannot update the listeners for file Change since the file content is invalid"); - continue; - } - log.debug("Loaded configuration after converting is {}", basicConfiguration); - + if (pFile == null) { + LOGGER.debug("Invalid file '{}'.", pFile); + return; + } - configurationListener.getCallBack().reconfigure(basicConfiguration); + if (fileChangeToCallBack == null) { + LOGGER.debug("File '{}' callback is null.", pFile); + return; + } - } - } - } else { + final String id = findIdFromFileName(pFile.getName()); + if (id == null) { + LOGGER.warn(EcompLoggerErrorCode.UNKNOWN_ERROR,"","", + "Cannot calculate id from file {}", pFile.getName()); + return; + } - log.warn(EcompLoggerErrorCode.UNKNOWN_ERROR,"","","Cannot calculate id from file {}", pFile.getName()); - } + final List listeners = fileChangeToCallBack.get(id); + if (CollectionUtils.isEmpty(listeners)) { + LOGGER.debug("No file listeners for file '{}', id '{}'.", pFile, id); + return; + } + for (final ConfigurationListener configurationListener : listeners) { + final Class configClass = configurationListener.getType(); + final BasicConfiguration basicConfiguration; + try { + basicConfiguration = yamlToObjectConverter.convert(pFile.getAbsolutePath(), configClass); + } catch (final YamlConversionException e) { + LOGGER.warn(EcompLoggerErrorCode.SCHEMA_ERROR, + "Configuration", "Configuration", + "Cannot update the listeners for file Change since the file content is invalid: {}", + e.getLocalizedMessage()); + continue; } - + LOGGER.debug("Loaded configuration after converting is {}", basicConfiguration); + configurationListener.getCallBack().reconfigure(basicConfiguration); } - - log.debug("File {} was changed.", pFile); + LOGGER.debug("File {} was changed.", pFile); } private String findIdFromFileName(String name) { @@ -95,10 +97,6 @@ public class ConfigFileChangeListener extends FileChangeListener { if (name.contains(File.separator)) { startIndex = name.lastIndexOf(File.separator); } - // String subNameString = name.substring(startIndex, endIndex); - // if (subNameString.contains(".")) { - // endIndex = subNameString.indexOf("."); - // } result = name.substring(startIndex, endIndex); @@ -126,20 +124,4 @@ public class ConfigFileChangeListener extends FileChangeListener { } - // public void notify(String id, BasicConfiguration object) { - // - // if (fileChangeToCallBack != null) { - // List listeners = fileChangeToCallBack - // .get(id); - // if (listeners != null) { - // for (ConfigurationListener configurationListener : listeners) { - // - // configurationListener.getCallBack().reconfigure(object); - // - // } - // } - // } - // - // } - } diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/impl/FSConfigurationSource.java b/common-app-api/src/main/java/org/openecomp/sdc/common/impl/FSConfigurationSource.java index 8cab431594..3820f2c26c 100644 --- a/common-app-api/src/main/java/org/openecomp/sdc/common/impl/FSConfigurationSource.java +++ b/common-app-api/src/main/java/org/openecomp/sdc/common/impl/FSConfigurationSource.java @@ -27,7 +27,9 @@ import java.util.stream.Collectors; import org.openecomp.sdc.common.api.ConfigurationListener; import org.openecomp.sdc.common.api.ConfigurationSource; import org.openecomp.sdc.common.api.Constants; +import org.openecomp.sdc.common.api.exception.LoadConfigurationException; import org.openecomp.sdc.common.util.YamlToObjectConverter; +import org.openecomp.sdc.exception.YamlConversionException; /** * Read configuration from file system @@ -55,16 +57,21 @@ public class FSConfigurationSource implements ConfigurationSource { * * @see org.openecomp.sdc.common.api.ConfigurationSource#getAndWatchConfiguration (java.lang.Class, org.openecomp.sdc.common.api.ConfigurationListener) */ - public T getAndWatchConfiguration(Class className, ConfigurationListener configurationListener) { + public T getAndWatchConfiguration(final Class className, final ConfigurationListener configurationListener) { - String configFileName = calculateFileName(className); + final String configFileName = calculateFileName(className); - T object = yamlToObjectConverter.convert(this.appConfigDir, className, configFileName); + T object; + try { + object = yamlToObjectConverter.convert(this.appConfigDir, className, configFileName); + } catch (final YamlConversionException e) { + final String errorMsg = + String.format("Could not load '%s' in '%s' for class '%s'", configFileName, appConfigDir, className); + throw new LoadConfigurationException(errorMsg, e); + } if (configurationListener != null && changeListener != null) { - if (object != null) { - changeListener.register(configFileName, configurationListener); - } + changeListener.register(configFileName, configurationListener); } return object; diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/util/YamlToObjectConverter.java b/common-app-api/src/main/java/org/openecomp/sdc/common/util/YamlToObjectConverter.java index b2435de12c..756670c54a 100644 --- a/common-app-api/src/main/java/org/openecomp/sdc/common/util/YamlToObjectConverter.java +++ b/common-app-api/src/main/java/org/openecomp/sdc/common/util/YamlToObjectConverter.java @@ -20,8 +20,23 @@ package org.openecomp.sdc.common.util; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; import org.apache.commons.codec.binary.Base64; -import org.openecomp.sdc.be.config.Configuration.*; +import org.openecomp.sdc.be.config.Configuration.ApplicationL1CacheConfig; +import org.openecomp.sdc.be.config.Configuration.ApplicationL2CacheConfig; +import org.openecomp.sdc.be.config.Configuration.ArtifactTypeConfig; +import org.openecomp.sdc.be.config.Configuration.BeMonitoringConfig; +import org.openecomp.sdc.be.config.Configuration.EcompPortalConfig; +import org.openecomp.sdc.be.config.Configuration.OnboardingConfig; +import org.openecomp.sdc.be.config.Configuration.SwitchoverDetectorConfig; +import org.openecomp.sdc.be.config.Configuration.ToscaValidatorsConfig; import org.openecomp.sdc.be.config.DistributionEngineConfiguration; import org.openecomp.sdc.be.config.DistributionEngineConfiguration.ComponentArtifactTypesConfig; import org.openecomp.sdc.be.config.DistributionEngineConfiguration.CreateTopicConfig; @@ -30,21 +45,11 @@ import org.openecomp.sdc.be.config.DistributionEngineConfiguration.DistributionS import org.openecomp.sdc.be.config.validation.DeploymentArtifactHeatConfiguration; import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode; import org.openecomp.sdc.common.log.wrappers.Logger; +import org.openecomp.sdc.exception.YamlConversionException; import org.openecomp.sdc.fe.config.Configuration.FeMonitoringConfig; import org.yaml.snakeyaml.TypeDescription; import org.yaml.snakeyaml.Yaml; -import org.yaml.snakeyaml.error.YAMLException; import org.yaml.snakeyaml.introspector.PropertyUtils; -import org.yaml.snakeyaml.nodes.Node; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.HashMap; -import java.util.Map; public class YamlToObjectConverter { @@ -132,115 +137,51 @@ public class YamlToObjectConverter { return yaml; } - public T convert(String dirPath, Class className, String configFileName) { - - T config = null; - - try { - - String fullFileName = dirPath + File.separator + configFileName; - - config = convert(fullFileName, className); - - } catch (Exception e) { - log.error(EcompLoggerErrorCode.UNKNOWN_ERROR,"","","Failed to convert yaml file {} to object.", configFileName,e); + public T convert(final String dirPath, final Class className, + final String configFileName) throws YamlConversionException { + if (className == null) { + throw new IllegalArgumentException("className cannot be null"); } - - return config; + final String fullFileName = dirPath + File.separator + configFileName; + return convert(fullFileName, className); } - public class MyYamlConstructor extends org.yaml.snakeyaml.constructor.Constructor { - private HashMap> classMap = new HashMap<>(); - - public MyYamlConstructor(Class theRoot) { - super(theRoot); - classMap.put(DistributionEngineConfiguration.class.getName(), DistributionEngineConfiguration.class); - classMap.put(DistributionStatusTopicConfig.class.getName(), DistributionStatusTopicConfig.class); + public T convert(String fullFileName, Class className) throws YamlConversionException { + if (!new File(fullFileName).exists()) { + log.warn(EcompLoggerErrorCode.UNKNOWN_ERROR,"","", + "The file {} cannot be found. Ignore reading configuration.", fullFileName); + return null; } - /* - * This is a modified version of the Constructor. Rather than using a - * class loader to get external classes, they are already predefined - * above. This approach works similar to the typeTags structure in the - * original constructor, except that class information is pre-populated - * during initialization rather than runtime. - * - * @see - * org.yaml.snakeyaml.constructor.Constructor#getClassForNode(org.yaml. - * snakeyaml.nodes.Node) - */ - protected Class getClassForNode(Node node) { - String name = node.getTag().getClassName(); - Class cl = classMap.get(name); - if (cl == null) - throw new YAMLException("Class not found: " + name); - else - return cl; - } - } - - public T convert(String fullFileName, Class className) { - - T config = null; - - Yaml yaml = getYamlByClassName(className); - - InputStream in = null; - try { + final Yaml yaml = getYamlByClassName(className); - File f = new File(fullFileName); - if (!f.exists()) { - log.warn(EcompLoggerErrorCode.UNKNOWN_ERROR,"","","The file {} cannot be found. Ignore reading configuration.",fullFileName); - return null; - } - in = Files.newInputStream(Paths.get(fullFileName)); - - config = yaml.loadAs(in, className); - - // System.out.println(config.toString()); + try (final InputStream in = Files.newInputStream(Paths.get(fullFileName))) { + return yaml.loadAs(in, className); + } catch (final IOException e) { + log.debug("Failed to open/close input stream", e); } catch (Exception e) { - log.error(EcompLoggerErrorCode.UNKNOWN_ERROR,"","","Failed to convert yaml file {} to object.", fullFileName, e); - } finally { - if (in != null) { - try { - in.close(); - } catch (IOException e) { - log.debug("Failed to close input stream", e); - e.printStackTrace(); - } - } + log.error(EcompLoggerErrorCode.UNKNOWN_ERROR,"","", + "Failed to convert yaml file {} to object.", fullFileName, e); + final String errorMsg = String.format("Could not parse '%s' to class '%s'", fullFileName, className); + throw new YamlConversionException(errorMsg, e); } - return config; + return null; } public T convert(byte[] fileContents, Class className) { - - T config = null; - - Yaml yaml = getYamlByClassName(className); - - InputStream in = null; - try { - - in = new ByteArrayInputStream(fileContents); - - config = yaml.loadAs(in, className); - - } catch (Exception e) { - log.error(EcompLoggerErrorCode.UNKNOWN_ERROR,"","","Failed to convert yaml file to object", e); - } finally { - if (in != null) { - try { - in.close(); - } catch (IOException e) { - log.debug("Failed to close input stream", e); - e.printStackTrace(); - } - } + final Yaml yaml = getYamlByClassName(className); + + try (final InputStream in = new ByteArrayInputStream(fileContents)){ + return yaml.loadAs(in, className); + } catch (final IOException e) { + log.debug("Failed to open or close input stream", e); + } catch (final Exception e) { + log.error(EcompLoggerErrorCode.UNKNOWN_ERROR, + "","","Failed to convert yaml file to object", e); } - return config; + return null; } public boolean isValidYamlEncoded64(byte[] fileContents) { @@ -261,7 +202,8 @@ public class YamlToObjectConverter { } } catch (Exception e) { - log.error(EcompLoggerErrorCode.UNKNOWN_ERROR,"","","Failed to convert yaml file to object - yaml is invalid", e); + log.error(EcompLoggerErrorCode.UNKNOWN_ERROR,"","", + "Failed to convert yaml file to object - yaml is invalid", e); return false; } return true; diff --git a/common-app-api/src/main/java/org/openecomp/sdc/exception/YamlConversionException.java b/common-app-api/src/main/java/org/openecomp/sdc/exception/YamlConversionException.java new file mode 100644 index 0000000000..4d8791f15d --- /dev/null +++ b/common-app-api/src/main/java/org/openecomp/sdc/exception/YamlConversionException.java @@ -0,0 +1,27 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.exception; + +public class YamlConversionException extends Exception { + + public YamlConversionException(final String s, final Throwable throwable) { + super(s, throwable); + } +} diff --git a/common-app-api/src/test/java/org/openecomp/sdc/common/util/YamlToObjectConverterTest.java b/common-app-api/src/test/java/org/openecomp/sdc/common/util/YamlToObjectConverterTest.java index 49fc553302..35af78bd4e 100644 --- a/common-app-api/src/test/java/org/openecomp/sdc/common/util/YamlToObjectConverterTest.java +++ b/common-app-api/src/test/java/org/openecomp/sdc/common/util/YamlToObjectConverterTest.java @@ -29,6 +29,7 @@ import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Paths; +import org.openecomp.sdc.exception.YamlConversionException; import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.assertFalse; @@ -81,14 +82,14 @@ public class YamlToObjectConverterTest { } @Test - public void validateConvertWithFullFilePathReturnsValidObjectCreatedFromYaml() { + public void validateConvertWithFullFilePathReturnsValidObjectCreatedFromYaml() throws YamlConversionException { Configuration result = yamlToObjectConverter.convert(filePath+fileName, Configuration.class); assertThatCreatedObjectIsValid(result); } @Test - public void validateConvertWithFullFilePathReturnsNullIfFileDoesNotExist() { + public void validateConvertWithFullFilePathReturnsNullIfFileDoesNotExist() throws YamlConversionException { final String wrongFileName = "wrong-configuration.yaml"; Configuration result = yamlToObjectConverter.convert(wrongFileName, Configuration.class); @@ -96,28 +97,23 @@ public class YamlToObjectConverterTest { assertNull(result); } - @Test - public void validateConvertWithFullFilePathReturnsNullIfClassDoesNotMathYaml() { - - HttpClient result = yamlToObjectConverter.convert(filePath+fileName, HttpClient.class); - - assertNull(result); + @Test(expected = YamlConversionException.class) + public void validateConvertWithFullFilePathThrowsExceptionIfClassDoesNotMathYaml() throws YamlConversionException { + yamlToObjectConverter.convert(filePath + fileName, HttpClient.class); } @Test - public void validateConvertWithFilePathAndFileNameReturnsValidObjectCreatedFromYaml() { + public void validateConvertWithFilePathAndFileNameReturnsValidObjectCreatedFromYaml() + throws YamlConversionException { Configuration result = yamlToObjectConverter.convert(filePath, Configuration.class, fileName); assertThatCreatedObjectIsValid(result); } - @Test - public void validateConvertWithFilePathAndFileNameReturnsNullIfClassIsNull() { - - HttpClient result = yamlToObjectConverter.convert(filePath, null, fileName); - - assertNull(result); + @Test(expected = IllegalArgumentException.class) + public void validateConvertWithFilePathAndFileNameThrowsExceptionIfClassIsNull() throws YamlConversionException { + yamlToObjectConverter.convert(filePath, null, fileName); } @Test diff --git a/common-app-api/src/test/java/org/openecomp/sdc/fe/config/WorkspaceConfigurationTest.java b/common-app-api/src/test/java/org/openecomp/sdc/fe/config/WorkspaceConfigurationTest.java index dd1fe8b2be..08e9b34195 100644 --- a/common-app-api/src/test/java/org/openecomp/sdc/fe/config/WorkspaceConfigurationTest.java +++ b/common-app-api/src/test/java/org/openecomp/sdc/fe/config/WorkspaceConfigurationTest.java @@ -41,7 +41,7 @@ public class WorkspaceConfigurationTest { @Before public void setUp() { - String appConfigDir = "src/test/resources/config/common"; + String appConfigDir = "src/test/resources/config/fe"; ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir); configurationManager = new ConfigurationManager(configurationSource); diff --git a/common-app-api/src/test/resources/config/common/workspace-configuration.yaml b/common-app-api/src/test/resources/config/common/workspace-configuration.yaml deleted file mode 100644 index fd382592b7..0000000000 --- a/common-app-api/src/test/resources/config/common/workspace-configuration.yaml +++ /dev/null @@ -1,199 +0,0 @@ -workspaceMenuConfiguration: - VFC: - - text: General - action: onMenuItemPressed - state: workspace.general - - text: Deployment Artifact - action: onMenuItemPressed - state: workspace.deployment_artifacts - - text: Information Artifact - action: onMenuItemPressed - state: workspace.information_artifacts - - text: TOSCA Artifacts - action: onMenuItemPressed - state: workspace.tosca_artifacts - - text: Properties - action: onMenuItemPressed - state: workspace.properties - - text: Attributes - action: onMenuItemPressed - state: workspace.attributes - - text: Req. & Capabilities - action: onMenuItemPressed - state: workspace.reqAndCap - - text: Activity Log - action: onMenuItemPressed - state: workspace.activity_log - VL: - - text: General - action: onMenuItemPressed - state: workspace.general - - text: Deployment Artifact - action: onMenuItemPressed - state: workspace.deployment_artifacts - - text: Information Artifact - action: onMenuItemPressed - state: workspace.information_artifacts - - text: TOSCA Artifacts - action: onMenuItemPressed - state: workspace.tosca_artifacts - - text: Properties - action: onMenuItemPressed - state: workspace.properties - - text: Attributes - action: onMenuItemPressed - state: workspace.attributes - - text: Req. & Capabilities - action: onMenuItemPressed - state: workspace.reqAndCap - - text: Activity Log - action: onMenuItemPressed - state: workspace.activity_log - CP: - - text: General - action: onMenuItemPressed - state: workspace.general - - text: Deployment Artifact - action: onMenuItemPressed - state: workspace.deployment_artifacts - - text: Information Artifact - action: onMenuItemPressed - state: workspace.information_artifacts - - text: TOSCA Artifacts - action: onMenuItemPressed - state: workspace.tosca_artifacts - - text: Properties - action: onMenuItemPressed - state: workspace.properties - - text: Attributes - action: onMenuItemPressed - state: workspace.attributes - - text: Req. & Capabilities - action: onMenuItemPressed - state: workspace.reqAndCap - - text: Activity Log - action: onMenuItemPressed - state: workspace.activity_log - VF: - - text: General - action: onMenuItemPressed - state: workspace.general - - text: Deployment Artifact - action: onMenuItemPressed - state: workspace.deployment_artifacts - - text: Information Artifact - action: onMenuItemPressed - state: workspace.information_artifacts - - text: TOSCA Artifacts - action: onMenuItemPressed - state: workspace.tosca_artifacts - - text: Composition - action: onMenuItemPressed - state: workspace.composition.details - - text: Operation - action: onMenuItemPressed - state: workspace.interface_operation - - text: Activity Log - action: onMenuItemPressed - state: workspace.activity_log - - text: Deployment - action: onMenuItemPressed - state: workspace.deployment - - text: Properties Assignment - action: onMenuItemPressed - state: workspace.properties_assignment - - text: Req. & Capabilities - action: onMenuItemPressed - state: workspace.reqAndCapEditable - PNF: - - text: General - action: onMenuItemPressed - state: workspace.general - - text: Deployment Artifact - action: onMenuItemPressed - state: workspace.deployment_artifacts - - text: Information Artifact - action: onMenuItemPressed - state: workspace.information_artifacts - - text: TOSCA Artifacts - action: onMenuItemPressed - state: workspace.tosca_artifacts - - text: Composition - action: onMenuItemPressed - state: workspace.composition.details - - text: Operation - action: onMenuItemPressed - state: workspace.interface_operation - - text: Activity Log - action: onMenuItemPressed - state: workspace.activity_log - - text: Properties Assignment - action: onMenuItemPressed - state: workspace.properties_assignment - - text: Req. & Capabilities - action: onMenuItemPressed - state: workspace.reqAndCapEditable - CR: - - text: General - action: onMenuItemPressed - state: workspace.general - - text: Deployment Artifact - action: onMenuItemPressed - state: workspace.deployment_artifacts - - text: Information Artifact - action: onMenuItemPressed - state: workspace.information_artifacts - - text: TOSCA Artifacts - action: onMenuItemPressed - state: workspace.tosca_artifacts - - text: Composition - action: onMenuItemPressed - state: workspace.composition.details - - text: Activity Log - action: onMenuItemPressed - state: workspace.activity_log - - text: Properties Assignment - action: onMenuItemPressed - state: workspace.properties_assignment - SERVICE: - - text: General - action: onMenuItemPressed - state: workspace.general - - text: TOSCA Artifacts - action: onMenuItemPressed - state: workspace.tosca_artifacts - - text: Composition - action: onMenuItemPressed - state: workspace.composition.details - - text: Operation - action: onMenuItemPressed - state: workspace.interface_operation - - text: Activity Log - action: onMenuItemPressed - state: workspace.activity_log - - text: Management Workflow - action: onMenuItemPressed - state: workspace.management_workflow - - text: 'Network Call Flow ' - action: onMenuItemPressed - state: workspace.network_call_flow - - text: Distribution - action: onMenuItemPressed - state: workspace.distribution - disabledRoles: - - ADMIN - - TESTER - - GOVERNOR - - DESIGNER - - text: Deployment - action: onMenuItemPressed - state: workspace.deployment - - text: Properties Assignment - action: onMenuItemPressed - state: workspace.properties_assignment - - text: Outputs - action: onMenuItemPressed - state: workspace.outputs_assignment - - text: Req. & Capabilities - action: onMenuItemPressed - state: workspace.reqAndCapEditable diff --git a/common-app-api/src/test/resources/config/fe/workspace-configuration.yaml b/common-app-api/src/test/resources/config/fe/workspace-configuration.yaml new file mode 100644 index 0000000000..fd382592b7 --- /dev/null +++ b/common-app-api/src/test/resources/config/fe/workspace-configuration.yaml @@ -0,0 +1,199 @@ +workspaceMenuConfiguration: + VFC: + - text: General + action: onMenuItemPressed + state: workspace.general + - text: Deployment Artifact + action: onMenuItemPressed + state: workspace.deployment_artifacts + - text: Information Artifact + action: onMenuItemPressed + state: workspace.information_artifacts + - text: TOSCA Artifacts + action: onMenuItemPressed + state: workspace.tosca_artifacts + - text: Properties + action: onMenuItemPressed + state: workspace.properties + - text: Attributes + action: onMenuItemPressed + state: workspace.attributes + - text: Req. & Capabilities + action: onMenuItemPressed + state: workspace.reqAndCap + - text: Activity Log + action: onMenuItemPressed + state: workspace.activity_log + VL: + - text: General + action: onMenuItemPressed + state: workspace.general + - text: Deployment Artifact + action: onMenuItemPressed + state: workspace.deployment_artifacts + - text: Information Artifact + action: onMenuItemPressed + state: workspace.information_artifacts + - text: TOSCA Artifacts + action: onMenuItemPressed + state: workspace.tosca_artifacts + - text: Properties + action: onMenuItemPressed + state: workspace.properties + - text: Attributes + action: onMenuItemPressed + state: workspace.attributes + - text: Req. & Capabilities + action: onMenuItemPressed + state: workspace.reqAndCap + - text: Activity Log + action: onMenuItemPressed + state: workspace.activity_log + CP: + - text: General + action: onMenuItemPressed + state: workspace.general + - text: Deployment Artifact + action: onMenuItemPressed + state: workspace.deployment_artifacts + - text: Information Artifact + action: onMenuItemPressed + state: workspace.information_artifacts + - text: TOSCA Artifacts + action: onMenuItemPressed + state: workspace.tosca_artifacts + - text: Properties + action: onMenuItemPressed + state: workspace.properties + - text: Attributes + action: onMenuItemPressed + state: workspace.attributes + - text: Req. & Capabilities + action: onMenuItemPressed + state: workspace.reqAndCap + - text: Activity Log + action: onMenuItemPressed + state: workspace.activity_log + VF: + - text: General + action: onMenuItemPressed + state: workspace.general + - text: Deployment Artifact + action: onMenuItemPressed + state: workspace.deployment_artifacts + - text: Information Artifact + action: onMenuItemPressed + state: workspace.information_artifacts + - text: TOSCA Artifacts + action: onMenuItemPressed + state: workspace.tosca_artifacts + - text: Composition + action: onMenuItemPressed + state: workspace.composition.details + - text: Operation + action: onMenuItemPressed + state: workspace.interface_operation + - text: Activity Log + action: onMenuItemPressed + state: workspace.activity_log + - text: Deployment + action: onMenuItemPressed + state: workspace.deployment + - text: Properties Assignment + action: onMenuItemPressed + state: workspace.properties_assignment + - text: Req. & Capabilities + action: onMenuItemPressed + state: workspace.reqAndCapEditable + PNF: + - text: General + action: onMenuItemPressed + state: workspace.general + - text: Deployment Artifact + action: onMenuItemPressed + state: workspace.deployment_artifacts + - text: Information Artifact + action: onMenuItemPressed + state: workspace.information_artifacts + - text: TOSCA Artifacts + action: onMenuItemPressed + state: workspace.tosca_artifacts + - text: Composition + action: onMenuItemPressed + state: workspace.composition.details + - text: Operation + action: onMenuItemPressed + state: workspace.interface_operation + - text: Activity Log + action: onMenuItemPressed + state: workspace.activity_log + - text: Properties Assignment + action: onMenuItemPressed + state: workspace.properties_assignment + - text: Req. & Capabilities + action: onMenuItemPressed + state: workspace.reqAndCapEditable + CR: + - text: General + action: onMenuItemPressed + state: workspace.general + - text: Deployment Artifact + action: onMenuItemPressed + state: workspace.deployment_artifacts + - text: Information Artifact + action: onMenuItemPressed + state: workspace.information_artifacts + - text: TOSCA Artifacts + action: onMenuItemPressed + state: workspace.tosca_artifacts + - text: Composition + action: onMenuItemPressed + state: workspace.composition.details + - text: Activity Log + action: onMenuItemPressed + state: workspace.activity_log + - text: Properties Assignment + action: onMenuItemPressed + state: workspace.properties_assignment + SERVICE: + - text: General + action: onMenuItemPressed + state: workspace.general + - text: TOSCA Artifacts + action: onMenuItemPressed + state: workspace.tosca_artifacts + - text: Composition + action: onMenuItemPressed + state: workspace.composition.details + - text: Operation + action: onMenuItemPressed + state: workspace.interface_operation + - text: Activity Log + action: onMenuItemPressed + state: workspace.activity_log + - text: Management Workflow + action: onMenuItemPressed + state: workspace.management_workflow + - text: 'Network Call Flow ' + action: onMenuItemPressed + state: workspace.network_call_flow + - text: Distribution + action: onMenuItemPressed + state: workspace.distribution + disabledRoles: + - ADMIN + - TESTER + - GOVERNOR + - DESIGNER + - text: Deployment + action: onMenuItemPressed + state: workspace.deployment + - text: Properties Assignment + action: onMenuItemPressed + state: workspace.properties_assignment + - text: Outputs + action: onMenuItemPressed + state: workspace.outputs_assignment + - text: Req. & Capabilities + action: onMenuItemPressed + state: workspace.reqAndCapEditable -- cgit 1.2.3-korg