aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-core
diff options
context:
space:
mode:
authorYuanHu <yuan.hu1@zte.com.cn>2016-09-06 11:25:05 +0800
committerYuanHu <yuan.hu1@zte.com.cn>2016-09-06 11:25:05 +0800
commit93e083fb82a86a07ba94cd17b308862b2f11fafa (patch)
treef9f4b2a2a63e9f0fd6236e43e430c7969709a7cf /catalog-core
parent663812633300ea2b64e159137248a140965bf31b (diff)
Put the csar package to the httpserver and post the path to the parser.
Change-Id: Icbb40a431c7202e41b957031d4500104a67cfc9d Signed-off-by: YuanHu <yuan.hu1@zte.com.cn>
Diffstat (limited to 'catalog-core')
-rw-r--r--catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/ToscaYamlModelParser.java43
1 files changed, 40 insertions, 3 deletions
diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/ToscaYamlModelParser.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/ToscaYamlModelParser.java
index 773cc1b4..ac381e7d 100644
--- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/ToscaYamlModelParser.java
+++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/ToscaYamlModelParser.java
@@ -16,6 +16,7 @@
package org.openo.commontosca.catalog.model.parser;
+import org.openo.commontosca.catalog.common.MsbAddrConfig;
import org.openo.commontosca.catalog.common.ToolUtil;
import org.openo.commontosca.catalog.db.exception.CatalogResourceException;
import org.openo.commontosca.catalog.db.resource.TemplateManager;
@@ -67,9 +68,8 @@ public class ToscaYamlModelParser extends AbstractModelParser {
@Override
public String parse(String packageId, String fileLocation) throws CatalogResourceException {
- ParseYamlResult result =
- YamlParseServiceConsumer.getServiceTemplates(comboRequest(fileLocation));
-
+ ParseYamlResult result = getParseYamlResult(fileLocation);
+
Map<String, String> toscaMeta = parseToscaMeta(fileLocation);
String stFileName = toscaMeta.get(TOSCA_META_FIELD_ENTRY_DEFINITIONS);
CsarFileUriResponse stDownloadUri =
@@ -93,6 +93,43 @@ public class ToscaYamlModelParser extends AbstractModelParser {
return st.getServiceTemplateId();
}
+ private ParseYamlResult getParseYamlResult(String fileLocation) throws CatalogResourceException {
+ String destPath = copyTemporaryFile2HttpServer(fileLocation);
+ try {
+ String url = getUrl(toTempFileLocalPath(fileLocation));
+ return YamlParseServiceConsumer.getServiceTemplates(comboRequest(url));
+ } finally {
+ if (destPath != null && !destPath.isEmpty() && (new File(destPath)).exists()) {
+ (new File(destPath)).deleteOnExit();
+ }
+ }
+ }
+
+ private String toTempFileLocalPath(String fileLocation) {
+ return File.separator + "temp" + File.separator + (new File(fileLocation)).getName();
+ }
+
+ private String getUrl(String uri) {
+ String url = null;
+ if ((MsbAddrConfig.getMsbAddress().endsWith("/")) && uri.startsWith("/")) {
+ url = MsbAddrConfig.getMsbAddress() + uri.substring(1);
+ }
+ url = MsbAddrConfig.getMsbAddress() + uri;
+ String urlresult = url.replace("\\", "/");
+ return urlresult;
+ }
+
+ private String copyTemporaryFile2HttpServer(String fileLocation) throws CatalogResourceException {
+ String destPath = Class.class.getClass().getResource("/").getPath()
+ + org.openo.commontosca.catalog.filemanage.http.ToolUtil.getHttpServerPath()
+ + toTempFileLocalPath(fileLocation);
+ if (!org.openo.commontosca.catalog.filemanage.http.ToolUtil.copyFile(fileLocation, destPath,
+ true)) {
+ throw new CatalogResourceException("Copy Temporary To HttpServer Failed.");
+ }
+ return destPath;
+ }
+
@SuppressWarnings("resource")
private Map<String, String> parseToscaMeta(String fileLocation) throws CatalogResourceException {
Map<String, String> toscaMeta = new HashMap<>();