summaryrefslogtreecommitdiffstats
path: root/catalog-core
diff options
context:
space:
mode:
authornancylizi <li.zi30@zte.com.cn>2016-09-26 17:31:54 +0800
committernancylizi <li.zi30@zte.com.cn>2016-09-26 17:31:54 +0800
commit46fb5720713fafcc47bb2d3db852728edff7a0ef (patch)
tree915539cfc5c5f185c436aac986262b8c221dbfc0 /catalog-core
parentf8a3c48b5ca94ffb04903b252c032073d17c83a9 (diff)
Change download uri of package, restore the bug in upload package.
Issue-id:TOSCA-81 Change-Id: I96964c84ac237f6e07ab4d63b409faec0de58c85 Signed-off-by: nancylizi <li.zi30@zte.com.cn>
Diffstat (limited to 'catalog-core')
-rw-r--r--catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/wrapper/PackageWrapper.java16
-rw-r--r--catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/wrapper/PackageWrapperUtil.java10
-rw-r--r--catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/wrapper/PackageWrapperTest.java13
-rw-r--r--catalog-core/catalog-mgr/src/test/resources/NanocellGW.csarbin978854 -> 80812 bytes
4 files changed, 24 insertions, 15 deletions
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<PackageData> dbResult = new ArrayList<PackageData>();
ArrayList<PackageMeta> result = new ArrayList<PackageMeta>();
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.
diff --git a/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/wrapper/PackageWrapperTest.java b/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/wrapper/PackageWrapperTest.java
index d6dc15b9..b4f838ec 100644
--- a/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/wrapper/PackageWrapperTest.java
+++ b/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/wrapper/PackageWrapperTest.java
@@ -192,10 +192,9 @@ public class PackageWrapperTest {
System.out.println("Test get csar file uri ");
CsarFileUriResponse expectResult = new CsarFileUriResponse();
String csarFileUri =
- MsbAddrConfig.getMsbAddress() + "/NSAR/ZTE/NanocellGW/v1.0/NanocellGW/images/segw.img";
- String localUri =
- HttpServerPathConfig.getHttpServerPath()
- + "NSAR/ZTE/NanocellGW/v1.0/NanocellGW/images/segw.img";
+ getDownloadUriHead() + "/NSAR/ZTE/NanocellGW/v1.0/NanocellGW/images/segw.img";
+ String localUri = HttpServerPathConfig.getHttpServerPath()
+ + "NSAR/ZTE/NanocellGW/v1.0/NanocellGW/images/segw.img";
File srcDir = new File(localUri);
String localPath = srcDir.getAbsolutePath().replace("\\", "/");
@@ -272,7 +271,7 @@ public class PackageWrapperTest {
meta.setCreateTime("2016-06-29 03:33:15");
meta.setCsarId("123456");
meta.setDeletionPending(false);
- meta.setDownloadUri(MsbAddrConfig.getMsbAddress()
+ meta.setDownloadUri(getDownloadUriHead()
+ "/NSAR/ZTE/NanocellGW/v1.0/NanocellGW.csar");
meta.setFormat("yml");
meta.setModifyTime("2016-06-29 03:33:15");
@@ -289,4 +288,8 @@ public class PackageWrapperTest {
metas.add(meta);
return metas;
}
+
+ private String getDownloadUriHead() {
+ return MsbAddrConfig.getMsbAddress() + "/files/catalog-http";
+ }
}
diff --git a/catalog-core/catalog-mgr/src/test/resources/NanocellGW.csar b/catalog-core/catalog-mgr/src/test/resources/NanocellGW.csar
index d9efb502..d41b6b99 100644
--- a/catalog-core/catalog-mgr/src/test/resources/NanocellGW.csar
+++ b/catalog-core/catalog-mgr/src/test/resources/NanocellGW.csar
Binary files differ