ab7590cdac6b65eb048412d99b6a3cd60315cfd9
[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.TestExec;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 public class SimpletxDomDelete extends DatastoreAbstractWriter {
25     private static final Logger LOG = (Logger) LoggerFactory.getLogger(SimpletxDomDelete.class);
26     private final DOMDataBroker domDataBroker;
27
28     public SimpletxDomDelete(DOMDataBroker domDataBroker, int outerListElem,
29             int innerListElem, long writesPerTx) {
30         super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx);
31         this.domDataBroker = domDataBroker;
32         LOG.info("Created simpleTxDomDelete");
33    }
34
35     @Override
36     public void createList() {
37         LOG.info("SimpletxDomDelete: 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         SimpletxDomWrite dd = new SimpletxDomWrite(domDataBroker,
41                                                    StartTestInput.Operation.PUT,
42                                                    outerListElem,
43                                                    innerListElem,
44                                                    outerListElem);
45         dd.createList();
46         dd.executeList();
47     }
48
49     @Override
50     public void executeList() {
51         long writeCnt = 0;
52
53         org.opendaylight.yangtools.yang.common.QName OL_ID = QName.create(OuterList.QNAME, "id");
54         DOMDataWriteTransaction tx = domDataBroker.newWriteOnlyTransaction();
55
56         for (int l = 0; l < outerListElem; l++) {
57             YangInstanceIdentifier yid = YangInstanceIdentifier.builder()
58                                          .node(TestExec.QNAME)
59                                          .node(OuterList.QNAME)
60                                          .nodeWithKey(OuterList.QNAME, OL_ID, l)
61                                          .build();
62
63             tx.delete(LogicalDatastoreType.CONFIGURATION, yid);
64             writeCnt++;
65             if (writeCnt == writesPerTx) {
66                 try {
67                     tx.submit().checkedGet();
68                     txOk++;
69                 } catch (TransactionCommitFailedException e) {
70                     LOG.error("Transaction failed: {}", e.toString());
71                     txError++;
72                 }
73                 tx = domDataBroker.newWriteOnlyTransaction();
74                 writeCnt = 0;
75             }
76         }
77         if (writeCnt != 0) {
78             try {
79                 tx.submit().checkedGet();
80             } catch (TransactionCommitFailedException e) {
81                 LOG.error("Transaction failed: {}", e.toString());
82             }
83         }
84     }
85
86 }