Bug 8621 - Add shutdown-prefix-shard-replica rpc to MdsalLowLevelTestProvider 78/58578/5
authorJakub Morvay <jmorvay@cisco.com>
Fri, 9 Jun 2017 07:45:14 +0000 (09:45 +0200)
committerJakub Morvay <jmorvay@cisco.com>
Thu, 22 Jun 2017 09:23:05 +0000 (09:23 +0000)
csit testing scenarios require clean shutdown of shard's local replica
funcionality. This introduces shutdown-prefix-shard-replica rpc to
MdsalLowLevelTestProvider. Upon invoking this rpc, local replica of
specified prefix-based shard is gracefully stopped.

Change-Id: I620b7ae2dbc9978dd155c64f703d421d46108e3d
Signed-off-by: Jakub Morvay <jmorvay@cisco.com>
(cherry picked from commit bdf02e09c13b6c8d170202054d44877707642cd9)

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

index bc3e039..89d220b 100644 (file)
@@ -524,4 +524,17 @@ module odl-mdsal-lowlevel-control {
             }
         }
     }
+
+    rpc shutdown-prefix-shard-replica {
+        description "Upon receiving this, the member will try to gracefully shutdown local configuration
+            data store prefix-based shard replica.";
+        input {
+            leaf prefix {
+                description "The prefix of the configuration data store prefix-based shard to be shutdown
+                    gracefully.";
+                mandatory true;
+                type instance-identifier;
+            }
+        }
+    }
 }
index f0569fa..688e7c0 100644 (file)
@@ -85,6 +85,7 @@ import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.l
 import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.RegisterSingletonConstantInput;
 import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.RemovePrefixShardInput;
 import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.RemoveShardReplicaInput;
+import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.ShutdownPrefixShardReplicaInput;
 import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.ShutdownShardReplicaInput;
 import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.StartPublishNotificationsInput;
 import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.SubscribeYnlInput;
@@ -581,6 +582,28 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService
             return Futures.immediateFuture(RpcResultBuilder.<Void>failed().withRpcError(rpcError).build());
         }
 
+        return shutdownShardGracefully(shardName);
+    }
+
+    @Override
+    public Future<RpcResult<Void>> shutdownPrefixShardReplica(final ShutdownPrefixShardReplicaInput input) {
+        LOG.debug("Received shutdown-prefix-shard-replica rpc, input: {}", input);
+
+        final InstanceIdentifier shardPrefix = input.getPrefix();
+
+        if (shardPrefix == null) {
+            final RpcError rpcError = RpcResultBuilder.newError(ErrorType.APPLICATION, "bad-element",
+                    "A valid shard prefix must be specified");
+            return Futures.immediateFuture(RpcResultBuilder.<Void>failed().withRpcError(rpcError).build());
+        }
+
+        final YangInstanceIdentifier shardPath = bindingNormalizedNodeSerializer.toYangInstanceIdentifier(shardPrefix);
+        final String cleanPrefixShardName = ClusterUtils.getCleanShardName(shardPath);
+
+        return shutdownShardGracefully(cleanPrefixShardName);
+    }
+
+    private SettableFuture<RpcResult<Void>> shutdownShardGracefully(final String shardName) {
         final SettableFuture<RpcResult<Void>> rpcResult = SettableFuture.create();
         final ActorContext context = configDataStore.getActorContext();
 
@@ -614,7 +637,6 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService
                 }
             }
         }, context.getClientDispatcher());
-
         return rpcResult;
     }