2 * Copyright (c) 2015 Cisco Systems and others. All rights reserved.
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
8 package org.opendaylight.dsbenchmark.txchain;
10 import com.google.common.util.concurrent.FutureCallback;
11 import com.google.common.util.concurrent.MoreExecutors;
12 import java.util.concurrent.ExecutionException;
13 import org.opendaylight.dsbenchmark.DatastoreAbstractWriter;
14 import org.opendaylight.mdsal.common.api.CommitInfo;
15 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
16 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
17 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
18 import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput.DataStore;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList;
23 import org.opendaylight.yangtools.yang.common.Empty;
24 import org.opendaylight.yangtools.yang.common.QName;
25 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
26 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 public class TxchainDomDelete extends DatastoreAbstractWriter implements FutureCallback<Empty> {
31 private static final Logger LOG = LoggerFactory.getLogger(TxchainDomDelete.class);
32 private final DOMDataBroker domDataBroker;
34 public TxchainDomDelete(final DOMDataBroker domDataBroker, final int outerListElem, final int innerListElem,
35 final long writesPerTx, final DataStore dataStore) {
36 super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx, dataStore);
37 this.domDataBroker = domDataBroker;
38 LOG.debug("Created TxchainDomDelete");
42 public void createList() {
43 LOG.debug("TxchainDomDelete: creating data in the data store");
45 // Dump the whole list into the data store in a single transaction
46 // with <outerListElem> PUTs on the transaction
47 TxchainDomWrite dd = new TxchainDomWrite(domDataBroker, StartTestInput.Operation.PUT, outerListElem,
48 innerListElem, outerListElem, dataStore);
54 public void executeList() {
55 final LogicalDatastoreType dsType = getDataStoreType();
56 final org.opendaylight.yangtools.yang.common.QName olId = QName.create(OuterList.QNAME, "id");
57 final YangInstanceIdentifier pid =
58 YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build();
59 final DOMTransactionChain chain = domDataBroker.createMergingTransactionChain();
60 chain.addCallback(this);
62 DOMDataTreeWriteTransaction tx = chain.newWriteOnlyTransaction();
66 for (int l = 0; l < outerListElem; l++) {
67 YangInstanceIdentifier yid = pid.node(NodeIdentifierWithPredicates.of(OuterList.QNAME, olId, l));
68 tx.delete(dsType, yid);
72 if (writeCnt == writesPerTx) {
74 tx.commit().addCallback(new FutureCallback<CommitInfo>() {
76 public void onSuccess(final CommitInfo result) {
81 public void onFailure(final Throwable cause) {
82 LOG.error("Transaction failed", cause);
85 }, MoreExecutors.directExecutor());
86 tx = chain.newWriteOnlyTransaction();
91 // *** Clean up and close the transaction chain ***
92 // Submit the outstanding transaction even if it's empty and wait for it to finish
93 // We need to empty the transaction chain before closing it
98 } catch (final InterruptedException | ExecutionException e) {
99 LOG.error("Transaction failed", e);
104 } catch (final IllegalStateException e) {
105 LOG.error("Transaction close failed,", e);
107 LOG.debug("Transactions: submitted {}, completed {}", txSubmitted, txOk + txError);
111 public void onFailure(final Throwable cause) {
112 LOG.error("Broken chain in TxchainDomDelete", cause);
116 public void onSuccess(final Empty result) {
117 LOG.debug("TxchainDomDelete closed successfully");