summaryrefslogtreecommitdiffstats
path: root/core/sli
diff options
context:
space:
mode:
Diffstat (limited to 'core/sli')
-rwxr-xr-xcore/sli/common/pom.xml2
-rwxr-xr-xcore/sli/installer/pom.xml2
-rwxr-xr-xcore/sli/model/pom.xml2
-rwxr-xr-xcore/sli/pom.xml2
-rw-r--r--core/sli/provider-base/pom.xml2
-rwxr-xr-xcore/sli/provider/pom.xml22
-rwxr-xr-xcore/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java190
-rw-r--r--core/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/YangUtils.java3
-rwxr-xr-xcore/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelperTest.java13
-rw-r--r--core/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/PrintYangToPropTest.java5
10 files changed, 227 insertions, 16 deletions
diff --git a/core/sli/common/pom.xml b/core/sli/common/pom.xml
index fb6c1055e..6faf31e81 100755
--- a/core/sli/common/pom.xml
+++ b/core/sli/common/pom.xml
@@ -5,7 +5,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>binding-parent</artifactId>
- <version>2.4.0</version>
+ <version>2.4.1-SNAPSHOT</version>
<relativePath/>
</parent>
diff --git a/core/sli/installer/pom.xml b/core/sli/installer/pom.xml
index a88e803d3..7c76d0ace 100755
--- a/core/sli/installer/pom.xml
+++ b/core/sli/installer/pom.xml
@@ -5,7 +5,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>odlparent-lite</artifactId>
- <version>2.4.0</version>
+ <version>2.4.1-SNAPSHOT</version>
<relativePath/>
</parent>
diff --git a/core/sli/model/pom.xml b/core/sli/model/pom.xml
index d4c0da2a9..ff5a329dd 100755
--- a/core/sli/model/pom.xml
+++ b/core/sli/model/pom.xml
@@ -5,7 +5,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>binding-parent</artifactId>
- <version>2.4.0</version>
+ <version>2.4.1-SNAPSHOT</version>
<relativePath/>
</parent>
diff --git a/core/sli/pom.xml b/core/sli/pom.xml
index 473ef6cfd..f127e2857 100755
--- a/core/sli/pom.xml
+++ b/core/sli/pom.xml
@@ -5,7 +5,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>odlparent-lite</artifactId>
- <version>2.4.0</version>
+ <version>2.4.1-SNAPSHOT</version>
<relativePath/>
</parent>
diff --git a/core/sli/provider-base/pom.xml b/core/sli/provider-base/pom.xml
index 43c9da533..a32ccf906 100644
--- a/core/sli/provider-base/pom.xml
+++ b/core/sli/provider-base/pom.xml
@@ -5,7 +5,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>binding-parent</artifactId>
- <version>2.4.0</version>
+ <version>2.4.1-SNAPSHOT</version>
<relativePath/>
</parent>
diff --git a/core/sli/provider/pom.xml b/core/sli/provider/pom.xml
index c207575b9..edcb63ee7 100755
--- a/core/sli/provider/pom.xml
+++ b/core/sli/provider/pom.xml
@@ -5,7 +5,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>binding-parent</artifactId>
- <version>2.4.0</version>
+ <version>2.4.1-SNAPSHOT</version>
<relativePath/>
</parent>
@@ -168,6 +168,26 @@
</environmentVariables>
</configuration>
</plugin>
+ <plugin>
+ <!-- a hint for IDE's to add the java sources to the classpath -->
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>3.0.0</version>
+ <executions>
+ <execution>
+ <id>add-model-sources</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-test-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>${basedir}/../model/target/generated-sources/BindingJavaFileGenerator</source>
+ </sources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
</project>
diff --git a/core/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java b/core/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java
index 37a6a5b24..8ffab7bee 100755
--- a/core/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java
+++ b/core/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java
@@ -311,7 +311,7 @@ public class MdsalHelper {
}
} else if (returnType.equals(Class.class)) {
- } else if (List.class.isAssignableFrom(returnType) || Map.class.isAssignableFrom(returnType)) {
+ } else if (List.class.isAssignableFrom(returnType) || Map.class.isAssignableFrom(returnType) || Set.class.isAssignableFrom(returnType)) {
// This getter method returns a list.
try {
@@ -320,8 +320,12 @@ public class MdsalHelper {
m.setAccessible(true);
}
Object retList = m.invoke(fromObj);
- if ((retList != null) && Map.class.isAssignableFrom(returnType)) {
- retList = new ArrayList(((Map)retList).values());
+ if (retList != null) {
+ if (Map.class.isAssignableFrom(returnType)) {
+ retList = new ArrayList(((Map) retList).values());
+ } else if (Set.class.isAssignableFrom(returnType)) {
+ retList = new ArrayList(((Set) retList));
+ }
}
//due duplicated getters with Map and List(deprecated) stop if already mapped
if(!hasAlreadyKeys(props,propNamePfx + "." + fieldName)) {
@@ -658,6 +662,155 @@ public class MdsalHelper {
}
}
+ public static Set toSet(Properties props, String pfx, Set toObj, Class elemType) {
+
+ int maxIdx = -1;
+ boolean foundValue = false;
+
+ if (props.containsKey(pfx + "_length")) {
+ try {
+ int listLength = Integer.parseInt(props.getProperty(pfx + "_length"));
+
+ if (listLength > 0) {
+ maxIdx = listLength - 1;
+ }
+ } catch (NumberFormatException e) {
+ LOG.info("Invalid input for length ", e);
+ }
+ }
+
+ String arrayKey = pfx + "[";
+ int arrayKeyLength = arrayKey.length();
+ if (maxIdx == -1) {
+ // Figure out array size
+ for (Object pNameObj : props.keySet()) {
+ String key = (String) pNameObj;
+
+ if (key.startsWith(arrayKey)) {
+ String idxStr = key.substring(arrayKeyLength);
+ int endloc = idxStr.indexOf("]");
+ if (endloc != -1) {
+ idxStr = idxStr.substring(0, endloc);
+ }
+ try {
+ int curIdx = Integer.parseInt(idxStr);
+ if (curIdx > maxIdx) {
+ maxIdx = curIdx;
+ }
+ } catch (Exception e) {
+ LOG.error("Illegal subscript in property {}", key, e);
+ }
+
+ }
+ }
+ }
+
+ for (int i = 0; i <= maxIdx; i++) {
+
+ String curBase = pfx + "[" + i + "]";
+
+ // Sets are used to represent yang system-ordered leaf-lists.
+ // Each entry in the Set is an yang-generated object,
+ // to be constructed by a builder.
+ if (isYangGenerated(elemType)) {
+
+ if (isIpAddress(elemType)) {
+
+ String curValue = props.getProperty(curBase, "");
+
+ if ((curValue != null) && (curValue.length() > 0)) {
+ toObj.add(IpAddressBuilder.getDefaultInstance(curValue));
+ foundValue = true;
+ }
+ } else if (isIpv4Address(elemType)) {
+ String curValue = props.getProperty(curBase, "");
+
+ if ((curValue != null) && (curValue.length() > 0)) {
+ toObj.add(new Ipv4Address(curValue));
+ foundValue = true;
+ }
+
+ } else if (isIpv6Address(elemType)) {
+ String curValue = props.getProperty(curBase, "");
+
+ if ((curValue != null) && (curValue.length() > 0)) {
+ toObj.add(new Ipv6Address(curValue));
+ foundValue = true;
+ }
+ } else if (isIpPrefix(elemType)) {
+
+ String curValue = props.getProperty(curBase, "");
+
+ if ((curValue != null) && (curValue.length() > 0)) {
+ toObj.add(IpPrefixBuilder.getDefaultInstance(curValue));
+ foundValue = true;
+ }
+ } else if (isPortNumber(elemType)) {
+
+ String curValue = props.getProperty(curBase, "");
+
+ if ((curValue != null) && (curValue.length() > 0)) {
+ toObj.add(PortNumber.getDefaultInstance(curValue));
+ foundValue = true;
+ }
+ } else if (isDscp(elemType)) {
+
+ String curValue = props.getProperty(curBase, "");
+
+ if ((curValue != null) && (curValue.length() > 0)) {
+ toObj.add(Dscp.getDefaultInstance(curValue));
+ foundValue = true;
+ }
+ } else if (elemType.isEnum()) {
+ String curValue = props.getProperty(curBase, "");
+ Object elemObj = null;
+
+ try {
+ elemObj = Enum.valueOf(elemType, toJavaEnum(curValue));
+ } catch (Exception e) {
+ LOG.error("Caught exception trying to convert field " + curBase + " to enum "
+ + elemType.getName(), e);
+ }
+ toObj.add(elemObj);
+ foundValue = true;
+ } else {
+ String builderName = elemType.getName() + "Builder";
+ try {
+ Class builderClass = Class.forName(builderName);
+ Object builderObj = builderClass.newInstance();
+ Method buildMethod = builderClass.getMethod("build");
+ builderObj = toBuilder(props, curBase, builderObj, true);
+ if (builderObj != null) {
+ Object builtObj = buildMethod.invoke(builderObj);
+ toObj.add(builtObj);
+ foundValue = true;
+ }
+
+ } catch (ClassNotFoundException e) {
+ LOG.warn("Could not find builder class {}", builderName, e);
+ } catch (Exception e) {
+ LOG.error("Caught exception trying to populate list from {}", pfx, e);
+ }
+ }
+ } else {
+ // Must be a leaf list
+ String curValue = props.getProperty(curBase, "");
+
+ toObj.add(curValue);
+
+ if ((curValue != null) && (curValue.length() > 0)) {
+ foundValue = true;
+ }
+ }
+ }
+
+ if (foundValue) {
+ return (toObj);
+ } else {
+ return (null);
+ }
+ }
+
public static Object toBuilder(Properties props, String pfx, Object toObj) {
return (toBuilder(props, pfx, toObj, false));
}
@@ -1119,6 +1272,37 @@ public class MdsalHelper {
+ "." + m.getName() + "() to Properties entry", e);
}
}
+ } else if (Set.class.isAssignableFrom(paramClass)) {
+ // Figure out what type of args are in Set and pass
+ // that to toList().
+
+ Type paramType = m.getGenericParameterTypes()[0];
+ Type elementType = ((ParameterizedType) paramType).getActualTypeArguments()[0];
+ Object paramObj = new HashSet();
+ try {
+ paramObj = toSet(props, propName, (Set) paramObj, (Class) elementType);
+ } catch (Exception e) {
+ LOG.error("Caught exception trying to create list expected as argument to {}.{}",
+ toClass.getName(), m.getName(), e);
+ }
+
+ if (paramObj != null) {
+ try {
+ boolean isAccessible = m.isAccessible();
+ if (!isAccessible) {
+ m.setAccessible(true);
+ }
+ m.invoke(toObj, paramObj);
+ if (!isAccessible) {
+ m.setAccessible(isAccessible);
+ }
+ foundValue = true;
+
+ } catch (Exception e) {
+ LOG.error("Caught exception trying to convert List returned by" + toClass.getName()
+ + "." + m.getName() + "() to Properties entry", e);
+ }
+ }
} else {
// Setter expects something that is not a List and
diff --git a/core/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/YangUtils.java b/core/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/YangUtils.java
index 573444bf2..e4d7618fe 100644
--- a/core/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/YangUtils.java
+++ b/core/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/YangUtils.java
@@ -401,7 +401,8 @@ public final class YangUtils {
}
public static Module findParentModule(final SchemaContext context, final SchemaNode schemaNode) {
- final QName qname = schemaNode.getPath().getLastComponent();
+ //final QName qname = schemaNode.getPath().getLastComponent();
+ final QName qname = schemaNode.getQName();
checkState(qname != null, "Schema Path contains invalid state of path parts. "
+ "The Schema Path MUST contain at least ONE QName which defines namespace and Local name of path.");
return context.findModule(qname.getModule()).orElse(null);
diff --git a/core/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelperTest.java b/core/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelperTest.java
index 0c06923e2..1e4b67d8f 100755
--- a/core/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelperTest.java
+++ b/core/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelperTest.java
@@ -477,7 +477,7 @@ public class MdsalHelperTest extends TestCase {
public void testToPropertiesWithDecimal64() throws Exception {
SampleContainerBuilder sampleBuilder = new SampleContainerBuilder();
- BigDecimal myBigDecimal = new BigDecimal(".0000000000000000000000000000001");
+ Decimal64 myBigDecimal = Decimal64.valueOf(".000000000000000001");
sampleBuilder.setSampleDecimal64(myBigDecimal);
Properties props = new Properties();
MdsalHelper.toProperties(props, sampleBuilder);
@@ -487,7 +487,7 @@ public class MdsalHelperTest extends TestCase {
public void testToPropertiesWithEmpty() throws Exception {
SampleContainerBuilder sampleBuilder = new SampleContainerBuilder();
- Empty isEmpty = Empty.getInstance();
+ Empty isEmpty = Empty.value();
sampleBuilder.setSampleEmpty(isEmpty);
Properties props = new Properties();
MdsalHelper.toProperties(props, sampleBuilder);
@@ -646,8 +646,7 @@ public class MdsalHelperTest extends TestCase {
public void testToPropertiesWithLeaftList() throws Exception {
SampleContainerBuilder sampleBuilder = new SampleContainerBuilder();
- List<String> nickNames = new ArrayList<String>();
- sampleBuilder.setCustomerNicknames(nickNames);
+ Set<String> nickNames = new LinkedHashSet<String>();
String nameOne = "coffee";
String nameTwo = "java";
String nameThree = "mud";
@@ -655,10 +654,13 @@ public class MdsalHelperTest extends TestCase {
nickNames.add(nameOne);
nickNames.add(nameTwo);
nickNames.add(nameThree);
+ sampleBuilder.setCustomerNicknames(nickNames);
Properties props = new Properties();
MdsalHelper.toProperties(props, sampleBuilder);
+ props.forEach((k, v) -> { LOG.info("Property {} = {}", k, v);});
+
assertEquals(nameOne, props.get("sample-container.customer-nicknames[0]"));
assertEquals(nameTwo, props.get("sample-container.customer-nicknames[1]"));
assertEquals(nameThree, props.get("sample-container.customer-nicknames[2]"));
@@ -813,7 +815,8 @@ public class MdsalHelperTest extends TestCase {
assertEquals(true, ipAddrIter.hasNext());
assertEquals("10.20.0.1", ipAddrIter.next().getIpAddr().stringValue());
assertEquals(1, result.getIpAddressLeafList().size());
- assertEquals("127.0.0.1", result.getIpAddressLeafList().get(0).stringValue());
+ IpAddress[] ipAddressArray = result.getIpAddressLeafList().toArray(new IpAddress[0]);
+ assertEquals("127.0.0.1", ipAddressArray[0].stringValue());
Map<IpAddressNamesKey, IpAddressNames> ipNamesMap = result.getIpAddressNames();
Iterator<IpAddressNames> ipNamesIter = ipNamesMap.values().iterator();
assertEquals(true, ipNamesIter.hasNext());
diff --git a/core/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/PrintYangToPropTest.java b/core/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/PrintYangToPropTest.java
index ada933d88..1ccbc90e9 100644
--- a/core/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/PrintYangToPropTest.java
+++ b/core/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/PrintYangToPropTest.java
@@ -24,10 +24,13 @@ package org.onap.ccsdk.sli.core.sli.provider;
import java.util.Enumeration;
import java.util.HashMap;
+import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
+import java.util.Set;
+
import org.junit.Test;
import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.ExecuteGraphInput.Mode;
import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.ExecuteGraphInputBuilder;
@@ -119,7 +122,7 @@ public class PrintYangToPropTest {
// Set builder with values
Map<TestResultKey, TestResult> resultList = new HashMap<>();
resultBuilder.setTestIdentifier("test1");
- List<String> results = new LinkedList<>();
+ Set<String> results = new LinkedHashSet <String>();
results.add("pass");
resultBuilder.setResults(results);
resultList.put(new TestResultKey(resultBuilder.getTestIdentifier()), resultBuilder.build());