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%2FNetconfDeviceSalProvider.java;h=568ebde0d393aca1b1d66c660d2b8f801f1dad8b;hp=cf9174dd50d707ef36c5e80deefce3ea8f8be20c;hb=009fc930faca431bc6802885c28ccdfe3b1ab86f;hpb=c46e223995956f1f759c551163c212947c1e2fb7 diff --git a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/sal/NetconfDeviceSalProvider.java b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/sal/NetconfDeviceSalProvider.java index cf9174dd50..568ebde0d3 100644 --- a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/sal/NetconfDeviceSalProvider.java +++ b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/sal/NetconfDeviceSalProvider.java @@ -23,7 +23,6 @@ import org.opendaylight.controller.sal.core.api.Provider; import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry; import org.opendaylight.controller.sal.core.api.notify.NotificationPublishService; import org.opendaylight.yangtools.concepts.ObjectRegistration; -import org.opendaylight.yangtools.yang.binding.RpcService; import org.opendaylight.yangtools.yang.data.api.CompositeNode; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.slf4j.Logger; @@ -38,6 +37,8 @@ final class NetconfDeviceSalProvider implements AutoCloseable, Provider, Binding private volatile NetconfDeviceDatastoreAdapter datastoreAdapter; private MountInstance mountInstance; + private volatile NetconfDeviceTopologyAdapter topologyDatastoreAdapter; + public NetconfDeviceSalProvider(final RemoteDeviceId deviceId, final ExecutorService executor) { this.id = deviceId; this.executor = executor; @@ -55,6 +56,12 @@ final class NetconfDeviceSalProvider implements AutoCloseable, Provider, Binding return datastoreAdapter; } + public NetconfDeviceTopologyAdapter getTopologyDatastoreAdapter() { + Preconditions.checkState(topologyDatastoreAdapter != null, + "%s: Sal provider %s was not initialized by sal. Cannot get topology datastore adapter", id); + return topologyDatastoreAdapter; + } + @Override public void onSessionInitiated(final Broker.ProviderSession session) { logger.debug("{}: (BI)Session with sal established {}", id, session); @@ -70,31 +77,22 @@ final class NetconfDeviceSalProvider implements AutoCloseable, Provider, Binding return Collections.emptySet(); } - @Override - public Collection getImplementations() { - return Collections.emptySet(); - } - - @Override - public Collection getFunctionality() { - return Collections.emptySet(); - } - @Override public void onSessionInitiated(final BindingAwareBroker.ProviderContext session) { logger.debug("{}: Session with sal established {}", id, session); final DataBroker dataBroker = session.getSALService(DataBroker.class); datastoreAdapter = new NetconfDeviceDatastoreAdapter(id, dataBroker); - } - @Override - public void onSessionInitialized(final BindingAwareBroker.ConsumerContext session) {} + topologyDatastoreAdapter = new NetconfDeviceTopologyAdapter(id, dataBroker); + } public void close() throws Exception { mountInstance.close(); datastoreAdapter.close(); datastoreAdapter = null; + topologyDatastoreAdapter.close(); + topologyDatastoreAdapter = null; } static final class MountInstance implements AutoCloseable { @@ -104,11 +102,14 @@ final class NetconfDeviceSalProvider implements AutoCloseable, Provider, Binding private ObjectRegistration registration; private NotificationPublishService notificationSerivce; + private ObjectRegistration topologyRegistration; + MountInstance(final DOMMountPointService mountService, final RemoteDeviceId id) { this.mountService = Preconditions.checkNotNull(mountService); this.id = Preconditions.checkNotNull(id); } + @Deprecated synchronized void onDeviceConnected(final SchemaContext initialCtx, final DOMDataBroker broker, final RpcProvisionRegistry rpc, final NotificationPublishService notificationSerivce) { @@ -127,6 +128,7 @@ final class NetconfDeviceSalProvider implements AutoCloseable, Provider, Binding registration = mountBuilder.register(); } + @Deprecated synchronized void onDeviceDisconnected() { if(registration == null) { return; @@ -142,10 +144,44 @@ final class NetconfDeviceSalProvider implements AutoCloseable, Provider, Binding } } + synchronized void onTopologyDeviceConnected(final SchemaContext initialCtx, + final DOMDataBroker broker, final RpcProvisionRegistry rpc, + final NotificationPublishService notificationSerivce) { + + Preconditions.checkNotNull(mountService, "Closed"); + Preconditions.checkState(topologyRegistration == null, "Already initialized"); + + final DOMMountPointService.DOMMountPointBuilder mountBuilder = mountService.createMountPoint(id.getTopologyPath()); + mountBuilder.addInitialSchemaContext(initialCtx); + + mountBuilder.addService(DOMDataBroker.class, broker); + mountBuilder.addService(RpcProvisionRegistry.class, rpc); + this.notificationSerivce = notificationSerivce; + mountBuilder.addService(NotificationPublishService.class, notificationSerivce); + + topologyRegistration = mountBuilder.register(); + } + + synchronized void onTopologyDeviceDisconnected() { + if(topologyRegistration == null) { + return; + } + + try { + topologyRegistration.close(); + } catch (final Exception e) { + // Only log and ignore + logger.warn("Unable to unregister mount instance for {}. Ignoring exception", id.getTopologyPath(), e); + } finally { + topologyRegistration = null; + } + } + @Override synchronized public void close() throws Exception { if(registration != null) { onDeviceDisconnected(); + onTopologyDeviceDisconnected(); } mountService = null; }