From 46fb5720713fafcc47bb2d3db852728edff7a0ef Mon Sep 17 00:00:00 2001
From: nancylizi
Date: Mon, 26 Sep 2016 17:31:54 +0800
Subject: Change download uri of package, restore the bug in upload package.
Issue-id:TOSCA-81
Change-Id: I96964c84ac237f6e07ab4d63b409faec0de58c85
Signed-off-by: nancylizi
---
.../commontosca/catalog/wrapper/PackageWrapper.java | 16 +++++++++-------
.../commontosca/catalog/wrapper/PackageWrapperUtil.java | 10 +++++++---
2 files changed, 16 insertions(+), 10 deletions(-)
(limited to 'catalog-core/catalog-mgr/src/main/java')
diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/wrapper/PackageWrapper.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/wrapper/PackageWrapper.java
index dbe570c8..5bee0382 100644
--- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/wrapper/PackageWrapper.java
+++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/wrapper/PackageWrapper.java
@@ -70,8 +70,8 @@ public class PackageWrapper {
ArrayList dbResult = new ArrayList();
ArrayList result = new ArrayList();
dbResult = PackageWrapperUtil.getPackageInfoById(csarId);
- result = PackageWrapperUtil.packageDataList2PackageMetaList(dbResult);
- return Response.ok(result).build();
+ result = PackageWrapperUtil.packageDataList2PackageMetaList(dbResult);
+ return Response.ok(result).build();
}
/**
@@ -124,18 +124,19 @@ public class PackageWrapper {
packageMeta.setDownloadUri(dowloadUri);
LOG.info("packageMeta = " + ToolUtil.objectToString(packageMeta));
Boolean isEnd = PackageWrapperUtil.isUploadEnd(contentRange, fileName);
+ PackageData packateDbData = new PackageData();
if (isEnd) {
String serviceTemplateId = null;
boolean uploadResult = FileManagerFactory.createFileManager().upload(tempDirName, destPath);
if (uploadResult == true) {
PackageData packageData = PackageWrapperUtil.getPackageData(packageMeta);
- PackageData packateDbData = PackageManager.getInstance().addPackage(packageData);
+ packateDbData = PackageManager.getInstance().addPackage(packageData);
LOG.info("Store package data to database succed ! packateDbData = "
+ ToolUtil.objectToString(packateDbData));
try {
String tempCsarPath = tempDirName + File.separator + fileName;
- serviceTemplateId = ModelParserFactory.getInstance().parse(packageMeta.getCsarId(),
- tempCsarPath, PackageWrapperUtil.getPackageFormat(packageMeta.getFormat()));
+ serviceTemplateId = ModelParserFactory.getInstance().parse(packateDbData.getCsarId(),
+ tempCsarPath, PackageWrapperUtil.getPackageFormat(packateDbData.getFormat()));
LOG.info("Package parse success ! serviceTemplateId = " + serviceTemplateId);
} catch (Exception e1) {
LOG.error("Parse package error ! ");
@@ -143,14 +144,15 @@ public class PackageWrapper {
throw new Exception(e1);
}
- if (null != packateDbData || null == serviceTemplateId) {
+ if (null != packateDbData && null == serviceTemplateId) {
+ LOG.info("Service template Id is null !");
PackageManager.getInstance().deletePackage(packateDbData.getCsarId());
}
}
LOG.info("upload package file end, fileName:" + fileName);
}
UploadPackageResponse result = new UploadPackageResponse();
- result.setCsarId(packageMeta.getCsarId());
+ result.setCsarId(packateDbData.getCsarId());
if (tempDirName != null) {
ToolUtil.deleteDir(new File(tempDirName));
}
diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/wrapper/PackageWrapperUtil.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/wrapper/PackageWrapperUtil.java
index 75d02af6..288248f1 100644
--- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/wrapper/PackageWrapperUtil.java
+++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/wrapper/PackageWrapperUtil.java
@@ -339,13 +339,17 @@ public class PackageWrapperUtil {
// url = MsbAddrConfig.getMsbAddress() + uri.substring(1);
// }
// url = MsbAddrConfig.getMsbAddress() + uri;
- if ((HttpServerAddrConfig.getHttpServerAddress().endsWith("/")) && uri.startsWith("/")) {
- url = HttpServerAddrConfig.getHttpServerAddress() + uri.substring(1);
+ if ((getDownloadUriHead().endsWith("/")) && uri.startsWith("/")) {
+ url = getDownloadUriHead() + uri.substring(1);
}
- url = MsbAddrConfig.getMsbAddress() + uri;
+ url = getDownloadUriHead() + uri;
String urlresult = url.replace("\\", "/");
return urlresult;
}
+
+ public static String getDownloadUriHead() {
+ return MsbAddrConfig.getMsbAddress() + "/files/catalog-http";
+ }
/**
* get local path.
--
cgit 1.2.3-korg