Merge "Update comments and imports after DataChangeListener changes" into stable...
[openflowplugin.git] / applications / statistics-manager / src / main / java / org / opendaylight / openflowplugin / applications / statistics / manager / impl / StatListenCommitMeter.java
index 0674bc9a53ad66528322cf8bce699c312a3f8a7e..20eb166586c81acce14f5f2e9dd487f2c85277ce 100644 (file)
@@ -8,10 +8,11 @@
 
 package org.opendaylight.openflowplugin.applications.statistics.manager.impl;
 
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
-
 import java.util.UUID;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
@@ -56,18 +57,14 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-
 /**
  * statistics-manager
  * org.opendaylight.openflowplugin.applications.statistics.manager.impl
  *
  * StatListenCommitMeter
- * Class is a NotifyListener for MeterStatistics and DataChangeListener for Config/DataStore for Meter node.
+ * Class is a NotifyListener for MeterStatistics and DataTreeChangeListener for Config/DataStore for Meter node.
  * All expected (registered) MeterStatistics will be builded and commit to Operational/DataStore.
- * DataChangeEven should call create/delete Meter in Operational/DS
- *
+ * DataTreeModification should call create/delete Meter in Operational/DS
  */
 public class StatListenCommitMeter extends StatAbstractListenCommit<Meter, OpendaylightMeterStatisticsListener>
                                             implements OpendaylightMeterStatisticsListener {
@@ -131,7 +128,6 @@ public class StatListenCommitMeter extends StatAbstractListenCommit<Meter, Opend
                 }
 
                 if(!nodeRegistrationManager.isFlowCapableNodeOwner(nodeId)) { return; }
-
                 /* Prepare List actual Meters and not updated Meters will be removed */
                 final List<Meter> existMeters = fNode.get().getMeter() != null
                         ? fNode.get().getMeter() : Collections.<Meter> emptyList();
@@ -177,11 +173,16 @@ public class StatListenCommitMeter extends StatAbstractListenCommit<Meter, Opend
                     return;
                 }
 
-                if(!nodeRegistrationManager.isFlowCapableNodeOwner(nodeId)) { return; }
-
                 final InstanceIdentifier<Node> nodeIdent = InstanceIdentifier
                         .create(Nodes.class).child(Node.class, new NodeKey(nodeId));
 
+                //Register meter feature irrespective of whether this instance is
+                //master instance of the device or not. In cluster mode, all instances
+                // should have knowledge if meter is supported by the device.
+                manager.registerAdditionalNodeFeature(nodeIdent, StatCapabTypes.METER_STATS);
+
+                if(!nodeRegistrationManager.isFlowCapableNodeOwner(nodeId)) { return; }
+
                 final List<? extends TransactionAware> cacheNotifs = txContainer.get().getNotifications();
                 for (final TransactionAware notif : cacheNotifs) {
                     if ( ! (notif instanceof MeterFeaturesUpdated)) {
@@ -202,7 +203,9 @@ public class StatListenCommitMeter extends StatAbstractListenCommit<Meter, Opend
                     if (node.isPresent()) {
                         tx.merge(LogicalDatastoreType.OPERATIONAL, nodeMeterFeatureIdent, new NodeMeterFeaturesBuilder().build(), true);
                         tx.put(LogicalDatastoreType.OPERATIONAL, meterFeatureIdent, stats);
-                        manager.registerAdditionalNodeFeature(nodeIdent, StatCapabTypes.METER_STATS);
+                        manager.unregisterNodeStats(nodeIdent, StatCapabTypes.METER_FEATURE_STATS);
+                    } else {
+                        LOG.debug("Node {} is NOT present in the operational data store",nodeId);
                     }
                 }
             }