summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/openecomp/sdc/tosca/parser/config/ConfigurationManager.java3
-rw-r--r--src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorInfo.java10
-rw-r--r--src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java59
-rw-r--r--src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java2
-rw-r--r--src/main/resources/config/error-configuration.yaml6
-rw-r--r--src/test/java/org/openecomp/sdc/impl/ToscaParserConfigurationTest.java20
-rw-r--r--src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java30
-rw-r--r--src/test/resources/config/error-configuration-test.yaml22
-rw-r--r--src/test/resources/config/error-configuration.yaml4
-rw-r--r--src/test/resources/csars/service-missing-csar-meta-file.csarbin0 -> 45132 bytes
10 files changed, 135 insertions, 21 deletions
diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/config/ConfigurationManager.java b/src/main/java/org/openecomp/sdc/tosca/parser/config/ConfigurationManager.java
index 72c06ed..f2fc903 100644
--- a/src/main/java/org/openecomp/sdc/tosca/parser/config/ConfigurationManager.java
+++ b/src/main/java/org/openecomp/sdc/tosca/parser/config/ConfigurationManager.java
@@ -118,4 +118,7 @@ public class ConfigurationManager {
public Configuration getConfiguration() {
return (Configuration) configurations.get((Configuration.class.getSimpleName()));
}
+ public void setErrorConfiguration(String fileName) {
+ loadConfigurationClass(ErrorConfiguration.class, fileName);
+ }
}
diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorInfo.java b/src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorInfo.java
index 01df115..34983ef 100644
--- a/src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorInfo.java
+++ b/src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorInfo.java
@@ -24,6 +24,7 @@ public class ErrorInfo {
private String code;
private String message;
+ private boolean failOnError;
public String getCode() {
return code;
@@ -40,10 +41,19 @@ public class ErrorInfo {
public void setMessage(String message) {
this.message = message;
}
+
+ public boolean getFailOnError() {
+ return failOnError;
+ }
+
+ public void setFailOnError(boolean failOnError) {
+ this.failOnError = failOnError;
+ }
public void cloneData(ErrorInfo other) {
this.code = other.getCode();
this.message = other.getMessage();
+ this.failOnError = other.getFailOnError();
}
}
diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java
index 7b94000..901b315 100644
--- a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java
+++ b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java
@@ -27,6 +27,7 @@ import java.util.stream.Collectors;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.openecomp.sdc.tosca.parser.config.ConfigurationManager;
import org.openecomp.sdc.toscaparser.api.CapabilityAssignments;
import org.openecomp.sdc.tosca.parser.utils.GeneralUtility;
import org.openecomp.sdc.toscaparser.api.RequirementAssignments;
@@ -46,12 +47,18 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
private static final String PATH_DELIMITER = "#";
private static final String CUSTOMIZATION_UUID = "customizationUUID";
private ToscaTemplate toscaTemplate;
+ private ConfigurationManager configurationManager;
private static Logger log = LoggerFactory.getLogger(SdcCsarHelperImpl.class.getName());
public SdcCsarHelperImpl(ToscaTemplate toscaTemplate) {
this.toscaTemplate = toscaTemplate;
}
+ public SdcCsarHelperImpl(ToscaTemplate toscaTemplate, ConfigurationManager configurationManager) {
+ this.toscaTemplate = toscaTemplate;
+ this.configurationManager = configurationManager;
+ }
+
@Override
//Sunny flow - covered with UT, flat and nested
public String getNodeTemplatePropertyLeafValue(NodeTemplate nodeTemplate, String leafValuePath) {
@@ -579,24 +586,40 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
return nodeTemplate.getTypeDefinition().getType();
}
- @Override
- public String getConformanceLevel() {
- LinkedHashMap<String, Object> csarMeta = toscaTemplate.getMetaProperties("csar.meta");
- if (csarMeta == null){
- log.warn("No csar.meta file is found in CSAR - this file should hold the conformance level of the CSAR. This might be OK for older CSARs.");
- return null;
- }
-
- Object conformanceLevel = csarMeta.get("SDC-TOSCA-Definitions-Version");
- if (conformanceLevel != null){
- String confLevelStr = conformanceLevel.toString();
- log.debug("CSAR conformance level is {}", confLevelStr);
- return confLevelStr;
- } else {
- log.error("Invalid csar.meta file - no entry found for SDC-TOSCA-Definitions-Version key. This entry should hold the conformance level.");
- return null;
- }
- }
+ /**
+ * This methdd is returning the csarConformanceLevel for input CSAR
+ * When csarConformanceLevel is configured with failOnError as False in Error Configuration; it
+ * assigns the default value to csarConformanceLevel which is the max level provided in
+ * Configuration file
+ * @return csarConformanceLevel
+ */
+ @Override
+ public String getConformanceLevel() {
+ LinkedHashMap<String, Object> csarMeta = toscaTemplate.getMetaProperties("csar.meta");
+ if (csarMeta == null){
+ log.warn("No csar.meta file is found in CSAR - this file should hold the conformance level of the CSAR. This might be OK for older CSARs.");
+ if (configurationManager != null && !configurationManager.getErrorConfiguration()
+ .getErrorInfo("CONFORMANCE_LEVEL_ERROR").getFailOnError()){
+ String csarConLevel = configurationManager.getConfiguration().getConformanceLevel().getMaxVersion();
+ log.warn("csarConformanceLevel is not found in input csar; defaulting to max version {}" , csarConLevel);
+ return csarConLevel;
+ }
+ else {
+ log.warn("csarConformanceLevel is not found in input csar; returning null as no defaults defined in error configuration");
+ return null;
+ }
+ }
+
+ Object conformanceLevel = csarMeta.get("SDC-TOSCA-Definitions-Version");
+ if (conformanceLevel != null){
+ String confLevelStr = conformanceLevel.toString();
+ log.debug("CSAR conformance level is {}", confLevelStr);
+ return confLevelStr;
+ } else {
+ log.error("Invalid csar.meta file - no entry found for SDC-TOSCA-Definitions-Version key. This entry should hold the conformance level.");
+ return null;
+ }
+ }
@Override
diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java
index f1a03b7..9fc59f2 100644
--- a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java
+++ b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java
@@ -77,7 +77,7 @@ public class SdcToscaParserFactory {
} catch (JToscaException e) {
throwSdcToscaParserException(e);
}
- SdcCsarHelperImpl sdcCsarHelperImpl = new SdcCsarHelperImpl(tosca);
+ SdcCsarHelperImpl sdcCsarHelperImpl = new SdcCsarHelperImpl(tosca, configurationManager);
String cSarConformanceLevel = sdcCsarHelperImpl.getConformanceLevel();
validateCsarVersion(cSarConformanceLevel);
try {
diff --git a/src/main/resources/config/error-configuration.yaml b/src/main/resources/config/error-configuration.yaml
index 3febd33..58d1de3 100644
--- a/src/main/resources/config/error-configuration.yaml
+++ b/src/main/resources/config/error-configuration.yaml
@@ -2,17 +2,21 @@
errors:
FILE_NOT_FOUND: {
code: TP0001,
+ failOnError: true,
message: "Error: CSAR file not found."
}
BAD_FORMAT: {
code: TP0002,
+ failOnError: true,
message: "Error: CSAR file bad format. Check the log for details."
}
CONFORMANCE_LEVEL_ERROR: {
code: TP0003,
+ failOnError: true,
message: "Error: CSAR version is unsupported. Parser supports versions %s to %s."
}
GENERAL_ERROR: {
code: TP0004,
+ failOnError: true,
message: "Error: an unexpected internal error occured."
- } \ No newline at end of file
+ }
diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserConfigurationTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserConfigurationTest.java
index 8c96303..b815064 100644
--- a/src/test/java/org/openecomp/sdc/impl/ToscaParserConfigurationTest.java
+++ b/src/test/java/org/openecomp/sdc/impl/ToscaParserConfigurationTest.java
@@ -1,12 +1,14 @@
package org.openecomp.sdc.impl;
import org.openecomp.sdc.tosca.parser.config.ErrorConfiguration;
+import org.openecomp.sdc.tosca.parser.config.JtoscaValidationIssueConfiguration;
import org.testng.annotations.Test;
import org.openecomp.sdc.tosca.parser.config.Configuration;
import org.openecomp.sdc.tosca.parser.config.ConfigurationManager;
import java.io.IOException;
+import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
public class ToscaParserConfigurationTest extends SdcToscaParserBasicTest {
@@ -28,4 +30,22 @@ public class ToscaParserConfigurationTest extends SdcToscaParserBasicTest {
assertNotNull(errorConfig.getErrors());
}
+ @Test
+ public void testSetErrorConfiguration() throws IOException {
+ ConfigurationManager configurationManager = ConfigurationManager.getInstance();
+ configurationManager.setErrorConfiguration("error-configuration-test.yaml");
+ ErrorConfiguration errorConfig = configurationManager.getErrorConfiguration();
+ assertEquals(false, errorConfig.getErrorInfo("CONFORMANCE_LEVEL_ERROR").getFailOnError());
+ assertEquals(true, errorConfig.getErrorInfo("FILE_NOT_FOUND").getFailOnError());
+ }
+
+ @Test
+ public void testSetJtoscaValidationIssueConfiguration() throws IOException {
+ ConfigurationManager configurationManager = ConfigurationManager.getInstance();
+ configurationManager.setJtoscaValidationIssueConfiguration(
+ "jtosca-validation-issue-configuration-test.yaml");
+ JtoscaValidationIssueConfiguration issueConfig = configurationManager
+ .getJtoscaValidationIssueConfiguration();
+ assertNotNull(issueConfig);
+ }
}
diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java
index 4e5c9bc..65c013a 100644
--- a/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java
+++ b/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java
@@ -1,8 +1,11 @@
package org.openecomp.sdc.impl;
+import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.openecomp.sdc.tosca.parser.config.ConfigurationManager;
+import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
import org.openecomp.sdc.toscaparser.api.NodeTemplate;
-import org.testng.annotations.Test;
import org.openecomp.sdc.toscaparser.api.elements.Metadata;
+import org.testng.annotations.Test;
import java.util.List;
import java.util.Map;
@@ -187,5 +190,30 @@ public class ToscaParserMetadataTest extends SdcToscaParserBasicTest {
assertEquals(serviceEcompNaming, "true");
}
//endregion
+
+ @Test
+ public void testCSARMissingConformanceLevelWithCustomErrorConfig() throws
+ SdcToscaParserException {
+ ConfigurationManager configurationManager = ConfigurationManager.getInstance();
+ configurationManager.setErrorConfiguration("error-configuration-test.yaml");
+ factory.setConfigurationManager(configurationManager);
+
+ ISdcCsarHelper missingCSARMetaCsarCustomConfig = getCsarHelper
+ ("csars/service-missing-csar-meta-file.csar");
+ String conformanceLevel = missingCSARMetaCsarCustomConfig.getConformanceLevel();
+ assertNotNull(conformanceLevel);
+ assertEquals(conformanceLevel, configurationManager.getConfiguration().getConformanceLevel()
+ .getMaxVersion());
+
+ configurationManager.setErrorConfiguration("error-configuration.yaml");
+ factory.setConfigurationManager(configurationManager);
+ }
+
+ @Test(expectedExceptions = SdcToscaParserException.class)
+ public void testCSARMissingConformanceLevelWithDefaultErrorConfig() throws
+ SdcToscaParserException {
+ ISdcCsarHelper missingCSARMetaCsarDefaultConfig = getCsarHelper("csars/service-missing-csar-meta-file.csar");
+ missingCSARMetaCsarDefaultConfig.getConformanceLevel();
+ }
}
diff --git a/src/test/resources/config/error-configuration-test.yaml b/src/test/resources/config/error-configuration-test.yaml
new file mode 100644
index 0000000..f5c20aa
--- /dev/null
+++ b/src/test/resources/config/error-configuration-test.yaml
@@ -0,0 +1,22 @@
+# Errors
+errors:
+ FILE_NOT_FOUND: {
+ code: TP0001,
+ failOnError: true,
+ message: "Error: CSAR file not found."
+ }
+ BAD_FORMAT: {
+ code: TP0002,
+ failOnError: true,
+ message: "Error: CSAR file bad format. Check the log for details."
+ }
+ CONFORMANCE_LEVEL_ERROR: {
+ code: TP0003,
+ failOnError: false,
+ message: "Error: CSAR version is unsupported. Parser supports versions %s to %s."
+ }
+ GENERAL_ERROR: {
+ code: TP0004,
+ failOnError: true,
+ message: "Error: an unexpected internal error occured."
+ } \ No newline at end of file
diff --git a/src/test/resources/config/error-configuration.yaml b/src/test/resources/config/error-configuration.yaml
index 3febd33..44173cd 100644
--- a/src/test/resources/config/error-configuration.yaml
+++ b/src/test/resources/config/error-configuration.yaml
@@ -2,17 +2,21 @@
errors:
FILE_NOT_FOUND: {
code: TP0001,
+ failOnError: true,
message: "Error: CSAR file not found."
}
BAD_FORMAT: {
code: TP0002,
+ failOnError: true,
message: "Error: CSAR file bad format. Check the log for details."
}
CONFORMANCE_LEVEL_ERROR: {
code: TP0003,
+ failOnError: true,
message: "Error: CSAR version is unsupported. Parser supports versions %s to %s."
}
GENERAL_ERROR: {
code: TP0004,
+ failOnError: true,
message: "Error: an unexpected internal error occured."
} \ No newline at end of file
diff --git a/src/test/resources/csars/service-missing-csar-meta-file.csar b/src/test/resources/csars/service-missing-csar-meta-file.csar
new file mode 100644
index 0000000..7c75314
--- /dev/null
+++ b/src/test/resources/csars/service-missing-csar-meta-file.csar
Binary files differ