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.binding.api.BindingTransactionChain;
15 import org.opendaylight.mdsal.binding.api.DataBroker;
16 import org.opendaylight.mdsal.binding.api.WriteTransaction;
17 import org.opendaylight.mdsal.common.api.AsyncTransaction;
18 import org.opendaylight.mdsal.common.api.CommitInfo;
19 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
20 import org.opendaylight.mdsal.common.api.TransactionChain;
21 import org.opendaylight.mdsal.common.api.TransactionChainListener;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput.DataStore;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterListKey;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 public class TxchainBaDelete extends DatastoreAbstractWriter implements TransactionChainListener {
32 private static final Logger LOG = LoggerFactory.getLogger(TxchainBaDelete.class);
33 private final DataBroker bindingDataBroker;
35 public TxchainBaDelete(final DataBroker bindingDataBroker, final int outerListElem, final int innerListElem,
36 final long writesPerTx, final DataStore dataStore) {
37 super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx, dataStore);
38 this.bindingDataBroker = bindingDataBroker;
39 LOG.debug("Created TxchainBaDelete");
43 public void createList() {
44 LOG.debug("TxchainBaDelete: creating data in the data store");
46 // Dump the whole list into the data store in a single transaction
47 // with <outerListElem> PUTs on the transaction
48 TxchainBaWrite dd = new TxchainBaWrite(bindingDataBroker,
49 StartTestInput.Operation.PUT,
59 public void executeList() {
60 final LogicalDatastoreType dsType = getDataStoreType();
61 final BindingTransactionChain chain = bindingDataBroker.createTransactionChain(this);
63 WriteTransaction tx = chain.newWriteOnlyTransaction();
67 for (int l = 0; l < outerListElem; l++) {
68 InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class)
69 .child(OuterList.class, new OuterListKey(l));
70 tx.delete(dsType, iid);
74 if (writeCnt == writesPerTx) {
76 tx.commit().addCallback(new FutureCallback<CommitInfo>() {
78 public void onSuccess(final CommitInfo result) {
83 public void onFailure(final Throwable t) {
84 LOG.error("Transaction failed, {}", t);
87 }, MoreExecutors.directExecutor());
88 tx = chain.newWriteOnlyTransaction();
93 // Submit the outstanding transaction even if it's empty and wait for it to finish
94 // We need to empty the chain before closing it
100 } catch (final InterruptedException | ExecutionException e) {
101 LOG.error("Transaction failed", e);
105 } catch (final IllegalStateException e) {
106 LOG.error("Transaction close failed,", e);
108 LOG.debug("Transactions: submitted {}, completed {}", txSubmitted, txOk + txError);
112 public void onTransactionChainFailed(final TransactionChain<?, ?> chain,
113 final AsyncTransaction<?, ?> transaction, final Throwable cause) {
114 LOG.error("Broken chain {} in TxchainBaDelete, transaction {}, cause {}",
115 chain, transaction.getIdentifier(), cause);
119 public void onTransactionChainSuccessful(final TransactionChain<?, ?> chain) {
120 LOG.debug("TxchainBaDelete closed successfully, chain {}", chain);