|
18 | 18 |
|
19 | 19 | import java.io.Closeable; |
20 | 20 | import java.util.HashMap; |
21 | | -import java.util.List; |
22 | 21 | import java.util.Map; |
23 | 22 | import java.util.Objects; |
24 | 23 | import java.util.Optional; |
25 | 24 | import java.util.concurrent.TimeUnit; |
26 | 25 | import java.util.concurrent.atomic.AtomicBoolean; |
27 | 26 | import java.util.concurrent.atomic.AtomicReference; |
28 | 27 | import org.apache.solr.client.solrj.SolrClient; |
| 28 | +import org.apache.solr.client.solrj.impl.CloudClientConnectionString; |
29 | 29 | import org.apache.solr.client.solrj.impl.CloudSolrClient; |
30 | 30 | import org.apache.solr.client.solrj.impl.HttpSolrClientBase; |
31 | 31 | import org.apache.solr.client.solrj.impl.HttpSolrClientBuilderBase; |
@@ -77,29 +77,33 @@ public void setDefaultZKHost(String zkHost) { |
77 | 77 | } |
78 | 78 | } |
79 | 79 |
|
80 | | - public synchronized CloudSolrClient getCloudSolrClient(String zkHost) { |
| 80 | + public synchronized CloudSolrClient getCloudSolrClient(String connectionString) { |
81 | 81 | ensureOpen(); |
82 | | - Objects.requireNonNull(zkHost, "ZooKeeper host cannot be null!"); |
83 | | - if (solrClients.containsKey(zkHost)) { |
84 | | - return (CloudSolrClient) solrClients.get(zkHost); |
| 82 | + Objects.requireNonNull(connectionString, "Connection string cannot be null!"); |
| 83 | + if (solrClients.containsKey(connectionString)) { |
| 84 | + return (CloudSolrClient) solrClients.get(connectionString); |
85 | 85 | } |
86 | 86 | // Can only use ZK ACLs if there is a default ZK Host, and the given ZK host contains that |
87 | 87 | // default. |
88 | 88 | // Basically the ZK ACLs are assumed to be only used for the default ZK host, |
89 | 89 | // thus we should only provide the ACLs to that Zookeeper instance. |
90 | | - String zkHostNoChroot = zkHost.split("/")[0]; |
91 | | - boolean canUseACLs = |
92 | | - Optional.ofNullable(defaultZkHost.get()).map(zkHostNoChroot::equals).orElse(false); |
| 90 | + boolean canUseACLs = false; |
| 91 | + CloudClientConnectionString cloudClientConnectionString = |
| 92 | + CloudClientConnectionString.parse(connectionString); |
| 93 | + if (cloudClientConnectionString.isZk()) { |
| 94 | + String zkHostNoChroot = connectionString.split("/")[0]; |
| 95 | + canUseACLs = |
| 96 | + Optional.ofNullable(defaultZkHost.get()).map(zkHostNoChroot::equals).orElse(false); |
| 97 | + } |
93 | 98 |
|
94 | | - final var client = newCloudSolrClient(zkHost, httpSolrClient, canUseACLs); |
95 | | - solrClients.put(zkHost, client); |
| 99 | + final var client = newCloudSolrClient(connectionString, httpSolrClient, canUseACLs); |
| 100 | + solrClients.put(connectionString, client); |
96 | 101 | return client; |
97 | 102 | } |
98 | 103 |
|
99 | 104 | protected CloudSolrClient newCloudSolrClient( |
100 | | - String zkHost, HttpSolrClientBase httpSolrClient, boolean canUseACLs) { |
101 | | - final List<String> hosts = List.of(zkHost); |
102 | | - var builder = new CloudSolrClient.Builder(hosts, Optional.empty()); |
| 105 | + String connectionString, HttpSolrClientBase httpSolrClient, boolean canUseACLs) { |
| 106 | + var builder = new CloudSolrClient.Builder(connectionString); |
103 | 107 | builder.canUseZkACLs(canUseACLs); |
104 | 108 | // using internal builder to ensure the internal client gets closed |
105 | 109 | builder = builder.withHttpClientBuilder(newHttpSolrClientBuilder(null, httpSolrClient)); |
|
0 commit comments