summaryrefslogtreecommitdiffstats
path: root/vnfmarket-be/vnf-sdk-marketplace/src
diff options
context:
space:
mode:
Diffstat (limited to 'vnfmarket-be/vnf-sdk-marketplace/src')
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/CommonErrorResponse.java6
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/filemanage/http/ToolUtil.java105
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/resource/PackageResource.java2
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java286
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapperUtil.java102
5 files changed, 207 insertions, 294 deletions
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/resource/PackageResource.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/resource/PackageResource.java
index 83babfa2..7ad48c61 100644
--- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/resource/PackageResource.java
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/resource/PackageResource.java
@@ -73,7 +73,7 @@ public class PackageResource {
@ApiParam(value = "http header") @Context HttpHeaders head
) throws Exception {
InputStream input = request.getInputStream();
- return PackageWrapper.getInstance().updateValidateStatus(input, head);
+ return PackageWrapper.getInstance().updateValidateStatus(input);
}
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 e21418f9..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);
@@ -75,7 +75,7 @@ public class PackageWrapper {
return packageWrapper;
}
- public Response updateValidateStatus(InputStream inputStream, HttpHeaders head) throws Exception
+ public Response updateValidateStatus(InputStream inputStream) throws IOException
{
String reqParam = IOUtils.toString(inputStream);
LOG.info("updateValidateStatus request param:"+reqParam);
@@ -83,39 +83,39 @@ public class PackageWrapper {
LOG.error("The updateValidateStatus request params can't be null");
return Response.status(Status.EXPECTATION_FAILED).build();
}
-
+
ValidateLifecycleTestResponse lyfValidateResp = JsonUtil.fromJson(reqParam, ValidateLifecycleTestResponse.class);
if(!checkOperationSucess(lyfValidateResp))
{
return Response.status(Status.EXPECTATION_FAILED).build();
}
-
+
String funcTestResponse = FunctionTestExceutor.executeFunctionTest(reqParam);
if(null == funcTestResponse)
{
return Response.status(Status.EXPECTATION_FAILED).build();
}
-
- JSONObject funcTestRspObject = JSONObject.fromObject(funcTestResponse);
+
+ JSONObject funcTestRspObject = JSONObject.fromObject(funcTestResponse);
if(!funcTestRspObject.get("status").equals(CommonConstant.SUCCESS_STR))
{
return Response.status(Status.EXPECTATION_FAILED).build();
}
-
- JSONObject result = new JSONObject();
+
+ JSONObject result = new JSONObject();
result.put("msg","SUCCESS");
return Response.ok(ToolUtil.objectToString(result), MediaType.APPLICATION_JSON).build();
}
-
- private boolean checkOperationSucess(ValidateLifecycleTestResponse lyfValidateResp)
+
+ private boolean checkOperationSucess(ValidateLifecycleTestResponse lyfValidateResp)
{
boolean bOperStatus = false;
- if(null == lyfValidateResp)
+ if(null == lyfValidateResp)
{
LOG.error("ValidateLifecycleTestResponse is NUll !!!");
return bOperStatus;
}
- if(lyfValidateResp.getLifecycle_status().equalsIgnoreCase(CommonConstant.SUCCESS_STR)
+ if(lyfValidateResp.getLifecycle_status().equalsIgnoreCase(CommonConstant.SUCCESS_STR)
&& lyfValidateResp.getValidate_status().equalsIgnoreCase(CommonConstant.SUCCESS_STR))
{
LOG.error("Lifecycle/Validation Response failed :" + lyfValidateResp.getLifecycle_status() + File.separator + lyfValidateResp.getValidate_status());
@@ -135,8 +135,8 @@ public class PackageWrapper {
*/
public Response queryPackageListByCond(String name, String provider, String version,
String deletionPending, String type) {
- ArrayList<PackageData> dbresult = new ArrayList<PackageData>();
- List<PackageMeta> result = new ArrayList<PackageMeta>();
+ ArrayList<PackageData> dbresult = new ArrayList<>();
+ List<PackageMeta> result = new ArrayList<>();
LOG.info("query package info.name:" + name + " provider:" + provider + " version" + version
+ " deletionPending" + deletionPending + " type:" + type);
try {
@@ -156,10 +156,8 @@ public class PackageWrapper {
* @return Response
*/
public Response queryPackageById(String csarId) {
- PackageData dbResult = new PackageData();
- PackageMeta result = new PackageMeta();
- dbResult = PackageWrapperUtil.getPackageInfoById(csarId);
- result = PackageWrapperUtil.packageData2PackageMeta(dbResult);
+ PackageData dbResult = PackageWrapperUtil.getPackageInfoById(csarId);
+ PackageMeta result = PackageWrapperUtil.packageData2PackageMeta(dbResult);
return Response.ok(ToolUtil.objectToString(result)).build();
}
@@ -172,10 +170,10 @@ public class PackageWrapper {
* @throws Exception e
*/
public Response uploadPackage(InputStream uploadedInputStream,
- FormDataContentDisposition fileDetail, String details, HttpHeaders head) throws Exception
+ FormDataContentDisposition fileDetail, String details, HttpHeaders head) throws IOException, MarketplaceResourceException
{
LOG.info("Upload/Reupload request Received !!!!");
-
+
String packageId = MarketplaceDbUtil.generateId();
return handlePackageUpload(packageId,uploadedInputStream, fileDetail, details, head);
}
@@ -192,8 +190,8 @@ public class PackageWrapper {
* @throws MarketplaceResourceException
*/
private Response handlePackageUpload(String packageId,InputStream uploadedInputStream, FormDataContentDisposition fileDetail,
- String details, HttpHeaders head) throws IOException, MarketplaceResourceException
- {
+ String details, HttpHeaders head) throws IOException, MarketplaceResourceException
+ {
boolean bResult = handleDataValidate(packageId,uploadedInputStream,fileDetail);
if(!bResult)
{
@@ -208,11 +206,11 @@ public class PackageWrapper {
fileName = ToolUtil.processFileName(fileDetail.getFileName());
}
-
+
String localDirName = ToolUtil.getTempDir(CommonConstant.CATALOG_CSAR_DIR_NAME, fileName);
String contentRange = null;
- if (head != null)
+ if (head != null)
{
contentRange = head.getHeaderString(CommonConstant.HTTP_HEADER_CONTENT_RANGE);
}
@@ -228,66 +226,48 @@ 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();
+ PackageBasicInfo basicInfo = PackageWrapperUtil.getPacageBasicInfo(fileLocation);
+ UploadPackageResponse result = new UploadPackageResponse();
Boolean isEnd = PackageWrapperUtil.isUploadEnd(contentRange);
- if (isEnd)
+ if (isEnd)
{
PackageMeta packageMeta = PackageWrapperUtil.getPackageMeta(packageId,fileName, fileLocation, basicInfo, details);
-
- 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);
-
- LOG.info("dest path is : " + path);
- LOG.info("packageMeta = " + ToolUtil.objectToString(packageMeta));
-
- PackageData packageData = PackageWrapperUtil.getPackageData(packageMeta);
-
- String destPath = File.separator + path + File.separator + File.separator;
- boolean uploadResult = FileManagerFactory.createFileManager().upload(localDirName, destPath);
- if (uploadResult)
- {
- //Create OnBoarding Request
- //--------------------------
- OnBoradingRequest oOnboradingRequest = new OnBoradingRequest();
- oOnboradingRequest.setCsarId(packageId);
- oOnboradingRequest.setPackageName(fileName);
- oOnboradingRequest.setPackagePath(localDirName);
-
- //Upload the Package to CATALOUGE and get CSARID
- //---------------------------------------------
- //String catalougeCsarId = LifecycleTestExceutor.uploadPackageToCatalouge(oOnboradingRequest);
- //if((null == catalougeCsarId) || catalougeCsarId.isEmpty())
- //{
- // LOG.error("Failed to Upload Package to catalougeCsarId " + ToolUtil.objectToString(basicInfo));
- //return Response.status(Status.INTERNAL_SERVER_ERROR).build();
- // }
- //oOnboradingRequest.setCsarIdCatalouge(catalougeCsarId);
- //LOG.info("catalougeCsarId :" + catalougeCsarId);
-
-
- //Update Default download count to -1
- 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);
-
- result.setCsarId(packateDbData.getCsarId());
-
- //Assign OnBoarding Request to OnBoarding Handler
- //------------------------------------------------
- addOnBoardingRequest(oOnboradingRequest);
-
- LOG.info("OnboradingRequest Data : " + ToolUtil.objectToString(oOnboradingRequest));
+ try {
+ 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);
+
+ LOG.info("dest path is : " + path);
+ LOG.info("packageMeta = " + ToolUtil.objectToString(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);
+
+ 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);
+
+ result.setCsarId(packateDbData.getCsarId());
+
+ addOnBoardingRequest(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();
@@ -297,17 +277,14 @@ public class PackageWrapper {
* Execute OnBarding request
* @param oOnboradingRequest
*/
- private void addOnBoardingRequest(final OnBoradingRequest oOnboradingRequest)
+ 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);
}
/**
@@ -334,13 +311,13 @@ public class PackageWrapper {
if (packagePath == null) {
LOG.error("package path is null! ");
}
-
+
//Delete Package
FileManagerFactory.createFileManager().delete(packagePath);
//Delete Results Data
FileManagerFactory.createFileManager().delete(File.separator + csarId);
-
+
//delete package data from database
try {
PackageManager.getInstance().deletePackage(csarId);
@@ -356,29 +333,29 @@ public class PackageWrapper {
*/
public Response downloadCsarPackagesById(String csarId) {
PackageData packageData = PackageWrapperUtil.getPackageInfoById(csarId);
-
+
String packageName = packageData.getName();
String path = org.onap.vnfsdk.marketplace.filemanage.http.ToolUtil.getHttpServerAbsolutePath() +File.separatorChar+packageData.getType()+File.separatorChar+
- packageData.getProvider()+File.separatorChar+ packageData.getCsarId() +File.separator +packageName+File.separatorChar+packageData.getVersion()
+ packageData.getProvider()+File.separatorChar+ packageData.getCsarId() +File.separator +packageName+File.separatorChar+packageData.getVersion()
+File.separator + packageName + ".csar";
-
+
LOG.info("downloadCsarPackagesById path is : " + path);
-
+
File csarFile = new File(path);
if (!csarFile.exists()) {
return Response.status(Status.INTERNAL_SERVER_ERROR).build();
}
LOG.info("downloadCsarPackagesById ABS path is : " + csarFile.getAbsolutePath());
-
- try
+
+ try
{
InputStream fis = new BufferedInputStream(new FileInputStream(csarFile.getAbsolutePath()));
return Response.ok(fis)
.header("Content-Disposition", "attachment; filename=\"" + csarFile.getName() + "\"")
.build();
- }
- catch (Exception e1)
+ }
+ catch (Exception e1)
{
LOG.error("download vnf package fail.", e1);
return RestUtil.getRestException(e1.getMessage());
@@ -401,8 +378,8 @@ public class PackageWrapper {
* @return
*/
public Response updateDwonloadCount(String csarId) {
- return handleDownladCountUpdate(csarId) ?
- Response.ok().build() :
+ return handleDownladCountUpdate(csarId) ?
+ Response.ok().build() :
Response.status(Status.EXPECTATION_FAILED).build();
}
@@ -413,12 +390,12 @@ public class PackageWrapper {
*/
private boolean handleDownladCountUpdate(String csarId) {
boolean bupdateSucess = false;
- try
+ try
{
PackageManager.getInstance().updateDwonloadCount(csarId);
bupdateSucess = true;
- }
- catch (Exception exp)
+ }
+ catch (Exception exp)
{
LOG.error("Updating Donwload count failed for Package with ID !!! : " + exp.getMessage(), exp);
}
@@ -426,7 +403,7 @@ public class PackageWrapper {
}
/**
- * Interface to Re upload Package
+ * Interface to Re upload Package
* @param csarId
* @param uploadedInputStream
* @param fileDetail
@@ -436,14 +413,14 @@ public class PackageWrapper {
* @throws Exception
*/
public Response reUploadPackage(String csarId,
- InputStream uploadedInputStream,
+ InputStream uploadedInputStream,
FormDataContentDisposition fileDetail,
- String details,
- HttpHeaders head) throws Exception
+ String details,
+ HttpHeaders head) throws IOException, MarketplaceResourceException
{
LOG.info("Reupload request Received !!!!");
-
- //STEP 1: Validate Input Data
+
+ //STEP 1: Validate Input Data
//----------------------------
boolean bResult = handleDataValidate(csarId,uploadedInputStream,fileDetail);
if(!bResult)
@@ -471,31 +448,30 @@ 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())) {
+ try {
+ PackageData packageData = PackageWrapperUtil.getPackageInfoById(csarId);
+ if (null == packageData) {
+ return Response.status(Response.Status.PRECONDITION_FAILED).build();
+ }
+
+ handleDelayExec(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();
+ } catch (NullPointerException e) {
+ LOG.error("Null param in getOnBoardingResult", e);
return Response.status(Response.Status.BAD_REQUEST).build();
}
- PackageData packageData = PackageWrapperUtil.getPackageInfoById(csarId);
- if (null == packageData) {
- return Response.status(Response.Status.PRECONDITION_FAILED).build();
- }
-
- handleDelayExec(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();
}
-
+
private void filterOnBoardingResultByOperId(OnBoardingResult oOnBoardingResult, String operId)
{
if (0 == operId.compareToIgnoreCase("all")) {
@@ -503,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);
@@ -511,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)) {
@@ -527,37 +503,37 @@ public class PackageWrapper {
* @param operTypeId
* @return
*/
- public Response getOperResultByOperTypeId(String csarId, String operTypeId)
+ public Response getOperResultByOperTypeId(String csarId, String operTypeId)
{
- LOG.error("getOnBoardingResult request : csarId:"+ csarId + " operTypeId:"+operTypeId);
+ LOG.error("getOnBoardingResult request : csarId:"+ csarId + " operTypeId:"+operTypeId);
if(null == csarId || null == operTypeId || csarId.isEmpty() || operTypeId.isEmpty())
{
- return Response.status(Status.BAD_REQUEST).build();
+ return Response.status(Status.BAD_REQUEST).build();
}
PackageData packageData = PackageWrapperUtil.getPackageInfoById(csarId);
if(null == packageData)
{
- LOG.error("Failed to find package for PackageID:"+ csarId);
- return Response.status(Status.PRECONDITION_FAILED).build();
- }
+ LOG.error("Failed to find package for PackageID:"+ csarId);
+ return Response.status(Status.PRECONDITION_FAILED).build();
+ }
//Get result key to fetch Function Test Results
//---------------------------------------------
String strResult = FunctionTestHook.getFuncTestResults(packageData);
if(null == strResult)
{
- LOG.error("NULL reponse for getOperResultByOperTypeId response :"+ strResult);
- return Response.status(Status.INTERNAL_SERVER_ERROR).build();
- }
- LOG.info("getOperResultByOperTypeId response :"+ strResult);
+ LOG.error("NULL reponse for getOperResultByOperTypeId response :"+ strResult);
+ return Response.status(Status.INTERNAL_SERVER_ERROR).build();
+ }
+ LOG.info("getOperResultByOperTypeId response :"+ strResult);
return Response.ok(strResult, MediaType.APPLICATION_JSON).build();
}
- private boolean handleDataValidate(String packageId,InputStream uploadedInputStream, FormDataContentDisposition fileDetail)
+ private boolean handleDataValidate(String packageId,InputStream uploadedInputStream, FormDataContentDisposition fileDetail)
{
boolean bvalidateOk = false;
- if ((null != uploadedInputStream) && (fileDetail != null) && !ToolUtil.isEmptyString(packageId))
+ if ((null != uploadedInputStream) && (fileDetail != null) && !ToolUtil.isEmptyString(packageId))
{
bvalidateOk = true;
}
@@ -572,7 +548,7 @@ public class PackageWrapper {
{
LOG.info("Get OnBoarding Steps request Received !!!");
- String filePath = org.onap.vnfsdk.marketplace.filemanage.http.ToolUtil.getAppDeployPath() + File.separator +"generalconfig/OnBoardingSteps.json";
+ String filePath = org.onap.vnfsdk.marketplace.filemanage.http.ToolUtil.getAppDeployPath() + File.separator +"generalconfig/OnBoardingSteps.json";
LOG.info("Onboarding Steps Json file Path :" + filePath);
OnBoardingSteps oOnBoardingSteps = (OnBoardingSteps)FileUtil.readJsonDatafFromFile(filePath, OnBoardingSteps.class);
@@ -583,19 +559,21 @@ public class PackageWrapper {
LOG.info("getOnBoardingSteps response :" + strResult);
return Response.ok(strResult, MediaType.APPLICATION_JSON).build();
}
-
- private void handleDelayExec(String operId)
+
+ private void handleDelayExec(String operId)
{
- if (0 == operId.compareToIgnoreCase(CommonConstant.functionTest.FUNCTEST_EXEC))
+ if (0 == operId.compareToIgnoreCase(CommonConstant.functionTest.FUNCTEST_EXEC))
{
- try
+ try
{
Thread.sleep(8000);
- }
- catch (InterruptedException e)
+ }
+ catch (InterruptedException e)
{
LOG.info("handleDelayExex response : ", e);
+ Thread.currentThread().interrupt();
}
}
}
}
+
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 a763a361..e3bfe0e4 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
@@ -113,7 +113,7 @@ public class PackageWrapperUtil {
result = PackageManager.getInstance().queryPackageByCsarId(csarId).get(0);
}
} catch (MarketplaceResourceException e1) {
- LOG.error("query package by csarId from db error ! " + e1.getMessage());
+ LOG.error("query package by csarId from db error ! " + e1.getMessage(), e1);
}
return result;
}
@@ -130,12 +130,10 @@ public class PackageWrapperUtil {
PackageMeta packageMeta = new PackageMeta();
long size = getPacakgeSize(fileLocation);
packageMeta.setFormat(basic.getFormat());
- String usedPackageId = null;
+ String usedPackageId = packageId;
if(null == packageId)
{
usedPackageId = ToolUtil.generateId();
- } else {
- usedPackageId = packageId;
}
packageMeta.setCsarId(usedPackageId);
@@ -167,13 +165,13 @@ public class PackageWrapperUtil {
* @return download uri
*/
public static String getPackagePath(String csarId) {
- ArrayList<PackageData> packageList = new ArrayList<PackageData>();
+ ArrayList<PackageData> packageList = new ArrayList<>();
String downloadUri = null;
try {
packageList = PackageManager.getInstance().queryPackageByCsarId(csarId);
downloadUri = packageList.get(0).getDownloadUri();
} catch (MarketplaceResourceException e1) {
- LOG.error("Query CSAR package by ID failed ! csarId = " + csarId);
+ LOG.error("Query CSAR package by ID failed ! csarId = " + csarId, e1);
}
return downloadUri;
}
@@ -198,11 +196,10 @@ public class PackageWrapperUtil {
public static List<PackageMeta> packageDataList2PackageMetaList(
List<PackageData> dbResult) {
ArrayList<PackageMeta> metas = new ArrayList<>();
- PackageMeta meta = null;
if (! dbResult.isEmpty()) {
for (int i = 0; i < dbResult.size(); i++) {
PackageData data = dbResult.get(i);
- meta = packageData2PackageMeta(data);
+ PackageMeta meta = packageData2PackageMeta(data);
metas.add(meta);
}
}
@@ -245,8 +242,7 @@ public class PackageWrapperUtil {
} else {
url += uri;
}
- String urlresult = url.replace("\\", "/");
- return urlresult;
+ return url.replace("\\", "/");
}
public static String getDownloadUriHead() {
@@ -280,15 +276,15 @@ public class PackageWrapperUtil {
isXmlCsar = true;
}
for (String unzipFile : unzipFiles) {
- if (unzipFile.endsWith(CommonConstant.MANIFEST)) {
- basicInfo = readManifest(unzipFile);
+ if (unzipFile.endsWith(CommonConstant.MANIFEST)) {
+ basicInfo = readManifest(unzipFile);
}
if (ToolUtil.isYamlFile(new File(unzipFile))) {
isXmlCsar = false;
}
}
} catch (IOException e1) {
- LOG.error("judge package type error ! " + e1.getMessage());
+ LOG.error("judge package type error ! " + e1.getMessage(), e1);
}
if (isXmlCsar) {
basicInfo.setFormat(CommonConstant.PACKAGE_XML_FORMAT);
@@ -298,81 +294,51 @@ public class PackageWrapperUtil {
return basicInfo;
}
- private static PackageBasicInfo readCsarMeta(String unzipFile) {
+ /**
+ * Reads the manifest file in the package and fills the basic infor about package
+ * @param unzipFile
+ * @return basic infor about package
+ */
+ 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))) {
+
String tempString = null;
while ((tempString = reader.readLine()) != null) {
- if (tempString.equals("")) {
+
+ // If line is empty, ignore
+ if ("".equals(tempString)) {
continue;
}
+
int count1 = tempString.indexOf(":");
String meta = tempString.substring(0, count1).trim();
- if (CommonConstant.CSAR_TYPE_META.equalsIgnoreCase(meta)) {
- int count = tempString.indexOf(":") + 1;
- basicInfo.setType(EnumType.valueOf(tempString.substring(count).trim()));
- }
- if (CommonConstant.CSAR_PROVIDER_META.equalsIgnoreCase(meta)) {
+
+ // Check for the package provider name
+ if (meta.equalsIgnoreCase(CommonConstant.MF_PROVIDER_META)) {
int count = tempString.indexOf(":") + 1;
basicInfo.setProvider(tempString.substring(count).trim());
}
- if (CommonConstant.CSAR_VERSION_META.equalsIgnoreCase(meta)) {
+
+ // 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 e2) {
- e2.printStackTrace();
+ } catch (IOException e) {
+ LOG.error("Exception while parsing manifest file" + e, e);
}
+
return basicInfo;
}
- /**
- * Reads the manifest file in the package and fills the basic infor about package
- * @param unzipFile
- * @return basic infor about package
- */
- 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))) {
-
- String tempString = null;
- while ((tempString = reader.readLine()) != null) {
-
- // If line is empty, ignore
- if (tempString.equals("")) {
- 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);
- }
-
- return basicInfo;
- }
/**
* get package format enum.
* @param format package format