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 com.google.common.util.concurrent.FutureCallback;
12 import com.google.common.util.concurrent.Futures;
14 import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
17 import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
18 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
19 import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
20 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
21 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
22 import org.opendaylight.dsbenchmark.DatastoreAbstractWriter;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput.DataStore;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterListKey;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public class TxchainBaDelete extends DatastoreAbstractWriter implements TransactionChainListener {
33 private static final Logger LOG = LoggerFactory.getLogger(TxchainBaDelete.class);
34 private DataBroker bindingDataBroker;
36 public TxchainBaDelete(DataBroker bindingDataBroker, int outerListElem, int innerListElem,
37 long writesPerTx, DataStore dataStore) {
38 super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx, dataStore);
39 this.bindingDataBroker = bindingDataBroker;
40 LOG.info("Created TxchainBaDelete");
44 public void createList() {
45 LOG.info("TxchainBaDelete: creating data in the data store");
47 // Dump the whole list into the data store in a single transaction
48 // with <outerListElem> PUTs on the transaction
49 TxchainBaWrite dd = new TxchainBaWrite(bindingDataBroker,
50 StartTestInput.Operation.PUT,
60 public void executeList() {
64 BindingTransactionChain chain = bindingDataBroker.createTransactionChain(this);
65 WriteTransaction tx = chain.newWriteOnlyTransaction();
67 for (long l = 0; l < outerListElem; l++) {
68 InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class)
69 .child(OuterList.class, new OuterListKey((int)l));
70 tx.delete(LogicalDatastoreType.CONFIGURATION, iid);
74 if (writeCnt == writesPerTx) {
76 Futures.addCallback(tx.submit(), new FutureCallback<Void>() {
78 public void onSuccess(final Void result) {
83 public void onFailure(final Throwable t) {
84 LOG.error("Transaction failed, {}", t);
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
99 tx.submit().checkedGet();
100 } catch (TransactionCommitFailedException e) {
101 LOG.error("Transaction failed", e);
105 } catch (IllegalStateException e) {
106 LOG.error("Transaction close failed,", e);
108 LOG.info("Transactions: submitted {}, completed {}", txSubmitted, (txOk + txError));
112 public void onTransactionChainFailed(TransactionChain<?, ?> chain,
113 AsyncTransaction<?, ?> transaction, Throwable cause) {
114 LOG.error("Broken chain {} in TxchainBaDelete, transaction {}, cause {}",
115 chain, transaction.getIdentifier(), cause);
119 public void onTransactionChainSuccessful(TransactionChain<?, ?> chain) {
120 LOG.info("TxchainBaDelete closed successfully, chain {}", chain);