Bug 1034 : Statistics request queue cleanup on node disconnection 26/7526/2
authorAnil Vishnoi <avishnoi@in.ibm.com>
Thu, 29 May 2014 20:05:29 +0000 (01:35 +0530)
committerAnil Vishnoi <avishnoi@in.ibm.com>
Tue, 3 Jun 2014 20:32:44 +0000 (02:02 +0530)
MD-SAL Statistics-manager was not removing the statistics request entries from request scheduler queue. So even if
node is getting disconnected, request scheduler was sending the request down to the plugin and plugin was throwing
IllegalArgumentException. With this fix, whenever node get disconnected its respective NodeStatisticsHandler clean up
its pending statistics request from scheduler queue.

Change-Id: Ie70544b11f660531312c29ff89bb868761104282
Signed-off-by: Anil Vishnoi <avishnoi@in.ibm.com>
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/NodeStatisticsHandler.java
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsRequestScheduler.java

index dbcbab9..7d9cc7e 100644 (file)
@@ -313,6 +313,9 @@ public final class NodeStatisticsHandler implements AutoCloseable, FlowCapableCo
         meterStats.close();
         queueStats.close();
 
+        //Clean up queued statistics request from scheduler queue 
+        srScheduler.removeRequestsFromSchedulerQueue(this.getNodeRef());
+
         logger.debug("Statistics handler for {} shut down", targetNodeKey.getId());
     }
 
index 9ebfd6f..bea43ef 100644 (file)
@@ -18,6 +18,7 @@ import java.util.concurrent.TimeUnit;
 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction.DataTransactionListener;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -62,6 +63,19 @@ public class StatisticsRequestScheduler implements DataTransactionListener {
         requestQueue.put(statsRequest, null);
     }
     
+    public void removeRequestsFromSchedulerQueue(NodeRef node){
+        AbstractStatsTracker stats = null;
+        synchronized(requestQueue){
+            Iterator<Map.Entry<AbstractStatsTracker, Integer>> nodesItr = requestQueue.entrySet().iterator();
+            while(nodesItr.hasNext()){
+                stats = nodesItr.next().getKey();
+                if(stats.getNodeRef().equals(node)){
+                    nodesItr.remove();
+                }
+            }
+        }
+
+    }
     public AbstractStatsTracker getNextRequestFromSchedulerQueue(){
         //Remove first element
         AbstractStatsTracker stats = null;
@@ -79,10 +93,7 @@ public class StatisticsRequestScheduler implements DataTransactionListener {
 
     private void requestStatistics(){
         AbstractStatsTracker stats = this.getNextRequestFromSchedulerQueue();
-        if(stats != null) {
-            stats.request();
-            stats.increaseRequestCounter();
-        }
+        sendStatsRequest(stats);
     }
     @Override
     public void onStatusUpdated(DataModificationTransaction transaction, TransactionStatus status) {
@@ -106,12 +117,19 @@ public class StatisticsRequestScheduler implements DataTransactionListener {
                 break;
             }
         }
+        sendStatsRequest(stats);
+    }
+    
+    private void sendStatsRequest(AbstractStatsTracker stats){
         if(stats != null){
-            stats.request();
-            stats.increaseRequestCounter();
+            try{
+                stats.request();
+                stats.increaseRequestCounter();
+            }catch(Exception e){
+                srsLogger.warn("Statistics request was not sent successfully. Reason : {}",e.getMessage());
+            }
         }
     }
-    
     public void start(){
         timer.schedule(task, 0, REQUEST_MONITOR_INTERVAL);
     }