From 93e083fb82a86a07ba94cd17b308862b2f11fafa Mon Sep 17 00:00:00 2001 From: YuanHu Date: Tue, 6 Sep 2016 11:25:05 +0800 Subject: Put the csar package to the httpserver and post the path to the parser. Change-Id: Icbb40a431c7202e41b957031d4500104a67cfc9d Signed-off-by: YuanHu --- .../catalog/model/parser/ToscaYamlModelParser.java | 43 ++++++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) (limited to 'catalog-core') 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 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 parseToscaMeta(String fileLocation) throws CatalogResourceException { Map toscaMeta = new HashMap<>(); -- cgit 1.2.3-korg