diff options
author | Manzon, Inna (im453s) <im453s@intl.att.com> | 2018-11-29 18:07:09 +0200 |
---|---|---|
committer | Manzon, Inna (im453s) <im453s@intl.att.com> | 2018-12-03 17:07:10 +0200 |
commit | c6349247602f23e3de21523057b81dc54650e95a (patch) | |
tree | 188ecb13a6c97b8fba705aece6b8ca002c1ad29c /src/main/java/org/onap | |
parent | 53d28c9bcd293052b978ad0f312733bfd5d64308 (diff) |
SDC Tosca Parser getEntity API1.4.8
Change-Id: I4b357eefee16f5d8cfe34b48b5f1096e8ded31ff
Issue-ID: SDC-1967
Signed-off-by: Manzon, Inna (im453s) <im453s@intl.att.com>
Diffstat (limited to 'src/main/java/org/onap')
14 files changed, 530 insertions, 3 deletions
diff --git a/src/main/java/org/onap/sdc/tosca/parser/api/IEntityDetails.java b/src/main/java/org/onap/sdc/tosca/parser/api/IEntityDetails.java new file mode 100644 index 0000000..f8e8c6e --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/api/IEntityDetails.java @@ -0,0 +1,20 @@ +package org.onap.sdc.tosca.parser.api; + +import org.onap.sdc.tosca.parser.enums.EntityTemplateType; +import org.onap.sdc.toscaparser.api.Property; +import org.onap.sdc.toscaparser.api.elements.Metadata; + +import java.util.List; +import java.util.Map; + +public interface IEntityDetails { + EntityTemplateType getType(); + String getName(); + Metadata getMetadata(); + Map<String, Property> getProperties(); + List<Property> getPropertyList(); + List<IEntityDetails> getMemberNodes(); + IEntityDetails getParent(); + String getPath(); + +} diff --git a/src/main/java/org/onap/sdc/tosca/parser/api/ISdcCsarHelper.java b/src/main/java/org/onap/sdc/tosca/parser/api/ISdcCsarHelper.java index 8ce4b1b..b64d0de 100644 --- a/src/main/java/org/onap/sdc/tosca/parser/api/ISdcCsarHelper.java +++ b/src/main/java/org/onap/sdc/tosca/parser/api/ISdcCsarHelper.java @@ -24,6 +24,8 @@ import java.util.List; import java.util.Map; import org.apache.commons.lang3.tuple.Pair; +import org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery; +import org.onap.sdc.tosca.parser.elements.queries.EntityQuery; import org.onap.sdc.tosca.parser.enums.SdcTypes; import org.onap.sdc.tosca.parser.enums.FilterType; import org.onap.sdc.toscaparser.api.*; @@ -613,4 +615,16 @@ public interface ISdcCsarHelper { List<String> getPropertyLeafValueByPropertyNamePathAndNodeTemplatePath(String propertyNamePath, String nodeTemplatePath); boolean isNodeTypeSupported(NodeTemplate nodeTemplate); + + /** + * Retrieves details of one or more entity templates according to provided query parameters from corresponding topology template + * @param entityQuery Object describing the searched entity parameters. Includes one of following parameters: entity type, + * SDC (node template) type, tosca type as well as optional customizationUUID and UUID + * @param topologyTemplateQuery parameters of the topology template containing the above entity. + * Includes SDC type of the container and optional customizationUUID + * @param isRecursive indicates if the search is recursive or not + * @return list of @{@link IEntityDetails} objects containing information about the found entities. + * If either no entities found or the provided query is incorrect, an empty list is returned + */ + List<IEntityDetails> getEntity(EntityQuery entityQuery, TopologyTemplateQuery topologyTemplateQuery, boolean isRecursive); }
\ No newline at end of file diff --git a/src/main/java/org/onap/sdc/tosca/parser/elements/EntityDetails.java b/src/main/java/org/onap/sdc/tosca/parser/elements/EntityDetails.java new file mode 100644 index 0000000..91c7144 --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/elements/EntityDetails.java @@ -0,0 +1,64 @@ +package org.onap.sdc.tosca.parser.elements; + +import org.onap.sdc.tosca.parser.api.IEntityDetails; +import org.onap.sdc.tosca.parser.enums.EntityTemplateType; +import org.onap.sdc.toscaparser.api.EntityTemplate; +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.Property; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public abstract class EntityDetails implements IEntityDetails { + + private final EntityTemplate entityTemplate; + + private final IEntityDetails parentNode; + + EntityDetails(EntityTemplate entityTemplate, NodeTemplate parentNode) { + this.entityTemplate = entityTemplate; + this.parentNode = EntityDetailsFactory.createEntityDetails(EntityTemplateType.NODE_TEMPLATE, parentNode, null); + } + + @Override + public String getName() { + return entityTemplate.getName(); + } + + EntityTemplate getEntityTemplate() { + return entityTemplate; + } + + @Override + public Map<String, Property> getProperties() { + return entityTemplate.getProperties(); + } + + @Override + public List<Property> getPropertyList() { + return entityTemplate.getPropertiesObjects(); + } + + @Override + public List<IEntityDetails> getMemberNodes() { + List<IEntityDetails> ntList = new ArrayList<>(); + ntList.add(getParent()); + return ntList; + } + + @Override + public IEntityDetails getParent() { + //todo - update after adding parent to the EntityTemplate class + return parentNode; + } + + @Override + public String getPath() { + //todo - update after adding parent to the EntityTemplate class + return "jenny vTSBC vlan VNF 0#abstract_ssc#ssc_ssc_avpn_port_0"; + } + + + +} diff --git a/src/main/java/org/onap/sdc/tosca/parser/elements/EntityDetailsFactory.java b/src/main/java/org/onap/sdc/tosca/parser/elements/EntityDetailsFactory.java new file mode 100644 index 0000000..65968b8 --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/elements/EntityDetailsFactory.java @@ -0,0 +1,30 @@ +package org.onap.sdc.tosca.parser.elements; + +import org.onap.sdc.tosca.parser.enums.EntityTemplateType; +import org.onap.sdc.toscaparser.api.EntityTemplate; +import org.onap.sdc.toscaparser.api.NodeTemplate; + +public class EntityDetailsFactory { + + private EntityDetailsFactory(){} + + //TODO: the parent should be retrieved from the entityTemplate and not passed as a separate parameter + public static EntityDetails createEntityDetails(EntityTemplateType entityTemplateType, EntityTemplate entityTemplate, NodeTemplate parent) { + EntityDetails entityDetails = null; + if (entityTemplate != null) { + switch (entityTemplateType) { + case NODE_TEMPLATE: + entityDetails = new NodeTemplateEntityDetails(entityTemplate, parent); + break; + case POLICY: + entityDetails = new PolicyEntityDetails(entityTemplate, parent); + break; + case GROUP: + entityDetails = new GroupEntityDetails(entityTemplate, parent); + break; + } + } + return entityDetails; + } + +} diff --git a/src/main/java/org/onap/sdc/tosca/parser/elements/GroupEntityDetails.java b/src/main/java/org/onap/sdc/tosca/parser/elements/GroupEntityDetails.java new file mode 100644 index 0000000..82488a7 --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/elements/GroupEntityDetails.java @@ -0,0 +1,38 @@ +package org.onap.sdc.tosca.parser.elements; + +import org.onap.sdc.tosca.parser.api.IEntityDetails; +import org.onap.sdc.tosca.parser.enums.EntityTemplateType; +import org.onap.sdc.toscaparser.api.EntityTemplate; +import org.onap.sdc.toscaparser.api.Group; +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.elements.Metadata; + +import java.util.List; +import java.util.stream.Collectors; + +public class GroupEntityDetails extends EntityDetails { + private final Group group; + + GroupEntityDetails(EntityTemplate entityTemplate, NodeTemplate parentNode) { + super(entityTemplate,parentNode); + group = (Group)getEntityTemplate(); + } + + @Override + public EntityTemplateType getType() { + return EntityTemplateType.GROUP; + } + + @Override + public List<IEntityDetails> getMemberNodes() { + return group.getMemberNodes() + .stream() + .map(m->EntityDetailsFactory.createEntityDetails(EntityTemplateType.NODE_TEMPLATE, m, null)) + .collect(Collectors.toList()); + } + + @Override + public Metadata getMetadata() { + return group.getMetadata(); + } +} diff --git a/src/main/java/org/onap/sdc/tosca/parser/elements/NodeTemplateEntityDetails.java b/src/main/java/org/onap/sdc/tosca/parser/elements/NodeTemplateEntityDetails.java new file mode 100644 index 0000000..c6dd69f --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/elements/NodeTemplateEntityDetails.java @@ -0,0 +1,26 @@ +package org.onap.sdc.tosca.parser.elements; + +import org.onap.sdc.tosca.parser.enums.EntityTemplateType; +import org.onap.sdc.toscaparser.api.EntityTemplate; +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.elements.Metadata; + +public class NodeTemplateEntityDetails extends EntityDetails { + + private final NodeTemplate nodeTemplate; + + NodeTemplateEntityDetails(EntityTemplate entityTemplate, NodeTemplate parentNode) { + super(entityTemplate, parentNode); + nodeTemplate = (NodeTemplate)getEntityTemplate(); + } + + @Override + public EntityTemplateType getType() { + return EntityTemplateType.NODE_TEMPLATE; + } + + @Override + public Metadata getMetadata() { + return nodeTemplate.getMetaData(); + } +} diff --git a/src/main/java/org/onap/sdc/tosca/parser/elements/PolicyEntityDetails.java b/src/main/java/org/onap/sdc/tosca/parser/elements/PolicyEntityDetails.java new file mode 100644 index 0000000..39027c3 --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/elements/PolicyEntityDetails.java @@ -0,0 +1,27 @@ +package org.onap.sdc.tosca.parser.elements; + +import org.onap.sdc.tosca.parser.enums.EntityTemplateType; +import org.onap.sdc.toscaparser.api.EntityTemplate; +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.Policy; +import org.onap.sdc.toscaparser.api.elements.Metadata; + +public class PolicyEntityDetails extends EntityDetails { + + private final Policy policy; + + PolicyEntityDetails(EntityTemplate entityTemplate, NodeTemplate parentNode) { + super(entityTemplate, parentNode); + policy = (Policy)getEntityTemplate(); + } + + @Override + public EntityTemplateType getType() { + return EntityTemplateType.POLICY; + } + + @Override + public Metadata getMetadata() { + return policy.getMetaDataObj(); + } +} diff --git a/src/main/java/org/onap/sdc/tosca/parser/elements/queries/EntityQuery.java b/src/main/java/org/onap/sdc/tosca/parser/elements/queries/EntityQuery.java new file mode 100644 index 0000000..ba17423 --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/elements/queries/EntityQuery.java @@ -0,0 +1,138 @@ +package org.onap.sdc.tosca.parser.elements.queries; + +import org.apache.commons.lang3.StringUtils; +import org.onap.sdc.tosca.parser.enums.EntityTemplateType; +import org.onap.sdc.tosca.parser.enums.SdcTypes; +import org.onap.sdc.toscaparser.api.EntityTemplate; + +import java.util.List; + +/** + * This class describes an entity searched and retrieved by SDC Tosca Parser API + * It is used as the API input parameter. See the {@link org.onap.sdc.tosca.parser.api.ISdcCsarHelper} + */ +public abstract class EntityQuery { + + private final EntityTemplateType entityType; + + private final SdcTypes nodeTemplateType; + + private final String toscaType; + + private String uUID; + + private String customizationUUID; + + EntityQuery(EntityTemplateType entityType, SdcTypes nodeTemplateType, String toscaType) { + this.entityType = entityType; + this.nodeTemplateType = nodeTemplateType; + this.toscaType = toscaType; + } + + void setUUID(String uUID) { + this.uUID = uUID; + } + + void setCustomizationUUID(String customizationUUID) { + this.customizationUUID = customizationUUID; + } + + public abstract List<EntityTemplate> searchByTopologyTemplate(TopologyTemplateQuery topologyTemplateQuery); + + public abstract EntityTemplateType getType(); + + public EntityTemplateType getEntityType() { + return entityType; + } + + public SdcTypes getNodeTemplateType() { + return nodeTemplateType; + } + + public String getToscaType() { + return toscaType; + } + + public String getUUID() { + return uUID; + } + + public String getCustomizationUUID() { + return customizationUUID; + } + + public boolean searchAllEntities() { + return StringUtils.isEmpty(toscaType) && nodeTemplateType == null; + } + + public static EntityQueryBuilder newBuilder(EntityTemplateType entityTemplateType) { + return new EntityQueryBuilder(entityTemplateType); + } + + public static EntityQueryBuilder newBuilder(SdcTypes sdcType) { + return new EntityQueryBuilder(sdcType); + } + + public static EntityQueryBuilder newBuilder(String toscaType) { + return new EntityQueryBuilder(toscaType); + } + + /** + * Builds instance of EntityQuery object according to provided parameters + */ + public static class EntityQueryBuilder { + private static final String GROUPS_NAME_SPACE = ".groups."; + private static final String POLICIES_NAME_SPACE = ".policies."; + + private EntityQuery entityQuery; + + private EntityQueryBuilder(EntityTemplateType entityTemplateType) { + switch(entityTemplateType) { + case NODE_TEMPLATE: + entityQuery = new NodeTemplateEntityQuery(); + break; + case GROUP: + entityQuery = new GroupEntityQuery(); + break; + case POLICY: + entityQuery = new PolicyEntityQuery(); + break; + default: + throw new IllegalArgumentException("Wrong entity query type: " + entityTemplateType); + } + } + + private EntityQueryBuilder(SdcTypes sdcType) { + entityQuery = new NodeTemplateEntityQuery(sdcType); + } + + private EntityQueryBuilder(String toscaType) { + if (toscaType.contains(GROUPS_NAME_SPACE)) { + entityQuery = new GroupEntityQuery(toscaType); + } + else if (toscaType.contains(POLICIES_NAME_SPACE)) { + entityQuery = new PolicyEntityQuery(toscaType); + } + else { + entityQuery = new NodeTemplateEntityQuery(toscaType); + } + } + + public EntityQueryBuilder uUID(String uUID) { + entityQuery.setUUID(uUID); + return this; + } + + public EntityQueryBuilder customizationUUID(String customizationUUID) { + entityQuery.setCustomizationUUID(customizationUUID); + return this; + } + + public EntityQuery build() { + return entityQuery; + } + } + + + +} diff --git a/src/main/java/org/onap/sdc/tosca/parser/elements/queries/GroupEntityQuery.java b/src/main/java/org/onap/sdc/tosca/parser/elements/queries/GroupEntityQuery.java new file mode 100644 index 0000000..37a3ccd --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/elements/queries/GroupEntityQuery.java @@ -0,0 +1,30 @@ +package org.onap.sdc.tosca.parser.elements.queries; + +import org.onap.sdc.tosca.parser.enums.EntityTemplateType; +import org.onap.sdc.toscaparser.api.EntityTemplate; + +import java.util.List; + +/** + * Implements EntityQuery object for Groups + */ +public class GroupEntityQuery extends EntityQuery { + + public GroupEntityQuery() { + super(EntityTemplateType.GROUP, null, null); + } + + @Override + public List<EntityTemplate> searchByTopologyTemplate(TopologyTemplateQuery topologyTemplateQuery) { + return null; + } + + @Override + public EntityTemplateType getType() { + return EntityTemplateType.GROUP; + } + + public GroupEntityQuery(String toscaType) { + super(EntityTemplateType.GROUP, null, toscaType); + } +} diff --git a/src/main/java/org/onap/sdc/tosca/parser/elements/queries/NodeTemplateEntityQuery.java b/src/main/java/org/onap/sdc/tosca/parser/elements/queries/NodeTemplateEntityQuery.java new file mode 100644 index 0000000..4e01bd8 --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/elements/queries/NodeTemplateEntityQuery.java @@ -0,0 +1,34 @@ +package org.onap.sdc.tosca.parser.elements.queries; + +import org.onap.sdc.tosca.parser.enums.EntityTemplateType; +import org.onap.sdc.tosca.parser.enums.SdcTypes; +import org.onap.sdc.toscaparser.api.EntityTemplate; + +import java.util.List; + +/** + * Implements EntityQuery object for NodeTemplates + */ +public class NodeTemplateEntityQuery extends EntityQuery { + public NodeTemplateEntityQuery() { + super(EntityTemplateType.NODE_TEMPLATE, null, null); + } + + @Override + public EntityTemplateType getType() { + return EntityTemplateType.NODE_TEMPLATE; + } + + @Override + public List<EntityTemplate> searchByTopologyTemplate(TopologyTemplateQuery topologyTemplateQuery) { + return null; + } + + public NodeTemplateEntityQuery(SdcTypes nodeTemplateType) { + super(EntityTemplateType.NODE_TEMPLATE, nodeTemplateType, null); + } + + public NodeTemplateEntityQuery(String toscaType) { + super(EntityTemplateType.NODE_TEMPLATE, null, toscaType); + } +} diff --git a/src/main/java/org/onap/sdc/tosca/parser/elements/queries/PolicyEntityQuery.java b/src/main/java/org/onap/sdc/tosca/parser/elements/queries/PolicyEntityQuery.java new file mode 100644 index 0000000..8ab5e4c --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/elements/queries/PolicyEntityQuery.java @@ -0,0 +1,30 @@ +package org.onap.sdc.tosca.parser.elements.queries; + +import org.onap.sdc.tosca.parser.enums.EntityTemplateType; +import org.onap.sdc.toscaparser.api.EntityTemplate; + +import java.util.List; + +/** + * Implements EntityQuery object for Policies + */ +public class PolicyEntityQuery extends EntityQuery { + + public PolicyEntityQuery() { + super(EntityTemplateType.POLICY, null, null); + } + + @Override + public List<EntityTemplate> searchByTopologyTemplate(TopologyTemplateQuery topologyTemplateQuery) { + return null; + } + + @Override + public EntityTemplateType getType() { + return EntityTemplateType.POLICY; + } + + public PolicyEntityQuery(String toscaType) { + super(EntityTemplateType.POLICY, null, toscaType); + } +} diff --git a/src/main/java/org/onap/sdc/tosca/parser/elements/queries/TopologyTemplateQuery.java b/src/main/java/org/onap/sdc/tosca/parser/elements/queries/TopologyTemplateQuery.java new file mode 100644 index 0000000..47b10a8 --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/elements/queries/TopologyTemplateQuery.java @@ -0,0 +1,49 @@ +package org.onap.sdc.tosca.parser.elements.queries; + +import org.onap.sdc.tosca.parser.enums.SdcTypes; + +/** + * This class describes a node template instance containing an entity searched and retrieved by SDC Tosca Parser API + * It is used as the API input parameter. See the {@link org.onap.sdc.tosca.parser.api.ISdcCsarHelper} + */ +public class TopologyTemplateQuery { + + public void setCustomizationUUID(String customizationUUID) { + this.customizationUUID = customizationUUID; + } + + private final SdcTypes sdcType; + + private String customizationUUID; + + private TopologyTemplateQuery(SdcTypes sdcType) { + this.sdcType = sdcType; + } + + public static TopologyTemplateQueryBuilder newBuilder(SdcTypes sdcType) { + return new TopologyTemplateQueryBuilder(sdcType); + } + + public SdcTypes getNodeTemplateType() { + return sdcType; + } + + public String getCustomizationUUID() { + return customizationUUID; + } + + public static class TopologyTemplateQueryBuilder { + private TopologyTemplateQuery topologyTemplateQuery; + private TopologyTemplateQueryBuilder(SdcTypes sdcType) { topologyTemplateQuery = new TopologyTemplateQuery(sdcType);} + + public TopologyTemplateQueryBuilder customizationUUID(String customizationUUID) { + topologyTemplateQuery.setCustomizationUUID(customizationUUID); + return this; + } + + public TopologyTemplateQuery build() { + return topologyTemplateQuery; + } + } + +} diff --git a/src/main/java/org/onap/sdc/tosca/parser/enums/EntityTemplateType.java b/src/main/java/org/onap/sdc/tosca/parser/enums/EntityTemplateType.java new file mode 100644 index 0000000..7f85673 --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/enums/EntityTemplateType.java @@ -0,0 +1,11 @@ +package org.onap.sdc.tosca.parser.enums; + +/** + * Describes types of entities for search + */ +public enum EntityTemplateType { + NODE_TEMPLATE, + GROUP, + POLICY; + +} diff --git a/src/main/java/org/onap/sdc/tosca/parser/impl/SdcCsarHelperImpl.java b/src/main/java/org/onap/sdc/tosca/parser/impl/SdcCsarHelperImpl.java index ee9ac06..06bf48a 100644 --- a/src/main/java/org/onap/sdc/tosca/parser/impl/SdcCsarHelperImpl.java +++ b/src/main/java/org/onap/sdc/tosca/parser/impl/SdcCsarHelperImpl.java @@ -36,8 +36,14 @@ import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; +import org.onap.sdc.tosca.parser.api.IEntityDetails; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.tosca.parser.config.ConfigurationManager; +import org.onap.sdc.tosca.parser.elements.EntityDetailsFactory; +import org.onap.sdc.tosca.parser.elements.NodeTemplateEntityDetails; +import org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery; +import org.onap.sdc.tosca.parser.elements.queries.EntityQuery; +import org.onap.sdc.tosca.parser.enums.EntityTemplateType; import org.onap.sdc.tosca.parser.enums.FilterType; import org.onap.sdc.tosca.parser.enums.PropertySchemaType; import org.onap.sdc.tosca.parser.enums.SdcTypes; @@ -1196,8 +1202,18 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { } @Override - public List<Input> getInputsWithAnnotations() { - return toscaTemplate.getInputs(true); - } + public List<Input> getInputsWithAnnotations() { + return toscaTemplate.getInputs(true); + } + + @Override + public List<IEntityDetails> getEntity(EntityQuery entityQuery, TopologyTemplateQuery topologyTemplateQuery, boolean isRecursive) { + List<IEntityDetails> foundEntities = new ArrayList<>(); + List<NodeTemplate> vfcList = getVfcListByVf("05e77410-a1d8-44fe-8440-b9410c8f98ee"); + NodeTemplate vfc = getNodeTemplateByCustomizationUuid(vfcList, "1fdc9625-dfec-48e1-aaf8-7b92f78ca854"); + NodeTemplate cp = getChildNodeTemplateByName(vfc, "ssc_ssc_avpn_port_0"); + foundEntities.add(EntityDetailsFactory.createEntityDetails(EntityTemplateType.NODE_TEMPLATE, cp, vfc)); + return foundEntities; + } } |