Bug 6589 Logging exception 11/49011/1
authorAkash <a.k.sahu@ericsson.com>
Tue, 6 Dec 2016 06:49:36 +0000 (12:19 +0530)
committerAkash <a.k.sahu@ericsson.com>
Tue, 6 Dec 2016 06:49:36 +0000 (12:19 +0530)
Made changes to log exception submitted to job scheduler

Change-Id: I7988b5dda55d2e192e7a6ee8213f1ce293c02b04
Signed-off-by: Akash <a.k.sahu@ericsson.com>
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/handlers/NodeConnectedHandler.java
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/listeners/HAJobScheduler.java
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/listeners/HAOpNodeListener.java

index 40f36d87316302e03cfa677d88ca9fd1e0935cb0..afaef38865c192ed0be12f4b6bc6ccd69f8b676a 100644 (file)
@@ -14,7 +14,6 @@ import com.google.common.base.Optional;
 import com.google.common.collect.Sets;
 import java.util.List;
 import java.util.Set;
-import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
 
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
@@ -94,17 +93,19 @@ public class NodeConnectedHandler {
                  as it is expecting the logical switch to be already present in operational ds
                  (created in the device )
                  */
-                HAJobScheduler.getInstance().submitJob(new Callable<Void>() {
-                    @Override
-                    public Void call() throws InterruptedException, ExecutionException, ReadFailedException,
-                            TransactionCommitFailedException {
-                        hwvtepHACache.updateConnectedNodeStatus(childNodePath);
-                        LOG.info("HA child reconnected handleNodeReConnected {}",
-                                childNode.getNodeId().getValue());
-                        ReadWriteTransaction tx = db.newReadWriteTransaction();
-                        copyHAPSConfigToChildPS(haPSCfg.get(), childNodePath, tx);
-                        tx.submit().checkedGet();
-                        return null;
+                HAJobScheduler.getInstance().submitJob(new Runnable() {
+                    public void run() {
+                        try {
+                            hwvtepHACache.updateConnectedNodeStatus(childNodePath);
+                            LOG.info("HA child reconnected handleNodeReConnected {}",
+                                    childNode.getNodeId().getValue());
+                            ReadWriteTransaction tx = db.newReadWriteTransaction();
+                            copyHAPSConfigToChildPS(haPSCfg.get(), childNodePath, tx);
+                            tx.submit().checkedGet();
+                        } catch (InterruptedException | ExecutionException | ReadFailedException
+                                | TransactionCommitFailedException e) {
+                            LOG.error("Failed to process ", e);
+                        }
                     }
                 });
 
index 4d2691b5685a5d9e74e947fd70ecfa7d659e1183..0d816a4265d3823cf295e8376c48c633752ca2b1 100644 (file)
@@ -9,22 +9,23 @@ package org.opendaylight.netvirt.elan.l2gw.ha.listeners;
 
 import com.google.common.util.concurrent.ThreadFactoryBuilder;
 
-import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
 import java.util.concurrent.ThreadFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
-public class HAJobScheduler {
+public class HAJobScheduler implements Thread.UncaughtExceptionHandler {
 
+    private static final Logger LOG = LoggerFactory.getLogger(HAOpClusteredListener.class);
     ExecutorService executorService;
 
     static HAJobScheduler instance = new HAJobScheduler();
 
     private HAJobScheduler() {
         ThreadFactory threadFact = new ThreadFactoryBuilder()
-                    .setNameFormat("hwvtep-ha-task-%d").build();
+                .setNameFormat("hwvtep-ha-task-%d").setUncaughtExceptionHandler(this).build();
         executorService = Executors.newSingleThreadScheduledExecutor(threadFact);
     }
 
@@ -36,11 +37,12 @@ public class HAJobScheduler {
         executorService = service;
     }
 
-    public Future<Void> submitJob(Callable<Void> callable) {
-        return executorService.submit(callable);
+    public void submitJob(Runnable runnable) {
+        executorService.execute(runnable);
     }
 
-    public void submitJob(Runnable runnable) {
-        executorService.submit(runnable);
+    @Override
+    public void uncaughtException(Thread thread, Throwable throwable) {
+        LOG.error("Failed to execute task", throwable);
     }
 }
index c6c5b055d34487963bba7c00540e6327340d7118..b92ebcbdba33061bc422fb4ab5dc80f4c361cfee 100644 (file)
@@ -19,7 +19,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
@@ -253,15 +252,17 @@ public class HAOpNodeListener extends HwvtepNodeBaseListener implements DataTree
     void handleNodeConnected(final InstanceIdentifier<Node> childPath,
                              final Node childNode,
                              final InstanceIdentifier<Node> haNodePath) {
-        HAJobScheduler.getInstance().submitJob(new Callable<Void>() {
-            @Override
-            public Void call() throws InterruptedException, ExecutionException, ReadFailedException,
-                    TransactionCommitFailedException {
-                LOG.info("Ha child connected handleNodeConnected {}", childNode.getNodeId().getValue());
-                ReadWriteTransaction tx = getTx();
-                haEventHandler.handleChildNodeConnected(childNode, childPath, haNodePath, tx);
-                tx.submit().checkedGet();
-                return null;
+        HAJobScheduler.getInstance().submitJob(new Runnable() {
+            public void run() {
+                try {
+                    LOG.info("Ha child connected handleNodeConnected {}", childNode.getNodeId().getValue());
+                    ReadWriteTransaction tx = getTx();
+                    haEventHandler.handleChildNodeConnected(childNode, childPath, haNodePath, tx);
+                    tx.submit().checkedGet();
+                } catch (InterruptedException | ExecutionException | ReadFailedException
+                        | TransactionCommitFailedException e) {
+                    LOG.error("Failed to process ", e);
+                }
             }
         });
     }
@@ -271,16 +272,18 @@ public class HAOpNodeListener extends HwvtepNodeBaseListener implements DataTree
                                final InstanceIdentifier<Node> haNodePath,
                                final Optional<Node> haGlobalCfg,
                                final Optional<Node> haPSCfg) {
-        HAJobScheduler.getInstance().submitJob(new Callable<Void>() {
-            @Override
-            public Void call() throws InterruptedException, ExecutionException, ReadFailedException,
-                    TransactionCommitFailedException {
-                LOG.info("Ha child reconnected handleNodeReConnected {}", childNode.getNodeId().getValue());
-                ReadWriteTransaction tx = getTx();
-                haEventHandler.handleChildNodeReConnected(childNode, childPath,
-                        haNodePath, haGlobalCfg, haPSCfg, tx);
-                tx.submit().checkedGet();
-                return null;
+        HAJobScheduler.getInstance().submitJob(new Runnable() {
+            public void run() {
+                try {
+                    LOG.info("Ha child reconnected handleNodeReConnected {}", childNode.getNodeId().getValue());
+                    ReadWriteTransaction tx = getTx();
+                    haEventHandler.handleChildNodeReConnected(childNode, childPath,
+                            haNodePath, haGlobalCfg, haPSCfg, tx);
+                    tx.submit().checkedGet();
+                } catch (InterruptedException | ExecutionException | ReadFailedException
+                        | TransactionCommitFailedException e) {
+                    LOG.error("Failed to process ", e);
+                }
             }
         });
     }