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.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.binding.InstanceIdentifier;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 public class SimpletxBaWrite extends DatastoreAbstractWriter {
28 private static final Logger LOG = LoggerFactory.getLogger(SimpletxBaWrite.class);
29 private final DataBroker dataBroker;
30 private List<OuterList> list;
32 public SimpletxBaWrite(DataBroker dataBroker, StartTestInput.Operation oper,
33 int outerListElem, int innerListElem, long writesPerTx, DataStore dataStore) {
34 super(oper, outerListElem, innerListElem, writesPerTx, dataStore);
35 this.dataBroker = dataBroker;
36 LOG.info("Created SimpletxBaWrite");
40 public void createList() {
41 list = BaListBuilder.buildOuterList(this.outerListElem, this.innerListElem);
45 public void executeList() {
46 WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
49 for (OuterList element : this.list) {
50 InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class)
51 .child(OuterList.class, element.getKey());
52 if (oper == StartTestInput.Operation.PUT) {
53 tx.put(LogicalDatastoreType.CONFIGURATION, iid, element);
55 tx.merge(LogicalDatastoreType.CONFIGURATION, iid, element);
60 if (writeCnt == writesPerTx) {
62 tx.submit().checkedGet();
64 } catch (TransactionCommitFailedException e) {
65 LOG.error("Transaction failed: {}", e.toString());
68 tx = dataBroker.newWriteOnlyTransaction();
75 tx.submit().checkedGet();
76 } catch (TransactionCommitFailedException e) {
77 LOG.error("Transaction failed: {}", e.toString());