Rename NodeStatisticsAger and StatisticsUpdateCommiter 77/5277/2
authorRobert Varga <rovarga@cisco.com>
Wed, 12 Feb 2014 02:16:40 +0000 (03:16 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 13 Feb 2014 05:14:12 +0000 (05:14 +0000)
The component's responsibilities have changed, rename them to reflect
this change. The new division of responsibilities is:

There is a single StatisticsListener listens for notifications
carrying the statistics data and routes them towards the appropriate
NodeStatisticsHandler. Once MD-SAL is able to route notifications based
on key, this class should be completely removed.

There are per-node NodeStatisticsHandlers, each of which is responsible
for taking care of lifecycle of statistics for a particular node.

Change-Id: I16d7a1f353a1f484db11da1e5edc97b4778dad3c
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/NodeStatisticsHandler.java [moved from opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/NodeStatisticsAger.java with 98% similarity]
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsListener.java [moved from opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsUpdateCommiter.java with 73% similarity]
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsProvider.java
opendaylight/md-sal/statistics-manager/src/test/java/org/opendaylight/controller/md/statistics/manager/StatisticsUpdateCommiterTest.java

@@ -97,13 +97,14 @@ import org.slf4j.LoggerFactory;
 import com.google.common.base.Preconditions;
 
 /**
- * Main responsibility of this class to clean up all the stale statistics data
- * associated to Flow,Meter,Group,Queue.
- * @author avishnoi@in.ibm.com
+ * This class handles the lifecycle of per-node statistics. It receives data
+ * from StatisticsListener, stores it in the data store and keeps track of
+ * when the data should be removed.
  *
+ * @author avishnoi@in.ibm.com
  */
-public class NodeStatisticsAger {
-    private static final Logger logger = LoggerFactory.getLogger(NodeStatisticsAger.class);
+public class NodeStatisticsHandler {
+    private static final Logger logger = LoggerFactory.getLogger(NodeStatisticsHandler.class);
     private static final int NUMBER_OF_WAIT_CYCLES = 2;
 
     private final Map<GroupDescStats,Long> groupDescStatsUpdate = new HashMap<>();
@@ -115,7 +116,7 @@ public class NodeStatisticsAger {
     private final NodeKey targetNodeKey;
     private int unaccountedFlowsCounter = 1;
 
-    public NodeStatisticsAger(StatisticsProvider statisticsProvider, NodeKey nodeKey){
+    public NodeStatisticsHandler(StatisticsProvider statisticsProvider, NodeKey nodeKey){
         this.statisticsProvider = Preconditions.checkNotNull(statisticsProvider);
         this.targetNodeKey = Preconditions.checkNotNull(nodeKey);
         this.targetNodeIdentifier = InstanceIdentifier.builder(Nodes.class).child(Node.class, targetNodeKey).build();
@@ -172,8 +173,8 @@ public class NodeStatisticsAger {
             return true;
         }
 
-        private NodeStatisticsAger getOuterType() {
-            return NodeStatisticsAger.this;
+        private NodeStatisticsHandler getOuterType() {
+            return NodeStatisticsHandler.this;
         }
     }
 
@@ -28,21 +28,21 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Class implement statistics manager related listener interface and augment all the
- * received statistics data to data stores.
+ * This class is responsible for listening for statistics update notifications and
+ * routing them to the appropriate NodeStatisticsHandler.
+
  * TODO: Need to add error message listener and clean-up the associated tx id
  * if it exists in the tx-id cache.
  * @author vishnoianil
- *
  */
-public class StatisticsUpdateCommiter implements OpendaylightGroupStatisticsListener,
+public class StatisticsListener implements OpendaylightGroupStatisticsListener,
         OpendaylightMeterStatisticsListener,
         OpendaylightFlowStatisticsListener,
         OpendaylightPortStatisticsListener,
         OpendaylightFlowTableStatisticsListener,
         OpendaylightQueueStatisticsListener{
 
-    private final static Logger sucLogger = LoggerFactory.getLogger(StatisticsUpdateCommiter.class);
+    private final static Logger sucLogger = LoggerFactory.getLogger(StatisticsListener.class);
     private final StatisticsProvider statisticsManager;
     private final MultipartMessageManager messageManager;
 
@@ -50,7 +50,7 @@ public class StatisticsUpdateCommiter implements OpendaylightGroupStatisticsList
      * default ctor
      * @param manager
      */
-    public StatisticsUpdateCommiter(final StatisticsProvider manager){
+    public StatisticsListener(final StatisticsProvider manager){
         this.statisticsManager = manager;
         this.messageManager = this.statisticsManager.getMultipartMessageManager();
     }
@@ -62,9 +62,9 @@ public class StatisticsUpdateCommiter implements OpendaylightGroupStatisticsList
             return;
 
         //Add statistics to local cache
-        final NodeStatisticsAger sna = this.statisticsManager.getStatisticsHandler(notification.getId());
-        if (sna != null) {
-            sna.updateMeterConfigStats(notification.getMeterConfigStats());
+        final NodeStatisticsHandler handler = this.statisticsManager.getStatisticsHandler(notification.getId());
+        if (handler != null) {
+            handler.updateMeterConfigStats(notification.getMeterConfigStats());
         }
     }
 
@@ -75,9 +75,9 @@ public class StatisticsUpdateCommiter implements OpendaylightGroupStatisticsList
             return;
 
         //Add statistics to local cache
-        final NodeStatisticsAger nsa = this.statisticsManager.getStatisticsHandler(notification.getId());
-        if (nsa != null) {
-            nsa.updateMeterStats(notification.getMeterStats());
+        final NodeStatisticsHandler handler = this.statisticsManager.getStatisticsHandler(notification.getId());
+        if (handler != null) {
+            handler.updateMeterStats(notification.getMeterStats());
         }
     }
 
@@ -87,9 +87,9 @@ public class StatisticsUpdateCommiter implements OpendaylightGroupStatisticsList
         if(!messageManager.isRequestTxIdExist(notification.getId(),notification.getTransactionId(),notification.isMoreReplies()))
             return;
 
-        final NodeStatisticsAger nsa = statisticsManager.getStatisticsHandler(notification.getId());
-        if (nsa != null) {
-            nsa.updateGroupDescStats(notification.getGroupDescStats());
+        final NodeStatisticsHandler handler = statisticsManager.getStatisticsHandler(notification.getId());
+        if (handler != null) {
+            handler.updateGroupDescStats(notification.getGroupDescStats());
         }
     }
 
@@ -99,15 +99,15 @@ public class StatisticsUpdateCommiter implements OpendaylightGroupStatisticsList
         if(!messageManager.isRequestTxIdExist(notification.getId(),notification.getTransactionId(),notification.isMoreReplies()))
             return;
 
-        final NodeStatisticsAger nsa = statisticsManager.getStatisticsHandler(notification.getId());
-        if (nsa != null) {
-            nsa.updateGroupStats(notification.getGroupStats());
+        final NodeStatisticsHandler handler = statisticsManager.getStatisticsHandler(notification.getId());
+        if (handler != null) {
+            handler.updateGroupStats(notification.getGroupStats());
         }
     }
 
     @Override
     public void onMeterFeaturesUpdated(MeterFeaturesUpdated notification) {
-        final NodeStatisticsAger sna = this.statisticsManager.getStatisticsHandler(notification.getId());
+        final NodeStatisticsHandler sna = this.statisticsManager.getStatisticsHandler(notification.getId());
         if (sna != null) {
             sna.updateMeterFeatures(notification);
         }
@@ -115,7 +115,7 @@ public class StatisticsUpdateCommiter implements OpendaylightGroupStatisticsList
 
     @Override
     public void onGroupFeaturesUpdated(GroupFeaturesUpdated notification) {
-        final NodeStatisticsAger sna = this.statisticsManager.getStatisticsHandler(notification.getId());
+        final NodeStatisticsHandler sna = this.statisticsManager.getStatisticsHandler(notification.getId());
         if (sna != null) {
             sna.updateGroupFeatures(notification);
         }
@@ -128,7 +128,7 @@ public class StatisticsUpdateCommiter implements OpendaylightGroupStatisticsList
             return;
 
         sucLogger.debug("Received flow stats update : {}",notification.toString());
-        final NodeStatisticsAger sna = this.statisticsManager.getStatisticsHandler(notification.getId());
+        final NodeStatisticsHandler sna = this.statisticsManager.getStatisticsHandler(notification.getId());
         if (sna != null) {
             sna.updateFlowStats(notification.getFlowAndStatisticsMapList());
         }
@@ -140,10 +140,10 @@ public class StatisticsUpdateCommiter implements OpendaylightGroupStatisticsList
         if(!messageManager.isRequestTxIdExist(notification.getId(),notification.getTransactionId(),notification.isMoreReplies()))
             return;
 
-        final NodeStatisticsAger nsa = this.statisticsManager.getStatisticsHandler(notification.getId());
-        if (nsa != null) {
+        final NodeStatisticsHandler handler = this.statisticsManager.getStatisticsHandler(notification.getId());
+        if (handler != null) {
             final Short tableId = messageManager.getTableIdForTxId(notification.getId(),notification.getTransactionId());
-            nsa.updateAggregateFlowStats(tableId, notification);
+            handler.updateAggregateFlowStats(tableId, notification);
         }
     }
 
@@ -153,9 +153,9 @@ public class StatisticsUpdateCommiter implements OpendaylightGroupStatisticsList
         if(!messageManager.isRequestTxIdExist(notification.getId(),notification.getTransactionId(),notification.isMoreReplies()))
             return;
 
-        final NodeStatisticsAger nsa = this.statisticsManager.getStatisticsHandler(notification.getId());
-        if (nsa != null) {
-            nsa.updateNodeConnectorStats(notification.getNodeConnectorStatisticsAndPortNumberMap());
+        final NodeStatisticsHandler handler = this.statisticsManager.getStatisticsHandler(notification.getId());
+        if (handler != null) {
+            handler.updateNodeConnectorStats(notification.getNodeConnectorStatisticsAndPortNumberMap());
         }
     }
 
@@ -165,9 +165,9 @@ public class StatisticsUpdateCommiter implements OpendaylightGroupStatisticsList
         if(!messageManager.isRequestTxIdExist(notification.getId(),notification.getTransactionId(),notification.isMoreReplies()))
             return;
 
-        final NodeStatisticsAger nsa = this.statisticsManager.getStatisticsHandler(notification.getId());
-        if (nsa != null) {
-            nsa.updateFlowTableStats(notification.getFlowTableAndStatisticsMap());
+        final NodeStatisticsHandler handler = this.statisticsManager.getStatisticsHandler(notification.getId());
+        if (handler != null) {
+            handler.updateFlowTableStats(notification.getFlowTableAndStatisticsMap());
         }
     }
 
@@ -178,9 +178,9 @@ public class StatisticsUpdateCommiter implements OpendaylightGroupStatisticsList
             return;
 
         //Add statistics to local cache
-        final NodeStatisticsAger nsa = this.statisticsManager.getStatisticsHandler(notification.getId());
-        if (nsa != null) {
-            nsa.updateQueueStats(notification.getQueueIdAndStatisticsMap());
+        final NodeStatisticsHandler handler = this.statisticsManager.getStatisticsHandler(notification.getId());
+        if (handler != null) {
+            handler.updateQueueStats(notification.getQueueIdAndStatisticsMap());
         }
     }
 }
index 1269c1c..ab5d20a 100644 (file)
@@ -96,7 +96,7 @@ public class StatisticsProvider implements AutoCloseable {
     private final DataProviderService dps;
 
     //Local caching of stats
-    private final ConcurrentMap<NodeId,NodeStatisticsAger> statisticsCache = new ConcurrentHashMap<>();
+    private final ConcurrentMap<NodeId,NodeStatisticsHandler> statisticsCache = new ConcurrentHashMap<>();
 
     private OpendaylightGroupStatisticsService groupStatsService;
 
@@ -125,7 +125,7 @@ public class StatisticsProvider implements AutoCloseable {
         return multipartMessageManager;
     }
 
-    private final StatisticsUpdateCommiter updateCommiter = new StatisticsUpdateCommiter(StatisticsProvider.this);
+    private final StatisticsListener updateCommiter = new StatisticsListener(StatisticsProvider.this);
 
     private Registration<NotificationListener> listenerRegistration;
 
@@ -170,7 +170,7 @@ public class StatisticsProvider implements AutoCloseable {
             public void run() {
                 while(true){
                     try {
-                        for(NodeStatisticsAger nodeStatisticsAger : statisticsCache.values()){
+                        for(NodeStatisticsHandler nodeStatisticsAger : statisticsCache.values()){
                             nodeStatisticsAger.cleanStaleStatistics();
                         }
                         multipartMessageManager.cleanStaleTransactionIds();
@@ -455,11 +455,11 @@ public class StatisticsProvider implements AutoCloseable {
      * @return Node statistics handler for that node. Null if the statistics should
      *         not handled.
      */
-    public final NodeStatisticsAger getStatisticsHandler(final NodeId nodeId) {
+    public final NodeStatisticsHandler getStatisticsHandler(final NodeId nodeId) {
         Preconditions.checkNotNull(nodeId);
-        NodeStatisticsAger ager = statisticsCache.get(nodeId);
+        NodeStatisticsHandler ager = statisticsCache.get(nodeId);
         if (ager == null) {
-            ager = new NodeStatisticsAger(this, new NodeKey(nodeId));
+            ager = new NodeStatisticsHandler(this, new NodeKey(nodeId));
             statisticsCache.put(nodeId, ager);
         }
 
index 2ed4e20..bf523a4 100644 (file)
@@ -25,7 +25,7 @@ public class StatisticsUpdateCommiterTest {
             .getLogger(StatisticsUpdateCommiterTest.class);
 
     /**
-     * Test method for {@link org.opendaylight.controller.md.statistics.manager.StatisticsUpdateCommiter#layer3MatchEquals(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match, org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match)}.
+     * Test method for {@link org.opendaylight.controller.md.statistics.manager.StatisticsListener#layer3MatchEquals(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match, org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match)}.
      */
     @Test
     public void testLayer3MatchEquals() {