2 * Copyright (c) 2015 Cisco Systems 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.simpletx;
11 import java.util.List;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
15 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
16 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
17 import org.opendaylight.dsbenchmark.BaListBuilder;
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.TestExec;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 public class SimpletxBaWrite extends DatastoreAbstractWriter {
27 private static final Logger LOG = LoggerFactory.getLogger(SimpletxBaWrite.class);
28 private final DataBroker dataBroker;
29 private List<OuterList> list;
31 public SimpletxBaWrite(DataBroker dataBroker, StartTestInput.Operation oper,
32 int outerListElem, int innerListElem, long writesPerTx) {
33 super(oper, outerListElem, innerListElem, writesPerTx);
34 this.dataBroker = dataBroker;
35 LOG.info("Created SimpletxBaWrite");
39 public void createList() {
40 list = BaListBuilder.buildOuterList(this.outerListElem, this.innerListElem);
44 public void executeList() {
45 WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
48 for (OuterList element : this.list) {
49 InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class)
50 .child(OuterList.class, element.getKey());
51 if (oper == StartTestInput.Operation.PUT) {
52 tx.put(LogicalDatastoreType.CONFIGURATION, iid, element);
54 tx.merge(LogicalDatastoreType.CONFIGURATION, iid, element);
59 if (writeCnt == writesPerTx) {
61 tx.submit().checkedGet();
63 } catch (TransactionCommitFailedException e) {
64 LOG.error("Transaction failed: {}", e.toString());
67 tx = dataBroker.newWriteOnlyTransaction();
74 tx.submit().checkedGet();
75 } catch (TransactionCommitFailedException e) {
76 LOG.error("Transaction failed: {}", e.toString());