Bug 8391 - Close producer in become-prefix-leader rpc implementation 83/56683/5
authorJakub Morvay <jmorvay@cisco.com>
Mon, 8 May 2017 11:58:57 +0000 (13:58 +0200)
committerJakub Morvay <jmorvay@cisco.com>
Wed, 10 May 2017 08:00:25 +0000 (08:00 +0000)
MdsalLowLevelTestProvider's become-prefix-leader rpc implementation
creates CDSDataTreeProducer to try to move shard leadership. However,
the producer is not closed after leadership change request. This
prevents any subsequent invocations of become-prefix-leader rpc with
same prefix parameter to be successful. Subtree specified by the prefix
is attached to still opened producer and creation of any new producer
for this subtree fails. Close producer once we don't need it.

Change-Id: I3827e425082c35a43ec18dac1ef0f2dbd19b291f
Signed-off-by: Jakub Morvay <jmorvay@cisco.com>
opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/impl/PrefixLeaderHandler.java

index f62ca36..24e0766 100644 (file)
@@ -17,6 +17,7 @@ import org.opendaylight.controller.cluster.dom.api.CDSShardAccess;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeProducerException;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeService;
 import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.BecomePrefixLeaderInput;
 import org.opendaylight.yangtools.yang.common.RpcResult;
@@ -43,17 +44,20 @@ public class PrefixLeaderHandler {
         final YangInstanceIdentifier yid = serializer.toYangInstanceIdentifier(input.getPrefix());
         final DOMDataTreeIdentifier prefix = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, yid);
 
-        final CDSDataTreeProducer producer =
-                (CDSDataTreeProducer) domDataTreeService.createProducer(Collections.singleton(prefix));
+        try (final CDSDataTreeProducer producer =
+                     (CDSDataTreeProducer) domDataTreeService.createProducer(Collections.singleton(prefix))) {
 
-        final CDSShardAccess shardAccess = producer.getShardAccess(prefix);
+            final CDSShardAccess shardAccess = producer.getShardAccess(prefix);
 
-        final CompletionStage<Void> completionStage = shardAccess.makeLeaderLocal();
+            final CompletionStage<Void> completionStage = shardAccess.makeLeaderLocal();
 
-        completionStage.exceptionally(throwable -> {
-            LOG.error("Leader movement failed.", throwable);
-            return null;
-        });
+            completionStage.exceptionally(throwable -> {
+                LOG.error("Leader movement failed.", throwable);
+                return null;
+            });
+        } catch (final DOMDataTreeProducerException e) {
+            LOG.warn("Error while closing producer", e);
+        }
 
         return Futures.immediateFuture(RpcResultBuilder.<Void>success().build());
     }

©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.