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>
+ 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 {
}
rpc register-ownership {
import com.google.common.base.Stopwatch;
import com.google.common.collect.Sets;
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;
import com.google.common.util.concurrent.Futures;
import java.util.Collection;
import java.util.concurrent.Future;
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.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;
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;
private static final String ENTITY_TYPE = "cars";
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();
private final CarEntityOwnershipListener ownershipListener = new CarEntityOwnershipListener();
private final AtomicBoolean registeredListener = new AtomicBoolean();
if ((input.getRate() == null) || (input.getRate() == 0)) {
log.info("Exiting stress test as no rate is given.");
return Futures.immediateFuture(RpcResultBuilder.<Void>failed()
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();
}
} else {
inputRate = input.getRate();
}
log.info("Stress test starting : rate: {} count: {}", inputRate, inputCount);
stopThread();
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();
WriteTransaction tx = dataProvider.newWriteOnlyTransaction();
InstanceIdentifier<Cars> carsId = InstanceIdentifier.<Cars>builder(Cars.class).build();
tx.put(LogicalDatastoreType.CONFIGURATION,
InstanceIdentifier.<Cars>builder(Cars.class).child(CarEntry.class, car.getKey()).build(),
car);
tx.put(LogicalDatastoreType.CONFIGURATION,
InstanceIdentifier.<Cars>builder(Cars.class).child(CarEntry.class, car.getKey()).build(),
car);
+ 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) {
try {
TimeUnit.NANOSECONDS.sleep(sleep);
} catch (InterruptedException e) {
- public Future<RpcResult<Void>> stopStressTest() {
+ public Future<RpcResult<StopStressTestOutput>> stopStressTest() {
- 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());