Value for transactions moved to yang module 12/20512/3
authorMarian Dubai <mdubai@cisco.com>
Fri, 15 May 2015 13:53:57 +0000 (15:53 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 19 May 2015 14:36:54 +0000 (14:36 +0000)
Timeout value for blocking operations within
transactions moved from AbstractWriteTx to yang module
odl-sal-netconf-connector-cfg.yang

Change-Id: I4414a613445c914b0b3262705ca5ceae058b51d5
Signed-off-by: Marian Dubai <mdubai@cisco.com>
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModule.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/sal/NetconfDeviceDataBroker.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/sal/NetconfDeviceSalFacade.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/sal/tx/AbstractWriteTx.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/sal/tx/WriteCandidateRunningTx.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/sal/tx/WriteCandidateTx.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/sal/tx/WriteRunningTx.java
opendaylight/md-sal/sal-netconf-connector/src/main/yang/odl-sal-netconf-connector-cfg.yang
opendaylight/md-sal/sal-netconf-connector/src/test/java/org/opendaylight/controller/sal/connect/netconf/sal/tx/NetconfDeviceWriteOnlyTxTest.java

index 4465e93dbf8836b13b03802a939c485aaf1490ad..e115c36ac0fda36a079620ffbcfdb15d8072a08c 100644 (file)
@@ -73,6 +73,9 @@ public final class NetconfConnectorModule extends org.opendaylight.controller.co
         checkNotNull(getConnectionTimeoutMillis(), connectionTimeoutMillisJmxAttribute);
         checkCondition(getConnectionTimeoutMillis() > 0, "must be > 0", connectionTimeoutMillisJmxAttribute);
 
+        checkNotNull(getConnectionTimeoutMillis(), defaultRequestTimeoutMillisJmxAttribute);
+        checkCondition(getConnectionTimeoutMillis() > 0, "must be > 0", defaultRequestTimeoutMillisJmxAttribute);
+
         checkNotNull(getBetweenAttemptsTimeoutMillis(), betweenAttemptsTimeoutMillisJmxAttribute);
         checkCondition(getBetweenAttemptsTimeoutMillis() > 0, "must be > 0", betweenAttemptsTimeoutMillisJmxAttribute);
 
@@ -104,7 +107,7 @@ public final class NetconfConnectorModule extends org.opendaylight.controller.co
         final BindingAwareBroker bindingBroker = getBindingRegistryDependency();
 
         final RemoteDeviceHandler<NetconfSessionPreferences> salFacade
-                = new NetconfDeviceSalFacade(id, domBroker, bindingBroker, bundleContext);
+                = new NetconfDeviceSalFacade(id, domBroker, bindingBroker, bundleContext, getDefaultRequestTimeoutMillis());
 
         final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO =
                 new NetconfDevice.SchemaResourcesDTO(schemaRegistry, schemaContextFactory, new NetconfStateSchemas.NetconfStateSchemasResolverImpl());
@@ -159,7 +162,7 @@ public final class NetconfConnectorModule extends org.opendaylight.controller.co
         .withAddress(socketAddress)
         .withConnectionTimeoutMillis(clientConnectionTimeoutMillis)
         .withReconnectStrategy(strategy)
-        .withAuthHandler(new LoginPassword(getUsername(),getPassword()))
+        .withAuthHandler(new LoginPassword(getUsername(), getPassword()))
         .withProtocol(getTcpOnly() ?
                 NetconfClientConfiguration.NetconfClientProtocol.TCP :
                 NetconfClientConfiguration.NetconfClientProtocol.SSH)
index ae9d3888d8f49fcbdcf0273e925d5ddc4adc5d15..8b7ea6caa8cb6370a8830c3da12643a3c38269b3 100644 (file)
@@ -36,11 +36,13 @@ final class NetconfDeviceDataBroker implements DOMDataBroker {
     private final RemoteDeviceId id;
     private final NetconfBaseOps netconfOps;
     private final NetconfSessionPreferences netconfSessionPreferences;
+    private final long defaultRequestTimeoutMillis;
 
-    public NetconfDeviceDataBroker(final RemoteDeviceId id, final SchemaContext schemaContext, final DOMRpcService rpc, final NetconfSessionPreferences netconfSessionPreferences) {
+    public NetconfDeviceDataBroker(final RemoteDeviceId id, final SchemaContext schemaContext, final DOMRpcService rpc, final NetconfSessionPreferences netconfSessionPreferences, long defaultRequestTimeoutMillis) {
         this.id = id;
         this.netconfOps = new NetconfBaseOps(rpc, schemaContext);
         this.netconfSessionPreferences = netconfSessionPreferences;
+        this.defaultRequestTimeoutMillis = defaultRequestTimeoutMillis;
     }
 
     @Override
@@ -57,12 +59,12 @@ final class NetconfDeviceDataBroker implements DOMDataBroker {
     public DOMDataWriteTransaction newWriteOnlyTransaction() {
         if(netconfSessionPreferences.isCandidateSupported()) {
             if(netconfSessionPreferences.isRunningWritable()) {
-                return new WriteCandidateRunningTx(id, netconfOps, netconfSessionPreferences);
+                return new WriteCandidateRunningTx(id, netconfOps, netconfSessionPreferences, defaultRequestTimeoutMillis);
             } else {
-                return new WriteCandidateTx(id, netconfOps, netconfSessionPreferences);
+                return new WriteCandidateTx(id, netconfOps, netconfSessionPreferences, defaultRequestTimeoutMillis);
             }
         } else {
-            return new WriteRunningTx(id, netconfOps, netconfSessionPreferences);
+            return new WriteRunningTx(id, netconfOps, netconfSessionPreferences, defaultRequestTimeoutMillis);
         }
     }
 
index 7ffeec3096934995dbc5dd73844ff49999d190c8..d73834e71adb1a8de00fbe9f16680ea7258a6671 100644 (file)
@@ -31,12 +31,14 @@ public final class NetconfDeviceSalFacade implements AutoCloseable, RemoteDevice
 
     private final RemoteDeviceId id;
     private final NetconfDeviceSalProvider salProvider;
+    private final long defaultRequestTimeoutMillis;
 
     private final List<AutoCloseable> salRegistrations = Lists.newArrayList();
 
-    public NetconfDeviceSalFacade(final RemoteDeviceId id, final Broker domBroker, final BindingAwareBroker bindingBroker, final BundleContext bundleContext) {
+    public NetconfDeviceSalFacade(final RemoteDeviceId id, final Broker domBroker, final BindingAwareBroker bindingBroker, final BundleContext bundleContext, long defaultRequestTimeoutMillis) {
         this.id = id;
         this.salProvider = new NetconfDeviceSalProvider(id);
+        this.defaultRequestTimeoutMillis = defaultRequestTimeoutMillis;
         registerToSal(domBroker, bindingBroker, bundleContext);
     }
 
@@ -54,7 +56,7 @@ public final class NetconfDeviceSalFacade implements AutoCloseable, RemoteDevice
     public synchronized void onDeviceConnected(final SchemaContext schemaContext,
                                                final NetconfSessionPreferences netconfSessionPreferences, final DOMRpcService deviceRpc) {
 
-        final DOMDataBroker domBroker = new NetconfDeviceDataBroker(id, schemaContext, deviceRpc, netconfSessionPreferences);
+        final DOMDataBroker domBroker = new NetconfDeviceDataBroker(id, schemaContext, deviceRpc, netconfSessionPreferences, defaultRequestTimeoutMillis);
 
         final NetconfDeviceNotificationService notificationService = new NetconfDeviceNotificationService();
 
index ee0a774dfdfdf19faceafb0fdfd8503b4e0dbaa0..ccdde08ddc0efb8b151c0fc598bd87b560eb9dbf 100644 (file)
@@ -23,7 +23,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 
 public abstract class AbstractWriteTx implements DOMDataWriteTransaction {
 
-    private static final long DEFAULT_REQUEST_TIMEOUT_MINUTES = 1L;
+    private final long defaultRequestTimeoutMillis;
 
     protected final RemoteDeviceId id;
     protected final NetconfBaseOps netOps;
@@ -31,10 +31,11 @@ public abstract class AbstractWriteTx implements DOMDataWriteTransaction {
     // Allow commit to be called only once
     protected boolean finished = false;
 
-    public AbstractWriteTx(final NetconfBaseOps netOps, final RemoteDeviceId id, final NetconfSessionPreferences netconfSessionPreferences) {
+    public AbstractWriteTx(final NetconfBaseOps netOps, final RemoteDeviceId id, final NetconfSessionPreferences netconfSessionPreferences, long defaultRequestTimeoutMillis) {
         this.netOps = netOps;
         this.id = id;
         this.netconfSessionPreferences = netconfSessionPreferences;
+        this.defaultRequestTimeoutMillis = defaultRequestTimeoutMillis;
         init();
     }
 
@@ -52,7 +53,7 @@ public abstract class AbstractWriteTx implements DOMDataWriteTransaction {
 
     protected void invokeBlocking(final String msg, final Function<NetconfBaseOps, ListenableFuture<DOMRpcResult>> op) throws NetconfDocumentedException {
         try {
-            final DOMRpcResult compositeNodeRpcResult = op.apply(netOps).get(DEFAULT_REQUEST_TIMEOUT_MINUTES, TimeUnit.MINUTES);
+            final DOMRpcResult compositeNodeRpcResult = op.apply(netOps).get(defaultRequestTimeoutMillis, TimeUnit.MILLISECONDS);
             if(isSuccess(compositeNodeRpcResult) == false) {
                 throw new NetconfDocumentedException(id + ": " + msg + " failed: " + compositeNodeRpcResult.getErrors(), NetconfDocumentedException.ErrorType.application,
                         NetconfDocumentedException.ErrorTag.operation_failed, NetconfDocumentedException.ErrorSeverity.warning);
index 33ca5f469b5b6118e159b8cef6c0a77411b94415..b7b213df70148ff07911356801d6ea7a318119b5 100644 (file)
@@ -30,8 +30,8 @@ public class WriteCandidateRunningTx extends WriteCandidateTx {
 
     private static final Logger LOG  = LoggerFactory.getLogger(WriteCandidateRunningTx.class);
 
-    public WriteCandidateRunningTx(final RemoteDeviceId id, final NetconfBaseOps netOps, final NetconfSessionPreferences netconfSessionPreferences) {
-        super(id, netOps, netconfSessionPreferences);
+    public WriteCandidateRunningTx(final RemoteDeviceId id, final NetconfBaseOps netOps, final NetconfSessionPreferences netconfSessionPreferences, long defaultRequestTimeoutMillis) {
+        super(id, netOps, netconfSessionPreferences, defaultRequestTimeoutMillis);
     }
 
     @Override
index cad65ff0bea0edebf56aa0dcaba174224e14a95b..5deb9e729c7cfdb8754e86b39de4aabac4feb458 100644 (file)
@@ -69,8 +69,8 @@ public class WriteCandidateTx extends AbstractWriteTx {
         }
     };
 
-    public WriteCandidateTx(final RemoteDeviceId id, final NetconfBaseOps rpc, final NetconfSessionPreferences netconfSessionPreferences) {
-        super(rpc, id, netconfSessionPreferences);
+    public WriteCandidateTx(final RemoteDeviceId id, final NetconfBaseOps rpc, final NetconfSessionPreferences netconfSessionPreferences, long defaultRequestTimeoutMillis) {
+        super(rpc, id, netconfSessionPreferences, defaultRequestTimeoutMillis);
     }
 
     @Override
index 00236803eba32eeb87ab7c51ccabc5fe9570bb3b..080aa60db2c27bfebb2cf8b036e24f1f5b3fa7e1 100644 (file)
@@ -50,8 +50,9 @@ public class WriteRunningTx extends AbstractWriteTx {
     private static final Logger LOG  = LoggerFactory.getLogger(WriteRunningTx.class);
 
     public WriteRunningTx(final RemoteDeviceId id, final NetconfBaseOps netOps,
-                          final NetconfSessionPreferences netconfSessionPreferences) {
-        super(netOps, id, netconfSessionPreferences);
+                          final NetconfSessionPreferences netconfSessionPreferences,
+                          final long defaultRequestTimeoutMillis) {
+        super(netOps, id, netconfSessionPreferences, defaultRequestTimeoutMillis);
     }
 
     @Override
index 7059a14aa33810eff4511f30da7e2630e6a15330..08c4de64f2d475926e74ea87cfb0e343bdd45371 100644 (file)
@@ -126,6 +126,12 @@ module odl-sal-netconf-connector-cfg {
                 default 20000;
             }
 
+            leaf default-request-timeout-millis {
+                description "Timeout for blocking operations within transactions.";
+                type uint32;
+                default 60000;
+            }
+
             leaf max-connection-attempts {
                 description "Maximum number of connection retries. Non positive value or null is interpreted as infinity.";
                 type uint32;
index 952ef07a3fd4282e467435a3517fbc68a68cf55b..7ac616cdb76fd02c87ad0b942f73df9eff0330a3 100644 (file)
@@ -60,7 +60,7 @@ public class NetconfDeviceWriteOnlyTxTest {
     @Test
     public void testDiscardChanges() {
         final WriteCandidateTx tx = new WriteCandidateTx(id, new NetconfBaseOps(rpc, mock(SchemaContext.class)),
-                NetconfSessionPreferences.fromStrings(Collections.<String>emptySet()));
+                NetconfSessionPreferences.fromStrings(Collections.<String>emptySet()), new Long(60000));
         final CheckedFuture<Void, TransactionCommitFailedException> submitFuture = tx.submit();
         try {
             submitFuture.checkedGet();
@@ -84,7 +84,7 @@ public class NetconfDeviceWriteOnlyTxTest {
                 .when(rpc).invokeRpc(any(SchemaPath.class), any(NormalizedNode.class));
 
         final WriteRunningTx tx = new WriteRunningTx(id, new NetconfBaseOps(rpc, NetconfDevice.INIT_SCHEMA_CTX),
-                NetconfSessionPreferences.fromStrings(Collections.<String>emptySet()));
+                NetconfSessionPreferences.fromStrings(Collections.<String>emptySet()), new Long(60000));
         try {
             tx.delete(LogicalDatastoreType.CONFIGURATION, yangIId);
         } catch (final Exception e) {