Bug 6348 : car:stop-stress-test RPC to return success & failure counters 59/43259/5
authorSai MarapaReddy <sai.marapareddy@gmail.com>
Tue, 19 Jul 2016 20:49:21 +0000 (13:49 -0700)
committerTom Pantelis <tpanteli@brocade.com>
Tue, 9 Aug 2016 14:39:41 +0000 (14:39 +0000)
Current RPC car:stop-stress-test doesn't return how many
cars are created or failed. Adding success and failure counters
will help user to determine the number of cars created or failed
during the the process of creation of car tests using
car:stress-test. This patch enhances car:stop-stress-test RPC.

Change-Id: Iff054c8210ce49f06b4fa96ca5a437d9b82deddb
Signed-off-by: Sai MarapaReddy <sai.marapareddy@gmail.com>
Author: Sai MarapaReddy <sai.marapareddy@gmail.com>

opendaylight/md-sal/samples/clustering-test-app/model/src/main/yang/car.yang
opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/CarProvider.java

index 2d552f4..14f12e4 100644 (file)
@@ -80,7 +80,19 @@ module car {
     }
     
     rpc stop-stress-test {
+        output {
+            leaf success-count {
+              type uint32;
+              default 0;
+              description "Total number of cars created when running stess-test rpc";
+            }
 
+            leaf failure-count {
+              type uint32;
+              default 0;
+              description "Total number of cars failed when running stess-test rpc";
+            }
+        }
     }
 
     rpc register-ownership {
index 2dfb32b..69535f7 100644 (file)
@@ -9,6 +9,8 @@ package org.opendaylight.controller.clustering.it.provider;
 
 import com.google.common.base.Stopwatch;
 import com.google.common.collect.Sets;
+import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import java.util.Collection;
 import java.util.concurrent.Future;
@@ -33,6 +35,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controll
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.Cars;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.CarsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.RegisterOwnershipInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.StopStressTestOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.StopStressTestOutputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.StressTestInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.UnregisterOwnershipInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.cars.CarEntry;
@@ -57,6 +61,9 @@ public class CarProvider implements CarService {
 
     private static final String ENTITY_TYPE = "cars";
 
+    private AtomicLong succcessCounter = new AtomicLong();
+    private AtomicLong failureCounter = new AtomicLong();
+
     private final CarEntityOwnershipListener ownershipListener = new CarEntityOwnershipListener();
     private final AtomicBoolean registeredListener = new AtomicBoolean();
 
@@ -97,8 +104,8 @@ public class CarProvider implements CarService {
         if ((input.getRate() == null) || (input.getRate() == 0)) {
             log.info("Exiting stress test as no rate is given.");
             return Futures.immediateFuture(RpcResultBuilder.<Void>failed()
-                                           .withError(ErrorType.PROTOCOL, "invalid rate")
-                                           .build());
+                    .withError(ErrorType.PROTOCOL, "invalid rate")
+                    .build());
         } else {
             inputRate = input.getRate();
         }
@@ -112,6 +119,9 @@ public class CarProvider implements CarService {
         log.info("Stress test starting : rate: {} count: {}", inputRate, inputCount);
 
         stopThread();
+        // clear counters
+        succcessCounter.set(0);
+        failureCounter.set(0);
 
         WriteTransaction tx = dataProvider.newWriteOnlyTransaction();
         InstanceIdentifier<Cars> carsId = InstanceIdentifier.<Cars>builder(Cars.class).build();
@@ -138,7 +148,22 @@ public class CarProvider implements CarService {
                     tx.put(LogicalDatastoreType.CONFIGURATION,
                             InstanceIdentifier.<Cars>builder(Cars.class).child(CarEntry.class, car.getKey()).build(),
                             car);
-                    tx.submit();
+                    CheckedFuture<Void, TransactionCommitFailedException> future =  tx.submit();
+                    Futures.addCallback(future, new FutureCallback<Void>() {
+
+                        @Override
+                        public void onSuccess(final Void result) {
+                            // Transaction succeeded
+                            succcessCounter.getAndIncrement();
+                        }
+
+                        @Override
+                        public void onFailure(final Throwable t) {
+                            // Transaction failed
+                            failureCounter.getAndIncrement();
+                            LOG.error("Put Cars failed", t);
+                        }
+                    });
                     try {
                         TimeUnit.NANOSECONDS.sleep(sleep);
                     } catch (InterruptedException e) {
@@ -164,9 +189,20 @@ public class CarProvider implements CarService {
     }
 
     @Override
-    public Future<RpcResult<Void>> stopStressTest() {
+    public Future<RpcResult<StopStressTestOutput>> stopStressTest() {
         stopThread();
-        return Futures.immediateFuture(RpcResultBuilder.<Void>success().build());
+        StopStressTestOutputBuilder stopStressTestOutput;
+        stopStressTestOutput = new StopStressTestOutputBuilder()
+                .setSuccessCount(succcessCounter.longValue())
+                .setFailureCount(failureCounter.longValue());
+
+        StopStressTestOutput result = stopStressTestOutput.build();
+        log.info("Executed Stop Stress test; No. of cars created {}; " +
+                "No. of cars failed {}; ", succcessCounter, failureCounter);
+        // clear counters
+        succcessCounter.set(0);
+        failureCounter.set(0);
+        return Futures.immediateFuture(RpcResultBuilder.<StopStressTestOutput>success(result).build());
     }