summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEster Rotstein <er767y@att.com>2017-06-20 09:42:36 +0300
committerEster Rotstein <er767y@att.com>2017-06-20 09:45:59 +0300
commitb29c5c244b23bbf549bc4e7637019e28ed48b0c4 (patch)
tree8ce7c46e081aebd233f22b62263255cbf0aa800c /src
parent6b61b88108c5d35efb61cd1006d0a3b9db9d35bf (diff)
[SDC-36] support get nt by sdc type
Change-Id: I0e514827ea7e9a420438a20c369e0b6a9967c66a Signed-off-by: Ester Rotstein <er767y@att.com>
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java18
-rw-r--r--src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java36
-rw-r--r--src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcTypes.java (renamed from src/main/java/org/openecomp/sdc/tosca/parser/impl/Types.java)13
-rw-r--r--src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java43
4 files changed, 88 insertions, 22 deletions
diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java b/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java
index 0317595..eeb23b4 100644
--- a/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java
+++ b/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java
@@ -23,6 +23,7 @@ import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.tuple.Pair;
+import org.openecomp.sdc.tosca.parser.impl.SdcTypes;
import org.openecomp.sdc.toscaparser.api.Group;
import org.openecomp.sdc.toscaparser.api.NodeTemplate;
import org.openecomp.sdc.toscaparser.api.elements.Metadata;
@@ -333,4 +334,21 @@ public interface ISdcCsarHelper {
* @return customization UUID of a node template.
*/
public String getNodeTemplateCustomizationUuid(NodeTemplate nt);
+
+ /**
+ * Get all node templates by sdcType for parent Node Template.
+ *
+ * @param parentNodeTemplate - parent node template
+ * @param sdcType - the SDC type of the node.
+ * @return node templates of this SDC type.
+ */
+ List<NodeTemplate> getNodeTemplateBySdcType(NodeTemplate parentNodeTemplate, SdcTypes sdcType);
+
+ /**
+ * Get all node templates by sdcType for this CSAR service.
+ *
+ * @param sdcType - the SDC type of the node.
+ * @return service node templates of this SDC type.
+ */
+ List<NodeTemplate> getServiceNodeTemplateBySdcType(SdcTypes sdcType);
}
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 612b896..1c4b71b 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
@@ -142,14 +142,14 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
@Override
//Sunny flow - covered with UT
public List<NodeTemplate> getServiceVlList() {
- List<NodeTemplate> serviceVlList = getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), Types.TYPE_VL);
+ List<NodeTemplate> serviceVlList = getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), SdcTypes.VL);
return serviceVlList;
}
@Override
//Sunny flow - covered with UT
public List<NodeTemplate> getServiceVfList() {
- List<NodeTemplate> serviceVfList = getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), Types.TYPE_VF);
+ List<NodeTemplate> serviceVfList = getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), SdcTypes.VF);
return serviceVfList;
}
@@ -205,7 +205,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
List<NodeTemplate> serviceVfList = getServiceVfList();
NodeTemplate vfInstance = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationId);
- return getNodeTemplateBySdcType(vfInstance, Types.TYPE_VFC);
+ return getNodeTemplateBySdcType(vfInstance, SdcTypes.VFC);
}
@Override
@@ -417,7 +417,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
log.debug("getCpListByVf vf list is null");
return cpList;
}
- cpList = getNodeTemplateBySdcType(vfInstance, Types.TYPE_CP);
+ cpList = getNodeTemplateBySdcType(vfInstance, SdcTypes.CP);
if (cpList == null || cpList.size() == 0)
log.debug("getCpListByVf cps not exist for vfCustomizationId {}", vfCustomizationId);
return cpList;
@@ -551,24 +551,23 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
return res;
}
- /************************************* helper functions ***********************************/
- private List<NodeTemplate> getNodeTemplateBySdcType(NodeTemplate nodeTemplate, String sdcType) {
- if (nodeTemplate == null) {
+ public List<NodeTemplate> getNodeTemplateBySdcType(NodeTemplate parentNodeTemplate, SdcTypes sdcType) {
+ if (parentNodeTemplate == null) {
log.error("getNodeTemplateBySdcType - nodeTemplate is null or empty");
return new ArrayList<>();
}
- if (GeneralUtility.isEmptyString(sdcType)) {
+ if (sdcType == null) {
log.error("getNodeTemplateBySdcType - sdcType is null or empty");
return new ArrayList<>();
}
- SubstitutionMappings substitutionMappings = nodeTemplate.getSubMappingToscaTemplate();
+ SubstitutionMappings substitutionMappings = parentNodeTemplate.getSubMappingToscaTemplate();
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());
+ return nodeTemplates.stream().filter(x -> (x.getMetaData() != null && sdcType.toString().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)))).collect(Collectors.toList());
else
log.debug("getNodeTemplateBySdcType - SubstitutionMappings' node Templates not exist");
} else
@@ -577,8 +576,19 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
return new ArrayList<>();
}
- private List<NodeTemplate> getNodeTemplateBySdcType(TopologyTemplate topologyTemplate, String sdcType) {
- if (GeneralUtility.isEmptyString(sdcType)) {
+ public List<NodeTemplate> getServiceNodeTemplateBySdcType(SdcTypes sdcType) {
+ if (sdcType == null) {
+ log.error("getServiceNodeTemplateBySdcType - sdcType is null or empty");
+ return new ArrayList<>();
+ }
+
+ TopologyTemplate topologyTemplate = toscaTemplate.getTopologyTemplate();
+ return getNodeTemplateBySdcType(topologyTemplate, sdcType);
+ }
+
+ /************************************* helper functions ***********************************/
+ private List<NodeTemplate> getNodeTemplateBySdcType(TopologyTemplate topologyTemplate, SdcTypes sdcType) {
+ if (sdcType == null) {
log.error("getNodeTemplateBySdcType - sdcType is null or empty");
return new ArrayList<>();
}
@@ -591,7 +601,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
List<NodeTemplate> nodeTemplates = topologyTemplate.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());
+ return nodeTemplates.stream().filter(x -> (x.getMetaData() != null && sdcType.toString().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)))).collect(Collectors.toList());
log.debug("getNodeTemplateBySdcType - topologyTemplate's nodeTemplates not exist");
return new ArrayList<>();
diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/impl/Types.java b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcTypes.java
index 9e71476..5b68aea 100644
--- a/src/main/java/org/openecomp/sdc/tosca/parser/impl/Types.java
+++ b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcTypes.java
@@ -20,13 +20,8 @@
package org.openecomp.sdc.tosca.parser.impl;
-public class Types {
- public static String TYPE_VFMODULE = "org.openecomp.groups.VfModule";
-
- // types found under metadata, type property
- public static String TYPE_CP = "CP";
- public static String TYPE_VL = "VL";
- public static String TYPE_VF = "VF";
- public static String TYPE_VFC = "VFC";
- public static String TYPE_SERVICE = "Service";
+public enum SdcTypes {
+
+ CP, VL, VF, VFC, PNF, SERVICE
+
}
diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java
index 42a6bd4..f9cedf3 100644
--- a/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java
+++ b/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java
@@ -12,6 +12,7 @@ import java.util.Map;
import org.apache.commons.lang3.tuple.Pair;
import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
+import org.openecomp.sdc.tosca.parser.impl.SdcTypes;
import org.openecomp.sdc.toscaparser.api.Group;
import org.openecomp.sdc.toscaparser.api.NodeTemplate;
import org.testng.annotations.Test;
@@ -394,4 +395,46 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest {
}
//endregion
+ //region getServiceNodeTemplateBySdcType
+ @Test
+ public void testServiceNodeTemplateBySdcType() {
+ List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceNodeTemplateBySdcType(SdcTypes.VF);
+ assertNotNull(serviceVfList);
+ assertEquals(2, serviceVfList.size());
+ assertEquals(serviceVfList.get(0).getName(), "FDNT 1");
+ }
+
+ @Test
+ public void testServiceNodeTemplateByNullSdcType() {
+ List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceNodeTemplateBySdcType(null);
+ assertNotNull(serviceVfList);
+ assertEquals(serviceVfList.size(), 0);
+ }
+ //endregion
+
+ //region getNodeTemplateBySdcType
+ @Test
+ public void testNodeTemplateBySdcType() {
+ List<NodeTemplate> vfList = fdntCsarHelper.getServiceVfList();
+ List<NodeTemplate> vfcList = fdntCsarHelper.getNodeTemplateBySdcType(vfList.get(0), SdcTypes.VFC);
+ assertNotNull(vfcList);
+ assertEquals(2, vfcList.size());
+ assertEquals("DNT_FW_RSG_SI_1", vfcList.get(0).getName());
+ }
+
+ @Test
+ public void testNodeTemplateByNullSdcType() {
+ List<NodeTemplate> vfList = fdntCsarHelper.getServiceVfList();
+ List<NodeTemplate> vfcList = fdntCsarHelper.getNodeTemplateBySdcType(vfList.get(0), null);
+ assertNotNull(vfcList);
+ assertEquals(0, vfcList.size());
+ }
+
+ @Test
+ public void testNodeTemplateBySdcTypeNullNT() {
+ List<NodeTemplate> vfcList = fdntCsarHelper.getNodeTemplateBySdcType(null, SdcTypes.VFC);
+ assertNotNull(vfcList);
+ assertEquals(0, vfcList.size());
+ }
+ //endregion
}