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;
}
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
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) {
private static final NetconfSessionPreferences CAPS = NetconfSessionPreferences.fromStrings(Collections.singleton("urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring?module=ietf-netconf-monitoring&revision=2010-10-04"));
private final RemoteDeviceId deviceId = new RemoteDeviceId("device", new InetSocketAddress(99));
private ContainerNode compositeNodeSchemas;
+ private final int NUMBER_OF_SCHEMAS = 73;
+ private final int NUMBER_OF_LEGAL_SCHEMAS = NUMBER_OF_SCHEMAS - 3;
+
@Mock
private DOMRpcService rpc;
final NetconfStateSchemas schemas = NetconfStateSchemas.create(deviceId, compositeNodeSchemas);
final Set<QName> availableYangSchemasQNames = schemas.getAvailableYangSchemasQNames();
- assertEquals(73, availableYangSchemasQNames.size());
+ assertEquals(NUMBER_OF_LEGAL_SCHEMAS, availableYangSchemasQNames.size());
assertThat(availableYangSchemasQNames,
hasItem(QName.create("urn:TBD:params:xml:ns:yang:network-topology", "2013-07-12", "network-topology")));
when(rpc.invokeRpc(eq(toPath(NETCONF_GET_QNAME)), any())).thenReturn(Futures.immediateCheckedFuture(new DefaultDOMRpcResult(rpcReply)));
final NetconfStateSchemas stateSchemas = NetconfStateSchemas.create(rpc, CAPS, deviceId);
final Set<QName> availableYangSchemasQNames = stateSchemas.getAvailableYangSchemasQNames();
- assertEquals(73, availableYangSchemasQNames.size());
+ assertEquals(NUMBER_OF_LEGAL_SCHEMAS, availableYangSchemasQNames.size());
assertThat(availableYangSchemasQNames,
hasItem(QName.create("urn:TBD:params:xml:ns:yang:network-topology", "2013-07-12", "network-topology")));
<ncm:version>2014-01-31</ncm:version>
</ncm:schema>
<ncm:schema>
- <ncm:namespace>urn:opendaylight:flow:types</ncm:namespace>
<ncm:location>NETCONF</ncm:location>
<ncm:identifier>opendaylight-flow-types</ncm:identifier>
<ncm:format xmlns:prefix="urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring">prefix:yang</ncm:format>
<ncm:version>2013-10-26</ncm:version>
</ncm:schema>
<ncm:schema>
- <ncm:namespace>urn:opendaylight:params:xml:ns:yang:controller:shutdown:impl</ncm:namespace>
<ncm:location>NETCONF</ncm:location>
<ncm:identifier>shutdown-impl</ncm:identifier>
<ncm:format xmlns:prefix="urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring">prefix:yang</ncm:format>
<ncm:version>2013-12-18</ncm:version>
</ncm:schema>
<ncm:schema>
- <ncm:namespace>urn:opendaylight:model:topology:inventory</ncm:namespace>
<ncm:location>NETCONF</ncm:location>
<ncm:identifier>opendaylight-topology-inventory</ncm:identifier>
<ncm:format xmlns:prefix="urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring">prefix:yang</ncm:format>
<ncm:version>2013-10-30</ncm:version>
</ncm:schema>
-</ncm:schemas>
\ No newline at end of file
+</ncm:schemas>