X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fnetconf-topology%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Ftopology%2Fimpl%2FNetconfTopologyImpl.java;h=86ce1f9c02865e4aa3ecb26ca57ea9dba257735f;hb=a0833fb27c69d919a4420c6ecbd11a3b2a1119cb;hp=c1e41189e3353a05dac9aa010cd1ec855ef2f6c8;hpb=fa3dfda499ef819dd61b9d03b4898318dfa6a91b;p=netconf.git diff --git a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/NetconfTopologyImpl.java b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/NetconfTopologyImpl.java index c1e41189e3..86ce1f9c02 100644 --- a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/NetconfTopologyImpl.java +++ b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/NetconfTopologyImpl.java @@ -5,40 +5,35 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.netconf.topology.impl; -import akka.actor.ActorContext; -import akka.actor.ActorRef; import com.google.common.util.concurrent.FutureCallback; -import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.MoreExecutors; import io.netty.util.concurrent.EventExecutor; import java.util.Collection; import javax.annotation.Nonnull; +import org.opendaylight.aaa.encrypt.AAAEncryptionService; import org.opendaylight.controller.config.threadpool.ScheduledThreadPool; import org.opendaylight.controller.config.threadpool.ThreadPool; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.DataObjectModification; -import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener; -import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier; -import org.opendaylight.controller.md.sal.binding.api.DataTreeModification; -import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext; -import org.opendaylight.controller.sal.core.api.Broker; +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.api.DataObjectModification; +import org.opendaylight.mdsal.binding.api.DataTreeChangeListener; +import org.opendaylight.mdsal.binding.api.DataTreeIdentifier; +import org.opendaylight.mdsal.binding.api.DataTreeModification; +import org.opendaylight.mdsal.binding.api.WriteTransaction; +import org.opendaylight.mdsal.common.api.CommitInfo; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.mdsal.dom.api.DOMMountPointService; import org.opendaylight.netconf.client.NetconfClientDispatcher; +import org.opendaylight.netconf.sal.connect.api.DeviceActionFactory; import org.opendaylight.netconf.sal.connect.api.RemoteDeviceHandler; import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences; import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceSalFacade; import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId; import org.opendaylight.netconf.topology.AbstractNetconfTopology; -import org.opendaylight.netconf.topology.SchemaRepositoryProvider; -import org.opendaylight.netconf.topology.pipeline.TopologyMountPointFacade.ConnectionStatusListenerRegistration; -import org.opendaylight.netconf.topology.util.TopologyUtil; +import org.opendaylight.netconf.topology.api.SchemaRepositoryProvider; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopologyBuilder; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyBuilder; @@ -49,27 +44,39 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class NetconfTopologyImpl extends AbstractNetconfTopology implements DataTreeChangeListener, AutoCloseable { +public class NetconfTopologyImpl extends AbstractNetconfTopology + implements DataTreeChangeListener, AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(NetconfTopologyImpl.class); - private ListenerRegistration datastoreListenerRegistration = null; + private ListenerRegistration datastoreListenerRegistration = null; public NetconfTopologyImpl(final String topologyId, final NetconfClientDispatcher clientDispatcher, - final BindingAwareBroker bindingAwareBroker, final Broker domBroker, - final EventExecutor eventExecutor, final ScheduledThreadPool keepaliveExecutor, - final ThreadPool processingExecutor, final SchemaRepositoryProvider schemaRepositoryProvider) { - super(topologyId, clientDispatcher, - bindingAwareBroker, domBroker, eventExecutor, - keepaliveExecutor, processingExecutor, schemaRepositoryProvider); - registerToSal(this, this); + final EventExecutor eventExecutor, final ScheduledThreadPool keepaliveExecutor, + final ThreadPool processingExecutor, + final SchemaRepositoryProvider schemaRepositoryProvider, + final DataBroker dataBroker, final DOMMountPointService mountPointService, + final AAAEncryptionService encryptionService) { + this(topologyId, clientDispatcher, eventExecutor, keepaliveExecutor, processingExecutor, + schemaRepositoryProvider, dataBroker, mountPointService, encryptionService, null); + } + + public NetconfTopologyImpl(final String topologyId, final NetconfClientDispatcher clientDispatcher, + final EventExecutor eventExecutor, final ScheduledThreadPool keepaliveExecutor, + final ThreadPool processingExecutor, + final SchemaRepositoryProvider schemaRepositoryProvider, + final DataBroker dataBroker, final DOMMountPointService mountPointService, + final AAAEncryptionService encryptionService, + final DeviceActionFactory deviceActionFactory) { + super(topologyId, clientDispatcher, eventExecutor, keepaliveExecutor, processingExecutor, + schemaRepositoryProvider, dataBroker, mountPointService, encryptionService, deviceActionFactory); } @Override - public void close() throws Exception { + public void close() { // close all existing connectors, delete whole topology in datastore? - for (NetconfConnectorDTO connectorDTO : activeConnectors.values()) { - connectorDTO.getCommunicator().close(); + for (final NetconfConnectorDTO connectorDTO : activeConnectors.values()) { + connectorDTO.close(); } activeConnectors.clear(); @@ -80,61 +87,38 @@ public class NetconfTopologyImpl extends AbstractNetconfTopology implements Data } @Override - protected RemoteDeviceHandler createSalFacade(RemoteDeviceId id, Broker domBroker, BindingAwareBroker bindingBroker) { - return new NetconfDeviceSalFacade(id, domBroker, bindingAwareBroker); - } - - @Override - public void registerMountPoint(ActorContext context, NodeId nodeId) { - throw new UnsupportedOperationException("MountPoint registration is not supported in regular topology, this happens automaticaly in the netconf pipeline"); - } - - @Override - public void registerMountPoint(ActorContext context, NodeId nodeId, ActorRef masterRef) { - throw new UnsupportedOperationException("MountPoint registration is not supported in regular topology, this happens automaticaly in the netconf pipeline"); + protected RemoteDeviceHandler createSalFacade(final RemoteDeviceId id) { + return new NetconfDeviceSalFacade(id, mountPointService, dataBroker, topologyId); } - @Override - public void unregisterMountPoint(NodeId nodeId) { - throw new UnsupportedOperationException("MountPoint registration is not supported in regular topology, this happens automaticaly in the netconf pipeline"); - } - - @Override - public ConnectionStatusListenerRegistration registerConnectionStatusListener(NodeId node, RemoteDeviceHandler listener) { - throw new UnsupportedOperationException("Registering a listener on a regular netconf device is not supported(supported only in clustered netconf topology)"); - } - - @Override - public void onSessionInitiated(ProviderContext session) { - dataBroker = session.getSALService(DataBroker.class); - + /** + * Invoked by blueprint. + */ + public void init() { final WriteTransaction wtx = dataBroker.newWriteOnlyTransaction(); initTopology(wtx, LogicalDatastoreType.CONFIGURATION); initTopology(wtx, LogicalDatastoreType.OPERATIONAL); - Futures.addCallback(wtx.submit(), new FutureCallback() { + wtx.commit().addCallback(new FutureCallback() { @Override - public void onSuccess(Void result) { + public void onSuccess(final CommitInfo result) { LOG.debug("topology initialization successful"); } @Override - public void onFailure(Throwable t) { - LOG.error("Unable to initialize netconf-topology, {}", t); + public void onFailure(final Throwable throwable) { + LOG.error("Unable to initialize netconf-topology", throwable); } - }); + }, MoreExecutors.directExecutor()); LOG.debug("Registering datastore listener"); - datastoreListenerRegistration = - dataBroker.registerDataTreeChangeListener( - new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, - TopologyUtil.createTopologyListPath(topologyId).child(Node.class)), this); - - + datastoreListenerRegistration = dataBroker.registerDataTreeChangeListener(DataTreeIdentifier.create( + LogicalDatastoreType.CONFIGURATION, TopologyUtil.createTopologyListPath(topologyId).child(Node.class)), + this); } @Override - public void onDataTreeChanged(@Nonnull Collection> collection) { - for (DataTreeModification change : collection) { + public void onDataTreeChanged(@Nonnull final Collection> collection) { + for (final DataTreeModification change : collection) { final DataObjectModification rootNode = change.getRootNode(); switch (rootNode.getModificationType()) { case SUBTREE_MODIFIED: @@ -145,7 +129,8 @@ public class NetconfTopologyImpl extends AbstractNetconfTopology implements Data case WRITE: LOG.debug("Config for node {} created", TopologyUtil.getNodeId(rootNode.getIdentifier())); if (activeConnectors.containsKey(TopologyUtil.getNodeId(rootNode.getIdentifier()))) { - LOG.warn("RemoteDevice{{}} was already configured, reconfiguring..", TopologyUtil.getNodeId(rootNode.getIdentifier())); + LOG.warn("RemoteDevice{{}} was already configured, reconfiguring..", + TopologyUtil.getNodeId(rootNode.getIdentifier())); disconnectNode(TopologyUtil.getNodeId(rootNode.getIdentifier())); } connectNode(TopologyUtil.getNodeId(rootNode.getIdentifier()), rootNode.getDataAfter()); @@ -154,16 +139,20 @@ public class NetconfTopologyImpl extends AbstractNetconfTopology implements Data LOG.debug("Config for node {} deleted", TopologyUtil.getNodeId(rootNode.getIdentifier())); disconnectNode(TopologyUtil.getNodeId(rootNode.getIdentifier())); break; + default: + LOG.debug("Unsupported modification type: {}.", rootNode.getModificationType()); } } } private void initTopology(final WriteTransaction wtx, final LogicalDatastoreType datastoreType) { final NetworkTopology networkTopology = new NetworkTopologyBuilder().build(); - final InstanceIdentifier networkTopologyId = InstanceIdentifier.builder(NetworkTopology.class).build(); + final InstanceIdentifier networkTopologyId = + InstanceIdentifier.builder(NetworkTopology.class).build(); wtx.merge(datastoreType, networkTopologyId, networkTopology); final Topology topology = new TopologyBuilder().setTopologyId(new TopologyId(topologyId)).build(); - wtx.merge(datastoreType, networkTopologyId.child(Topology.class, new TopologyKey(new TopologyId(topologyId))), topology); + wtx.merge(datastoreType, + networkTopologyId.child(Topology.class, new TopologyKey(new TopologyId(topologyId))), topology); } }