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.common.api.data.AsyncTransaction;
12 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
13 import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
14 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
15 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
16 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
17 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
18 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
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.yangtools.yang.common.QName;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
25 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
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 TxchainDomDelete extends DatastoreAbstractWriter implements TransactionChainListener{
33 private static final Logger LOG = LoggerFactory.getLogger(TxchainBaWrite.class);
34 private final DOMDataBroker domDataBroker;
36 public TxchainDomDelete(DOMDataBroker domDataBroker, int outerListElem, int innerListElem, long writesPerTx) {
37 super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx);
38 this.domDataBroker = domDataBroker;
39 LOG.info("Created TxchainDomDelete");
43 public void createList() {
44 LOG.info("TxchainDomDelete: 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 TxchainDomWrite dd = new TxchainDomWrite(domDataBroker,
49 StartTestInput.Operation.PUT,
58 public void executeList() {
62 org.opendaylight.yangtools.yang.common.QName OL_ID = QName.create(OuterList.QNAME, "id");
63 DOMTransactionChain chain = domDataBroker.createTransactionChain(this);
64 DOMDataWriteTransaction tx = chain.newWriteOnlyTransaction();
66 YangInstanceIdentifier pid = YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build();
67 for (int l = 0; l < outerListElem; l++) {
68 YangInstanceIdentifier yid = pid.node(new NodeIdentifierWithPredicates(OuterList.QNAME, OL_ID, l));
69 tx.delete(LogicalDatastoreType.CONFIGURATION, yid);
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 // *** 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
96 tx.submit().checkedGet();
98 } catch (TransactionCommitFailedException e) {
99 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 TxchainDomDelete, transaction {}, cause {}",
115 chain, transaction.getIdentifier(), cause);
119 public void onTransactionChainSuccessful(TransactionChain<?, ?> chain) {
120 LOG.info("TxchainDomDelete closed successfully, chain {}", chain);