summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java68
-rw-r--r--src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java17
-rw-r--r--src/test/resources/csars/service-consolidated-props-csar.csarbin321286 -> 321331 bytes
3 files changed, 46 insertions, 39 deletions
diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java
index 8095974..e3b9937 100644
--- a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java
+++ b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java
@@ -22,11 +22,9 @@ package org.openecomp.sdc.tosca.parser.impl;
import java.util.*;
import java.util.Map.Entry;
-import java.util.regex.Matcher;
import java.util.regex.Pattern;
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.json.JSONObject;
@@ -52,9 +50,7 @@ import static org.openecomp.sdc.tosca.parser.impl.SdcPropertyNames.PROPERTY_NAME
public class SdcCsarHelperImpl implements ISdcCsarHelper {
private static final String PATH_DELIMITER = "#";
- private static final String PREFIX = "port_";
private static final String CUSTOMIZATION_UUID = "customizationUUID";
- private static Pattern SUFFIX = Pattern.compile("(_network_role_tag|_ip_requirements|_subnetpoolid)$");
private ToscaTemplate toscaTemplate;
private static Logger log = LoggerFactory.getLogger(SdcCsarHelperImpl.class.getName());
@@ -101,37 +97,30 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
return new HashMap<>();
}
- List<String> paths = new ArrayList<>();
- paths.add("network_role_tag");
- paths.add("ip_requirements#ip_count_required#count");
- paths.add("ip_requirements#dhcp_enabled");
- paths.add("ip_requirements#ip_version");
- paths.add("subnetpoolid");
-
- Map<String, Property> props = vfc.getProperties();
-
+ String presetProperty = "_ip_requirements";
Map<String, Map<String, Object>> cps = new HashMap<>();
+ Map<String, Property> props = vfc.getProperties();
if (props != null) {
+ // find all port names by pre-set property (ip_requirements)
for (Map.Entry<String, Property> entry : props.entrySet()) {
- String fullCpName = entry.getKey();
- Matcher matcher = SUFFIX.matcher(fullCpName);
-
- if (fullCpName.startsWith(PREFIX) && matcher.find()) {
- //this is CP - get all it's properties according to paths list
- String cpName = fullCpName.replaceAll("^(" + PREFIX + ")", "").replaceAll(matcher.group(1), "");
-
- List<String> propertiesToSearch = paths.stream().filter(i -> i.contains(StringUtils.stripStart(matcher.group(1), "_"))).collect(Collectors.toList());
- for (String item : propertiesToSearch) {
- String fullPathToSearch = PREFIX + cpName + "_" + item;
- Object value = getNodeTemplatePropertyAsObject(vfc, fullPathToSearch);
- if (value != null) {
- if (!cps.containsKey(cpName)){
- cps.put(cpName, new HashMap<>());
- }
- cps.get(cpName).put(item, value);
- }
+ if (entry.getKey().endsWith(presetProperty)) {
+ String portName = entry.getKey().replaceAll(presetProperty, "");
+ cps.put(portName, new HashMap<>());
+ }
+ }
+
+ if (cps.size() > 0) {
+ // ports found - find all their properties
+ for (String portName : cps.keySet()) {
+ for (Map.Entry<String, Property> property: props.entrySet()) {
+ if (property.getKey().startsWith(portName)) {
+ Map<String, Object> portPaths = new HashMap<>();
+ String portProperty = property.getKey().replaceFirst(portName + "_", "");
+ buildPathMappedToValue(portProperty, property.getValue().getValue(), portPaths);
+ cps.get(portName).putAll(portPaths);
+ }
}
}
}
@@ -140,6 +129,25 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
return cps;
}
+ private void buildPathMappedToValue(String path, Object property, Map<String, Object> pathsMap) {
+ if (property instanceof Map) {
+ for (Map.Entry<String, Object> item : ((Map<String, Object>) property).entrySet()) {
+ if (item.getValue() instanceof Map || item.getValue() instanceof List) {
+ buildPathMappedToValue(path + PATH_DELIMITER + item.getKey(), item.getValue(), pathsMap);
+ } else {
+ pathsMap.put(path + PATH_DELIMITER + item.getKey(), item.getValue());
+ }
+ }
+ } else if (property instanceof List) {
+ for (Object item: (List<Object>)property) {
+ buildPathMappedToValue(path, item, pathsMap);
+ }
+ } else {
+ pathsMap.put(path, property);
+ }
+
+ }
+
@Override
//Sunny flow - covered with UT
public List<NodeTemplate> getServiceVlList() {
diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java
index 28058a5..a0808c5 100644
--- a/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java
+++ b/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java
@@ -343,22 +343,21 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest {
assertEquals(3,cps.size());
- assertEquals(new Integer(1), cps.get("ddc_int_imbl__port").get("ip_requirements#ip_count_required#count"));
- assertEquals(new Boolean(true), cps.get("ddc_int_imbl__port").get("ip_requirements#dhcp_enabled"));
- assertEquals(new Integer(6), cps.get("ddc_int_imbl__port").get("ip_requirements#ip_version"));
- assertEquals(null, cps.get("ddc_int_imbl__port").get("subnetpoolid"));
-
- //assertEquals("\"int_imsp\"", cps.get("mon_ist_imsp__port").get("network_role_tag"));
+ assertEquals(new Integer(1), cps.get("port_ddc_int_imbl__port").get("ip_requirements#ip_count_required#count"));
+ assertEquals(new Boolean(true), cps.get("port_ddc_int_imbl__port").get("ip_requirements#dhcp_enabled"));
+ assertEquals(new Integer(6), cps.get("port_ddc_int_imbl__port").get("ip_requirements#ip_version"));
+ assertEquals("subnetpoolid_test", cps.get("port_ddc_int_imbl__port").get("subnetpoolid"));
+ assertEquals("int_imbl", cps.get("port_ddc_int_imbl__port").get("network_role_tag"));
}
if(vfcs.get(i).getName().equalsIgnoreCase("abstract_mda"))
{
isChecked1 = true;
- Map<String, Map<String, Object>> cps1 = complexCps.getCpPropertiesFromVfc(vfcs.get(i));
+ Map<String, Map<String, Object>> cps1 = complexCps.getCpPropertiesFromVfc(vfcs.get(i));
- assertEquals(new Integer(4), cps1.get("mda_int_imsp__port").get("ip_requirements#ip_version"));
- assertEquals(null, cps1.get("mda_int_imsp__port").get("ip_requirements#ip_count_required#count"));
+ assertEquals(new Integer(4), cps1.get("port_mda_int_imsp__port").get("ip_requirements#ip_version"));
+ assertEquals(null, cps1.get("port_mda_int_imsp__port").get("ip_requirements#ip_count_required#count"));
}
diff --git a/src/test/resources/csars/service-consolidated-props-csar.csar b/src/test/resources/csars/service-consolidated-props-csar.csar
index 37baffb..79f95ce 100644
--- a/src/test/resources/csars/service-consolidated-props-csar.csar
+++ b/src/test/resources/csars/service-consolidated-props-csar.csar
Binary files differ