From 9542ec5708daad3dd43052d326780f7f5c9a987d Mon Sep 17 00:00:00 2001 From: Tal Gitelman Date: Thu, 4 Jan 2018 16:11:30 +0200 Subject: CSAR files are decompressed twice in the same thread fixed Change-Id: Id59cc7250d8431114ab90d14e03049f86a4d49ca Issue-ID: SDC-250 Signed-off-by: Tal Gitelman --- .../sdc/toscaparser/api/ToscaTemplate.java | 4 +-- .../openecomp/sdc/toscaparser/api/prereq/CSAR.java | 9 ++++--- .../sdc/toscaparser/api/JToscaMetadataParse.java | 30 ++++++++++++++++++--- src/test/resources/csars/emptyCsar.csar | Bin 0 -> 22 bytes .../resources/csars/service-ServiceFdnt-csar.csar | Bin 40171 -> 0 bytes .../csars/tmpCSAR_Huawei_vSPGW_fixed.csar | Bin 0 -> 44576 bytes .../csars/tmpCSAR_Huawei_vSPGW_fixed.csar.csar | Bin 44576 -> 0 bytes 7 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 src/test/resources/csars/emptyCsar.csar delete mode 100644 src/test/resources/csars/service-ServiceFdnt-csar.csar create mode 100644 src/test/resources/csars/tmpCSAR_Huawei_vSPGW_fixed.csar delete mode 100644 src/test/resources/csars/tmpCSAR_Huawei_vSPGW_fixed.csar.csar diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java b/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java index 07cce1c..8d7d130 100644 --- a/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java +++ b/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java @@ -172,8 +172,7 @@ public class ToscaTemplate extends Object { //log.info(msg) log.debug("ToscaTemplate - Both path and yaml_dict_tpl arguments were provided. Using path and ignoring yaml_dict_tpl"); } - } - else { + } else { // no input to process... _abort(); } @@ -225,6 +224,7 @@ public class ToscaTemplate extends Object { verifyTemplate(); throw new JToscaException("jtosca aborting", JToscaErrorCodes.PATH_NOT_VALID.getValue()); } + private TopologyTemplate _topologyTemplate() { return new TopologyTemplate( _tplTopologyTemplate(), diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/prereq/CSAR.java b/src/main/java/org/openecomp/sdc/toscaparser/api/prereq/CSAR.java index b40eded..b64bd9a 100644 --- a/src/main/java/org/openecomp/sdc/toscaparser/api/prereq/CSAR.java +++ b/src/main/java/org/openecomp/sdc/toscaparser/api/prereq/CSAR.java @@ -54,7 +54,6 @@ public class CSAR { metaProperties = new LinkedHashMap<>(); } - @SuppressWarnings("unchecked") public boolean validate() throws JToscaException { isValidated = true; @@ -310,9 +309,11 @@ public class CSAR { if(!isValidated) { validate(); } - tempDir = Files.createTempDirectory("JTP").toString(); - unzip(path,tempDir); - + + if(tempDir == null || tempDir.isEmpty()) { + tempDir = Files.createTempDirectory("JTP").toString(); + unzip(path,tempDir); + } } private void _validateExternalReferences() throws JToscaException { diff --git a/src/test/java/org/openecomp/sdc/toscaparser/api/JToscaMetadataParse.java b/src/test/java/org/openecomp/sdc/toscaparser/api/JToscaMetadataParse.java index 37292e5..8f55fa4 100644 --- a/src/test/java/org/openecomp/sdc/toscaparser/api/JToscaMetadataParse.java +++ b/src/test/java/org/openecomp/sdc/toscaparser/api/JToscaMetadataParse.java @@ -5,12 +5,11 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.io.File; -import java.util.Collection; import java.util.LinkedHashMap; import org.junit.Test; import org.openecomp.sdc.toscaparser.api.common.JToscaException; -import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue; +import org.openecomp.sdc.toscaparser.api.utils.JToscaErrorCodes; import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; public class JToscaMetadataParse { @@ -29,11 +28,34 @@ public class JToscaMetadataParse { @Test public void noWarningsAfterParse() throws JToscaException { - String fileStr = JToscaMetadataParse.class.getClassLoader().getResource("csars/tmpCSAR_Huawei_vSPGW_fixed.csar.csar").getFile(); + String fileStr = JToscaMetadataParse.class.getClassLoader().getResource("csars/tmpCSAR_Huawei_vSPGW_fixed.csar").getFile(); File file = new File(fileStr); ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null); int validationIssuesCaught = ThreadLocalsHolder.getCollector().validationIssuesCaught(); assertTrue(validationIssuesCaught == 0 ); } - + + @Test + public void testEmptyCsar() throws JToscaException { + String fileStr = JToscaMetadataParse.class.getClassLoader().getResource("csars/emptyCsar.csar").getFile(); + File file = new File(fileStr); + try { + ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null); + } catch (JToscaException e) { + assertTrue(e.getCode().equals(JToscaErrorCodes.INVALID_CSAR_FORMAT.getValue())); + } + int validationIssuesCaught = ThreadLocalsHolder.getCollector().validationIssuesCaught(); + assertTrue(validationIssuesCaught == 0 ); + } + + @Test + public void testEmptyPath() throws JToscaException { + String fileStr = JToscaMetadataParse.class.getClassLoader().getResource("").getFile(); + File file = new File(fileStr); + try { + ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null); + }catch (JToscaException e) { + assertTrue(e.getCode().equals(JToscaErrorCodes.PATH_NOT_VALID.getValue())); + } + } } diff --git a/src/test/resources/csars/emptyCsar.csar b/src/test/resources/csars/emptyCsar.csar new file mode 100644 index 0000000..15cb0ec Binary files /dev/null and b/src/test/resources/csars/emptyCsar.csar differ diff --git a/src/test/resources/csars/service-ServiceFdnt-csar.csar b/src/test/resources/csars/service-ServiceFdnt-csar.csar deleted file mode 100644 index 983dc9b..0000000 Binary files a/src/test/resources/csars/service-ServiceFdnt-csar.csar and /dev/null differ diff --git a/src/test/resources/csars/tmpCSAR_Huawei_vSPGW_fixed.csar b/src/test/resources/csars/tmpCSAR_Huawei_vSPGW_fixed.csar new file mode 100644 index 0000000..70f8cc4 Binary files /dev/null and b/src/test/resources/csars/tmpCSAR_Huawei_vSPGW_fixed.csar differ diff --git a/src/test/resources/csars/tmpCSAR_Huawei_vSPGW_fixed.csar.csar b/src/test/resources/csars/tmpCSAR_Huawei_vSPGW_fixed.csar.csar deleted file mode 100644 index 70f8cc4..0000000 Binary files a/src/test/resources/csars/tmpCSAR_Huawei_vSPGW_fixed.csar.csar and /dev/null differ -- cgit 1.2.3-korg