From f273cff9baab6d3bd6a93214b639ecab7061e242 Mon Sep 17 00:00:00 2001 From: "miroslav.kovac" Date: Thu, 16 Feb 2017 12:41:49 +0100 Subject: [PATCH] Bug 6581 - Make timeout for ask configurable Change-Id: Ie430aa39cc6a7b30e86ef3c73d27b35a10e97dac Signed-off-by: miroslav.kovac --- .../singleton/impl/MasterSalFacade.java | 19 +++++----- .../singleton/impl/NetconfNodeManager.java | 9 +++-- .../impl/NetconfTopologyContext.java | 19 ++++++---- .../impl/NetconfTopologyManager.java | 36 +++++++++++-------- .../singleton/impl/ProxyDOMRpcService.java | 8 +++-- .../impl/ProxyYangTextSourceProvider.java | 9 +++-- .../impl/RemoteDeviceConnectorImpl.java | 7 ++-- .../singleton/impl/SlaveSalFacade.java | 10 ++++-- .../impl/actors/NetconfNodeActor.java | 25 +++++++------ .../impl/tx/NetconfProxyDOMTransaction.java | 21 ++++++----- .../impl/utils/NetconfTopologyUtils.java | 12 +++---- .../singleton/impl/NetconfNodeActorTest.java | 14 ++++---- .../impl/NetconfTopologyManagerTest.java | 3 +- .../impl/RemoteDeviceConnectorImplTest.java | 13 ++++--- .../TestingRemoteDeviceConnectorImpl.java | 11 +++--- .../impl/tx/ReadOnlyTransactionTest.java | 4 +-- .../impl/tx/WriteOnlyTransactionTest.java | 4 +-- .../src/main/yang/netconf-node-topology.yang | 9 +++++ 18 files changed, 139 insertions(+), 94 deletions(-) diff --git a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/MasterSalFacade.java b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/MasterSalFacade.java index 36ab07bbea..d905fa1dc0 100644 --- a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/MasterSalFacade.java +++ b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/MasterSalFacade.java @@ -13,6 +13,7 @@ import akka.actor.ActorSystem; import akka.cluster.Cluster; import akka.dispatch.OnComplete; import akka.pattern.Patterns; +import akka.util.Timeout; import com.google.common.base.Optional; import com.google.common.base.Preconditions; import java.util.List; @@ -31,7 +32,6 @@ import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId; import org.opendaylight.netconf.topology.singleton.api.NetconfDOMTransaction; import org.opendaylight.netconf.topology.singleton.impl.tx.NetconfMasterDOMTransaction; import org.opendaylight.netconf.topology.singleton.impl.tx.NetconfProxyDOMTransaction; -import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologyUtils; import org.opendaylight.netconf.topology.singleton.messages.CreateInitialMasterActorData; import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; import org.opendaylight.yangtools.yang.model.api.SchemaContext; @@ -46,6 +46,7 @@ class MasterSalFacade implements AutoCloseable, RemoteDeviceHandler future = Patterns.ask(masterActorRef, new RefreshSetupMasterActorData( - netconfTopologyDeviceSetup, remoteDeviceId), NetconfTopologyUtils.TIMEOUT); + netconfTopologyDeviceSetup, remoteDeviceId), actorResponseWaitTime); future.onComplete(new OnComplete() { @Override 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 cfd9dd8113..23a46aaa5a 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 @@ -9,6 +9,7 @@ package org.opendaylight.netconf.topology.singleton.impl; import akka.actor.ActorSystem; +import akka.util.Timeout; import com.google.common.base.Preconditions; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; @@ -51,6 +52,7 @@ import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import scala.concurrent.duration.Duration; public class NetconfTopologyManager implements ClusteredDataTreeChangeListener, NetconfTopologySingletonService, AutoCloseable { @@ -76,11 +78,11 @@ public class NetconfTopologyManager private final String topologyId; public NetconfTopologyManager(final DataBroker dataBroker, final RpcProviderRegistry rpcProviderRegistry, - final ClusterSingletonServiceProvider clusterSingletonServiceProvider, - final BindingAwareBroker bindingAwareBroker, - final ScheduledThreadPool keepaliveExecutor, final ThreadPool processingExecutor, - final Broker domBroker, final ActorSystemProvider actorSystemProvider, final EventExecutor eventExecutor, - final NetconfClientDispatcher clientDispatcher, final String topologyId) { + final ClusterSingletonServiceProvider clusterSingletonServiceProvider, + final BindingAwareBroker bindingAwareBroker, + final ScheduledThreadPool keepaliveExecutor, final ThreadPool processingExecutor, + final Broker domBroker, final ActorSystemProvider actorSystemProvider, final EventExecutor eventExecutor, + final NetconfClientDispatcher clientDispatcher, final String topologyId) { this.dataBroker = Preconditions.checkNotNull(dataBroker); this.rpcProviderRegistry = Preconditions.checkNotNull(rpcProviderRegistry); this.clusterSingletonServiceProvider = Preconditions.checkNotNull(clusterSingletonServiceProvider); @@ -101,7 +103,7 @@ public class NetconfTopologyManager @Override public void onDataTreeChanged(@Nonnull final Collection> changes) { - for (DataTreeModification change : changes) { + for (final DataTreeModification change : changes) { final DataObjectModification rootNode = change.getRootNode(); final InstanceIdentifier dataModifIdent = change.getRootPath().getRootIdentifier(); final NodeId nodeId = NetconfTopologyUtils.getNodeId(rootNode.getIdentifier()); @@ -129,7 +131,7 @@ public class NetconfTopologyManager } } - private void refreshNetconfDeviceContext(InstanceIdentifier instanceIdentifier, Node node) { + private void refreshNetconfDeviceContext(final InstanceIdentifier instanceIdentifier, final Node node) { final NetconfTopologyContext context = contexts.get(instanceIdentifier); context.refresh(createSetup(instanceIdentifier, node)); } @@ -140,11 +142,15 @@ public class NetconfTopologyManager Preconditions.checkNotNull(netconfNode.getHost()); Preconditions.checkNotNull(netconfNode.getHost().getIpAddress()); + final Timeout actorResponseWaitTime = new Timeout(Duration.create(netconfNode.getActorResponseWaitTime(), + "seconds")); + final ServiceGroupIdentifier serviceGroupIdent = ServiceGroupIdentifier.create(instanceIdentifier.toString()); final NetconfTopologyContext newNetconfTopologyContext = - new NetconfTopologyContext(createSetup(instanceIdentifier, node), serviceGroupIdent); + new NetconfTopologyContext(createSetup(instanceIdentifier, node), serviceGroupIdent, + actorResponseWaitTime); final ClusterSingletonServiceRegistration clusterSingletonServiceRegistration = clusterSingletonServiceProvider.registerClusterSingletonService(newNetconfTopologyContext); @@ -158,7 +164,7 @@ public class NetconfTopologyManager try { clusterRegistrations.get(instanceIdentifier).close(); contexts.get(instanceIdentifier).closeFinal(); - } catch (Exception e) { + } catch (final Exception e) { LOG.warn("Error at closing topology context. InstanceIdentifier: " + instanceIdentifier); } contexts.remove(instanceIdentifier); @@ -175,14 +181,14 @@ public class NetconfTopologyManager contexts.forEach((instanceIdentifier, netconfTopologyContext) -> { try { netconfTopologyContext.closeFinal(); - } catch (Exception e) { + } catch (final Exception e) { LOG.error("Error at closing topology context. InstanceIdentifier: " + instanceIdentifier, e); } }); clusterRegistrations.forEach((instanceIdentifier, clusterSingletonServiceRegistration) -> { try { clusterSingletonServiceRegistration.close(); - } catch (Exception e) { + } catch (final Exception e) { LOG.error("Error at unregistering from cluster. InstanceIdentifier: " + instanceIdentifier, e); } }); @@ -190,18 +196,18 @@ public class NetconfTopologyManager clusterRegistrations.clear(); } - private ListenerRegistration registerDataTreeChangeListener(String topologyId) { + private ListenerRegistration registerDataTreeChangeListener(final String topologyId) { final WriteTransaction wtx = dataBroker.newWriteOnlyTransaction(); initTopology(wtx, LogicalDatastoreType.CONFIGURATION, topologyId); initTopology(wtx, LogicalDatastoreType.OPERATIONAL, topologyId); Futures.addCallback(wtx.submit(), new FutureCallback() { @Override - public void onSuccess(Void result) { + public void onSuccess(final Void result) { LOG.debug("topology initialization successful"); } @Override - public void onFailure(@Nonnull Throwable throwable) { + public void onFailure(@Nonnull final Throwable throwable) { LOG.error("Unable to initialize netconf-topology, {}", throwable); } }); @@ -212,7 +218,7 @@ public class NetconfTopologyManager NetconfTopologyUtils.createTopologyListPath(topologyId).child(Node.class)), this); } - private void initTopology(final WriteTransaction wtx, final LogicalDatastoreType datastoreType, String topologyId) { + private void initTopology(final WriteTransaction wtx, final LogicalDatastoreType datastoreType, final String topologyId) { final NetworkTopology networkTopology = new NetworkTopologyBuilder().build(); final InstanceIdentifier networkTopologyId = InstanceIdentifier.builder(NetworkTopology.class).build(); diff --git a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/ProxyDOMRpcService.java b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/ProxyDOMRpcService.java index c4ee7a7ea1..4fcd296329 100644 --- a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/ProxyDOMRpcService.java +++ b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/ProxyDOMRpcService.java @@ -12,6 +12,7 @@ import akka.actor.ActorRef; import akka.actor.ActorSystem; import akka.dispatch.OnComplete; import akka.pattern.Patterns; +import akka.util.Timeout; import com.google.common.base.Function; import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.Futures; @@ -26,7 +27,6 @@ import org.opendaylight.controller.md.sal.dom.api.DOMRpcService; import org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult; import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId; import org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringRpcException; -import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologyUtils; import org.opendaylight.netconf.topology.singleton.messages.NormalizedNodeMessage; import org.opendaylight.netconf.topology.singleton.messages.SchemaPathMessage; import org.opendaylight.netconf.topology.singleton.messages.rpc.InvokeRpcMessage; @@ -48,12 +48,14 @@ public class ProxyDOMRpcService implements DOMRpcService { private final ActorRef masterActorRef; private final ActorSystem actorSystem; private final RemoteDeviceId id; + private final Timeout actorResponseWaitTime; public ProxyDOMRpcService(final ActorSystem actorSystem, final ActorRef masterActorRef, - final RemoteDeviceId remoteDeviceId) { + final RemoteDeviceId remoteDeviceId, final Timeout actorResponseWaitTime) { this.actorSystem = actorSystem; this.masterActorRef = masterActorRef; id = remoteDeviceId; + this.actorResponseWaitTime = actorResponseWaitTime; } @Nonnull @@ -67,7 +69,7 @@ public class ProxyDOMRpcService implements DOMRpcService { final Future scalaFuture = Patterns.ask(masterActorRef, new InvokeRpcMessage(new SchemaPathMessage(type), normalizedNodeMessage), - NetconfTopologyUtils.TIMEOUT); + actorResponseWaitTime); final SettableFuture settableFuture = SettableFuture.create(); diff --git a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/ProxyYangTextSourceProvider.java b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/ProxyYangTextSourceProvider.java index 27514c788b..d4f0d79712 100644 --- a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/ProxyYangTextSourceProvider.java +++ b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/ProxyYangTextSourceProvider.java @@ -13,12 +13,12 @@ import akka.actor.ActorRef; import akka.dispatch.Futures; import akka.dispatch.OnComplete; import akka.pattern.Patterns; +import akka.util.Timeout; import com.google.common.collect.Sets; import java.util.Set; import javax.annotation.Nonnull; import org.opendaylight.controller.cluster.schema.provider.RemoteYangTextSourceProvider; import org.opendaylight.controller.cluster.schema.provider.impl.YangTextSchemaSourceSerializationProxy; -import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologyUtils; import org.opendaylight.netconf.topology.singleton.messages.YangTextSchemaSourceRequest; import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier; import scala.concurrent.Future; @@ -28,10 +28,13 @@ public class ProxyYangTextSourceProvider implements RemoteYangTextSourceProvider private final ActorRef masterRef; private final ActorContext actorContext; + private final Timeout actorResponseWaitTime; - public ProxyYangTextSourceProvider(final ActorRef masterRef, final ActorContext actorContext) { + public ProxyYangTextSourceProvider(final ActorRef masterRef, final ActorContext actorContext, + final Timeout actorResponseWaitTime) { this.masterRef = masterRef; this.actorContext = actorContext; + this.actorResponseWaitTime = actorResponseWaitTime; } @Override @@ -45,7 +48,7 @@ public class ProxyYangTextSourceProvider implements RemoteYangTextSourceProvider @Nonnull final SourceIdentifier sourceIdentifier) { final Future scalaFuture = Patterns.ask(masterRef, - new YangTextSchemaSourceRequest(sourceIdentifier), NetconfTopologyUtils.TIMEOUT); + new YangTextSchemaSourceRequest(sourceIdentifier), actorResponseWaitTime); final Promise.DefaultPromise promise = new Promise.DefaultPromise<>(); diff --git a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java index aa8853daa4..5a0d45c4f7 100644 --- a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java +++ b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java @@ -9,6 +9,7 @@ package org.opendaylight.netconf.topology.singleton.impl; import akka.actor.ActorRef; +import akka.util.Timeout; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.common.base.Strings; @@ -88,6 +89,7 @@ public class RemoteDeviceConnectorImpl implements RemoteDeviceConnector { * synchronization locks. */ private static final Map schemaResourcesDTOs = new HashMap<>(); + private final Timeout actorResponseWaitTime; // Initializes default constant instances for the case when the default schema repository // directory cache/schema is used. @@ -111,10 +113,11 @@ public class RemoteDeviceConnectorImpl implements RemoteDeviceConnector { private NetconfConnectorDTO deviceCommunicatorDTO; public RemoteDeviceConnectorImpl(final NetconfTopologySetup netconfTopologyDeviceSetup, - final RemoteDeviceId remoteDeviceId) { + final RemoteDeviceId remoteDeviceId, final Timeout actorResponseWaitTime) { this.netconfTopologyDeviceSetup = Preconditions.checkNotNull(netconfTopologyDeviceSetup); this.remoteDeviceId = remoteDeviceId; + this.actorResponseWaitTime = actorResponseWaitTime; } @Override @@ -170,7 +173,7 @@ public class RemoteDeviceConnectorImpl implements RemoteDeviceConnector { RemoteDeviceHandler salFacade = new MasterSalFacade(remoteDeviceId, netconfTopologyDeviceSetup.getDomBroker(), netconfTopologyDeviceSetup.getBindingAwareBroker(), - netconfTopologyDeviceSetup.getActorSystem(), deviceContextActorRef); + netconfTopologyDeviceSetup.getActorSystem(), deviceContextActorRef, actorResponseWaitTime); if (keepaliveDelay > 0) { LOG.info("{}: Adding keepalive facade.", remoteDeviceId); salFacade = new KeepaliveSalFacade(remoteDeviceId, salFacade, diff --git a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/SlaveSalFacade.java b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/SlaveSalFacade.java index 877436d6cc..fd1c28a0ad 100644 --- a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/SlaveSalFacade.java +++ b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/SlaveSalFacade.java @@ -10,6 +10,7 @@ package org.opendaylight.netconf.topology.singleton.impl; import akka.actor.ActorRef; import akka.actor.ActorSystem; +import akka.util.Timeout; import org.opendaylight.controller.md.sal.dom.api.DOMRpcService; import org.opendaylight.controller.sal.core.api.Broker; import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceNotificationService; @@ -29,13 +30,16 @@ public class SlaveSalFacade { private final NetconfDeviceSalProvider salProvider; private final ActorSystem actorSystem; + private final Timeout actorResponseWaitTime; public SlaveSalFacade(final RemoteDeviceId id, final Broker domBroker, - final ActorSystem actorSystem) { + final ActorSystem actorSystem, + final Timeout actorResponseWaitTime) { this.id = id; this.salProvider = new NetconfDeviceSalProvider(id); this.actorSystem = actorSystem; + this.actorResponseWaitTime = actorResponseWaitTime; registerToSal(domBroker); } @@ -50,7 +54,7 @@ public class SlaveSalFacade { final NetconfDeviceNotificationService notificationService = new NetconfDeviceNotificationService(); final NetconfDOMTransaction proxyDOMTransactions = - new NetconfProxyDOMTransaction(id, actorSystem, masterActorRef); + new NetconfProxyDOMTransaction(id, actorSystem, masterActorRef, actorResponseWaitTime); final NetconfDOMDataBroker netconfDeviceDataBroker = new NetconfDOMDataBroker(actorSystem, id, proxyDOMTransactions); @@ -69,7 +73,7 @@ public class SlaveSalFacade { unregisterSlaveMountPoint(); try { salProvider.getMountInstance().close(); - } catch (Exception exception) { + } catch (final Exception exception) { LOG.warn("{}: Exception in closing slave sal facade: {}", id, exception); } diff --git a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/actors/NetconfNodeActor.java b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/actors/NetconfNodeActor.java index edbfe1be51..ba8f11fdc0 100644 --- a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/actors/NetconfNodeActor.java +++ b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/actors/NetconfNodeActor.java @@ -11,6 +11,7 @@ package org.opendaylight.netconf.topology.singleton.impl.actors; import akka.actor.ActorRef; import akka.actor.Props; import akka.actor.UntypedActor; +import akka.util.Timeout; import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; @@ -79,21 +80,23 @@ public class NetconfNodeActor extends UntypedActor { private List sourceIdentifiers; private DOMRpcService deviceRpc; private SlaveSalFacade slaveSalManager; + private final Timeout actorResponseWaitTime; public static Props props(final NetconfTopologySetup setup, final RemoteDeviceId id, final SchemaSourceRegistry schemaRegistry, - final SchemaRepository schemaRepository) { + final SchemaRepository schemaRepository, final Timeout actorResponseWaitTime) { return Props.create(NetconfNodeActor.class, () -> - new NetconfNodeActor(setup, id, schemaRegistry, schemaRepository)); + new NetconfNodeActor(setup, id, schemaRegistry, schemaRepository, actorResponseWaitTime)); } private NetconfNodeActor(final NetconfTopologySetup setup, - final RemoteDeviceId id, SchemaSourceRegistry schemaRegistry, - final SchemaRepository schemaRepository) { + final RemoteDeviceId id, final SchemaSourceRegistry schemaRegistry, + final SchemaRepository schemaRepository, final Timeout actorResponseWaitTime) { this.setup = setup; this.id = id; this.schemaRegistry = schemaRegistry; this.schemaRepository = schemaRepository; + this.actorResponseWaitTime = actorResponseWaitTime; } @Override @@ -195,7 +198,7 @@ public class NetconfNodeActor extends UntypedActor { public void onSuccess(final YangTextSchemaSource yangTextSchemaSource) { try { sender.tell(new YangTextSchemaSourceSerializationProxy(yangTextSchemaSource), getSelf()); - } catch (IOException exception) { + } catch (final IOException exception) { sender.tell(exception.getCause(), getSelf()); } } @@ -235,11 +238,11 @@ public class NetconfNodeActor extends UntypedActor { }); } - private void registerSlaveMountPoint(ActorRef masterReference) { + private void registerSlaveMountPoint(final ActorRef masterReference) { if (this.slaveSalManager != null) { slaveSalManager.close(); } - slaveSalManager = new SlaveSalFacade(id, setup.getDomBroker(), setup.getActorSystem()); + slaveSalManager = new SlaveSalFacade(id, setup.getDomBroker(), setup.getActorSystem(), actorResponseWaitTime); final CheckedFuture remoteSchemaContext = getSchemaContext(masterReference); @@ -259,14 +262,14 @@ public class NetconfNodeActor extends UntypedActor { }); } - private DOMRpcService getDOMRpcService(ActorRef masterReference) { - return new ProxyDOMRpcService(setup.getActorSystem(), masterReference, id); + private DOMRpcService getDOMRpcService(final ActorRef masterReference) { + return new ProxyDOMRpcService(setup.getActorSystem(), masterReference, id, actorResponseWaitTime); } - private CheckedFuture getSchemaContext(ActorRef masterReference) { + private CheckedFuture getSchemaContext(final ActorRef masterReference) { final RemoteYangTextSourceProvider remoteYangTextSourceProvider = - new ProxyYangTextSourceProvider(masterReference, getContext()); + new ProxyYangTextSourceProvider(masterReference, getContext(), actorResponseWaitTime); final RemoteSchemaProvider remoteProvider = new RemoteSchemaProvider(remoteYangTextSourceProvider, getContext().dispatcher()); diff --git a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/tx/NetconfProxyDOMTransaction.java b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/tx/NetconfProxyDOMTransaction.java index 9b2adf2efa..aa05f5415d 100644 --- a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/tx/NetconfProxyDOMTransaction.java +++ b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/tx/NetconfProxyDOMTransaction.java @@ -12,13 +12,13 @@ import akka.actor.ActorRef; import akka.actor.ActorSystem; import akka.dispatch.OnComplete; import akka.pattern.Patterns; +import akka.util.Timeout; import com.google.common.base.Optional; import com.google.common.base.Throwables; import org.opendaylight.controller.config.util.xml.DocumentedException; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId; import org.opendaylight.netconf.topology.singleton.api.NetconfDOMTransaction; -import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologyUtils; import org.opendaylight.netconf.topology.singleton.messages.NormalizedNodeMessage; import org.opendaylight.netconf.topology.singleton.messages.transactions.CancelRequest; import org.opendaylight.netconf.topology.singleton.messages.transactions.DeleteRequest; @@ -45,13 +45,16 @@ public class NetconfProxyDOMTransaction implements NetconfDOMTransaction { private final RemoteDeviceId id; private final ActorSystem actorSystem; private final ActorRef masterContextRef; + private final Timeout actorResponseWaitTime; public NetconfProxyDOMTransaction(final RemoteDeviceId id, final ActorSystem actorSystem, - final ActorRef masterContextRef) { + final ActorRef masterContextRef, + final Timeout actorResponseWaitTime) { this.id = id; this.actorSystem = actorSystem; this.masterContextRef = masterContextRef; + this.actorResponseWaitTime = actorResponseWaitTime; } @Override @@ -61,10 +64,10 @@ public class NetconfProxyDOMTransaction implements NetconfDOMTransaction { // node. LOG.debug("{}: Requesting leader {} to open new transaction", id, masterContextRef); final Future openTxFuture = - Patterns.ask(masterContextRef, new OpenTransaction(), NetconfTopologyUtils.TIMEOUT); + Patterns.ask(masterContextRef, new OpenTransaction(), actorResponseWaitTime); try { // we have to wait here so we can see if tx can be opened - Await.result(openTxFuture, NetconfTopologyUtils.TIMEOUT.duration()); + Await.result(openTxFuture, actorResponseWaitTime.duration()); LOG.debug("{}: New transaction opened successfully", id); } catch (final Exception e) { LOG.error("{}: Failed to open new transaction", id, e); @@ -77,7 +80,7 @@ public class NetconfProxyDOMTransaction implements NetconfDOMTransaction { final YangInstanceIdentifier path) { final Future readScalaFuture = - Patterns.ask(masterContextRef, new ReadRequest(store, path), NetconfTopologyUtils.TIMEOUT); + Patterns.ask(masterContextRef, new ReadRequest(store, path), actorResponseWaitTime); LOG.trace("{}: Read {} via NETCONF: {}", id, store, path); @@ -111,7 +114,7 @@ public class NetconfProxyDOMTransaction implements NetconfDOMTransaction { @Override public Future exists(final LogicalDatastoreType store, final YangInstanceIdentifier path) { final Future existsScalaFuture = - Patterns.ask(masterContextRef, new ExistsRequest(store, path), NetconfTopologyUtils.TIMEOUT); + Patterns.ask(masterContextRef, new ExistsRequest(store, path), actorResponseWaitTime); LOG.trace("{}: Exists {} via NETCONF: {}", id, store, path); @@ -161,13 +164,13 @@ public class NetconfProxyDOMTransaction implements NetconfDOMTransaction { @Override public boolean cancel() { final Future cancelScalaFuture = - Patterns.ask(masterContextRef, new CancelRequest(), NetconfTopologyUtils.TIMEOUT); + Patterns.ask(masterContextRef, new CancelRequest(), actorResponseWaitTime); LOG.trace("{}: Cancel {} via NETCONF", id); try { // here must be Await because AsyncWriteTransaction do not return future - return (boolean) Await.result(cancelScalaFuture, NetconfTopologyUtils.TIMEOUT.duration()); + return (boolean) Await.result(cancelScalaFuture, actorResponseWaitTime.duration()); } catch (Exception e) { return false; } @@ -176,7 +179,7 @@ public class NetconfProxyDOMTransaction implements NetconfDOMTransaction { @Override public Future submit() { final Future submitScalaFuture = - Patterns.ask(masterContextRef, new SubmitRequest(), NetconfTopologyUtils.TIMEOUT); + Patterns.ask(masterContextRef, new SubmitRequest(), actorResponseWaitTime); LOG.trace("{}: Submit {} via NETCONF", id); diff --git a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfTopologyUtils.java b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfTopologyUtils.java index a0aad347d4..0968ddbebd 100644 --- a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfTopologyUtils.java +++ b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfTopologyUtils.java @@ -8,7 +8,6 @@ package org.opendaylight.netconf.topology.singleton.impl.utils; -import akka.util.Timeout; import java.io.File; import java.math.BigDecimal; import java.net.InetSocketAddress; @@ -30,14 +29,11 @@ import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceFilter; import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource; import org.opendaylight.yangtools.yang.model.repo.util.FilesystemSchemaSourceCache; import org.opendaylight.yangtools.yang.parser.repo.SharedSchemaRepository; -import scala.concurrent.duration.Duration; public class NetconfTopologyUtils { private static final String DEFAULT_SCHEMA_REPOSITORY_NAME = "sal-netconf-connector"; - public static final Timeout TIMEOUT = new Timeout(Duration.create(10, "seconds")); - public static final long DEFAULT_REQUEST_TIMEOUT_MILLIS = 60000L; public static final int DEFAULT_KEEPALIVE_DELAY = 0; public static final boolean DEFAULT_RECONNECT_ON_CHANGED_SCHEMA = false; @@ -74,18 +70,18 @@ public class NetconfTopologyUtils { DEFAULT_SCHEMA_REPOSITORY.createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT); public static RemoteDeviceId createRemoteDeviceId(final NodeId nodeId, final NetconfNode node) { - IpAddress ipAddress = node.getHost().getIpAddress(); - InetSocketAddress address = new InetSocketAddress(ipAddress.getIpv4Address() != null + final IpAddress ipAddress = node.getHost().getIpAddress(); + final InetSocketAddress address = new InetSocketAddress(ipAddress.getIpv4Address() != null ? ipAddress.getIpv4Address().getValue() : ipAddress.getIpv6Address().getValue(), node.getPort().getValue()); return new RemoteDeviceId(nodeId.getValue(), address); } - public static String createActorPath(String masterMember, String name) { + public static String createActorPath(final String masterMember, final String name) { return masterMember + "/user/" + name; } - public static String createMasterActorName(String name, String masterAddress) { + public static String createMasterActorName(final String name, final String masterAddress) { return masterAddress.replaceAll("//", "") + "_" + name; } diff --git a/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/NetconfNodeActorTest.java b/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/NetconfNodeActorTest.java index 63246e0951..b17b8daa70 100644 --- a/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/NetconfNodeActorTest.java +++ b/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/NetconfNodeActorTest.java @@ -100,7 +100,7 @@ public class NetconfNodeActorTest { final NetconfTopologySetup setup = mock(NetconfTopologySetup.class); final Props props = NetconfNodeActor.props(setup, remoteDeviceId, DEFAULT_SCHEMA_REPOSITORY, - DEFAULT_SCHEMA_REPOSITORY); + DEFAULT_SCHEMA_REPOSITORY, TIMEOUT); system = ActorSystem.create(); @@ -180,19 +180,19 @@ public class NetconfNodeActorTest { final SchemaRepository schemaRepository = mock(SchemaRepository.class); final SourceIdentifier sourceIdentifier = RevisionSourceIdentifier.create("testID", Optional.absent()); final Props props = NetconfNodeActor.props(mock(NetconfTopologySetup.class), remoteDeviceId, - DEFAULT_SCHEMA_REPOSITORY, schemaRepository); + DEFAULT_SCHEMA_REPOSITORY, schemaRepository, TIMEOUT); final ActorRef actorRefSchemaRepo = TestActorRef.create(system, props, "master_mocked_schema_repository"); final ActorContext actorContext = mock(ActorContext.class); doReturn(system.dispatcher()).when(actorContext).dispatcher(); final ProxyYangTextSourceProvider proxyYang = - new ProxyYangTextSourceProvider(actorRefSchemaRepo, actorContext); + new ProxyYangTextSourceProvider(actorRefSchemaRepo, actorContext, TIMEOUT); // test if asking for source is resolved and sended back final YangTextSchemaSource yangTextSchemaSource = new YangTextSchemaSource(sourceIdentifier) { @Override - protected MoreObjects.ToStringHelper addToStringAttributes(MoreObjects.ToStringHelper toStringHelper) { + protected MoreObjects.ToStringHelper addToStringAttributes(final MoreObjects.ToStringHelper toStringHelper) { return null; } @@ -254,7 +254,7 @@ public class NetconfNodeActorTest { // test if slave get right identifiers from master - final ProxyDOMRpcService slaveDomRPCService = new ProxyDOMRpcService(system, masterRef, remoteDeviceId); + final ProxyDOMRpcService slaveDomRPCService = new ProxyDOMRpcService(system, masterRef, remoteDeviceId, TIMEOUT); final SchemaPath schemaPath = SchemaPath.create(true, QName.create("TestQname")); final NormalizedNode outputNode = ImmutableContainerNodeBuilder.create() @@ -325,8 +325,8 @@ public class NetconfNodeActorTest { } - private String convertStreamToString(java.io.InputStream is) { - java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A"); + private String convertStreamToString(final java.io.InputStream is) { + final java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A"); return s.hasNext() ? s.next() : ""; } diff --git a/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/NetconfTopologyManagerTest.java b/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/NetconfTopologyManagerTest.java index 9a3749c14e..df398f3fb2 100644 --- a/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/NetconfTopologyManagerTest.java +++ b/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/NetconfTopologyManagerTest.java @@ -131,6 +131,7 @@ public class NetconfTopologyManagerTest { .setBetweenAttemptsTimeoutMillis(100) .setSchemaless(false) .setTcpOnly(false) + .setActorResponseWaitTime(10) .build(); final Node node = new NodeBuilder().setNodeId(new NodeId("node-id")) .addAugmentation(NetconfNode.class, netconfNode).build(); @@ -251,7 +252,7 @@ public class NetconfTopologyManagerTest { private final DataTreeIdentifier rootPath; private final DataObjectModification rootNode; - CustomTreeModification(DataTreeIdentifier rootPath, DataObjectModification rootNode) { + CustomTreeModification(final DataTreeIdentifier rootPath, final DataObjectModification rootNode) { this.rootPath = rootPath; this.rootNode = rootNode; } diff --git a/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImplTest.java b/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImplTest.java index c1515abffb..c1036e70f7 100644 --- a/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImplTest.java +++ b/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImplTest.java @@ -19,6 +19,7 @@ import static org.mockito.MockitoAnnotations.initMocks; import akka.actor.ActorRef; import akka.actor.ActorSystem; +import akka.util.Timeout; import io.netty.util.concurrent.EventExecutor; import java.net.InetAddress; import java.net.InetSocketAddress; @@ -55,11 +56,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev15 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.network.topology.topology.Node; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder; +import scala.concurrent.duration.Duration; public class RemoteDeviceConnectorImplTest { private static final NodeId NODE_ID = new NodeId("testing-node"); private static final String TOPOLOGY_ID = "testing-topology"; + private static final Timeout TIMEOUT = new Timeout(Duration.create(5, "seconds")); @Mock private DataBroker dataBroker; @@ -138,7 +141,7 @@ public class RemoteDeviceConnectorImplTest { final RemoteDeviceHandler salFacade = mock(RemoteDeviceHandler.class); final TestingRemoteDeviceConnectorImpl remoteDeviceConnection = - new TestingRemoteDeviceConnectorImpl(builder.build(), remoteDeviceId, communicator, salFacade); + new TestingRemoteDeviceConnectorImpl(builder.build(), remoteDeviceId, communicator, salFacade, TIMEOUT); final ActorRef masterRef = mock(ActorRef.class); @@ -169,7 +172,7 @@ public class RemoteDeviceConnectorImplTest { .build(); final RemoteDeviceConnectorImpl remoteDeviceConnection = - new RemoteDeviceConnectorImpl(builder.build(), remoteDeviceId); + new RemoteDeviceConnectorImpl(builder.build(), remoteDeviceId, TIMEOUT); final ActorRef masterRef = mock(ActorRef.class); @@ -201,7 +204,7 @@ public class RemoteDeviceConnectorImplTest { new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 9999)); final RemoteDeviceConnectorImpl remoteDeviceConnection = - new RemoteDeviceConnectorImpl(builder.build(), remoteDeviceId); + new RemoteDeviceConnectorImpl(builder.build(), remoteDeviceId, TIMEOUT); final ActorRef masterRef = mock(ActorRef.class); @@ -228,7 +231,7 @@ public class RemoteDeviceConnectorImplTest { .build(); final RemoteDeviceConnectorImpl remoteDeviceConnection = - new RemoteDeviceConnectorImpl(builder.build(), remoteDeviceId); + new RemoteDeviceConnectorImpl(builder.build(), remoteDeviceId, TIMEOUT); final NetconfReconnectingClientConfiguration defaultClientConfig = remoteDeviceConnection.getClientConfig(listener, testingNode); @@ -259,7 +262,7 @@ public class RemoteDeviceConnectorImplTest { .build(); final RemoteDeviceConnectorImpl remoteDeviceConnection = - new RemoteDeviceConnectorImpl(builder.build(), remoteDeviceId); + new RemoteDeviceConnectorImpl(builder.build(), remoteDeviceId, TIMEOUT); final ActorRef masterRef = mock(ActorRef.class); diff --git a/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/TestingRemoteDeviceConnectorImpl.java b/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/TestingRemoteDeviceConnectorImpl.java index 780b14e86f..d2a515b1e0 100644 --- a/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/TestingRemoteDeviceConnectorImpl.java +++ b/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/TestingRemoteDeviceConnectorImpl.java @@ -12,6 +12,7 @@ import static org.mockito.Matchers.any; import static org.mockito.Mockito.doReturn; import akka.actor.ActorRef; +import akka.util.Timeout; import com.google.common.util.concurrent.Futures; import org.opendaylight.netconf.sal.connect.api.RemoteDeviceHandler; import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator; @@ -27,10 +28,11 @@ class TestingRemoteDeviceConnectorImpl extends RemoteDeviceConnectorImpl { private final RemoteDeviceHandler salFacade; TestingRemoteDeviceConnectorImpl(final NetconfTopologySetup netconfTopologyDeviceSetup, - final RemoteDeviceId remoteDeviceId, - final NetconfDeviceCommunicator communicator, - final RemoteDeviceHandler salFacade) { - super(netconfTopologyDeviceSetup, remoteDeviceId); + final RemoteDeviceId remoteDeviceId, + final NetconfDeviceCommunicator communicator, + final RemoteDeviceHandler salFacade, + final Timeout actorResponseWaitTime) { + super(netconfTopologyDeviceSetup, remoteDeviceId, actorResponseWaitTime); this.communicator = communicator; this.salFacade = salFacade; } @@ -38,7 +40,6 @@ class TestingRemoteDeviceConnectorImpl extends RemoteDeviceConnectorImpl { @Override public NetconfConnectorDTO createDeviceCommunicator(final NodeId nodeId, final NetconfNode node, final ActorRef deviceContextActorRef) { - final NetconfConnectorDTO connectorDTO = new NetconfConnectorDTO(communicator, salFacade); doReturn(Futures.immediateCheckedFuture(null)).when(communicator).initializeRemoteConnection(any(), any()); return connectorDTO; diff --git a/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/tx/ReadOnlyTransactionTest.java b/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/tx/ReadOnlyTransactionTest.java index 6297efe963..58422776f5 100644 --- a/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/tx/ReadOnlyTransactionTest.java +++ b/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/tx/ReadOnlyTransactionTest.java @@ -89,7 +89,7 @@ public class ReadOnlyTransactionTest { final NetconfTopologySetup setup = mock(NetconfTopologySetup.class); final Props props = NetconfNodeActor.props(setup, remoteDeviceId, DEFAULT_SCHEMA_REPOSITORY, - DEFAULT_SCHEMA_REPOSITORY); + DEFAULT_SCHEMA_REPOSITORY, TIMEOUT); masterRef = TestActorRef.create(system, props, "master_read"); @@ -111,7 +111,7 @@ public class ReadOnlyTransactionTest { // Create slave data broker for testing proxy final NetconfDOMTransaction proxyDOMTransactions = - new NetconfProxyDOMTransaction(remoteDeviceId, system, masterRef); + new NetconfProxyDOMTransaction(remoteDeviceId, system, masterRef, TIMEOUT); slaveDataBroker = new NetconfDOMDataBroker(system, remoteDeviceId, proxyDOMTransactions); diff --git a/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/tx/WriteOnlyTransactionTest.java b/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/tx/WriteOnlyTransactionTest.java index c8cd518746..2dc446118c 100644 --- a/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/tx/WriteOnlyTransactionTest.java +++ b/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/tx/WriteOnlyTransactionTest.java @@ -94,7 +94,7 @@ public class WriteOnlyTransactionTest { final NetconfTopologySetup setup = mock(NetconfTopologySetup.class); final Props props = NetconfNodeActor.props(setup, remoteDeviceId, DEFAULT_SCHEMA_REPOSITORY, - DEFAULT_SCHEMA_REPOSITORY); + DEFAULT_SCHEMA_REPOSITORY, TIMEOUT); masterRef = TestActorRef.create(system, props, "master_read"); @@ -118,7 +118,7 @@ public class WriteOnlyTransactionTest { // Create slave data broker for testing proxy final NetconfDOMTransaction proxyDOMTransactions = - new NetconfProxyDOMTransaction(remoteDeviceId, system, masterRef); + new NetconfProxyDOMTransaction(remoteDeviceId, system, masterRef, TIMEOUT); slaveDataBroker = new NetconfDOMDataBroker(system, remoteDeviceId, proxyDOMTransactions); diff --git a/netconf/sal-netconf-connector/src/main/yang/netconf-node-topology.yang b/netconf/sal-netconf-connector/src/main/yang/netconf-node-topology.yang index d52b93dd25..446d815406 100644 --- a/netconf/sal-netconf-connector/src/main/yang/netconf-node-topology.yang +++ b/netconf/sal-netconf-connector/src/main/yang/netconf-node-topology.yang @@ -143,6 +143,15 @@ module netconf-node-topology { description "Limit of concurrent messages that can be send before reply messages are received. If value <1 is provided, no limit will be enforced"; } + + leaf actor-response-wait-time { + config true; + type uint16 { + range "1..max"; + } + default 5; + description "Time that slave actor will wait for response from master."; + } } grouping netconf-node-connection-status { -- 2.36.6