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=68c1a5c6a8828e584e01ffcf4ba85ae519e973ca;hp=b5400347e7961c1a7c9b4bd621a47b6e7ff495e7;hb=6794f32049ae180ef7f896e08ecf7096cec36edf;hpb=f4b583dd481d8db60c894690a6c9189922f360a9 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..68c1a5c6a8 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 @@ -11,7 +11,7 @@ import java.net.URI; import java.util.Collections; import java.util.Set; import java.util.concurrent.ExecutionException; -import org.opendaylight.controller.sal.connect.netconf.listener.NetconfSessionCapabilities; +import org.opendaylight.controller.sal.connect.netconf.listener.NetconfSessionPreferences; import org.opendaylight.controller.sal.connect.netconf.sal.NetconfDeviceRpc; import org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil; import org.opendaylight.controller.sal.connect.util.RemoteDeviceId; @@ -40,7 +40,7 @@ public final class NetconfStateSchemas { * Factory for NetconfStateSchemas */ public interface NetconfStateSchemasResolver { - NetconfStateSchemas resolve(final NetconfDeviceRpc deviceRpc, final NetconfSessionCapabilities remoteSessionCapabilities, final RemoteDeviceId id); + NetconfStateSchemas resolve(final NetconfDeviceRpc deviceRpc, final NetconfSessionPreferences remoteSessionCapabilities, final RemoteDeviceId id); } /** @@ -49,7 +49,7 @@ public final class NetconfStateSchemas { public static final class NetconfStateSchemasResolverImpl implements NetconfStateSchemasResolver { @Override - public NetconfStateSchemas resolve(final NetconfDeviceRpc deviceRpc, final NetconfSessionCapabilities remoteSessionCapabilities, final RemoteDeviceId id) { + public NetconfStateSchemas resolve(final NetconfDeviceRpc deviceRpc, final NetconfSessionPreferences remoteSessionCapabilities, final RemoteDeviceId id) { return NetconfStateSchemas.create(deviceRpc, remoteSessionCapabilities, id); } } @@ -91,9 +91,9 @@ public final class NetconfStateSchemas { /** * Issue get request to remote device and parse response to find all schemas under netconf-state/schemas */ - private static NetconfStateSchemas create(final NetconfDeviceRpc deviceRpc, final NetconfSessionCapabilities remoteSessionCapabilities, final RemoteDeviceId id) { + private static NetconfStateSchemas create(final NetconfDeviceRpc deviceRpc, final NetconfSessionPreferences 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; }