package org.opendaylight.netconf.sal.connect.netconf.sal;
import com.google.common.annotations.VisibleForTesting;
-import com.google.common.collect.Lists;
-import java.util.ArrayList;
-import java.util.List;
import org.opendaylight.mdsal.binding.api.DataBroker;
import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.mdsal.dom.api.DOMActionService;
import org.opendaylight.mdsal.dom.api.DOMMountPointService;
import org.opendaylight.mdsal.dom.api.DOMNotification;
-import org.opendaylight.mdsal.dom.api.DOMRpcService;
+import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
import org.opendaylight.netconf.sal.connect.api.RemoteDeviceHandler;
+import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices;
+import org.opendaylight.netconf.sal.connect.netconf.NetconfDeviceSchema;
import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities;
import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.optional.rev190614.netconf.node.fields.optional.topology.Node;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.optional.rev190614.netconf.node.fields.optional.topology.NodeKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.optional.rev190614.netconf.node.fields.optional.topology.node.DatastoreLock;
-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.NetconfNodeConnectionStatus.ConnectionStatus;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.rfc8528.data.api.MountPointContext;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public final class NetconfDeviceSalFacade implements AutoCloseable, RemoteDeviceHandler<NetconfSessionPreferences> {
-
+public final class NetconfDeviceSalFacade implements RemoteDeviceHandler, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(NetconfDeviceSalFacade.class);
private final RemoteDeviceId id;
private final NetconfDeviceSalProvider salProvider;
- private final List<AutoCloseable> salRegistrations = new ArrayList<>();
private final DataBroker dataBroker;
private final String topologyId;
}
@Override
- public synchronized void onDeviceConnected(final MountPointContext mountContext,
- final NetconfSessionPreferences netconfSessionPreferences,
- final DOMRpcService deviceRpc, final DOMActionService deviceAction) {
- final SchemaContext schemaContext = mountContext.getSchemaContext();
- final NetconfDeviceDataBroker netconfDeviceDataBroker =
- new NetconfDeviceDataBroker(id, schemaContext, deviceRpc, netconfSessionPreferences);
- registerLockListener(netconfDeviceDataBroker);
- final NetconfDeviceNotificationService notificationService = new NetconfDeviceNotificationService();
-
- salProvider.getMountInstance()
- .onTopologyDeviceConnected(schemaContext, netconfDeviceDataBroker, deviceRpc, notificationService,
- deviceAction);
- salProvider.getTopologyDatastoreAdapter()
- .updateDeviceData(true, netconfSessionPreferences.getNetconfDeviceCapabilities());
- }
-
- @Override
- public synchronized void onDeviceReconnected(final NetconfSessionPreferences netconfSessionPreferences,
- final NetconfNode node) {
- this.salProvider.getTopologyDatastoreAdapter().updateDeviceData(ConnectionStatus.Connecting,
- netconfSessionPreferences.getNetconfDeviceCapabilities(), LogicalDatastoreType.CONFIGURATION, node);
+ public synchronized void onDeviceConnected(final NetconfDeviceSchema deviceSchema,
+ final NetconfSessionPreferences sessionPreferences, final RemoteDeviceServices services) {
+ final var mountContext = deviceSchema.mountContext();
+ final var modelContext = mountContext.getEffectiveModelContext();
+
+ final var deviceRpc = services.rpcs();
+ final var netconfDataTree = AbstractNetconfDataTreeService.of(id, mountContext, deviceRpc, sessionPreferences);
+ final var netconfDataBroker = new NetconfDeviceDataBroker(id, mountContext, deviceRpc, sessionPreferences);
+ registerLockListener(netconfDataBroker, netconfDataTree);
+
+ salProvider.getMountInstance().onTopologyDeviceConnected(modelContext, services, netconfDataBroker,
+ netconfDataTree);
+ salProvider.getTopologyDatastoreAdapter().updateDeviceData(true, deviceSchema.capabilities());
}
@Override
public synchronized void onDeviceDisconnected() {
- salProvider.getTopologyDatastoreAdapter().updateDeviceData(false, new NetconfDeviceCapabilities());
+ salProvider.getTopologyDatastoreAdapter().updateDeviceData(false, NetconfDeviceCapabilities.empty());
salProvider.getMountInstance().onTopologyDeviceDisconnected();
closeLockChangeListener();
}
@Override
public synchronized void close() {
- for (final AutoCloseable reg : Lists.reverse(salRegistrations)) {
- closeGracefully(reg);
- }
closeGracefully(salProvider);
closeLockChangeListener();
}
}
}
- private void registerLockListener(final NetconfDeviceDataBroker netconfDeviceDataBroker) {
+ private void registerLockListener(final NetconfDeviceDataBroker netconfDeviceDataBroker,
+ final NetconfDataTreeService netconfDataTreeService) {
listenerRegistration = dataBroker.registerDataTreeChangeListener(
- DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION, createTopologyListPath()),
- new LockChangeListener(netconfDeviceDataBroker));
- }
-
- private InstanceIdentifier<DatastoreLock> createTopologyListPath() {
- return InstanceIdentifier.create(NetconfNodeFieldsOptional.class)
+ DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION,
+ InstanceIdentifier.create(NetconfNodeFieldsOptional.class)
.child(Topology.class, new TopologyKey(new TopologyId(topologyId)))
.child(Node.class, new NodeKey(new NodeId(id.getName())))
- .child(DatastoreLock.class);
-
+ .child(DatastoreLock.class)),
+ new LockChangeListener(netconfDeviceDataBroker, netconfDataTreeService));
}
}