dsbenchmark: final parameters
[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
9 package org.opendaylight.dsbenchmark.simpletx;
10
11
12 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
13 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
16 import org.opendaylight.dsbenchmark.DatastoreAbstractWriter;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput.DataStore;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterListKey;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 public class SimpletxBaDelete extends DatastoreAbstractWriter {
27     private static final Logger LOG = LoggerFactory.getLogger(SimpletxBaDelete.class);
28     private final DataBroker dataBroker;
29
30     public SimpletxBaDelete(final DataBroker dataBroker, final int outerListElem, final int innerListElem,
31             final long writesPerTx, final DataStore dataStore) {
32         super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx, dataStore);
33         this.dataBroker = dataBroker;
34         LOG.debug("Created SimpletxBaDelete");
35     }
36
37     @Override
38     public void createList() {
39         LOG.debug("DatastoreDelete: creating data in the data store");
40         // Dump the whole list into the data store in a single transaction
41         // with <outerListElem> PUTs on the transaction
42         SimpletxBaWrite dd = new SimpletxBaWrite(dataBroker,
43                                                  StartTestInput.Operation.PUT,
44                                                  outerListElem,
45                                                  innerListElem,
46                                                  outerListElem,
47                                                  dataStore);
48         dd.createList();
49         dd.executeList();
50     }
51
52     @Override
53     public void executeList() {
54         final LogicalDatastoreType dsType = getDataStoreType();
55
56         WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
57         long putCnt = 0;
58
59         for (long l = 0; l < outerListElem; l++) {
60             InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class)
61                                                         .child(OuterList.class, new OuterListKey((int)l));
62             tx.delete(dsType, iid);
63             putCnt++;
64             if (putCnt == writesPerTx) {
65                 try {
66                     tx.submit().checkedGet();
67                     txOk++;
68                 } catch (final TransactionCommitFailedException e) {
69                     LOG.error("Transaction failed: {}", e);
70                     txError++;
71                 }
72                 tx = dataBroker.newWriteOnlyTransaction();
73                 putCnt = 0;
74             }
75         }
76         if (putCnt != 0) {
77             try {
78                 tx.submit().checkedGet();
79             } catch (final TransactionCommitFailedException e) {
80                 LOG.error("Transaction failed: {}", e);
81             }
82         }
83     }
84 }