--- /dev/null
+.. This work is licensed under a Creative Commons Attribution 4.0 International License.
+
+TODO Add files to toctree and delete this header
+------------------------------------------------
+.. toctree::
+ :maxdepth: 1
+
+
<artifactId>sdc-tosca</artifactId>\r
<name>sdc-sdc-tosca</name>\r
<description>SDC Tosca Parser JAR file for use by consumers</description>\r
- <version>1.1.51-SNAPSHOT</version>\r
+ <version>1.1.53-SNAPSHOT</version>\r
<packaging>jar</packaging>\r
\r
<properties>\r
<version>21.0</version>\r
<scope>compile</scope>\r
</dependency>\r
+ <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->\r
+ <dependency>\r
+ <groupId>com.fasterxml.jackson.core</groupId>\r
+ <artifactId>jackson-databind</artifactId>\r
+ <version>2.0.2</version>\r
+ </dependency>\r
\r
<!-- jtosca Tosca Parser -->\r
<dependency>\r
<groupId>org.openecomp.sdc.jtosca</groupId>\r
<artifactId>jtosca</artifactId>\r
- <version>1.1.10-SNAPSHOT</version>\r
+ <version>1.1.13-SNAPSHOT</version>\r
</dependency>\r
\r
\r
private void initialConfigObjectsFromFiles() {
loadConfigurationClass(ErrorConfiguration.class);
loadConfigurationClass(Configuration.class);
+ loadConfigurationClass(JtoscaValidationIssueConfiguration.class);
}
private <T> void loadConfigurationClass(Class<T> clazz) {
public static ConfigurationManager getInstance() {
- if (instance == null) {
- synchronized (ConfigurationManager.class) {
- if (instance == null) {
+ // if (instance == null) {
+ // synchronized (ConfigurationManager.class) {
+ // if (instance == null) {
instance = new ConfigurationManager();
- }
- }
- }
+ // }
+ // }
+ // }
return instance;
}
public ErrorConfiguration getErrorConfiguration() {
return (ErrorConfiguration) configurations.get((ErrorConfiguration.class.getSimpleName()));
}
+ public JtoscaValidationIssueConfiguration getJtoscaValidationIssueConfiguration() {
+ return (JtoscaValidationIssueConfiguration) configurations.get((JtoscaValidationIssueConfiguration.class.getSimpleName()));
+ }
public Configuration getConfiguration() {
return (Configuration) configurations.get((Configuration.class.getSimpleName()));
--- /dev/null
+package org.openecomp.sdc.tosca.parser.config;
+
+public class JToscaValidationIssueInfo {
+
+ private String issueType;
+ private String sinceCsarConformanceLevel;
+
+ public JToscaValidationIssueInfo() {}
+
+ public String getIssueType() {
+ return issueType;
+ }
+
+ public void setIssueType(String issueType) {
+ this.issueType = issueType;
+ }
+
+ public String getSinceCsarConformanceLevel() {
+ return sinceCsarConformanceLevel;
+ }
+
+ public void setSinceCsarConformanceLevel(String sinceCsarConformanceLevel) {
+ this.sinceCsarConformanceLevel = sinceCsarConformanceLevel;
+ }
+
+ public void cloneData(JToscaValidationIssueInfo other) {
+ this.issueType = other.getIssueType();
+ this.sinceCsarConformanceLevel = other.getSinceCsarConformanceLevel();
+ }
+
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.tosca.parser.config;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class JtoscaValidationIssueConfiguration {
+
+ private Map<String, List<JToscaValidationIssueInfo>> validationIssues;
+
+ public Map<String, List<JToscaValidationIssueInfo>> getValidationIssues() {
+ return validationIssues;
+ }
+
+ public void setValidationIssues(Map<String, List<JToscaValidationIssueInfo>> validationIssues) {
+ this.validationIssues = validationIssues;
+ }
+
+ public List<JToscaValidationIssueInfo> getJtoscaValidationIssueInfo(String key) {
+ List<JToscaValidationIssueInfo> clone = new ArrayList<>();
+ List<JToscaValidationIssueInfo> other = validationIssues.get(key);
+ if (other != null) {
+ for (JToscaValidationIssueInfo item: other) {
+ JToscaValidationIssueInfo cloneitem = new JToscaValidationIssueInfo();
+ cloneitem.cloneData(item);
+ clone.add(cloneitem);
+ }
+ }
+ return clone;
+ }
+
+}
--- /dev/null
+package org.openecomp.sdc.tosca.parser.impl;
+
+public enum JToscaValidationIssueType {
+ CRITICAL,
+ WARNING
+}
package org.openecomp.sdc.tosca.parser.impl;\r
\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
import org.openecomp.sdc.tosca.parser.api.ConformanceLevel;\r
import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;\r
import org.openecomp.sdc.tosca.parser.config.*;\r
import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;\r
import org.openecomp.sdc.tosca.parser.utils.GeneralUtility;\r
import org.openecomp.sdc.toscaparser.api.ToscaTemplate;\r
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;\r
import org.openecomp.sdc.toscaparser.api.common.JToscaException;\r
import org.openecomp.sdc.toscaparser.api.utils.JToscaErrorCodes;\r
+import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
\r
public class SdcToscaParserFactory {\r
-\r
+ private static Logger log = LoggerFactory.getLogger(SdcToscaParserFactory.class.getName());\r
+ \r
private static volatile SdcToscaParserFactory instance;\r
private static Configuration configuration;\r
private static ErrorConfiguration errorConfiguration;\r
-\r
+ private static JtoscaValidationIssueConfiguration jtoscaValidationIssueConfiguration;\r
+ private List<JToscaValidationIssue> criticalExceptions = new ArrayList<>();\r
+ private List<JToscaValidationIssue> warningExceptions = new ArrayList<>();\r
+ private List<JToscaValidationIssue> notAnalyzadExceptions = new ArrayList<>();\r
private SdcToscaParserFactory() {\r
\r
}\r
instance = new SdcToscaParserFactory();\r
configuration = ConfigurationManager.getInstance().getConfiguration();\r
errorConfiguration = ConfigurationManager.getInstance().getErrorConfiguration();\r
+ jtoscaValidationIssueConfiguration = ConfigurationManager.getInstance().getJtoscaValidationIssueConfiguration();\r
}\r
}\r
}\r
throwSdcToscaParserException(e);\r
}\r
SdcCsarHelperImpl sdcCsarHelperImpl = new SdcCsarHelperImpl(tosca);\r
- validateCsarVersion(sdcCsarHelperImpl.getConformanceLevel());\r
+ String cSarConformanceLevel = sdcCsarHelperImpl.getConformanceLevel();\r
+ validateCsarVersion(cSarConformanceLevel);\r
+ try {\r
+ handleErrorsByTypes(csarPath, cSarConformanceLevel);\r
+ } catch (JToscaException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ }\r
return sdcCsarHelperImpl;\r
}\r
}\r
\r
- private void validateCsarVersion(String cSarVersion) throws SdcToscaParserException {\r
+ private void handleErrorsByTypes(String csarPath, String cSarConformanceLevel) throws JToscaException {\r
+ clearValidationIssuesLists();\r
+ for(JToscaValidationIssue toscaValidationIssue : ThreadLocalsHolder.getCollector().getValidationIssues().values()){\r
+ List<JToscaValidationIssueInfo> issueInfos = jtoscaValidationIssueConfiguration.getValidationIssues().get(toscaValidationIssue.getCode());\r
+ if(issueInfos != null && !issueInfos.isEmpty()){\r
+ JToscaValidationIssueInfo issueInfo = null;\r
+ issueInfo = issueInfos.stream()\r
+ .filter(i-> isMatchConformanceLevel(cSarConformanceLevel,i.getSinceCsarConformanceLevel()))\r
+ .max((i1,i2) -> GeneralUtility.conformanceLevelCompare(i1.getSinceCsarConformanceLevel(), i2.getSinceCsarConformanceLevel()) )\r
+ .orElse(null);\r
+\r
+ if(issueInfo != null){\r
+ switch (JToscaValidationIssueType.valueOf(issueInfo.getIssueType())) {\r
+ case CRITICAL:\r
+ criticalExceptions.add(toscaValidationIssue);\r
+ break;\r
+ case WARNING:\r
+ warningExceptions.add(toscaValidationIssue);\r
+ break;\r
+ default:\r
+ break;\r
+ }\r
+ }else{\r
+ notAnalyzadExceptions.add(toscaValidationIssue);\r
+ }\r
+ }else{//notAnalyzed\r
+ notAnalyzadExceptions.add(toscaValidationIssue);\r
+ }\r
+ }\r
+ logErrors(csarPath);\r
+ }\r
+\r
+ private void clearValidationIssuesLists(){\r
+ notAnalyzadExceptions.clear();\r
+ criticalExceptions.clear();\r
+ warningExceptions.clear();\r
+ }\r
+\r
+ private void logErrors(String inputPath) throws JToscaException{\r
+ //Warnings\r
+ int warningsCount = warningExceptions.size();\r
+ if (warningsCount > 0) {\r
+ log.warn("####################################################################################################");\r
+ log.warn("CSAR Warnings found! CSAR name - {}", inputPath);\r
+ log.warn("ToscaTemplate - verifyTemplate - {} Parsing Warning{} occurred...", warningsCount, (warningsCount > 1 ? "s" : ""));\r
+ for (JToscaValidationIssue info : warningExceptions) {\r
+ log.warn("JTosca Exception [{}]: {}. CSAR name - {}", info.getCode(),info.getMessage(), inputPath);\r
+ }\r
+ log.warn("####################################################################################################");\r
+ }\r
+ //Criticals\r
+ int criticalsCount = criticalExceptions.size();\r
+ if (criticalsCount > 0) {\r
+ log.error("####################################################################################################");\r
+ log.error("ToscaTemplate - verifyTemplate - {} Parsing Critical{} occurred...", criticalsCount, (criticalsCount > 1 ? "s" : ""));\r
+ for (JToscaValidationIssue info : criticalExceptions) {\r
+ log.error("JTosca Exception [{}]: {}. CSAR name - {}", info.getCode(),info.getMessage(), inputPath);\r
+ }\r
+ throw new JToscaException(String.format("CSAR Validation Failed. CSAR name - {}. Please check logs for details.", inputPath), JToscaErrorCodes.CSAR_TOSCA_VALIDATION_ERROR.getValue());\r
+ }\r
+ }\r
+ public List<JToscaValidationIssue> getCriticalExceptions() {\r
+ return criticalExceptions;\r
+ }\r
+\r
+ public List<JToscaValidationIssue> getWarningExceptions() {\r
+ return warningExceptions;\r
+ }\r
+\r
+ public List<JToscaValidationIssue> getNotAnalyzadExceptions() {\r
+ return notAnalyzadExceptions;\r
+ }\r
+\r
+\r
+ private void validateCsarVersion(String cSarVersion) throws SdcToscaParserException {\r
ConformanceLevel level = configuration.getConformanceLevel();\r
String minVersion = level.getMinVersion();\r
String maxVersion = level.getMaxVersion();\r
}\r
}\r
\r
+ private boolean isMatchConformanceLevel(String ValidationIssueVersion, String cSarVersion){\r
+ if (ValidationIssueVersion != null && cSarVersion != null) {\r
+ if ((GeneralUtility.conformanceLevelCompare(ValidationIssueVersion, cSarVersion) >= 0)) {\r
+ return true;\r
+ }\r
+ }\r
+ return false;\r
+ }\r
private void throwConformanceLevelException(String minVersion, String maxVersion) throws SdcToscaParserException {\r
ErrorInfo errorInfo = errorConfiguration.getErrorInfo(SdcToscaParserErrors.CONFORMANCE_LEVEL_ERROR.toString());\r
throw new SdcToscaParserException(String.format(errorInfo.getMessage(), minVersion, maxVersion), errorInfo.getCode());\r
ErrorInfo errorInfo = errorConfiguration.getErrorInfo(SdcToscaParserErrors.getSdcErrorByJToscaError(JToscaErrorCodes.getByCode(e.getCode())).toString());\r
throw new SdcToscaParserException(errorInfo.getMessage(), errorInfo.getCode());\r
}\r
+\r
}
\ No newline at end of file
package org.openecomp.sdc.tosca.parser.utils;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;
public <T> T convertFromString(String yamlContents, Class<T> className) {
T config = null;
-
- Yaml yaml = getYamlByClassName(className);
-
+ Yaml yaml = new Yaml();
try {
- config = yaml.loadAs(yamlContents, className);
+ Object data = yaml.load(yamlContents);
+ // convert it manually with jackson instead of using snakeyaml auto converter,
+ // because of problematic complex objects like JtoscaValidationIssueConfiguration
+ ObjectMapper mapper = new ObjectMapper();
+ config = mapper.convertValue(data, className);
} catch (Exception e){
log.error("Failed to convert YAML {} to object." , yamlContents, e);
}
--- /dev/null
+# jTosca validation issues
+#by error code, type the validation issue to be CRITICAL/WARNING
+# since Conformance level considered to this type. for example:
+#JE001:
+# - issueType: WARNING
+# sinceCsarConformanceLevel: 3.0
+# - issueType: WARNING
+# sinceCsarConformanceLevel: 5.0
+validationIssues:
+ # TypeMismatchError
+ JE001:
+ - issueType: WARNING
+ sinceCsarConformanceLevel: 3.0
+ # MissingType
+ JE002:
+ - issueType: WARNING
+ sinceCsarConformanceLevel: 3.0
+ #MissingRequiredFieldError
+ JE003:
+ - issueType: WARNING
+ sinceCsarConformanceLevel: 3.0
+ #MissingRequiredFieldError2
+ JE004:
+ - issueType: WARNING
+ sinceCsarConformanceLevel: 3.0
+ #InvalidGroupTargetException
+ JE005:
+ - issueType: WARNING
+ sinceCsarConformanceLevel: 3.0
+ #Schema definition of \"%s\" has \"status\" attribute with an invalid value
+ JE006:
+ - issueType: WARNING
+ sinceCsarConformanceLevel: 3.0
+ #The unit \"%s\" is not valid
+ JE007:
+ - issueType: WARNING
+ sinceCsarConformanceLevel: 3.0
+ #ValidationError
+ JE008:
+ - issueType: WARNING
+ sinceCsarConformanceLevel: 3.0
+ #ValueError: Expected max 2 arguments for function \"get_input\" but received \"%s\"",args.size())
+ JE009:
+ - issueType: WARNING
+ sinceCsarConformanceLevel: 3.0
+ #MissingRequiredFieldError3
+ JE010:
+ - issueType: WARNING
+ sinceCsarConformanceLevel: 3.0
\ No newline at end of file
assertEquals("VF_1_V_port_1", vfList.get(0).getMetaData().getValue("name"));
}
// endregion Added by QA - Continue with testings of resolve get_input
-
+
+
+ @Test
+ public void testResolveGetInputArrayStructure() {
+ List<NodeTemplate> vfcs = resolveGetInputCsarQA.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b");
+ Object propertyAsObject = resolveGetInputCsarQA.getNodeTemplatePropertyAsObject(vfcs.get(0), "compute_pd_server_name");
+ assertEquals( ((ArrayList)propertyAsObject).get(0).toString(), "\"ZRDM1MOGX01MPD001\"");
+ propertyAsObject = resolveGetInputCsarQA.getNodeTemplatePropertyAsObject(vfcs.get(0), "port_pd01_port_ip_requirements");
+ assertEquals( ((ArrayList)propertyAsObject).get(1), null);
+ }
}
--- /dev/null
+package org.openecomp.sdc.impl;
+
+import static org.testng.Assert.assertEquals;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+import org.testng.annotations.Test;
+
+public class ToscaParserValidationIssueTest extends SdcToscaParserBasicTest {
+
+ @Test
+ public void testNoValidationIssues() throws SdcToscaParserException {
+ ISdcCsarHelper rainyCsarHelper = getCsarHelper("csars/service-ServiceFdnt-csar-rainy.csar");//conformance level 3.0
+
+ //List<JToscaValidationIssue> notAnalyzedReport = factory.getNotAnalyzadExceptions();
+ //assertEquals( notAnalyzedReport.size(),0);
+ List<JToscaValidationIssue> warningsReport = factory.getWarningExceptions();
+ assertEquals( warningsReport.size(),0);
+ List<JToscaValidationIssue> criticalsReport = factory.getCriticalExceptions();
+ assertEquals( criticalsReport.size(),0);
+ }
+ @Test
+ public void testGetLowSinceConformanceLevel() throws SdcToscaParserException {
+ ISdcCsarHelper fdntCsarHelperWithInputs = getCsarHelper("csars/service-NfodService-csar.csar");//conformance level 3.0
+ //Service level
+
+ List<JToscaValidationIssue> notAnalyzedReport = factory.getNotAnalyzadExceptions();
+ assertEquals( notAnalyzedReport.size(),10);
+ //JE003 high CL 4.0
+ assertEquals( notAnalyzedReport.stream().filter(n->n.getCode().equals("JE003")).collect(Collectors.toList()).size(), 2);
+ assertEquals( notAnalyzedReport.stream().filter(n->n.getCode().equals("JE235")).collect(Collectors.toList()).size(), 7);
+ assertEquals( notAnalyzedReport.stream().filter(n->n.getCode().equals("JE236")).collect(Collectors.toList()).size(), 1);
+ List<JToscaValidationIssue> warningsReport = factory.getWarningExceptions();
+ assertEquals( warningsReport.size(),14);
+ assertEquals( warningsReport.stream().filter(w->w.getCode().equals("JE006")).collect(Collectors.toList()).size(), 13);
+ //JE004 low CL 2.0
+ assertEquals( warningsReport.stream().filter(w->w.getCode().equals("JE004")).collect(Collectors.toList()).size(), 1);
+ List<JToscaValidationIssue> criticalsReport = factory.getCriticalExceptions();
+ assertEquals( criticalsReport.size(),0);
+ }
+ @Test
+ public void testMultiSinceConformanceLevelIssues() throws SdcToscaParserException {
+ ISdcCsarHelper Nfod2images = getCsarHelper("csars/service-Nfod2images-csar.csar");//conformance level 4.0
+ List<JToscaValidationIssue> notAnalyzedReport = factory.getNotAnalyzadExceptions();
+ assertEquals( notAnalyzedReport.size(),17);
+ List<JToscaValidationIssue> warningsReport = factory.getWarningExceptions();
+ assertEquals( warningsReport.size(),0);
+ List<JToscaValidationIssue> criticalsReport = factory.getCriticalExceptions();
+ assertEquals( criticalsReport.size(),24);
+ //JE006 multy values sinceCsarConformanceLevel
+ assertEquals( criticalsReport.stream().filter(c->c.getCode().equals("JE006")).collect(Collectors.toList()).size(), 18);
+ assertEquals( criticalsReport.stream().filter(c->c.getCode().equals("JE003")).collect(Collectors.toList()).size(), 6);
+ }
+
+
+}
--- /dev/null
+# jTosca validation issues
+#by error code, type the validation issue to be CRITICAL/WARNING
+# since Conformance level considered to this type. for example:
+#JE001:
+# - type: WARNING,
+# sinceCsarConformanceLevel: 3.0
+# - type: WARNING,
+# sinceCsarConformanceLevel: 5.0
+validationIssues:
+ # TypeMismatchError
+ JE001:
+ - issueType: WARNING
+ sinceCsarConformanceLevel: 3.0
+ - issueType: CRITICAL
+ sinceCsarConformanceLevel: 4.0
+ - issueType: WARNING
+ sinceCsarConformanceLevel: 5.0
+ # MissingType
+ JE002:
+ - issueType: WARNING
+ sinceCsarConformanceLevel: 3.0
+ #MissingRequiredFieldError
+ JE003:
+ - issueType: CRITICAL
+ sinceCsarConformanceLevel: 4.0
+ #MissingRequiredFieldError2
+ JE004:
+ - issueType: WARNING
+ sinceCsarConformanceLevel: 2.0
+ #InvalidGroupTargetException
+ JE005:
+ - issueType: WARNING
+ sinceCsarConformanceLevel: 3.0
+ #Schema definition of \"%s\" has \"status\" attribute with an invalid value
+ JE006:
+ - issueType: WARNING
+ sinceCsarConformanceLevel: 3.0
+ - issueType: CRITICAL
+ sinceCsarConformanceLevel: 4.0
+ - issueType: WARNING
+ sinceCsarConformanceLevel: 5.0
+ #The unit \"%s\" is not valid
+ JE007:
+ - issueType: WARNING
+ sinceCsarConformanceLevel: 3.0
+ #ValidationError
+ JE008:
+ - issueType: WARNING
+ sinceCsarConformanceLevel: 3.0
+ #ValueError: Expected max 2 arguments for function \"get_input\" but received \"%s\"",args.size())
+ JE009:
+ - issueType: WARNING
+ sinceCsarConformanceLevel: 3.0
+ #MissingRequiredFieldError3
+ JE010:
+ - issueType: WARNING
+ sinceCsarConformanceLevel: 3.0
\ No newline at end of file