BUG-7390: fix dsbenchmark
[controller.git] / benchmark / dsbenchmark / src / main / java / org / opendaylight / dsbenchmark / simpletx / SimpletxDomDelete.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 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
12 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
13 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
14 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
15 import org.opendaylight.dsbenchmark.DatastoreAbstractWriter;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput.DataStore;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList;
20 import org.opendaylight.yangtools.yang.common.QName;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 public class SimpletxDomDelete extends DatastoreAbstractWriter {
27     private static final Logger LOG = LoggerFactory.getLogger(SimpletxDomDelete.class);
28     private final DOMDataBroker domDataBroker;
29
30     public SimpletxDomDelete(final DOMDataBroker domDataBroker, final int outerListElem,
31             final int innerListElem, final long writesPerTx, final DataStore dataStore) {
32         super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx, dataStore);
33         this.domDataBroker = domDataBroker;
34         LOG.info("Created simpleTxDomDelete");
35     }
36
37     @Override
38     public void createList() {
39         LOG.info("SimpletxDomDelete: 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         SimpletxDomWrite dd = new SimpletxDomWrite(domDataBroker,
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         final org.opendaylight.yangtools.yang.common.QName olId = QName.create(OuterList.QNAME, "id");
56         final YangInstanceIdentifier pid =
57                 YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build();
58
59
60         DOMDataWriteTransaction tx = domDataBroker.newWriteOnlyTransaction();
61         long writeCnt = 0;
62
63         for (int l = 0; l < outerListElem; l++) {
64             YangInstanceIdentifier yid = pid.node(new NodeIdentifierWithPredicates(OuterList.QNAME, olId, l));
65
66             tx.delete(dsType, yid);
67             writeCnt++;
68             if (writeCnt == writesPerTx) {
69                 try {
70                     tx.submit().checkedGet();
71                     txOk++;
72                 } catch (TransactionCommitFailedException e) {
73                     LOG.error("Transaction failed: {}", e);
74                     txError++;
75                 }
76                 tx = domDataBroker.newWriteOnlyTransaction();
77                 writeCnt = 0;
78             }
79         }
80         if (writeCnt != 0) {
81             try {
82                 tx.submit().checkedGet();
83             } catch (TransactionCommitFailedException e) {
84                 LOG.error("Transaction failed: {}", e);
85             }
86         }
87     }
88
89 }

©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.