X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fmd-sal%2Fsal-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fconnect%2Fnetconf%2FNetconfDevice.java;h=c0b57de9a0d32ed26c60fa64e8dcfb551c62a354;hb=1447e0132075bbd3013aa41b98384a373bd82d1a;hp=ac84acb2f177a16d3aa110f54ee4bcc692f80664;hpb=5ce3f45de1eb4a6f7abd9b02343ef215d06654c3;p=controller.git diff --git a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDevice.java b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDevice.java index ac84acb2f1..c0b57de9a0 100644 --- a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDevice.java +++ b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDevice.java @@ -21,7 +21,6 @@ import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; import java.util.Collection; -import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Set; @@ -119,7 +118,7 @@ public final class NetconfDevice implements RemoteDevice requiredSources = Sets.newHashSet(Collections2.transform( - remoteSessionCapabilities.getModuleBasedCaps(), QNAME_TO_SOURCE_ID_FUNCTION)); - - // If monitoring is not supported, we will still attempt to create schema, sources might be already provided final NetconfStateSchemas availableSchemas = stateSchemasResolver.resolve(deviceRpc, remoteSessionCapabilities, id); logger.debug("{}: Schemas exposed by ietf-netconf-monitoring: {}", id, availableSchemas.getAvailableYangSchemasQNames()); - final Set providedSources = Sets.newHashSet(Collections2.transform( - availableSchemas.getAvailableYangSchemasQNames(), QNAME_TO_SOURCE_ID_FUNCTION)); - - final Set requiredSourcesNotProvided = Sets.difference(requiredSources, providedSources); + final Set requiredSources = Sets.newHashSet(remoteSessionCapabilities.getModuleBasedCaps()); + final Set providedSources = availableSchemas.getAvailableYangSchemasQNames(); + final Set requiredSourcesNotProvided = Sets.difference(requiredSources, providedSources); if (!requiredSourcesNotProvided.isEmpty()) { logger.warn("{}: Netconf device does not provide all yang models reported in hello message capabilities, required but not provided: {}", id, requiredSourcesNotProvided); logger.warn("{}: Attempting to build schema context from required sources", id); } - // Here all the sources reported in netconf monitoring are merged with those reported in hello. // It is necessary to perform this since submodules are not mentioned in hello but still required. // This clashes with the option of a user to specify supported yang models manually in configuration for netconf-connector // and as a result one is not able to fully override yang models of a device. It is only possible to add additional models. - final Set providedSourcesNotRequired = Sets.difference(providedSources, requiredSources); + final Set providedSourcesNotRequired = Sets.difference(providedSources, requiredSources); if (!providedSourcesNotRequired.isEmpty()) { logger.warn("{}: Netconf device provides additional yang models not reported in hello message capabilities: {}", id, providedSourcesNotRequired); @@ -365,22 +358,30 @@ public final class NetconfDevice implements RemoteDevice requiredSources; - private final Collection providedSources; + private final Set requiredSources; + private final Set providedSources; - public DeviceSources(final Collection requiredSources, final Collection providedSources) { + public DeviceSources(final Set requiredSources, final Set providedSources) { this.requiredSources = requiredSources; this.providedSources = providedSources; } - public Collection getRequiredSources() { + public Set getRequiredSourcesQName() { return requiredSources; } - public Collection getProvidedSources() { + public Set getProvidedSourcesQName() { return providedSources; } + public Collection getRequiredSources() { + return Collections2.transform(requiredSources, QNAME_TO_SOURCE_ID_FUNCTION); + } + + public Collection getProvidedSources() { + return Collections2.transform(providedSources, QNAME_TO_SOURCE_ID_FUNCTION); + } + } /** @@ -413,7 +414,9 @@ public final class NetconfDevice implements RemoteDevice filteredQNames = Sets.difference(remoteSessionCapabilities.getModuleBasedCaps(), capabilities.getUnresolvedCapabilites().keySet()); + final Collection filteredQNames = Sets.difference(deviceSources.getProvidedSourcesQName(), capabilities.getUnresolvedCapabilites().keySet()); capabilities.addCapabilities(filteredQNames); capabilities.addNonModuleBasedCapabilities(remoteSessionCapabilities.getNonModuleCaps()); handleSalInitializationSuccess(result, remoteSessionCapabilities, getDeviceSpecificRpc(result)); @@ -458,7 +461,7 @@ public final class NetconfDevice implements RemoteDevice stripMissingSource(final Collection requiredSources, final SourceIdentifier sIdToRemove) { @@ -469,27 +472,36 @@ public final class NetconfDevice implements RemoteDevice getQNameFromSourceIdentifiers(final Collection identifiers) { - final Collection qNames = new HashSet<>(); - for (final SourceIdentifier source : identifiers) { - final Optional qname = getQNameFromSourceIdentifier(source); - if (qname.isPresent()) { - qNames.add(qname.get()); + final Collection qNames = Collections2.transform(identifiers, new Function() { + @Override + public QName apply(final SourceIdentifier sourceIdentifier) { + return getQNameFromSourceIdentifier(sourceIdentifier); } - } + }); + if (qNames.isEmpty()) { logger.debug("Unable to map any source identfiers to a capability reported by device : " + identifiers); } return qNames; } - private Optional getQNameFromSourceIdentifier(final SourceIdentifier identifier) { - for (final QName qname : remoteSessionCapabilities.getModuleBasedCaps()) { - if (qname.getLocalName().equals(identifier.getName()) - && qname.getFormattedRevision().equals(identifier.getRevision())) { - return Optional.of(qname); + private QName getQNameFromSourceIdentifier(final SourceIdentifier identifier) { + // Required sources are all required and provided merged in DeviceSourcesResolver + for (final QName qname : deviceSources.getRequiredSourcesQName()) { + if(qname.getLocalName().equals(identifier.getName()) == false) { + continue; + } + + if(identifier.getRevision().equals(SourceIdentifier.NOT_PRESENT_FORMATTED_REVISION) && + qname.getRevision() == null) { + return qname; + } + + if (qname.getFormattedRevision().equals(identifier.getRevision())) { + return qname; } } - throw new IllegalArgumentException("Unable to map identifier to a devices reported capability: " + identifier); + throw new IllegalArgumentException("Unable to map identifier to a devices reported capability: " + identifier + " Available: " + deviceSources.getRequiredSourcesQName()); } } }