Reduce use of deprecated methods
[controller.git] / benchmark / dsbenchmark / src / main / java / org / opendaylight / dsbenchmark / simpletx / SimpletxDomDelete.java
index 8f748533df0066a426e723c09a7644d702f68760..af9ad559e55a858182619dc3a74d7b7676c0eb70 100644 (file)
@@ -8,8 +8,8 @@
 
 package org.opendaylight.dsbenchmark.simpletx;
 
+import java.util.concurrent.ExecutionException;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
 import org.opendaylight.dsbenchmark.DatastoreAbstractWriter;
@@ -19,6 +19,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchm
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -26,16 +27,16 @@ public class SimpletxDomDelete extends DatastoreAbstractWriter {
     private static final Logger LOG = LoggerFactory.getLogger(SimpletxDomDelete.class);
     private final DOMDataBroker domDataBroker;
 
-    public SimpletxDomDelete(DOMDataBroker domDataBroker, int outerListElem,
-            int innerListElem, long writesPerTx, DataStore dataStore) {
+    public SimpletxDomDelete(final DOMDataBroker domDataBroker, final int outerListElem,
+            final int innerListElem, final long writesPerTx, final DataStore dataStore) {
         super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx, dataStore);
         this.domDataBroker = domDataBroker;
-        LOG.info("Created simpleTxDomDelete");
-   }
+        LOG.debug("Created simpleTxDomDelete");
+    }
 
     @Override
     public void createList() {
-        LOG.info("SimpletxDomDelete: creating data in the data store");
+        LOG.debug("SimpletxDomDelete: creating data in the data store");
         // Dump the whole list into the data store in a single transaction
         // with <outerListElem> PUTs on the transaction
         SimpletxDomWrite dd = new SimpletxDomWrite(domDataBroker,
@@ -50,26 +51,26 @@ public class SimpletxDomDelete extends DatastoreAbstractWriter {
 
     @Override
     public void executeList() {
-        long writeCnt = 0;
+        final LogicalDatastoreType dsType = getDataStoreType();
+        final org.opendaylight.yangtools.yang.common.QName olId = QName.create(OuterList.QNAME, "id");
+        final YangInstanceIdentifier pid =
+                YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build();
+
 
-        org.opendaylight.yangtools.yang.common.QName OL_ID = QName.create(OuterList.QNAME, "id");
         DOMDataWriteTransaction tx = domDataBroker.newWriteOnlyTransaction();
+        long writeCnt = 0;
 
         for (int l = 0; l < outerListElem; l++) {
-            YangInstanceIdentifier yid = YangInstanceIdentifier.builder()
-                                         .node(TestExec.QNAME)
-                                         .node(OuterList.QNAME)
-                                         .nodeWithKey(OuterList.QNAME, OL_ID, l)
-                                         .build();
+            YangInstanceIdentifier yid = pid.node(new NodeIdentifierWithPredicates(OuterList.QNAME, olId, l));
 
-            tx.delete(LogicalDatastoreType.CONFIGURATION, yid);
+            tx.delete(dsType, yid);
             writeCnt++;
             if (writeCnt == writesPerTx) {
                 try {
-                    tx.submit().checkedGet();
+                    tx.commit().get();
                     txOk++;
-                } catch (TransactionCommitFailedException e) {
-                    LOG.error("Transaction failed: {}", e.toString());
+                } catch (final  InterruptedException | ExecutionException e) {
+                    LOG.error("Transaction failed: {}", e);
                     txError++;
                 }
                 tx = domDataBroker.newWriteOnlyTransaction();
@@ -78,9 +79,9 @@ public class SimpletxDomDelete extends DatastoreAbstractWriter {
         }
         if (writeCnt != 0) {
             try {
-                tx.submit().checkedGet();
-            } catch (TransactionCommitFailedException e) {
-                LOG.error("Transaction failed: {}", e.toString());
+                tx.commit().get();
+            } catch (final InterruptedException | ExecutionException e) {
+                LOG.error("Transaction failed: {}", e);
             }
         }
     }