Reduce use of deprecated methods
[controller.git] / benchmark / dsbenchmark / src / main / java / org / opendaylight / dsbenchmark / simpletx / SimpletxBaDelete.java
1 /*
2  * Copyright (c) 2015 Cisco Systems and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.dsbenchmark.simpletx;
9
10 import java.util.concurrent.ExecutionException;
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
13 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
14 import org.opendaylight.dsbenchmark.DatastoreAbstractWriter;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput.DataStore;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterListKey;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 public class SimpletxBaDelete extends DatastoreAbstractWriter {
25     private static final Logger LOG = LoggerFactory.getLogger(SimpletxBaDelete.class);
26     private final DataBroker dataBroker;
27
28     public SimpletxBaDelete(final DataBroker dataBroker, final int outerListElem, final int innerListElem,
29             final long writesPerTx, final DataStore dataStore) {
30         super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx, dataStore);
31         this.dataBroker = dataBroker;
32         LOG.debug("Created SimpletxBaDelete");
33     }
34
35     @Override
36     public void createList() {
37         LOG.debug("DatastoreDelete: creating data in the data store");
38         // Dump the whole list into the data store in a single transaction
39         // with <outerListElem> PUTs on the transaction
40         SimpletxBaWrite dd = new SimpletxBaWrite(dataBroker,
41                                                  StartTestInput.Operation.PUT,
42                                                  outerListElem,
43                                                  innerListElem,
44                                                  outerListElem,
45                                                  dataStore);
46         dd.createList();
47         dd.executeList();
48     }
49
50     @Override
51     public void executeList() {
52         final LogicalDatastoreType dsType = getDataStoreType();
53
54         WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
55         long putCnt = 0;
56
57         for (long l = 0; l < outerListElem; l++) {
58             InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class)
59                                                         .child(OuterList.class, new OuterListKey((int)l));
60             tx.delete(dsType, iid);
61             putCnt++;
62             if (putCnt == writesPerTx) {
63                 try {
64                     tx.commit().get();
65                     txOk++;
66                 } catch (final InterruptedException | ExecutionException e) {
67                     LOG.error("Transaction failed: {}", e);
68                     txError++;
69                 }
70                 tx = dataBroker.newWriteOnlyTransaction();
71                 putCnt = 0;
72             }
73         }
74         if (putCnt != 0) {
75             try {
76                 tx.commit().get();
77             } catch (final InterruptedException | ExecutionException e) {
78                 LOG.error("Transaction failed: {}", e);
79             }
80         }
81     }
82 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.