Make Netty-3 dependency optional
[controller.git] / benchmark / dsbenchmark / src / main / java / org / opendaylight / dsbenchmark / DsbenchmarkProvider.java
index 0bcc5811844d4c8fdecf2682d9b9441067903350..32f849596e16ca52f84959b89a92fdc704ec981b 100644 (file)
@@ -35,10 +35,11 @@ import org.opendaylight.mdsal.binding.api.RpcProviderService;
 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.CleanupStore;
 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.StartTest;
 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;
@@ -63,17 +64,17 @@ import org.slf4j.LoggerFactory;
 @Singleton
 @Component(service = { })
 @RequireServiceComponentRuntime
-public final class DsbenchmarkProvider implements DsbenchmarkService, AutoCloseable {
+public final class DsbenchmarkProvider implements AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(DsbenchmarkProvider.class);
-    private static final InstanceIdentifier<TestExec> TEST_EXEC_IID =
-            InstanceIdentifier.builder(TestExec.class).build();
-    private static final InstanceIdentifier<TestStatus> TEST_STATUS_IID =
-            InstanceIdentifier.builder(TestStatus.class).build();
+    private static final InstanceIdentifier<TestExec> TEST_EXEC_IID = InstanceIdentifier.create(TestExec.class);
+    private static final InstanceIdentifier<TestStatus> TEST_STATUS_IID = InstanceIdentifier.create(TestStatus.class);
 
     private final AtomicReference<ExecStatus> execStatus = new AtomicReference<>(ExecStatus.Idle);
     private final DsbenchmarkListenerProvider listenerProvider;
-    private final DOMDataBroker domDataBroker;  // Async DOM Broker for use with all DOM operations
-    private final DataBroker dataBroker; // Async Binding-Aware Broker for use in tx chains
+    // Async DOM Broker for use with all DOM operations
+    private final DOMDataBroker domDataBroker;
+    // Async Binding-Aware Broker for use in tx chains;
+    private final DataBroker dataBroker;
     private final Registration rpcReg;
 
     private long testsCompleted = 0;
@@ -95,7 +96,7 @@ public final class DsbenchmarkProvider implements DsbenchmarkService, AutoClosea
             LOG.warn("Working around Bugs 8829 and 6793 by ignoring exception from setTestOperData", e);
         }
 
-        rpcReg = rpcService.registerRpcImplementation(DsbenchmarkService.class, this);
+        rpcReg = rpcService.registerRpcImplementations((StartTest) this::startTest, (CleanupStore) this::cleanupStore);
         LOG.info("DsbenchmarkProvider initiated");
     }
 
@@ -107,24 +108,22 @@ public final class DsbenchmarkProvider implements DsbenchmarkService, AutoClosea
         LOG.info("DsbenchmarkProvider closed");
     }
 
-    @Override
-    public ListenableFuture<RpcResult<CleanupStoreOutput>> cleanupStore(final CleanupStoreInput input) {
+    private ListenableFuture<RpcResult<CleanupStoreOutput>> cleanupStore(final CleanupStoreInput input) {
         cleanupTestStore();
         LOG.debug("Data Store cleaned up");
         return Futures.immediateFuture(RpcResultBuilder.success(new CleanupStoreOutputBuilder().build()).build());
     }
 
-    @Override
     @SuppressWarnings("checkstyle:illegalCatch")
-    public ListenableFuture<RpcResult<StartTestOutput>> startTest(final StartTestInput input) {
+    private ListenableFuture<RpcResult<StartTestOutput>> 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)) {
             LOG.info("Test in progress");
             return RpcResultBuilder.success(new StartTestOutputBuilder()
-                    .setStatus(StartTestOutput.Status.TESTINPROGRESS)
-                    .build()).buildFuture();
+                .setStatus(StartTestOutput.Status.TESTINPROGRESS)
+                .build()).buildFuture();
         }
 
         // Cleanup data that may be left over from a previous test run
@@ -153,11 +152,11 @@ public final class DsbenchmarkProvider implements DsbenchmarkService, AutoClosea
             testsCompleted++;
 
         } catch (final Exception e) {
-            LOG.error("Test error: {}", e.toString());
+            LOG.error("Test error", e);
             execStatus.set(ExecStatus.Idle);
             return RpcResultBuilder.success(new StartTestOutputBuilder()
-                    .setStatus(StartTestOutput.Status.FAILED)
-                    .build()).buildFuture();
+                .setStatus(StartTestOutput.Status.FAILED)
+                .build()).buildFuture();
         }
 
         LOG.info("Test finished");
@@ -249,43 +248,37 @@ public final class DsbenchmarkProvider implements DsbenchmarkService, AutoClosea
                         retVal = new SimpletxBaWrite(dataBroker, oper, outerListElem,
                                 innerListElem, writesPerTx, dataStore);
                     }
+                } else if (StartTestInput.Operation.DELETE == oper) {
+                    retVal = new SimpletxDomDelete(domDataBroker, outerListElem,
+                            innerListElem, writesPerTx, dataStore);
+                } else if (StartTestInput.Operation.READ == oper) {
+                    retVal = new SimpletxDomRead(domDataBroker, outerListElem,
+                            innerListElem, writesPerTx, dataStore);
                 } else {
-                    if (StartTestInput.Operation.DELETE == oper) {
-                        retVal = new SimpletxDomDelete(domDataBroker, outerListElem,
-                                innerListElem, writesPerTx, dataStore);
-                    } else if (StartTestInput.Operation.READ == oper) {
-                        retVal = new SimpletxDomRead(domDataBroker, outerListElem,
-                                innerListElem, writesPerTx, dataStore);
-                    } else {
-                        retVal = new SimpletxDomWrite(domDataBroker, oper, outerListElem,
-                                innerListElem, writesPerTx, dataStore);
-                    }
+                    retVal = new SimpletxDomWrite(domDataBroker, oper, outerListElem,
+                            innerListElem, writesPerTx, dataStore);
                 }
-            } else {
-                if (dataFormat == StartTestInput.DataFormat.BINDINGAWARE) {
-                    if (StartTestInput.Operation.DELETE == oper) {
-                        retVal = new TxchainBaDelete(dataBroker, outerListElem,
-                                innerListElem, writesPerTx, dataStore);
-                    } else if (StartTestInput.Operation.READ == oper) {
-                        retVal = new TxchainBaRead(dataBroker, outerListElem,
-                                innerListElem,writesPerTx, dataStore);
-                    } else {
-                        retVal = new TxchainBaWrite(dataBroker, oper, outerListElem,
-                                innerListElem, writesPerTx, dataStore);
-                    }
+            } else if (dataFormat == StartTestInput.DataFormat.BINDINGAWARE) {
+                if (StartTestInput.Operation.DELETE == oper) {
+                    retVal = new TxchainBaDelete(dataBroker, outerListElem,
+                            innerListElem, writesPerTx, dataStore);
+                } else if (StartTestInput.Operation.READ == oper) {
+                    retVal = new TxchainBaRead(dataBroker, outerListElem,
+                            innerListElem,writesPerTx, dataStore);
                 } else {
-                    if (StartTestInput.Operation.DELETE == oper) {
-                        retVal = new TxchainDomDelete(domDataBroker, outerListElem,
-                                innerListElem, writesPerTx, dataStore);
-                    } else if (StartTestInput.Operation.READ == oper) {
-                        retVal = new TxchainDomRead(domDataBroker, outerListElem,
-                                innerListElem, writesPerTx, dataStore);
-
-                    } else {
-                        retVal = new TxchainDomWrite(domDataBroker, oper, outerListElem,
-                                innerListElem,writesPerTx, dataStore);
-                    }
+                    retVal = new TxchainBaWrite(dataBroker, oper, outerListElem,
+                            innerListElem, writesPerTx, dataStore);
                 }
+            } else if (StartTestInput.Operation.DELETE == oper) {
+                retVal = new TxchainDomDelete(domDataBroker, outerListElem,
+                        innerListElem, writesPerTx, dataStore);
+            } else if (StartTestInput.Operation.READ == oper) {
+                retVal = new TxchainDomRead(domDataBroker, outerListElem,
+                        innerListElem, writesPerTx, dataStore);
+
+            } else {
+                retVal = new TxchainDomWrite(domDataBroker, oper, outerListElem,
+                        innerListElem,writesPerTx, dataStore);
             }
         } finally {
             execStatus.set(ExecStatus.Idle);