X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsamples%2Fclustering-test-app%2Fprovider%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fclustering%2Fit%2Fprovider%2FCarProvider.java;h=3f8bff0992709710bcfac271f4b1d5ef455805e6;hb=0cb5ce07fc959deed2e7887ed22dfde81cb2c9a2;hp=a6f154bfcde7282b7b0bdb6c0d5a7166bdbd3238;hpb=634dfac8eead60f443bf75e749c70d1f2bb29198;p=controller.git diff --git a/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/CarProvider.java b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/CarProvider.java index a6f154bfcd..3f8bff0992 100644 --- a/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/CarProvider.java +++ b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/CarProvider.java @@ -8,26 +8,28 @@ 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.FutureCallback; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.MoreExecutors; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import java.util.Collection; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier; -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.md.sal.dom.api.DOMDataTreeCommitCohortRegistry; +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.api.DataTreeIdentifier; +import org.opendaylight.mdsal.binding.api.WriteTransaction; +import org.opendaylight.mdsal.common.api.CommitInfo; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.mdsal.dom.api.DOMDataBroker; import org.opendaylight.mdsal.dom.api.DOMDataTreeCommitCohortRegistration; +import org.opendaylight.mdsal.dom.api.DOMDataTreeCommitCohortRegistry; +import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier; import org.opendaylight.mdsal.eos.binding.api.Entity; import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipChange; import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipListener; @@ -68,6 +70,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.common.RpcError.ErrorType; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; +import org.opendaylight.yangtools.yang.common.Uint32; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -85,7 +88,7 @@ public class CarProvider implements CarService { private static final String ENTITY_TYPE = "cars"; private static final InstanceIdentifier CARS_IID = InstanceIdentifier.builder(Cars.class).build(); - private static final DataTreeIdentifier CARS_DTID = new DataTreeIdentifier<>( + private static final DataTreeIdentifier CARS_DTID = DataTreeIdentifier.create( LogicalDatastoreType.CONFIGURATION, CARS_IID); private final DataBroker dataProvider; @@ -97,10 +100,9 @@ public class CarProvider implements CarService { private final CarEntityOwnershipListener ownershipListener = new CarEntityOwnershipListener(); private final AtomicBoolean registeredListener = new AtomicBoolean(); - private final Collection> carsDclRegistrations = - Sets.newConcurrentHashSet(); - private final Collection> carsDtclRegistrations = - Sets.newConcurrentHashSet(); + private final Set> carsDclRegistrations = ConcurrentHashMap.newKeySet(); + private final Set> carsDtclRegistrations = + ConcurrentHashMap.newKeySet(); private volatile Thread testThread; private volatile boolean stopThread; @@ -138,16 +140,16 @@ public class CarProvider implements CarService { final long inputCount; // If rate is not provided, or given as zero, then just return. - if (input.getRate() == null || input.getRate() == 0) { + if (input.getRate() == null || input.getRate().toJava() == 0) { LOG_PURCHASE_CAR.info("Exiting stress test as no rate is given."); return Futures.immediateFuture(RpcResultBuilder.failed() .withError(ErrorType.PROTOCOL, "invalid rate") .build()); } - inputRate = input.getRate(); + inputRate = input.getRate().toJava(); if (input.getCount() != null) { - inputCount = input.getCount(); + inputCount = input.getCount().toJava(); } else { inputCount = 0; } @@ -163,8 +165,8 @@ public class CarProvider implements CarService { InstanceIdentifier carsId = InstanceIdentifier.create(Cars.class); tx.merge(LogicalDatastoreType.CONFIGURATION, carsId, new CarsBuilder().build()); try { - tx.submit().checkedGet(5, TimeUnit.SECONDS); - } catch (TransactionCommitFailedException | TimeoutException e) { + tx.commit().get(5, TimeUnit.SECONDS); + } catch (TimeoutException | InterruptedException | ExecutionException e) { LOG_PURCHASE_CAR.error("Put Cars failed",e); return Futures.immediateFuture(RpcResultBuilder.success(new StressTestOutputBuilder().build()).build()); } @@ -181,10 +183,10 @@ public class CarProvider implements CarService { CarEntry car = new CarEntryBuilder().setId(new CarId("car" + id)).build(); tx1.put(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(Cars.class).child(CarEntry.class, car.key()).build(), car); - Futures.addCallback(tx1.submit(), new FutureCallback() { + tx1.commit().addCallback(new FutureCallback() { @Override - public void onSuccess(final Void result) { + public void onSuccess(final CommitInfo result) { // Transaction succeeded succcessCounter.getAndIncrement(); } @@ -224,8 +226,8 @@ public class CarProvider implements CarService { stopThread(); StopStressTestOutputBuilder stopStressTestOutput; stopStressTestOutput = new StopStressTestOutputBuilder() - .setSuccessCount(succcessCounter.longValue()) - .setFailureCount(failureCounter.longValue()); + .setSuccessCount(Uint32.valueOf(succcessCounter.longValue())) + .setFailureCount(Uint32.valueOf(failureCounter.longValue())); final StopStressTestOutput result = stopStressTestOutput.build(); LOG_PURCHASE_CAR.info("Executed Stop Stress test; No. of cars created {}; " @@ -318,8 +320,8 @@ public class CarProvider implements CarService { return RpcResultBuilder.success(new RegisterCommitCohortOutputBuilder().build()).buildFuture(); } - final DOMDataTreeCommitCohortRegistry commitCohortRegistry = (DOMDataTreeCommitCohortRegistry) - domDataBroker.getSupportedExtensions().get(DOMDataTreeCommitCohortRegistry.class); + final DOMDataTreeCommitCohortRegistry commitCohortRegistry = domDataBroker.getExtensions().getInstance( + DOMDataTreeCommitCohortRegistry.class); if (commitCohortRegistry == null) { // Shouldn't happen @@ -335,10 +337,8 @@ public class CarProvider implements CarService { // to address all list entries, the second path argument is wild-carded by specifying just the CarEntry.QNAME. final YangInstanceIdentifier carEntryPath = YangInstanceIdentifier.builder( YangInstanceIdentifier.of(Cars.QNAME)).node(CarEntry.QNAME).node(CarEntry.QNAME).build(); - commitCohortReg.set(commitCohortRegistry.registerCommitCohort( - new org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier( - org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION, - carEntryPath), new CarEntryDataTreeCommitCohort())); + commitCohortReg.set(commitCohortRegistry.registerCommitCohort(new DOMDataTreeIdentifier( + LogicalDatastoreType.CONFIGURATION, carEntryPath), new CarEntryDataTreeCommitCohort())); LOG_CAR_PROVIDER.info("Registered commit cohort");