2 * Copyright (c) 2015 Cisco Systems, Inc. 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.base.Optional;
12 import com.google.common.util.concurrent.CheckedFuture;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
15 import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
18 import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
19 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
20 import org.opendaylight.dsbenchmark.DatastoreAbstractWriter;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput.DataStore;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterListKey;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.outer.list.InnerList;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 public class TxchainBaRead extends DatastoreAbstractWriter implements TransactionChainListener {
32 private static final Logger LOG = LoggerFactory.getLogger(TxchainBaRead.class);
33 private final DataBroker bindingDataBroker;
35 public TxchainBaRead(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 TxchainBaRead");
43 public void createList() {
44 LOG.debug("TxchainBaRead: reading 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();
62 try (ReadOnlyTransaction tx = bindingDataBroker.newReadOnlyTransaction()) {
63 for (long l = 0; l < outerListElem; l++) {
65 InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class)
66 .child(OuterList.class, new OuterListKey((int) l));
67 CheckedFuture<Optional<OuterList>, ReadFailedException> submitFuture =
71 Optional<OuterList> optionalDataObject = submitFuture.checkedGet();
72 if (optionalDataObject != null && optionalDataObject.isPresent()) {
73 OuterList outerList = optionalDataObject.get();
75 String[] objectsArray = new String[outerList.getInnerList().size()];
76 for (InnerList innerList : outerList.getInnerList()) {
77 if (objectsArray[innerList.getName()] != null) {
78 LOG.error("innerList: DUPLICATE name: {}, value: {}", innerList.getName(),
79 innerList.getValue());
81 objectsArray[innerList.getName()] = innerList.getValue();
83 for (int i = 0; i < outerList.getInnerList().size(); i++) {
84 String itemStr = objectsArray[i];
85 if (!itemStr.contentEquals("Item-" + String.valueOf(l) + "-" + String.valueOf(i))) {
86 LOG.error("innerList: name: {}, value: {}", i, itemStr);
94 } catch (ReadFailedException e) {
95 LOG.warn("failed to ....", e);
103 public void onTransactionChainFailed(final TransactionChain<?, ?> chain,
104 final AsyncTransaction<?, ?> transaction, final Throwable cause) {
105 LOG.error("Broken chain {} in TxchainBaDelete, transaction {}, cause {}",
106 chain, transaction.getIdentifier(), cause);
110 public void onTransactionChainSuccessful(final TransactionChain<?, ?> chain) {
111 LOG.debug("TxchainBaDelete closed successfully, chain {}", chain);