From 1df0b72a316dcc7f913061706db165d78d2c3a03 Mon Sep 17 00:00:00 2001 From: Pavel Aharoni Date: Mon, 3 Apr 2017 10:06:16 +0300 Subject: [SDC-8] trying to merge changes of tests and csars Change-Id: Iac4d5bd1ea312b76cba52a172d5ac80757173409 Signed-off-by: Pavel Aharoni --- .../sdc/tosca/parser/impl/SdcCsarHelperImpl.java | 61 ++++++++++++++-------- 1 file changed, 38 insertions(+), 23 deletions(-) (limited to 'sdc-tosca-parser/src/main/java') 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 51afe7e..d5caa5d 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 @@ -24,6 +24,8 @@ 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; @@ -32,27 +34,34 @@ 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(); + + public SdcCsarHelperImpl(ToscaTemplate toscaTemplate) { this.toscaTemplate = toscaTemplate; } @Override + //Sunny flow - covered with UT, flat and nested public String getNodeTemplatePropertyLeafValue(NodeTemplate nodeTemplate, String leafValuePath) { String[] split = leafValuePath.split("#"); List properties = nodeTemplate.getProperties(); Optional findFirst = properties.stream().filter(x -> x.getName().equals(split[0])).findFirst(); if (findFirst.isPresent()){ - Object current = findFirst.get().getValue(); - /*for (int i = 1; i < split.length; i++) { - //if (i ) - }*/ - //TODO add nested props - return (String)current; + 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)current).get(split[i]); + } + } + return String.valueOf(current); } return null; } @@ -64,11 +73,13 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { } @Override + //Sunny flow - covered with UT public List getServiceVfList() { return getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), Types.TYPE_VF); } - + @Override + //Sunny flow - covered with UT public List getServiceNodeTemplatesByType(String nodeType) { List res = new ArrayList<>(); List nodeTemplates = toscaTemplate.getNodeTemplates(); @@ -113,11 +124,6 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { return res; } - /*@Override - public String getMetadataPropertyValue(Metadata metadata, String metadataPropertyName) { - return (String)metadata.get(metadataPropertyName); - }*/ - @Override public String getServiceInputLeafValue(String inputLeafValuePath) { //toscaTemplate.getTopologyTemplate().getNodeTemplates().get(0).getProperties().get(0). @@ -131,7 +137,9 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { @Override public Map getServiceMetadata() { - return toscaTemplate.getTopologyTemplate().getMetadata(); + TopologyTemplate topologyTemplate = toscaTemplate.getTopologyTemplate(); + System.out.println(topologyTemplate.toString()); + return topologyTemplate.getMetadata(); } //Get property from group @@ -139,10 +147,10 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { public String getGroupPropertyLeafValue(Group group, String propertyName) { return null;//getLeafPropertyValue(group, propertyName); } - + private List getNodeTemplateBySdcType(NodeTemplate nodeTemplate, String sdcType){ //Need metadata to fetch by type - + /*List nodeTemplates = nodeTemplate.getNestedNodeTemplates(); List res = new ArrayList<>(); for (NodeTemplate nodeTemplateEntry : nodeTemplates){ @@ -152,16 +160,16 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { }*/ return null; } - + private List getNodeTemplateBySdcType(TopologyTemplate topologyTemplate, String sdcType){ //Need metadata to fetch by type - + List nodeTemplates = topologyTemplate.getNodeTemplates(); List 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))){ + //if (sdcType.equals(nodeTemplateEntry.getMetadata().get(SdcPropertyNames.PROPERTY_NAME_TYPE))){ res.add(nodeTemplateEntry); } } @@ -189,16 +197,23 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { } @Override + //TODO constant strings public List getAllottedResources() { - //TODO - Need metadata - return new ArrayList<>(); + List nodeTemplates = toscaTemplate.getTopologyTemplate().getNodeTemplates(); + return nodeTemplates.stream().filter(x -> x.getMetadata() != null && x.getMetadata().get("category").equals("allotted_resources")).collect(Collectors.toList()); } @Override + //Sunny flow - covered with UT public String getTypeOfNodeTemplate(NodeTemplate nodeTemplate) { //Can be done return nodeTemplate.getTypeDefinition().getType(); } - - + + /*//Not part of API, for inner/test use + public NodeTemplate getNodeTemplateByName(TopologyTemplate topologyTemplate, String topologyName){ + List nodeTemplates = topologyTemplate.getNodeTemplates(); + Optional findFirst = nodeTemplates.stream().filter(x -> x.getName().equals(topologyName)).findFirst(); + return findFirst.isPresent() ? findFirst.get() : null; + }*/ } -- cgit 1.2.3-korg