9624343f398ea7ee5ffee28cd48309897080e467
[controller.git] / benchmark / dsbenchmark / src / main / java / org / opendaylight / dsbenchmark / simpletx / SimpletxDomRead.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.simpletx;
10
11
12 import com.google.common.base.Optional;
13 import com.google.common.util.concurrent.CheckedFuture;
14
15 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
16 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
17 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
18 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
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.StartTestInput.DataStore;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList;
24 import org.opendaylight.yangtools.yang.common.QName;
25 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
26 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30
31 public class SimpletxDomRead extends DatastoreAbstractWriter {
32     private static final Logger LOG = LoggerFactory.getLogger(SimpletxDomRead.class);
33     private final DOMDataBroker domDataBroker;
34
35     public SimpletxDomRead(DOMDataBroker domDataBroker, int outerListElem,
36                            int innerListElem, long writesPerTx, DataStore dataStore) {
37         super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx, dataStore);
38         this.domDataBroker = domDataBroker;
39         LOG.info("Created simpleTxDomRead");
40
41     }
42
43     @Override
44     public void createList() {
45         LOG.info("SimpletxDomRead: 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         SimpletxDomWrite dd = new SimpletxDomWrite(domDataBroker,
49                                                    StartTestInput.Operation.PUT,
50                                                    outerListElem,
51                                                    innerListElem,
52                                                    outerListElem,
53                                                    dataStore);
54         dd.createList();
55         dd.executeList();
56     }
57
58     @Override
59     public void executeList() {
60         org.opendaylight.yangtools.yang.common.QName olId = QName.create(OuterList.QNAME, "id");
61         DOMDataReadOnlyTransaction tx = domDataBroker.newReadOnlyTransaction();
62
63         for (long l = 0; l < outerListElem; l++) {
64             NormalizedNode<?,?> ret = null;
65
66             YangInstanceIdentifier yid = YangInstanceIdentifier.builder()
67                     .node(TestExec.QNAME)
68                     .node(OuterList.QNAME)
69                     .nodeWithKey(OuterList.QNAME, olId, l)
70                     .build();
71             Optional<NormalizedNode<?,?>> optionalDataObject;
72             CheckedFuture<Optional<NormalizedNode<?,?>>, ReadFailedException> submitFuture =
73                     tx.read(LogicalDatastoreType.CONFIGURATION, yid);
74             try {
75                 optionalDataObject = submitFuture.checkedGet();
76                 if (optionalDataObject != null && optionalDataObject.isPresent()) {
77                     ret = optionalDataObject.get();
78                     LOG.info("/n" + String.valueOf(ret));
79                     txOk++;
80                 } else {
81                     txError++;
82                     LOG.warn("optionalDataObject is either null or .isPresent is false");
83                 }
84             } catch (ReadFailedException e) {
85                 LOG.warn("failed to ....", e);
86                 txError++;
87             }
88         }
89     }
90
91 }

©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.