cb57f377a26e467d2e1a07492646d4102114bc33
[controller.git] / benchmark / dsbenchmark / src / main / java / org / opendaylight / dsbenchmark / txchain / TxchainBaRead.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.dsbenchmark.txchain;
10
11 import com.google.common.base.Optional;
12 import com.google.common.util.concurrent.CheckedFuture;
13
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.StartTestInput.DataStore;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterListKey;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.outer.list.InnerList;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 public class TxchainBaRead extends DatastoreAbstractWriter implements TransactionChainListener {
29     private static final Logger LOG = LoggerFactory.getLogger(TxchainBaRead.class);
30     private DataBroker bindingDataBroker;
31
32     public TxchainBaRead(DataBroker bindingDataBroker, int outerListElem, int innerListElem,
33             long writesPerTx, DataStore dataStore) {
34         super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx, dataStore);
35         this.bindingDataBroker = bindingDataBroker;
36         LOG.info("Created TxchainBaRead");
37     }
38
39     @Override
40     public void createList() {
41         LOG.info("TxchainBaRead: reading data in the data store");
42
43         // Dump the whole list into the data store in a single transaction
44         // with <outerListElem> PUTs on the transaction
45         TxchainBaWrite dd = new TxchainBaWrite(bindingDataBroker,
46                                                StartTestInput.Operation.PUT,
47                                                outerListElem,
48                                                innerListElem,
49                                                outerListElem,
50                                                dataStore);
51         dd.createList();
52         dd.executeList();
53     }
54
55     @Override
56     public void executeList() {
57         ReadTransaction tx = bindingDataBroker.newReadOnlyTransaction();
58
59         for (long l = 0; l < outerListElem; l++) {
60
61             OuterList outerList;
62             InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class)
63                     .child(OuterList.class, new OuterListKey((int) l));
64             Optional<OuterList> optionalDataObject;
65             CheckedFuture<Optional<OuterList>, ReadFailedException> submitFuture =
66                     tx.read(LogicalDatastoreType.CONFIGURATION, iid);
67
68             try {
69                 optionalDataObject = submitFuture.checkedGet();
70                 if (optionalDataObject != null && optionalDataObject.isPresent()) {
71                     outerList = optionalDataObject.get();
72
73                     String[] objectsArray = new String[outerList.getInnerList().size()];
74                     for (InnerList innerList : outerList.getInnerList()) {
75                         if (objectsArray[innerList.getName()] != null) {
76                             LOG.error("innerList: DUPLICATE name: {}, value: {}", innerList.getName(),
77                                     innerList.getValue());
78                         }
79                         objectsArray[innerList.getName()] = innerList.getValue();
80                     }
81                     for (int i = 0; i < outerList.getInnerList().size(); i++) {
82                         String itemStr = objectsArray[i];
83                         if (!itemStr.contentEquals("Item-" + String.valueOf(l) + "-" + String.valueOf(i))) {
84                             LOG.error("innerList: name: {}, value: {}", i, itemStr);
85                             break;
86                         }
87                     }
88                     txOk++;
89                 } else {
90                     txError++;
91                 }
92             } catch (ReadFailedException e) {
93                 LOG.warn("failed to ....", e);
94                 txError++;
95             }
96         }
97     }
98
99     @Override
100     public void onTransactionChainFailed(TransactionChain<?, ?> chain,
101                                          AsyncTransaction<?, ?> transaction, Throwable cause) {
102         LOG.error("Broken chain {} in TxchainBaDelete, transaction {}, cause {}",
103                 chain, transaction.getIdentifier(), cause);
104     }
105
106     @Override
107     public void onTransactionChainSuccessful(TransactionChain<?, ?> chain) {
108         LOG.info("TxchainBaDelete closed successfully, chain {}", chain);
109     }
110
111 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.