4d67d4c90a7e99c9bd1d2407182ea1a407741eb6
[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 DataBroker dataBroker;
29
30     public SimpletxBaDelete(DataBroker dataBroker, int outerListElem, int innerListElem,
31             long writesPerTx, DataStore dataStore) {
32         super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx, dataStore);
33         this.dataBroker = dataBroker;
34         LOG.info("Created SimpletxBaDelete");
35     }
36
37     @Override
38     public void createList() {
39         LOG.info("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         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(LogicalDatastoreType.CONFIGURATION, iid);
61             putCnt++;
62             if (putCnt == writesPerTx) {
63                 try {
64                     tx.submit().checkedGet();
65                     txOk++;
66                 } catch (TransactionCommitFailedException 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.submit().checkedGet();
77             } catch (TransactionCommitFailedException 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.