Bug 6304 - Regression in Connection reconciliation functionality 57/42757/1
authorAnil Vishnoi <vishnoianil@gmail.com>
Fri, 29 Jul 2016 04:35:07 +0000 (21:35 -0700)
committerAnil Vishnoi <vishnoianil@gmail.com>
Fri, 29 Jul 2016 04:54:26 +0000 (04:54 +0000)
After enabling the checkstyle, we start catching the
specific exceptions rather then catching all the exception
using Exception. During the retry, connection task encounters
ConnectionException, but nobody catches that exception and
it kills the reconciliation thread, so it does not retry
the connection after first attempt. This patch fixes this
issue and handles the ConnectionException properly.

Change-Id: I0e1f71ea6fa550df484ade9036f7dfe6c9dfa57e
Signed-off-by: Anil Vishnoi <vishnoianil@gmail.com>
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionManager.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepDataChangeListener.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/reconciliation/connection/ConnectionReconciliationTask.java
library/impl/src/main/java/org/opendaylight/ovsdb/lib/impl/OvsdbConnectionService.java
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionManager.java
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbDataTreeChangeListener.java
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/reconciliation/connection/ConnectionReconciliationTask.java

index 98a6661381781531e7ba7a3f0d4890ffdb8ab5e3..471a67f9d00da6875f173f34a5d613ff7daf5ac0 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.ovsdb.hwvtepsouthbound;
 
 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
 
+import java.net.ConnectException;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
@@ -158,7 +159,8 @@ public class HwvtepConnectionManager implements OvsdbConnectionListener, AutoClo
         LOG.trace("HwvtepConnectionManager exit disconnected client: {}", client);
     }
 
-    public OvsdbClient connect(InstanceIdentifier<Node> iid, HwvtepGlobalAugmentation hwvtepGlobal) throws UnknownHostException {
+    public OvsdbClient connect(InstanceIdentifier<Node> iid,
+                               HwvtepGlobalAugmentation hwvtepGlobal) throws UnknownHostException, ConnectException {
         LOG.info("Connecting to {}", HwvtepSouthboundUtil.connectionInfoToString(hwvtepGlobal.getConnectionInfo()));
         InetAddress ip = HwvtepSouthboundMapper.createInetAddress(hwvtepGlobal.getConnectionInfo().getRemoteIp());
         OvsdbClient client = OvsdbConnectionService.getService()
index ce6d6150697fd24dc13bbfb7186d9c8ad24aa43e..5cca754d4b009ab573164316b20c812ae5e8c2a5 100644 (file)
@@ -8,6 +8,7 @@
 
 package org.opendaylight.ovsdb.hwvtepsouthbound;
 
+import java.net.ConnectException;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -134,7 +135,7 @@ public class HwvtepDataChangeListener implements ClusteredDataTreeChangeListener
                     } else {
                         try {
                             OvsdbClient client = hcm.connect(key, hwvtepGlobal);
-                        } catch (UnknownHostException e) {
+                        } catch (UnknownHostException | ConnectException e) {
                             LOG.warn("Failed to connect to HWVTEP node", e);
                         }
                     }
@@ -164,7 +165,7 @@ public class HwvtepDataChangeListener implements ClusteredDataTreeChangeListener
                             if (newClient == null) {
                                 hcm.reconcileConnection(key, hgUpdated);
                             }
-                        } catch (UnknownHostException e) {
+                        } catch (UnknownHostException | ConnectException e) {
                             LOG.warn("Failed to update connection on HWVTEP Node", e);
                         }
                     }
index ce02e8e48abb797a8ed45997ff04cdfeecdf8a94..476765ffe4e4cca191f2450054c74967ee0d3f2c 100644 (file)
@@ -18,6 +18,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.net.ConnectException;
 import java.net.UnknownHostException;
 import java.util.concurrent.atomic.AtomicInteger;
 
@@ -59,7 +60,7 @@ public class ConnectionReconciliationTask extends ReconciliationTask {
                 LOG.warn("Connection retry({}) failed for {}.",
                         connectionAttempt.get(), hwvtepNode.getConnectionInfo());
             }
-        } catch (UnknownHostException e) {
+        } catch (UnknownHostException | ConnectException e) {
             LOG.warn("Connection retry({}) failed with exception. ",connectionAttempt.get(), e);
         }
         return result;
index fc7aacf296949aed72ce6578c91ea94c9d0cf53b..0b032e5df61286d949cb8e455064e2e67240bbb8 100644 (file)
@@ -195,6 +195,7 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
 
         OvsdbRPC rpc = factory.getClient(channel, OvsdbRPC.class);
         OvsdbClientImpl client = new OvsdbClientImpl(rpc, channel, type, socketConnType);
+        client.setConnectionPublished(true);
         connections.put(client, channel);
         ChannelFuture closeFuture = channel.closeFuture();
         closeFuture.addListener(new ChannelConnectionHandler(client));
index 73f0004939c223fde1c867a081da21ee427f8a86..3a5067c7237ded66f2fd813b8c8bb77e3ee06133 100644 (file)
@@ -14,6 +14,8 @@ import com.google.common.base.Preconditions;
 import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
+
+import java.net.ConnectException;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
@@ -186,7 +188,7 @@ public class OvsdbConnectionManager implements OvsdbConnectionListener, AutoClos
     }
 
     public OvsdbClient connect(InstanceIdentifier<Node> iid,
-            OvsdbNodeAugmentation ovsdbNode) throws UnknownHostException {
+            OvsdbNodeAugmentation ovsdbNode) throws UnknownHostException, ConnectException {
         LOG.info("Connecting to {}", SouthboundUtil.connectionInfoToString(ovsdbNode.getConnectionInfo()));
 
         // TODO handle case where we already have a connection
index 1acd7bed8166579a3e2f9a48f03e74be05d04f01..df93e4aac948d0c45306be42b69bef5a67eb0592 100644 (file)
@@ -8,6 +8,7 @@
 
 package org.opendaylight.ovsdb.southbound;
 
+import java.net.ConnectException;
 import java.net.UnknownHostException;
 import java.util.Collection;
 import java.util.HashMap;
@@ -118,7 +119,7 @@ public class OvsdbDataTreeChangeListener implements ClusteredDataTreeChangeListe
                             InstanceIdentifier<Node> instanceIdentifier = change.getRootPath().getRootIdentifier();
                             cm.connect(instanceIdentifier, ovsdbNode);
                             LOG.info("OVSDB node has been connected: {}",ovsdbNode);
-                        } catch (UnknownHostException e) {
+                        } catch (UnknownHostException | ConnectException e) {
                             LOG.warn("Failed to connect to ovsdbNode", e);
                         }
                     }
@@ -164,7 +165,7 @@ public class OvsdbDataTreeChangeListener implements ClusteredDataTreeChangeListe
                                 cm.disconnect(ovsdbNodeModification.getDataBefore());
                                 cm.connect(change.getRootPath().getRootIdentifier(), ovsdbNodeModification
                                         .getDataAfter());
-                            } catch (UnknownHostException e) {
+                            } catch (UnknownHostException | ConnectException e) {
                                 LOG.warn("Error disconnecting from or connecting to ovsdbNode", e);
                             }
                         }
index 7e844f79b81b10a95e1bf4791d60ee8c6fb1b009..942e2e0cbefbdd9d81c631d51c114b65c4d458a2 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.ovsdb.southbound.reconciliation.connection;
 
+import java.net.ConnectException;
 import java.net.UnknownHostException;
 import java.util.concurrent.atomic.AtomicInteger;
 import org.opendaylight.ovsdb.lib.OvsdbClient;
@@ -53,7 +54,7 @@ public class ConnectionReconciliationTask extends ReconciliationTask {
                 LOG.warn("Connection retry({}) failed for {}.",
                         connectionAttempt.get(), ovsdbNode.getConnectionInfo());
             }
-        } catch (UnknownHostException e) {
+        } catch (UnknownHostException | ConnectException e) {
             LOG.warn("Connection retry({}) failed with exception. ",connectionAttempt.get(), e);
         }
         return result;