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;
* 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);
}
/**
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);
}
}
/**
* 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 provided schemas");
return EMPTY;
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<RemoteYangSchema> availableYangSchemas = Sets.newHashSet();
for (final CompositeNode schemaNode : schemasNode.getCompositesByName(Schema.QNAME.withoutRevision())) {
- availableYangSchemas.add(RemoteYangSchema.createFromCompositeNode(schemaNode));
+ final Optional<RemoteYangSchema> fromCompositeNode = RemoteYangSchema.createFromCompositeNode(id, schemaNode);
+ if(fromCompositeNode.isPresent()) {
+ availableYangSchemas.add(fromCompositeNode.get());
+ }
}
return new NetconfStateSchemas(availableYangSchemas);
return qname;
}
- static RemoteYangSchema createFromCompositeNode(final CompositeNode schemaNode) {
+ static Optional<RemoteYangSchema> 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<String> 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();
? 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<String> getAllChildNodeValues(final CompositeNode schemaNode, final QName childNodeQName) {
@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;
}