process flows statistics in one commit tx only when device is synchronized 04/19504/1
authorMartin Bobak <mbobak@cisco.com>
Mon, 4 May 2015 08:08:58 +0000 (10:08 +0200)
committerMartin Bobak <mbobak@cisco.com>
Mon, 4 May 2015 08:09:34 +0000 (10:09 +0200)
Change-Id: I1d3490686445836299e3058a3102889e5c67549c
Signed-off-by: Martin Bobak <mbobak@cisco.com>
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsGatheringUtils.java

index be98bbfa83abffa7ded1a1e9d352b225b2eca454..2e3812350485e37b90ab785a5c4ac0834e5983e3 100644 (file)
@@ -186,9 +186,11 @@ public final class StatisticsGatheringUtils {
         final InstanceIdentifier<Node> nodeIdent = InstanceIdentifier.create(Nodes.class)
                 .child(Node.class, new NodeKey(flowsStatistics.getId()));
 
-        deviceContext.startGatheringOperationsToOneTransaction();
-        deleteAllKnownFlows(deviceContext, nodeIdent);
+        if (deviceContext.getDeviceState().isValid()) {
+            deviceContext.startGatheringOperationsToOneTransaction();
+        }
 
+        deleteAllKnownFlows(deviceContext, nodeIdent);
 
         for (final FlowAndStatisticsMapList flowStat : flowsStatistics.getFlowAndStatisticsMapList()) {
             final FlowBuilder flowBuilder = new FlowBuilder(flowStat);
@@ -212,7 +214,9 @@ public final class StatisticsGatheringUtils {
             deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, flowIdent, flowBuilder.build());
         }
 
-        deviceContext.commitOperationsGatheredInOneTransaction();
+        if (deviceContext.getDeviceState().isValid()) {
+            deviceContext.commitOperationsGatheredInOneTransaction();
+        }
     }
 
     private static void deleteAllKnownFlows(final DeviceContext deviceContext, final InstanceIdentifier<Node> nodeIdent) {