Convert dsbenchmark to mdsal APIs
[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 package org.opendaylight.dsbenchmark.simpletx;
9
10 import java.util.concurrent.ExecutionException;
11 import org.opendaylight.dsbenchmark.DatastoreAbstractWriter;
12 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
13 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
14 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput.DataStore;
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.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 public class SimpletxDomDelete extends DatastoreAbstractWriter {
26     private static final Logger LOG = LoggerFactory.getLogger(SimpletxDomDelete.class);
27     private final DOMDataBroker domDataBroker;
28
29     public SimpletxDomDelete(final DOMDataBroker domDataBroker, final int outerListElem,
30             final int innerListElem, final long writesPerTx, final DataStore dataStore) {
31         super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx, dataStore);
32         this.domDataBroker = domDataBroker;
33         LOG.debug("Created simpleTxDomDelete");
34     }
35
36     @Override
37     public void createList() {
38         LOG.debug("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         final LogicalDatastoreType dsType = getDataStoreType();
54         final org.opendaylight.yangtools.yang.common.QName olId = QName.create(OuterList.QNAME, "id");
55         final YangInstanceIdentifier pid =
56                 YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build();
57
58
59         DOMDataTreeWriteTransaction tx = domDataBroker.newWriteOnlyTransaction();
60         long writeCnt = 0;
61
62         for (int l = 0; l < outerListElem; l++) {
63             YangInstanceIdentifier yid = pid.node(new NodeIdentifierWithPredicates(OuterList.QNAME, olId, l));
64
65             tx.delete(dsType, yid);
66             writeCnt++;
67             if (writeCnt == writesPerTx) {
68                 try {
69                     tx.commit().get();
70                     txOk++;
71                 } catch (final  InterruptedException | ExecutionException e) {
72                     LOG.error("Transaction failed: {}", e);
73                     txError++;
74                 }
75                 tx = domDataBroker.newWriteOnlyTransaction();
76                 writeCnt = 0;
77             }
78         }
79         if (writeCnt != 0) {
80             try {
81                 tx.commit().get();
82             } catch (final InterruptedException | ExecutionException e) {
83                 LOG.error("Transaction failed: {}", e);
84             }
85         }
86     }
87
88 }

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