Added support for data store type (OPERATIONAL or CONFIG or BOTH)
[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.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 public class SimpletxDomDelete extends DatastoreAbstractWriter {
26     private static final Logger LOG = (Logger) LoggerFactory.getLogger(SimpletxDomDelete.class);
27     private final DOMDataBroker domDataBroker;
28
29     public SimpletxDomDelete(DOMDataBroker domDataBroker, int outerListElem,
30             int innerListElem, long writesPerTx, DataStore dataStore) {
31         super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx, dataStore);
32         this.domDataBroker = domDataBroker;
33         LOG.info("Created simpleTxDomDelete");
34    }
35
36     @Override
37     public void createList() {
38         LOG.info("SimpletxDomDelete: creating data in the data store");
39         // Dump the whole list into the data store in a single transaction
40         // with <outerListElem> PUTs on the transaction
41         SimpletxDomWrite dd = new SimpletxDomWrite(domDataBroker,
42                                                    StartTestInput.Operation.PUT,
43                                                    outerListElem,
44                                                    innerListElem,
45                                                    outerListElem,
46                                                    dataStore);
47         dd.createList();
48         dd.executeList();
49     }
50
51     @Override
52     public void executeList() {
53         long writeCnt = 0;
54
55         org.opendaylight.yangtools.yang.common.QName OL_ID = QName.create(OuterList.QNAME, "id");
56         DOMDataWriteTransaction tx = domDataBroker.newWriteOnlyTransaction();
57
58         for (int l = 0; l < outerListElem; l++) {
59             YangInstanceIdentifier yid = YangInstanceIdentifier.builder()
60                                          .node(TestExec.QNAME)
61                                          .node(OuterList.QNAME)
62                                          .nodeWithKey(OuterList.QNAME, OL_ID, l)
63                                          .build();
64
65             tx.delete(LogicalDatastoreType.CONFIGURATION, yid);
66             writeCnt++;
67             if (writeCnt == writesPerTx) {
68                 try {
69                     tx.submit().checkedGet();
70                     txOk++;
71                 } catch (TransactionCommitFailedException e) {
72                     LOG.error("Transaction failed: {}", e.toString());
73                     txError++;
74                 }
75                 tx = domDataBroker.newWriteOnlyTransaction();
76                 writeCnt = 0;
77             }
78         }
79         if (writeCnt != 0) {
80             try {
81                 tx.submit().checkedGet();
82             } catch (TransactionCommitFailedException e) {
83                 LOG.error("Transaction failed: {}", e.toString());
84             }
85         }
86     }
87
88 }