Merge changes I6575ddd8,I4b78f51d,I0a0441e6
authorJakub Morvay <jmorvay@cisco.com>
Thu, 20 Jul 2017 15:31:38 +0000 (15:31 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 20 Jul 2017 15:31:38 +0000 (15:31 +0000)
* changes:
  Cleanup Precondtions in singleton
  Cleanup Throwable catches
  Cleanup NetconfDevice

netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/ProxyDOMDataBroker.java
netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/actors/NetconfNodeActor.java
netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/actors/ReadWriteTransactionActorTest.java
netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/actors/WriteTransactionActorTest.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NetconfDevice.java

index 893782feb729d2e1827b1cb8297042c74ae4433a..761b62a7909743dee60d3f2ae133162eae4e4225 100644 (file)
@@ -12,7 +12,7 @@ import akka.actor.ActorRef;
 import akka.actor.ActorSystem;
 import akka.pattern.Patterns;
 import akka.util.Timeout;
-import com.google.common.base.Preconditions;
+import com.google.common.base.Verify;
 import java.util.Collections;
 import java.util.Map;
 import javax.annotation.Nonnull;
@@ -67,51 +67,60 @@ public class ProxyDOMDataBroker implements DOMDataBroker {
     @Override
     public DOMDataReadOnlyTransaction newReadOnlyTransaction() {
         final Future<Object> txActorFuture = Patterns.ask(masterNode, new NewReadTransactionRequest(), askTimeout);
+        final Object msg;
         try {
-            final Object msg = Await.result(txActorFuture, askTimeout.duration());
-            if (msg instanceof Throwable) {
-                throw (Throwable) msg;
-            }
-            Preconditions.checkState(msg instanceof NewReadTransactionReply);
-            final NewReadTransactionReply reply = (NewReadTransactionReply) msg;
-            return new ProxyReadTransaction(reply.getTxActor(), id, actorSystem, askTimeout);
-        } catch (final Throwable t) {
-            throw new IllegalStateException("Can't create ProxyReadTransaction", t);
+            msg = Await.result(txActorFuture, askTimeout.duration());
+        } catch (Exception e) {
+            throw new IllegalStateException("Can't create ProxyReadTransaction", e);
         }
+
+        if (msg instanceof Exception) {
+            throw new IllegalStateException("Can't create ProxyReadTransaction", (Exception) msg);
+        }
+
+        Verify.verify(msg instanceof NewReadTransactionReply);
+        final NewReadTransactionReply reply = (NewReadTransactionReply) msg;
+        return new ProxyReadTransaction(reply.getTxActor(), id, actorSystem, askTimeout);
     }
 
     @SuppressWarnings("checkstyle:IllegalCatch")
     @Override
     public DOMDataReadWriteTransaction newReadWriteTransaction() {
         final Future<Object> txActorFuture = Patterns.ask(masterNode, new NewReadWriteTransactionRequest(), askTimeout);
+        final Object msg;
         try {
-            final Object msg = Await.result(txActorFuture, askTimeout.duration());
-            if (msg instanceof Throwable) {
-                throw (Throwable) msg;
-            }
-            Preconditions.checkState(msg instanceof NewReadWriteTransactionReply);
-            final NewReadWriteTransactionReply reply = (NewReadWriteTransactionReply) msg;
-            return new ProxyReadWriteTransaction(reply.getTxActor(), id, actorSystem, askTimeout);
-        } catch (final Throwable t) {
-            throw new IllegalStateException("Can't create ProxyReadTransaction", t);
+            msg = Await.result(txActorFuture, askTimeout.duration());
+        } catch (Exception e) {
+            throw new IllegalStateException("Can't create ProxyReadWriteTransaction", e);
+        }
+
+        if (msg instanceof Exception) {
+            throw new IllegalStateException("Can't create ProxyReadWriteTransaction", (Exception) msg);
         }
+
+        Verify.verify(msg instanceof NewReadWriteTransactionReply);
+        final NewReadWriteTransactionReply reply = (NewReadWriteTransactionReply) msg;
+        return new ProxyReadWriteTransaction(reply.getTxActor(), id, actorSystem, askTimeout);
     }
 
     @SuppressWarnings("checkstyle:IllegalCatch")
     @Override
     public DOMDataWriteTransaction newWriteOnlyTransaction() {
         final Future<Object> txActorFuture = Patterns.ask(masterNode, new NewWriteTransactionRequest(), askTimeout);
+        final Object msg;
         try {
-            final Object msg = Await.result(txActorFuture, askTimeout.duration());
-            if (msg instanceof Throwable) {
-                throw (Throwable) msg;
-            }
-            Preconditions.checkState(msg instanceof NewWriteTransactionReply);
-            final NewWriteTransactionReply reply = (NewWriteTransactionReply) msg;
-            return new ProxyWriteTransaction(reply.getTxActor(), id, actorSystem, askTimeout);
-        } catch (final Throwable t) {
-            throw new IllegalStateException("Can't create ProxyWriteTransaction", t);
+            msg = Await.result(txActorFuture, askTimeout.duration());
+        } catch (Exception e) {
+            throw new IllegalStateException("Can't create ProxyWriteTransaction", e);
+        }
+
+        if (msg instanceof Exception) {
+            throw new IllegalStateException("Can't create ProxyWriteTransaction", (Exception) msg);
         }
+
+        Verify.verify(msg instanceof NewWriteTransactionReply);
+        final NewWriteTransactionReply reply = (NewWriteTransactionReply) msg;
+        return new ProxyWriteTransaction(reply.getTxActor(), id, actorSystem, askTimeout);
     }
 
     @Override
index 20ddde3db396e3c3e9e0b18f1d5a67c553db41de..6d1e7717168bdf1780c42400909566ba1d04281e 100644 (file)
@@ -153,7 +153,7 @@ public class NetconfNodeActor extends UntypedActor {
                 final DOMDataWriteTransaction tx = deviceDataBroker.newWriteOnlyTransaction();
                 final ActorRef txActor = context().actorOf(WriteTransactionActor.props(tx, writeTxIdleTimeout));
                 sender().tell(new NewWriteTransactionReply(txActor), self());
-            } catch (final Throwable t) {
+            } catch (final Exception t) {
                 sender().tell(t, self());
             }
 
@@ -162,7 +162,7 @@ public class NetconfNodeActor extends UntypedActor {
                 final DOMDataReadWriteTransaction tx = deviceDataBroker.newReadWriteTransaction();
                 final ActorRef txActor = context().actorOf(ReadWriteTransactionActor.props(tx, writeTxIdleTimeout));
                 sender().tell(new NewReadWriteTransactionReply(txActor), self());
-            } catch (final Throwable t) {
+            } catch (final Exception t) {
                 sender().tell(t, self());
             }
         } else if (message instanceof InvokeRpcMessage) { // master
index 08b755ef987d94176c60e4e4c30fa39c915b7f63..e02f1f8dc72a6bce4fbfe9230988ae01221ce52f 100644 (file)
@@ -19,7 +19,6 @@ import akka.testkit.TestActorRef;
 import akka.testkit.TestProbe;
 import akka.util.Timeout;
 import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
 import com.google.common.util.concurrent.Futures;
 import java.util.concurrent.TimeUnit;
 import org.junit.After;
@@ -153,7 +152,7 @@ public class ReadWriteTransactionActorTest {
         when(deviceReadWriteTx.cancel()).thenReturn(true);
         final Future<Object> cancelFuture = Patterns.ask(actorRef, new CancelRequest(), TIMEOUT);
         final Object result = Await.result(cancelFuture, TIMEOUT.duration());
-        Preconditions.checkState(result instanceof Boolean);
+        Assert.assertTrue(result instanceof Boolean);
         verify(deviceReadWriteTx).cancel();
         Assert.assertTrue((Boolean) result);
     }
index 158ee468ba2ef37bd4236d3e8b60e653865c1ab8..4e7fc3537b5e006a837026aa11355106b17af587 100644 (file)
@@ -18,7 +18,6 @@ import akka.testkit.JavaTestKit;
 import akka.testkit.TestActorRef;
 import akka.testkit.TestProbe;
 import akka.util.Timeout;
-import com.google.common.base.Preconditions;
 import com.google.common.util.concurrent.Futures;
 import java.util.concurrent.TimeUnit;
 import org.junit.After;
@@ -101,7 +100,7 @@ public class WriteTransactionActorTest {
         when(deviceWriteTx.cancel()).thenReturn(true);
         final Future<Object> cancelFuture = Patterns.ask(actorRef, new CancelRequest(), TIMEOUT);
         final Object result = Await.result(cancelFuture, TIMEOUT.duration());
-        Preconditions.checkState(result instanceof Boolean);
+        Assert.assertTrue(result instanceof Boolean);
         verify(deviceWriteTx).cancel();
         Assert.assertTrue((Boolean) result);
     }
index 6452cfae415b093dbbf8ffac59e7549cbfae42da..b78011460e4e81f4544c79863184e7f7089ea429 100644 (file)
@@ -500,32 +500,26 @@ public class NetconfDevice
 
                     capabilities.addNonModuleBasedCapabilities(remoteSessionCapabilities
                             .getNonModuleCaps().stream().map(entry -> new AvailableCapabilityBuilder()
-                            .setCapability(entry).setCapabilityOrigin(
+                                    .setCapability(entry).setCapabilityOrigin(
                                             remoteSessionCapabilities.getNonModuleBasedCapsOrigin().get(entry)).build())
                             .collect(Collectors.toList()));
 
                     handleSalInitializationSuccess(result, remoteSessionCapabilities, getDeviceSpecificRpc(result));
                     return;
-                } catch (final Throwable t) {
-                    if (t instanceof MissingSchemaSourceException) {
-                        requiredSources =
-                                handleMissingSchemaSourceException(requiredSources, (MissingSchemaSourceException) t);
-                    } else if (t instanceof SchemaResolutionException) {
-                        // schemaBuilderFuture.checkedGet() throws only SchemaResolutionException
-                        // that might be wrapping a MissingSchemaSourceException so we need to look
-                        // at the cause of the exception to make sure we don't misinterpret it.
-                        if (t.getCause() instanceof MissingSchemaSourceException) {
-                            requiredSources = handleMissingSchemaSourceException(
-                                    requiredSources, (MissingSchemaSourceException) t.getCause());
-                            continue;
-                        }
-                        requiredSources =
-                                handleSchemaResolutionException(requiredSources, (SchemaResolutionException) t);
-                    } else {
-                        // unknown error, fail
-                        handleSalInitializationFailure(t, listener);
-                        return;
+                } catch (final SchemaResolutionException e) {
+                    // schemaBuilderFuture.checkedGet() throws only SchemaResolutionException
+                    // that might be wrapping a MissingSchemaSourceException so we need to look
+                    // at the cause of the exception to make sure we don't misinterpret it.
+                    if (e.getCause() instanceof MissingSchemaSourceException) {
+                        requiredSources = handleMissingSchemaSourceException(
+                                requiredSources, (MissingSchemaSourceException) e.getCause());
+                        continue;
                     }
+                    requiredSources = handleSchemaResolutionException(requiredSources, e);
+                } catch (final Exception e) {
+                    // unknown error, fail
+                    handleSalInitializationFailure(e, listener);
+                    return;
                 }
             }
             // No more sources, fail