Kaynağa Gözat

AMBARI-16701. Do not use implicit routing by default in solr-client (oleewere)

oleewere 9 yıl önce
ebeveyn
işleme
26f7bfb0f8

+ 12 - 3
ambari-common/src/main/python/resource_management/libraries/functions/solr_cloud_util.py

@@ -49,18 +49,27 @@ def upload_configuration_to_zk(zookeeper_quorum, solr_znode, config_set, config_
   )
 
 def create_collection(zookeeper_quorum, solr_znode, collection, config_set, java64_home, user, group,
-                      shards = 1, replication_factor = 1, max_shards = 1, retry = 5, interval = 10):
+                      shards = 1, replication_factor = 1, max_shards = 1, retry = 5, interval = 10,
+                      router_name = None, router_field = None):
   """
   Create Solr collection based on a configuration set in zookeeper.
   If this method called again the with higher shard number (or max_shard number), then it will indicate
   the cli tool to add new shards to the Solr collection. This can be useful after added a new Solr Cloud
   instance to the cluster.
+
+  If you would like to add shards later to a collection, then use implicit routing, e.g.:
+  router_name = "implicit", router_field = "_router_field_"
   """
   solr_cli_prefix = __create_solr_cloud_cli_prefix(zookeeper_quorum, solr_znode, java64_home)
 
   if max_shards == 1: # if max shards is not specified use this strategy
     max_shards = replication_factor * shards
 
-  Execute(format('{solr_cli_prefix} --create-collection -c {collection} -cs {config_set} -s {shards} -r {replication_factor} '\
-    '-m {max_shards} -rt {retry} -i {interval}'), user=user, group=group
+  create_collection_cmd = format('{solr_cli_prefix} --create-collection -c {collection} -cs {config_set} -s {shards} -r {replication_factor} '\
+    '-m {max_shards} -rt {retry} -i {interval}')
+
+  if router_name is not None and router_field is not None:
+    create_collection_cmd += format(' -rn {router_name} -rf {router_field}')
+
+  Execute(create_collection_cmd, user=user, group=group
   )

+ 2 - 2
ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/AmbariSolrCloudCLI.java

@@ -241,8 +241,8 @@ public class AmbariSolrCloudCLI {
       int retry = cli.hasOption("rt") ? Integer.parseInt(cli.getOptionValue("rt")) : 5;
       int interval = cli.hasOption('i') ? Integer.parseInt(cli.getOptionValue('i')) : 10;
       int maxShards = cli.hasOption('m') ? Integer.parseInt(cli.getOptionValue('m')) : shards * replication;
-      String routerName = cli.hasOption("rn") ? cli.getOptionValue("rn") : "implicit";
-      String routerField = cli.hasOption("rf") ? cli.getOptionValue("rf") : "_router_field_";
+      String routerName = cli.hasOption("rn") ? cli.getOptionValue("rn") : null;
+      String routerField = cli.hasOption("rf") ? cli.getOptionValue("rf") : null;
       String shardName = cli.hasOption("sn") ? cli.getOptionValue("sn") : null;
       boolean isSplitting = !cli.hasOption("ns");
 

+ 4 - 2
ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/CreateCollectionCommand.java

@@ -45,11 +45,13 @@ public class CreateCollectionCommand extends AbstractSolrRetryCommand<Collection
     request.setNumShards(client.getShards());
     request.setReplicationFactor(client.getReplication());
     request.setMaxShardsPerNode(client.getMaxShardsPerNode());
-    if (client.isSplitting()) {
-      request.setShards(ShardUtils.generateShardListStr(client.getMaxShardsPerNode()));
+    if (client.getRouterField() != null && client.getRouterName()!= null) {
       request.setRouterName(client.getRouterName());
       request.setRouterField(client.getRouterField());
     }
+    if (client.isSplitting()) {
+      request.setShards(ShardUtils.generateShardListStr(client.getMaxShardsPerNode()));
+    }
     return request;
   }