summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJian Huang <huang.jian12@zte.com.cn>2016-09-08 01:36:02 +0000
committerGerrit Code Review <gerrit@open-o.org>2016-09-08 01:36:02 +0000
commit0a57e28d2f48fb4a70664fa96e0c978ad30eb4ab (patch)
tree105b3339714ac423f7a1196b0fe2f90984eccc82
parent1f0470d3dc04c3e3a3005948112c0082cb391494 (diff)
parent93e083fb82a86a07ba94cd17b308862b2f11fafa (diff)
Merge changes Icbb40a43,I4c84d3bb,I124e06b6
* changes: Put the csar package to the httpserver and post the path to the parser. Protected for Response Null While Deploy Plan-Package to wso2 NullPointer Protected while plan is empty.
-rw-r--r--catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/ToscaYamlModelParser.java43
-rw-r--r--catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/entity/ParseYamlResult.java5
-rw-r--r--catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/plan/wso2/Wso2ServiceConsumer.java6
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 {
}
}
-