From f09c2646860e66de2d91bccd61217ce22abfe75d Mon Sep 17 00:00:00 2001 From: Pavel Aharoni Date: Thu, 4 May 2017 20:04:08 +0300 Subject: [SDC-15] allotted resource CSAR fixes Change-Id: I31dcd0a6b697357fed0e7f8c431b5317339b3c74 Signed-off-by: Pavel Aharoni --- jtosca/pom.xml | 8 +-- .../sdc/toscaparser/api/ToscaTemplate.java | 4 +- .../toscaparser/api/common/ExceptionCollector.java | 29 +++++------ pom.xml | 2 +- sdc-distribution-ci/pom.xml | 2 +- .../java/org/openecomp/test/CsarToscaTester.java | 18 +++++++ sdc-distribution-client/pom.xml | 2 +- sdc-tosca-parser/pom.xml | 8 +-- .../sdc/tosca/parser/impl/SdcCsarHelperImpl.java | 2 +- .../sdc/impl/ToscaParserNodeTemplateTest.java | 4 +- .../openecomp/sdc/impl/ToscaParserTestSuite.java | 58 +++++++++------------ ...vice-ServiceFdnt-csar-allotted-resources-4.csar | Bin 39949 -> 0 bytes .../service-ServiceFdnt-csar-cp-vfc-req-cap-8.csar | Bin 40116 -> 0 bytes .../service-ServiceFdnt-csar-flat-input-9-1.csar | Bin 40109 -> 0 bytes .../service-ServiceFdnt-csar-group-meta-10.csar | Bin 40119 -> 0 bytes ...ceFdnt-csar-groups-status-supported-case-3.csar | Bin 39943 -> 0 bytes .../csars/service-ServiceFdnt-csar-inputs-9.csar | Bin 40130 -> 0 bytes .../csars/service-ServiceFdnt-csar-nt-props-1.csar | Bin 39948 -> 0 bytes .../service-ServiceFdnt-csar-nt-tt-metadata-2.csar | Bin 39938 -> 0 bytes .../service-ServiceFdnt-csar-service-vl-7.csar | Bin 40014 -> 0 bytes .../csars/service-ServiceFdnt-csar-two-vfs-5.csar | Bin 39964 -> 0 bytes .../csars/service-ServiceFdnt-with-allotted.csar | Bin 0 -> 44991 bytes .../test/resources/csars/service-vmme-csar.csar | Bin 74074 -> 0 bytes 23 files changed, 73 insertions(+), 64 deletions(-) create mode 100644 sdc-distribution-ci/src/main/java/org/openecomp/test/CsarToscaTester.java delete mode 100644 sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-allotted-resources-4.csar delete mode 100644 sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-cp-vfc-req-cap-8.csar delete mode 100644 sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-flat-input-9-1.csar delete mode 100644 sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-group-meta-10.csar delete mode 100644 sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-groups-status-supported-case-3.csar delete mode 100644 sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-inputs-9.csar delete mode 100644 sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-nt-props-1.csar delete mode 100644 sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-nt-tt-metadata-2.csar delete mode 100644 sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-service-vl-7.csar delete mode 100644 sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-two-vfs-5.csar create mode 100644 sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-with-allotted.csar delete mode 100644 sdc-tosca-parser/src/test/resources/csars/service-vmme-csar.csar diff --git a/jtosca/pom.xml b/jtosca/pom.xml index 6122858..847579c 100644 --- a/jtosca/pom.xml +++ b/jtosca/pom.xml @@ -5,11 +5,11 @@ org.openecomp.sdc.sdc-distribution-client sdc-main-distribution-client - 1.1.8-SNAPSHOT + 1.1.9-SNAPSHOT jtosca - 0.1.0-SNAPSHOT + 0.1.1-SNAPSHOT @@ -27,12 +27,12 @@ 1.7.25 - + \ No newline at end of file diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java index 8b7abce..942ca96 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java @@ -101,7 +101,7 @@ public class ToscaTemplate extends Object { //long startTime = System.nanoTime(); - ExceptionCollector.start(); + //ExceptionCollector.start(); isFile = aFile; inputPath = null; @@ -184,7 +184,7 @@ public class ToscaTemplate extends Object { csarTempDir = null; } - ExceptionCollector.stop(); + //ExceptionCollector.stop(); verifyTemplate(); } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/common/ExceptionCollector.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/common/ExceptionCollector.java index 9bef6bc..07dabf8 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/common/ExceptionCollector.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/common/ExceptionCollector.java @@ -1,45 +1,44 @@ package org.openecomp.sdc.toscaparser.api.common; -import org.openecomp.sdc.toscaparser.api.elements.EntityType; +import java.util.ArrayList; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; - // Perfectly good enough... public class ExceptionCollector { private static Logger log = LoggerFactory.getLogger(ExceptionCollector.class.getName()); - private static boolean isCollecting = false; - private static ArrayList exceptionStrings = null; - private static ArrayList traceStrings = null; + //private static boolean isCollecting = false; + private static ArrayList exceptionStrings = new ArrayList<>(); + private static ArrayList traceStrings = new ArrayList<>(); private static boolean bWantTrace = true; - public static void start() { + /*public static void start() { if(exceptionStrings == null) { exceptionStrings = new ArrayList(); traceStrings = new ArrayList(); } isCollecting = true; - } + }*/ - public static void stop() { + /*public static void stop() { isCollecting = false; - } + }*/ public static void clear() { - exceptionStrings = null; - traceStrings = null; + exceptionStrings = new ArrayList<>(); + traceStrings = new ArrayList<>(); } public static void appendException(String strExc) { // throws Exception { - if(!isCollecting) { + /*if(!isCollecting) { // throw new Exception("Can't append exception " + strExc); log.error("ExceptionCollector - appendException - Can't append exception {}", strExc); - } + }*/ if(!exceptionStrings.contains(strExc)) { exceptionStrings.add(strExc); @@ -66,7 +65,7 @@ public class ExceptionCollector { } return report; } - return null; + return new ArrayList<>(); } public static int errorsCaught() { diff --git a/pom.xml b/pom.xml index 78d7d0c..f03c0fe 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.openecomp.sdc.sdc-distribution-client sdc-main-distribution-client - 1.1.8-SNAPSHOT + 1.1.9-SNAPSHOT pom diff --git a/sdc-distribution-ci/pom.xml b/sdc-distribution-ci/pom.xml index 0c53c74..c7b544c 100644 --- a/sdc-distribution-ci/pom.xml +++ b/sdc-distribution-ci/pom.xml @@ -6,7 +6,7 @@ org.openecomp.sdc.sdc-distribution-client sdc-main-distribution-client - 1.1.8-SNAPSHOT + 1.1.9-SNAPSHOT sdc-distribution-ci diff --git a/sdc-distribution-ci/src/main/java/org/openecomp/test/CsarToscaTester.java b/sdc-distribution-ci/src/main/java/org/openecomp/test/CsarToscaTester.java new file mode 100644 index 0000000..4dae5eb --- /dev/null +++ b/sdc-distribution-ci/src/main/java/org/openecomp/test/CsarToscaTester.java @@ -0,0 +1,18 @@ +package org.openecomp.test; + +import java.util.ArrayList; +import java.util.Arrays; + +import org.openecomp.sdc.tosca.parser.impl.SdcToscaParserFactory; +import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; + +public class CsarToscaTester { + public static void main(String[] args) throws Exception { + ClassLoader loader = CsarToscaTester.class.getClassLoader(); + System.out.println("CsarToscaParser - path to CSAR is "+Arrays.toString(args)); + SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); + factory.getSdcCsarHelper(args[0]); + ArrayList exceptionReport = ExceptionCollector.getExceptionReport(); + System.out.println("Errors during CSAR parsing are: "+(exceptionReport != null ? exceptionReport.toString() : "none")); + } +} diff --git a/sdc-distribution-client/pom.xml b/sdc-distribution-client/pom.xml index c9ee8bb..ea13907 100644 --- a/sdc-distribution-client/pom.xml +++ b/sdc-distribution-client/pom.xml @@ -6,7 +6,7 @@ org.openecomp.sdc.sdc-distribution-client sdc-main-distribution-client - 1.1.8-SNAPSHOT + 1.1.9-SNAPSHOT sdc-distribution-client diff --git a/sdc-tosca-parser/pom.xml b/sdc-tosca-parser/pom.xml index 56cc293..f05622f 100644 --- a/sdc-tosca-parser/pom.xml +++ b/sdc-tosca-parser/pom.xml @@ -6,7 +6,7 @@ org.openecomp.sdc.sdc-distribution-client sdc-main-distribution-client - 1.1.8-SNAPSHOT + 1.1.9-SNAPSHOT sdc-tosca-parser @@ -71,7 +71,7 @@ org.openecomp.sdc.sdc-distribution-client jtosca - 0.1.0-SNAPSHOT + 0.1.1-SNAPSHOT @@ -111,12 +111,12 @@ test - + diff --git a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java index b5fb6af..000b381 100644 --- a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java +++ b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java @@ -385,7 +385,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { log.error("getAllottedResources nodeTemplates not exist"); } nodeTemplates = nodeTemplates.stream().filter( - x -> x.getMetaData() != null && x.getMetaData().getValue("category").equals("Allotted Resources")) + x -> x.getMetaData() != null && x.getMetaData().getValue("category").equals("Allotted Resource")) .collect(Collectors.toList()); if (nodeTemplates.isEmpty()) { log.debug("getAllottedResources - allotted resources not exist"); diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java index 469ddd2..7c30616 100644 --- a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java +++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java @@ -20,7 +20,7 @@ public class ToscaParserNodeTemplateTest extends BasicTest { public void testNumberOfVfSunnyFlow() throws SdcToscaParserException { List serviceVfList = ToscaParserTestSuite.fdntCsarHelper.getServiceVfList(); assertNotNull(serviceVfList); - assertEquals(1, serviceVfList.size()); + assertEquals(2, serviceVfList.size()); } @Test @@ -136,7 +136,7 @@ public class ToscaParserNodeTemplateTest extends BasicTest { @Test public void testGetAllottedResources() { List allottedResources = ToscaParserTestSuite.fdntCsarHelper.getAllottedResources(); - assertEquals(0, allottedResources.size()); + assertEquals(1, allottedResources.size()); } @Test diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserTestSuite.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserTestSuite.java index d4b474f..83e7d13 100644 --- a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserTestSuite.java +++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserTestSuite.java @@ -1,16 +1,18 @@ package org.openecomp.sdc.impl; -import org.junit.*; -import org.junit.runners.Suite; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; + +import org.junit.BeforeClass; import org.junit.runner.RunWith; +import org.junit.runners.Suite; import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; import org.openecomp.sdc.tosca.parser.impl.SdcToscaParserFactory; +import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; import org.openecomp.sdc.toscaparser.api.common.JToscaException; -import java.io.File; -import java.io.IOException; - @RunWith( Suite.class ) @Suite.SuiteClasses( { ToscaParserNodeTemplateTest.class, @@ -31,34 +33,24 @@ public class ToscaParserTestSuite { public static void init() throws SdcToscaParserException, JToscaException, IOException { factory = SdcToscaParserFactory.getInstance(); - long startTime = System.currentTimeMillis(); - long estimatedTime = System.currentTimeMillis() - startTime; - System.out.println("Time to init factory " + estimatedTime); - - String fileStr1 = ToscaParserTestSuite.class.getClassLoader().getResource("csars/service-ServiceFdnt-csar-0904-2.csar").getFile(); + fdntCsarHelper = getCsarHelper("csars/service-ServiceFdnt-with-allotted.csar"); + rainyCsarHelperMultiVfs = getCsarHelper("csars/service-ServiceFdnt-csar-rainy.csar"); + rainyCsarHelperSingleVf = getCsarHelper("csars/service-ServiceFdnt-csar.csar"); + } + + private static ISdcCsarHelper getCsarHelper(String path) throws JToscaException, IOException, SdcToscaParserException { + System.out.println("Parsing CSAR "+path+"..."); + String fileStr1 = ToscaParserTestSuite.class.getClassLoader().getResource(path).getFile(); File file1 = new File(fileStr1); - startTime = System.currentTimeMillis(); - - fdntCsarHelper = factory.getSdcCsarHelper(file1.getAbsolutePath()); - - estimatedTime = System.currentTimeMillis() - startTime; - System.out.println("init CSAR Execution time: " + estimatedTime); - - String fileStr2 = ToscaParserTestSuite.class.getClassLoader().getResource("csars/service-ServiceFdnt-csar-rainy.csar").getFile(); - File file2 = new File(fileStr2); - rainyCsarHelperMultiVfs = factory.getSdcCsarHelper(file2.getAbsolutePath()); - - String fileStr3 = ToscaParserTestSuite.class.getClassLoader().getResource("csars/service-ServiceFdnt-csar.csar").getFile(); - File file3 = new File(fileStr3); - rainyCsarHelperSingleVf = factory.getSdcCsarHelper(file3.getAbsolutePath()); - }; - - @AfterClass - public static void after(){ - long startTime = System.currentTimeMillis(); - long estimatedTime = System.currentTimeMillis() - startTime; - System.out.println("close Execution time: "+estimatedTime); - }; - + ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper(file1.getAbsolutePath()); + ArrayList exceptionReport = ExceptionCollector.getExceptionReport(); + if (!exceptionReport.isEmpty()){ + System.out.println("TOSCA Errors found in CSAR - failing the tests..."); + System.out.println(exceptionReport.toString()); + ExceptionCollector.clear(); + throw new SdcToscaParserException("CSAR didn't pass validation"); + } + return sdcCsarHelper; + } } diff --git a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-allotted-resources-4.csar b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-allotted-resources-4.csar deleted file mode 100644 index 7b4cff2..0000000 Binary files a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-allotted-resources-4.csar and /dev/null differ diff --git a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-cp-vfc-req-cap-8.csar b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-cp-vfc-req-cap-8.csar deleted file mode 100644 index be254a0..0000000 Binary files a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-cp-vfc-req-cap-8.csar and /dev/null differ diff --git a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-flat-input-9-1.csar b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-flat-input-9-1.csar deleted file mode 100644 index 4ae4c6f..0000000 Binary files a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-flat-input-9-1.csar and /dev/null differ diff --git a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-group-meta-10.csar b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-group-meta-10.csar deleted file mode 100644 index 5bcf960..0000000 Binary files a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-group-meta-10.csar and /dev/null differ diff --git a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-groups-status-supported-case-3.csar b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-groups-status-supported-case-3.csar deleted file mode 100644 index 7286663..0000000 Binary files a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-groups-status-supported-case-3.csar and /dev/null differ diff --git a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-inputs-9.csar b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-inputs-9.csar deleted file mode 100644 index c1c2855..0000000 Binary files a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-inputs-9.csar and /dev/null differ diff --git a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-nt-props-1.csar b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-nt-props-1.csar deleted file mode 100644 index ceac90a..0000000 Binary files a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-nt-props-1.csar and /dev/null differ diff --git a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-nt-tt-metadata-2.csar b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-nt-tt-metadata-2.csar deleted file mode 100644 index 3cda214..0000000 Binary files a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-nt-tt-metadata-2.csar and /dev/null differ diff --git a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-service-vl-7.csar b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-service-vl-7.csar deleted file mode 100644 index db3af99..0000000 Binary files a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-service-vl-7.csar and /dev/null differ diff --git a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-two-vfs-5.csar b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-two-vfs-5.csar deleted file mode 100644 index 565929a..0000000 Binary files a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-two-vfs-5.csar and /dev/null differ diff --git a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-with-allotted.csar b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-with-allotted.csar new file mode 100644 index 0000000..41ee2c7 Binary files /dev/null and b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-with-allotted.csar differ diff --git a/sdc-tosca-parser/src/test/resources/csars/service-vmme-csar.csar b/sdc-tosca-parser/src/test/resources/csars/service-vmme-csar.csar deleted file mode 100644 index 416707c..0000000 Binary files a/sdc-tosca-parser/src/test/resources/csars/service-vmme-csar.csar and /dev/null differ -- cgit 1.2.3-korg