diff options
7 files changed, 222 insertions, 141 deletions
diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/InputParameter.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/InputParameter.java index a3f80a9f..15dee596 100644 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/InputParameter.java +++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/InputParameter.java @@ -26,7 +26,7 @@ import lombok.NoArgsConstructor; @AllArgsConstructor public class InputParameter { private String name; - private EnumDataType type = EnumDataType.STRING; + private String type = "string"; private String description; private Object defaultValue; private boolean required; 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 2ec83cbf..33c1676a 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,19 +15,11 @@ */ package org.openo.commontosca.catalog.model.parser.yaml.aria; -import java.io.File; -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; import org.openo.commontosca.catalog.entity.response.CsarFileUriResponse; import org.openo.commontosca.catalog.model.common.TemplateDataHelper; -import org.openo.commontosca.catalog.model.entity.EnumDataType; import org.openo.commontosca.catalog.model.entity.InputParameter; import org.openo.commontosca.catalog.model.entity.NodeTemplate; import org.openo.commontosca.catalog.model.entity.OutputParameter; @@ -43,6 +35,13 @@ import org.openo.commontosca.catalog.model.parser.yaml.aria.entity.AriaParserRes import org.openo.commontosca.catalog.model.parser.yaml.aria.entity.AriaParserResult.Substitution.Mapping; import org.openo.commontosca.catalog.model.parser.yaml.aria.service.AriaParserServiceConsumer; +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + /** * @author 10090474 * @@ -144,9 +143,10 @@ public class AriaModelParser extends AbstractModelParser { * @param serviceTemplateId * @param result * @return + * @throws CatalogResourceException */ private List<NodeTemplate> parseNodeTemplates(String packageId, String serviceTemplateId, - AriaParserResult result) { + AriaParserResult result) throws CatalogResourceException { Node[] nodes = result.getNodes(); if (nodes == null || nodes.length == 0) { return null; @@ -155,12 +155,12 @@ public class AriaModelParser extends AbstractModelParser { List<NodeTemplate> retList = new ArrayList<>(); for (Node node : nodes) { NodeTemplate ret = new NodeTemplate(); - ret.setId(node.getName()); - ret.setName(node.getName()); + ret.setId(node.getTemplate_name()); + ret.setName(node.getTemplate_name()); ret.setType(node.getType_name()); ret.setProperties(node.getPropertyAssignments()); List<RelationShip> relationShipList = - parseNodeTemplateRelationShip(node.getRelationships(), node); + parseNodeTemplateRelationShip(node.getRelationships(), node, nodes); ret.setRelationShips(relationShipList); retList.add(ret); @@ -173,9 +173,11 @@ public class AriaModelParser extends AbstractModelParser { /** * @param relationships * @param sourceNode + * @param nodes * @return + * @throws CatalogResourceException */ - private List<RelationShip> parseNodeTemplateRelationShip(Relationship[] relationships, Node sourceNode) { + private List<RelationShip> parseNodeTemplateRelationShip(Relationship[] relationships, Node sourceNode, Node[] nodes) throws CatalogResourceException { List<RelationShip> retList = new ArrayList<>(); if (relationships == null || relationships.length == 0) { @@ -184,10 +186,11 @@ public class AriaModelParser extends AbstractModelParser { for (Relationship relationship : relationships) { RelationShip ret = new RelationShip(); - ret.setSourceNodeId(sourceNode.getName()); - ret.setSourceNodeName(sourceNode.getName()); - ret.setTargetNodeId(relationship.getTemplate_name()); - ret.setTargetNodeName(relationship.getTemplate_name()); + ret.setSourceNodeId(sourceNode.getTemplate_name()); + ret.setSourceNodeName(sourceNode.getTemplate_name()); + Node targetNode = getNodeById(nodes, relationship.getTarget_node_id()); + ret.setTargetNodeId(targetNode.getTemplate_name()); + ret.setTargetNodeName(targetNode.getTemplate_name()); ret.setType(relationship.getType_name()); retList.add(ret); } @@ -197,6 +200,30 @@ public class AriaModelParser extends AbstractModelParser { /** + * @param nodes + * @param nodeId + * @return + * @throws CatalogResourceException + */ + private Node getNodeById(Node[] nodes, String nodeId) throws CatalogResourceException { + if (nodeId == null) { + throw new CatalogResourceException("Target node id is null."); + } + if (nodes == null || nodes.length == 0) { + throw new CatalogResourceException("Can't find target node. nodeId = " + nodeId); + } + + for (Node node : nodes) { + if (nodeId.equals(node.getId())) { + return node; + } + } + + throw new CatalogResourceException("Can't find target node. nodeId = " + nodeId); + } + + + /** * @param result * @param packageId * @param downloadUri @@ -232,34 +259,13 @@ public class AriaModelParser extends AbstractModelParser { retList.add( new InputParameter( e.getKey(), - getEnumDataType(e.getValue().getType_name()), + e.getValue().getType_name(), e.getValue().getDescription(), e.getValue().getValue(), false)); } return retList.toArray(new InputParameter[0]); } - - /** - * @param type - * @return - */ - private EnumDataType getEnumDataType(String type) { - if (EnumDataType.INTEGER.toString().equalsIgnoreCase(type)) { - return EnumDataType.INTEGER; - } - - if (EnumDataType.FLOAT.toString().equalsIgnoreCase(type)) { - return EnumDataType.FLOAT; - } - - if (EnumDataType.BOOLEAN.toString().equalsIgnoreCase(type)) { - return EnumDataType.BOOLEAN; - } - - return EnumDataType.STRING; - } - /** * @param result diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/EnumDataType.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/entity/AriaParserExceptionResult.java index 091a9554..10789fa9 100644 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/EnumDataType.java +++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/entity/AriaParserExceptionResult.java @@ -14,26 +14,27 @@ * limitations under the License. */ -package org.openo.commontosca.catalog.model.entity; +package org.openo.commontosca.catalog.model.parser.yaml.aria.entity; import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +@Data +@NoArgsConstructor @AllArgsConstructor -public enum EnumDataType { - STRING("String"), INTEGER("Integer"), FLOAT("Float"), BOOLEAN("Boolean"); +public class AriaParserExceptionResult { + private Issue[] issues; - private String value; - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; + @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; } } + 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 b610ecd9..f24e0c99 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 @@ -24,8 +24,6 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; -import com.google.gson.JsonObject; - @Data @NoArgsConstructor @AllArgsConstructor @@ -33,57 +31,48 @@ public class AriaParserResult { private String description; private Map<String, String> metadata; private Node[] nodes; - private JsonObject groups; - private JsonObject policies; + private Group[] groups; + private Policy[] policies; private Substitution substitution; private Map<String, Input> inputs; private Map<String, Output> outpus; - @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 Output { - private String type_name; - private Object value; - private String description; - } - - @Data public class Node { private String id; - private String name; private String type_name; + private String template_name; private Map<String, Property> properties; - private JsonObject[] interfaces; - private JsonObject[] artifacts; - private JsonObject[] capabilities; + private Interface[] interfaces; + private Artifact[] artifacts; + private Capability[] capabilities; private Relationship[] relationships; @Data - public class Property { + 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; + } + } + + @Data + public class Capability { + private String name; private String type_name; - private Object value; - private String description; + private Map<String, Property> properties; } @Data @@ -93,15 +82,8 @@ public class AriaParserResult { private String type_name; private String template_name; private Map<String, Property> properties; - private JsonObject[] source_interfaces; - private JsonObject[] target_interfaces; - - @Data - public class Property { - private String type_name; - private Object value; - private String description; - } + private Interface[] source_interfaces; + private Interface[] target_interfaces; } /** @@ -120,4 +102,98 @@ public class AriaParserResult { 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 { + 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; + private String name; + + } + } + + @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 +class Property { + private String type_name; + private Object value; + private String description; +} + +@Data +class Interface { + private String name; + private String type_name; + private Map<String, Property> inputs; + private Operation[] operation; + + @Data + class Operation { + private String name; + private String implementation; + private String[] dependencies; + private String executor; + private int max_retries; + private int retry_interval; + private Map<String, Property> inputs; + } +} + 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 03122eeb..72cee0ed 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 @@ -19,6 +19,7 @@ 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; @@ -45,11 +46,18 @@ public class AriaParserServiceConsumer { Config.getConfigration().getMsbServerAddr(), new ClientConfig(), IAriaParserRest.class); - String jsonStr = parseProxy.parse(request); - return new Gson().fromJson(jsonStr, AriaParserResult.class); + String strResult = parseProxy.parse(request); + validateResult(strResult); + return new Gson().fromJson(strResult, AriaParserResult.class); } 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) { + throw new CatalogResourceException("Aria parser return failure message: " + except.getIssues()[0].getMessage()); + } + } } diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/ToscaYamlModelParser.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/ToscaYamlModelParser.java index 48e1d6a0..5b599987 100644 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/ToscaYamlModelParser.java +++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/ToscaYamlModelParser.java @@ -21,7 +21,6 @@ import org.openo.commontosca.catalog.db.exception.CatalogResourceException; import org.openo.commontosca.catalog.db.resource.TemplateManager; import org.openo.commontosca.catalog.entity.response.CsarFileUriResponse; import org.openo.commontosca.catalog.model.common.TemplateDataHelper; -import org.openo.commontosca.catalog.model.entity.EnumDataType; import org.openo.commontosca.catalog.model.entity.InputParameter; import org.openo.commontosca.catalog.model.entity.NodeTemplate; import org.openo.commontosca.catalog.model.entity.OutputParameter; @@ -133,7 +132,7 @@ public class ToscaYamlModelParser extends AbstractModelParser { } List<InputParameter> retList = new ArrayList<InputParameter>(); for (Input input : inputList) { - retList.add(new InputParameter(input.getName(), getEnumDataType(input.getType()), + retList.add(new InputParameter(input.getName(), input.getType(), input.getDescription(), input.getDefault(), input.isRequired())); } return retList.toArray(new InputParameter[0]); @@ -208,28 +207,12 @@ public class ToscaYamlModelParser extends AbstractModelParser { List<InputParameter> retList = new ArrayList<>(); for (PlanInput input : inputList) { - retList.add(new InputParameter(input.getName(), getEnumDataType(input.getType()), + retList.add(new InputParameter(input.getName(), input.getType(), input.getDescription(), input.getDefault(), input.isRequired())); } return retList.toArray(new InputParameter[0]); } - private EnumDataType getEnumDataType(String type) { - if (EnumDataType.INTEGER.toString().equalsIgnoreCase(type)) { - return EnumDataType.INTEGER; - } - - if (EnumDataType.FLOAT.toString().equalsIgnoreCase(type)) { - return EnumDataType.FLOAT; - } - - if (EnumDataType.BOOLEAN.toString().equalsIgnoreCase(type)) { - return EnumDataType.BOOLEAN; - } - - return EnumDataType.STRING; - } - private List<NodeTemplate> parseNodeTemplates(String csarId, String templateId, ParseYamlResult result) { List<ParseYamlResult.TopologyTemplate.NodeTemplate> nodetemplateList = diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/resources/TemplateResource.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/resources/TemplateResource.java index ecc3301e..ab3760bd 100644 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/resources/TemplateResource.java +++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/resources/TemplateResource.java @@ -16,15 +16,6 @@ package org.openo.commontosca.catalog.resources; -import com.codahale.metrics.annotation.Timed; - -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; - -import org.eclipse.jetty.http.HttpStatus; import org.openo.commontosca.catalog.common.CommonErrorResponse; import org.openo.commontosca.catalog.common.ToolUtil; import org.openo.commontosca.catalog.db.exception.CatalogResourceException; @@ -35,11 +26,11 @@ import org.openo.commontosca.catalog.model.entity.QueryRawDataCondition; import org.openo.commontosca.catalog.model.entity.ServiceTemplate; import org.openo.commontosca.catalog.model.entity.ServiceTemplateOperation; import org.openo.commontosca.catalog.model.entity.ServiceTemplateRawData; +import org.openo.commontosca.catalog.model.parser.AbstractModelParser; +import org.openo.commontosca.catalog.model.parser.yaml.aria.AriaModelParser; import org.openo.commontosca.catalog.model.parser.yaml.zte.ToscaYamlModelParser; import org.openo.commontosca.catalog.model.service.ModelService; import org.openo.commontosca.catalog.model.wrapper.ServiceTemplateWrapper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import javax.ws.rs.Consumes; import javax.ws.rs.GET; @@ -51,6 +42,19 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import org.eclipse.jetty.http.HttpStatus; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; + +import com.codahale.metrics.annotation.Timed; + /** * model template service. * @@ -432,13 +436,16 @@ public class TemplateResource { @Timed public Response test() { try { - ToscaYamlModelParser parser = new ToscaYamlModelParser(); - parser.parse("pk11111", "C:\\Users\\10090474\\Desktop\\1\\bm\\bm.zip"); - String[] strs = {"111", "222", null, null, "555"}; - Response.status(Response.Status.OK).entity(strs).build(); + AbstractModelParser parser1 = new ToscaYamlModelParser(); +// parser1.parse("pk11111", "C:\\Users\\10090474\\Desktop\\1\\bm\\bm.zip"); + + AbstractModelParser parser = new AriaModelParser(); + parser.parse("pk11111", "/home/b/common-tosca-aria/blueprints/tosca/node-cellar.yaml"); ModelService.getInstance().delete("pk11111"); - throw new CatalogResourceException("test failed."); + + String[] strs = {"111", "222", null, null, "555"}; + return Response.status(Response.Status.OK).entity(strs).build(); } catch (CatalogResourceException e1) { logger.error("test failed.", e1); throw RestUtils.newInternalServerErrorException(e1); |