X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=benchmark%2Fdsbenchmark%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fdsbenchmark%2FDsbenchmarkProvider.java;h=c5232a2b79f6fbef55d5df02ad7bf55e33dad652;hb=0b283e62a5872be1960635d5d6c4d301b1f87df2;hp=b46089d30fd9336b466a26d736463567d5235bed;hpb=625723b875800d5c421061f09cd5f387ccb59e62;p=controller.git diff --git a/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/DsbenchmarkProvider.java b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/DsbenchmarkProvider.java index b46089d30f..c5232a2b79 100644 --- a/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/DsbenchmarkProvider.java +++ b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/DsbenchmarkProvider.java @@ -7,18 +7,11 @@ */ package org.opendaylight.dsbenchmark; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; import java.util.Collections; -import java.util.concurrent.Future; +import java.util.concurrent.ExecutionException; 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.listener.DsbenchmarkListenerProvider; import org.opendaylight.dsbenchmark.simpletx.SimpletxBaDelete; import org.opendaylight.dsbenchmark.simpletx.SimpletxBaRead; @@ -32,6 +25,13 @@ 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.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.api.WriteTransaction; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.mdsal.dom.api.DOMDataBroker; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.CleanupStoreInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.CleanupStoreOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.CleanupStoreOutputBuilder; 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; @@ -48,9 +48,7 @@ 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 { +public class DsbenchmarkProvider implements DsbenchmarkService, AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(DsbenchmarkProvider.class); private static final InstanceIdentifier TEST_EXEC_IID = @@ -58,53 +56,52 @@ public class DsbenchmarkProvider implements BindingAwareProvider, DsbenchmarkSer private static final InstanceIdentifier TEST_STATUS_IID = InstanceIdentifier.builder(TestStatus.class).build(); - private final AtomicReference execStatus = new AtomicReference( ExecStatus.Idle ); + private final AtomicReference execStatus = new AtomicReference<>(ExecStatus.Idle); private final DsbenchmarkListenerProvider listenerProvider = new DsbenchmarkListenerProvider(); private final DOMDataBroker domDataBroker; // Async DOM Broker for use with all DOM operations - private final DataBroker bindingDataBroker; // Async Binding-Aware Broker for use in tx chains; initialized to - // ping-pong broker in default config (see default-config.xml and - // dsbenchmark-impl.yang) - private DataBroker dataBroker; // "Legacy" OSGI Data Broker for use in simple transactions - private RpcRegistration dstReg; + private final DataBroker dataBroker; // Async Binding-Aware Broker for use in tx chains 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 + public DsbenchmarkProvider(final DOMDataBroker domDataBroker, final DataBroker dataBroker) { this.domDataBroker = domDataBroker; - this.bindingDataBroker = bindingDataBroker; + this.dataBroker = dataBroker; } - @Override - public void onSessionInitiated(ProviderContext session) { - this.dataBroker = session.getSALService(DataBroker.class); - this.dstReg = session.addRpcImplementation( DsbenchmarkService.class, this ); + @SuppressWarnings("checkstyle:illegalCatch") + public void init() { listenerProvider.setDataBroker(dataBroker); - setTestOperData(this.execStatus.get(), testsCompleted); - LOG.info("DsbenchmarkProvider Session Initiated"); + try { + // We want to set the initial operation status so users can detect we are ready to start test. + setTestOperData(this.execStatus.get(), testsCompleted); + } catch (final Exception e) { + // TODO: Use a singleton service to make sure the initial write is performed only once. + LOG.warn("Working around Bugs 8829 and 6793 by ignoring exception from setTestOperData: {}", e); + } + + LOG.info("DsbenchmarkProvider initiated"); } @Override - public void close() throws Exception { - dstReg.close(); - LOG.info("DsbenchmarkProvider Closed"); + public void close() { + LOG.info("DsbenchmarkProvider closed"); } @Override - public Future> cleanupStore() { + public ListenableFuture> cleanupStore(final CleanupStoreInput input) { cleanupTestStore(); - LOG.info("Data Store cleaned up"); - return Futures.immediateFuture( RpcResultBuilder.success().build()); + LOG.debug("Data Store cleaned up"); + return Futures.immediateFuture(RpcResultBuilder.success(new CleanupStoreOutputBuilder().build()).build()); } @Override - public Future> startTest(StartTestInput input) { + @SuppressWarnings("checkstyle:illegalCatch") + public ListenableFuture> startTest(final 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 ) { + if (execStatus.compareAndSet(ExecStatus.Idle, ExecStatus.Executing) == false) { LOG.info("Test in progress"); return RpcResultBuilder.success(new StartTestOutputBuilder() .setStatus(StartTestOutput.Status.TESTINPROGRESS) @@ -120,14 +117,14 @@ public class DsbenchmarkProvider implements BindingAwareProvider, DsbenchmarkSer // Create listeners on OPERATIONAL and CONFIG test data subtrees listenerProvider.createAndRegisterListeners(input.getListeners().intValue()); - long startTime, endTime, listCreateTime, execTime; - startTime = System.nanoTime(); + long startTime = System.nanoTime(); dsWriter.createList(); - endTime = System.nanoTime(); - listCreateTime = (endTime - startTime) / 1000; + long endTime = System.nanoTime(); + final long listCreateTime = (endTime - startTime) / 1000; // Run the test and measure the execution time + long execTime; try { startTime = System.nanoTime(); dsWriter.executeList(); @@ -136,16 +133,16 @@ public class DsbenchmarkProvider implements BindingAwareProvider, DsbenchmarkSer this.testsCompleted++; - } catch (Exception e) { - LOG.error( "Test error: {}", e.toString()); - execStatus.set( ExecStatus.Idle ); + } catch (final 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); + setTestOperData(ExecStatus.Idle, testsCompleted); execStatus.set(ExecStatus.Idle); // Get the number of data change events and cleanup the data change listeners @@ -165,7 +162,7 @@ public class DsbenchmarkProvider implements BindingAwareProvider, DsbenchmarkSer return RpcResultBuilder.success(output).buildFuture(); } - private void setTestOperData( ExecStatus sts, long tstCompl ) { + private void setTestOperData(final ExecStatus sts, final long tstCompl) { TestStatus status = new TestStatusBuilder() .setExecStatus(sts) .setTestsCompleted(tstCompl) @@ -175,12 +172,12 @@ public class DsbenchmarkProvider implements BindingAwareProvider, DsbenchmarkSer tx.put(LogicalDatastoreType.OPERATIONAL, TEST_STATUS_IID, status); try { - tx.submit().checkedGet(); - } catch (TransactionCommitFailedException e) { + tx.commit().get(); + } catch (final InterruptedException | ExecutionException e) { throw new IllegalStateException(e); } - LOG.info("DataStore test oper status populated: {}", status); + LOG.debug("DataStore test oper status populated: {}", status); } private void cleanupTestStore() { @@ -191,9 +188,9 @@ public class DsbenchmarkProvider implements BindingAwareProvider, DsbenchmarkSer WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); tx.put(LogicalDatastoreType.CONFIGURATION, TEST_EXEC_IID, data); try { - tx.submit().checkedGet(); - LOG.info("DataStore config test data cleaned up"); - } catch (TransactionCommitFailedException e) { + tx.commit().get(); + LOG.debug("DataStore config test data cleaned up"); + } catch (final InterruptedException | ExecutionException e) { LOG.info("Failed to cleanup DataStore configtest data"); throw new IllegalStateException(e); } @@ -201,16 +198,16 @@ public class DsbenchmarkProvider implements BindingAwareProvider, DsbenchmarkSer tx = dataBroker.newWriteOnlyTransaction(); tx.put(LogicalDatastoreType.OPERATIONAL, TEST_EXEC_IID, data); try { - tx.submit().checkedGet(); - LOG.info("DataStore operational test data cleaned up"); - } catch (TransactionCommitFailedException e) { + tx.commit().get(); + LOG.debug("DataStore operational test data cleaned up"); + } catch (final InterruptedException | ExecutionException e) { LOG.info("Failed to cleanup DataStore operational test data"); throw new IllegalStateException(e); } } - private DatastoreAbstractWriter getDatastoreWriter(StartTestInput input) { + private DatastoreAbstractWriter getDatastoreWriter(final StartTestInput input) { final DatastoreAbstractWriter retVal; @@ -250,13 +247,13 @@ public class DsbenchmarkProvider implements BindingAwareProvider, DsbenchmarkSer } else { if (dataFormat == StartTestInput.DataFormat.BINDINGAWARE) { if (StartTestInput.Operation.DELETE == oper) { - retVal = new TxchainBaDelete(this.bindingDataBroker, outerListElem, + retVal = new TxchainBaDelete(this.dataBroker, outerListElem, innerListElem, writesPerTx, dataStore); } else if (StartTestInput.Operation.READ == oper) { - retVal = new TxchainBaRead(this.bindingDataBroker,outerListElem, + retVal = new TxchainBaRead(this.dataBroker, outerListElem, innerListElem,writesPerTx, dataStore); } else { - retVal = new TxchainBaWrite(this.bindingDataBroker, oper, outerListElem, + retVal = new TxchainBaWrite(this.dataBroker, oper, outerListElem, innerListElem, writesPerTx, dataStore); } } else {