X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fnetconf-topology-singleton%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Ftopology%2Fsingleton%2Fimpl%2FNetconfTopologyManager.java;h=82e340d9171649d57752af5c733b570764542f13;hb=45cfee1861924b4a8086d38079ce8cbd320386d6;hp=1a9816c3f7707a2d9f4905887b2931728862d3c6;hpb=0daed243d5fa216f5274ad9257f9692dd91c77eb;p=netconf.git diff --git a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/NetconfTopologyManager.java b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/NetconfTopologyManager.java index 1a9816c3f7..82e340d917 100644 --- a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/NetconfTopologyManager.java +++ b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/NetconfTopologyManager.java @@ -13,12 +13,14 @@ import akka.util.Timeout; import com.google.common.base.Preconditions; 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 java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; import javax.annotation.Nonnull; +import org.opendaylight.aaa.encrypt.AAAEncryptionService; import org.opendaylight.controller.cluster.ActorSystemProvider; import org.opendaylight.controller.config.threadpool.ScheduledThreadPool; import org.opendaylight.controller.config.threadpool.ThreadPool; @@ -75,8 +77,10 @@ public class NetconfTopologyManager private final String topologyId; private final Duration writeTxIdleTimeout; private final DOMMountPointService mountPointService; - + private final AAAEncryptionService encryptionService; private ListenerRegistration dataChangeListenerRegistration; + private String privateKeyPath; + private String privateKeyPassphrase; public NetconfTopologyManager(final DataBroker dataBroker, final RpcProviderRegistry rpcProviderRegistry, final ClusterSingletonServiceProvider clusterSingletonServiceProvider, @@ -84,7 +88,9 @@ public class NetconfTopologyManager final ActorSystemProvider actorSystemProvider, final EventExecutor eventExecutor, final NetconfClientDispatcher clientDispatcher, final String topologyId, final Config config, - final DOMMountPointService mountPointService) { + final DOMMountPointService mountPointService, + final AAAEncryptionService encryptionService) { + this.dataBroker = Preconditions.checkNotNull(dataBroker); this.rpcProviderRegistry = Preconditions.checkNotNull(rpcProviderRegistry); this.clusterSingletonServiceProvider = Preconditions.checkNotNull(clusterSingletonServiceProvider); @@ -96,11 +102,13 @@ public class NetconfTopologyManager this.topologyId = Preconditions.checkNotNull(topologyId); this.writeTxIdleTimeout = Duration.apply(config.getWriteTransactionIdleTimeout(), TimeUnit.SECONDS); this.mountPointService = mountPointService; + this.encryptionService = Preconditions.checkNotNull(encryptionService); + } // Blueprint init method public void init() { - dataChangeListenerRegistration = registerDataTreeChangeListener(topologyId); + dataChangeListenerRegistration = registerDataTreeChangeListener(); } @Override @@ -138,6 +146,11 @@ public class NetconfTopologyManager context.refresh(createSetup(instanceIdentifier, node)); } + // ClusterSingletonServiceRegistration registerClusterSingletonService method throws a Runtime exception if there + // are problems with registration and client has to deal with it. Only thing we can do if this error occurs is to + // retry registration several times and log the error. + // TODO change to a specific documented Exception when changed in ClusterSingletonServiceProvider + @SuppressWarnings("checkstyle:IllegalCatch") private void startNetconfDeviceContext(final InstanceIdentifier instanceIdentifier, final Node node) { final NetconfNode netconfNode = node.getAugmentation(NetconfNode.class); Preconditions.checkNotNull(netconfNode); @@ -154,13 +167,29 @@ public class NetconfTopologyManager new NetconfTopologyContext(createSetup(instanceIdentifier, node), serviceGroupIdent, actorResponseWaitTime, mountPointService); - final ClusterSingletonServiceRegistration clusterSingletonServiceRegistration = - clusterSingletonServiceProvider.registerClusterSingletonService(newNetconfTopologyContext); + int tries = 3; + while (true) { + try { + final ClusterSingletonServiceRegistration clusterSingletonServiceRegistration = + clusterSingletonServiceProvider.registerClusterSingletonService(newNetconfTopologyContext); + clusterRegistrations.put(instanceIdentifier, clusterSingletonServiceRegistration); + contexts.put(instanceIdentifier, newNetconfTopologyContext); + break; + } catch (final RuntimeException e) { + LOG.warn("Unable to register cluster singleton service {}, trying again", newNetconfTopologyContext, e); + + if (--tries <= 0) { + LOG.error("Unable to register cluster singleton service {} - done trying, closing topology context", + newNetconfTopologyContext, e); + close(); + break; + } + } + } - clusterRegistrations.put(instanceIdentifier, clusterSingletonServiceRegistration); - contexts.put(instanceIdentifier, newNetconfTopologyContext); } + @SuppressWarnings("checkstyle:IllegalCatch") private void stopNetconfDeviceContext(final InstanceIdentifier instanceIdentifier) { if (contexts.containsKey(instanceIdentifier)) { try { @@ -174,6 +203,7 @@ public class NetconfTopologyManager } } + @SuppressWarnings("checkstyle:IllegalCatch") @Override public void close() { if (dataChangeListenerRegistration != null) { @@ -198,10 +228,24 @@ public class NetconfTopologyManager clusterRegistrations.clear(); } - private ListenerRegistration registerDataTreeChangeListener(final String topologyId) { + /** + * Sets the private key path from location specified in configuration file using blueprint. + */ + public void setPrivateKeyPath(String privateKeyPath) { + this.privateKeyPath = privateKeyPath; + } + + /** + * Sets the private key passphrase from location specified in configuration file using blueprint. + */ + public void setPrivateKeyPassphrase(String privateKeyPassphrase) { + this.privateKeyPassphrase = privateKeyPassphrase; + } + + private ListenerRegistration registerDataTreeChangeListener() { final WriteTransaction wtx = dataBroker.newWriteOnlyTransaction(); - initTopology(wtx, LogicalDatastoreType.CONFIGURATION, topologyId); - initTopology(wtx, LogicalDatastoreType.OPERATIONAL, topologyId); + initTopology(wtx, LogicalDatastoreType.CONFIGURATION); + initTopology(wtx, LogicalDatastoreType.OPERATIONAL); Futures.addCallback(wtx.submit(), new FutureCallback() { @Override public void onSuccess(final Void result) { @@ -212,7 +256,7 @@ public class NetconfTopologyManager public void onFailure(@Nonnull final Throwable throwable) { LOG.error("Unable to initialize netconf-topology, {}", throwable); } - }); + }, MoreExecutors.directExecutor()); LOG.debug("Registering datastore listener"); return dataBroker.registerDataTreeChangeListener( @@ -220,7 +264,7 @@ public class NetconfTopologyManager NetconfTopologyUtils.createTopologyListPath(topologyId).child(Node.class)), this); } - private void initTopology(final WriteTransaction wtx, final LogicalDatastoreType datastoreType, final String topologyId) { + private void initTopology(final WriteTransaction wtx, final LogicalDatastoreType datastoreType) { final NetworkTopology networkTopology = new NetworkTopologyBuilder().build(); final InstanceIdentifier networkTopologyId = InstanceIdentifier.builder(NetworkTopology.class).build(); @@ -244,7 +288,10 @@ public class NetconfTopologyManager .setTopologyId(topologyId) .setNetconfClientDispatcher(clientDispatcher) .setSchemaResourceDTO(NetconfTopologyUtils.setupSchemaCacheDTO(node)) - .setIdleTimeout(writeTxIdleTimeout); + .setIdleTimeout(writeTxIdleTimeout) + .setPrivateKeyPath(privateKeyPath) + .setPrivateKeyPassphrase(privateKeyPassphrase) + .setEncryptionService(encryptionService); return builder.build(); }