Bug 7805 - Implement agent RPCs for shard leader movement testing 01/53901/12
authorTomas Cere <tcere@cisco.com>
Mon, 27 Mar 2017 14:30:27 +0000 (16:30 +0200)
committerTomas Cere <tcere@cisco.com>
Sun, 2 Apr 2017 19:59:29 +0000 (21:59 +0200)
Change-Id: Ic19d1867f3c54ec22d600e9b80c6490d5a4b99bb
Signed-off-by: Tomas Cere <tcere@cisco.com>
opendaylight/md-sal/samples/clustering-test-app/model/src/main/yang/odl-mdsal-lowlevel-control.yang
opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/MdsalLowLevelTestProvider.java
opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/impl/PrefixLeaderHandler.java [new file with mode: 0644]

index dbd65d1..de8df73 100644 (file)
@@ -374,12 +374,9 @@ module odl-mdsal-lowlevel-control {
             to become Leader of the given shard (presumably the llt:list-ints one,
             created by produce-transactions) and return immediatelly.";
         input {
-            leaf shard-name {
-                description "TBD.
-
-                FIXME: Ask Java implementation developer about the format needed.";
+            leaf prefix {
                 mandatory true;
-                type string;
+                type instance-identifier;
             }
         }
         // No output.
index f9f82a2..98ae842 100644 (file)
@@ -27,6 +27,7 @@ import org.opendaylight.controller.clustering.it.provider.impl.FlappingSingleton
 import org.opendaylight.controller.clustering.it.provider.impl.GetConstantService;
 import org.opendaylight.controller.clustering.it.provider.impl.IdIntsDOMDataTreeLIstener;
 import org.opendaylight.controller.clustering.it.provider.impl.IdIntsListener;
+import org.opendaylight.controller.clustering.it.provider.impl.PrefixLeaderHandler;
 import org.opendaylight.controller.clustering.it.provider.impl.PrefixShardHandler;
 import org.opendaylight.controller.clustering.it.provider.impl.ProduceTransactionsHandler;
 import org.opendaylight.controller.clustering.it.provider.impl.PublishNotificationsTask;
@@ -112,6 +113,7 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService
     private final SchemaService schemaService;
     private final ClusterSingletonServiceProvider singletonService;
     private final DOMRpcProviderService domRpcService;
+    private final PrefixLeaderHandler prefixLeaderHandler;
     private final PrefixShardHandler prefixShardHandler;
     private final DOMDataTreeChangeService domDataTreeChangeService;
 
@@ -151,6 +153,7 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService
         this.domDataBroker = domDataBroker;
         this.domDataTreeService = domDataTreeService;
         this.distributedShardFactory = distributedShardFactory;
+        this.prefixLeaderHandler = new PrefixLeaderHandler(domDataTreeService, bindingNormalizedNodeSerializer);
 
         domDataTreeChangeService =
                 (DOMDataTreeChangeService) domDataBroker.getSupportedExtensions().get(DOMDataTreeChangeService.class);
@@ -268,7 +271,9 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService
 
     @Override
     public Future<RpcResult<Void>> becomePrefixLeader(final BecomePrefixLeaderInput input) {
-        return null;
+        LOG.debug("become-prefix-leader, input: {}", input);
+
+        return prefixLeaderHandler.makeLeaderLocal(input);
     }
 
     @Override
diff --git a/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/impl/PrefixLeaderHandler.java b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/impl/PrefixLeaderHandler.java
new file mode 100644 (file)
index 0000000..f62ca36
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2017 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.clustering.it.provider.impl;
+
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import java.util.Collections;
+import java.util.concurrent.CompletionStage;
+import org.opendaylight.controller.cluster.dom.api.CDSDataTreeProducer;
+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.DOMDataTreeService;
+import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.BecomePrefixLeaderInput;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PrefixLeaderHandler {
+
+    private static final Logger LOG = LoggerFactory.getLogger(PrefixLeaderHandler.class);
+
+    private final DOMDataTreeService domDataTreeService;
+    private final BindingNormalizedNodeSerializer serializer;
+
+    public PrefixLeaderHandler(final DOMDataTreeService domDataTreeService,
+                               final BindingNormalizedNodeSerializer serializer) {
+        this.domDataTreeService = domDataTreeService;
+        this.serializer = serializer;
+    }
+
+    public ListenableFuture<RpcResult<Void>> makeLeaderLocal(final BecomePrefixLeaderInput input) {
+
+        final YangInstanceIdentifier yid = serializer.toYangInstanceIdentifier(input.getPrefix());
+        final DOMDataTreeIdentifier prefix = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, yid);
+
+        final CDSDataTreeProducer producer =
+                (CDSDataTreeProducer) domDataTreeService.createProducer(Collections.singleton(prefix));
+
+        final CDSShardAccess shardAccess = producer.getShardAccess(prefix);
+
+        final CompletionStage<Void> completionStage = shardAccess.makeLeaderLocal();
+
+        completionStage.exceptionally(throwable -> {
+            LOG.error("Leader movement failed.", throwable);
+            return null;
+        });
+
+        return Futures.immediateFuture(RpcResultBuilder.<Void>success().build());
+    }
+}