diff options
author | YuanHu <yuan.hu1@zte.com.cn> | 2016-10-24 16:52:54 +0800 |
---|---|---|
committer | YuanHu <yuan.hu1@zte.com.cn> | 2016-10-24 16:52:54 +0800 |
commit | 70b444e76b311092e78288e1fb4f43e1b1ad0715 (patch) | |
tree | a655e5efbd6ddf652a5188748e4e6a1b9b8b2979 | |
parent | 5a0fa8ba78bf1de745b279e2cc7f09d158bbec80 (diff) |
The response of aria parser changed, need to fix it.
Change-Id: I8f7a976517e8d07c6eb20a7ed245478502787b83
Issue-id: TOSCA-141
Signed-off-by: YuanHu <yuan.hu1@zte.com.cn>
4 files changed, 186 insertions, 161 deletions
diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/AriaModelParser.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/AriaModelParser.java index 8e5b749d..2501a158 100644 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/AriaModelParser.java +++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/AriaModelParser.java @@ -15,6 +15,12 @@ */ package org.openo.commontosca.catalog.model.parser.yaml.aria; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + import org.openo.commontosca.catalog.common.ToolUtil; import org.openo.commontosca.catalog.db.exception.CatalogResourceException; import org.openo.commontosca.catalog.db.resource.TemplateManager; @@ -29,22 +35,16 @@ import org.openo.commontosca.catalog.model.entity.ServiceTemplateOperation; import org.openo.commontosca.catalog.model.entity.SubstitutionMapping; import org.openo.commontosca.catalog.model.parser.AbstractModelParser; import org.openo.commontosca.catalog.model.parser.yaml.aria.entity.AriaParserResult; -import org.openo.commontosca.catalog.model.parser.yaml.aria.entity.AriaParserResult.Input; -import org.openo.commontosca.catalog.model.parser.yaml.aria.entity.AriaParserResult.Node; -import org.openo.commontosca.catalog.model.parser.yaml.aria.entity.AriaParserResult.Node.Relationship; -import org.openo.commontosca.catalog.model.parser.yaml.aria.entity.AriaParserResult.Output; -import org.openo.commontosca.catalog.model.parser.yaml.aria.entity.AriaParserResult.Substitution.Mapping; +import org.openo.commontosca.catalog.model.parser.yaml.aria.entity.AriaParserResult.Instance.Input; +import org.openo.commontosca.catalog.model.parser.yaml.aria.entity.AriaParserResult.Instance.Node; +import org.openo.commontosca.catalog.model.parser.yaml.aria.entity.AriaParserResult.Instance.Node.Relationship; +import org.openo.commontosca.catalog.model.parser.yaml.aria.entity.AriaParserResult.Instance.Output; +import org.openo.commontosca.catalog.model.parser.yaml.aria.entity.AriaParserResult.Instance.Substitution.Mapping; import org.openo.commontosca.catalog.model.parser.yaml.aria.service.AriaParserServiceConsumer; import org.openo.commontosca.catalog.wrapper.PackageWrapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - /** * @author 10090474 * @@ -97,8 +97,8 @@ public class AriaModelParser extends AbstractModelParser { return null; } - org.openo.commontosca.catalog.model.parser.yaml.aria.entity.AriaParserResult.Substitution stm = - result.getSubstitution(); + org.openo.commontosca.catalog.model.parser.yaml.aria.entity.AriaParserResult.Instance.Substitution stm = + result.getInstance().getSubstitution(); return new SubstitutionMapping( serviceTemplateId, type, @@ -140,10 +140,10 @@ public class AriaModelParser extends AbstractModelParser { * @return */ private String getSubstitutionType(AriaParserResult result) { - if (result.getSubstitution() == null) { + if (result.getInstance().getSubstitution() == null) { return null; } - return result.getSubstitution().getNode_type_name(); + return result.getInstance().getSubstitution().getNode_type_name(); } @@ -156,7 +156,7 @@ public class AriaModelParser extends AbstractModelParser { */ private List<NodeTemplate> parseNodeTemplates(String packageId, String serviceTemplateId, AriaParserResult result) throws CatalogResourceException { - Node[] nodes = result.getNodes(); + Node[] nodes = result.getInstance().getNodes(); if (nodes == null || nodes.length == 0) { return null; } @@ -243,9 +243,9 @@ public class AriaModelParser extends AbstractModelParser { ServiceTemplate st = new ServiceTemplate(); st.setServiceTemplateId(ToolUtil.generateId()); - st.setTemplateName(result.getMetadata().get("template_name")); - st.setVendor(result.getMetadata().get("template_author")); - st.setVersion(result.getMetadata().get("template_version")); + st.setTemplateName(result.getInstance().getMetadata().get("template_name")); + st.setVendor(result.getInstance().getMetadata().get("template_author")); + st.setVersion(result.getInstance().getMetadata().get("template_version")); st.setCsarId(packageId); st.setDownloadUri(downloadUri); st.setInputs(parseInputs(result)); @@ -259,7 +259,7 @@ public class AriaModelParser extends AbstractModelParser { * @return */ private InputParameter[] parseInputs(AriaParserResult result) { - Map<String, Input> inputs = result.getInputs(); + Map<String, Input> inputs = result.getInstance().getInputs(); if (inputs == null || inputs.isEmpty()) { return new InputParameter[0]; } @@ -281,7 +281,7 @@ public class AriaModelParser extends AbstractModelParser { * @return */ private OutputParameter[] parseOutputs(AriaParserResult result) { - Map<String, Output> outputs = result.getOutpus(); + Map<String, Output> outputs = result.getInstance().getOutpus(); if (outputs == null || outputs.isEmpty()) { return new OutputParameter[0]; } diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/entity/AriaParserExceptionResult.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/entity/AriaParserExceptionResult.java index 73b645aa..b06c97de 100644 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/entity/AriaParserExceptionResult.java +++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/entity/AriaParserExceptionResult.java @@ -15,25 +15,25 @@ */ package org.openo.commontosca.catalog.model.parser.yaml.aria.entity; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class AriaParserExceptionResult { - private Issue[] issues; - - @Data - public class Issue { - private int level; - private String message; +//import lombok.AllArgsConstructor; +//import lombok.Data; +//import lombok.NoArgsConstructor; +// +//@Data +//@NoArgsConstructor +//@AllArgsConstructor +//public class AriaParserExceptionResult { +// private Issue[] issues; +// +// @Data +// public class Issue { +// private int level; +// private String message; // private String location; // private String line; // private String column; // private String snippet; - private String exception; - } -} +// private String exception; +// } +//} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/entity/AriaParserResult.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/entity/AriaParserResult.java index 2b5e0edb..7e80c901 100644 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/entity/AriaParserResult.java +++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/entity/AriaParserResult.java @@ -15,165 +15,191 @@ */ package org.openo.commontosca.catalog.model.parser.yaml.aria.entity; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + @Data @NoArgsConstructor @AllArgsConstructor public class AriaParserResult { - private String description; - private Map<String, String> metadata; - private Node[] nodes; - private Group[] groups; - private Policy[] policies; - private Substitution substitution; - private Map<String, Input> inputs; - private Map<String, Output> outpus; - - public Map<String, String> getMetadata() { - if (this.metadata == null) { - return new HashMap<>(); - } - - return metadata; - } + private Issue[] issues; + private Instance instance = new Instance(); +// private Type[] types; +// private Model model; +// @Data +// public class Type { +// } +// @Data +// public class Model { +// } + @Data + public class Issue { + private int level; + private String message; + private String location; + private String line; + private String column; + private String snippet; + private String exception; + } + @Data - public class Node { - private String id; - private String type_name; - private String template_name; - private Map<String, Property> properties; - private Interface[] interfaces; - private Artifact[] artifacts; - private Capability[] capabilities; - private Relationship[] relationships; + public class Instance { + private String description; + private Map<String, String> metadata; + private Node[] nodes; + private Group[] groups; + private Policy[] policies; + private Substitution substitution; + private Map<String, Input> inputs; + private Map<String, Output> outpus; - @Data - public class Artifact { - private String name; - private String type_name; - private String source_path; - private String target_path; - private String repository_url; - private Credential repository_credential; - private Map<String, Property> properties; - - @Data - public class Credential { - private String protocol; - private String token_type; - private Map<String, String> keys; - private String user; + public Map<String, String> getMetadata() { + if (this.metadata == null) { + return new HashMap<>(); } - } - - @Data - public class Capability { - private String name; - private String type_name; - private Map<String, Property> properties; + + return metadata; } @Data - public class Relationship { - private String target_node_id; - private String target_capability_name; + public class Node { + private String id; private String type_name; private String template_name; private Map<String, Property> properties; - private Interface[] source_interfaces; - private Interface[] target_interfaces; - } - - /** - * @return - */ - public Map<String, Object> getPropertyAssignments() { - if (this.properties == null || this.properties.isEmpty()) { - return new HashMap<String, Object>(); + private Interface[] interfaces; + private Artifact[] artifacts; + private Capability[] capabilities; + private Relationship[] relationships; + + @Data + public class Artifact { + private String name; + private String type_name; + private String source_path; + private String target_path; + private String repository_url; + private Credential repository_credential; + private Map<String, Property> properties; + + @Data + public class Credential { + private String protocol; + private String token_type; + private Map<String, String> keys; + private String user; + } } - Map<String, Object> ret = new HashMap<String, Object>(); - for (Entry<String, Property> e : this.properties.entrySet()) { - ret.put(e.getKey(), e.getValue().getValue()); + @Data + public class Capability { + private String name; + private String type_name; + private Map<String, Property> properties; } - return ret; + @Data + public class Relationship { + private String target_node_id; + private String target_capability_name; + private String type_name; + private String template_name; + private Map<String, Property> properties; + private Interface[] source_interfaces; + private Interface[] target_interfaces; + } + + /** + * @return + */ + public Map<String, Object> getPropertyAssignments() { + if (this.properties == null || this.properties.isEmpty()) { + return new HashMap<String, Object>(); + } + + Map<String, Object> ret = new HashMap<String, Object>(); + for (Entry<String, Property> e : this.properties.entrySet()) { + ret.put(e.getKey(), e.getValue().getValue()); + } + + return ret; + } } - } - - @Data - public class Group { - private String id; - private String type_name; - private String template_name; - private Map<String, Property> properties; - private Interface[] interfaces; - private GroupPolicy[] policies; - private String[] member_node_ids; @Data - public class GroupPolicy { + public class Group { private String id; private String type_name; + private String template_name; private Map<String, Property> properties; - private Trigger[] triggers; + private Interface[] interfaces; + private GroupPolicy[] policies; + private String[] member_node_ids; @Data - public class Trigger { - private String name; - private String implementation; + public class GroupPolicy { + private String id; + private String type_name; private Map<String, Property> properties; + private Trigger[] triggers; + + @Data + public class Trigger { + private String name; + private String implementation; + private Map<String, Property> properties; + } } + } - - } - - @Data - public class Policy { - private String name; - private String type_name; - private Map<String, Property> properties; - private String[] target_node_ids; - private String[] target_group_ids; - } - - @Data - public class Substitution { - private String node_type_name; - private Mapping[] requirement; - private Mapping[] capabilities; @Data - public class Mapping { - private String mapped_name; - private String node_id; + public class Policy { private String name; + private String type_name; + private Map<String, Property> properties; + private String[] target_node_ids; + private String[] target_group_ids; + } + + @Data + public class Substitution { + private String node_type_name; + private Mapping[] requirement; + private Mapping[] capabilities; + @Data + public class Mapping { + private String mapped_name; + private String node_id; + private String name; + + } } - } - @Data - public class Input { - private String type_name; - private Object value; - private String description; + @Data + public class Input { + private String type_name; + private Object value; + private String description; + } + + @Data + public class Output { + private String type_name; + private Object value; + private String description; + } } - @Data - public class Output { - private String type_name; - private Object value; - private String description; - } } diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/service/AriaParserServiceConsumer.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/service/AriaParserServiceConsumer.java index fe6acc2a..5c18a851 100644 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/service/AriaParserServiceConsumer.java +++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/service/AriaParserServiceConsumer.java @@ -18,7 +18,6 @@ package org.openo.commontosca.catalog.model.parser.yaml.aria.service; import org.glassfish.jersey.client.ClientConfig; import org.openo.commontosca.catalog.common.Config; import org.openo.commontosca.catalog.db.exception.CatalogResourceException; -import org.openo.commontosca.catalog.model.parser.yaml.aria.entity.AriaParserExceptionResult; import org.openo.commontosca.catalog.model.parser.yaml.aria.entity.AriaParserRequest; import org.openo.commontosca.catalog.model.parser.yaml.aria.entity.AriaParserResult; import org.slf4j.Logger; @@ -51,16 +50,16 @@ public class AriaParserServiceConsumer { new ClientConfig(), IAriaParserRest.class); String strResult = parseProxy.parse(request); - validateResult(strResult); - return new Gson().fromJson(strResult, AriaParserResult.class); + AriaParserResult result = new Gson().fromJson(strResult, AriaParserResult.class); + validateResult(result, strResult); + return result; } catch (Exception e) { throw new CatalogResourceException("Call aria parser api failed.", e); } } - private static void validateResult(String strResult) throws CatalogResourceException { - AriaParserExceptionResult except = new Gson().fromJson(strResult, AriaParserExceptionResult.class); - if (except.getIssues() != null && except.getIssues().length > 0) { + private static void validateResult(AriaParserResult result, String strResult) throws CatalogResourceException { + if (result.getIssues() != null && result.getIssues().length > 0) { logger.error("Aria parser return failure message: " + strResult); throw new CatalogResourceException("Aria parser return failure message: " + strResult); } |