diff options
Diffstat (limited to 'vnfmarket-be')
6 files changed, 233 insertions, 16 deletions
diff --git a/vnfmarket-be/deployment/docker/docker-refrepo/src/main/docker/Dockerfile b/vnfmarket-be/deployment/docker/docker-refrepo/src/main/docker/Dockerfile index 22ced94a..70322788 100644 --- a/vnfmarket-be/deployment/docker/docker-refrepo/src/main/docker/Dockerfile +++ b/vnfmarket-be/deployment/docker/docker-refrepo/src/main/docker/Dockerfile @@ -29,7 +29,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.20/bin/apache-tomcat-8.5.20.tar.gz && tar --strip-components=1 -xf apache-tomcat-8.5.20.tar.gz && rm -f apache-tomcat-8.5.20.tar.gz && rm -rf webapps && mkdir -p webapps/ROOT +RUN wget -q http://mirrors.ocf.berkeley.edu/apache/tomcat/tomcat-8/v8.5.23/bin/apache-tomcat-8.5.23.tar.gz && tar --strip-components=1 -xf apache-tomcat-8.5.23.tar.gz && rm -f apache-tomcat-8.5.23.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/vnfmarket-be/deployment/install/.env b/vnfmarket-be/deployment/install/.env index 83c135f3..527088e9 100644 --- a/vnfmarket-be/deployment/install/.env +++ b/vnfmarket-be/deployment/install/.env @@ -8,3 +8,5 @@ POSTGRES_TAG=latest NEXUS_REPO=nexus3.onap.org:10001 +export MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1) + diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/CommonConstant.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/CommonConstant.java index 1ba18cd6..92d19de6 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/CommonConstant.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/CommonConstant.java @@ -31,11 +31,11 @@ public class CommonConstant { public static final String TOSCA_METADATA = "TOSCA-Metadata"; - public static final String CSAR_VERSION_META = "version"; + public static final String CSAR_VERSION_META = "Version"; - public static final String CSAR_TYPE_META = "type"; + public static final String CSAR_TYPE_META = "Type"; - public static final String CSAR_PROVIDER_META = "provider"; + public static final String CSAR_PROVIDER_META = "Provider"; public static final String DEFINITIONS = "Definitions"; diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/CommonErrorResponse.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/CommonErrorResponse.java index 2c22bdca..967d0039 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/CommonErrorResponse.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/CommonErrorResponse.java @@ -19,6 +19,11 @@ package org.onap.vnfsdk.marketplace.common; public class CommonErrorResponse { private String message; + + public CommonErrorResponse(String message) { + super(); + this.message = message; + } public String getMessage() { return message; @@ -27,11 +32,5 @@ public class CommonErrorResponse { public static Object failure(String message) { return message; } - - public CommonErrorResponse(String message) { - super(); - this.message = message; - } - } diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapperUtil.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapperUtil.java index 1777c1ec..ab94e983 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapperUtil.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapperUtil.java @@ -184,8 +184,8 @@ public class PackageWrapperUtil { */ public static String getPackageName(String ftpUrl) { int index = ftpUrl.lastIndexOf("/"); - String packageName = ftpUrl.substring(index); - return packageName; + + return ftpUrl.substring(index); } /** @@ -279,6 +279,11 @@ public class PackageWrapperUtil { if (unzipFile.endsWith(CommonConstant.MANIFEST)) { basicInfo = readManifest(unzipFile); } + + if (unzipFile.endsWith(CommonConstant.CSAR_META)) { + basicInfo = readMetaData(unzipFile); + } + if (ToolUtil.isYamlFile(new File(unzipFile))) { isXmlCsar = false; } @@ -299,7 +304,7 @@ public class PackageWrapperUtil { * @param unzipFile * @return basic infor about package */ - private static PackageBasicInfo readManifest(String unzipFile) { + private static PackageBasicInfo readMetaData(String unzipFile) { // Fix the package type to CSAR, temporary PackageBasicInfo basicInfo = new PackageBasicInfo(); @@ -308,7 +313,7 @@ public class PackageWrapperUtil { File file = new File(unzipFile); try (BufferedReader reader = new BufferedReader(new FileReader(file))) { - for(String tempString = null; (tempString = reader.readLine()) != null;) + for(String tempString; (tempString = reader.readLine()) != null;) { // If line is empty, ignore if ("".equals(tempString)) { @@ -319,16 +324,23 @@ public class PackageWrapperUtil { String meta = tempString.substring(0, count1).trim(); // Check for the package provider name - if (meta.equalsIgnoreCase(CommonConstant.MF_PROVIDER_META)) { + if (meta.equalsIgnoreCase(CommonConstant.CSAR_PROVIDER_META)) { int count = tempString.indexOf(":") + 1; basicInfo.setProvider(tempString.substring(count).trim()); } // Check for package version - if (meta.equalsIgnoreCase(CommonConstant.MF_VERSION_META)) { + if (meta.equalsIgnoreCase(CommonConstant.CSAR_VERSION_META)) { int count = tempString.indexOf(":") + 1; basicInfo.setVersion(tempString.substring(count).trim()); } + + // Check for package type + if (meta.equalsIgnoreCase(CommonConstant.CSAR_TYPE_META)) { + int count = tempString.indexOf(":") + 1; + + basicInfo.setType(getEnumType(tempString.substring(count).trim())); + } } reader.close(); @@ -338,6 +350,77 @@ public class PackageWrapperUtil { return basicInfo; } + + private static EnumType getEnumType (String type) + { + EnumType vnfType = EnumType.CSAR; + if (type == "CSAR") + { + vnfType = EnumType.CSAR; + } + + if (type == "GSAR") + { + vnfType = EnumType.GSAR; + } + + if (type == "NSAR") + { + vnfType = EnumType.NSAR; + } + + if (type == "SSAR") + { + vnfType = EnumType.SSAR; + } + + if (type == "NFAR") + { + vnfType = EnumType.NFAR; + } + + return vnfType; + } + + private static PackageBasicInfo readManifest(String unzipFile) { + + // Fix the package type to CSAR, temporary + PackageBasicInfo basicInfo = new PackageBasicInfo(); + basicInfo.setType(EnumType.CSAR); + + File file = new File(unzipFile); + try (BufferedReader reader = new BufferedReader(new FileReader(file))) { + + for(String tempString; (tempString = reader.readLine()) != null;) + { + // If line is empty, ignore + if ("".equals(tempString)) { + continue; + } + + int count1 = tempString.indexOf(":"); + String meta = tempString.substring(0, count1).trim(); + + // Check for the package provider name + if (meta.equalsIgnoreCase(CommonConstant.MF_PROVIDER_META)) { + int count = tempString.indexOf(":") + 1; + basicInfo.setProvider(tempString.substring(count).trim()); + } + + // Check for package version + if (meta.equalsIgnoreCase(CommonConstant.MF_VERSION_META)) { + int count = tempString.indexOf(":") + 1; + basicInfo.setVersion(tempString.substring(count).trim()); + } + } + + reader.close(); + } catch (IOException e) { + LOG.error("Exception while parsing manifest file" + e, e); + } + + return basicInfo; + } /** * get package format enum. * @param format package format diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/test/filemanage/FileManageTest.java b/vnfmarket-be/vnf-sdk-marketplace/src/test/filemanage/FileManageTest.java new file mode 100644 index 00000000..2fbaf756 --- /dev/null +++ b/vnfmarket-be/vnf-sdk-marketplace/src/test/filemanage/FileManageTest.java @@ -0,0 +1,133 @@ +/** + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * 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. + */ + +package org.onap.vnfsdk.marketplace.filemanage; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import org.junit.Before; +import org.junit.Test; +import org.onap.vnfsdk.marketplace.filemanage.http.ToolUtil; + +import mockit.Mock; +import mockit.MockUp; + +public class FileManageTest { + + @Test + public void testCreateFileManager() { + new MockUp<FileManagerFactory>() { + @Mock + private FileManagerType getType() { + return FileManagerType.ftp; + } + }; + FileManager manager = FileManagerFactory.createFileManager(); + + assertNull(manager); + } + + @Test + public void testFileManagerFactoryConstructor() { + try { + Constructor<FileManagerFactory> constructor = FileManagerFactory.class.getDeclaredConstructor(); + assertTrue(Modifier.isPrivate(constructor.getModifiers())); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + } + + @Before + public void createTestFile() + { + String srcPath = "./srcPathForTest"; + String dstPath = "./dstPathForTest"; + File src = new File(srcPath); + File dst = new File(dstPath); + src.mkdir(); + dst.mkdir(); + } + + @Test + public void testDelete() throws IOException { + new MockUp<FileManagerFactory>() { + @Mock + private FileManagerType getType() { + return FileManagerType.http; + } + }; + + FileManager ManagerImpl = FileManagerFactory.createFileManager(); + String srcPath = "./srcPathForTest"; + new MockUp<ToolUtil>() { + @Mock + private String getHttpServerAbsolutePath() { + return null; + } + }; + new MockUp<ToolUtil>() { + @Mock + private boolean deleteDir(File dir) { + return true; + } + }; + + assertEquals(ManagerImpl.delete(srcPath), true); + } + + @Test + public void testUpload() throws IOException { + new MockUp<FileManagerFactory>() { + @Mock + private FileManagerType getType() { + return FileManagerType.http; + } + }; + + FileManager ManagerImpl = FileManagerFactory.createFileManager(); + String srcPath = "./srcPathForTest"; + String dstPath = "./dstPathForTest"; + new MockUp<ToolUtil>() { + @Mock + private String getHttpServerAbsolutePath() { + return null; + } + }; + new MockUp<ToolUtil>() { + @Mock + private boolean copyDirectory(String srcDirName, String destDirName, boolean overlay) { + return true; + } + }; + assertEquals(ManagerImpl.upload(srcPath, dstPath), true); + + File src = new File(srcPath); + if (src.exists()) + { + src.delete(); + } + + assertEquals(ManagerImpl.upload(srcPath, dstPath), false); + } + +} |