From 674928cc08dfa6b822acc20940fbb8ea3f3fd84f Mon Sep 17 00:00:00 2001 From: Oleksandr Zharov Date: Thu, 28 Sep 2023 19:31:01 +0200 Subject: [PATCH] Do not use RpcService in toaster-provider Migrated usage of RpcService to Rpc for toaster-provider. JIRA: CONTROLLER-2085 Change-Id: I30c112ba11eb14cc645e4dd7d76758bead3a7de2 Signed-off-by: Oleksandr Zharov Signed-off-by: Robert Varga --- .../sample/toaster/it/ToasterTest.java | 5 ++-- .../toaster/provider/OpendaylightToaster.java | 29 ++++++++++--------- .../provider/OpenDaylightToasterTest.java | 2 +- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/opendaylight/md-sal/samples/toaster-it/src/test/java/org/opendaylight/controller/sample/toaster/it/ToasterTest.java b/opendaylight/md-sal/samples/toaster-it/src/test/java/org/opendaylight/controller/sample/toaster/it/ToasterTest.java index 9bc905c3f4..0b4ea8e72a 100644 --- a/opendaylight/md-sal/samples/toaster-it/src/test/java/org/opendaylight/controller/sample/toaster/it/ToasterTest.java +++ b/opendaylight/md-sal/samples/toaster-it/src/test/java/org/opendaylight/controller/sample/toaster/it/ToasterTest.java @@ -21,7 +21,7 @@ import org.opendaylight.controller.mdsal.it.base.AbstractMdsalTestBase; import org.opendaylight.controller.sample.kitchen.api.EggsType; import org.opendaylight.controller.sample.kitchen.api.KitchenService; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.HashBrown; -import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterService; +import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToast; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.WhiteBread; import org.ops4j.pax.exam.junit.PaxExam; import org.ops4j.pax.exam.options.MavenUrlReference; @@ -34,7 +34,8 @@ public class ToasterTest extends AbstractMdsalTestBase { KitchenService kitchenService; @Inject @Filter(timeout = 60 * 1000) - ToasterService toasterService; + // proxy for the entire toaster, nothing else + MakeToast makeToast; @Override public MavenUrlReference getFeatureRepo() { diff --git a/opendaylight/md-sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/OpendaylightToaster.java b/opendaylight/md-sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/OpendaylightToaster.java index 5f4a2d3f3f..37ebe29c87 100644 --- a/opendaylight/md-sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/OpendaylightToaster.java +++ b/opendaylight/md-sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/OpendaylightToaster.java @@ -14,6 +14,7 @@ import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATI import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.OPERATIONAL; import static org.opendaylight.yangtools.yang.common.ErrorType.APPLICATION; +import com.google.common.collect.ImmutableClassToInstanceMap; import com.google.common.util.concurrent.FluentFuture; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; @@ -47,13 +48,16 @@ import org.opendaylight.mdsal.binding.api.WriteTransaction; import org.opendaylight.mdsal.common.api.CommitInfo; import org.opendaylight.mdsal.common.api.OptimisticLockFailedException; import org.opendaylight.mdsal.common.api.TransactionCommitFailedException; +import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.CancelToast; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.CancelToastInput; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.CancelToastOutput; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.CancelToastOutputBuilder; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.DisplayString; +import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToast; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToastInput; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToastOutput; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToastOutputBuilder; +import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.RestockToaster; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.RestockToasterInput; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.RestockToasterOutput; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.RestockToasterOutputBuilder; @@ -63,10 +67,10 @@ import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterOutOfBreadBuilder; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterRestocked; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterRestockedBuilder; -import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterService; import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.concepts.Registration; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.Rpc; import org.opendaylight.yangtools.yang.common.ErrorTag; import org.opendaylight.yangtools.yang.common.ErrorType; import org.opendaylight.yangtools.yang.common.RpcError; @@ -84,10 +88,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Singleton -@Component(service = ToasterService.class, immediate = true) +@Component(service = MakeToast.class, immediate = true) @Designate(ocd = OpendaylightToaster.Configuration.class) public final class OpendaylightToaster extends AbstractMXBean - implements ToasterService, ToasterProviderRuntimeMXBean, DataTreeChangeListener, AutoCloseable { + implements MakeToast, ToasterProviderRuntimeMXBean, DataTreeChangeListener, AutoCloseable { @ObjectClassDefinition public @interface Configuration { @AttributeDefinition(description = "The name of the toaster's manufacturer", max = "255") @@ -140,7 +144,11 @@ public final class OpendaylightToaster extends AbstractMXBean this.maxMakeToastTries = maxMakeToastTries; executor = Executors.newFixedThreadPool(1); - reg = rpcProviderService.registerRpcImplementation(ToasterService.class, this); + reg = rpcProviderService.registerRpcImplementations(ImmutableClassToInstanceMap.>builder() + .put(CancelToast.class, this::cancelToast) + .put(MakeToast.class, this) + .put(RestockToaster.class, this::restockToaster) + .build()); LOG.info("Initializing..."); @@ -247,8 +255,7 @@ public final class OpendaylightToaster extends AbstractMXBean /** * RPC call implemented from the ToasterService interface that cancels the current toast, if any. */ - @Override - public ListenableFuture> cancelToast(final CancelToastInput input) { + private ListenableFuture> cancelToast(final CancelToastInput input) { Future current = currentMakeToastTask.getAndSet(null); if (current != null) { current.cancel(true); @@ -262,13 +269,10 @@ public final class OpendaylightToaster extends AbstractMXBean * RPC call implemented from the ToasterService interface that attempts to make toast. */ @Override - public ListenableFuture> makeToast(final MakeToastInput input) { + public ListenableFuture> invoke(final MakeToastInput input) { LOG.info("makeToast: {}", input); - - final SettableFuture> futureResult = SettableFuture.create(); - + final var futureResult = SettableFuture.>create(); checkStatusAndMakeToast(input, futureResult, maxMakeToastTries); - return futureResult; } @@ -368,8 +372,7 @@ public final class OpendaylightToaster extends AbstractMXBean * Restocks the bread for the toaster, resets the toastsMade counter to 0, and sends a * ToasterRestocked notification. */ - @Override - public ListenableFuture> restockToaster(final RestockToasterInput input) { + private ListenableFuture> restockToaster(final RestockToasterInput input) { LOG.info("restockToaster: {}", input); amountOfBreadInStock.set(input.getAmountOfBreadToStock().toJava()); diff --git a/opendaylight/md-sal/samples/toaster-provider/src/test/java/org/opendaylight/controller/sample/toaster/provider/OpenDaylightToasterTest.java b/opendaylight/md-sal/samples/toaster-provider/src/test/java/org/opendaylight/controller/sample/toaster/provider/OpenDaylightToasterTest.java index 245bf0edb8..86d2e6d19c 100644 --- a/opendaylight/md-sal/samples/toaster-provider/src/test/java/org/opendaylight/controller/sample/toaster/provider/OpenDaylightToasterTest.java +++ b/opendaylight/md-sal/samples/toaster-provider/src/test/java/org/opendaylight/controller/sample/toaster/provider/OpenDaylightToasterTest.java @@ -78,7 +78,7 @@ public class OpenDaylightToasterTest extends AbstractConcurrentDataBrokerTest { // NOTE: In a real test we would want to override the Thread.sleep() to // prevent our junit test // for sleeping for a second... - Future> makeToast = toaster.makeToast(toastInput); + Future> makeToast = toaster.invoke(toastInput); RpcResult rpcResult = makeToast.get(); -- 2.36.6