Reduce use of deprecated methods
[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 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
16 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
17 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
18 import org.opendaylight.dsbenchmark.DatastoreAbstractWriter;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput.DataStore;
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.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(final DOMDataBroker domDataBroker, final int outerListElem,
36                            final int innerListElem, final long writesPerTx, final DataStore dataStore) {
37         super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx, dataStore);
38         this.domDataBroker = domDataBroker;
39         LOG.debug("Created simpleTxDomRead");
40
41     }
42
43     @Override
44     public void createList() {
45         LOG.debug("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         final LogicalDatastoreType dsType = getDataStoreType();
61         final org.opendaylight.yangtools.yang.common.QName olId = QName.create(OuterList.QNAME, "id");
62         final YangInstanceIdentifier pid =
63                 YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build();
64
65         try (DOMDataReadOnlyTransaction tx = domDataBroker.newReadOnlyTransaction()) {
66             for (int l = 0; l < outerListElem; l++) {
67                 YangInstanceIdentifier yid = pid.node(new NodeIdentifierWithPredicates(OuterList.QNAME, olId, l));
68                 CheckedFuture<Optional<NormalizedNode<?,?>>, ReadFailedException> submitFuture = tx.read(dsType, yid);
69                 try {
70                     Optional<NormalizedNode<?,?>> optionalDataObject = submitFuture.checkedGet();
71                     if (optionalDataObject != null && optionalDataObject.isPresent()) {
72                         NormalizedNode<?, ?> ret = optionalDataObject.get();
73                         LOG.trace("optionalDataObject is {}", ret);
74                         txOk++;
75                     } else {
76                         txError++;
77                         LOG.warn("optionalDataObject is either null or .isPresent is false");
78                     }
79                 } catch (final ReadFailedException e) {
80                     LOG.warn("failed to ....", e);
81                     txError++;
82                 }
83             }
84         }
85     }
86 }

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