Handle shcema without namespace.
[netconf.git] / netconf / sal-netconf-connector / src / main / java / org / opendaylight / netconf / sal / connect / netconf / NetconfStateSchemas.java
index d9ca7df3e923572d8acb8aed014450fba92f0163..3986c8f371bceab36e5f93786bafa40a891e201d 100644 (file)
@@ -121,7 +121,7 @@ public final class NetconfStateSchemas implements NetconfDeviceSchemas {
         if(schemasNode.isPresent()) {
             Preconditions.checkState(schemasNode.get() instanceof ContainerNode,
                     "Expecting container containing schemas, but was %s", schemasNode.get());
-            return create(id, ((ContainerNode) schemasNode.get()));
+            return create(id, (ContainerNode) schemasNode.get());
         } else {
             LOG.warn("{}: Unable to detect available schemas, get to {} was empty", id, STATE_SCHEMAS_IDENTIFIER);
             return EMPTY;
@@ -198,7 +198,12 @@ public final class NetconfStateSchemas implements NetconfDeviceSchemas {
             }
 
             childNode = NetconfMessageTransformUtil.IETF_NETCONF_MONITORING_SCHEMA_NAMESPACE;
-            final String namespaceAsString = getSingleChildNodeValue(schemaNode, childNode).get();
+            final Optional<String> namespaceValue = getSingleChildNodeValue(schemaNode, childNode);
+            if (!namespaceValue.isPresent()) {
+                LOG.warn("{}: Ignoring schema due to missing namespace", id);
+                return Optional.absent();
+            }
+            final String namespaceAsString = namespaceValue.get();
 
             childNode = NetconfMessageTransformUtil.IETF_NETCONF_MONITORING_SCHEMA_VERSION;
             // Revision does not have to be filled
@@ -230,8 +235,12 @@ public final class NetconfStateSchemas implements NetconfDeviceSchemas {
 
         private static Optional<String> getSingleChildNodeValue(final DataContainerNode<?> schemaNode, final QName childNode) {
             final Optional<DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> node = schemaNode.getChild(toId(childNode));
-            Preconditions.checkArgument(node.isPresent(), "Child node %s not present", childNode);
-            return getValueOfSimpleNode(node.get());
+            if (node.isPresent()) {
+                return getValueOfSimpleNode(node.get());
+            } else {
+                LOG.debug("Child node {} not present", childNode);
+                return Optional.absent();
+            }
         }
 
         private static Optional<String> getValueOfSimpleNode(final NormalizedNode<? extends YangInstanceIdentifier.PathArgument, ?> node) {