From: Jan Medved Date: Thu, 5 Nov 2015 22:26:27 +0000 (-0800) Subject: Added the data store benchmark (dsbenchmark, Bug 4519, https://bugs.opendaylight... X-Git-Tag: release/beryllium~194 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=bc740310bca93dcefcf546f7c4a627d8153b3739 Added the data store benchmark (dsbenchmark, Bug 4519, https://bugs.opendaylight.org/show_bug.cgi?id=4519) Change-Id: Ibc6d214b43b6353adbc49ba7b5b4a302ae1fbd95 Signed-off-by: Jan Medved --- diff --git a/benchmark/api/pom.xml b/benchmark/api/pom.xml new file mode 100644 index 0000000000..1bd6f14206 --- /dev/null +++ b/benchmark/api/pom.xml @@ -0,0 +1,23 @@ + + + + + org.opendaylight.mdsal + binding-parent + 0.8.0-SNAPSHOT + + + + 4.0.0 + org.opendaylight.controller + benchmark-api + 1.1.0-SNAPSHOT + bundle + + diff --git a/benchmark/api/src/main/yang/dsbenchmark.yang b/benchmark/api/src/main/yang/dsbenchmark.yang new file mode 100644 index 0000000000..062cc85486 --- /dev/null +++ b/benchmark/api/src/main/yang/dsbenchmark.yang @@ -0,0 +1,196 @@ +module dsbenchmark { + yang-version 1; + namespace "urn:opendaylight:params:xml:ns:yang:dsbenchmark"; + prefix "dsbenchmark"; + + revision "2015-01-05" { + description "Initial revision of dsbenchmark model"; + } + container test-exec { + config true; + + list outer-list { + key id; + leaf id { + type int32; + } + choice outer-choice { + case one { + leaf one { + type string; + } + } + case two-three { + leaf two { + type string; + } + leaf three { + type string; + } + } + } + list inner-list { + key name; + leaf name { + type int32; + } + leaf value { + type string; + } + } + } + } + + container test-status { + leaf execStatus { + type enumeration { + enum "idle" { + value 1; + } + enum "executing" { + value 2; + } + } + config false; + mandatory true; + description + "Indicates whether a test run is in progress; only one test can run at a time"; + } + leaf testsCompleted { + type uint32; + default 1; + description + "Number of completed test runs"; + } + } + + rpc start-test { + description + "Start a new data store write test run"; + + input { + leaf operation { + mandatory true; + type enumeration { + enum "PUT" { + value 1; + description + "The put operation"; + } + enum "MERGE" { + value 2; + description + "The merge operation"; + } + enum "DELETE" { + value 3; + description + "Delete items from a list sotred in the data store"; + } + enum "READ" { + value 4; + description + "The read operation"; + } + } + description + "Type of the transaction operation to benchmark"; + } + + leaf data-format { + mandatory true; + type enumeration { + enum "BINDING-AWARE" { + value 1; + } + enum "BINDING-INDEPENDENT" { + value 2; + } + } + description + "Data format:-binding-aware or binding-independent"; + } + + leaf transaction-type { + mandatory true; + type enumeration { + enum "SIMPLE-TX" { + value 1; + } + enum "TX-CHAINING" { + value 2; + } + } + description + "Data format:-binding-aware or binding-independent"; + } + + leaf outerElements { + type uint32; + default 100000; + description + "Number of elements in the OuterList"; + } + leaf innerElements { + type uint32; + default 1; + description + "Number of elements in the InnerList"; + } + leaf putsPerTx { + type uint32; + default 1; + description + "Number of write operations (PUT, MERGE, or DELETE) per transaction submit"; + } + } + output { + leaf status { + mandatory true; + type enumeration { + enum "OK" { + value 1; + } + enum "FAILED" { + value 2; + } + enum "TEST-IN-PROGRESS" { + value 3; + } + } + description + "Indicates whether the test finished successfuly"; + } + leaf listBuildTime { + type uint32; + default 1; + description + "The time it took to build the list of lists"; + } + leaf execTime { + type uint32; + default 1; + description + "The time it took to execute all transactions"; + } + leaf txOk { + type uint32; + default 1; + description + "The number of successful transactions"; + } + leaf txError { + type uint32; + default 1; + description + "The number of failed transactions"; + } + + } + } + + rpc cleanup-store { + description + "Delete data in the test-exec container that may have been left behind from a previous test run"; + } +} diff --git a/benchmark/artifacts/pom.xml b/benchmark/artifacts/pom.xml new file mode 100644 index 0000000000..dada4e0f9b --- /dev/null +++ b/benchmark/artifacts/pom.xml @@ -0,0 +1,39 @@ + + + + + + 4.0.0 + org.opendaylight.controller + benchmark-artifacts + 1.1.0-SNAPSHOT + pom + + + + + ${project.groupId} + benchmark-api + ${project.version} + + + ${project.groupId} + dsbenchmark + ${project.version} + + + ${project.groupId} + benchmark-features + ${project.version} + features + xml + + + + diff --git a/benchmark/dsbenchmark/pom.xml b/benchmark/dsbenchmark/pom.xml new file mode 100644 index 0000000000..85ef828479 --- /dev/null +++ b/benchmark/dsbenchmark/pom.xml @@ -0,0 +1,39 @@ + + + + + + org.opendaylight.controller + config-parent + 0.4.0-SNAPSHOT + + + + 4.0.0 + org.opendaylight.controller + dsbenchmark + 1.1.0-SNAPSHOT + bundle + + + org.opendaylight.controller + benchmark-api + ${project.version} + + + org.opendaylight.controller + sal-core-api + + + org.opendaylight.yangtools + yang-data-impl + + + + diff --git a/benchmark/dsbenchmark/src/main/config/default-config.xml b/benchmark/dsbenchmark/src/main/config/default-config.xml new file mode 100644 index 0000000000..7fc1b6bc61 --- /dev/null +++ b/benchmark/dsbenchmark/src/main/config/default-config.xml @@ -0,0 +1,38 @@ + + + + + + urn:opendaylight:params:xml:ns:yang:dsbenchmark:impl?module=dsbenchmark-impl&revision=2014-12-10 + urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding?module=opendaylight-md-sal-binding&revision=2013-10-28 + + + + + + + prefix:dsbenchmark-impl + dsbenchmark-default + + binding:binding-broker-osgi-registry + binding-osgi-broker + + + dom:dom-async-data-broker + pingpong-broker + + + binding:binding-async-data-broker + pingpong-binding-data-broker + + + + + + diff --git a/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/BaListBuilder.java b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/BaListBuilder.java new file mode 100644 index 0000000000..610c3b571b --- /dev/null +++ b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/BaListBuilder.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2015 Cisco Systems and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.dsbenchmark; + +import java.util.ArrayList; +import java.util.List; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterListBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterListKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.outer.list.InnerList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.outer.list.InnerListBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.outer.list.InnerListKey; + +public final class BaListBuilder { + static public List buildOuterList(int outerElements, int innerElements) { + List outerList = new ArrayList(outerElements); + for (int j = 0; j < outerElements; j++) { + outerList.add(new OuterListBuilder() + .setId( j ) + .setInnerList(buildInnerList(j, innerElements)) + .setKey(new OuterListKey( j )) + .build()); + } + + return outerList; + } + + static private List buildInnerList( int index, int elements ) { + List innerList = new ArrayList( elements ); + + final String itemStr = "Item-" + String.valueOf(index) + "-"; + for( int i = 0; i < elements; i++ ) { + innerList.add(new InnerListBuilder() + .setKey( new InnerListKey( i ) ) + .setName(i) + .setValue( itemStr + String.valueOf( i ) ) + .build()); + } + + return innerList; + } + +} diff --git a/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/DatastoreAbstractWriter.java b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/DatastoreAbstractWriter.java new file mode 100644 index 0000000000..93a4876340 --- /dev/null +++ b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/DatastoreAbstractWriter.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2015 Cisco Systems and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.dsbenchmark; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput; + +public abstract class DatastoreAbstractWriter { + protected final int outerListElem; + protected final int innerListElem; + protected final long writesPerTx; + protected final StartTestInput.Operation oper; + + protected int txOk = 0; + protected int txError = 0; + + + public DatastoreAbstractWriter(StartTestInput.Operation oper, + int outerListElem, int innerListElem, long writesPerTx) { + this.outerListElem = outerListElem; + this.innerListElem = innerListElem; + this.writesPerTx = writesPerTx; + this.oper = oper; + } + + public abstract void createList(); + public abstract void executeList(); + + public int getTxError() { + return txError; + } + + public int getTxOk() { + return txOk; + } + +} diff --git a/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/DomListBuilder.java b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/DomListBuilder.java new file mode 100644 index 0000000000..a250823705 --- /dev/null +++ b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/DomListBuilder.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2015 Cisco Systems and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.dsbenchmark; + +import java.util.ArrayList; +import java.util.List; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.outer.list.InnerList; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; +import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; +import org.opendaylight.yangtools.yang.data.api.schema.MapNode; +import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; +import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder; + +public final class DomListBuilder { + // Inner List Qname identifiers for yang model's 'name' and 'value' + private static final org.opendaylight.yangtools.yang.common.QName IL_NAME = QName.create(InnerList.QNAME, "name"); + private static final org.opendaylight.yangtools.yang.common.QName IL_VALUE = QName.create(InnerList.QNAME, "value"); + + // Outer List Qname identifier for yang model's 'id' + private static final org.opendaylight.yangtools.yang.common.QName OL_ID = QName.create(OuterList.QNAME, "id"); + + static public List buildOuterList(int outerElements, int innerElements) { + List outerList = new ArrayList(outerElements); + for (int j = 0; j < outerElements; j++) { + outerList.add(ImmutableNodes.mapEntryBuilder() + .withNodeIdentifier(new NodeIdentifierWithPredicates(OuterList.QNAME, OL_ID, j)) + .withChild(ImmutableNodes.leafNode(OL_ID, j)) + .withChild(buildInnerList(j, innerElements)) + .build()); + } + + return outerList; + } + + static private MapNode buildInnerList(int index, int elements ) { + CollectionNodeBuilder innerList = ImmutableNodes.mapNodeBuilder(InnerList.QNAME); + + final String itemStr = "Item-" + String.valueOf(index) + "-"; + for( int i = 0; i < elements; i++ ) { + innerList.addChild(ImmutableNodes.mapEntryBuilder() + .withNodeIdentifier(new NodeIdentifierWithPredicates(InnerList.QNAME, IL_NAME, i)) + .withChild(ImmutableNodes.leafNode(IL_NAME, i)) + .withChild(ImmutableNodes.leafNode(IL_VALUE, itemStr + String.valueOf(i))) + .build()); + } + return innerList.build(); + } + + +} diff --git a/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/DsbenchmarkProvider.java b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/DsbenchmarkProvider.java new file mode 100644 index 0000000000..56e3899d2d --- /dev/null +++ b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/DsbenchmarkProvider.java @@ -0,0 +1,254 @@ +/* + * Copyright (c) 2015 Cisco Systems and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.dsbenchmark; + +import java.util.Collections; +import java.util.concurrent.Future; +import java.util.concurrent.atomic.AtomicReference; + +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration; +import org.opendaylight.controller.sal.binding.api.BindingAwareProvider; +import org.opendaylight.dsbenchmark.simpletx.SimpletxBaDelete; +import org.opendaylight.dsbenchmark.simpletx.SimpletxBaRead; +import org.opendaylight.dsbenchmark.simpletx.SimpletxBaWrite; +import org.opendaylight.dsbenchmark.simpletx.SimpletxDomDelete; +import org.opendaylight.dsbenchmark.simpletx.SimpletxDomRead; +import org.opendaylight.dsbenchmark.simpletx.SimpletxDomWrite; +import org.opendaylight.dsbenchmark.txchain.TxchainBaDelete; +import org.opendaylight.dsbenchmark.txchain.TxchainBaRead; +import org.opendaylight.dsbenchmark.txchain.TxchainBaWrite; +import org.opendaylight.dsbenchmark.txchain.TxchainDomDelete; +import org.opendaylight.dsbenchmark.txchain.TxchainDomRead; +import org.opendaylight.dsbenchmark.txchain.TxchainDomWrite; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.DsbenchmarkService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExecBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestStatus; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestStatus.ExecStatus; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestStatusBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.common.RpcResultBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.util.concurrent.Futures; + +public class DsbenchmarkProvider implements BindingAwareProvider, DsbenchmarkService, AutoCloseable { + + private static final Logger LOG = LoggerFactory.getLogger(DsbenchmarkProvider.class); + private final AtomicReference execStatus = new AtomicReference( ExecStatus.Idle ); + + private static final InstanceIdentifier TEST_EXEC_IID = InstanceIdentifier.builder(TestExec.class).build(); + private static final InstanceIdentifier TEST_STATUS_IID = InstanceIdentifier.builder(TestStatus.class).build(); + private final DOMDataBroker domDataBroker; + private final DataBroker bindingDataBroker; + private RpcRegistration dstReg; + private DataBroker dataBroker; + + private long testsCompleted = 0; + + public DsbenchmarkProvider(DOMDataBroker domDataBroker, DataBroker bindingDataBroker) { + // We have to get the DOMDataBroker via the constructor, + // since we can't get it from the session + this.domDataBroker = domDataBroker; + this.bindingDataBroker = bindingDataBroker; + } + + @Override + public void onSessionInitiated(ProviderContext session) { + this.dataBroker = session.getSALService(DataBroker.class); + this.dstReg = session.addRpcImplementation( DsbenchmarkService.class, this ); + setTestOperData(this.execStatus.get(), testsCompleted); + + LOG.info("DsbenchmarkProvider Session Initiated"); + } + + @Override + public void close() throws Exception { + dstReg.close(); + LOG.info("DsbenchmarkProvider Closed"); + } + + @Override + public Future> cleanupStore() { + cleanupTestStore(); + LOG.info("Data Store cleaned up"); + return Futures.immediateFuture( RpcResultBuilder. success().build() ); + } + + @Override + public Future> startTest(StartTestInput input) { + LOG.info("Starting the data store benchmark test, input: {}", input); + + // Check if there is a test in progress + if ( execStatus.compareAndSet(ExecStatus.Idle, ExecStatus.Executing) == false ) { + LOG.info("Test in progress"); + return RpcResultBuilder.success(new StartTestOutputBuilder() + .setStatus(StartTestOutput.Status.TESTINPROGRESS) + .build()).buildFuture(); + } + + // Cleanup data that may be left over from a previous test run + cleanupTestStore(); + + // Get the appropriate writer based on operation type and data format + DatastoreAbstractWriter dsWriter = getDatastoreWriter(input); + + long startTime, endTime, listCreateTime, execTime; + + startTime = System.nanoTime(); + dsWriter.createList(); + endTime = System.nanoTime(); + listCreateTime = (endTime - startTime) / 1000; + + // Run the test and measure the execution time + try { + startTime = System.nanoTime(); + dsWriter.executeList(); + endTime = System.nanoTime(); + execTime = (endTime - startTime) / 1000; + + this.testsCompleted++; + + } catch ( Exception e ) { + LOG.error( "Test error: {}", e.toString()); + execStatus.set( ExecStatus.Idle ); + return RpcResultBuilder.success(new StartTestOutputBuilder() + .setStatus(StartTestOutput.Status.FAILED) + .build()).buildFuture(); + } + + LOG.info("Test finished"); + setTestOperData( ExecStatus.Idle, testsCompleted); + execStatus.set(ExecStatus.Idle); + + StartTestOutput output = new StartTestOutputBuilder() + .setStatus(StartTestOutput.Status.OK) + .setListBuildTime(listCreateTime) + .setExecTime(execTime) + .setTxOk((long)dsWriter.getTxOk()) + .setTxError((long)dsWriter.getTxError()) + .build(); + + return RpcResultBuilder.success(output).buildFuture(); + } + + private void setTestOperData( ExecStatus sts, long tstCompl ) { + TestStatus status = new TestStatusBuilder() + .setExecStatus(sts) + .setTestsCompleted(tstCompl) + .build(); + + WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); + tx.put(LogicalDatastoreType.OPERATIONAL, TEST_STATUS_IID, status); + + try { + tx.submit().checkedGet(); + } catch (TransactionCommitFailedException e) { + throw new IllegalStateException(e); + } + + LOG.info("DataStore test oper status populated: {}", status); + } + + private void cleanupTestStore() { + TestExec data = new TestExecBuilder() + .setOuterList(Collections.emptyList()) + .build(); + + WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); + tx.put(LogicalDatastoreType.CONFIGURATION, TEST_EXEC_IID, data); + try { + tx.submit().checkedGet(); + LOG.info("DataStore test data cleaned up"); + } catch (TransactionCommitFailedException e) { + LOG.info("Failed to cleanup DataStore test data"); + throw new IllegalStateException(e); + } + + } + + private DatastoreAbstractWriter getDatastoreWriter(StartTestInput input) { + + final DatastoreAbstractWriter retVal; + + StartTestInput.TransactionType txType = input.getTransactionType(); + StartTestInput.Operation oper = input.getOperation(); + StartTestInput.DataFormat dataFormat = input.getDataFormat(); + int outerListElem = input.getOuterElements().intValue(); + int innerListElem = input.getInnerElements().intValue(); + int writesPerTx = input.getPutsPerTx().intValue(); + + try { + if (txType == StartTestInput.TransactionType.SIMPLETX) { + if (dataFormat == StartTestInput.DataFormat.BINDINGAWARE) { + if (StartTestInput.Operation.DELETE == oper) { + retVal = new SimpletxBaDelete(this.dataBroker, outerListElem, + innerListElem,writesPerTx); + } else if (StartTestInput.Operation.READ == oper) { + retVal = new SimpletxBaRead(this.dataBroker, outerListElem, + innerListElem,writesPerTx); + } else { + retVal = new SimpletxBaWrite(this.dataBroker, oper, outerListElem, + innerListElem,writesPerTx); + } + } else { + if (StartTestInput.Operation.DELETE == oper) { + retVal = new SimpletxDomDelete(this.domDataBroker, outerListElem, + innerListElem, writesPerTx); + } else if (StartTestInput.Operation.READ == oper) { + retVal = new SimpletxDomRead(this.domDataBroker, outerListElem, + innerListElem, writesPerTx); + } else { + retVal = new SimpletxDomWrite(this.domDataBroker, oper, outerListElem, + innerListElem,writesPerTx); + } + } + } else { + if (dataFormat == StartTestInput.DataFormat.BINDINGAWARE) { + if (StartTestInput.Operation.DELETE == oper) { + retVal = new TxchainBaDelete(this.bindingDataBroker, outerListElem, + innerListElem, writesPerTx); + } else if (StartTestInput.Operation.READ == oper) { + retVal = new TxchainBaRead(this.bindingDataBroker,outerListElem, + innerListElem,writesPerTx); + } else { + retVal = new TxchainBaWrite(this.bindingDataBroker, oper, outerListElem, + innerListElem,writesPerTx); + } + } else { + if (StartTestInput.Operation.DELETE == oper) { + retVal = new TxchainDomDelete(this.domDataBroker, outerListElem, + innerListElem, writesPerTx); + } else if (StartTestInput.Operation.READ == oper) { + retVal = new TxchainDomRead(this.domDataBroker, outerListElem, + innerListElem, writesPerTx); + + } else { + retVal = new TxchainDomWrite(this.domDataBroker, oper, outerListElem, + innerListElem,writesPerTx); + } + } + } + } finally { + execStatus.set(ExecStatus.Idle); + } + return retVal; + } +} diff --git a/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/simpletx/SimpletxBaDelete.java b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/simpletx/SimpletxBaDelete.java new file mode 100644 index 0000000000..976623fd99 --- /dev/null +++ b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/simpletx/SimpletxBaDelete.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2015 Cisco Systems and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.dsbenchmark.simpletx; + + +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; +import org.opendaylight.dsbenchmark.DatastoreAbstractWriter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterListKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SimpletxBaDelete extends DatastoreAbstractWriter { + private static final Logger LOG = (Logger) LoggerFactory.getLogger(SimpletxBaDelete.class); + private DataBroker dataBroker; + + public SimpletxBaDelete(DataBroker dataBroker, int outerListElem, int innerListElem, long writesPerTx) { + super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx); + this.dataBroker = dataBroker; + LOG.info("Created SimpletxBaDelete"); + } + + @Override + public void createList() { + LOG.info("DatastoreDelete: creating data in the data store"); + // Dump the whole list into the data store in a single transaction + // with PUTs on the transaction + SimpletxBaWrite dd = new SimpletxBaWrite(dataBroker, + StartTestInput.Operation.PUT, + outerListElem, + innerListElem, + outerListElem); + dd.createList(); + dd.executeList(); + } + + @Override + public void executeList() { + WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); + long putCnt = 0; + + for (long l = 0; l < outerListElem; l++) { + InstanceIdentifier iid = InstanceIdentifier.create(TestExec.class) + .child(OuterList.class, new OuterListKey((int)l)); + tx.delete(LogicalDatastoreType.CONFIGURATION, iid); + putCnt++; + if (putCnt == writesPerTx) { + try { + tx.submit().checkedGet(); + txOk++; + } catch (TransactionCommitFailedException e) { + LOG.error("Transaction failed: {}", e.toString()); + txError++; + } + tx = dataBroker.newWriteOnlyTransaction(); + putCnt = 0; + } + } + if (putCnt != 0) { + try { + tx.submit().checkedGet(); + } catch (TransactionCommitFailedException e) { + LOG.error("Transaction failed: {}", e.toString()); + } + } + } +} diff --git a/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/simpletx/SimpletxBaRead.java b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/simpletx/SimpletxBaRead.java new file mode 100644 index 0000000000..b64726932e --- /dev/null +++ b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/simpletx/SimpletxBaRead.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.dsbenchmark.simpletx; + + +import com.google.common.base.Optional; +import com.google.common.util.concurrent.CheckedFuture; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.ReadTransaction; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; +import org.opendaylight.dsbenchmark.DatastoreAbstractWriter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterListKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.outer.list.InnerList; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public class SimpletxBaRead extends DatastoreAbstractWriter { + private static final Logger LOG = (Logger) LoggerFactory.getLogger(SimpletxBaRead.class); + private DataBroker dataBroker; + + public SimpletxBaRead(DataBroker dataBroker, int outerListElem, int innerListElem, long writesPerTx) { + super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx); + this.dataBroker = dataBroker; + LOG.info("Created SimpletxBaRead"); + } + + @Override + public void createList() { + LOG.info("DatastoreRead: creating data in the data store"); + // Dump the whole list into the data store in a single transaction + // with PUTs on the transaction + SimpletxBaWrite dd = new SimpletxBaWrite(dataBroker, + StartTestInput.Operation.PUT, + outerListElem, + innerListElem, + outerListElem); + dd.createList(); + dd.executeList(); + } + + @Override + public void executeList() { + ReadTransaction tx = dataBroker.newReadOnlyTransaction(); + + for (long l = 0; l < outerListElem; l++) { + + OuterList outerList; + InstanceIdentifier iid = InstanceIdentifier.create(TestExec.class) + .child(OuterList.class, new OuterListKey((int)l)); + Optional optionalDataObject; + CheckedFuture, ReadFailedException> submitFuture = tx.read(LogicalDatastoreType.CONFIGURATION, iid); + try { + optionalDataObject = submitFuture.checkedGet(); + if (optionalDataObject != null && optionalDataObject.isPresent()) { + outerList = optionalDataObject.get(); + + String[] objectsArray = new String[outerList.getInnerList().size()]; + + //LOG.info("innerList element: " + objectsArray ); + for (InnerList innerList : outerList.getInnerList()) { + if (objectsArray[innerList.getName()] != null) { + LOG.error("innerList: DUPLICATE name: {}, value: {}", innerList.getName(), innerList.getValue()); + } + objectsArray[innerList.getName()] = innerList.getValue(); + // LOG.info("innerList: name: {}, value: {}", innerList.getName(), innerList.getValue()); + } + boolean foundAll = true; + for (int i = 0; i < outerList.getInnerList().size(); i++) { + String itemStr = objectsArray[i]; + if (!itemStr.contentEquals("Item-" + String.valueOf(l) + "-" + String.valueOf(i))) { + foundAll = false; + LOG.error("innerList: name: {}, value: {}", i, itemStr); + break; + } + } + txOk++; + } else { + txError++; + } + } catch (ReadFailedException e) { + LOG.warn("failed to ....", e); + txError++; + } + } + + } +} diff --git a/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/simpletx/SimpletxBaWrite.java b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/simpletx/SimpletxBaWrite.java new file mode 100644 index 0000000000..f811c4b6b6 --- /dev/null +++ b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/simpletx/SimpletxBaWrite.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2015 Cisco Systems and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.dsbenchmark.simpletx; + +import java.util.List; + +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; +import org.opendaylight.dsbenchmark.BaListBuilder; +import org.opendaylight.dsbenchmark.DatastoreAbstractWriter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SimpletxBaWrite extends DatastoreAbstractWriter { + private static final Logger LOG = LoggerFactory.getLogger(SimpletxBaWrite.class); + private final DataBroker dataBroker; + private List list; + + public SimpletxBaWrite(DataBroker dataBroker, StartTestInput.Operation oper, + int outerListElem, int innerListElem, long writesPerTx) { + super(oper, outerListElem, innerListElem, writesPerTx); + this.dataBroker = dataBroker; + LOG.info("Created SimpletxBaWrite"); + } + + @Override + public void createList() { + list = BaListBuilder.buildOuterList(this.outerListElem, this.innerListElem); + } + + @Override + public void executeList() { + WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); + long writeCnt = 0; + + for (OuterList element : this.list) { + InstanceIdentifier iid = InstanceIdentifier.create(TestExec.class) + .child(OuterList.class, element.getKey()); + if (oper == StartTestInput.Operation.PUT) { + tx.put(LogicalDatastoreType.CONFIGURATION, iid, element); + } else { + tx.merge(LogicalDatastoreType.CONFIGURATION, iid, element); + } + + writeCnt++; + + if (writeCnt == writesPerTx) { + try { + tx.submit().checkedGet(); + txOk++; + } catch (TransactionCommitFailedException e) { + LOG.error("Transaction failed: {}", e.toString()); + txError++; + } + tx = dataBroker.newWriteOnlyTransaction(); + writeCnt = 0; + } + } + + if (writeCnt != 0) { + try { + tx.submit().checkedGet(); + } catch (TransactionCommitFailedException e) { + LOG.error("Transaction failed: {}", e.toString()); + } + } + } + +} diff --git a/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/simpletx/SimpletxDomDelete.java b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/simpletx/SimpletxDomDelete.java new file mode 100644 index 0000000000..ab7590cdac --- /dev/null +++ b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/simpletx/SimpletxDomDelete.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2015 Cisco Systems and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.dsbenchmark.simpletx; + +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; +import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; +import org.opendaylight.dsbenchmark.DatastoreAbstractWriter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SimpletxDomDelete extends DatastoreAbstractWriter { + private static final Logger LOG = (Logger) LoggerFactory.getLogger(SimpletxDomDelete.class); + private final DOMDataBroker domDataBroker; + + public SimpletxDomDelete(DOMDataBroker domDataBroker, int outerListElem, + int innerListElem, long writesPerTx) { + super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx); + this.domDataBroker = domDataBroker; + LOG.info("Created simpleTxDomDelete"); + } + + @Override + public void createList() { + LOG.info("SimpletxDomDelete: creating data in the data store"); + // Dump the whole list into the data store in a single transaction + // with PUTs on the transaction + SimpletxDomWrite dd = new SimpletxDomWrite(domDataBroker, + StartTestInput.Operation.PUT, + outerListElem, + innerListElem, + outerListElem); + dd.createList(); + dd.executeList(); + } + + @Override + public void executeList() { + long writeCnt = 0; + + org.opendaylight.yangtools.yang.common.QName OL_ID = QName.create(OuterList.QNAME, "id"); + DOMDataWriteTransaction tx = domDataBroker.newWriteOnlyTransaction(); + + for (int l = 0; l < outerListElem; l++) { + YangInstanceIdentifier yid = YangInstanceIdentifier.builder() + .node(TestExec.QNAME) + .node(OuterList.QNAME) + .nodeWithKey(OuterList.QNAME, OL_ID, l) + .build(); + + tx.delete(LogicalDatastoreType.CONFIGURATION, yid); + writeCnt++; + if (writeCnt == writesPerTx) { + try { + tx.submit().checkedGet(); + txOk++; + } catch (TransactionCommitFailedException e) { + LOG.error("Transaction failed: {}", e.toString()); + txError++; + } + tx = domDataBroker.newWriteOnlyTransaction(); + writeCnt = 0; + } + } + if (writeCnt != 0) { + try { + tx.submit().checkedGet(); + } catch (TransactionCommitFailedException e) { + LOG.error("Transaction failed: {}", e.toString()); + } + } + } + +} diff --git a/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/simpletx/SimpletxDomRead.java b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/simpletx/SimpletxDomRead.java new file mode 100644 index 0000000000..98f8c9f7a7 --- /dev/null +++ b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/simpletx/SimpletxDomRead.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.dsbenchmark.simpletx; + + +import com.google.common.base.Optional; +import com.google.common.util.concurrent.CheckedFuture; +import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; +import org.opendaylight.dsbenchmark.DatastoreAbstractWriter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public class SimpletxDomRead extends DatastoreAbstractWriter { + private static final Logger LOG = (Logger) LoggerFactory.getLogger(SimpletxDomRead.class); + private final DOMDataBroker domDataBroker; + + public SimpletxDomRead(DOMDataBroker domDataBroker, int outerListElem, + int innerListElem, long writesPerTx) { + super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx); + this.domDataBroker = domDataBroker; + LOG.info("Created simpleTxDomRead"); + + } + + @Override + public void createList() { + LOG.info("SimpletxDomRead: creating data in the data store"); + // Dump the whole list into the data store in a single transaction + // with PUTs on the transaction + SimpletxDomWrite dd = new SimpletxDomWrite(domDataBroker, + StartTestInput.Operation.PUT, + outerListElem, + innerListElem, + outerListElem); + dd.createList(); + dd.executeList(); + } + + @Override + public void executeList() { + org.opendaylight.yangtools.yang.common.QName OL_ID = QName.create(OuterList.QNAME, "id"); + DOMDataReadOnlyTransaction tx = domDataBroker.newReadOnlyTransaction(); + + for (long l = 0; l < outerListElem; l++) { + NormalizedNode ret = null; + + YangInstanceIdentifier yid = YangInstanceIdentifier.builder() + .node(TestExec.QNAME) + .node(OuterList.QNAME) + .nodeWithKey(OuterList.QNAME, OL_ID, l) + .build(); + Optional> optionalDataObject; + CheckedFuture>, ReadFailedException> submitFuture = tx.read(LogicalDatastoreType.CONFIGURATION, yid); + try { + optionalDataObject = submitFuture.checkedGet(); + if (optionalDataObject != null && optionalDataObject.isPresent()) { + ret = optionalDataObject.get(); + LOG.info("/n" + String.valueOf(ret)); + txOk++; + } + /*if (optionalDataObject != null && optionalDataObject.isPresent()) { + ret = optionalDataObject.get(); + + String[] objectsArray = new String[ret.getInnerList().size()]; + + //LOG.info("innerList element: " + objectsArray ); + for (InnerList innerList : ret.getInnerList()) { + if (objectsArray[innerList.getName()] != null) { + LOG.error("innerList: DUPLICATE name: {}, value: {}", innerList.getName(), innerList.getValue()); + } + objectsArray[innerList.getName()] = innerList.getValue(); + // LOG.info("innerList: name: {}, value: {}", innerList.getName(), innerList.getValue()); + } + boolean foundAll = true; + for (int i = 0; i < ret.getInnerList().size(); i++) { + String itemStr = objectsArray[i]; + if (!itemStr.contentEquals("Item-" + String.valueOf(l) + "-" + String.valueOf(i))) { + foundAll = false; + LOG.error("innerList: name: {}, value: {}", i, itemStr); + break; + } + } + txOk++; + }*/ else { + txError++; + LOG.info("In the else part"); + } + } catch (ReadFailedException e) { + LOG.warn("failed to ....", e); + txError++; + } + } + } + +} diff --git a/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/simpletx/SimpletxDomWrite.java b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/simpletx/SimpletxDomWrite.java new file mode 100644 index 0000000000..97dc900d00 --- /dev/null +++ b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/simpletx/SimpletxDomWrite.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2015 Cisco Systems and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.dsbenchmark.simpletx; + +import java.util.List; + +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; +import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; +import org.opendaylight.dsbenchmark.DatastoreAbstractWriter; +import org.opendaylight.dsbenchmark.DomListBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; +import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SimpletxDomWrite extends DatastoreAbstractWriter { + private static final Logger LOG = LoggerFactory.getLogger(SimpletxDomWrite.class); + private final DOMDataBroker domDataBroker; + private List list; + + public SimpletxDomWrite(DOMDataBroker domDataBroker, StartTestInput.Operation oper, + int outerListElem, int innerListElem, long putsPerTx ) { + super(oper, outerListElem, innerListElem, putsPerTx); + this.domDataBroker = domDataBroker; + LOG.info("Created SimpletxDomWrite"); + } + + @Override + public void createList() { + list = DomListBuilder.buildOuterList(this.outerListElem, this.innerListElem); + } + + @Override + public void executeList() { + DOMDataWriteTransaction tx = domDataBroker.newWriteOnlyTransaction(); + long writeCnt = 0; + + YangInstanceIdentifier pid = YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build(); + for (MapEntryNode element : this.list) { + YangInstanceIdentifier yid = pid.node(new NodeIdentifierWithPredicates(OuterList.QNAME, element.getIdentifier().getKeyValues())); + + if (oper == StartTestInput.Operation.PUT) { + tx.put(LogicalDatastoreType.CONFIGURATION, yid, element); + } else { + tx.merge(LogicalDatastoreType.CONFIGURATION, yid, element); + } + + writeCnt++; + + if (writeCnt == writesPerTx) { + try { + tx.submit().checkedGet(); + txOk++; + } catch (TransactionCommitFailedException e) { + LOG.error("Transaction failed", e); + txError++; + } + tx = domDataBroker.newWriteOnlyTransaction(); + writeCnt = 0; + } + } + + if (writeCnt != 0) { + try { + tx.submit().checkedGet(); + } catch (TransactionCommitFailedException e) { + LOG.error("Transaction failed", e); + } + } + + } + +} diff --git a/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/txchain/TxchainBaDelete.java b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/txchain/TxchainBaDelete.java new file mode 100644 index 0000000000..dd565fb945 --- /dev/null +++ b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/txchain/TxchainBaDelete.java @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2015 Cisco Systems and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.dsbenchmark.txchain; + +import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; +import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.TransactionChain; +import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; +import org.opendaylight.dsbenchmark.DatastoreAbstractWriter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterListKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; + +public class TxchainBaDelete extends DatastoreAbstractWriter implements TransactionChainListener{ + private static final Logger LOG = (Logger) LoggerFactory.getLogger(TxchainBaDelete.class); + private DataBroker bindingDataBroker; + + public TxchainBaDelete(DataBroker bindingDataBroker, int outerListElem, int innerListElem, long writesPerTx) { + super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx); + this.bindingDataBroker = bindingDataBroker; + LOG.info("Created TxchainBaDelete"); + } + + @Override + public void createList() { + LOG.info("TxchainBaDelete: creating data in the data store"); + + // Dump the whole list into the data store in a single transaction + // with PUTs on the transaction + TxchainBaWrite dd = new TxchainBaWrite(bindingDataBroker, + StartTestInput.Operation.PUT, + outerListElem, + innerListElem, + outerListElem); + dd.createList(); + dd.executeList(); + } + + @Override + public void executeList() { + int txSubmitted = 0; + int writeCnt = 0; + + BindingTransactionChain chain = bindingDataBroker.createTransactionChain(this); + WriteTransaction tx = chain.newWriteOnlyTransaction(); + + for (long l = 0; l < outerListElem; l++) { + InstanceIdentifier iid = InstanceIdentifier.create(TestExec.class) + .child(OuterList.class, new OuterListKey((int)l)); + tx.delete(LogicalDatastoreType.CONFIGURATION, iid); + + writeCnt++; + + if (writeCnt == writesPerTx) { + txSubmitted++; + Futures.addCallback(tx.submit(), new FutureCallback() { + @Override + public void onSuccess(final Void result) { + txOk++; + } + @Override + public void onFailure(final Throwable t) { + LOG.error("Transaction failed, {}", t); + txError++; + } + }); + tx = chain.newWriteOnlyTransaction(); + writeCnt = 0; + } + } + + // Submit the outstanding transaction even if it's empty and wait for it to finish + // We need to empty the chain before closing it + try { + if (writeCnt > 0) { + txSubmitted++; + } + tx.submit().checkedGet(); + } catch (TransactionCommitFailedException e) { + LOG.error("Transaction failed", e); + } + try { + chain.close(); + } + catch (IllegalStateException e){ + LOG.error("Transaction close failed,", e); + } + LOG.info("Transactions: submitted {}, completed {}", txSubmitted, (txOk + txError)); + } + + @Override + public void onTransactionChainFailed(TransactionChain chain, + AsyncTransaction transaction, Throwable cause) { + LOG.error("Broken chain {} in TxchainBaDelete, transaction {}, cause {}", + chain, transaction.getIdentifier(), cause); + } + + @Override + public void onTransactionChainSuccessful(TransactionChain chain) { + LOG.info("TxchainBaDelete closed successfully, chain {}", chain); + } + +} diff --git a/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/txchain/TxchainBaRead.java b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/txchain/TxchainBaRead.java new file mode 100644 index 0000000000..3763b89c74 --- /dev/null +++ b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/txchain/TxchainBaRead.java @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.dsbenchmark.txchain; + +import com.google.common.base.Optional; +import com.google.common.util.concurrent.CheckedFuture; +import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.ReadTransaction; +import org.opendaylight.controller.md.sal.common.api.data.*; +import org.opendaylight.dsbenchmark.DatastoreAbstractWriter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterListKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.outer.list.InnerList; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class TxchainBaRead extends DatastoreAbstractWriter implements TransactionChainListener{ + private static final Logger LOG = (Logger) LoggerFactory.getLogger(TxchainBaRead.class); + private DataBroker bindingDataBroker; + + public TxchainBaRead(DataBroker bindingDataBroker, int outerListElem, int innerListElem, long writesPerTx) { + super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx); + this.bindingDataBroker = bindingDataBroker; + LOG.info("Created TxchainBaRead"); + } + + @Override + public void createList() { + LOG.info("TxchainBaRead: reading data in the data store"); + + // Dump the whole list into the data store in a single transaction + // with PUTs on the transaction + TxchainBaWrite dd = new TxchainBaWrite(bindingDataBroker, + StartTestInput.Operation.PUT, + outerListElem, + innerListElem, + outerListElem); + dd.createList(); + dd.executeList(); + } + + @Override + public void executeList() { + + BindingTransactionChain chain = bindingDataBroker.createTransactionChain(this); + ReadTransaction tx = bindingDataBroker.newReadOnlyTransaction(); + + for (long l = 0; l < outerListElem; l++) { + + OuterList outerList; + InstanceIdentifier iid = InstanceIdentifier.create(TestExec.class) + .child(OuterList.class, new OuterListKey((int) l)); + Optional optionalDataObject; + CheckedFuture, ReadFailedException> submitFuture = tx.read(LogicalDatastoreType.CONFIGURATION, iid); + + try { + optionalDataObject = submitFuture.checkedGet(); + /*if (optionalDataObject != null && optionalDataObject.isPresent()) { + ret = optionalDataObject.get(); + txOk++; + }*/ + if (optionalDataObject != null && optionalDataObject.isPresent()) { + outerList = optionalDataObject.get(); + + String[] objectsArray = new String[outerList.getInnerList().size()]; + + //LOG.info("innerList element: " + objectsArray ); + for (InnerList innerList : outerList.getInnerList()) { + if (objectsArray[innerList.getName()] != null) { + LOG.error("innerList: DUPLICATE name: {}, value: {}", innerList.getName(), innerList.getValue()); + } + objectsArray[innerList.getName()] = innerList.getValue(); + // LOG.info("innerList: name: {}, value: {}", innerList.getName(), innerList.getValue()); + } + boolean foundAll = true; + for (int i = 0; i < outerList.getInnerList().size(); i++) { + String itemStr = objectsArray[i]; + if (!itemStr.contentEquals("Item-" + String.valueOf(l) + "-" + String.valueOf(i))) { + foundAll = false; + LOG.error("innerList: name: {}, value: {}", i, itemStr); + break; + } + } + txOk++; + } + else { + txError++; + } + } catch (ReadFailedException e) { + LOG.warn("failed to ....", e); + txError++; + } + } + } + + @Override + public void onTransactionChainFailed(TransactionChain chain, + AsyncTransaction transaction, Throwable cause) { + LOG.error("Broken chain {} in TxchainBaDelete, transaction {}, cause {}", + chain, transaction.getIdentifier(), cause); + } + + @Override + public void onTransactionChainSuccessful(TransactionChain chain) { + LOG.info("TxchainBaDelete closed successfully, chain {}", chain); + } + +} diff --git a/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/txchain/TxchainBaWrite.java b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/txchain/TxchainBaWrite.java new file mode 100644 index 0000000000..3c78de4b1a --- /dev/null +++ b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/txchain/TxchainBaWrite.java @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2015 Cisco Systems and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.dsbenchmark.txchain; + +import java.util.List; + +import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; +import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.TransactionChain; +import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; +import org.opendaylight.dsbenchmark.BaListBuilder; +import org.opendaylight.dsbenchmark.DatastoreAbstractWriter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput.Operation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; + +public class TxchainBaWrite extends DatastoreAbstractWriter implements TransactionChainListener { + private static final Logger LOG = LoggerFactory.getLogger(TxchainBaWrite.class); + private final DataBroker bindingDataBroker; + private List list; + + public TxchainBaWrite(DataBroker bindingDataBroker, Operation oper, + int outerListElem, int innerListElem, long writesPerTx) { + super(oper, outerListElem, innerListElem, writesPerTx); + this.bindingDataBroker = bindingDataBroker; + LOG.info("Created TxchainBaWrite"); + } + + @Override + public void createList() { + list = BaListBuilder.buildOuterList(this.outerListElem, this.innerListElem); + } + + @Override + public void executeList() { + int txSubmitted = 0; + int writeCnt = 0; + + BindingTransactionChain chain = bindingDataBroker.createTransactionChain(this); + WriteTransaction tx = chain.newWriteOnlyTransaction(); + + for (OuterList element : this.list) { + InstanceIdentifier iid = InstanceIdentifier.create(TestExec.class) + .child(OuterList.class, element.getKey()); + if (oper == StartTestInput.Operation.PUT) { + tx.put(LogicalDatastoreType.CONFIGURATION, iid, element); + } else { + tx.merge(LogicalDatastoreType.CONFIGURATION, iid, element); + } + + writeCnt++; + + if (writeCnt == writesPerTx) { + txSubmitted++; + Futures.addCallback(tx.submit(), new FutureCallback() { + @Override + public void onSuccess(final Void result) { + txOk++; + } + @Override + public void onFailure(final Throwable t) { + LOG.error("Transaction failed, {}", t); + txError++; + } + }); + tx = chain.newWriteOnlyTransaction(); + writeCnt = 0; + } + } + + // *** Clean up and close the transaction chain *** + // Submit the outstanding transaction even if it's empty and wait for it to finish + // We need to empty the transaction chain before closing it + try { + txSubmitted++; + tx.submit().checkedGet(); + txOk++; + } catch (TransactionCommitFailedException e) { + LOG.error("Transaction failed", e); + txError++; + } + try { + chain.close(); + } + catch (IllegalStateException e){ + LOG.error("Transaction close failed,", e); + } + LOG.info("Transactions: submitted {}, completed {}", txSubmitted, (txOk + txError)); + } + + @Override + public void onTransactionChainFailed(TransactionChain chain, + AsyncTransaction transaction, Throwable cause) { + LOG.error("Broken chain {} in DatastoreBaAbstractWrite, transaction {}, cause {}", + chain, transaction.getIdentifier(), cause); + } + + @Override + public void onTransactionChainSuccessful(TransactionChain chain) { + LOG.info("DatastoreBaAbstractWrite closed successfully, chain {}", chain); + } + +} \ No newline at end of file diff --git a/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/txchain/TxchainDomDelete.java b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/txchain/TxchainDomDelete.java new file mode 100644 index 0000000000..b1df83e46e --- /dev/null +++ b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/txchain/TxchainDomDelete.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2015 Cisco Systems and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.dsbenchmark.txchain; + +import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.TransactionChain; +import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; +import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; +import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain; +import org.opendaylight.dsbenchmark.DatastoreAbstractWriter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; + +public class TxchainDomDelete extends DatastoreAbstractWriter implements TransactionChainListener{ + private static final Logger LOG = LoggerFactory.getLogger(TxchainBaWrite.class); + private final DOMDataBroker domDataBroker; + + public TxchainDomDelete(DOMDataBroker domDataBroker, int outerListElem, int innerListElem, long writesPerTx) { + super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx); + this.domDataBroker = domDataBroker; + LOG.info("Created TxchainDomDelete"); + } + + @Override + public void createList() { + LOG.info("TxchainDomDelete: creating data in the data store"); + + // Dump the whole list into the data store in a single transaction + // with PUTs on the transaction + TxchainDomWrite dd = new TxchainDomWrite(domDataBroker, + StartTestInput.Operation.PUT, + outerListElem, + innerListElem, + outerListElem); + dd.createList(); + dd.executeList(); + } + + @Override + public void executeList() { + int txSubmitted = 0; + int writeCnt = 0; + + org.opendaylight.yangtools.yang.common.QName OL_ID = QName.create(OuterList.QNAME, "id"); + DOMTransactionChain chain = domDataBroker.createTransactionChain(this); + DOMDataWriteTransaction tx = chain.newWriteOnlyTransaction(); + + YangInstanceIdentifier pid = YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build(); + for (int l = 0; l < outerListElem; l++) { + YangInstanceIdentifier yid = pid.node(new NodeIdentifierWithPredicates(OuterList.QNAME, OL_ID, l)); + tx.delete(LogicalDatastoreType.CONFIGURATION, yid); + + writeCnt++; + + if (writeCnt == writesPerTx) { + txSubmitted++; + Futures.addCallback(tx.submit(), new FutureCallback() { + @Override + public void onSuccess(final Void result) { + txOk++; + } + @Override + public void onFailure(final Throwable t) { + LOG.error("Transaction failed, {}", t); + txError++; + } + }); + tx = chain.newWriteOnlyTransaction(); + writeCnt = 0; + } + } + + // *** Clean up and close the transaction chain *** + // Submit the outstanding transaction even if it's empty and wait for it to finish + // We need to empty the transaction chain before closing it + try { + txSubmitted++; + tx.submit().checkedGet(); + txOk++; + } catch (TransactionCommitFailedException e) { + LOG.error("Transaction failed", e); + txError++; + } + try { + chain.close(); + } + catch (IllegalStateException e){ + LOG.error("Transaction close failed,", e); + } + LOG.info("Transactions: submitted {}, completed {}", txSubmitted, (txOk + txError)); + } + + @Override + public void onTransactionChainFailed(TransactionChain chain, + AsyncTransaction transaction, Throwable cause) { + LOG.error("Broken chain {} in TxchainDomDelete, transaction {}, cause {}", + chain, transaction.getIdentifier(), cause); + } + + @Override + public void onTransactionChainSuccessful(TransactionChain chain) { + LOG.info("TxchainDomDelete closed successfully, chain {}", chain); + } +} diff --git a/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/txchain/TxchainDomRead.java b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/txchain/TxchainDomRead.java new file mode 100644 index 0000000000..208d21774f --- /dev/null +++ b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/txchain/TxchainDomRead.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.dsbenchmark.txchain; + +import com.google.common.base.Optional; +import com.google.common.util.concurrent.CheckedFuture; +import org.opendaylight.controller.md.sal.common.api.data.*; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; +import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction; +import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain; +import org.opendaylight.dsbenchmark.DatastoreAbstractWriter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; +import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class TxchainDomRead extends DatastoreAbstractWriter implements TransactionChainListener{ + private static final Logger LOG = LoggerFactory.getLogger(TxchainDomRead.class); + private final DOMDataBroker domDataBroker; + + public TxchainDomRead(DOMDataBroker domDataBroker, int outerListElem, int innerListElem, long writesPerTx) { + super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx); + this.domDataBroker = domDataBroker; + LOG.info("Created TxchainDomDelete"); + } + + @Override + public void createList() { + LOG.info("TxchainDomDelete: creating data in the data store"); + + // Dump the whole list into the data store in a single transaction + // with PUTs on the transaction + TxchainDomWrite dd = new TxchainDomWrite(domDataBroker, + StartTestInput.Operation.PUT, + outerListElem, + innerListElem, + outerListElem); + dd.createList(); + dd.executeList(); + } + + @Override + public void executeList() { + + org.opendaylight.yangtools.yang.common.QName OL_ID = QName.create(OuterList.QNAME, "id"); + DOMTransactionChain chain = domDataBroker.createTransactionChain(this); + DOMDataReadOnlyTransaction tx = domDataBroker.newReadOnlyTransaction(); + + YangInstanceIdentifier pid = YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build(); + for (int l = 0; l < outerListElem; l++) { + NormalizedNode ret; + YangInstanceIdentifier yid = pid.node(new NodeIdentifierWithPredicates(OuterList.QNAME, OL_ID, l)); + Optional> optionalDataObject; + CheckedFuture>, ReadFailedException> submitFuture = tx.read(LogicalDatastoreType.CONFIGURATION, yid); + try { + optionalDataObject = submitFuture.checkedGet(); + if (optionalDataObject != null && optionalDataObject.isPresent()) { + ret = optionalDataObject.get(); + txOk++; + } + } catch (ReadFailedException e) { + LOG.warn("failed to ....", e); + txError++; + } + } + + + } + + @Override + public void onTransactionChainFailed(TransactionChain chain, + AsyncTransaction transaction, Throwable cause) { + LOG.error("Broken chain {} in TxchainDomDelete, transaction {}, cause {}", + chain, transaction.getIdentifier(), cause); + } + + @Override + public void onTransactionChainSuccessful(TransactionChain chain) { + LOG.info("TxchainDomDelete closed successfully, chain {}", chain); + } +} diff --git a/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/txchain/TxchainDomWrite.java b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/txchain/TxchainDomWrite.java new file mode 100644 index 0000000000..f7a44d5f58 --- /dev/null +++ b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/txchain/TxchainDomWrite.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2015 Cisco Systems and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.dsbenchmark.txchain; + +import java.util.List; + +import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.TransactionChain; +import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; +import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; +import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain; +import org.opendaylight.dsbenchmark.DatastoreAbstractWriter; +import org.opendaylight.dsbenchmark.DomListBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; +import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; + +public class TxchainDomWrite extends DatastoreAbstractWriter implements TransactionChainListener { + private static final Logger LOG = LoggerFactory.getLogger(TxchainDomWrite.class); + private final DOMDataBroker domDataBroker; + private List list; + + public TxchainDomWrite(DOMDataBroker domDataBroker, StartTestInput.Operation oper, int outerListElem, + int innerListElem, long writesPerTx) { + super(oper, outerListElem, innerListElem, writesPerTx); + this.domDataBroker = domDataBroker; + LOG.info("Created TxchainDomWrite"); + } + + @Override + public void createList() { + list = DomListBuilder.buildOuterList(this.outerListElem, this.innerListElem); + } + + @Override + public void executeList() { + int txSubmitted = 0; + int writeCnt = 0; + + DOMTransactionChain chain = domDataBroker.createTransactionChain(this); + DOMDataWriteTransaction tx = chain.newWriteOnlyTransaction(); + + YangInstanceIdentifier pid = YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build(); + for (MapEntryNode element : this.list) { + YangInstanceIdentifier yid = pid.node(new NodeIdentifierWithPredicates(OuterList.QNAME, element.getIdentifier().getKeyValues())); + + if (oper == StartTestInput.Operation.PUT) { + tx.put(LogicalDatastoreType.CONFIGURATION, yid, element); + } else { + tx.merge(LogicalDatastoreType.CONFIGURATION, yid, element); + } + + writeCnt++; + + if (writeCnt == writesPerTx) { + txSubmitted++; + Futures.addCallback(tx.submit(), new FutureCallback() { + @Override + public void onSuccess(final Void result) { + txOk++; + } + @Override + public void onFailure(final Throwable t) { + LOG.error("Transaction failed, {}", t); + txError++; + } + }); + tx = chain.newWriteOnlyTransaction(); + writeCnt = 0; + } + } + + // *** Clean up and close the transaction chain *** + // Submit the outstanding transaction even if it's empty and wait for it to finish + // We need to empty the transaction chain before closing it + try { + txSubmitted++; + tx.submit().checkedGet(); + txOk++; + } catch (TransactionCommitFailedException e) { + LOG.error("Transaction failed", e); + txError++; + } + try { + chain.close(); + } + catch (IllegalStateException e){ + LOG.error("Transaction close failed,", e); + } + LOG.info("Transactions: submitted {}, completed {}", txSubmitted, (txOk + txError)); + } + + @Override + public void onTransactionChainFailed(TransactionChain chain, + AsyncTransaction transaction, Throwable cause) { + LOG.error("Broken chain {} in TxchainDomWrite, transaction {}, cause {}", + chain, transaction.getIdentifier(), cause); + } + + @Override + public void onTransactionChainSuccessful(TransactionChain chain) { + LOG.info("Chain {} closed successfully", chain); + } + +} diff --git a/benchmark/dsbenchmark/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/dsbenchmark/impl/rev141210/DsbenchmarkImplModule.java b/benchmark/dsbenchmark/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/dsbenchmark/impl/rev141210/DsbenchmarkImplModule.java new file mode 100644 index 0000000000..82d1270677 --- /dev/null +++ b/benchmark/dsbenchmark/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/dsbenchmark/impl/rev141210/DsbenchmarkImplModule.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2015 Cisco Systems and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.impl.rev141210; + +import org.opendaylight.dsbenchmark.DsbenchmarkProvider; + +public class DsbenchmarkImplModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.impl.rev141210.AbstractDsbenchmarkImplModule { + public DsbenchmarkImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + super(identifier, dependencyResolver); + } + + public DsbenchmarkImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.impl.rev141210.DsbenchmarkImplModule oldModule, java.lang.AutoCloseable oldInstance) { + super(identifier, dependencyResolver, oldModule, oldInstance); + } + + @Override + public void customValidation() { + // add custom validation form module attributes here. + } + + @Override + public java.lang.AutoCloseable createInstance() { + DsbenchmarkProvider provider = new DsbenchmarkProvider(getDomDataBrokerDependency(), + getBindingDataBrokerDependency()); + getBrokerDependency().registerProvider(provider); + return provider; + } + +} diff --git a/benchmark/dsbenchmark/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/dsbenchmark/impl/rev141210/DsbenchmarkImplModuleFactory.java b/benchmark/dsbenchmark/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/dsbenchmark/impl/rev141210/DsbenchmarkImplModuleFactory.java new file mode 100644 index 0000000000..f3a89a0702 --- /dev/null +++ b/benchmark/dsbenchmark/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/dsbenchmark/impl/rev141210/DsbenchmarkImplModuleFactory.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2015 Cisco Systems and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +/* +* Generated file +* +* Generated from: yang module name: dsbenchmark yang module local name: dsbenchmark +* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator +* Generated at: Fri Jan 02 13:49:24 CST 2015 +* +* Do not modify this file unless it is present under src/main directory +*/ +package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.impl.rev141210; +public class DsbenchmarkImplModuleFactory extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.impl.rev141210.AbstractDsbenchmarkImplModuleFactory { + +} diff --git a/benchmark/dsbenchmark/src/main/yang/dsbenchmark-impl.yang b/benchmark/dsbenchmark/src/main/yang/dsbenchmark-impl.yang new file mode 100644 index 0000000000..d7053c1115 --- /dev/null +++ b/benchmark/dsbenchmark/src/main/yang/dsbenchmark-impl.yang @@ -0,0 +1,52 @@ +module dsbenchmark-impl { + yang-version 1; + namespace "urn:opendaylight:params:xml:ns:yang:dsbenchmark:impl"; + prefix "dsbenchmark-impl"; + + import config { prefix config; revision-date 2013-04-05; } + import opendaylight-md-sal-binding { prefix md-sal-binding; revision-date 2013-10-28;} + import opendaylight-md-sal-dom { prefix md-sal-dom; revision-date 2013-10-28;} + + description + "Service definition for dsbenchmark project"; + + revision "2014-12-10" { + description + "Initial revision"; + } + + identity dsbenchmark-impl { + base config:module-type; + config:java-name-prefix DsbenchmarkImpl; + } + + augment "/config:modules/config:module/config:configuration" { + case dsbenchmark-impl { + when "/config:modules/config:module/config:type = 'dsbenchmark-impl'"; + container broker { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity md-sal-binding:binding-broker-osgi-registry; + } + } + } + container dom-data-broker { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity md-sal-dom:dom-async-data-broker; + } + } + } + container binding-data-broker { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity md-sal-binding:binding-async-data-broker; + } + } + } + } + } +} diff --git a/benchmark/pom.xml b/benchmark/pom.xml new file mode 100644 index 0000000000..107eca4f88 --- /dev/null +++ b/benchmark/pom.xml @@ -0,0 +1,23 @@ + + + + org.opendaylight.controller + benchmark-aggregator + 1.1.0-SNAPSHOT + ${project.artifactId} + pom + 4.0.0 + + 3.1.1 + + + api + dsbenchmark + artifacts + + diff --git a/features/benchmark/pom.xml b/features/benchmark/pom.xml new file mode 100644 index 0000000000..ed99085c7e --- /dev/null +++ b/features/benchmark/pom.xml @@ -0,0 +1,83 @@ + + + + + org.opendaylight.odlparent + features-parent + 1.6.0-SNAPSHOT + + + org.opendaylight.controller + benchmark-features + 1.1.0-SNAPSHOT + ${project.artifactId} + 4.0.0 + + 3.1.1 + + + + 1.3.0-SNAPSHOT + 2.0.0-SNAPSHOT + 0.8.0-SNAPSHOT + 0.8.0-SNAPSHOT + 04-xsql.xml + + + + + org.opendaylight.yangtools + features-yangtools + features + ${yangtools.version} + xml + runtime + + + org.opendaylight.mdsal + features-mdsal + ${mdsal.version} + features + xml + runtime + + + org.opendaylight.mdsal.model + features-mdsal-model + ${mdsal.model.version} + features + xml + runtime + + + org.opendaylight.controller + features-mdsal + features + ${controller.mdsal.version} + xml + runtime + + + ${project.groupId} + dsbenchmark + ${project.version} + + + ${project.groupId} + dsbenchmark + ${project.version} + xml + config + + + ${project.groupId} + benchmark-api + ${project.version} + + + diff --git a/features/benchmark/src/main/features/features.xml b/features/benchmark/src/main/features/features.xml new file mode 100644 index 0000000000..55e60e57bc --- /dev/null +++ b/features/benchmark/src/main/features/features.xml @@ -0,0 +1,27 @@ + + + + + mvn:org.opendaylight.yangtools/features-yangtools/{{VERSION}}/xml/features + mvn:org.opendaylight.controller/features-mdsal/{{VERSION}}/xml/features + mvn:org.opendaylight.mdsal.model/features-mdsal-model/{{VERSION}}/xml/features + + + odl-mdsal-models + mvn:org.opendaylight.controller/benchmark-api/{{VERSION}} + + + odl-mdsal-broker + odl-benchmark-api + mvn:org.opendaylight.controller/dsbenchmark/{{VERSION}} + mvn:org.opendaylight.controller/dsbenchmark/{{VERSION}}/xml/config + + diff --git a/features/pom.xml b/features/pom.xml index c03e7cf9f7..fcdfdbe5c1 100644 --- a/features/pom.xml +++ b/features/pom.xml @@ -18,5 +18,6 @@ protocol-framework akka extras + benchmark diff --git a/pom.xml b/pom.xml index 822d29ac46..9ea0abd1c9 100644 --- a/pom.xml +++ b/pom.xml @@ -32,6 +32,7 @@ opendaylight/commons/filter-valve opendaylight/commons/liblldp opendaylight/commons/enunciate-parent + benchmark karaf