2 * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netconf.topology.spi;
10 import java.util.concurrent.ExecutionException;
11 import org.opendaylight.mdsal.binding.api.DataBroker;
12 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
13 import org.opendaylight.netconf.client.mdsal.NetconfDeviceCapabilities;
14 import org.opendaylight.netconf.client.mdsal.NetconfDeviceSchema;
15 import org.opendaylight.netconf.client.mdsal.api.NetconfSessionPreferences;
16 import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceId;
17 import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceServices;
18 import org.opendaylight.netconf.client.mdsal.spi.NetconfDeviceSalFacade;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev240611.credentials.Credentials;
22 * {@link NetconfDeviceSalFacade} specialization for netconf topology.
24 public class NetconfTopologyDeviceSalFacade extends NetconfDeviceSalFacade {
25 private final NetconfDeviceTopologyAdapter datastoreAdapter;
28 * NetconfTopologyDeviceSalFacade is a specialization of NetconfDeviceSalFacade
29 * for the netconf topology. It handles the lifecycle and data updates for
30 * NETCONF devices within the topology.
32 * @param id the unique identifier for the remote device
33 * @param credentials the credentials used to authenticate the remote device
34 * @param mountPointService the mount point service for managing mount points
35 * @param lockDatastore a flag indicating whether the datastore should be locked
36 * @param dataBroker the data broker for accessing and modifying data in the data store
38 public NetconfTopologyDeviceSalFacade(final RemoteDeviceId id, final Credentials credentials,
39 final DOMMountPointService mountPointService, final boolean lockDatastore, final DataBroker dataBroker) {
40 super(id, mountPointService, NetconfNodeUtils.defaultTopologyMountPath(id), lockDatastore);
41 datastoreAdapter = new NetconfDeviceTopologyAdapter(dataBroker, NetconfNodeUtils.DEFAULT_TOPOLOGY_IID, id,
46 public synchronized void onDeviceConnected(final NetconfDeviceSchema deviceSchema,
47 final NetconfSessionPreferences sessionPreferences, final RemoteDeviceServices services) {
48 super.onDeviceConnected(deviceSchema, sessionPreferences, services);
49 datastoreAdapter.updateDeviceData(true, deviceSchema.capabilities(), sessionPreferences.sessionId());
53 public synchronized void onDeviceDisconnected() {
54 datastoreAdapter.updateDeviceData(false, NetconfDeviceCapabilities.empty(), null);
55 super.onDeviceDisconnected();
59 public synchronized void onDeviceFailed(final Throwable throwable) {
60 datastoreAdapter.setDeviceAsFailed(throwable);
61 super.onDeviceFailed(throwable);
65 public synchronized void close() {
66 final var future = datastoreAdapter.shutdown();
71 } catch (InterruptedException e) {
72 Thread.currentThread().interrupt();
73 throw new IllegalStateException("Interrupted while waiting for datastore adapter shutdown", e);
74 } catch (ExecutionException e) {
75 throw new IllegalStateException("Datastore adapter shutdown failed", e);