diff options
3 files changed, 49 insertions, 5 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<>();
diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/entity/ParseYamlResult.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/entity/ParseYamlResult.java index 5075f485..e64a6abb 100644 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/entity/ParseYamlResult.java +++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/entity/ParseYamlResult.java @@ -153,7 +153,10 @@ public class ParseYamlResult { }
private List<Plan> jsonObject2PlanList(JsonObject plans) {
- List<Plan> retList = new ArrayList<Plan>();
+ if (plans == null) {
+ return new ArrayList<>();
+ }
+ List<Plan> retList = new ArrayList<>();
Iterator<Entry<String, JsonElement>> iterator = plans.entrySet().iterator();
while (iterator.hasNext()) {
Plan ret = new Plan();
diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/plan/wso2/Wso2ServiceConsumer.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/plan/wso2/Wso2ServiceConsumer.java index da52dcd7..48b866e0 100644 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/plan/wso2/Wso2ServiceConsumer.java +++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/plan/wso2/Wso2ServiceConsumer.java @@ -66,6 +66,11 @@ public class Wso2ServiceConsumer { Integer.parseInt(Config.getConfigration().getWso2HostPort()), WSO2_APP_URL,
buildRequest(ins, planFilePath));
+ if (res.getStatusCode() == null || res.getResult() == null) {
+ throw new CatalogResourceException(
+ "Deploy Package return null. Response = " + res);
+ }
+
if (200 == res.getStatusCode() || 201 == res.getStatusCode()) {
DeployPackageResponse response =
new Gson().fromJson(res.getResult(), DeployPackageResponse.class);
@@ -182,4 +187,3 @@ public class Wso2ServiceConsumer { }
}
-
|