Fix PeopleProvider activation 31/90231/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 3 Jun 2020 12:35:18 +0000 (14:35 +0200)
committerRobert Varga <nite@hq.sk>
Wed, 3 Jun 2020 13:54:48 +0000 (13:54 +0000)
Detected by CSIT, this was broken during MD-SAL API removal. Rework
instantiation to use constructor injection and proper shutdown.
Fixes the following splat:

java.lang.NullPointerException: null
at org.opendaylight.controller.clustering.it.provider.PeopleProvider$1.onSuccess(PeopleProvider.java:74) ~[bundleFile:?]
at org.opendaylight.controller.clustering.it.provider.PeopleProvider$1.onSuccess(PeopleProvider.java:70) ~[bundleFile:?]
at com.google.common.util.concurrent.Futures$CallbackListener.run(Futures.java:1078) ~[bundleFile:?]
at com.google.common.util.concurrent.DirectExecutor.execute(DirectExecutor.java:30) ~[bundleFile:?]
at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:1164) [bundleFile:?]
at com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:958) [bundleFile:?]
at com.google.common.util.concurrent.AbstractFuture.set(AbstractFuture.java:727) [bundleFile:?]
at com.google.common.util.concurrent.AbstractTransformFuture$TransformFuture.setResult(AbstractTransformFuture.java:247) [bundleFile:?]
at com.google.common.util.concurrent.AbstractTransformFuture.run(AbstractTransformFuture.java:163) [bundleFile:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
at java.lang.Thread.run(Thread.java:834) [?:?]

Change-Id: I08273c8112ec4d3592440975b77e4ce3467d78a2
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/PeopleProvider.java
opendaylight/md-sal/samples/clustering-test-app/provider/src/main/resources/OSGI-INF/blueprint/cluster-test-app.xml

index fd1acaf..e958c86 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.controller.clustering.it.provider;
 
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.collect.ImmutableSet;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.ListenableFuture;
@@ -40,16 +42,15 @@ public class PeopleProvider implements PeopleService, AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(PeopleProvider.class);
 
     private final Set<ObjectRegistration<?>> regs = new HashSet<>();
-    private DataBroker dataProvider;
-    private RpcProviderService rpcProviderService;
-    private CarPurchaseService rpcImplementation;
-
-    public void setDataProvider(final DataBroker salDataProvider) {
-        this.dataProvider = salDataProvider;
-    }
+    private final DataBroker dataProvider;
+    private final RpcProviderService rpcProviderService;
+    private final CarPurchaseService rpcImplementation;
 
-    public void setRpcImplementation(final CarPurchaseService rpcImplementation) {
-        this.rpcImplementation = rpcImplementation;
+    public PeopleProvider(final DataBroker dataProvider, final RpcProviderService rpcProviderService,
+            final CarPurchaseService rpcImplementation) {
+        this.dataProvider = requireNonNull(dataProvider);
+        this.rpcProviderService = requireNonNull(rpcProviderService);
+        this.rpcImplementation = requireNonNull(rpcImplementation);
     }
 
     @Override
index 11bea1a..ef8c73b 100644 (file)
 
   <!-- odl:routed-rpc-implementation id="carPurchaseRpcReg" ref="purchaseCarProvider"/ -->
 
-  <bean id="peopleProvider" class="org.opendaylight.controller.clustering.it.provider.PeopleProvider" >
-    <property name="dataProvider" ref="dataBroker"/>
-    <property name="rpcImplementation" ref="purchaseCarProvider"/>
+  <bean id="peopleProvider" class="org.opendaylight.controller.clustering.it.provider.PeopleProvider"
+        destroy-method="close">
+    <argument ref="dataBroker"/>
+    <argument ref="bindingRpcRegistry"/>
+    <argument ref="purchaseCarProvider"/>
   </bean>
 
   <bean id="carProvider" class="org.opendaylight.controller.clustering.it.provider.CarProvider"
-       destroy-method="close">
+        destroy-method="close">
     <argument ref="dataBroker"/>
     <argument ref="entityOwnershipService"/>
     <argument ref="domDataBroker"/>

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.