Put the csar package to the httpserver and post the path to the parser.
authorYuanHu <yuan.hu1@zte.com.cn>
Tue, 6 Sep 2016 03:25:05 +0000 (11:25 +0800)
committerYuanHu <yuan.hu1@zte.com.cn>
Tue, 6 Sep 2016 03:25:05 +0000 (11:25 +0800)
Change-Id: Icbb40a431c7202e41b957031d4500104a67cfc9d
Signed-off-by: YuanHu <yuan.hu1@zte.com.cn>
catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/ToscaYamlModelParser.java

index 773cc1b..ac381e7 100644 (file)
@@ -16,6 +16,7 @@
 \r
 package org.openo.commontosca.catalog.model.parser;\r
 \r
+import org.openo.commontosca.catalog.common.MsbAddrConfig;\r
 import org.openo.commontosca.catalog.common.ToolUtil;\r
 import org.openo.commontosca.catalog.db.exception.CatalogResourceException;\r
 import org.openo.commontosca.catalog.db.resource.TemplateManager;\r
@@ -67,9 +68,8 @@ public class ToscaYamlModelParser extends AbstractModelParser {
 \r
   @Override\r
   public String parse(String packageId, String fileLocation) throws CatalogResourceException {\r
-    ParseYamlResult result =\r
-        YamlParseServiceConsumer.getServiceTemplates(comboRequest(fileLocation));\r
-\r
+    ParseYamlResult result = getParseYamlResult(fileLocation);\r
+    \r
     Map<String, String> toscaMeta = parseToscaMeta(fileLocation);\r
     String stFileName = toscaMeta.get(TOSCA_META_FIELD_ENTRY_DEFINITIONS);\r
     CsarFileUriResponse stDownloadUri =\r
@@ -93,6 +93,43 @@ public class ToscaYamlModelParser extends AbstractModelParser {
     return st.getServiceTemplateId();\r
   }\r
 \r
+  private ParseYamlResult getParseYamlResult(String fileLocation) throws CatalogResourceException {\r
+    String destPath = copyTemporaryFile2HttpServer(fileLocation);\r
+    try {\r
+      String url = getUrl(toTempFileLocalPath(fileLocation));\r
+      return YamlParseServiceConsumer.getServiceTemplates(comboRequest(url));\r
+    } finally {\r
+      if (destPath != null && !destPath.isEmpty() && (new File(destPath)).exists()) {\r
+        (new File(destPath)).deleteOnExit();\r
+      }\r
+    }\r
+  }\r
+\r
+  private String toTempFileLocalPath(String fileLocation) {\r
+    return File.separator + "temp" + File.separator + (new File(fileLocation)).getName();\r
+  }\r
+  \r
+  private String getUrl(String uri) {\r
+    String url = null;\r
+    if ((MsbAddrConfig.getMsbAddress().endsWith("/")) && uri.startsWith("/")) {\r
+      url = MsbAddrConfig.getMsbAddress() + uri.substring(1);\r
+    }\r
+    url = MsbAddrConfig.getMsbAddress() + uri;\r
+    String urlresult = url.replace("\\", "/");\r
+    return urlresult;\r
+  }\r
+\r
+  private String copyTemporaryFile2HttpServer(String fileLocation) throws CatalogResourceException {\r
+    String destPath = Class.class.getClass().getResource("/").getPath()\r
+        + org.openo.commontosca.catalog.filemanage.http.ToolUtil.getHttpServerPath()\r
+        + toTempFileLocalPath(fileLocation);\r
+    if (!org.openo.commontosca.catalog.filemanage.http.ToolUtil.copyFile(fileLocation, destPath,\r
+        true)) {\r
+      throw new CatalogResourceException("Copy Temporary To HttpServer Failed.");\r
+    }\r
+    return destPath;\r
+  }\r
+\r
   @SuppressWarnings("resource")\r
   private Map<String, String> parseToscaMeta(String fileLocation) throws CatalogResourceException {\r
     Map<String, String> toscaMeta = new HashMap<>();\r