5ab27d161093bf1d49ce96130358ced34413a5e9
[netconf.git] / netconf / netconf-topology / src / main / java / org / opendaylight / netconf / topology / spi / NetconfTopologyDeviceSalFacade.java
1 /*
2  * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netconf.topology.spi;
9
10 import org.opendaylight.mdsal.binding.api.DataBroker;
11 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
12 import org.opendaylight.netconf.sal.connect.api.RemoteDeviceId;
13 import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices;
14 import org.opendaylight.netconf.sal.connect.netconf.NetconfDeviceSchema;
15 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities;
16 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
17 import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceMount;
18 import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceSalFacade;
19
20 /**
21  * {@link NetconfDeviceSalFacade} specialization for netconf topology.
22  */
23 public class NetconfTopologyDeviceSalFacade extends NetconfDeviceSalFacade {
24     private final NetconfDeviceTopologyAdapter datastoreAdapter;
25
26     public NetconfTopologyDeviceSalFacade(final RemoteDeviceId id, final DOMMountPointService mountPointService,
27             final boolean lockDatastore, final DataBroker dataBroker) {
28         super(id, mountPointService, NetconfDeviceMount.defaultTopologyMountPath(id), lockDatastore);
29         datastoreAdapter = new NetconfDeviceTopologyAdapter(dataBroker, AbstractNetconfTopology.DEFAULT_TOPOLOGY_IID,
30             id);
31     }
32
33     @Override
34     public synchronized void onDeviceConnected(final NetconfDeviceSchema deviceSchema,
35             final NetconfSessionPreferences sessionPreferences, final RemoteDeviceServices services) {
36         super.onDeviceConnected(deviceSchema, sessionPreferences, services);
37         datastoreAdapter.updateDeviceData(true, deviceSchema.capabilities());
38
39     }
40
41     @Override
42     public synchronized void onDeviceDisconnected() {
43         datastoreAdapter.updateDeviceData(false, NetconfDeviceCapabilities.empty());
44         super.onDeviceDisconnected();
45     }
46
47     @Override
48     public synchronized void onDeviceFailed(final Throwable throwable) {
49         datastoreAdapter.setDeviceAsFailed(throwable);
50         super.onDeviceFailed(throwable);
51     }
52
53     @Override
54     public void close() {
55         datastoreAdapter.close();
56         super.close();
57     }
58 }