diff options
Diffstat (limited to 'vnfmarket-be/vnf-sdk-marketplace')
4 files changed, 123 insertions, 163 deletions
diff --git a/vnfmarket-be/vnf-sdk-marketplace/pom.xml b/vnfmarket-be/vnf-sdk-marketplace/pom.xml index 325f9053..d281b973 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/pom.xml +++ b/vnfmarket-be/vnf-sdk-marketplace/pom.xml @@ -51,7 +51,7 @@ <artifactId>log4j</artifactId> <version>1.2.16</version> </dependency> - + <dependency> <groupId>io.dropwizard</groupId> <artifactId>dropwizard-core</artifactId> @@ -98,7 +98,7 @@ <groupId>org.apache.httpcomponents</groupId> <artifactId>httpmime</artifactId> <version>4.5.2</version> - </dependency> + </dependency> <!-- consumer --> <dependency> <groupId>com.eclipsesource.jaxrs</groupId> @@ -118,11 +118,6 @@ <version>2.2.4</version> </dependency> <dependency> - <groupId>mysql</groupId> - <artifactId>mysql-connector-java</artifactId> - <version>5.1.18</version> - </dependency> - <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <version>42.1.1</version> @@ -170,31 +165,31 @@ <scope>test</scope> </dependency> <dependency> - <groupId>org.codehaus.jackson</groupId> - <artifactId>jackson-jaxrs</artifactId> - <version>1.9.2</version> - </dependency> - <dependency> - <groupId>org.codehaus.jackson</groupId> - <artifactId>jackson-mapper-asl</artifactId> - <version>1.9.2</version> - </dependency> - <dependency> - <groupId>net.sf.json-lib</groupId> - <artifactId>json-lib</artifactId> - <version>2.4</version> - <classifier>jdk15</classifier> - </dependency> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-io</artifactId> - <version>1.3.2</version> - </dependency> - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - <version>2.4</version> - </dependency> + <groupId>org.codehaus.jackson</groupId> + <artifactId>jackson-jaxrs</artifactId> + <version>1.9.2</version> + </dependency> + <dependency> + <groupId>org.codehaus.jackson</groupId> + <artifactId>jackson-mapper-asl</artifactId> + <version>1.9.2</version> + </dependency> + <dependency> + <groupId>net.sf.json-lib</groupId> + <artifactId>json-lib</artifactId> + <version>2.4</version> + <classifier>jdk15</classifier> + </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-io</artifactId> + <version>1.3.2</version> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>2.4</version> + </dependency> <!-- UT end --> </dependencies> <profiles> 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 e2514a88..2c22bdca 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 @@ -18,10 +18,11 @@ package org.onap.vnfsdk.marketplace.common; public class CommonErrorResponse { - private String code; - private String message; + public String getMessage() { + return message; + } public static Object failure(String message) { return message; @@ -33,3 +34,4 @@ public class CommonErrorResponse { } } + diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/filemanage/http/ToolUtil.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/filemanage/http/ToolUtil.java index 1b45e75f..1d5d46f9 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/filemanage/http/ToolUtil.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/filemanage/http/ToolUtil.java @@ -17,7 +17,6 @@ package org.onap.vnfsdk.marketplace.filemanage.http; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; @@ -31,6 +30,8 @@ import org.slf4j.LoggerFactory; public class ToolUtil { private static final Logger LOGGER = LoggerFactory.getLogger(ToolUtil.class); + private ToolUtil() { + } /** * copy from directory. * @param srcDirName source directory name @@ -42,49 +43,36 @@ public class ToolUtil { public static boolean copyDirectory(String srcDirName, String destDirName, boolean overlay) throws IOException { File srcDir = new File(srcDirName); - if (!srcDir.exists()) { - return false; - } else if (!srcDir.isDirectory()) { + if (!srcDir.exists() || !srcDir.isDirectory()) { return false; } - if (!destDirName.endsWith(File.separator)) { - destDirName = destDirName + File.separator; + String useDestDirName = destDirName; + if (!useDestDirName.endsWith(File.separator)) { + useDestDirName += File.separator; } - File destDir = new File(destDirName); - if (destDir.exists()) { - if (overlay) { + File destDir = new File(useDestDirName); + if (destDir.exists() && overlay) { new File(destDirName).delete(); - } else { + } else if ((destDir.exists() && !overlay) || (!destDir.exists() && !destDir.mkdirs())) { return false; - } - } else { - if (!destDir.mkdirs()) { - return false; - } } boolean flag = true; File[] files = srcDir.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isFile()) { flag = copyFile(files[i].getAbsolutePath(), destDirName + files[i].getName(), true); - if (!flag) { - break; - } } else if (files[i].isDirectory()) { flag = copyDirectory(files[i].getAbsolutePath(), destDirName + files[i].getName(), overlay); - if (!flag) { - break; - } + } + if (!flag) { + String message = "Copy catagory " + srcDirName + " to " + destDirName + " failed!"; + LOGGER.error(message); + return false; } } - if (!flag) { - String message = "Copy catagory " + srcDirName + " to " + destDirName + " failed!"; - LOGGER.error(message); - return false; - } else { - return true; - } + + return true; } /** @@ -97,56 +85,36 @@ public class ToolUtil { public static boolean copyFile(String srcFileName, String destFileName, boolean overlay) { File srcFile = new File(srcFileName); - if (!srcFile.exists()) { + if (!srcFile.exists() || !srcFile.isFile()) { String message = "Source file : " + srcFileName + " not exist !"; LOGGER.error(message); return false; - } else if (!srcFile.isFile()) { - return false; } File destFile = new File(destFileName); - if (destFile.exists()) { - if (overlay) { + if (destFile.exists() && overlay) { new File(destFileName).delete(); - } - } else { - if (!destFile.getParentFile().exists()) { - if (!destFile.getParentFile().mkdirs()) { - return false; - } - } + } else if (!destFile.exists() && !destFile.getParentFile().exists() && !destFile.getParentFile().mkdirs()) { + return false; } int byteread = 0; - InputStream in = null; - OutputStream out = null; - try { - in = new FileInputStream(srcFile); - out = new FileOutputStream(destFile); + try ( + InputStream in = new FileInputStream(srcFile); + OutputStream out = new FileOutputStream(destFile); + ) { byte[] buffer = new byte[1024]; while ((byteread = in.read(buffer)) != -1) { out.write(buffer, 0, byteread); } return true; - } catch (FileNotFoundException e1) { - return false; - } catch (IOException e1) { + } catch (IOException e) { + LOGGER.error("IOException in copyFile", e); return false; - } finally { - try { - if (out != null) { - out.close(); - } - if (in != null) { - in.close(); - } - } catch (IOException e1) { - e1.printStackTrace(); - } } + } /** @@ -155,18 +123,16 @@ public class ToolUtil { * @return boolean */ public static boolean createDir(String destDirName) { - File dir = new File(destDirName); + String useDestDirName = destDirName; + if (!useDestDirName.endsWith(File.separator)) { + useDestDirName += File.separator; + } + File dir = new File(useDestDirName); if (dir.exists()) { dir.delete(); } - if (!destDirName.endsWith(File.separator)) { - destDirName = destDirName + File.separator; - } - if (dir.mkdirs()) { - return true; - } else { - return false; - } + + return dir.mkdirs(); } public static String getHttpServerAbsolutePath() { @@ -190,9 +156,10 @@ public class ToolUtil { } return dir.delete(); } - + public static String getAppDeployPath() { return Thread.currentThread().getContextClassLoader().getResource("/").getPath(); } } + diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java index d9af683f..518d2060 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java @@ -31,7 +31,6 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; -import net.sf.json.JSONObject; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.glassfish.jersey.media.multipart.FormDataContentDisposition; @@ -54,12 +53,13 @@ import org.onap.vnfsdk.marketplace.onboarding.entity.OnBoardingSteps; import org.onap.vnfsdk.marketplace.onboarding.entity.OnBoradingRequest; import org.onap.vnfsdk.marketplace.onboarding.hooks.functiontest.FunctionTestExceutor; import org.onap.vnfsdk.marketplace.onboarding.hooks.functiontest.FunctionTestHook; -import org.onap.vnfsdk.marketplace.onboarding.hooks.validatelifecycle.LifecycleTestExceutor; import org.onap.vnfsdk.marketplace.onboarding.hooks.validatelifecycle.ValidateLifecycleTestResponse; import org.onap.vnfsdk.marketplace.onboarding.onboardmanager.OnBoardingHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import net.sf.json.JSONObject; + public class PackageWrapper { private static PackageWrapper packageWrapper; private static final Logger LOG = LoggerFactory.getLogger(PackageWrapper.class); @@ -227,48 +227,47 @@ public class PackageWrapper { uploadedInputStream.close(); PackageBasicInfo basicInfo = PackageWrapperUtil.getPacageBasicInfo(fileLocation); - if (null == basicInfo.getType() || null == basicInfo.getProvider() || null == basicInfo.getVersion()) - { - LOG.error("Package basicInfo is incorrect ! basicIonfo = " + ToolUtil.objectToString(basicInfo)); - return Response.serverError().build(); - } - UploadPackageResponse result = new UploadPackageResponse(); Boolean isEnd = PackageWrapperUtil.isUploadEnd(contentRange); if (isEnd) { PackageMeta packageMeta = PackageWrapperUtil.getPackageMeta(packageId,fileName, fileLocation, basicInfo, details); + try { + String path = basicInfo.getType().toString() + File.separator + basicInfo.getProvider() + File.separator + packageMeta.getCsarId() + File.separator + fileName.replace(".csar", "") + File.separator + basicInfo.getVersion(); - String path = basicInfo.getType().toString() + File.separator + basicInfo.getProvider() + File.separator + packageMeta.getCsarId() + File.separator + fileName.replace(".csar", "") + File.separator + basicInfo.getVersion(); - String dowloadUri = File.separator + path + File.separator; - packageMeta.setDownloadUri(dowloadUri); + String dowloadUri = File.separator + path + File.separator; + packageMeta.setDownloadUri(dowloadUri); - LOG.info("dest path is : " + path); - LOG.info("packageMeta = " + ToolUtil.objectToString(packageMeta)); + LOG.info("dest path is : " + path); + LOG.info("packageMeta = " + ToolUtil.objectToString(packageMeta)); - PackageData packageData = PackageWrapperUtil.getPackageData(packageMeta); + PackageData packageData = PackageWrapperUtil.getPackageData(packageMeta); - String destPath = File.separator + path + File.separator + File.separator; - boolean uploadResult = FileManagerFactory.createFileManager().upload(localDirName, destPath); - if (uploadResult) - { - OnBoradingRequest oOnboradingRequest = new OnBoradingRequest(); - oOnboradingRequest.setCsarId(packageId); - oOnboradingRequest.setPackageName(fileName); - oOnboradingRequest.setPackagePath(localDirName); + String destPath = File.separator + path + File.separator + File.separator; + boolean uploadResult = FileManagerFactory.createFileManager().upload(localDirName, destPath); + if (uploadResult) + { + OnBoradingRequest oOnboradingRequest = new OnBoradingRequest(); + oOnboradingRequest.setCsarId(packageId); + oOnboradingRequest.setPackageName(fileName); + oOnboradingRequest.setPackagePath(localDirName); - packageData.setCsarId(packageId); - packageData.setDownloadCount(-1); - PackageData packateDbData = PackageManager.getInstance().addPackage(packageData); + packageData.setCsarId(packageId); + packageData.setDownloadCount(-1); + PackageData packateDbData = PackageManager.getInstance().addPackage(packageData); - LOG.info("Store package data to database succed ! packateDbData = " + ToolUtil.objectToString(packateDbData)); - LOG.info("upload package file end, fileName:" + fileName); + LOG.info("Store package data to database succed ! packateDbData = " + ToolUtil.objectToString(packateDbData)); + LOG.info("upload package file end, fileName:" + fileName); - result.setCsarId(packateDbData.getCsarId()); + result.setCsarId(packateDbData.getCsarId()); - addOnBoardingRequest(oOnboradingRequest); + addOnBoardingRequest(oOnboradingRequest); - LOG.info("OnboradingRequest Data : " + ToolUtil.objectToString(oOnboradingRequest)); + LOG.info("OnboradingRequest Data : " + ToolUtil.objectToString(oOnboradingRequest)); + } + } catch (NullPointerException e) { + LOG.error("Package basicInfo is incorrect ! basicIonfo = " + ToolUtil.objectToString(basicInfo), e); + return Response.serverError().build(); } } return Response.ok(ToolUtil.objectToString(result), MediaType.APPLICATION_JSON).build(); @@ -281,14 +280,11 @@ public class PackageWrapper { private void addOnBoardingRequest(final OnBoradingRequest oOnboradingRequest) { ExecutorService es = Executors.newFixedThreadPool(CommonConstant.ONBOARDING_THREAD_COUNT); - es.submit(new Callable<Integer>() - { - public Integer call() throws Exception - { - new OnBoardingHandler().handleOnBoardingReq(oOnboradingRequest); - return CommonConstant.SUCESS; - } - }); + Callable<Integer> callableInteger = () -> { + new OnBoardingHandler().handleOnBoardingReq(oOnboradingRequest); + return CommonConstant.SUCESS; + }; + es.submit(callableInteger); } /** @@ -420,7 +416,7 @@ public class PackageWrapper { InputStream uploadedInputStream, FormDataContentDisposition fileDetail, String details, - HttpHeaders head) throws Exception + HttpHeaders head) throws IOException, MarketplaceResourceException { LOG.info("Reupload request Received !!!!"); @@ -452,28 +448,27 @@ public class PackageWrapper { public Response getOnBoardingResult(String csarId, String operTypeId, String operId) { LOG.info("getOnBoardingResult request : csarId:" + csarId + " operTypeId:" + operTypeId + " operId:" + operId); - if ((null == csarId) || (null == operTypeId) || (null == operId)) { - return Response.status(Response.Status.BAD_REQUEST).build(); - } - if ((csarId.isEmpty()) || (operTypeId.isEmpty()) || (operId.isEmpty())) { - return Response.status(Response.Status.BAD_REQUEST).build(); - } - PackageData packageData = PackageWrapperUtil.getPackageInfoById(csarId); - if (null == packageData) { - return Response.status(Response.Status.PRECONDITION_FAILED).build(); - } + try { + PackageData packageData = PackageWrapperUtil.getPackageInfoById(csarId); + if (null == packageData) { + return Response.status(Response.Status.PRECONDITION_FAILED).build(); + } - handleDelayExec(operId); + handleDelayExec(operId); - OnBoardingResult oOnBoardingResult = FunctionTestHook.getOnBoardingResult(packageData); - if (null == oOnBoardingResult) { - return Response.status(Response.Status.PRECONDITION_FAILED).build(); - } - filterOnBoardingResultByOperId(oOnBoardingResult, operId); + OnBoardingResult oOnBoardingResult = FunctionTestHook.getOnBoardingResult(packageData); + if (null == oOnBoardingResult) { + return Response.status(Response.Status.PRECONDITION_FAILED).build(); + } + filterOnBoardingResultByOperId(oOnBoardingResult, operId); - String strResult = ToolUtil.objectToString(oOnBoardingResult); - LOG.info("getOnBoardingResult response : " + strResult); - return Response.ok(strResult, "application/json").build(); + String strResult = ToolUtil.objectToString(oOnBoardingResult); + LOG.info("getOnBoardingResult response : " + strResult); + return Response.ok(strResult, "application/json").build(); + } catch (NullPointerException e) { + LOG.error("Null param in getOnBoardingResult", e); + return Response.status(Response.Status.BAD_REQUEST).build(); + } } @@ -484,7 +479,7 @@ public class PackageWrapper { } if (0 == operId.compareToIgnoreCase("download")) { - List<OnBoardingOperResult> operResultListTemp = new ArrayList<OnBoardingOperResult>(); + List<OnBoardingOperResult> operResultListTemp = new ArrayList<>(); OnBoardingOperResult operResultListTmp = new OnBoardingOperResult(); operResultListTmp.setOperId("download"); operResultListTmp.setStatus(0); @@ -492,7 +487,7 @@ public class PackageWrapper { oOnBoardingResult.setOperResult(operResultListTemp); return; } - List<OnBoardingOperResult> operResultListOut = new ArrayList<OnBoardingOperResult>(); + List<OnBoardingOperResult> operResultListOut = new ArrayList<>(); List<OnBoardingOperResult> operResultList = oOnBoardingResult.getOperResult(); for (OnBoardingOperResult operResult : operResultList) { if (0 == operResult.getOperId().compareToIgnoreCase(operId)) { @@ -576,6 +571,7 @@ public class PackageWrapper { catch (InterruptedException e) { LOG.info("handleDelayExex response : ", e); + Thread.currentThread().interrupt(); } } } |