summaryrefslogtreecommitdiffstats
path: root/sdc-tosca-parser/src/main
diff options
context:
space:
mode:
authorPavel Aharoni <pa0916@att.com>2017-04-06 18:56:11 +0300
committerPavel Aharoni <pa0916@att.com>2017-04-06 18:56:11 +0300
commit9fc2ad8285866c5d45391f9c9f4f49a87a36763a (patch)
treec36fa770a85d68a5f976051e8c930abb5b1668e3 /sdc-tosca-parser/src/main
parent1df0b72a316dcc7f913061706db165d78d2c3a03 (diff)
[SDC-8] implementing the tosca stubs
Change-Id: Icadc0cc0dadce98e36eaffed0fe551c1387f6f8f Signed-off-by: Pavel Aharoni <pa0916@att.com>
Diffstat (limited to 'sdc-tosca-parser/src/main')
-rw-r--r--sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java31
-rw-r--r--sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java422
-rw-r--r--sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java18
-rw-r--r--sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/utils/GeneralUtility.java8
4 files changed, 370 insertions, 109 deletions
diff --git a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java
index 26995c4..88e22a0 100644
--- a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java
+++ b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java
@@ -20,11 +20,12 @@ package org.openecomp.sdc.tosca.parser.api;
import java.util.List;
-import java.util.Map;
import org.apache.commons.lang3.tuple.Pair;
import org.openecomp.sdc.toscaparser.api.Group;
+import org.openecomp.sdc.toscaparser.api.Metadata;
import org.openecomp.sdc.toscaparser.api.NodeTemplate;
+import org.openecomp.sdc.toscaparser.api.parameters.Input;
public interface ISdcCsarHelper {
@@ -120,17 +121,18 @@ public interface ISdcCsarHelper {
* @param metadata - metadata object.
* @param metadataPropertyName - the name of the metadata property.
* @return metadata property value
- *//*
- //public String getMetadataPropertyValue(Metadata metadata, String metadataPropertyName);
- */
+ */
+ public String getMetadataPropertyValue(Metadata metadata, String metadataPropertyName);
+
/**
* Get input leaf value for the CSAR service, by full path separated by #.<br>
* Same logic as in {@link #getNodeTemplatePropertyLeafValue(NodeTemplate, String) getNodeTemplatePropertyLeafValue}, only for an input full path.
+ * The expected format is "input_name#default[optionally #rest_of_path]"
* @param inputLeafValuePath by full path separated by #.
* @return input leaf value for the service.
*/
- public String getServiceInputLeafValue(String inputLeafValuePath);
+ public String getServiceInputLeafValueOfDefault(String inputLeafValuePath);
/**
* Get the type name of the CSAR service's substitution mappings element.<br>
@@ -151,7 +153,7 @@ public interface ISdcCsarHelper {
* Get the CSAR service metadata
* @return - the service metadata object.
*/
- public Map<String, String> getServiceMetadata();
+ public Metadata getServiceMetadata();
/**
* Get all VFC node templates from a specified VF.
@@ -178,13 +180,14 @@ public interface ISdcCsarHelper {
&nbsp;&nbsp;members: [vIPR_ATM_Ha_Two, vIPR_ATM_Ha_One, vIPR_ATM_OAM_SG, vIPR_ATM_HA_TWO_SG, vIPR_ATM_HA_ONE_SG]<br><br>
calling<br>
- getMembersOfGroup(group)<br>
- will return List of the following Strings: "vIPR_ATM_Ha_Two, vIPR_ATM_Ha_One, vIPR_ATM_OAM_SG, vIPR_ATM_HA_TWO_SG, vIPR_ATM_HA_ONE_SG"<br>
- * @param group - group to return the members.
- * @return names of all group members.
+ getMembersOfVfModule(NoteTemplate vfNodeTemplate, Group group)<br>
+ will return List of the following Node templates in the vfNodeTemplate: "vIPR_ATM_Ha_Two, vIPR_ATM_Ha_One, vIPR_ATM_OAM_SG, vIPR_ATM_HA_TWO_SG, vIPR_ATM_HA_ONE_SG"<br>
+ * @param vf - VF to return the node templates from.
+ * @param vfModule - group to return the members from.
+ * @return node templates from vf with the names as in members section.
*
*/
- public List<String> getMembersOfGroup(Group group);
+ public List<NodeTemplate> getMembersOfVfModule(NodeTemplate vf, Group vfModule);
/**
@@ -238,4 +241,10 @@ public interface ISdcCsarHelper {
*/
public String getTypeOfNodeTemplate(NodeTemplate nodeTemplate);
+ /**
+ * Get the CSAR service inputs list.
+ * @return - the service inputs list.
+ */
+ public List<Input> getServiceInputs();
+
}
diff --git a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java
index d5caa5d..612bc04 100644
--- a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java
+++ b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java
@@ -20,27 +20,27 @@
package org.openecomp.sdc.tosca.parser.impl;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.lang3.tuple.Pair;
+import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.openecomp.sdc.tosca.parser.utils.GeneralUtility;
+import org.openecomp.sdc.toscaparser.api.*;
+import org.openecomp.sdc.toscaparser.api.elements.NodeType;
+import org.openecomp.sdc.toscaparser.api.parameters.Input;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.yaml.snakeyaml.Yaml;
+
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
-import java.util.stream.Collector;
import java.util.stream.Collectors;
-import org.apache.commons.lang3.tuple.Pair;
-import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
-import org.openecomp.sdc.toscaparser.api.Group;
-import org.openecomp.sdc.toscaparser.api.NodeTemplate;
-import org.openecomp.sdc.toscaparser.api.Property;
-import org.openecomp.sdc.toscaparser.api.TopologyTemplate;
-import org.openecomp.sdc.toscaparser.api.ToscaTemplate;
-import org.yaml.snakeyaml.Yaml;
-
public class SdcCsarHelperImpl implements ISdcCsarHelper {
private ToscaTemplate toscaTemplate;
- private static Yaml defaultYaml = new Yaml();
-
+ private static Logger log = LoggerFactory.getLogger(SdcCsarHelperImpl.class.getName());
public SdcCsarHelperImpl(ToscaTemplate toscaTemplate) {
this.toscaTemplate = toscaTemplate;
@@ -49,38 +49,62 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
@Override
//Sunny flow - covered with UT, flat and nested
public String getNodeTemplatePropertyLeafValue(NodeTemplate nodeTemplate, String leafValuePath) {
+ if (nodeTemplate == null) {
+ log.error("getNodeTemplatePropertyLeafValue - nodeTemplate is null");
+ return null;
+ }
+ if (GeneralUtility.isEmptyString(leafValuePath)) {
+ log.error("getNodeTemplatePropertyLeafValue - leafValuePath is null or empty");
+ return null;
+ }
+ log.trace("getNodeTemplatePropertyLeafValue - nodeTemplate is : {}, leafValuePath is {} ", nodeTemplate.toString(), leafValuePath);
String[] split = leafValuePath.split("#");
List<Property> properties = nodeTemplate.getProperties();
- Optional<Property> findFirst = properties.stream().filter(x -> x.getName().equals(split[0])).findFirst();
- if (findFirst.isPresent()){
- Property property = findFirst.get();
- Object current = property.getValue();
- if (split.length > 1){
- current = defaultYaml.load((String)current);
- for (int i = 1; i < split.length; i++) {
- current = ((Map<String, Object>)current).get(split[i]);
- }
- }
- return String.valueOf(current);
- }
- return null;
+ log.trace("getNodeTemplatePropertyLeafValue - properties of nodeTemplate are : {}", properties.toString());
+ return processProperties(split, properties);
}
@Override
+ //Sunny flow - covered with UT
public List<NodeTemplate> getServiceVlList() {
- return getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), Types.TYPE_VL);
-
+ List<NodeTemplate> serviceVlList = getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), Types.TYPE_VL);
+ log.trace("getServiceVlList - the VL list is {}", serviceVlList);
+ return serviceVlList;
}
@Override
//Sunny flow - covered with UT
public List<NodeTemplate> getServiceVfList() {
- return getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), Types.TYPE_VF);
+ List<NodeTemplate> serviceVfList = getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), Types.TYPE_VF);
+ log.trace("getServiceVfList - the VF list is {}", serviceVfList);
+ return serviceVfList;
+ }
+
+ @Override
+ //Sunny flow - covered with UT
+ public String getMetadataPropertyValue(Metadata metadata, String metadataPropertyName) {
+ if (GeneralUtility.isEmptyString(metadataPropertyName)) {
+ log.error("getMetadataPropertyValue - the metadataPropertyName is null or empty");
+ return null;
+ }
+ if (metadata == null) {
+ log.error("getMetadataPropertyValue - the metadata is null");
+ return null;
+ }
+ String metadataPropertyValue = metadata.getValue(metadataPropertyName);
+ log.trace("getMetadataPropertyValue - metadata is {} metadataPropertyName is {} the value is : {}", metadata.toString(), metadataPropertyName , metadataPropertyValue);
+ return metadataPropertyValue;
}
+
@Override
//Sunny flow - covered with UT
public List<NodeTemplate> getServiceNodeTemplatesByType(String nodeType) {
+ if (GeneralUtility.isEmptyString(nodeType)) {
+ log.error("getServiceNodeTemplatesByType - nodeType - is null or empty");
+ return new ArrayList<>();
+ }
+
List<NodeTemplate> res = new ArrayList<>();
List<NodeTemplate> nodeTemplates = toscaTemplate.getNodeTemplates();
for (NodeTemplate nodeTemplate : nodeTemplates){
@@ -88,132 +112,336 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
res.add(nodeTemplate);
}
}
+
+ log.trace("getServiceNodeTemplatesByType - NodeTemplate list value is: {}", res);
return res;
}
@Override
+ //Sunny flow - covered with UT
public List<NodeTemplate> getVfcListByVf(String vfCustomizationId) {
+ if (GeneralUtility.isEmptyString(vfCustomizationId)) {
+ log.error("getVfcListByVf - vfCustomizationId - is null or empty");
+ return new ArrayList<>();
+ }
+
List<NodeTemplate> serviceVfList = getServiceVfList();
NodeTemplate vfInstance = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationId);
+ log.trace("getVfcListByVf - serviceVfList value: {}, vfInstance value: {}", serviceVfList, vfInstance);
return getNodeTemplateBySdcType(vfInstance, Types.TYPE_VFC);
}
- //Assumed to be unique property for the list
- private NodeTemplate getNodeTemplateByCustomizationUuid(List<NodeTemplate> nodeTemplates, String customizationId){
- for (NodeTemplate nodeTemplate : nodeTemplates){
- if (customizationId.equals(nodeTemplate.getMetadata().get(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))){
- return nodeTemplate;
- }
- }
- return null;
- }
-
@Override
+ //Sunny flow - covered with UT
public List<Group> getVfModulesByVf(String vfCustomizationUuid) {
List<NodeTemplate> serviceVfList = getServiceVfList();
- List<Group> res = new ArrayList<>();
NodeTemplate nodeTemplateByCustomizationUuid = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationUuid);
- //Asked Yaniv about getGroups from NodeTemplate
- /*
- List<Group> groups = nodeTemplateByCustomizationUuid.;
- for (Group group : groups){
- if (Types.TYPE_VFMODULE.equals(group.getType())){
- res.add(group);
+ if (nodeTemplateByCustomizationUuid != null){
+ SubstitutionMappings substitutionMappings = nodeTemplateByCustomizationUuid.getSubstitutionMappings();
+ if (substitutionMappings != null){
+ List<Group> groups = substitutionMappings.getGroups();
+ if (groups != null){
+ return groups.stream().filter(x -> "org.openecomp.groups.VfModule".equals(x.getTypeDefinition().getType())).collect(Collectors.toList());
+ }
}
- }*/
- return res;
+ }
+ return new ArrayList<>();
}
@Override
- public String getServiceInputLeafValue(String inputLeafValuePath) {
- //toscaTemplate.getTopologyTemplate().getNodeTemplates().get(0).getProperties().get(0).
- return null;//getLeafPropertyValue(toscaTemplate, inputLeafValuePath);
+ //Sunny flow - covered with UT
+ public String getServiceInputLeafValueOfDefault(String inputLeafValuePath) {
+ if (GeneralUtility.isEmptyString(inputLeafValuePath)) {
+ log.error("getServiceInputLeafValueOfDefault - inputLeafValuePath is null or empty");
+ return null;
+ }
+
+ String[] split = inputLeafValuePath.split("#");
+ if (split.length < 2 || !split[1].equals("default")){
+ log.error("getServiceInputLeafValue - inputLeafValuePath should be of format <input name>#default[optionally #<rest of path>] ");
+ return null;
+ }
+
+ List<Input> inputs = toscaTemplate.getInputs();
+ log.trace("getServiceInputLeafValue - the leafValuePath is {} , the inputs are {}", inputLeafValuePath, inputs);
+ if (inputs != null){
+ Optional<Input> findFirst = inputs.stream().filter(x -> x.getName().equals(split[0])).findFirst();
+ if (findFirst.isPresent()){
+ log.trace("getServiceInputLeafValue - find first item is {}", findFirst.get().toString());
+ Input input = findFirst.get();
+ Object current = input.getDefault();
+ if (current == null){
+ log.error("getServiceInputLeafValue - this input has no default");
+ return null;
+ }
+ if (split.length > 2){
+ current = new Yaml().load((String)current);
+ for (int i = 2; i < split.length; i++) {
+ if (current instanceof Map){
+ current = ((Map<String, Object>)current).get(split[i]);
+ } else {
+ log.error("getServiceInputLeafValue - found an unexpected leaf where expected to find a complex type");
+ return null;
+ }
+ }
+ }
+ if (current != null){
+ log.trace("getServiceInputLeafValue - the input default leaf value is {}", String.valueOf(current));
+ return String.valueOf(current);
+ }
+ }
+ }
+ log.error("getServiceInputLeafValue - value not found");
+ return null;
}
+
@Override
+ //Sunny flow - covered with UT
public String getServiceSubstitutionMappingsTypeName() {
- return toscaTemplate.getTopologyTemplate().getSubstitutionMappings().getNodeDefinition().getType();
- }
+ SubstitutionMappings substitutionMappings = toscaTemplate.getTopologyTemplate().getSubstitutionMappings();
+ if (substitutionMappings == null) {
+ log.trace("getServiceSubstitutionMappingsTypeName - No Substitution Mappings defined");
+ return null;
+ }
+ log.trace("getServiceSubstitutionMappingsTypeName - SubstitutionMappings value: {}", substitutionMappings);
- @Override
- public Map<String, String> getServiceMetadata() {
- TopologyTemplate topologyTemplate = toscaTemplate.getTopologyTemplate();
- System.out.println(topologyTemplate.toString());
- return topologyTemplate.getMetadata();
+ NodeType nodeType = substitutionMappings.getNodeDefinition();
+ if (nodeType == null) {
+ log.trace("getServiceSubstitutionMappingsTypeName - No Substitution Mappings node defined");
+ return null;
+ }
+ log.trace("getServiceSubstitutionMappingsTypeName - nodeType value: {}", nodeType);
+
+ return nodeType.getType();
}
- //Get property from group
@Override
- public String getGroupPropertyLeafValue(Group group, String propertyName) {
- return null;//getLeafPropertyValue(group, propertyName);
+ //Sunny flow - covered with UT
+ public Metadata getServiceMetadata() {
+ return toscaTemplate.getMetadata();
}
- private List<NodeTemplate> getNodeTemplateBySdcType(NodeTemplate nodeTemplate, String sdcType){
- //Need metadata to fetch by type
-
- /*List<NodeTemplate> nodeTemplates = nodeTemplate.getNestedNodeTemplates();
- List<NodeTemplate> res = new ArrayList<>();
- for (NodeTemplate nodeTemplateEntry : nodeTemplates){
- if (nodeTemplateEntry.getMetadata().getMetadataPropertyValue(SdcPropertyNames.PROPERTY_NAME_TYPE).equals(sdcType)){
- res.add(nodeTemplateEntry);
- }
- }*/
- return null;
+ @Override
+ //Sunny flow - covered with UT
+ public List<Input> getServiceInputs() {
+ return toscaTemplate.getInputs();
}
- private List<NodeTemplate> getNodeTemplateBySdcType(TopologyTemplate topologyTemplate, String sdcType){
- //Need metadata to fetch by type
+ @Override
+ //Sunny flow - covered with UT
+ public String getGroupPropertyLeafValue(Group group, String leafValuePath) {
+ if (group == null) {
+ log.error("getGroupPropertyLeafValue - group is null");
+ return null;
+ }
- List<NodeTemplate> nodeTemplates = topologyTemplate.getNodeTemplates();
- List<NodeTemplate> res = new ArrayList<>();
- for (NodeTemplate nodeTemplateEntry : nodeTemplates){
- //TODO switch back to type condition
- if (nodeTemplateEntry.getTypeDefinition().getType().contains("."+sdcType.toLowerCase()+".")){
- //if (sdcType.equals(nodeTemplateEntry.getMetadata().get(SdcPropertyNames.PROPERTY_NAME_TYPE))){
- res.add(nodeTemplateEntry);
- }
+ if (GeneralUtility.isEmptyString(leafValuePath)) {
+ log.error("getGroupPropertyLeafValue - leafValuePath is null or empty");
+ return null;
}
- return res;
+
+ String[] split = leafValuePath.split("#");
+ List<Property> properties = group.getProperties();
+ return processProperties(split, properties);
}
@Override
+ //Sunny flow - covered with UT
public List<NodeTemplate> getCpListByVf(String vfCustomizationId) {
+ List<NodeTemplate> cpList = new ArrayList<>();
+ if (GeneralUtility.isEmptyString(vfCustomizationId)){
+ log.error("getCpListByVf vfCustomizationId string is empty");
+ return cpList;
+ }
+
List<NodeTemplate> serviceVfList = getServiceVfList();
+ if (serviceVfList == null || serviceVfList.size() == 0){
+ log.error("getCpListByVf Vfs not exist for vfCustomizationId {}",vfCustomizationId);
+ return cpList;
+ }
NodeTemplate vfInstance = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationId);
- return getNodeTemplateBySdcType(vfInstance, Types.TYPE_CP);
+ log.debug("getCpListByVf vf list is {}", vfInstance);
+ if (vfInstance == null) {
+ log.debug("getCpListByVf vf list is null");
+ return cpList;
+ }
+ cpList = getNodeTemplateBySdcType(vfInstance, Types.TYPE_CP);
+ if(cpList == null || cpList.size()==0)
+ log.trace("getCpListByVf cps not exist for vfCustomizationId {}",vfCustomizationId);
+ return cpList;
}
@Override
- public List<String> getMembersOfGroup(Group group) {
- //Can be done
- return null;//toscaTemplate.getTopologyTemplate().getSubstitutionMappings().getNodeTemplates().get(0).get
+ //Sunny flow - covered with UT
+ public List<NodeTemplate> getMembersOfVfModule(NodeTemplate vf, Group vfModule) {
+ if (vf == null) {
+ log.error("getMembersOfVfModule - vf is null");
+ return new ArrayList<>();
+ }
+
+ if (vfModule == null) {
+ log.error("getMembersOfVfModule - vfModule is null");
+ return new ArrayList<>();
+ }
+
+ List<String> members = vfModule.getMembers();
+ if (members != null){
+ SubstitutionMappings substitutionMappings = vf.getSubstitutionMappings();
+ if (substitutionMappings != null){
+ return substitutionMappings.getNodeTemplates().stream().filter(x -> members.contains(x.getName())).collect(Collectors.toList());
+ }
+ }
+ return new ArrayList<>();
}
@Override
+ //Sunny flow - covered with UT
public List<Pair<NodeTemplate, NodeTemplate>> getNodeTemplatePairsByReqName(
List<NodeTemplate> listOfReqNodeTemplates, List<NodeTemplate> listOfCapNodeTemplates, String reqName) {
- //TODO - Can be done
- return new ArrayList<>();
+ if (listOfReqNodeTemplates == null || listOfCapNodeTemplates == null || reqName == null){
+ //TODO error message
+ return new ArrayList<>();
+ }
+
+ List<Pair<NodeTemplate, NodeTemplate>> pairsList = new ArrayList<>();
+
+ if (listOfReqNodeTemplates != null){
+ for (NodeTemplate reqNodeTemplate : listOfReqNodeTemplates) {
+ List<Map<String, Map<String, Object>>> requirements = reqNodeTemplate.getRequirements();
+ if (requirements != null){
+ for (Map<String, Map<String, Object>> reqEntry : requirements){
+ Map<String, Object> reqEntryMap = reqEntry.get(reqName);
+
+ if (reqEntryMap != null){
+ Object node = reqEntryMap.get("node");
+ if (node != null){
+ String nodeString = (String)node;
+ Optional<NodeTemplate> findFirst = listOfCapNodeTemplates.stream().filter(x -> x.getName().equals(nodeString)).findFirst();
+ if (findFirst.isPresent()){
+ pairsList.add(new ImmutablePair<NodeTemplate, NodeTemplate>(reqNodeTemplate, findFirst.get()));
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return pairsList;
}
@Override
+ //Sunny flow - covered with UT
//TODO constant strings
public List<NodeTemplate> getAllottedResources() {
- List<NodeTemplate> nodeTemplates = toscaTemplate.getTopologyTemplate().getNodeTemplates();
- return nodeTemplates.stream().filter(x -> x.getMetadata() != null && x.getMetadata().get("category").equals("allotted_resources")).collect(Collectors.toList());
+ List<NodeTemplate> nodeTemplates = null;
+ nodeTemplates = toscaTemplate.getTopologyTemplate().getNodeTemplates();
+ if(nodeTemplates==null || nodeTemplates.size()==0 ){
+ log.error("getAllottedResources nodeTemplates not exist");
+ }
+ nodeTemplates = nodeTemplates.stream().filter(x -> x.getMetadata() != null && x.getMetadata().getValue("category").equals("Allotted Resources")).collect(Collectors.toList());
+ if(nodeTemplates==null || nodeTemplates.size()==0 ){
+ log.trace("getAllottedResources - allotted resources not exist");
+ }else
+ log.trace("getAllottedResources - the allotted resources list is {}", nodeTemplates);
+ return nodeTemplates;
}
-
@Override
//Sunny flow - covered with UT
public String getTypeOfNodeTemplate(NodeTemplate nodeTemplate) {
- //Can be done
+ if(nodeTemplate == null){
+
+ log.error("getTypeOfNodeTemplate nodeTemplate is null");
+ return null;
+ }
+ log.debug("getTypeOfNodeTemplate node template type is {}",nodeTemplate.getTypeDefinition().getType());
return nodeTemplate.getTypeDefinition().getType();
}
- /*//Not part of API, for inner/test use
- public NodeTemplate getNodeTemplateByName(TopologyTemplate topologyTemplate, String topologyName){
+ /************************************* helper functions ***********************************/
+ private List<NodeTemplate> getNodeTemplateBySdcType(NodeTemplate nodeTemplate, String sdcType){
+ if (nodeTemplate == null) {
+ log.error("getNodeTemplateBySdcType - nodeTemplate is null or empty");
+ return new ArrayList<>();
+ }
+
+ if (GeneralUtility.isEmptyString(sdcType)) {
+ log.error("getNodeTemplateBySdcType - sdcType is null or empty");
+ return new ArrayList<>();
+ }
+
+ SubstitutionMappings substitutionMappings = nodeTemplate.getSubstitutionMappings();
+
+ if (substitutionMappings != null) {
+ List<NodeTemplate> nodeTemplates = substitutionMappings.getNodeTemplates();
+ if (nodeTemplates != null && nodeTemplates.size() > 0)
+ return nodeTemplates.stream().filter(x -> (x.getMetadata() != null && sdcType.equals(x.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)))).collect(Collectors.toList());
+ else
+ log.trace("getNodeTemplateBySdcType - SubstitutionMappings' node Templates not exist");
+ } else
+ log.trace("getNodeTemplateBySdcType - SubstitutionMappings not exist");
+
+ return new ArrayList<>();
+ }
+
+ private List<NodeTemplate> getNodeTemplateBySdcType(TopologyTemplate topologyTemplate, String sdcType){
+ if (GeneralUtility.isEmptyString(sdcType)) {
+ log.error("getNodeTemplateBySdcType - sdcType is null or empty");
+ return new ArrayList<>();
+ }
+
+ if (topologyTemplate == null) {
+ log.error("getNodeTemplateBySdcType - topologyTemplate is null");
+ return new ArrayList<>();
+ }
+
List<NodeTemplate> nodeTemplates = topologyTemplate.getNodeTemplates();
- Optional<NodeTemplate> findFirst = nodeTemplates.stream().filter(x -> x.getName().equals(topologyName)).findFirst();
- return findFirst.isPresent() ? findFirst.get() : null;
- }*/
+
+ if (nodeTemplates != null && nodeTemplates.size() > 0)
+ return nodeTemplates.stream().filter(x -> (x.getMetadata() != null && sdcType.equals(x.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)))).collect(Collectors.toList());
+
+ log.trace("getNodeTemplateBySdcType - topologyTemplate's nodeTemplates not exist");
+ return new ArrayList<>();
+ }
+
+ //Assumed to be unique property for the list
+ private NodeTemplate getNodeTemplateByCustomizationUuid(List<NodeTemplate> nodeTemplates, String customizationId){
+ for (NodeTemplate nodeTemplate : nodeTemplates){
+ if (customizationId.equals(nodeTemplate.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))){
+ return nodeTemplate;
+ }
+ }
+ return null;
+ }
+
+ private String processProperties(String[] split, List<Property> properties) {
+ log.trace("processProperties - the leafValuePath is {} , the properties are {}", split.toString(), properties.toString());
+ Optional<Property> findFirst = properties.stream().filter(x -> x.getName().equals(split[0])).findFirst();
+ if (findFirst.isPresent()){
+ log.trace("processProperties - find first item is {}", findFirst.get().toString());
+ Property property = findFirst.get();
+ Object current = property.getValue();
+ if (current == null){
+ log.error("processProperties - this property has no value");
+ return null;
+ }
+ if (split.length > 1){
+ current = new Yaml().load((String)current);
+ for (int i = 1; i < split.length; i++) {
+ if (current instanceof Map){
+ current = ((Map<String, Object>)current).get(split[i]);
+ } else {
+ log.error("processProperties - found an unexpected leaf where expected to find a complex type");
+ return null;
+ }
+ }
+ }
+ if (current != null){
+ log.trace("processProperties - the property value is {}", String.valueOf(current));
+ return String.valueOf(current);
+ }
+ }
+ log.error("processProperties - Dont find property");
+ return null;
+ }
}
diff --git a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java
index 6be293e..243d238 100644
--- a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java
+++ b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java
@@ -1,10 +1,14 @@
package org.openecomp.sdc.tosca.parser.impl;
import java.io.IOException;
+import java.util.List;
import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
+import org.openecomp.sdc.toscaparser.ToscaParser;
import org.openecomp.sdc.toscaparser.ToscaParserFactory;
+import org.openecomp.sdc.toscaparser.api.NodeTemplate;
+import org.openecomp.sdc.toscaparser.api.ToscaTemplate;
public class SdcToscaParserFactory implements AutoCloseable{
@@ -42,7 +46,10 @@ public class SdcToscaParserFactory implements AutoCloseable{
throw new SdcToscaParserException("The factory is closed. It was probably closed too soon.");
}
try {
- return new SdcCsarHelperImpl(toscaParserFactory.create().parse(csarPath));
+ ToscaParser create = toscaParserFactory.create();
+ ToscaTemplate parse = create.parse(csarPath);
+ SdcCsarHelperImpl sdcCsarHelperImpl = new SdcCsarHelperImpl(parse);
+ return sdcCsarHelperImpl;
} catch (IOException e) {
throw new SdcToscaParserException("Exception when creating the parser: "+e.getMessage());
}
@@ -66,4 +73,13 @@ public class SdcToscaParserFactory implements AutoCloseable{
}
}
}
+
+ public static void main(String[] args) throws SdcToscaParserException {
+ try (SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance()){ //Autoclosable
+ ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper("C:\\Users\\pa0916\\Desktop\\Work\\ASDC\\CSARs\\csar_hello_world.zip");
+ //Can run methods on the helper
+ List<NodeTemplate> allottedResources = sdcCsarHelper.getAllottedResources();
+ //..............
+ }
+ }
} \ No newline at end of file
diff --git a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/utils/GeneralUtility.java b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/utils/GeneralUtility.java
new file mode 100644
index 0000000..e4d92f5
--- /dev/null
+++ b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/utils/GeneralUtility.java
@@ -0,0 +1,8 @@
+package org.openecomp.sdc.tosca.parser.utils;
+
+public class GeneralUtility {
+
+ public static boolean isEmptyString(String str){
+ return str == null || str.trim().isEmpty();
+ }
+}