Interfaces support in SDC Parser 01/42301/1
authorPriyanshuAgarwal <pagarwal@amdocs.com>
Wed, 11 Apr 2018 16:49:30 +0000 (22:19 +0530)
committerpriyanshu <pagarwal@amdocs.com>
Wed, 11 Apr 2018 16:49:30 +0000 (22:19 +0530)
Part 2 of the changes of interface support in SDC Parser.

Change-Id: I0e234415c2dd77a447908359c2f75e7ea3f3f27d
Issue-ID: SDC-1197
Signed-off-by: priyanshu <pagarwal@amdocs.com>
pom.xml
src/main/java/org/onap/sdc/tosca/parser/api/ISdcCsarHelper.java
src/main/java/org/onap/sdc/tosca/parser/impl/SdcCsarHelperImpl.java
src/test/java/org/onap/sdc/impl/SdcToscaParserBasicTest.java
src/test/java/org/onap/sdc/impl/ToscaParserInterfaceTest.java [new file with mode: 0644]
src/test/resources/csars/service-CxSvc-csar.csar [new file with mode: 0644]
version.properties

diff --git a/pom.xml b/pom.xml
index 7091b7c..47497a5 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
        <artifactId>sdc-tosca</artifactId>
        <name>sdc-sdc-tosca</name>
        <description>SDC Tosca Parser JAR file for use by consumers</description>
-       <version>1.3.4-SNAPSHOT</version>
+       <version>1.3.5-SNAPSHOT</version>
        <packaging>jar</packaging>
 
        <properties>
                <dependency>
                        <groupId>org.onap.sdc.jtosca</groupId>
                        <artifactId>jtosca</artifactId>
-                       <version>1.3.4-SNAPSHOT</version>
+                       <version>1.3.5-SNAPSHOT</version>
                </dependency>
 
 
index 4f2ef29..5052ddf 100644 (file)
@@ -27,6 +27,7 @@ import org.apache.commons.lang3.tuple.Pair;
 import org.onap.sdc.tosca.parser.impl.SdcTypes;
 import org.onap.sdc.tosca.parser.impl.FilterType;
 import org.onap.sdc.toscaparser.api.*;
+import org.onap.sdc.toscaparser.api.elements.InterfacesDef;
 import org.onap.sdc.toscaparser.api.elements.Metadata;
 import org.onap.sdc.toscaparser.api.parameters.Input;
 
@@ -560,4 +561,39 @@ public interface ISdcCsarHelper {
      */
     public List<NodeTemplate> getGroupMembersOfOriginOfNodeTemplate(NodeTemplate nodeTemplate, String groupName);
 
+       /**
+        * Get all interface details for given node template.<br>
+        * @return Map that contains the list of all interfaces and their definitions.
+        * If none found, an empty map will be returned.
+        */
+       public Map<String, List<InterfacesDef>> getInterfacesOf(NodeTemplate nt);
+
+       /**
+        * Get all interface names for given node template.<br>
+        * @return List that contains the name of all interfaces.
+        * If none found, an empty list will be returned.
+        */
+       public List<String> getInterfaces(NodeTemplate nt);
+
+       /**
+        * Get all details for given node template and interface name.<br>
+        * @return List that contains the definitions of given interface name.
+        * If none found, an empty list will be returned.
+        */
+       public List<InterfacesDef> getInterfaceDetails(NodeTemplate nt, String interfaceName);
+
+       /**
+        * Get all operation names for given node template and interface name.<br>
+        * @return List that contains the name of all operations for a given node template and interface name.
+        * If none found, an empty list will be returned.
+        */
+       public List<String> getAllInterfaceOperations(NodeTemplate nt, String interfaceName);
+
+       /**
+        * Get interface details for a given node template, interface name and operation name.<br>
+        * @return InterfaceDef representing the operation details.
+        * If none found, null will be returned.
+        */
+       public InterfacesDef getInterfaceOperationDetails(NodeTemplate nt, String interfaceName, String operationName);
+
 }
\ No newline at end of file
index 8e16c14..ee4c7e8 100644 (file)
@@ -48,6 +48,7 @@ import org.onap.sdc.toscaparser.api.RequirementAssignments;
 import org.onap.sdc.toscaparser.api.SubstitutionMappings;
 import org.onap.sdc.toscaparser.api.TopologyTemplate;
 import org.onap.sdc.toscaparser.api.ToscaTemplate;
+import org.onap.sdc.toscaparser.api.elements.InterfacesDef;
 import org.onap.sdc.toscaparser.api.elements.Metadata;
 import org.onap.sdc.toscaparser.api.elements.NodeType;
 import org.onap.sdc.toscaparser.api.functions.Function;
@@ -1082,4 +1083,41 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
         return null;
     }
 
+  @Override
+  public Map<String, List<InterfacesDef>> getInterfacesOf(NodeTemplate nt){
+    if (nt == null) {
+      return null;
+    }
+    return nt.getAllInterfaceDetailsForNodeType();
+  }
+
+  @Override
+  public List<String> getInterfaces(NodeTemplate nt){
+    Map<String, List<InterfacesDef>> interfaceDetails = nt.getAllInterfaceDetailsForNodeType();
+    return new ArrayList<>(interfaceDetails.keySet());
+  }
+
+  @Override
+  public List<InterfacesDef> getInterfaceDetails(NodeTemplate nt, String interfaceName){
+    Map<String, List<InterfacesDef>> interfaceDetails = nt.getAllInterfaceDetailsForNodeType();
+    return interfaceDetails.get(interfaceName);
+  }
+
+  @Override
+  public List<String> getAllInterfaceOperations(NodeTemplate nt, String interfaceName){
+    Map<String, List<InterfacesDef>> interfaceDetails = nt.getAllInterfaceDetailsForNodeType();
+    return interfaceDetails.values().stream().flatMap(List::stream).map(val -> val.getOperationName()).collect(
+        Collectors.toList());
+  }
+
+  @Override
+  public InterfacesDef getInterfaceOperationDetails(NodeTemplate nt, String interfaceName, String operationName){
+    Map<String, List<InterfacesDef>> interfaceDetails = nt.getAllInterfaceDetailsForNodeType();
+    if(!interfaceDetails.isEmpty()){
+      List<InterfacesDef> interfaceDefs = interfaceDetails.get(interfaceName);
+      return interfaceDefs.stream().filter(val -> val.getOperationName().equals(operationName)).findFirst().orElse(null);
+    }
+    return null;
+  }
+
 }
index ff4f3db..08f5bf1 100644 (file)
@@ -42,6 +42,7 @@ public abstract class SdcToscaParserBasicTest {
        static ISdcCsarHelper csarHelperServiceGroupsCapabilities;
        static ISdcCsarHelper csarHelperVfGroupsPolicies;
        static ISdcCsarHelper csarHelperServiceGroupsPolicies;
+       static ISdcCsarHelper csarHelperVfInterfaces;
 
        static Map<String, HashMap<String, List<String>>> fdntCsarHelper_Data;
     
@@ -71,6 +72,7 @@ public abstract class SdcToscaParserBasicTest {
                csarHelperServiceGroupsCapabilities = getCsarHelper("csars/service-VdbePx-csar.csar");
                csarHelperVfGroupsPolicies = getCsarHelper("csars/resource-Vdbe-csar.csar");
                csarHelperServiceGroupsPolicies = getCsarHelper("csars/service-VlanD2dSrv-csar.csar");
+               csarHelperVfInterfaces = getCsarHelper("csars/service-CxSvc-csar.csar");
 
                fdntCsarHelper_Data = new HashMap<String, HashMap<String, List<String>>>(){
                {
diff --git a/src/test/java/org/onap/sdc/impl/ToscaParserInterfaceTest.java b/src/test/java/org/onap/sdc/impl/ToscaParserInterfaceTest.java
new file mode 100644 (file)
index 0000000..e6755e1
--- /dev/null
@@ -0,0 +1,59 @@
+package org.onap.sdc.impl;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+
+import java.util.List;
+import java.util.Map;
+import org.mockito.internal.util.collections.Sets;
+import org.onap.sdc.toscaparser.api.NodeTemplate;
+import org.onap.sdc.toscaparser.api.elements.InterfacesDef;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class ToscaParserInterfaceTest extends SdcToscaParserBasicTest {
+
+    List<NodeTemplate> vfs;
+
+    @BeforeClass
+    public void setup(){
+        vfs = csarHelperVfInterfaces.getServiceVfList();
+    }
+
+    @Test
+    public void testGetInterfaceOf() {
+        Map<String, List<InterfacesDef>> interfaceDetails = csarHelperVfInterfaces.getInterfacesOf(vfs.get(0));
+        assertNotNull(interfaceDetails);
+        assertEquals(interfaceDetails.size(), 2);
+    }
+
+    @Test
+    public void testGetInterfaces() {
+        List<String> interfaceNames = csarHelperVfInterfaces.getInterfaces(vfs.get(0));
+        assertNotNull(interfaceNames);
+        assertEquals(interfaceNames, Sets.newSet("org.openecomp.interfaces.node.lifecycle.CxVnf1", "tosca.interfaces.node.lifecycle.Standard"));
+    }
+
+    @Test
+    public void testGetInterfaceDetails() {
+        List<InterfacesDef> interfaceDetails = csarHelperVfInterfaces.getInterfaceDetails(vfs.get(0), "org.openecomp.interfaces.node.lifecycle.CxVnf1");
+        assertNotNull(interfaceDetails);
+        assertEquals(interfaceDetails.get(0).getOperationName(), "instantiate");
+        assertEquals(interfaceDetails.get(1).getOperationName(), "upgrade");
+    }
+
+    @Test
+    public void testGetAllInterfaceOperations() {
+        List<String> operations = csarHelperVfInterfaces.getAllInterfaceOperations(vfs.get(0), "org.openecomp.interfaces.node.lifecycle.CxVnf1");
+        assertNotNull(operations);
+        assertEquals(operations, Sets.newSet("instantiate", "upgrade", "create", "configure", "start", "stop", "delete"));
+    }
+
+    @Test
+    public void testGetInterfaceOperationDetails() {
+        InterfacesDef interfaceDef = csarHelperVfInterfaces.getInterfaceOperationDetails(vfs.get(0), "org.openecomp.interfaces.node.lifecycle.CxVnf1", "instantiate");
+        assertNotNull(interfaceDef);
+        assertEquals(interfaceDef.getOperationName(), "instantiate");
+    }
+
+}
diff --git a/src/test/resources/csars/service-CxSvc-csar.csar b/src/test/resources/csars/service-CxSvc-csar.csar
new file mode 100644 (file)
index 0000000..feb67c9
Binary files /dev/null and b/src/test/resources/csars/service-CxSvc-csar.csar differ
index a8f201d..a24b0ee 100644 (file)
@@ -5,7 +5,7 @@
 
 major=1
 minor=3
-patch=4
+patch=5
 
 base_version=${major}.${minor}.${patch}