2 * Copyright (c) 2014 Cisco Systems, Inc. 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.controller.sal.connect.netconf.sal;
10 import com.google.common.collect.Lists;
11 import java.util.Collections;
12 import java.util.List;
13 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
14 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
15 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
16 import org.opendaylight.controller.sal.connect.api.RemoteDeviceHandler;
17 import org.opendaylight.controller.sal.connect.netconf.listener.NetconfDeviceCapabilities;
18 import org.opendaylight.controller.sal.connect.netconf.listener.NetconfSessionPreferences;
19 import org.opendaylight.controller.sal.connect.util.RemoteDeviceId;
20 import org.opendaylight.controller.sal.core.api.Broker;
21 import org.opendaylight.yangtools.yang.common.QName;
22 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
23 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
24 import org.osgi.framework.BundleContext;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 public final class NetconfDeviceSalFacade implements AutoCloseable, RemoteDeviceHandler<NetconfSessionPreferences> {
30 private static final Logger logger= LoggerFactory.getLogger(NetconfDeviceSalFacade.class);
32 private final RemoteDeviceId id;
33 private final NetconfDeviceSalProvider salProvider;
35 private final List<AutoCloseable> salRegistrations = Lists.newArrayList();
37 public NetconfDeviceSalFacade(final RemoteDeviceId id, final Broker domBroker, final BindingAwareBroker bindingBroker, final BundleContext bundleContext) {
39 this.salProvider = new NetconfDeviceSalProvider(id);
40 registerToSal(domBroker, bindingBroker, bundleContext);
43 public void registerToSal(final Broker domRegistryDependency, final BindingAwareBroker bindingBroker, final BundleContext bundleContext) {
44 domRegistryDependency.registerProvider(salProvider, bundleContext);
45 bindingBroker.registerProvider(salProvider, bundleContext);
49 public synchronized void onNotification(final ContainerNode domNotification) {
50 salProvider.getMountInstance().publish(domNotification);
54 public synchronized void onDeviceConnected(final SchemaContext schemaContext,
55 final NetconfSessionPreferences netconfSessionPreferences, final DOMRpcService deviceRpc) {
57 final DOMDataBroker domBroker = new NetconfDeviceDataBroker(id, schemaContext, deviceRpc, netconfSessionPreferences);
59 final NetconfDeviceNotificationService notificationService = new NetconfDeviceNotificationService();
61 salProvider.getMountInstance().onDeviceConnected(schemaContext, domBroker, deviceRpc, notificationService);
62 salProvider.getDatastoreAdapter().updateDeviceState(true, netconfSessionPreferences.getModuleBasedCaps());
63 salProvider.getMountInstance().onTopologyDeviceConnected(schemaContext, domBroker, deviceRpc, notificationService);
64 salProvider.getTopologyDatastoreAdapter().updateDeviceData(true, netconfSessionPreferences.getNetconfDeviceCapabilities());
68 public synchronized void onDeviceDisconnected() {
69 salProvider.getDatastoreAdapter().updateDeviceState(false, Collections.<QName>emptySet());
70 salProvider.getTopologyDatastoreAdapter().updateDeviceData(false, new NetconfDeviceCapabilities());
71 salProvider.getMountInstance().onDeviceDisconnected();
72 salProvider.getMountInstance().onTopologyDeviceDisconnected();
76 public void onDeviceFailed(final Throwable throwable) {
77 salProvider.getTopologyDatastoreAdapter().setDeviceAsFailed(throwable);
78 salProvider.getMountInstance().onDeviceDisconnected();
79 salProvider.getMountInstance().onTopologyDeviceDisconnected();
84 for (final AutoCloseable reg : Lists.reverse(salRegistrations)) {
87 closeGracefully(salProvider);
90 private void closeGracefully(final AutoCloseable resource) {
91 if (resource != null) {
94 } catch (final Exception e) {
95 logger.warn("{}: Ignoring exception while closing {}", id, resource, e);