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.StartTestInput.DataStore;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterListKey;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 import com.google.common.util.concurrent.FutureCallback;
30 import com.google.common.util.concurrent.Futures;
32 public class TxchainBaDelete extends DatastoreAbstractWriter implements TransactionChainListener{
33 private static final Logger LOG = (Logger) LoggerFactory.getLogger(TxchainBaDelete.class);
34 private DataBroker bindingDataBroker;
36 public TxchainBaDelete(DataBroker bindingDataBroker, int outerListElem, int innerListElem, long writesPerTx, DataStore dataStore) {
37 super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx, dataStore);
38 this.bindingDataBroker = bindingDataBroker;
39 LOG.info("Created TxchainBaDelete");
43 public void createList() {
44 LOG.info("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() {
63 BindingTransactionChain chain = bindingDataBroker.createTransactionChain(this);
64 WriteTransaction tx = chain.newWriteOnlyTransaction();
66 for (long l = 0; l < outerListElem; l++) {
67 InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class)
68 .child(OuterList.class, new OuterListKey((int)l));
69 tx.delete(LogicalDatastoreType.CONFIGURATION, iid);
73 if (writeCnt == writesPerTx) {
75 Futures.addCallback(tx.submit(), new FutureCallback<Void>() {
77 public void onSuccess(final Void result) {
81 public void onFailure(final Throwable t) {
82 LOG.error("Transaction failed, {}", t);
86 tx = chain.newWriteOnlyTransaction();
91 // Submit the outstanding transaction even if it's empty and wait for it to finish
92 // We need to empty the chain before closing it
97 tx.submit().checkedGet();
98 } catch (TransactionCommitFailedException e) {
99 LOG.error("Transaction failed", e);
104 catch (IllegalStateException e){
105 LOG.error("Transaction close failed,", e);
107 LOG.info("Transactions: submitted {}, completed {}", txSubmitted, (txOk + txError));
111 public void onTransactionChainFailed(TransactionChain<?, ?> chain,
112 AsyncTransaction<?, ?> transaction, Throwable cause) {
113 LOG.error("Broken chain {} in TxchainBaDelete, transaction {}, cause {}",
114 chain, transaction.getIdentifier(), cause);
118 public void onTransactionChainSuccessful(TransactionChain<?, ?> chain) {
119 LOG.info("TxchainBaDelete closed successfully, chain {}", chain);