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
9 package org.opendaylight.dsbenchmark.txchain;
11 import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain;
12 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
13 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
14 import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
15 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
16 import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
17 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
18 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
19 import org.opendaylight.dsbenchmark.DatastoreAbstractWriter;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput;
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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterListKey;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 import com.google.common.util.concurrent.FutureCallback;
29 import com.google.common.util.concurrent.Futures;
31 public class TxchainBaDelete extends DatastoreAbstractWriter implements TransactionChainListener{
32 private static final Logger LOG = (Logger) LoggerFactory.getLogger(TxchainBaDelete.class);
33 private DataBroker bindingDataBroker;
35 public TxchainBaDelete(DataBroker bindingDataBroker, int outerListElem, int innerListElem, long writesPerTx) {
36 super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx);
37 this.bindingDataBroker = bindingDataBroker;
38 LOG.info("Created TxchainBaDelete");
42 public void createList() {
43 LOG.info("TxchainBaDelete: 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 TxchainBaWrite dd = new TxchainBaWrite(bindingDataBroker,
48 StartTestInput.Operation.PUT,
57 public void executeList() {
61 BindingTransactionChain chain = bindingDataBroker.createTransactionChain(this);
62 WriteTransaction tx = chain.newWriteOnlyTransaction();
64 for (long l = 0; l < outerListElem; l++) {
65 InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class)
66 .child(OuterList.class, new OuterListKey((int)l));
67 tx.delete(LogicalDatastoreType.CONFIGURATION, iid);
71 if (writeCnt == writesPerTx) {
73 Futures.addCallback(tx.submit(), new FutureCallback<Void>() {
75 public void onSuccess(final Void result) {
79 public void onFailure(final Throwable t) {
80 LOG.error("Transaction failed, {}", t);
84 tx = chain.newWriteOnlyTransaction();
89 // Submit the outstanding transaction even if it's empty and wait for it to finish
90 // We need to empty the chain before closing it
95 tx.submit().checkedGet();
96 } catch (TransactionCommitFailedException e) {
97 LOG.error("Transaction failed", e);
102 catch (IllegalStateException e){
103 LOG.error("Transaction close failed,", e);
105 LOG.info("Transactions: submitted {}, completed {}", txSubmitted, (txOk + txError));
109 public void onTransactionChainFailed(TransactionChain<?, ?> chain,
110 AsyncTransaction<?, ?> transaction, Throwable cause) {
111 LOG.error("Broken chain {} in TxchainBaDelete, transaction {}, cause {}",
112 chain, transaction.getIdentifier(), cause);
116 public void onTransactionChainSuccessful(TransactionChain<?, ?> chain) {
117 LOG.info("TxchainBaDelete closed successfully, chain {}", chain);