diff options
11 files changed, 97 insertions, 90 deletions
diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/docker/Dockerfile b/juju/juju-vnfmadapter/Juju-vnfmadapterService/docker/Dockerfile index d80695d..81ce852 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/docker/Dockerfile +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/docker/Dockerfile @@ -19,7 +19,7 @@ COPY init-mysql.sh . # 30-tomcat.txt - AUTOGENERATED, DO NOT MODIFY MANUALLY # Set up tomcat -RUN wget -q http://mirrors.ocf.berkeley.edu/apache/tomcat/tomcat-8/v8.5.28/bin/apache-tomcat-8.5.28.tar.gz && tar --strip-components=1 -xf apache-tomcat-8.5.28.tar.gz && rm -f apache-tomcat-8.5.28.tar.gz && rm -rf webapps && mkdir -p webapps/ROOT +RUN wget -q http://mirrors.ocf.berkeley.edu/apache/tomcat/tomcat-8/v8.5.29/bin/apache-tomcat-8.5.29.tar.gz && tar --strip-components=1 -xf apache-tomcat-8.5.29.tar.gz && rm -f apache-tomcat-8.5.29.tar.gz && rm -rf webapps && mkdir -p webapps/ROOT RUN echo 'export CATALINA_OPTS="$CATALINA_OPTS -Xms64m -Xmx256m -XX:MaxPermSize=64m"' > /service/bin/setenv.sh ENV CATALINA_HOME /service diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/pom.xml b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/pom.xml index 4895f1f..146328d 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/pom.xml +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/pom.xml @@ -14,7 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.onap.vfc.nfvo.driver.vnfm.gvnfm</groupId> @@ -38,9 +39,9 @@ <version>2.5.0</version> </dependency> <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-lang3</artifactId> - <version>3.1</version> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + <version>3.1</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> @@ -138,7 +139,7 @@ <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-jaxrs</artifactId> - <version>1.9.2</version> + <version>1.9.13</version> </dependency> <dependency> <groupId>javax.ws.rs</groupId> @@ -163,17 +164,17 @@ <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> - <version>4.3.5</version> + <version>4.5.3</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient-cache</artifactId> - <version>4.3.5</version> + <version>4.5.3</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpmime</artifactId> - <version>4.3.5</version> + <version>4.5.3</version> </dependency> <!-- <dependency> <groupId>org.openo.integration</groupId> diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/DownloadCsarManager.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/DownloadCsarManager.java index d246705..a7cdf1e 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/DownloadCsarManager.java +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/DownloadCsarManager.java @@ -19,10 +19,7 @@ package org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.FileOutputStream; -import java.io.IOException; import java.io.InputStream; import java.util.Enumeration; import java.util.zip.ZipEntry; @@ -41,8 +38,6 @@ import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.constant.Constant; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; /** * Utility class to download CSAR @@ -100,8 +95,6 @@ public class DownloadCsarManager { } } is.close(); - //fileout.flush(); - //fileout.close(); status = Constant.DOWNLOADCSAR_SUCCESS; } catch (Exception e) { @@ -168,10 +161,8 @@ public class DownloadCsarManager { public static int unzipCSAR(String fileName,String filePath){ final int BUFFER = 2048; int status=0; - - try ( ZipFile zipFile = new ZipFile(fileName)){ + try (ZipFile zipFile = new ZipFile(fileName)){ Enumeration emu = zipFile.entries(); - int i=0; while(emu.hasMoreElements()){ ZipEntry entry = (ZipEntry)emu.nextElement(); //read directory as file first,so only need to create directory @@ -189,17 +180,14 @@ public class DownloadCsarManager { parent.mkdirs(); } try(FileOutputStream fos = new FileOutputStream(file); - BufferedOutputStream bos = new BufferedOutputStream(fos,BUFFER)){ - - int count; - byte data[] = new byte[BUFFER]; - while ((count = bis.read(data, 0, BUFFER)) != -1) - { - bos.write(data, 0, count); - } + BufferedOutputStream bos = new BufferedOutputStream(fos,BUFFER)){ + int count; + byte[] data = new byte[BUFFER]; + while ((count = bis.read(data, 0, BUFFER)) != -1) + { + bos.write(data, 0, count); + } } - //bos.flush(); - //bos.close(); bis.close(); if(entry.getName().endsWith(".zip")){ @@ -218,7 +206,6 @@ public class DownloadCsarManager { zipFile.close(); } catch (Exception e) { status=Constant.UNZIP_FAIL; - //e.printStackTrace(); LOG.error("unzipCSAR Exception: ",e); } @@ -238,6 +225,6 @@ public class DownloadCsarManager { return csarfilepath; } public static void main(String[] args) { - System.out.println(getImagesPath("e:/juju/csar2/")); + LOG.info("AbsolutePath: " + getImagesPath("e:/juju/csar2/")); } } diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/EntityUtils.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/EntityUtils.java index 6b4c2cb..1cb803c 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/EntityUtils.java +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/EntityUtils.java @@ -1,4 +1,4 @@ -/* +/** * Copyright 2016 Huawei Technologies Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/FileUtils.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/FileUtils.java index 357f2c5..3a8bc5c 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/FileUtils.java +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/FileUtils.java @@ -241,10 +241,10 @@ public class FileUtils { int byteread = 0; File oldfile = new File(oldPath); if (oldfile.exists()) { - if (flag == false) { + if (!flag) { delFiles(newPath); } - if (new File(newPath).exists() && flag == true) { + if (new File(newPath).exists() && flag) { return; } newFile(newPath); @@ -255,8 +255,6 @@ public class FileUtils { fos.write(buffer, 0, byteread); } } - //fos.close(); - //fis.close(); } else { throw new FileNotFoundException("the " + oldfile + " is not exits "); } @@ -278,12 +276,12 @@ public class FileUtils { return true; if (myDelFile.isDirectory()) { File[] fs = myDelFile.listFiles(); - for (int i = 0; i < fs.length; i++) { + for (int i = 0; i < fs.length; i++) {//no need to assign if (fs[i].isFile()) - flag = fs[i].delete(); + fs[i].delete(); if (fs[i].isDirectory()) { - flag = delFiles(fs[i].getAbsolutePath()); - flag = fs[i].delete(); + delFiles(fs[i].getAbsolutePath()); + fs[i].delete(); } } } @@ -317,7 +315,7 @@ public class FileUtils { * */ public static List<File> getFiles(String path) { - List<File> list = new ArrayList<File>(); + List<File> list = new ArrayList<>(); File file = new File(path); if (!file.exists()) { diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/LocalComandUtils.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/LocalComandUtils.java index 9cb8833..7cf6418 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/LocalComandUtils.java +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/LocalComandUtils.java @@ -1,4 +1,4 @@ -/* +/** * Copyright 2016 Huawei Technologies Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -38,13 +38,12 @@ import org.slf4j.LoggerFactory; * @version NFVO 0.5 Sep 19, 2016 */ public class LocalComandUtils { + private static final Logger log = LoggerFactory.getLogger(LocalComandUtils.class); + private LocalComandUtils(){ } - private static final Logger log = LoggerFactory.getLogger(LocalComandUtils.class); - - /** * <br> * diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/UnCompressUtil.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/UnCompressUtil.java index 308adb2..f2098fc 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/UnCompressUtil.java +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/UnCompressUtil.java @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2016, Huawei Technologies Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,7 +22,6 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; -import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -51,9 +50,9 @@ public class UnCompressUtil { private static Logger log = LoggerFactory.getLogger(UnCompressUtil.class); - private static Map<String, String> archiveMap = new HashMap<String, String>(); + private static Map<String, String> archiveMap = new HashMap<>(); - private static Map<String, String> compressorMap = new HashMap<String, String>(); + private static Map<String, String> compressorMap = new HashMap<>(); static { // archive type @@ -160,7 +159,7 @@ public class UnCompressUtil { FileUtils.mkDirs(fileName); } else { int count; - byte data[] = new byte[2048]; + byte[] data = new byte[2048]; File file = getRealFileName(targetPath, name); fileNames.add(file.getName()); diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/restclient/RestHttpContentExchange.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/restclient/RestHttpContentExchange.java index fa0344c..685785f 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/restclient/RestHttpContentExchange.java +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/restclient/RestHttpContentExchange.java @@ -79,41 +79,16 @@ public class RestHttpContentExchange extends ContentExchange { if(data == null) { return ""; } - ByteArrayInputStream input = null; - GZIPInputStream gzis = null; - InputStreamReader reader = null; final StringBuilder out = new StringBuilder(); - try { - input = new ByteArrayInputStream(data); - gzis = new GZIPInputStream(input); - reader = new InputStreamReader(gzis, Charset.forName(RestfulClientConst.ENCODING)); + try ( + ByteArrayInputStream input = new ByteArrayInputStream(data); + GZIPInputStream gzis = new GZIPInputStream(input); + InputStreamReader reader = new InputStreamReader(gzis, Charset.forName(RestfulClientConst.ENCODING))){ final char[] buff = new char[1024]; for(int n; (n = reader.read(buff)) != -1;) { out.append(new String(buff, 0, n)); } - } finally { - if(reader != null) { - try { - reader.close(); - } catch(final IOException e) { - LOGGER.error("decompress Gzip reader exception:", e); - } - } - if(gzis != null) { - try { - gzis.close(); - } catch(final IOException e) { - LOGGER.error("decompress Gzip exception:", e); - } - } - if(input != null) { - try { - input.close(); - } catch(final IOException e) { - LOGGER.error("decompress Gzip input exception:", e); - } - } - } + } return out.toString(); } diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/DownloadCsarManagerTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/DownloadCsarManagerTest.java index 533e081..75dd4a4 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/DownloadCsarManagerTest.java +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/DownloadCsarManagerTest.java @@ -13,26 +13,34 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common; -import static org.junit.Assert.*; +import static org.junit.Assert.assertTrue; import java.lang.reflect.Constructor; import java.lang.reflect.Modifier; +import org.apache.http.HttpResponse; +import org.apache.http.ProtocolVersion; +import org.apache.http.StatusLine; +import org.apache.http.message.BasicHttpResponse; +import org.apache.http.message.BasicStatusLine; import org.junit.Test; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.DownloadCsarManager; public class DownloadCsarManagerTest { + DownloadCsarManager mgr; + @Test public void test() { - String url=""; - String filepath=""; + String url = ""; + String filepath = ""; mgr.download(url); mgr.download(url, filepath); mgr.getRandomFileName(); } + @Test public void testPrivateConstructor() throws Exception { Constructor constructor = DownloadCsarManager.class.getDeclaredConstructor(); @@ -40,4 +48,35 @@ public class DownloadCsarManagerTest { constructor.setAccessible(true); constructor.newInstance(); } + + @Test + public void getFileNameTest() { + ProtocolVersion version = new ProtocolVersion("HTTP", 1, 1); + StatusLine sl = new BasicStatusLine(version, 200, "success"); + HttpResponse response = new BasicHttpResponse(sl); + response.setHeader("Content-Disposition", "filename"); + DownloadCsarManager.getFileName(response); + } + + @Test + public void downloadTest() { + DownloadCsarManager.download("http://www.baidu.com"); + DownloadCsarManager.download("http://www.baidu.com", "/opt"); + DownloadCsarManager.getRandomFileName(); + } + + @Test + public void getFilePath() { + ProtocolVersion version = new ProtocolVersion("HTTP", 1, 1); + StatusLine sl = new BasicStatusLine(version, 200, "success"); + HttpResponse response = new BasicHttpResponse(sl); + response.setHeader("Content-Disposition", "filename"); + DownloadCsarManager.getFilePath(response); + } + + @Test + public void testUnzip() { + DownloadCsarManager.unzipCSAR("test.zip", "/opt"); + } + } diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/YamlUtilTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/YamlUtilTest.java index 7bcbd14..e98f058 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/YamlUtilTest.java +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/YamlUtilTest.java @@ -20,13 +20,13 @@ import java.io.File; import org.junit.Before; import org.junit.Test; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.YamlUtil; import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.restclient.ServiceException; import org.yaml.snakeyaml.Yaml; import net.sf.json.JSON; public class YamlUtilTest { + YamlUtil yaml; @Before @@ -38,12 +38,18 @@ public class YamlUtilTest { @Test public void test() throws ServiceException { String yamlName = "src/test/resources/test.yaml"; + String arrayName = "src/test/resources/testArray.yaml"; + JSON json = yaml.yamlToJson(yamlName); + yaml.yamlToJson(arrayName); + String S = yaml.loadYaml(yamlName); + Yaml yaml = new Yaml(); + File file = new File(yamlName); + } - JSON json=yaml.yamlToJson(yamlName); - - String S=yaml.loadYaml(yamlName); - Yaml yaml = new Yaml(); - File file =new File(yamlName); + @Test + public void testFileNotFoundException() throws ServiceException { + yaml.yamlToJson("src/test/resources/abc.yaml"); + yaml.loadYaml("src/test/resources/abc.yaml"); } } diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/resources/testArray.yaml b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/resources/testArray.yaml new file mode 100644 index 0000000..d08d0bd --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/resources/testArray.yaml @@ -0,0 +1,3 @@ +- Cat
+- Dog
+- Goldfish
\ No newline at end of file |