X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fconnect%2Fnetconf%2Fsal%2FNetconfDeviceSalFacade.java;h=7ffeec3096934995dbc5dd73844ff49999d190c8;hb=e433e0aa67cc6d144cd3d8d6117de864eb7ebf97;hp=dbef290197b91ea2e7eb55e19fbb9363cadace16;hpb=580c443727609bd275d0f9a088c4f7ee3dc9a9ee;p=controller.git diff --git a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/sal/NetconfDeviceSalFacade.java b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/sal/NetconfDeviceSalFacade.java index dbef290197..7ffeec3096 100644 --- a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/sal/NetconfDeviceSalFacade.java +++ b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/sal/NetconfDeviceSalFacade.java @@ -7,38 +7,25 @@ */ package org.opendaylight.controller.sal.connect.netconf.sal; +import com.google.common.collect.Lists; import java.util.Collections; import java.util.List; -import java.util.Map; -import java.util.concurrent.ExecutorService; - import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; +import org.opendaylight.controller.md.sal.dom.api.DOMNotification; +import org.opendaylight.controller.md.sal.dom.api.DOMRpcService; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; import org.opendaylight.controller.sal.connect.api.RemoteDeviceHandler; -import org.opendaylight.controller.sal.connect.netconf.listener.NetconfSessionCapabilities; +import org.opendaylight.controller.sal.connect.netconf.listener.NetconfDeviceCapabilities; +import org.opendaylight.controller.sal.connect.netconf.listener.NetconfSessionPreferences; import org.opendaylight.controller.sal.connect.util.RemoteDeviceId; import org.opendaylight.controller.sal.core.api.Broker; -import org.opendaylight.controller.sal.core.api.RpcImplementation; -import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry; -import org.opendaylight.controller.sal.core.api.notify.NotificationListener; -import org.opendaylight.controller.sal.core.api.notify.NotificationPublishService; -import org.opendaylight.controller.sal.dom.broker.impl.NotificationRouterImpl; -import org.opendaylight.controller.sal.dom.broker.impl.SchemaAwareRpcBroker; -import org.opendaylight.controller.sal.dom.broker.spi.NotificationRouter; -import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.CompositeNode; -import org.opendaylight.yangtools.yang.model.api.RpcDefinition; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider; import org.osgi.framework.BundleContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; - -public final class NetconfDeviceSalFacade implements AutoCloseable, RemoteDeviceHandler { +public final class NetconfDeviceSalFacade implements AutoCloseable, RemoteDeviceHandler { private static final Logger logger= LoggerFactory.getLogger(NetconfDeviceSalFacade.class); @@ -47,9 +34,9 @@ public final class NetconfDeviceSalFacade implements AutoCloseable, RemoteDevice private final List salRegistrations = Lists.newArrayList(); - public NetconfDeviceSalFacade(final RemoteDeviceId id, final Broker domBroker, final BindingAwareBroker bindingBroker, final BundleContext bundleContext, final ExecutorService executor) { + public NetconfDeviceSalFacade(final RemoteDeviceId id, final Broker domBroker, final BindingAwareBroker bindingBroker, final BundleContext bundleContext) { this.id = id; - this.salProvider = new NetconfDeviceSalProvider(id, executor); + this.salProvider = new NetconfDeviceSalProvider(id); registerToSal(domBroker, bindingBroker, bundleContext); } @@ -59,77 +46,41 @@ public final class NetconfDeviceSalFacade implements AutoCloseable, RemoteDevice } @Override - public synchronized void onNotification(final CompositeNode domNotification) { + public synchronized void onNotification(final DOMNotification domNotification) { salProvider.getMountInstance().publish(domNotification); } @Override - public synchronized void onDeviceConnected(final SchemaContextProvider remoteSchemaContextProvider, - final NetconfSessionCapabilities netconfSessionPreferences, final RpcImplementation deviceRpc) { - final SchemaContext schemaContext = remoteSchemaContextProvider.getSchemaContext(); - - // TODO remove deprecated SchemaContextProvider from SchemaAwareRpcBroker - // TODO move SchemaAwareRpcBroker from sal-broker-impl, now we have depend on the whole sal-broker-impl - final RpcProvisionRegistry rpcRegistry = new SchemaAwareRpcBroker(id.getPath().toString(), new org.opendaylight.controller.sal.dom.broker.impl.SchemaContextProvider() { - @Override - public SchemaContext getSchemaContext() { - return schemaContext; - } - }); - registerRpcsToSal(schemaContext, rpcRegistry, deviceRpc); - final DOMDataBroker domBroker = new NetconfDeviceDataBroker(id, deviceRpc, schemaContext, netconfSessionPreferences); + public synchronized void onDeviceConnected(final SchemaContext schemaContext, + final NetconfSessionPreferences netconfSessionPreferences, final DOMRpcService deviceRpc) { - // TODO NotificationPublishService and NotificationRouter have the same interface - final NotificationPublishService notificationService = new NotificationPublishService() { + final DOMDataBroker domBroker = new NetconfDeviceDataBroker(id, schemaContext, deviceRpc, netconfSessionPreferences); - private final NotificationRouter innerRouter = new NotificationRouterImpl(); + final NetconfDeviceNotificationService notificationService = new NetconfDeviceNotificationService(); - @Override - public void publish(final CompositeNode notification) { - innerRouter.publish(notification); - } - - @Override - public ListenerRegistration addNotificationListener(final QName notification, final NotificationListener listener) { - return innerRouter.addNotificationListener(notification, listener); - } - }; - - salProvider.getMountInstance().onDeviceConnected(schemaContext, domBroker, rpcRegistry, notificationService); + salProvider.getMountInstance().onDeviceConnected(schemaContext, domBroker, deviceRpc, notificationService); salProvider.getDatastoreAdapter().updateDeviceState(true, netconfSessionPreferences.getModuleBasedCaps()); + salProvider.getMountInstance().onTopologyDeviceConnected(schemaContext, domBroker, deviceRpc, notificationService); + salProvider.getTopologyDatastoreAdapter().updateDeviceData(true, netconfSessionPreferences.getNetconfDeviceCapabilities()); } @Override - public void onDeviceDisconnected() { + public synchronized void onDeviceDisconnected() { salProvider.getDatastoreAdapter().updateDeviceState(false, Collections.emptySet()); + salProvider.getTopologyDatastoreAdapter().updateDeviceData(false, new NetconfDeviceCapabilities()); salProvider.getMountInstance().onDeviceDisconnected(); + salProvider.getMountInstance().onTopologyDeviceDisconnected(); } - private void registerRpcsToSal(final SchemaContext schemaContext, final RpcProvisionRegistry rpcRegistry, final RpcImplementation deviceRpc) { - final Map failedRpcs = Maps.newHashMap(); - for (final RpcDefinition rpcDef : schemaContext.getOperations()) { - try { - salRegistrations.add(rpcRegistry.addRpcImplementation(rpcDef.getQName(), deviceRpc)); - logger.debug("{}: Rpc {} from netconf registered successfully", id, rpcDef.getQName()); - } catch (final Exception e) { - // Only debug per rpc, warn for all of them at the end to pollute log a little less (e.g. routed rpcs) - logger.debug("{}: Unable to register rpc {} from netconf device. This rpc will not be available", id, - rpcDef.getQName(), e); - failedRpcs.put(rpcDef.getQName(), e.getClass() + ":" + e.getMessage()); - } - } - - if (failedRpcs.isEmpty() == false) { - if (logger.isDebugEnabled()) { - logger.warn("{}: Some rpcs from netconf device were not registered: {}", id, failedRpcs); - } else { - logger.warn("{}: Some rpcs from netconf device were not registered: {}", id, failedRpcs.keySet()); - } - } + @Override + public synchronized void onDeviceFailed(final Throwable throwable) { + salProvider.getTopologyDatastoreAdapter().setDeviceAsFailed(throwable); + salProvider.getMountInstance().onDeviceDisconnected(); + salProvider.getMountInstance().onTopologyDeviceDisconnected(); } @Override - public void close() { + public synchronized void close() { for (final AutoCloseable reg : Lists.reverse(salRegistrations)) { closeGracefully(reg); } @@ -145,4 +96,5 @@ public final class NetconfDeviceSalFacade implements AutoCloseable, RemoteDevice } } } + }