X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fconnect%2Fnetconf%2Fsal%2FNetconfDeviceSalFacade.java;h=dbef290197b91ea2e7eb55e19fbb9363cadace16;hp=37b87045d5f0f9061f9c276183fb6fc156879060;hb=a6a97a57081df63432dde5a6b1613eb779b74d79;hpb=412323d01e3caa3e0d0801760f957f865629b9da 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 37b87045d5..dbef290197 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,32 +7,40 @@ */ package org.opendaylight.controller.sal.connect.netconf.sal; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; 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.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.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.mount.MountProvisionInstance; +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.data.api.InstanceIdentifier; 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 { private static final Logger logger= LoggerFactory.getLogger(NetconfDeviceSalFacade.class); - private static final InstanceIdentifier ROOT_PATH = InstanceIdentifier.builder().toInstance(); private final RemoteDeviceId id; private final NetconfDeviceSalProvider salProvider; @@ -58,24 +66,50 @@ public final class NetconfDeviceSalFacade implements AutoCloseable, RemoteDevice @Override public synchronized void onDeviceConnected(final SchemaContextProvider remoteSchemaContextProvider, final NetconfSessionCapabilities netconfSessionPreferences, final RpcImplementation deviceRpc) { - salProvider.getMountInstance().setSchemaContext(remoteSchemaContextProvider.getSchemaContext()); + 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); + + // TODO NotificationPublishService and NotificationRouter have the same interface + final NotificationPublishService notificationService = new NotificationPublishService() { + + private final NotificationRouter innerRouter = new NotificationRouterImpl(); + + @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.getDatastoreAdapter().updateDeviceState(true, netconfSessionPreferences.getModuleBasedCaps()); - registerDataHandlersToSal(deviceRpc, netconfSessionPreferences); - registerRpcsToSal(deviceRpc); } @Override public void onDeviceDisconnected() { salProvider.getDatastoreAdapter().updateDeviceState(false, Collections.emptySet()); + salProvider.getMountInstance().onDeviceDisconnected(); } - private void registerRpcsToSal(final RpcImplementation deviceRpc) { - final MountProvisionInstance mountInstance = salProvider.getMountInstance(); - + private void registerRpcsToSal(final SchemaContext schemaContext, final RpcProvisionRegistry rpcRegistry, final RpcImplementation deviceRpc) { final Map failedRpcs = Maps.newHashMap(); - for (final RpcDefinition rpcDef : mountInstance.getSchemaContext().getOperations()) { + for (final RpcDefinition rpcDef : schemaContext.getOperations()) { try { - salRegistrations.add(mountInstance.addRpcImplementation(rpcDef.getQName(), deviceRpc)); + 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) @@ -94,18 +128,6 @@ public final class NetconfDeviceSalFacade implements AutoCloseable, RemoteDevice } } - private void registerDataHandlersToSal(final RpcImplementation deviceRpc, - final NetconfSessionCapabilities netconfSessionPreferences) { - final NetconfDeviceDataReader dataReader = new NetconfDeviceDataReader(id, deviceRpc); - final NetconfDeviceCommitHandler commitHandler = new NetconfDeviceCommitHandler(id, deviceRpc, - netconfSessionPreferences.isRollbackSupported()); - - final MountProvisionInstance mountInstance = salProvider.getMountInstance(); - salRegistrations.add(mountInstance.registerConfigurationReader(ROOT_PATH, dataReader)); - salRegistrations.add(mountInstance.registerOperationalReader(ROOT_PATH, dataReader)); - salRegistrations.add(mountInstance.registerCommitHandler(ROOT_PATH, commitHandler)); - } - @Override public void close() { for (final AutoCloseable reg : Lists.reverse(salRegistrations)) {