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=bec65aa561a3357daf980b58a6f6ebbda36f8db5;hb=1c79e662c75f327e4d1953710cc78b70780ef4e1;hp=da3b8a4a9481a4a087a279e96248ef02e76b1f16;hpb=fd11f0d7d2b18671d4877fceb82579389106a363;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 da3b8a4a94..bec65aa561 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 @@ -12,7 +12,6 @@ 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.HashSet; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -32,45 +31,51 @@ 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.DOMDataBroker.CommitCohortExtension; import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier; import org.opendaylight.mdsal.eos.binding.api.Entity; import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipListener; import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService; import org.opendaylight.mdsal.eos.common.api.CandidateAlreadyRegisteredException; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.CarId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.CarService; 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.RegisterCommitCohort; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.RegisterCommitCohortInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.RegisterCommitCohortOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.RegisterCommitCohortOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.RegisterLoggingDtcl; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.RegisterLoggingDtclInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.RegisterLoggingDtclOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.RegisterLoggingDtclOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.RegisterOwnership; 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.RegisterOwnershipOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.RegisterOwnershipOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.StopStressTest; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.StopStressTestInput; 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.StressTest; 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.StressTestOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.StressTestOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.UnregisterCommitCohort; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.UnregisterCommitCohortInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.UnregisterCommitCohortOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.UnregisterCommitCohortOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.UnregisterLoggingDtcls; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.UnregisterLoggingDtclsInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.UnregisterLoggingDtclsOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.UnregisterLoggingDtclsOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.UnregisterOwnership; 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.UnregisterOwnershipOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.UnregisterOwnershipOutputBuilder; 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.cars.CarEntryBuilder; -import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.concepts.ObjectRegistration; +import org.opendaylight.yangtools.concepts.Registration; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.common.ErrorType; import org.opendaylight.yangtools.yang.common.RpcResult; @@ -91,15 +96,12 @@ import org.slf4j.LoggerFactory; */ @Singleton @Component(service = { }) -@SuppressFBWarnings("SLF4J_ILLEGAL_PASSED_CLASS") -public final class CarProvider implements CarService { - private static final Logger LOG_PURCHASE_CAR = LoggerFactory.getLogger(PurchaseCarProvider.class); - - private static final Logger LOG_CAR_PROVIDER = LoggerFactory.getLogger(CarProvider.class); +public final class CarProvider { + private static final Logger LOG = LoggerFactory.getLogger(CarProvider.class); private static final String ENTITY_TYPE = "cars"; private static final InstanceIdentifier CARS_IID = InstanceIdentifier.builder(Cars.class).build(); - private static final DataTreeIdentifier CARS_DTID = DataTreeIdentifier.create( + private static final DataTreeIdentifier CARS_DTID = DataTreeIdentifier.of( LogicalDatastoreType.CONFIGURATION, CARS_IID); private final DataBroker dataProvider; @@ -108,21 +110,17 @@ public final class CarProvider implements CarService { private final AtomicLong succcessCounter = new AtomicLong(); private final AtomicLong failureCounter = new AtomicLong(); - private final EntityOwnershipListener ownershipListener = - ownershipChange -> LOG_CAR_PROVIDER.info("ownershipChanged: {}", ownershipChange); + private final EntityOwnershipListener ownershipListener = (entity, change, inJeopardy) -> + LOG.info("ownershipChanged: entity={} change={} inJeopardy={}", entity, change, inJeopardy); private final AtomicBoolean registeredListener = new AtomicBoolean(); - - private final Set> carsDclRegistrations = ConcurrentHashMap.newKeySet(); - - private final Set> regs = new HashSet<>(); - private final Set> carsDtclRegistrations = - ConcurrentHashMap.newKeySet(); + private final AtomicReference commitCohortReg = new AtomicReference<>(); + private final Set> carsDclRegistrations = ConcurrentHashMap.newKeySet(); + private final Set regs = new HashSet<>(); + private final Set carsDtclRegistrations = ConcurrentHashMap.newKeySet(); private volatile Thread testThread; private volatile boolean stopThread; - private final AtomicReference> commitCohortReg = - new AtomicReference<>(); @Inject @Activate @@ -132,7 +130,15 @@ public final class CarProvider implements CarService { this.dataProvider = dataProvider; this.ownershipService = ownershipService; this.domDataBroker = domDataBroker; - regs.add(rpcProviderService.registerRpcImplementation(CarService.class, this)); + regs.add(rpcProviderService.registerRpcImplementations( + (StressTest) this::stressTest, + (StopStressTest) this::stopStressTest, + (RegisterOwnership) this::registerOwnership, + (UnregisterOwnership) this::unregisterOwnership, + (RegisterLoggingDtcl) this::registerLoggingDtcl, + (UnregisterLoggingDtcls) this::unregisterLoggingDtcls, + (RegisterCommitCohort) this::registerCommitCohort, + (UnregisterCommitCohort) this::unregisterCommitCohort)); } @PreDestroy @@ -140,7 +146,7 @@ public final class CarProvider implements CarService { public void close() { stopThread(); closeCommitCohortRegistration(); - regs.forEach(ObjectRegistration::close); + regs.forEach(Registration::close); regs.clear(); } @@ -157,14 +163,13 @@ public final class CarProvider implements CarService { } } - @Override - public ListenableFuture> stressTest(final StressTestInput input) { + private ListenableFuture> stressTest(final StressTestInput input) { final int inputRate; final long inputCount; // If rate is not provided, or given as zero, then just return. if (input.getRate() == null || input.getRate().toJava() == 0) { - LOG_PURCHASE_CAR.info("Exiting stress test as no rate is given."); + LOG.info("Exiting stress test as no rate is given."); return Futures.immediateFuture(RpcResultBuilder.failed() .withError(ErrorType.PROTOCOL, "invalid rate") .build()); @@ -177,7 +182,7 @@ public final class CarProvider implements CarService { inputCount = 0; } - LOG_PURCHASE_CAR.info("Stress test starting : rate: {} count: {}", inputRate, inputCount); + LOG.info("Stress test starting : rate: {} count: {}", inputRate, inputCount); stopThread(); // clear counters @@ -190,7 +195,7 @@ public final class CarProvider implements CarService { try { tx.commit().get(5, TimeUnit.SECONDS); } catch (TimeoutException | InterruptedException | ExecutionException e) { - LOG_PURCHASE_CAR.error("Put Cars failed",e); + LOG.error("Put Cars failed",e); return Futures.immediateFuture(RpcResultBuilder.success(new StressTestOutputBuilder().build()).build()); } @@ -218,7 +223,7 @@ public final class CarProvider implements CarService { public void onFailure(final Throwable ex) { // Transaction failed failureCounter.getAndIncrement(); - LOG_CAR_PROVIDER.error("Put Cars failed", ex); + LOG.error("Put Cars failed", ex); } }, MoreExecutors.directExecutor()); try { @@ -228,7 +233,7 @@ public final class CarProvider implements CarService { } if (count.get() % 1000 == 0) { - LOG_PURCHASE_CAR.info("Cars created {}, time: {}", count.get(), sw.elapsed(TimeUnit.SECONDS)); + LOG.info("Cars created {}, time: {}", count.get(), sw.elapsed(TimeUnit.SECONDS)); } // Check if a count is specified in input and we have created that many cars. @@ -237,15 +242,14 @@ public final class CarProvider implements CarService { } } - LOG_PURCHASE_CAR.info("Stress test thread stopping after creating {} cars.", count.get()); + LOG.info("Stress test thread stopping after creating {} cars.", count.get()); }); testThread.start(); return Futures.immediateFuture(RpcResultBuilder.success(new StressTestOutputBuilder().build()).build()); } - @Override - public ListenableFuture> stopStressTest(final StopStressTestInput input) { + private ListenableFuture> stopStressTest(final StopStressTestInput input) { stopThread(); StopStressTestOutputBuilder stopStressTestOutput; stopStressTestOutput = new StopStressTestOutputBuilder() @@ -253,17 +257,15 @@ public final class CarProvider implements CarService { .setFailureCount(Uint32.valueOf(failureCounter.longValue())); final StopStressTestOutput result = stopStressTestOutput.build(); - LOG_PURCHASE_CAR.info("Executed Stop Stress test; No. of cars created {}; " - + "No. of cars failed {}; ", succcessCounter, failureCounter); + 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.success(result).build()); } - - @Override - public ListenableFuture> registerOwnership(final RegisterOwnershipInput input) { + private ListenableFuture> registerOwnership(final RegisterOwnershipInput input) { if (registeredListener.compareAndSet(false, true)) { ownershipService.registerListener(ENTITY_TYPE, ownershipListener); } @@ -279,42 +281,36 @@ public final class CarProvider implements CarService { return RpcResultBuilder.success(new RegisterOwnershipOutputBuilder().build()).buildFuture(); } - @Override - public ListenableFuture> unregisterOwnership( + private ListenableFuture> unregisterOwnership( final UnregisterOwnershipInput input) { return RpcResultBuilder.success(new UnregisterOwnershipOutputBuilder().build()).buildFuture(); } - @Override - public ListenableFuture> registerLoggingDtcl( + private ListenableFuture> registerLoggingDtcl( final RegisterLoggingDtclInput input) { - LOG_CAR_PROVIDER.info("Registering a new CarDataTreeChangeListener"); - final ListenerRegistration carsDtclRegistration = - dataProvider.registerDataTreeChangeListener(CARS_DTID, new CarDataTreeChangeListener()); - - carsDtclRegistrations.add(carsDtclRegistration); + LOG.info("Registering a new CarDataTreeChangeListener"); + final var reg = dataProvider.registerTreeChangeListener(CARS_DTID, new CarDataTreeChangeListener()); + carsDtclRegistrations.add(reg); return RpcResultBuilder.success(new RegisterLoggingDtclOutputBuilder().build()).buildFuture(); } - @Override - public ListenableFuture> unregisterLoggingDtcls( + private ListenableFuture> unregisterLoggingDtcls( final UnregisterLoggingDtclsInput input) { - LOG_CAR_PROVIDER.info("Unregistering the CarDataTreeChangeListener(s)"); + LOG.info("Unregistering the CarDataTreeChangeListener(s)"); synchronized (carsDtclRegistrations) { int numListeners = 0; - for (ListenerRegistration carsDtclRegistration : carsDtclRegistrations) { + for (var carsDtclRegistration : carsDtclRegistrations) { carsDtclRegistration.close(); numListeners++; } carsDtclRegistrations.clear(); - LOG_CAR_PROVIDER.info("Unregistered {} CaraDataTreeChangeListener(s)", numListeners); + LOG.info("Unregistered {} CaraDataTreeChangeListener(s)", numListeners); } return RpcResultBuilder.success(new UnregisterLoggingDtclsOutputBuilder().build()).buildFuture(); } - @Override @SuppressWarnings("checkstyle:IllegalCatch") - public ListenableFuture> unregisterCommitCohort( + private ListenableFuture> unregisterCommitCohort( final UnregisterCommitCohortInput input) { closeCommitCohortRegistration(); @@ -322,23 +318,20 @@ public final class CarProvider implements CarService { } private void closeCommitCohortRegistration() { - final DOMDataTreeCommitCohortRegistration reg = commitCohortReg.getAndSet(null); + final var reg = commitCohortReg.getAndSet(null); if (reg != null) { reg.close(); - LOG_CAR_PROVIDER.info("Unregistered commit cohort"); + LOG.info("Unregistered commit cohort"); } } - @Override - public synchronized ListenableFuture> registerCommitCohort( + private synchronized ListenableFuture> registerCommitCohort( final RegisterCommitCohortInput input) { if (commitCohortReg.get() != null) { return RpcResultBuilder.success(new RegisterCommitCohortOutputBuilder().build()).buildFuture(); } - final DOMDataTreeCommitCohortRegistry commitCohortRegistry = domDataBroker.getExtensions().getInstance( - DOMDataTreeCommitCohortRegistry.class); - + final var commitCohortRegistry = domDataBroker.extension(CommitCohortExtension.class); if (commitCohortRegistry == null) { // Shouldn't happen return RpcResultBuilder.failed().withError(ErrorType.APPLICATION, @@ -353,10 +346,10 @@ public final 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 DOMDataTreeIdentifier( + commitCohortReg.set(commitCohortRegistry.registerCommitCohort(DOMDataTreeIdentifier.of( LogicalDatastoreType.CONFIGURATION, carEntryPath), new CarEntryDataTreeCommitCohort())); - LOG_CAR_PROVIDER.info("Registered commit cohort"); + LOG.info("Registered commit cohort"); return RpcResultBuilder.success(new RegisterCommitCohortOutputBuilder().build()).buildFuture(); }