Remove no-schema reconnect
[netconf.git] / netconf / sal-netconf-connector / src / main / java / org / opendaylight / netconf / sal / connect / netconf / NetconfDevice.java
index 0c589810ca0b3d22d9b847e706a2be25bd0cef1b..89ce12533b035867ee049ff00f8ec407577a9ee7 100644 (file)
@@ -20,22 +20,20 @@ import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.ListeningExecutorService;
 import com.google.common.util.concurrent.MoreExecutors;
 import com.google.common.util.concurrent.SettableFuture;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
-import io.netty.util.concurrent.EventExecutor;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.LinkedList;
 import java.util.List;
-import java.util.Optional;
+import java.util.Objects;
 import java.util.Set;
 import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 import org.checkerframework.checker.lock.qual.GuardedBy;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
 import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.netconf.api.NetconfMessage;
+import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.opendaylight.netconf.sal.connect.api.DeviceActionFactory;
 import org.opendaylight.netconf.sal.connect.api.MessageTransformer;
 import org.opendaylight.netconf.sal.connect.api.NetconfDeviceSchemasResolver;
@@ -46,17 +44,17 @@ import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabi
 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator;
 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
 import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas;
 import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseSchema;
 import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer;
 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.optional.rev190614.NetconfNodeAugmentedOptional;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.available.capabilities.AvailableCapabilityBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.unavailable.capabilities.UnavailableCapability;
-import org.opendaylight.yangtools.rcf8528.data.util.EmptyMountPointContext;
+import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.rfc8528.data.api.MountPointContext;
+import org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext;
 import org.opendaylight.yangtools.rfc8528.model.api.SchemaMountConstants;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.RpcError;
@@ -72,9 +70,6 @@ import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
-import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
-import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
-import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration;
 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -82,12 +77,8 @@ import org.slf4j.LoggerFactory;
 /**
  *  This is a mediator between NetconfDeviceCommunicator and NetconfDeviceSalFacade.
  */
-public class NetconfDevice
-        implements RemoteDevice<NetconfSessionPreferences, NetconfMessage, NetconfDeviceCommunicator> {
-
-    @SuppressFBWarnings(value = "SLF4J_LOGGER_SHOULD_BE_PRIVATE",
-            justification = "Needed for common logging of related classes")
-    static final Logger LOG = LoggerFactory.getLogger(NetconfDevice.class);
+public class NetconfDevice implements RemoteDevice<NetconfDeviceCommunicator> {
+    private static final Logger LOG = LoggerFactory.getLogger(NetconfDevice.class);
 
     private static final QName RFC8528_SCHEMA_MOUNTS_QNAME = QName.create(
         SchemaMountConstants.RFC8528_MODULE, "schema-mounts").intern();
@@ -99,50 +90,43 @@ public class NetconfDevice
     protected final SchemaSourceRegistry schemaRegistry;
     protected final SchemaRepository schemaRepository;
 
-    protected final List<SchemaSourceRegistration<?>> sourceRegistrations = new ArrayList<>();
+    protected final List<Registration> sourceRegistrations = new ArrayList<>();
 
-    private final RemoteDeviceHandler<NetconfSessionPreferences> salFacade;
+    private final RemoteDeviceHandler salFacade;
     private final ListeningExecutorService processingExecutor;
     private final DeviceActionFactory deviceActionFactory;
     private final NetconfDeviceSchemasResolver stateSchemasResolver;
     private final NotificationHandler notificationHandler;
     private final boolean reconnectOnSchemasChange;
-    private final NetconfNode node;
-    private final EventExecutor eventExecutor;
-    private final NetconfNodeAugmentedOptional nodeOptional;
+    private final BaseNetconfSchemas baseSchemas;
 
     @GuardedBy("this")
     private boolean connected = false;
 
     // Message transformer is constructed once the schemas are available
-    private MessageTransformer<NetconfMessage> messageTransformer;
-
-    public NetconfDevice(final SchemaResourcesDTO schemaResourcesDTO, final RemoteDeviceId id,
-                         final RemoteDeviceHandler<NetconfSessionPreferences> salFacade,
-                         final ListeningExecutorService globalProcessingExecutor,
-                         final boolean reconnectOnSchemasChange) {
-        this(schemaResourcesDTO, id, salFacade, globalProcessingExecutor, reconnectOnSchemasChange, null, null, null,
-                null);
+    private MessageTransformer messageTransformer;
+
+    public NetconfDevice(final SchemaResourcesDTO schemaResourcesDTO, final BaseNetconfSchemas baseSchemas,
+            final RemoteDeviceId id, final RemoteDeviceHandler salFacade,
+            final ListeningExecutorService globalProcessingExecutor, final boolean reconnectOnSchemasChange) {
+        this(schemaResourcesDTO, baseSchemas, id, salFacade, globalProcessingExecutor, reconnectOnSchemasChange, null);
     }
 
-    public NetconfDevice(final SchemaResourcesDTO schemaResourcesDTO, final RemoteDeviceId id,
-            final RemoteDeviceHandler<NetconfSessionPreferences> salFacade,
+    public NetconfDevice(final SchemaResourcesDTO schemaResourcesDTO, final BaseNetconfSchemas baseSchemas,
+            final RemoteDeviceId id, final RemoteDeviceHandler salFacade,
             final ListeningExecutorService globalProcessingExecutor, final boolean reconnectOnSchemasChange,
-            final DeviceActionFactory deviceActionFactory, final NetconfNode node, final EventExecutor eventExecutor,
-            final NetconfNodeAugmentedOptional nodeOptional) {
+            final DeviceActionFactory deviceActionFactory) {
+        this.baseSchemas = requireNonNull(baseSchemas);
         this.id = id;
         this.reconnectOnSchemasChange = reconnectOnSchemasChange;
         this.deviceActionFactory = deviceActionFactory;
-        this.node = node;
-        this.eventExecutor = eventExecutor;
-        this.nodeOptional = nodeOptional;
-        this.schemaRegistry = schemaResourcesDTO.getSchemaRegistry();
-        this.schemaRepository = schemaResourcesDTO.getSchemaRepository();
-        this.schemaContextFactory = schemaResourcesDTO.getSchemaContextFactory();
+        schemaRegistry = schemaResourcesDTO.getSchemaRegistry();
+        schemaRepository = schemaResourcesDTO.getSchemaRepository();
+        schemaContextFactory = schemaResourcesDTO.getSchemaContextFactory();
         this.salFacade = salFacade;
-        this.stateSchemasResolver = schemaResourcesDTO.getStateSchemasResolver();
-        this.processingExecutor = requireNonNull(globalProcessingExecutor);
-        this.notificationHandler = new NotificationHandler(salFacade, id);
+        stateSchemasResolver = schemaResourcesDTO.getStateSchemasResolver();
+        processingExecutor = requireNonNull(globalProcessingExecutor);
+        notificationHandler = new NotificationHandler(salFacade, id);
     }
 
     @Override
@@ -157,7 +141,7 @@ public class NetconfDevice
         LOG.debug("{}: Session to remote device established with {}", id, remoteSessionCapabilities);
 
         final BaseSchema baseSchema = resolveBaseSchema(remoteSessionCapabilities.isNotificationsSupported());
-        final NetconfDeviceRpc initRpc = new NetconfDeviceRpc(baseSchema.getSchemaContext(), listener,
+        final NetconfDeviceRpc initRpc = new NetconfDeviceRpc(baseSchema.getEffectiveModelContext(), listener,
             new NetconfMessageTransformer(baseSchema.getMountPointContext(), false, baseSchema));
         final ListenableFuture<DeviceSources> sourceResolverFuture = processingExecutor.submit(
             new DeviceSourcesResolver(id, baseSchema, initRpc, remoteSessionCapabilities, stateSchemasResolver));
@@ -178,28 +162,14 @@ public class NetconfDevice
             @Override
             public void onSuccess(final MountPointContext result) {
                 handleSalInitializationSuccess(result, remoteSessionCapabilities,
-                    getDeviceSpecificRpc(result, listener), listener);
+                        getDeviceSpecificRpc(result, listener, baseSchema), listener);
             }
 
             @Override
             public void onFailure(final Throwable cause) {
                 LOG.warn("{}: Unexpected error resolving device sources", id, cause);
-
-                // No more sources, fail or try to reconnect
-                if (cause instanceof EmptySchemaContextException) {
-                    if (nodeOptional != null && nodeOptional.getIgnoreMissingSchemaSources().isAllowed()) {
-                        eventExecutor.schedule(() -> {
-                            LOG.warn("Reconnection is allowed! This can lead to unexpected errors at runtime.");
-                            LOG.warn("{} : No more sources for schema context.", id);
-                            LOG.info("{} : Try to remount device.", id);
-                            onRemoteSessionDown();
-                            salFacade.onDeviceReconnected(remoteSessionCapabilities, node);
-                        }, nodeOptional.getIgnoreMissingSchemaSources().getReconnectTime().toJava(),
-                            TimeUnit.MILLISECONDS);
-                        return;
-                    }
-                }
-
+                // FIXME: this causes salFacade to see onDeviceDisconnected() and then onDeviceFailed(), which is quite
+                //        weird
                 handleSalInitializationFailure(cause, listener);
                 salFacade.onDeviceFailed(cause);
             }
@@ -212,21 +182,21 @@ public class NetconfDevice
         // Perhaps add a default schema context to support create-subscription if the model was not provided
         // (same as what we do for base netconf operations in transformer)
         final ListenableFuture<DOMRpcResult> rpcResultListenableFuture = deviceRpc.invokeRpc(
-                NetconfMessageTransformUtil.CREATE_SUBSCRIPTION_RPC_PATH,
+                NetconfMessageTransformUtil.CREATE_SUBSCRIPTION_RPC_QNAME,
                 NetconfMessageTransformUtil.CREATE_SUBSCRIPTION_RPC_CONTENT);
 
         Futures.addCallback(rpcResultListenableFuture, new FutureCallback<DOMRpcResult>() {
             @Override
             public void onSuccess(final DOMRpcResult domRpcResult) {
                 notificationHandler.addNotificationFilter(notification -> {
-                    if (NetconfCapabilityChange.QNAME.equals(notification.getBody().getNodeType())) {
+                    if (NetconfCapabilityChange.QNAME.equals(notification.getBody().getIdentifier().getNodeType())) {
                         LOG.info("{}: Schemas change detected, reconnecting", id);
                         // Only disconnect is enough,
                         // the reconnecting nature of the connector will take care of reconnecting
                         listener.disconnect();
-                        return Optional.empty();
+                        return false;
                     }
-                    return Optional.of(notification);
+                    return true;
                 });
             }
 
@@ -242,25 +212,20 @@ public class NetconfDevice
         return remoteSessionCapabilities.isNotificationsSupported() && reconnectOnSchemasChange;
     }
 
-    @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
-            justification = "https://github.com/spotbugs/spotbugs/issues/811")
     private synchronized void handleSalInitializationSuccess(final MountPointContext result,
-                                        final NetconfSessionPreferences remoteSessionCapabilities,
-                                        final DOMRpcService deviceRpc,
-                                        final RemoteDeviceCommunicator<NetconfMessage> listener) {
+            final NetconfSessionPreferences remoteSessionCapabilities, final DOMRpcService deviceRpc,
+            final RemoteDeviceCommunicator listener) {
         //NetconfDevice.SchemaSetup can complete after NetconfDeviceCommunicator was closed. In that case do nothing,
         //since salFacade.onDeviceDisconnected was already called.
         if (connected) {
-            final BaseSchema baseSchema =
-                remoteSessionCapabilities.isNotificationsSupported()
-                        ? BaseSchema.BASE_NETCONF_CTX_WITH_NOTIFICATIONS : BaseSchema.BASE_NETCONF_CTX;
-            this.messageTransformer = new NetconfMessageTransformer(result, true, baseSchema);
+            messageTransformer = new NetconfMessageTransformer(result, true,
+                resolveBaseSchema(remoteSessionCapabilities.isNotificationsSupported()));
 
             // salFacade.onDeviceConnected has to be called before the notification handler is initialized
-            this.salFacade.onDeviceConnected(result, remoteSessionCapabilities, deviceRpc,
-                    this.deviceActionFactory == null ? null : this.deviceActionFactory.createDeviceAction(
-                            this.messageTransformer, listener, result.getSchemaContext()));
-            this.notificationHandler.onRemoteSchemaUp(this.messageTransformer);
+            salFacade.onDeviceConnected(result, remoteSessionCapabilities, deviceRpc,
+                    deviceActionFactory == null ? null : deviceActionFactory.createDeviceAction(
+                            messageTransformer, listener, result.getEffectiveModelContext()));
+            notificationHandler.onRemoteSchemaUp(messageTransformer);
 
             LOG.info("{}: Netconf connector initialized successfully", id);
         } else {
@@ -268,10 +233,7 @@ public class NetconfDevice
         }
     }
 
-    @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
-            justification = "https://github.com/spotbugs/spotbugs/issues/811")
-    private void handleSalInitializationFailure(final Throwable throwable,
-                                                final RemoteDeviceCommunicator<NetconfMessage> listener) {
+    private void handleSalInitializationFailure(final Throwable throwable, final RemoteDeviceCommunicator listener) {
         LOG.error("{}: Initialization in sal failed, disconnecting from device", id, throwable);
         listener.close();
         onRemoteSessionDown();
@@ -285,7 +247,7 @@ public class NetconfDevice
         updateTransformer(null);
     }
 
-    private synchronized void updateTransformer(final MessageTransformer<NetconfMessage> transformer) {
+    private synchronized void updateTransformer(final MessageTransformer transformer) {
         messageTransformer = transformer;
     }
 
@@ -293,17 +255,11 @@ public class NetconfDevice
         this.connected = connected;
     }
 
-    @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
-            justification = "https://github.com/spotbugs/spotbugs/issues/811")
     private ListenableFuture<EffectiveModelContext> assembleSchemaContext(final DeviceSources deviceSources,
             final NetconfSessionPreferences remoteSessionCapabilities) {
         LOG.debug("{}: Resolved device sources to {}", id, deviceSources);
-        final SchemaSourceProvider<YangTextSchemaSource> yangProvider = deviceSources.getSourceProvider();
-        for (final SourceIdentifier sourceId : deviceSources.getProvidedSources()) {
-            sourceRegistrations.add(schemaRegistry.registerSchemaSource(yangProvider,
-                PotentialSchemaSource.create(sourceId, YangTextSchemaSource.class,
-                    PotentialSchemaSource.Costs.REMOTE_IO.getValue())));
-        }
+
+        sourceRegistrations.addAll(deviceSources.register(schemaRegistry));
 
         return new SchemaSetup(deviceSources, remoteSessionCapabilities).startResolution();
     }
@@ -311,7 +267,7 @@ public class NetconfDevice
     private ListenableFuture<MountPointContext> createMountPointContext(final EffectiveModelContext schemaContext,
             final BaseSchema baseSchema, final NetconfDeviceCommunicator listener) {
         final MountPointContext emptyContext = new EmptyMountPointContext(schemaContext);
-        if (!schemaContext.findModule(SchemaMountConstants.RFC8528_MODULE).isPresent()) {
+        if (schemaContext.findModule(SchemaMountConstants.RFC8528_MODULE).isEmpty()) {
             return Futures.immediateFuture(emptyContext);
         }
 
@@ -320,7 +276,7 @@ public class NetconfDevice
         final NetconfDeviceRpc deviceRpc = new NetconfDeviceRpc(schemaContext, listener,
             new NetconfMessageTransformer(emptyContext, false, baseSchema));
 
-        return Futures.transform(deviceRpc.invokeRpc(NetconfMessageTransformUtil.NETCONF_GET_PATH,
+        return Futures.transform(deviceRpc.invokeRpc(NetconfMessageTransformUtil.NETCONF_GET_QNAME,
             Builders.containerBuilder().withNodeIdentifier(NETCONF_GET_NODEID)
                 .withChild(NetconfMessageTransformUtil.toFilterStructure(RFC8528_SCHEMA_MOUNTS, schemaContext))
                 .build()), rpcResult -> processSchemaMounts(rpcResult, emptyContext), MoreExecutors.directExecutor());
@@ -331,7 +287,7 @@ public class NetconfDevice
         if (!errors.isEmpty()) {
             LOG.warn("{}: Schema-mounts acquisition resulted in errors {}", id, errors);
         }
-        final NormalizedNode<?, ?> schemaMounts = rpcResult.getResult();
+        final NormalizedNode schemaMounts = rpcResult.getResult();
         if (schemaMounts == null) {
             LOG.debug("{}: device does not define any schema mounts", id);
             return emptyContext;
@@ -350,7 +306,7 @@ public class NetconfDevice
         notificationHandler.onRemoteSchemaDown();
 
         salFacade.onDeviceDisconnected();
-        sourceRegistrations.forEach(SchemaSourceRegistration::close);
+        sourceRegistrations.forEach(Registration::close);
         sourceRegistrations.clear();
         resetMessageTransformer();
     }
@@ -366,13 +322,14 @@ public class NetconfDevice
         notificationHandler.handleNotification(notification);
     }
 
-    private static BaseSchema resolveBaseSchema(final boolean notificationSupport) {
-        return notificationSupport ? BaseSchema.BASE_NETCONF_CTX_WITH_NOTIFICATIONS : BaseSchema.BASE_NETCONF_CTX;
+    private BaseSchema resolveBaseSchema(final boolean notificationSupport) {
+        return notificationSupport ? baseSchemas.getBaseSchemaWithNotifications() : baseSchemas.getBaseSchema();
     }
 
     protected NetconfDeviceRpc getDeviceSpecificRpc(final MountPointContext result,
-            final RemoteDeviceCommunicator<NetconfMessage> listener) {
-        return new NetconfDeviceRpc(result.getSchemaContext(), listener, new NetconfMessageTransformer(result, true));
+            final RemoteDeviceCommunicator listener, final BaseSchema schema) {
+        return new NetconfDeviceRpc(result.getEffectiveModelContext(), listener,
+            new NetconfMessageTransformer(result, true, schema));
     }
 
     /**
@@ -391,7 +348,7 @@ public class NetconfDevice
             this.schemaRegistry = requireNonNull(schemaRegistry);
             this.schemaRepository = requireNonNull(schemaRepository);
             this.schemaContextFactory = requireNonNull(schemaContextFactory);
-            this.stateSchemasResolver = requireNonNull(deviceSchemasResolver);
+            stateSchemasResolver = requireNonNull(deviceSchemasResolver);
         }
 
         public SchemaSourceRegistry getSchemaRegistry() {
@@ -412,14 +369,12 @@ public class NetconfDevice
     }
 
     /**
-     * A dedicated exception to indicate when we fail to setup a SchemaContext.
-     *
-     * @author Robert Varga
+     * A dedicated exception to indicate when we fail to setup an {@link EffectiveModelContext}.
      */
-    private static final class EmptySchemaContextException extends Exception {
+    public static final class EmptySchemaContextException extends Exception {
         private static final long serialVersionUID = 1L;
 
-        EmptySchemaContextException(final String message) {
+        public EmptySchemaContextException(final String message) {
             super(message);
         }
     }
@@ -439,7 +394,20 @@ public class NetconfDevice
         SchemaSetup(final DeviceSources deviceSources, final NetconfSessionPreferences remoteSessionCapabilities) {
             this.deviceSources = deviceSources;
             this.remoteSessionCapabilities = remoteSessionCapabilities;
-            this.capabilities = remoteSessionCapabilities.getNetconfDeviceCapabilities();
+            capabilities = remoteSessionCapabilities.getNetconfDeviceCapabilities();
+
+            // If device supports notifications and does not contain necessary modules, add them automatically
+            if (remoteSessionCapabilities.containsNonModuleCapability(
+                    XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_CAPABILITY_NOTIFICATION_1_0)) {
+                deviceSources.getRequiredSourcesQName().addAll(
+                        Arrays.asList(
+                                org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714
+                                        .$YangModuleInfoImpl.getInstance().getName(),
+                                org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715
+                                        .$YangModuleInfoImpl.getInstance().getName()
+                        )
+                );
+            }
 
             requiredSources = deviceSources.getRequiredSources();
             final Collection<SourceIdentifier> missingSources = filterMissingSources(requiredSources);
@@ -505,7 +473,7 @@ public class NetconfDevice
             }
         }
 
-        private Collection<SourceIdentifier> filterMissingSources(final Collection<SourceIdentifier> origSources) {
+        private List<SourceIdentifier> filterMissingSources(final Collection<SourceIdentifier> origSources) {
             return origSources.parallelStream().filter(sourceIdentifier -> {
                 try {
                     schemaRepository.getSchemaSource(sourceIdentifier, YangTextSchemaSource.class).get();
@@ -516,7 +484,7 @@ public class NetconfDevice
             }).collect(Collectors.toList());
         }
 
-        private Collection<SourceIdentifier> handleMissingSchemaSourceException(
+        private List<SourceIdentifier> handleMissingSchemaSourceException(
                 final MissingSchemaSourceException exception) {
             // In case source missing, try without it
             final SourceIdentifier missingSource = exception.getSourceId();
@@ -561,11 +529,11 @@ public class NetconfDevice
             return resolutionException.getResolvedSources();
         }
 
-        private Collection<SourceIdentifier> stripUnavailableSource(final SourceIdentifier sourceIdToRemove) {
-            final LinkedList<SourceIdentifier> sourceIdentifiers = new LinkedList<>(requiredSources);
-            checkState(sourceIdentifiers.remove(sourceIdToRemove),
-                    "%s: Trying to remove %s from %s failed", id, sourceIdToRemove, requiredSources);
-            return sourceIdentifiers;
+        private List<SourceIdentifier> stripUnavailableSource(final SourceIdentifier sourceIdToRemove) {
+            final var tmp = new ArrayList<>(requiredSources);
+            checkState(tmp.remove(sourceIdToRemove), "%s: Trying to remove %s from %s failed", id, sourceIdToRemove,
+                requiredSources);
+            return tmp;
         }
 
         private Collection<QName> getQNameFromSourceIdentifiers(final Collection<SourceIdentifier> identifiers) {
@@ -581,11 +549,11 @@ public class NetconfDevice
         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())) {
+                if (!qname.getLocalName().equals(identifier.name().getLocalName())) {
                     continue;
                 }
 
-                if (identifier.getRevision().equals(qname.getRevision())) {
+                if (Objects.equals(identifier.revision(), qname.getRevision().orElse(null))) {
                     return qname;
                 }
             }