X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fconnect%2Fnetconf%2FNetconfStateSchemas.java;h=d758073a8e5839e942669428239b72d444e646d2;hp=b5400347e7961c1a7c9b4bd621a47b6e7ff495e7;hb=e420318157140a0cf7e9afd5ac33f5814cb54b35;hpb=5c7fe226016d6997f411601502589e86ad9d8f87 diff --git a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfStateSchemas.java b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfStateSchemas.java index b5400347e7..d758073a8e 100644 --- a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfStateSchemas.java +++ b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfStateSchemas.java @@ -93,7 +93,7 @@ public final class NetconfStateSchemas { */ private static NetconfStateSchemas create(final NetconfDeviceRpc deviceRpc, final NetconfSessionCapabilities remoteSessionCapabilities, final RemoteDeviceId id) { if(remoteSessionCapabilities.isMonitoringSupported() == false) { - logger.warn("{}: Netconf monitoring not supported on device, cannot detect available schemas"); + logger.warn("{}: Netconf monitoring not supported on device, cannot detect provided schemas"); return EMPTY; } @@ -115,18 +115,26 @@ public final class NetconfStateSchemas { final CompositeNode schemasNode = (CompositeNode) NetconfMessageTransformUtil.findNode(schemasNodeResult.getResult(), DATA_STATE_SCHEMAS_IDENTIFIER); - return create(schemasNode); + if(schemasNode == null) { + logger.warn("{}: Unable to detect available schemas, get to {} was empty", id, STATE_SCHEMAS_IDENTIFIER); + return EMPTY; + } + + return create(id, schemasNode); } /** * Parse response of get(netconf-state/schemas) to find all schemas under netconf-state/schemas */ @VisibleForTesting - protected static NetconfStateSchemas create(final CompositeNode schemasNode) { + protected static NetconfStateSchemas create(final RemoteDeviceId id, final CompositeNode schemasNode) { final Set availableYangSchemas = Sets.newHashSet(); for (final CompositeNode schemaNode : schemasNode.getCompositesByName(Schema.QNAME.withoutRevision())) { - availableYangSchemas.add(RemoteYangSchema.createFromCompositeNode(schemaNode)); + final Optional fromCompositeNode = RemoteYangSchema.createFromCompositeNode(id, schemaNode); + if(fromCompositeNode.isPresent()) { + availableYangSchemas.add(fromCompositeNode.get()); + } } return new NetconfStateSchemas(availableYangSchemas); @@ -143,19 +151,29 @@ public final class NetconfStateSchemas { return qname; } - static RemoteYangSchema createFromCompositeNode(final CompositeNode schemaNode) { + static Optional createFromCompositeNode(final RemoteDeviceId id, final CompositeNode schemaNode) { Preconditions.checkArgument(schemaNode.getKey().equals(Schema.QNAME.withoutRevision()), "Wrong QName %s", schemaNode.getKey()); QName childNode = NetconfMessageTransformUtil.IETF_NETCONF_MONITORING_SCHEMA_FORMAT.withoutRevision(); - final String formatAsString = getSingleChildNodeValue(schemaNode, childNode).get(); - Preconditions.checkArgument(formatAsString.equals(Yang.QNAME.getLocalName()), - "Expecting format to be only %s, not %s", Yang.QNAME.getLocalName(), formatAsString); + String formatAsString = getSingleChildNodeValue(schemaNode, childNode).get(); + //This is HotFix for situations where format statement in netconf-monitoring might be passed with prefix. + if (formatAsString.contains(":")) { + String[] prefixedString = formatAsString.split(":"); + //FIXME: might be good idea to check prefix against model namespace + formatAsString = prefixedString[1]; + } + if(formatAsString.equals(Yang.QNAME.getLocalName()) == false) { + logger.debug("{}: Ignoring schema due to unsupported format: {}", id, formatAsString); + return Optional.absent(); + } childNode = NetconfMessageTransformUtil.IETF_NETCONF_MONITORING_SCHEMA_LOCATION.withoutRevision(); final Set locationsAsString = getAllChildNodeValues(schemaNode, childNode); - Preconditions.checkArgument(locationsAsString.contains(Schema.Location.Enumeration.NETCONF.toString()), - "Expecting location to be %s, not %s", Schema.Location.Enumeration.NETCONF.toString(), locationsAsString); + if(locationsAsString.contains(Schema.Location.Enumeration.NETCONF.toString()) == false) { + logger.debug("{}: Ignoring schema due to unsupported location: {}", id, locationsAsString); + return Optional.absent(); + } childNode = NetconfMessageTransformUtil.IETF_NETCONF_MONITORING_SCHEMA_NAMESPACE.withoutRevision(); final String namespaceAsString = getSingleChildNodeValue(schemaNode, childNode).get(); @@ -171,7 +189,7 @@ public final class NetconfStateSchemas { ? QName.create(namespaceAsString, revisionAsString.get(), moduleNameAsString) : QName.create(URI.create(namespaceAsString), null, moduleNameAsString).withoutRevision(); - return new RemoteYangSchema(moduleQName); + return Optional.of(new RemoteYangSchema(moduleQName)); } private static Set getAllChildNodeValues(final CompositeNode schemaNode, final QName childNodeQName) { @@ -195,12 +213,18 @@ public final class NetconfStateSchemas { @Override public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } final RemoteYangSchema that = (RemoteYangSchema) o; - if (!qname.equals(that.qname)) return false; + if (!qname.equals(that.qname)) { + return false; + } return true; }