Switch to MD-SAL APIs
[openflowplugin.git] / applications / bulk-o-matic / src / main / java / org / opendaylight / openflowplugin / applications / bulk / o / matic / FlowReader.java
index de5f8952a4274e27dab4fa4186a662a202b458fd..edf3dded44e69df8f75934bc85b7e353adbbcd4a 100644 (file)
@@ -7,13 +7,13 @@
  */
 package org.opendaylight.openflowplugin.applications.bulk.o.matic;
 
-import com.google.common.base.Optional;
+import java.util.Optional;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.ReadTransaction;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
@@ -63,14 +63,14 @@ public final class FlowReader implements Runnable, FlowCounterMBean {
 
     @Override
     public void run() {
-        readFlowsX(dpnCount, flowsPerDpn, verbose);
+        readFlowsX();
     }
 
-    private void readFlowsX(Integer dpnCount, Integer flowsPerDPN, boolean verbose) {
+    private void readFlowsX() {
         readOpStatus.set(FlowCounter.OperationStatus.IN_PROGRESS.status());
         for (int i = 1; i <= dpnCount; i++) {
             String dpId = BulkOMaticUtils.DEVICE_TYPE_PREFIX + i;
-            for (int j = 0; j < flowsPerDPN; j++) {
+            for (int j = 0; j < flowsPerDpn; j++) {
                 short tableRollover = (short) (endTableId - startTableId + 1);
                 short tableId = (short) (j % tableRollover + startTableId);
 
@@ -79,14 +79,12 @@ public final class FlowReader implements Runnable, FlowCounterMBean {
                 String flowId = "Flow-" + dpId + "." + tableId + "." + sourceIp;
                 InstanceIdentifier<Flow> flowIid = getFlowInstanceIdentifier(dpId, tableId, flowId);
 
-                ReadOnlyTransaction readOnlyTransaction = dataBroker.newReadOnlyTransaction();
-                try {
+                try (ReadTransaction readOnlyTransaction = dataBroker.newReadOnlyTransaction()) {
                     Optional<Flow> flowOptional;
                     if (isConfigDs) {
-                        flowOptional = readOnlyTransaction.read(LogicalDatastoreType.CONFIGURATION, flowIid)
-                                .checkedGet();
+                        flowOptional = readOnlyTransaction.read(LogicalDatastoreType.CONFIGURATION, flowIid).get();
                     } else {
-                        flowOptional = readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, flowIid).checkedGet();
+                        flowOptional = readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, flowIid).get();
                     }
 
                     if (flowOptional.isPresent()) {
@@ -99,9 +97,9 @@ public final class FlowReader implements Runnable, FlowCounterMBean {
                             LOG.info("Flow: {} not found", flowIid);
                         }
                     }
-                } catch (ReadFailedException e) {
+                } catch (InterruptedException | ExecutionException e) {
                     readOpStatus.set(FlowCounter.OperationStatus.FAILURE.status());
-                    LOG.error(e.getMessage(), e);
+                    LOG.error("Error {}", e);
                 }
             }
         }