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.BindingTransactionChain;
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
16 import org.opendaylight.controller.md.sal.common.api.data.*;
17 import org.opendaylight.dsbenchmark.DatastoreAbstractWriter;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterListKey;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.outer.list.InnerList;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 public class TxchainBaRead extends DatastoreAbstractWriter implements TransactionChainListener{
28 private static final Logger LOG = (Logger) LoggerFactory.getLogger(TxchainBaRead.class);
29 private DataBroker bindingDataBroker;
31 public TxchainBaRead(DataBroker bindingDataBroker, int outerListElem, int innerListElem, long writesPerTx) {
32 super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx);
33 this.bindingDataBroker = bindingDataBroker;
34 LOG.info("Created TxchainBaRead");
38 public void createList() {
39 LOG.info("TxchainBaRead: reading data in the data store");
41 // Dump the whole list into the data store in a single transaction
42 // with <outerListElem> PUTs on the transaction
43 TxchainBaWrite dd = new TxchainBaWrite(bindingDataBroker,
44 StartTestInput.Operation.PUT,
53 public void executeList() {
55 BindingTransactionChain chain = bindingDataBroker.createTransactionChain(this);
56 ReadTransaction tx = bindingDataBroker.newReadOnlyTransaction();
58 for (long l = 0; l < outerListElem; l++) {
61 InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class)
62 .child(OuterList.class, new OuterListKey((int) l));
63 Optional<OuterList> optionalDataObject;
64 CheckedFuture<Optional<OuterList>, ReadFailedException> submitFuture = tx.read(LogicalDatastoreType.CONFIGURATION, iid);
67 optionalDataObject = submitFuture.checkedGet();
68 /*if (optionalDataObject != null && optionalDataObject.isPresent()) {
69 ret = optionalDataObject.get();
72 if (optionalDataObject != null && optionalDataObject.isPresent()) {
73 outerList = optionalDataObject.get();
75 String[] objectsArray = new String[outerList.getInnerList().size()];
77 //LOG.info("innerList element: " + objectsArray );
78 for (InnerList innerList : outerList.getInnerList()) {
79 if (objectsArray[innerList.getName()] != null) {
80 LOG.error("innerList: DUPLICATE name: {}, value: {}", innerList.getName(), innerList.getValue());
82 objectsArray[innerList.getName()] = innerList.getValue();
83 // LOG.info("innerList: name: {}, value: {}", innerList.getName(), innerList.getValue());
85 boolean foundAll = true;
86 for (int i = 0; i < outerList.getInnerList().size(); i++) {
87 String itemStr = objectsArray[i];
88 if (!itemStr.contentEquals("Item-" + String.valueOf(l) + "-" + String.valueOf(i))) {
90 LOG.error("innerList: name: {}, value: {}", i, itemStr);
99 } catch (ReadFailedException e) {
100 LOG.warn("failed to ....", e);
107 public void onTransactionChainFailed(TransactionChain<?, ?> chain,
108 AsyncTransaction<?, ?> transaction, Throwable cause) {
109 LOG.error("Broken chain {} in TxchainBaDelete, transaction {}, cause {}",
110 chain, transaction.getIdentifier(), cause);
114 public void onTransactionChainSuccessful(TransactionChain<?, ?> chain) {
115 LOG.info("TxchainBaDelete closed successfully, chain {}", chain);