Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-18130: new param "solrConnection" in solrj-streaming, support HTTP (#4320)

Vladimir Vyatkinb2e1f8ed4a30
diff --git a/changelog/unreleased/SOLR-18130-cli-tools-solr-connection-support.yml b/changelog/unreleased/SOLR-18130-cli-tools-solr-connection-support.yml
new file mode 100644
index 00000000000..9e3e8253336
--- /dev/null
+++ b/changelog/unreleased/SOLR-18130-cli-tools-solr-connection-support.yml
@@ -0,0 +1,7 @@
+title: Add --solr-connection option to Solr CLI tools, enabling HTTP(S)-based communication without requiring direct ZooKeeper access
+type: added
+authors:
+ - name: vyatkin.v
+links:
+ - name: SOLR-18130
+ url: https://issues.apache.org/jira/browse/SOLR-18130
diff --git a/changelog/unreleased/SOLR-18130-jdbc-driver-solr-connection-support.yml b/changelog/unreleased/SOLR-18130-jdbc-driver-solr-connection-support.yml
new file mode 100644
index 00000000000..a35ac98cab2
--- /dev/null
+++ b/changelog/unreleased/SOLR-18130-jdbc-driver-solr-connection-support.yml
@@ -0,0 +1,7 @@
+title: Add HTTP(S)-based SolrCloud connection support for the Solr SQL JDBC driver
+type: added
+authors:
+ - name: vyatkin.v
+links:
+ - name: SOLR-18130
+ url: https://issues.apache.org/jira/browse/SOLR-18130
diff --git a/changelog/unreleased/SOLR-18130-join-query-parser-solr-connection-support.yml b/changelog/unreleased/SOLR-18130-join-query-parser-solr-connection-support.yml
new file mode 100644
index 00000000000..8f2f3f34c56
--- /dev/null
+++ b/changelog/unreleased/SOLR-18130-join-query-parser-solr-connection-support.yml
@@ -0,0 +1,7 @@
+title: Add 'solrConnection' parameter to cross-collection joins in the Join Query Parser, expanding use to HTTP based SolrCloud coordinates.
+type: added
+authors:
+ - name: vyatkin.v
+links:
+ - name: SOLR-18130
+ url: https://issues.apache.org/jira/browse/SOLR-18130
diff --git a/changelog/unreleased/SOLR-18130-solrj-streaming-solr-connection-support.yml b/changelog/unreleased/SOLR-18130-solrj-streaming-solr-connection-support.yml
new file mode 100644
index 00000000000..5f679490a4e
--- /dev/null
+++ b/changelog/unreleased/SOLR-18130-solrj-streaming-solr-connection-support.yml
@@ -0,0 +1,7 @@
+title: Added solrConnection param to solrj-streaming module, expanding use to HTTP based SolrCloud coordinates. zkHost is deprecated.
+type: added
+authors:
+ - name: vyatkin.v
+links:
+ - name: SOLR-18130
+ url: https://issues.apache.org/jira/browse/SOLR-18130
diff --git a/solr/benchmark/src/java/org/apache/solr/bench/search/StreamingSearch.java b/solr/benchmark/src/java/org/apache/solr/bench/search/StreamingSearch.java
index 5797682c63e..2c3814bf8a5 100644
--- a/solr/benchmark/src/java/org/apache/solr/bench/search/StreamingSearch.java
+++ b/solr/benchmark/src/java/org/apache/solr/bench/search/StreamingSearch.java
@@ -27,6 +27,7 @@ import org.apache.solr.bench.Docs;
import org.apache.solr.bench.SolrBenchState;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.SolrClientCache;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.stream.CloudSolrStream;
@@ -114,7 +115,8 @@ public class StreamingSearch {
@Benchmark
public Object stream(BenchState benchState, SolrBenchState solrBenchState)
throws SolrServerException, IOException {
- CloudSolrStream stream = new CloudSolrStream(benchState.zkHost, collection, benchState.params);
+ var solrConnection = CloudSolrClient.CloudSolrClientConnection.parse(benchState.zkHost);
+ CloudSolrStream stream = new CloudSolrStream(solrConnection, collection, benchState.params);
stream.setStreamContext(benchState.streamContext);
return getTuples(stream);
}
diff --git a/solr/core/src/java/org/apache/solr/cli/CLIUtils.java b/solr/core/src/java/org/apache/solr/cli/CLIUtils.java
index 162e20e274e..914aec0c4e5 100644
--- a/solr/core/src/java/org/apache/solr/cli/CLIUtils.java
+++ b/solr/core/src/java/org/apache/solr/cli/CLIUtils.java
@@ -26,10 +26,8 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.util.Arrays;
-import java.util.List;
import java.util.Locale;
import java.util.Map;
-import java.util.Optional;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.apache.commons.cli.CommandLine;
@@ -46,8 +44,8 @@ import org.apache.solr.client.solrj.request.SystemInfoRequest;
import org.apache.solr.client.solrj.response.SystemInfoResponse;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.cloud.SolrZkClient;
-import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.util.EnvUtils;
+import org.apache.solr.common.util.URLUtil;
/** Utility class that holds various helper methods for the CLI. */
public final class CLIUtils {
@@ -63,6 +61,45 @@ public final class CLIUtils {
private static final long MAX_WAIT_FOR_CORE_LOAD_NANOS =
TimeUnit.NANOSECONDS.convert(1, TimeUnit.MINUTES);
+ private static CloudSolrClient.CloudSolrClientConnection resolveSolrConnectionFromCli(
+ CommandLine cli) throws IOException {
+ String solrConnection =
+ getCliOptionOrPropValue(
+ cli, CommonCLIOptions.SOLR_CONNECTION_OPTION, "solr-connection", null);
+ if (solrConnection != null && !solrConnection.isBlank()) {
+ return CloudSolrClient.CloudSolrClientConnection.parse(solrConnection);
+ }
+ String zkHost = getCliOptionOrPropValue(cli, CommonCLIOptions.ZK_HOST_OPTION, "zkHost", null);
+ if (zkHost != null && !zkHost.isBlank()) {
+ var zkSolrConnection = CloudSolrClient.CloudSolrClientConnection.parse(zkHost);
+ if (!zkSolrConnection.isZookeeper()) {
+ throw new IOException(
+ String.format(
+ Locale.ROOT, "Expected ZooKeeper connection string, but got: '%s'.", zkHost));
+ }
+ return zkSolrConnection;
+ }
+ return null;
+ }
+
+ private static String resolveZkHostFromCluster(CommandLine cli) throws Exception {
+ String zkHost = null;
+ try (SolrClient solrClient = getSolrClient(cli)) {
+ // hit Solr to get system info
+ Map<String, Object> status = StatusTool.reportStatus(solrClient);
+ @SuppressWarnings("unchecked")
+ Map<String, Object> cloud = (Map<String, Object>) status.get("cloud");
+ if (cloud != null) {
+ String zookeeper = (String) cloud.get("ZooKeeper");
+ if (zookeeper.endsWith("(embedded)")) {
+ zookeeper = zookeeper.substring(0, zookeeper.length() - "(embedded)".length());
+ }
+ zkHost = zookeeper;
+ }
+ }
+ return zkHost;
+ }
+
public static String getDefaultSolrUrl() {
// note that ENV_VAR syntax (and the env vars too) are mapped to env.var sys props
String scheme = EnvUtils.getProperty("solr.url.scheme", "http");
@@ -181,28 +218,39 @@ public final class CLIUtils {
/**
* Get the base URL of a live Solr instance from either the --solr-url command-line option or from
- * ZooKeeper.
+ * SolrCloud.
*/
public static String normalizeSolrUrl(CommandLine cli) throws Exception {
String solrUrl = cli.getOptionValue(CommonCLIOptions.SOLR_URL_OPTION);
if (solrUrl == null) {
- String zkHost = getCliOptionOrPropValue(cli, CommonCLIOptions.ZK_HOST_OPTION, "zkHost", null);
- if (zkHost == null) {
+ var solrConnection = resolveSolrConnectionFromCli(cli);
+ if (solrConnection == null) {
solrUrl = getDefaultSolrUrl();
CLIO.err(
- "Neither --zk-host or --solr-url parameters, nor ZK_HOST env var provided, so assuming solr url is "
+ "Neither --solr-connection, --zk-host or --solr-url parameters, nor SOLR_CONNECTION, ZK_HOST env var provided, so assuming solr url is "
+ solrUrl
+ ".");
+ } else if (!solrConnection.isZookeeper()) {
+ // HTTP form (e.g. `-s http://host:port`): the connection string already names a Solr URL,
+ // so use it directly without spinning up a CloudSolrClient.
+ solrUrl = normalizeSolrUrl(solrConnection.quorumItems().get(0), false);
} else {
- try (CloudSolrClient cloudSolrClient = getCloudSolrClient(zkHost)) {
+ var builder =
+ new HttpJettySolrClient.Builder()
+ .withOptionalBasicAuthCredentials(
+ cli.getOptionValue(CommonCLIOptions.CREDENTIALS_OPTION));
+ try (CloudSolrClient cloudSolrClient = getCloudSolrClient(solrConnection, builder)) {
Set<String> liveNodes = cloudSolrClient.getClusterState().getLiveNodes();
if (liveNodes.isEmpty())
throw new IllegalStateException(
- "No live nodes found! Cannot determine 'solrUrl' from ZooKeeper: " + zkHost);
+ "No live nodes found! Cannot determine 'solrUrl' from SolrCloud: "
+ + solrConnection);
String firstLiveNode = liveNodes.iterator().next();
- solrUrl = ZkStateReader.from(cloudSolrClient).getBaseUrlForNodeName(firstLiveNode);
+ String urlScheme =
+ cloudSolrClient.getClusterStateProvider().getClusterProperty("urlScheme", "http");
+ solrUrl = URLUtil.getBaseUrlForNodeName(firstLiveNode, urlScheme, false);
solrUrl = normalizeSolrUrl(solrUrl, false);
}
}
@@ -211,6 +259,17 @@ public final class CLIUtils {
return solrUrl;
}
+ /**
+ * Returns true if the user supplied any of the connection-related CLI options ({@code
+ * --solr-url}, {@code --solr-connection}, or {@code --zk-host}). Use this to gate logic that
+ * should only run when an explicit connection target was provided.
+ */
+ public static boolean hasConnectionOption(CommandLine cli) {
+ return cli.hasOption(CommonCLIOptions.SOLR_URL_OPTION)
+ || cli.hasOption(CommonCLIOptions.SOLR_CONNECTION_OPTION)
+ || cli.hasOption(CommonCLIOptions.ZK_HOST_OPTION);
+ }
+
/**
* Get the value of the specified CLI option with fallback to system property and default value.
*
@@ -241,22 +300,40 @@ public final class CLIUtils {
if (zkHost != null && !zkHost.isBlank()) {
return zkHost;
}
+ return resolveZkHostFromCluster(cli);
+ }
- try (SolrClient solrClient = getSolrClient(cli)) {
- // hit Solr to get system info
- Map<String, Object> status = StatusTool.reportStatus(solrClient);
- @SuppressWarnings("unchecked")
- Map<String, Object> cloud = (Map<String, Object>) status.get("cloud");
- if (cloud != null) {
- String zookeeper = (String) cloud.get("ZooKeeper");
- if (zookeeper.endsWith("(embedded)")) {
- zookeeper = zookeeper.substring(0, zookeeper.length() - "(embedded)".length());
- }
- zkHost = zookeeper;
- }
- }
+ /**
+ * Resolves a Solr connection definition from command-line options, system properties, environment
+ * variables, or cluster discovery.
+ *
+ * <p>The connection is resolved in the following order of precedence:
+ *
+ * <ul>
+ * <li>{@code solr-connection} command-line option
+ * <li>{@code solrConnection} system property or {@code SOLR_CONNECTION} environment variable
+ * <li>{@code zk-host} command-line option
+ * <li>{@code zkHost} system property or {@code ZK_HOST} environment variable
+ * <li>ZooKeeper connection discovered from a running Solr instance using the {@code solr-url}
+ * option
+ * <li>{@code null} if none is specified or discoverable
+ * </ul>
+ *
+ * @return the resolved Solr connection, or {@code null} if unavailable
+ */
+ public static CloudSolrClient.CloudSolrClientConnection getSolrConnection(CommandLine cli)
+ throws Exception {
- return zkHost;
+ var solrConnection = resolveSolrConnectionFromCli(cli);
+ if (solrConnection != null) {
+ return solrConnection;
+ }
+ String zkHost = resolveZkHostFromCluster(cli);
+ if (zkHost == null) {
+ return null;
+ }
+ solrConnection = CloudSolrClient.CloudSolrClientConnection.parse(zkHost);
+ return solrConnection;
}
public static SolrZkClient getSolrZkClient(CommandLine cli, String zkHost) {
@@ -272,15 +349,10 @@ public final class CLIUtils {
.build();
}
- public static CloudSolrClient getCloudSolrClient(String zkHost) {
- return getCloudSolrClient(zkHost, null);
- }
-
public static CloudSolrClient getCloudSolrClient(
- String zkHost, HttpJettySolrClient.Builder builder) {
- return new CloudSolrClient.Builder(List.of(zkHost), Optional.empty())
- .withHttpClientBuilder(builder)
- .build();
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
+ HttpJettySolrClient.Builder builder) {
+ return new CloudSolrClient.Builder(solrConnection).withHttpClientBuilder(builder).build();
}
/**
diff --git a/solr/core/src/java/org/apache/solr/cli/CommonCLIOptions.java b/solr/core/src/java/org/apache/solr/cli/CommonCLIOptions.java
index d0b77403071..eea6905a948 100644
--- a/solr/core/src/java/org/apache/solr/cli/CommonCLIOptions.java
+++ b/solr/core/src/java/org/apache/solr/cli/CommonCLIOptions.java
@@ -40,8 +40,19 @@ public final class CommonCLIOptions {
+ '.')
.get();
- public static final Option SOLR_URL_OPTION =
+ public static final Option SOLR_CONNECTION_OPTION =
Option.builder("s")
+ .longOpt("solr-connection")
+ .hasArg()
+ .argName("CONNECTION_STRING")
+ .desc(
+ "Zookeeper or HTTP(s) connection string; unnecessary if SOLR_CONNECTION is defined in solr.in.sh; otherwise, defaults to "
+ + DefaultValues.ZK_HOST
+ + '.')
+ .get();
+
+ public static final Option SOLR_URL_OPTION =
+ Option.builder()
.longOpt("solr-url")
.hasArg()
.argName("HOST")
diff --git a/solr/core/src/java/org/apache/solr/cli/CreateTool.java b/solr/core/src/java/org/apache/solr/cli/CreateTool.java
index 74778e7e490..e74bcd070b4 100644
--- a/solr/core/src/java/org/apache/solr/cli/CreateTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/CreateTool.java
@@ -133,8 +133,7 @@ public class CreateTool extends ToolBase {
protected void createCore(CommandLine cli, SolrClient solrClient) throws Exception {
String coreName = cli.getOptionValue(COLLECTION_NAME_OPTION);
- String solrUrl =
- cli.getOptionValue(CommonCLIOptions.SOLR_URL_OPTION, CLIUtils.getDefaultSolrUrl());
+ String solrUrl = CLIUtils.normalizeSolrUrl(cli);
final String solrInstallDir = System.getProperty("solr.install.dir");
final String confDirName =
@@ -203,7 +202,13 @@ public class CreateTool extends ToolBase {
cli.getOptionValue(CommonCLIOptions.CREDENTIALS_OPTION));
String zkHost = CLIUtils.getZkHost(cli);
echoIfVerbose("Connecting to ZooKeeper at " + zkHost);
- try (CloudSolrClient cloudSolrClient = CLIUtils.getCloudSolrClient(zkHost, builder)) {
+ var zkSolrConnection = CloudSolrClient.CloudSolrClientConnection.parse(zkHost);
+ if (!zkSolrConnection.isZookeeper()) {
+ throw new IOException(
+ String.format(
+ Locale.ROOT, "Expected ZooKeeper connection string, but got: '%s'.", zkHost));
+ }
+ try (var cloudSolrClient = CLIUtils.getCloudSolrClient(zkSolrConnection, builder)) {
createCollection(cloudSolrClient, cli);
}
}
@@ -226,8 +231,10 @@ public class CreateTool extends ToolBase {
"No live nodes found! Cannot create a collection until "
+ "there is at least 1 live node in the cluster.");
- String solrUrl = cli.getOptionValue(CommonCLIOptions.SOLR_URL_OPTION);
- if (solrUrl == null) {
+ String solrUrl;
+ if (CLIUtils.hasConnectionOption(cli)) {
+ solrUrl = CLIUtils.normalizeSolrUrl(cli);
+ } else {
String firstLiveNode = liveNodes.iterator().next();
solrUrl = ZkStateReader.from(cloudSolrClient).getBaseUrlForNodeName(firstLiveNode);
}
@@ -248,7 +255,9 @@ public class CreateTool extends ToolBase {
confName = collectionName;
}
- // TODO: This should be done using the configSet API
+ // TODO: This should be done using the configSet API. This would let us remove
+ // the direct dependency on ZooKeeper APIs. Unlike the bin/solr zk comamnds that
+ // work directly with ZooKeeper.
final Path configsetsDirPath = CLIUtils.getConfigSetsDir(solrInstallDirPath);
ConfigSetService configSetService =
new ZkConfigSetService(ZkStateReader.from(cloudSolrClient).getZkClient());
@@ -319,7 +328,7 @@ public class CreateTool extends ToolBase {
}
}
- private void printDefaultConfigsetWarningIfNecessary(CommandLine cli) {
+ private void printDefaultConfigsetWarningIfNecessary(CommandLine cli) throws Exception {
final String confDirectoryName =
cli.getOptionValue(CONF_DIR_OPTION, DefaultValues.DEFAULT_CONFIG_SET);
final String confName = cli.getOptionValue(CONF_NAME_OPTION, "");
@@ -327,8 +336,7 @@ public class CreateTool extends ToolBase {
if (confDirectoryName.equals("_default")
&& (confName.isEmpty() || confName.equals("_default"))) {
final String collectionName = cli.getOptionValue(COLLECTION_NAME_OPTION);
- final String solrUrl =
- cli.getOptionValue(CommonCLIOptions.SOLR_URL_OPTION, CLIUtils.getDefaultSolrUrl());
+ final String solrUrl = CLIUtils.normalizeSolrUrl(cli);
final String curlCommand =
String.format(
Locale.ROOT,
diff --git a/solr/core/src/java/org/apache/solr/cli/DeleteTool.java b/solr/core/src/java/org/apache/solr/cli/DeleteTool.java
index 77db2184a4c..59450cf00c1 100644
--- a/solr/core/src/java/org/apache/solr/cli/DeleteTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/DeleteTool.java
@@ -30,8 +30,8 @@ import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.jetty.HttpJettySolrClient;
import org.apache.solr.client.solrj.request.CollectionsApi;
+import org.apache.solr.client.solrj.request.ConfigsetsApi;
import org.apache.solr.client.solrj.request.CoresApi;
-import org.apache.solr.common.cloud.ZkStateReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -110,9 +110,9 @@ public class DeleteTool extends ToolBase {
.withOptionalBasicAuthCredentials(
cli.getOptionValue(CommonCLIOptions.CREDENTIALS_OPTION));
- String zkHost = CLIUtils.getZkHost(cli);
- try (CloudSolrClient cloudSolrClient = CLIUtils.getCloudSolrClient(zkHost, builder)) {
- echoIfVerbose("Connecting to ZooKeeper at " + zkHost);
+ var solrConnection = CLIUtils.getSolrConnection(cli);
+ try (var cloudSolrClient = CLIUtils.getCloudSolrClient(solrConnection, builder)) {
+ echoIfVerbose("Connecting to Solr at " + solrConnection.toString());
deleteCollection(cloudSolrClient, cli);
}
}
@@ -125,14 +125,13 @@ public class DeleteTool extends ToolBase {
"No live nodes found! Cannot delete a collection until "
+ "there is at least 1 live node in the cluster.");
- ZkStateReader zkStateReader = ZkStateReader.from(cloudSolrClient);
String collectionName = cli.getOptionValue(COLLECTION_NAME_OPTION);
- if (!zkStateReader.getClusterState().hasCollection(collectionName)) {
+ if (!cloudSolrClient.getClusterState().hasCollection(collectionName)) {
throw new IllegalArgumentException("Collection " + collectionName + " not found!");
}
String configName =
- zkStateReader.getClusterState().getCollection(collectionName).getConfigName();
+ cloudSolrClient.getClusterState().getCollection(collectionName).getConfigName();
boolean deleteConfig = cli.hasOption(DELETE_CONFIG_OPTION);
if (deleteConfig && configName != null) {
@@ -142,7 +141,7 @@ public class DeleteTool extends ToolBase {
configName);
} else {
// need to scan all Collections to see if any are using the config
- Collection<String> collections = zkStateReader.getClusterState().getCollectionNames();
+ Collection<String> collections = cloudSolrClient.getClusterState().getCollectionNames();
// give a little note to the user if there are many collections in case it takes a while
if (collections.size() > 50)
@@ -159,7 +158,7 @@ public class DeleteTool extends ToolBase {
.filter(
name ->
configName.equals(
- zkStateReader.getClusterState().getCollection(name).getConfigName()))
+ cloudSolrClient.getClusterState().getCollection(name).getConfigName()))
.findFirst();
if (inUse.isPresent()) {
deleteConfig = false;
@@ -184,14 +183,14 @@ public class DeleteTool extends ToolBase {
}
if (deleteConfig) {
- String configZnode = "/configs/" + configName;
try {
- zkStateReader.getZkClient().clean(configZnode);
+ var req = new ConfigsetsApi.DeleteConfigSet(configName);
+ req.process(cloudSolrClient);
} catch (Exception exc) {
echo(
- "\nWARNING: Failed to delete configuration directory "
- + configZnode
- + " in ZooKeeper due to: "
+ "\nWARNING: Failed to delete configSet "
+ + configName
+ + " in solr due to: "
+ exc.getMessage()
+ "\nYou'll need to manually delete this znode using the bin/solr zk rm command.");
}
diff --git a/solr/core/src/java/org/apache/solr/cli/ExportTool.java b/solr/core/src/java/org/apache/solr/cli/ExportTool.java
index 20314c6ee1c..9fb9a23e3d2 100644
--- a/solr/core/src/java/org/apache/solr/cli/ExportTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/ExportTool.java
@@ -157,8 +157,8 @@ public class ExportTool extends ToolBase {
.addOption(LIMIT_OPTION)
.addOption(QUERY_OPTION)
.addOption(FIELDS_OPTION)
- .addOption(CommonCLIOptions.SOLR_URL_OPTION)
- .addOption(CommonCLIOptions.CREDENTIALS_OPTION);
+ .addOption(CommonCLIOptions.CREDENTIALS_OPTION)
+ .addOptionGroup(getConnectionOptions());
}
public abstract static class Info {
@@ -281,16 +281,16 @@ public class ExportTool extends ToolBase {
@Override
public void runImpl(CommandLine cli) throws Exception {
String url;
- if (cli.hasOption(CommonCLIOptions.SOLR_URL_OPTION)) {
+ if (CLIUtils.hasConnectionOption(cli)) {
if (!cli.hasOption(COLLECTION_NAME_OPTION)) {
throw new IllegalArgumentException(
- "Must specify -c / --name parameter with --solr-url to post documents.");
+ "Must specify -c / --name parameter with a connection target to export documents.");
}
url = CLIUtils.normalizeSolrUrl(cli) + "/solr/" + cli.getOptionValue(COLLECTION_NAME_OPTION);
} else {
- // think about support --zk-host someday.
- throw new IllegalArgumentException("Must specify --solr-url.");
+ throw new IllegalArgumentException(
+ "Must specify a connection target via -s/--solr-connection, --solr-url, or --zk-host.");
}
String credentials = cli.getOptionValue(CommonCLIOptions.CREDENTIALS_OPTION);
Info info = new MultiThreadedRunner(runtime, url, credentials);
diff --git a/solr/core/src/java/org/apache/solr/cli/HealthcheckTool.java b/solr/core/src/java/org/apache/solr/cli/HealthcheckTool.java
index 670bb0eb656..176debbb0b8 100644
--- a/solr/core/src/java/org/apache/solr/cli/HealthcheckTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/HealthcheckTool.java
@@ -31,6 +31,7 @@ import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
+import org.apache.solr.client.solrj.jetty.HttpJettySolrClient;
import org.apache.solr.client.solrj.request.SolrQuery;
import org.apache.solr.client.solrj.request.SystemInfoRequest;
import org.apache.solr.client.solrj.response.QueryResponse;
@@ -39,7 +40,6 @@ import org.apache.solr.common.cloud.ClusterState;
import org.apache.solr.common.cloud.DocCollection;
import org.apache.solr.common.cloud.Replica;
import org.apache.solr.common.cloud.Slice;
-import org.apache.solr.common.cloud.ZkStateReader;
import org.noggit.CharArr;
import org.noggit.JSONWriter;
import org.slf4j.Logger;
@@ -80,13 +80,17 @@ public class HealthcheckTool extends ToolBase {
@Override
public void runImpl(CommandLine cli) throws Exception {
- String zkHost = CLIUtils.getZkHost(cli);
- if (zkHost == null) {
+ var solrConnection = CLIUtils.getSolrConnection(cli);
+ if (solrConnection == null) {
CLIO.err("Healthcheck tool only works in Solr Cloud mode.");
runtime.exit(1);
}
- try (var cloudSolrClient = CLIUtils.getCloudSolrClient(zkHost)) {
- echoIfVerbose("\nConnecting to ZooKeeper at " + zkHost + " ...");
+ var builder =
+ new HttpJettySolrClient.Builder()
+ .withOptionalBasicAuthCredentials(
+ cli.getOptionValue(CommonCLIOptions.CREDENTIALS_OPTION));
+ try (var cloudSolrClient = CLIUtils.getCloudSolrClient(solrConnection, builder)) {
+ echoIfVerbose("Connecting to Solr at " + solrConnection.toString());
runCloudTool(cloudSolrClient, cli);
}
}
@@ -101,9 +105,7 @@ public class HealthcheckTool extends ToolBase {
log.debug("Running healthcheck for {}", collection);
- ZkStateReader zkStateReader = ZkStateReader.from(cloudSolrClient);
-
- ClusterState clusterState = zkStateReader.getClusterState();
+ ClusterState clusterState = cloudSolrClient.getClusterStateProvider().getClusterState();
Set<String> liveNodes = clusterState.getLiveNodes();
final DocCollection docCollection = clusterState.getCollectionOrNull(collection);
if (docCollection == null || docCollection.getSlices() == null) {
@@ -129,14 +131,6 @@ public class HealthcheckTool extends ToolBase {
for (Slice slice : slices) {
String shardName = slice.getName();
- // since we're reporting health of this shard, there's no guarantee of a leader
- String leaderUrl = null;
- try {
- leaderUrl = zkStateReader.getLeaderUrl(collection, shardName, 1000);
- } catch (Exception exc) {
- log.warn("Failed to get leader for shard {} due to: {}", shardName, exc);
- }
-
List<ReplicaHealth> replicaList = new ArrayList<>();
for (Replica r : slice.getReplicas()) {
@@ -146,7 +140,7 @@ public class HealthcheckTool extends ToolBase {
long numDocs = -1L;
String coreUrl = r.getCoreUrl();
- boolean isLeader = coreUrl.equals(leaderUrl);
+ boolean isLeader = r.isLeader();
// if replica's node is not live, its status is DOWN
String nodeName = r.getNodeName();
diff --git a/solr/core/src/java/org/apache/solr/cli/PostLogsTool.java b/solr/core/src/java/org/apache/solr/cli/PostLogsTool.java
index 82dccf53742..dd83821ea29 100644
--- a/solr/core/src/java/org/apache/solr/cli/PostLogsTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/PostLogsTool.java
@@ -79,19 +79,19 @@ public class PostLogsTool extends ToolBase {
return super.getOptions()
.addOption(COLLECTION_NAME_OPTION)
.addOption(ROOT_DIR_OPTION)
- .addOption(CommonCLIOptions.SOLR_URL_OPTION)
- .addOption(CommonCLIOptions.CREDENTIALS_OPTION);
+ .addOption(CommonCLIOptions.CREDENTIALS_OPTION)
+ .addOptionGroup(getConnectionOptions());
}
@Override
public void runImpl(CommandLine cli) throws Exception {
String url;
- if (cli.hasOption(CommonCLIOptions.SOLR_URL_OPTION)) {
+ if (CLIUtils.hasConnectionOption(cli)) {
url = CLIUtils.normalizeSolrUrl(cli) + "/solr/" + cli.getOptionValue(COLLECTION_NAME_OPTION);
} else {
- // Could be required arg, but maybe we want to support --zk-host option too?
- throw new IllegalArgumentException("Must specify --solr-url.");
+ throw new IllegalArgumentException(
+ "Must specify a connection target via -s/--solr-connection, --solr-url, or --zk-host.");
}
String rootDir = cli.getOptionValue(ROOT_DIR_OPTION);
String credentials = cli.getOptionValue(CommonCLIOptions.CREDENTIALS_OPTION);
diff --git a/solr/core/src/java/org/apache/solr/cli/PostTool.java b/solr/core/src/java/org/apache/solr/cli/PostTool.java
index 97751490e3f..4975033b8d6 100644
--- a/solr/core/src/java/org/apache/solr/cli/PostTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/PostTool.java
@@ -267,14 +267,14 @@ public class PostTool extends ToolBase {
.addOption(PARAMS_OPTION)
.addOption(FORMAT_OPTION)
.addOption(DRY_RUN_OPTION)
- .addOption(CommonCLIOptions.SOLR_URL_OPTION)
- .addOption(CommonCLIOptions.CREDENTIALS_OPTION);
+ .addOption(CommonCLIOptions.CREDENTIALS_OPTION)
+ .addOptionGroup(getConnectionOptions());
}
@Override
public void runImpl(CommandLine cli) throws Exception {
solrUpdateUrl = null;
- if (cli.hasOption(CommonCLIOptions.SOLR_URL_OPTION)) {
+ if (CLIUtils.hasConnectionOption(cli)) {
String url =
CLIUtils.normalizeSolrUrl(cli)
+ "/solr/"
diff --git a/solr/core/src/java/org/apache/solr/cli/StatusTool.java b/solr/core/src/java/org/apache/solr/cli/StatusTool.java
index ca9391fca18..27a4840a3a4 100644
--- a/solr/core/src/java/org/apache/solr/cli/StatusTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/StatusTool.java
@@ -89,6 +89,8 @@ public class StatusTool extends ToolBase {
OptionGroup optionGroup = new OptionGroup();
optionGroup.addOption(PORT_OPTION);
optionGroup.addOption(CommonCLIOptions.SOLR_URL_OPTION);
+ optionGroup.addOption(CommonCLIOptions.SOLR_CONNECTION_OPTION);
+ optionGroup.addOption(CommonCLIOptions.ZK_HOST_OPTION);
return super.getOptions()
.addOption(MAX_WAIT_SECS_OPTION)
.addOption(SHORT_OPTION)
@@ -98,7 +100,7 @@ public class StatusTool extends ToolBase {
@Override
public void runImpl(CommandLine cli) throws Exception {
- String solrUrl = cli.getOptionValue(CommonCLIOptions.SOLR_URL_OPTION);
+ String solrUrl = CLIUtils.hasConnectionOption(cli) ? CLIUtils.normalizeSolrUrl(cli) : null;
Integer port = cli.hasOption(PORT_OPTION) ? cli.getParsedOptionValue(PORT_OPTION) : null;
boolean shortFormat = cli.hasOption(SHORT_OPTION);
int maxWaitSecs = cli.getParsedOptionValue(MAX_WAIT_SECS_OPTION, 0);
diff --git a/solr/core/src/java/org/apache/solr/cli/StreamTool.java b/solr/core/src/java/org/apache/solr/cli/StreamTool.java
index 61d95c79d41..203291c53f0 100644
--- a/solr/core/src/java/org/apache/solr/cli/StreamTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/StreamTool.java
@@ -245,12 +245,11 @@ public class StreamTool extends ToolBase {
* locally.
*/
private PushBackStream doLocalMode(CommandLine cli, String expr) throws Exception {
- String zkHost = CLIUtils.getZkHost(cli);
-
- echoIfVerbose("Connecting to ZooKeeper at " + zkHost);
+ var solrConnection = CLIUtils.getSolrConnection(cli);
+ echoIfVerbose("Connecting to Solr at " + solrConnection.toString());
solrClientCache.setBasicAuthCredentials(
cli.getOptionValue(CommonCLIOptions.CREDENTIALS_OPTION));
- solrClientCache.getCloudSolrClient(zkHost);
+ solrClientCache.getCloudSolrClient(solrConnection);
TupleStream stream;
PushBackStream pushBackStream;
@@ -266,7 +265,7 @@ public class StreamTool extends ToolBase {
// logic about where to read data from.
streamFactory.withFunctionName("cat", LocalCatStream.class);
- streamFactory.withDefaultZkHost(zkHost);
+ streamFactory.withDefaultSolrConnection(solrConnection);
Lang.register(streamFactory);
diff --git a/solr/core/src/java/org/apache/solr/cli/ToolBase.java b/solr/core/src/java/org/apache/solr/cli/ToolBase.java
index 9d3734c3d93..f06a6cfd088 100644
--- a/solr/core/src/java/org/apache/solr/cli/ToolBase.java
+++ b/solr/core/src/java/org/apache/solr/cli/ToolBase.java
@@ -71,14 +71,16 @@ public abstract class ToolBase implements Tool {
}
/**
- * Provides the two ways of connecting to Solr for CLI Tools
+ * Provides the connection options for CLI Tools: {@code --solr-url}, {@code --zk-host}, and the
+ * unified {@code --solr-connection} (which accepts either form).
*
- * @return OptionGroup validates that only one option is supplied by the caller.
+ * @return OptionGroup that enforces only one of the connection options is supplied.
*/
public OptionGroup getConnectionOptions() {
OptionGroup optionGroup = new OptionGroup();
optionGroup.addOption(CommonCLIOptions.SOLR_URL_OPTION);
optionGroup.addOption(CommonCLIOptions.ZK_HOST_OPTION);
+ optionGroup.addOption(CommonCLIOptions.SOLR_CONNECTION_OPTION);
return optionGroup;
}
diff --git a/solr/core/src/java/org/apache/solr/cli/VersionTool.java b/solr/core/src/java/org/apache/solr/cli/VersionTool.java
index ca004e380c5..8bb14172467 100644
--- a/solr/core/src/java/org/apache/solr/cli/VersionTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/VersionTool.java
@@ -26,8 +26,9 @@ import org.apache.solr.client.solrj.response.SystemInfoResponse;
/**
* Supports version command in the bin/solr script.
*
- * <p>Prints the client (CLI) version. When {@code --solr-url} is provided, also prints the version
- * of the remote Solr server.
+ * <p>Prints the client (CLI) version. When a connection target ({@code -s}/{@code
+ * --solr-connection}, {@code --solr-url}, or {@code --zk-host}) is provided, also prints the
+ * version of the remote Solr server.
*/
public class VersionTool extends ToolBase {
@@ -43,16 +44,16 @@ public class VersionTool extends ToolBase {
@Override
public Options getOptions() {
return super.getOptions()
- .addOption(CommonCLIOptions.SOLR_URL_OPTION)
- .addOption(CommonCLIOptions.CREDENTIALS_OPTION);
+ .addOption(CommonCLIOptions.CREDENTIALS_OPTION)
+ .addOptionGroup(getConnectionOptions());
}
@Override
public void runImpl(CommandLine cli) throws Exception {
echo("Client version: " + SolrVersion.LATEST);
- String solrUrl = cli.getOptionValue(CommonCLIOptions.SOLR_URL_OPTION);
- if (solrUrl != null) {
+ if (CLIUtils.hasConnectionOption(cli)) {
+ String solrUrl = CLIUtils.normalizeSolrUrl(cli);
String credentials = cli.getOptionValue(CommonCLIOptions.CREDENTIALS_OPTION);
try (var solrClient = CLIUtils.getSolrClient(solrUrl, credentials)) {
SystemInfoResponse sysResponse = new SystemInfoRequest().process(solrClient);
diff --git a/solr/core/src/java/org/apache/solr/handler/ExportHandler.java b/solr/core/src/java/org/apache/solr/handler/ExportHandler.java
index acab3531950..5a8b4bddfac 100644
--- a/solr/core/src/java/org/apache/solr/handler/ExportHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/ExportHandler.java
@@ -24,6 +24,7 @@ import java.lang.invoke.MethodHandles;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.ModelCache;
import org.apache.solr.client.solrj.io.SolrClientCache;
import org.apache.solr.client.solrj.io.stream.StreamContext;
@@ -104,9 +105,10 @@ public class ExportHandler extends SearchHandler {
if (coreContainer.isZooKeeperAware()) {
defaultCollection = core.getCoreDescriptor().getCollectionName();
defaultZkhost = core.getCoreContainer().getZkController().getZkServerAddress();
- streamFactory.withCollectionZkHost(defaultCollection, defaultZkhost);
- streamFactory.withDefaultZkHost(defaultZkhost);
- modelCache = new ModelCache(250, defaultZkhost, solrClientCache);
+ var solrConnection = CloudSolrClient.CloudSolrClientConnection.parse(defaultZkhost);
+ streamFactory.withCollectionUseThisConnection(defaultCollection, solrConnection);
+ streamFactory.withDefaultSolrConnection(solrConnection);
+ modelCache = new ModelCache(250, solrConnection, solrClientCache);
}
streamFactory.withSolrResourceLoader(core.getResourceLoader());
StreamHandler.addExpressiblePlugins(streamFactory, core);
diff --git a/solr/core/src/java/org/apache/solr/handler/GraphHandler.java b/solr/core/src/java/org/apache/solr/handler/GraphHandler.java
index 7288878fab7..28fe28d708e 100644
--- a/solr/core/src/java/org/apache/solr/handler/GraphHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/GraphHandler.java
@@ -21,6 +21,7 @@ import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.List;
import java.util.Map;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.SolrClientCache;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.comp.StreamComparator;
@@ -79,8 +80,9 @@ public class GraphHandler extends RequestHandlerBase
if (coreContainer.isZooKeeperAware()) {
defaultCollection = core.getCoreDescriptor().getCollectionName();
defaultZkhost = core.getCoreContainer().getZkController().getZkServerAddress();
- streamFactory.withCollectionZkHost(defaultCollection, defaultZkhost);
- streamFactory.withDefaultZkHost(defaultZkhost);
+ var solrConnection = CloudSolrClient.CloudSolrClientConnection.parse(defaultZkhost);
+ streamFactory.withCollectionUseThisConnection(defaultCollection, solrConnection);
+ streamFactory.withDefaultSolrConnection(solrConnection);
}
// This pulls all the overrides and additions from the config
diff --git a/solr/core/src/java/org/apache/solr/handler/StreamHandler.java b/solr/core/src/java/org/apache/solr/handler/StreamHandler.java
index 90b0137a07d..b62bda76d5f 100644
--- a/solr/core/src/java/org/apache/solr/handler/StreamHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/StreamHandler.java
@@ -29,6 +29,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.ModelCache;
import org.apache.solr.client.solrj.io.SolrClientCache;
import org.apache.solr.client.solrj.io.Tuple;
@@ -111,15 +112,16 @@ public class StreamHandler extends RequestHandlerBase
if (coreContainer.isZooKeeperAware()) {
defaultCollection = core.getCoreDescriptor().getCollectionName();
defaultZkhost = core.getCoreContainer().getZkController().getZkServerAddress();
- streamFactory.withCollectionZkHost(defaultCollection, defaultZkhost);
- streamFactory.withDefaultZkHost(defaultZkhost);
+ var solrConnection = CloudSolrClient.CloudSolrClientConnection.parse(defaultZkhost);
+ streamFactory.withCollectionUseThisConnection(defaultCollection, solrConnection);
+ streamFactory.withDefaultSolrConnection(solrConnection);
modelCache =
coreContainer
.getObjectCache()
.computeIfAbsent(
cacheKey + "modelCache",
ModelCache.class,
- k -> new ModelCache(250, defaultZkhost, solrClientCache));
+ k -> new ModelCache(250, solrConnection, solrClientCache));
}
streamFactory.withSolrResourceLoader(core.getResourceLoader());
diff --git a/solr/core/src/java/org/apache/solr/search/join/CrossCollectionJoinQParser.java b/solr/core/src/java/org/apache/solr/search/join/CrossCollectionJoinQParser.java
index 2e4675a880d..696c5b286cb 100644
--- a/solr/core/src/java/org/apache/solr/search/join/CrossCollectionJoinQParser.java
+++ b/solr/core/src/java/org/apache/solr/search/join/CrossCollectionJoinQParser.java
@@ -22,6 +22,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.apache.lucene.search.Query;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.ShardParams;
import org.apache.solr.common.params.SolrParams;
@@ -34,6 +35,7 @@ import org.apache.solr.search.SyntaxError;
public class CrossCollectionJoinQParser extends QParser {
public static final String ZK_HOST = "zkHost";
+ public static final String SOLR_CONNECTION = "solrConnection";
public static final String SOLR_URL = "solrUrl";
public static final String FROM_INDEX = "fromIndex";
public static final String FROM = "from";
@@ -76,6 +78,7 @@ public class CrossCollectionJoinQParser extends QParser {
public Query parse() throws SyntaxError {
String query = localParams.get(QueryParsing.V);
String zkHost = localParams.get(ZK_HOST);
+ String solrConnectionString = localParams.get(SOLR_CONNECTION);
String solrUrl = localParams.get(SOLR_URL);
// Test if this is a valid solr url.
if (solrUrl != null) {
@@ -108,8 +111,21 @@ public class CrossCollectionJoinQParser extends QParser {
if (shardsPreference != null && otherParams.get(ShardParams.SHARDS_PREFERENCE) == null) {
otherParams.set(ShardParams.SHARDS_PREFERENCE, shardsPreference);
}
-
+ CloudSolrClient.CloudSolrClientConnection solrConnection = null;
+ if (solrConnectionString != null && !solrConnectionString.isBlank()) {
+ solrConnection = CloudSolrClient.CloudSolrClientConnection.parse(solrConnectionString);
+ } else if (zkHost != null && !zkHost.isBlank()) {
+ solrConnection = CloudSolrClient.CloudSolrClientConnection.parse(zkHost);
+ }
return new CrossCollectionJoinQuery(
- query, zkHost, solrUrl, collection, fromField, toField, routedByJoinKey, ttl, otherParams);
+ query,
+ solrConnection,
+ solrUrl,
+ collection,
+ fromField,
+ toField,
+ routedByJoinKey,
+ ttl,
+ otherParams);
}
}
diff --git a/solr/core/src/java/org/apache/solr/search/join/CrossCollectionJoinQuery.java b/solr/core/src/java/org/apache/solr/search/join/CrossCollectionJoinQuery.java
index 8381ed17dbb..6d12f731f11 100644
--- a/solr/core/src/java/org/apache/solr/search/join/CrossCollectionJoinQuery.java
+++ b/solr/core/src/java/org/apache/solr/search/join/CrossCollectionJoinQuery.java
@@ -38,6 +38,7 @@ import org.apache.lucene.search.ScorerSupplier;
import org.apache.lucene.search.Weight;
import org.apache.lucene.util.BytesRefBuilder;
import org.apache.lucene.util.FixedBitSet;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.SolrClientCache;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.eq.FieldEqualitor;
@@ -70,7 +71,7 @@ import org.apache.solr.util.SolrDefaultScorerSupplier;
public class CrossCollectionJoinQuery extends Query implements SolrSearcherRequirer {
protected final String query;
- protected final String zkHost;
+ protected final CloudSolrClient.CloudSolrClientConnection solrConnection;
protected final String solrUrl;
protected final String collection;
protected final String fromField;
@@ -85,7 +86,7 @@ public class CrossCollectionJoinQuery extends Query implements SolrSearcherRequi
public CrossCollectionJoinQuery(
String query,
- String zkHost,
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
String solrUrl,
String collection,
String fromField,
@@ -95,7 +96,7 @@ public class CrossCollectionJoinQuery extends Query implements SolrSearcherRequi
SolrParams otherParams) {
this.query = query;
- this.zkHost = zkHost;
+ this.solrConnection = solrConnection;
this.solrUrl = solrUrl;
this.collection = collection;
this.fromField = fromField;
@@ -224,11 +225,12 @@ public class CrossCollectionJoinQuery extends Query implements SolrSearcherRequi
private TupleStream createCloudSolrStream(SolrClientCache solrClientCache) throws IOException {
ZkController zkController = searcher.getCore().getCoreContainer().getZkController();
- String streamZkHost;
- if (zkHost != null) {
- streamZkHost = zkHost;
+ CloudSolrClient.CloudSolrClientConnection streamingSolrConnection;
+ if (solrConnection != null) {
+ streamingSolrConnection = solrConnection;
} else {
- streamZkHost = zkController.getZkServerAddress();
+ streamingSolrConnection =
+ CloudSolrClient.CloudSolrClientConnection.parse(zkController.getZkServerAddress());
}
ModifiableSolrParams params = new ModifiableSolrParams(otherParams);
@@ -260,7 +262,8 @@ public class CrossCollectionJoinQuery extends Query implements SolrSearcherRequi
streamContext.setRequestReplicaListTransformerGenerator(rltg);
}
- TupleStream cloudSolrStream = new CloudSolrStream(streamZkHost, collection, params);
+ TupleStream cloudSolrStream =
+ new CloudSolrStream(streamingSolrConnection, collection, params);
TupleStream uniqueStream = new UniqueStream(cloudSolrStream, new FieldEqualitor(fromField));
uniqueStream.setStreamContext(streamContext);
return uniqueStream;
@@ -300,9 +303,9 @@ public class CrossCollectionJoinQuery extends Query implements SolrSearcherRequi
}
private DocSet getDocSet() throws IOException {
- SolrClientCache solrClientCache = searcher.getCore().getCoreContainer().getSolrClientCache();
TupleStream solrStream;
- if (zkHost != null || solrUrl == null) {
+ if (solrConnection != null || solrUrl == null) {
+ var solrClientCache = searcher.getCore().getCoreContainer().getSolrClientCache();
solrStream = createCloudSolrStream(solrClientCache);
} else {
solrStream = createSolrStream();
@@ -381,7 +384,7 @@ public class CrossCollectionJoinQuery extends Query implements SolrSearcherRequi
final int prime = 31;
int result = classHash();
result = prime * result + Objects.hashCode(query);
- result = prime * result + Objects.hashCode(zkHost);
+ result = prime * result + Objects.hashCode(solrConnection);
result = prime * result + Objects.hashCode(solrUrl);
result = prime * result + Objects.hashCode(collection);
result = prime * result + Objects.hashCode(fromField);
@@ -399,7 +402,7 @@ public class CrossCollectionJoinQuery extends Query implements SolrSearcherRequi
private boolean equalsTo(CrossCollectionJoinQuery other) {
return Objects.equals(query, other.query)
- && Objects.equals(zkHost, other.zkHost)
+ && Objects.equals(solrConnection, other.solrConnection)
&& Objects.equals(solrUrl, other.solrUrl)
&& Objects.equals(collection, other.collection)
&& Objects.equals(fromField, other.fromField)
diff --git a/solr/core/src/test/org/apache/solr/cli/DeleteToolTest.java b/solr/core/src/test/org/apache/solr/cli/DeleteToolTest.java
index c0444b82009..8c36e1b661c 100644
--- a/solr/core/src/test/org/apache/solr/cli/DeleteToolTest.java
+++ b/solr/core/src/test/org/apache/solr/cli/DeleteToolTest.java
@@ -65,6 +65,35 @@ public class DeleteToolTest extends SolrCloudTestCase {
assertEquals(0, CLITestHelper.runTool(args, DeleteTool.class));
}
+ @Test
+ public void testDeleteCollectionWithBasicAuthAndConnectionString() throws Exception {
+ String[] connStrings = {
+ getZookeeperSolrConnection().toString(), getHttpSolrConnection().toString()
+ };
+ for (String connectionString : connStrings) {
+ withBasicAuth(
+ CollectionAdminRequest.createCollection(
+ "testDeleteCollectionWithBasicAuth", "conf", 1, 1))
+ .processAndWait(cluster.getSolrClient(), 10);
+ waitForState(
+ "Expected collection to be created with 1 shard and 1 replicas",
+ "testDeleteCollectionWithBasicAuth",
+ clusterShape(1, 1));
+
+ String[] args = {
+ "delete",
+ "-c",
+ "testDeleteCollectionWithBasicAuth",
+ "-s",
+ connectionString,
+ "--credentials",
+ SecurityJson.USER_PASS,
+ "--verbose"
+ };
+ assertEquals(0, CLITestHelper.runTool(args, DeleteTool.class));
+ }
+ }
+
@Test
public void testFailsToDeleteProtectedCollection() throws Exception {
diff --git a/solr/core/src/test/org/apache/solr/cli/HealthcheckToolTest.java b/solr/core/src/test/org/apache/solr/cli/HealthcheckToolTest.java
index 429777afaf4..68d7fba3c5d 100644
--- a/solr/core/src/test/org/apache/solr/cli/HealthcheckToolTest.java
+++ b/solr/core/src/test/org/apache/solr/cli/HealthcheckToolTest.java
@@ -72,4 +72,23 @@ public class HealthcheckToolTest extends SolrCloudTestCase {
String[] args = new String[] {"healthcheck", "-c", "bob", "--solr-url", solrUrl};
assertEquals(0, CLITestHelper.runTool(args, HealthcheckTool.class));
}
+
+ @Test
+ public void testHealthcheckWithSolrConnectionParameter() throws Exception {
+ String[] connStrings = {
+ getZookeeperSolrConnection().toString(), getHttpSolrConnection().toString()
+ };
+ for (String connectionString : connStrings) {
+ String[] args =
+ new String[] {"healthcheck", "-c", "bob", "--solr-connection", connectionString};
+ assertEquals(0, CLITestHelper.runTool(args, HealthcheckTool.class));
+ }
+ }
+
+ @Test
+ public void testHealthcheckWithZookeeperParameter() throws Exception {
+ String zkHost = cluster.getZkServer().getZkAddress();
+ String[] args = new String[] {"healthcheck", "-c", "bob", "--zk-host", zkHost};
+ assertEquals(0, CLITestHelper.runTool(args, HealthcheckTool.class));
+ }
}
diff --git a/solr/core/src/test/org/apache/solr/cli/StreamToolTest.java b/solr/core/src/test/org/apache/solr/cli/StreamToolTest.java
index 5d60662189e..a50254ef67e 100644
--- a/solr/core/src/test/org/apache/solr/cli/StreamToolTest.java
+++ b/solr/core/src/test/org/apache/solr/cli/StreamToolTest.java
@@ -235,8 +235,8 @@ public class StreamToolTest extends SolrCloudTestCase {
"--name",
"fakeCollection",
"--verbose",
- "--zk-host",
- cluster.getZkClient().getZkServerAddress(),
+ "--solr-connection",
+ getSolrConnection().toString(),
expression
};
assertEquals(1, CLITestHelper.runTool(args, StreamTool.class));
@@ -252,8 +252,10 @@ public class StreamToolTest extends SolrCloudTestCase {
"--execution",
"local",
"-v",
- "-z",
- cluster.getZkClient().getZkServerAddress(),
+ "-s",
+ getSolrConnection().toString(),
+ "--credentials",
+ SecurityJson.USER_PASS,
expression
};
assertEquals(0, CLITestHelper.runTool(args, StreamTool.class));
@@ -275,8 +277,10 @@ public class StreamToolTest extends SolrCloudTestCase {
"--execution",
"local",
"--verbose",
- "-zk-host",
- cluster.getZkClient().getZkServerAddress(),
+ "--solr-connection",
+ getSolrConnection().toString(),
+ "--credentials",
+ SecurityJson.USER_PASS,
expressionFile.toString()
};
@@ -289,8 +293,10 @@ public class StreamToolTest extends SolrCloudTestCase {
"--execution",
"local",
"--verbose",
- "--zk-host",
- cluster.getZkClient().getZkServerAddress(),
+ "--solr-connection",
+ getSolrConnection().toString(),
+ "--credentials",
+ SecurityJson.USER_PASS,
expression
};
@@ -339,8 +345,8 @@ public class StreamToolTest extends SolrCloudTestCase {
"--name",
collectionName,
"--verbose",
- "--zk-host",
- cluster.getZkClient().getZkServerAddress(),
+ "--solr-connection",
+ getSolrConnection().toString(),
"--credentials",
SecurityJson.USER_PASS,
expression
diff --git a/solr/core/src/test/org/apache/solr/search/join/CrossCollectionJoinQueryTest.java b/solr/core/src/test/org/apache/solr/search/join/CrossCollectionJoinQueryTest.java
index 70d77363539..078fd4dcf98 100644
--- a/solr/core/src/test/org/apache/solr/search/join/CrossCollectionJoinQueryTest.java
+++ b/solr/core/src/test/org/apache/solr/search/join/CrossCollectionJoinQueryTest.java
@@ -206,6 +206,18 @@ public class CrossCollectionJoinQueryTest extends SolrCloudTestCase {
"{!join method=crossCollection zkHost=\"%s\" fromIndex=products from=product_id_s to=product_id_s}size_s:M",
client.getClusterStateProvider().getQuorumHosts()),
true);
+ testCcJoinQuery(
+ String.format(
+ Locale.ROOT,
+ "{!join method=crossCollection solrConnection=\"%s\" fromIndex=products from=product_id_s to=product_id_s}size_s:M",
+ client.getClusterStateProvider().getQuorumHosts()),
+ true);
+ testCcJoinQuery(
+ String.format(
+ Locale.ROOT,
+ "{!join method=crossCollection solrConnection=\"%s\" fromIndex=products from=product_id_s to=product_id_s}size_s:M",
+ getSolrUrl()),
+ true);
// Test the ability to set other parameters on crossCollection join and have them passed
// through
diff --git a/solr/modules/sql/src/java/org/apache/solr/handler/sql/CalciteSolrDriver.java b/solr/modules/sql/src/java/org/apache/solr/handler/sql/CalciteSolrDriver.java
index 67609eb093a..e77ece4aea0 100644
--- a/solr/modules/sql/src/java/org/apache/solr/handler/sql/CalciteSolrDriver.java
+++ b/solr/modules/sql/src/java/org/apache/solr/handler/sql/CalciteSolrDriver.java
@@ -26,6 +26,7 @@ import org.apache.calcite.schema.SchemaPlus;
import org.apache.calcite.sql.fun.SqlStdOperatorTable;
import org.apache.calcite.sql2rel.SqlToRelConverter;
import org.apache.calcite.util.Holder;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.SolrClientCache;
import org.apache.solr.handler.sql.functions.ArrayContainsAll;
import org.apache.solr.handler.sql.functions.ArrayContainsAny;
@@ -87,7 +88,8 @@ public class CalciteSolrDriver extends Driver {
if (schemaName == null) {
throw new SQLException("zk must be set");
}
- final SolrSchema solrSchema = new SolrSchema(info, solrClientCache);
+ var solrConnection = CloudSolrClient.CloudSolrClientConnection.parse(schemaName);
+ final SolrSchema solrSchema = new SolrSchema(info, solrClientCache, solrConnection);
rootSchema.add(schemaName, solrSchema);
registerUDFs();
diff --git a/solr/modules/sql/src/java/org/apache/solr/handler/sql/SolrSchema.java b/solr/modules/sql/src/java/org/apache/solr/handler/sql/SolrSchema.java
index 376c5df343e..702f0b756eb 100644
--- a/solr/modules/sql/src/java/org/apache/solr/handler/sql/SolrSchema.java
+++ b/solr/modules/sql/src/java/org/apache/solr/handler/sql/SolrSchema.java
@@ -56,6 +56,7 @@ import org.apache.solr.security.PKIAuthenticationPlugin;
class SolrSchema extends AbstractSchema implements Closeable {
final Properties properties;
+ final CloudSolrClient.CloudSolrClientConnection solrConnection;
final SolrClientCache solrClientCache;
private volatile boolean isClosed = false;
@@ -64,10 +65,14 @@ class SolrSchema extends AbstractSchema implements Closeable {
// every statement gets a new SolrSchema instance
private Map<String, RelDataType> schemaCache = new ConcurrentHashMap<>();
- SolrSchema(Properties properties, SolrClientCache solrClientCache) {
+ SolrSchema(
+ Properties properties,
+ SolrClientCache solrClientCache,
+ CloudSolrClient.CloudSolrClientConnection solrConnection) {
super();
this.properties = properties;
this.solrClientCache = solrClientCache;
+ this.solrConnection = solrConnection;
}
public SolrClientCache getSolrClientCache() {
@@ -85,8 +90,7 @@ class SolrSchema extends AbstractSchema implements Closeable {
@Override
protected Map<String, Table> getTableMap() {
- String zk = this.properties.getProperty("zk");
- CloudSolrClient cloudSolrClient = solrClientCache.getCloudSolrClient(zk);
+ CloudSolrClient cloudSolrClient = solrClientCache.getCloudSolrClient(solrConnection);
ClusterState clusterState = cloudSolrClient.getClusterState();
Aliases aliases = ZkStateReader.from(cloudSolrClient).getAliases();
@@ -97,12 +101,13 @@ class SolrSchema extends AbstractSchema implements Closeable {
}
private Map<String, LukeResponse.FieldInfo> getFieldInfo(final String collection) {
- final String zk = this.properties.getProperty("zk");
PKIAuthenticationPlugin.withServerIdentity(true);
try {
LukeRequest lukeRequest = new LukeRequest();
lukeRequest.setNumTerms(0);
- return lukeRequest.process(solrClientCache.getCloudSolrClient(zk), collection).getFieldInfo();
+ return lukeRequest
+ .process(solrClientCache.getCloudSolrClient(solrConnection), collection)
+ .getFieldInfo();
} catch (SolrServerException | IOException e) {
throw new RuntimeException(e);
} finally {
@@ -111,13 +116,12 @@ class SolrSchema extends AbstractSchema implements Closeable {
}
private LukeResponse getSchema(final String collection) {
- final String zk = this.properties.getProperty("zk");
PKIAuthenticationPlugin.withServerIdentity(true);
try {
LukeRequest lukeRequest = new LukeRequest();
lukeRequest.setShowSchema(true); // for empty fields and custom type info ...
lukeRequest.setNumTerms(0);
- return lukeRequest.process(solrClientCache.getCloudSolrClient(zk), collection);
+ return lukeRequest.process(solrClientCache.getCloudSolrClient(solrConnection), collection);
} catch (SolrServerException | IOException e) {
throw new RuntimeException(e);
} finally {
diff --git a/solr/modules/sql/src/java/org/apache/solr/handler/sql/SolrTable.java b/solr/modules/sql/src/java/org/apache/solr/handler/sql/SolrTable.java
index daffb2788ff..fde3ef7807a 100644
--- a/solr/modules/sql/src/java/org/apache/solr/handler/sql/SolrTable.java
+++ b/solr/modules/sql/src/java/org/apache/solr/handler/sql/SolrTable.java
@@ -46,6 +46,7 @@ import org.apache.calcite.schema.SchemaPlus;
import org.apache.calcite.schema.TranslatableTable;
import org.apache.calcite.schema.impl.AbstractTableQueryable;
import org.apache.calcite.util.Pair;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.comp.ComparatorOrder;
import org.apache.solr.client.solrj.io.comp.FieldComparator;
import org.apache.solr.client.solrj.io.comp.MultipleFieldComparator;
@@ -156,17 +157,18 @@ class SolrTable extends AbstractQueryableTable implements TranslatableTable {
TupleStream tupleStream;
String zk = properties.getProperty("zk");
+ var solrConnection = CloudSolrClient.CloudSolrClientConnection.parse(zk);
try {
if (metricPairs.isEmpty() && buckets.isEmpty()) {
- tupleStream = handleSelect(zk, collection, q, fields, orders, limit, offset);
+ tupleStream = handleSelect(solrConnection, collection, q, fields, orders, limit, offset);
} else {
if (buckets.isEmpty()) {
- tupleStream = handleStats(zk, collection, q, metricPairs, fields);
+ tupleStream = handleStats(solrConnection, collection, q, metricPairs, fields);
} else {
if (mapReduce) {
tupleStream =
handleGroupByMapReduce(
- zk,
+ solrConnection,
collection,
properties,
fields,
@@ -179,7 +181,7 @@ class SolrTable extends AbstractQueryableTable implements TranslatableTable {
} else {
tupleStream =
handleGroupByFacet(
- zk,
+ solrConnection,
collection,
fields,
q,
@@ -295,7 +297,7 @@ class SolrTable extends AbstractQueryableTable implements TranslatableTable {
}
private TupleStream handleSelect(
- String zk,
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
String collection,
String query,
List<Map.Entry<String, Class<?>>> fields,
@@ -356,17 +358,19 @@ class SolrTable extends AbstractQueryableTable implements TranslatableTable {
StreamComparator streamSorter = new MultipleFieldComparator(getComps(orders));
limitStream =
new LimitStream(
- new SortStream(new CloudSolrStream(zk, collection, params), streamSorter),
+ new SortStream(
+ new CloudSolrStream(solrConnection, collection, params), streamSorter),
limitInt,
offsetInt);
} else {
params.add(CommonParams.ROWS, limit);
- limitStream = new LimitStream(new CloudSolrStream(zk, collection, params), limitInt);
+ limitStream =
+ new LimitStream(new CloudSolrStream(solrConnection, collection, params), limitInt);
}
return limitStream;
} else {
params.add(CommonParams.QT, "/export");
- return new CloudSolrStream(zk, collection, params);
+ return new CloudSolrStream(solrConnection, collection, params);
}
}
@@ -493,7 +497,7 @@ class SolrTable extends AbstractQueryableTable implements TranslatableTable {
}
private TupleStream handleGroupByMapReduce(
- String zk,
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
String collection,
Properties properties,
final List<Map.Entry<String, Class<?>>> fields,
@@ -517,7 +521,7 @@ class SolrTable extends AbstractQueryableTable implements TranslatableTable {
if (metrics.length == 0) {
return handleSelectDistinctMapReduce(
- zk, collection, properties, fields, query, orders, buckets, limit);
+ solrConnection, collection, properties, fields, query, orders, buckets, limit);
} else {
for (Metric metric : metrics) {
Class<?> c = fmap.get(metric.getIdentifier());
@@ -554,7 +558,7 @@ class SolrTable extends AbstractQueryableTable implements TranslatableTable {
TupleStream tupleStream = null;
- CloudSolrStream cstream = new CloudSolrStream(zk, collection, params);
+ CloudSolrStream cstream = new CloudSolrStream(solrConnection, collection, params);
tupleStream = new RollupStream(cstream, buckets, metrics);
StreamFactory factory =
@@ -591,7 +595,7 @@ class SolrTable extends AbstractQueryableTable implements TranslatableTable {
StreamComparator comp = bucketSortComp(buckets, sortDirection);
@SuppressWarnings("resource")
final ParallelStream parallelStream =
- new ParallelStream(zk, collection, tupleStream, numWorkers, comp);
+ new ParallelStream(solrConnection, collection, tupleStream, numWorkers, comp);
parallelStream.setStreamFactory(factory);
tupleStream = parallelStream;
@@ -641,7 +645,7 @@ class SolrTable extends AbstractQueryableTable implements TranslatableTable {
}
private TupleStream handleGroupByFacet(
- String zkHost,
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
String collection,
final List<Map.Entry<String, Class<?>>> fields,
final String query,
@@ -690,7 +694,7 @@ class SolrTable extends AbstractQueryableTable implements TranslatableTable {
int overfetch = (int) (limit * 1.25);
TupleStream tupleStream =
- new FacetStream(zkHost, collection, solrParams, buckets, metrics, sorts, overfetch);
+ new FacetStream(solrConnection, collection, solrParams, buckets, metrics, sorts, overfetch);
StreamFactory factory =
new StreamFactory()
@@ -727,7 +731,7 @@ class SolrTable extends AbstractQueryableTable implements TranslatableTable {
}
private TupleStream handleSelectDistinctMapReduce(
- final String zkHost,
+ final CloudSolrClient.CloudSolrClientConnection solrConnection,
final String collection,
final Properties properties,
final List<Map.Entry<String, Class<?>>> fields,
@@ -813,7 +817,7 @@ class SolrTable extends AbstractQueryableTable implements TranslatableTable {
TupleStream tupleStream = null;
- CloudSolrStream cstream = new CloudSolrStream(zkHost, collection, params);
+ CloudSolrStream cstream = new CloudSolrStream(solrConnection, collection, params);
tupleStream = new UniqueStream(cstream, ecomp);
if (numWorkers > 1) {
@@ -821,7 +825,7 @@ class SolrTable extends AbstractQueryableTable implements TranslatableTable {
// Maintain the sort of the Tuples coming from the workers.
@SuppressWarnings("resource")
final ParallelStream parallelStream =
- new ParallelStream(zkHost, collection, tupleStream, numWorkers, comp);
+ new ParallelStream(solrConnection, collection, tupleStream, numWorkers, comp);
StreamFactory factory =
new StreamFactory()
@@ -877,7 +881,7 @@ class SolrTable extends AbstractQueryableTable implements TranslatableTable {
}
private TupleStream handleStats(
- String zk,
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
String collection,
String query,
List<Pair<String, String>> metricPairs,
@@ -900,7 +904,7 @@ class SolrTable extends AbstractQueryableTable implements TranslatableTable {
}
}
- return new StatsStream(zk, collection, solrParams, metrics);
+ return new StatsStream(solrConnection, collection, solrParams, metrics);
}
@Override
diff --git a/solr/packaging/test/test_config.bats b/solr/packaging/test/test_config.bats
index 5400d6d91cb..62e482e812c 100644
--- a/solr/packaging/test/test_config.bats
+++ b/solr/packaging/test/test_config.bats
@@ -43,10 +43,10 @@ teardown() {
run solr config -c COLL_NAME --action set-property --property updateHandler.autoCommit.maxDocs --solr-url http://localhost:${SOLR_PORT}
assert_output --partial "'value' is a required option."
-
+
run solr config -c COLL_NAME --action set-property --property updateHandler.autoCommit.maxDocs --value 100 --solr-url http://localhost:${SOLR_PORT}
assert_output --partial "Successfully set-property updateHandler.autoCommit.maxDocs to 100"
-
+
run solr config -c COLL_NAME --action unset-property --property updateHandler.autoCommit.maxDocs --solr-url http://localhost:${SOLR_PORT}
assert_output --partial "Successfully unset-property updateHandler.autoCommit.maxDocs"
}
@@ -59,7 +59,7 @@ teardown() {
assert_output --partial "assuming solr url is http://localhost:${SOLR_PORT}."
}
-@test "connecting to solr via various solr urls and zk hosts" {
+@test "connecting to solr via various connection types" {
solr create -c COLL_NAME
run solr config -c COLL_NAME --property updateHandler.autoCommit.maxDocs --value 100 -s http://localhost:${SOLR_PORT}
@@ -71,4 +71,7 @@ teardown() {
run solr config -c COLL_NAME --property updateHandler.autoCommit.maxDocs --value 100 --zk-host localhost:${ZK_PORT}
assert_output --partial "Successfully set-property updateHandler.autoCommit.maxDocs to 100"
+ run solr config -c COLL_NAME --property updateHandler.autoCommit.maxDocs --value 100 --solr-connection http://localhost:${SOLR_PORT}/solr
+ assert_output --partial "Successfully set-property updateHandler.autoCommit.maxDocs to 100"
+
}
diff --git a/solr/packaging/test/test_create.bats b/solr/packaging/test/test_create.bats
index e9199358253..a261938c23d 100644
--- a/solr/packaging/test/test_create.bats
+++ b/solr/packaging/test/test_create.bats
@@ -42,5 +42,5 @@ teardown() {
@test "multiple connection options are prevented" {
run solr create -c COLL_NAME2 --solr-url http://localhost:${SOLR_PORT} -z localhost:${ZK_PORT}
- assert_output --partial "The option 'z' was specified but an option from this group has already been selected: 's'"
+ assert_output --partial "The option 'z' was specified but an option from this group has already been selected: 'solr-url'"
}
diff --git a/solr/packaging/test/test_delete_collection.bats b/solr/packaging/test/test_delete_collection.bats
index 0ff455d1b27..9cf90fd73bd 100644
--- a/solr/packaging/test/test_delete_collection.bats
+++ b/solr/packaging/test/test_delete_collection.bats
@@ -56,6 +56,15 @@ teardown() {
assert config_exists "COLL_NAME"
}
+@test "can delete collections with solr-connection" {
+ solr create -c "COLL_NAME"
+ assert collection_exists "COLL_NAME"
+
+ solr delete -c "COLL_NAME" --solr-connection http://localhost:${SOLR_PORT}/solr
+ refute collection_exists "COLL_NAME"
+ assert config_exists "COLL_NAME"
+}
+
@test "collection delete also deletes zk config" {
solr create -c "COLL_NAME"
assert config_exists "COLL_NAME"
diff --git a/solr/packaging/test/test_healthcheck.bats b/solr/packaging/test/test_healthcheck.bats
index 30edfeff235..e8f6069cb08 100644
--- a/solr/packaging/test/test_healthcheck.bats
+++ b/solr/packaging/test/test_healthcheck.bats
@@ -32,12 +32,19 @@ teardown() {
solr start -e films
run solr healthcheck -c films
refute_output --partial 'error'
-
+
+}
+
+@test "healthcheck on remote cloud solr" {
+ solr start -e films
+ run solr healthcheck -c films --solr-connection http://localhost:${SOLR_PORT}/solr
+ refute_output --partial 'error'
+
}
@test "healthcheck errors on standalone solr" {
solr start --user-managed -e films
run solr healthcheck -c films
assert_output --partial 'Healthcheck tool only works in Solr Cloud mode'
-
+
}
diff --git a/solr/packaging/test/test_post.bats b/solr/packaging/test/test_post.bats
index 73f4471cc5c..3c90e7d1451 100644
--- a/solr/packaging/test/test_post.bats
+++ b/solr/packaging/test/test_post.bats
@@ -85,6 +85,17 @@ teardown() {
refute_output --partial 'ERROR'
}
+@test "basic post with -s (solr-connection short form) and collection" {
+
+ run solr create -c monitors_s_param -d _default
+ assert_output --partial "Created collection 'monitors_s_param'"
+
+ run solr post --type application/xml -c monitors_s_param -s http://localhost:${SOLR_PORT} ${SOLR_TIP}/example/exampledocs/monitor.xml
+
+ assert_output --partial '1 files indexed.'
+ refute_output --partial 'ERROR'
+}
+
@test "basic post WITHOUT a type specified" {
solr create -c monitors_no_type -d _default
diff --git a/solr/packaging/test/test_snapshots.bats b/solr/packaging/test/test_snapshots.bats
index 5bceed84863..858daccc2a3 100644
--- a/solr/packaging/test/test_snapshots.bats
+++ b/solr/packaging/test/test_snapshots.bats
@@ -37,42 +37,64 @@ setup() {
teardown() {
# save a snapshot of SOLR_HOME for failed tests
save_home_on_failure
-
+
}
-@test "snapshot lifecycle" {
+@test "snapshot lifecycle" {
# the way snapshots live, if you run create twice you get an error because snapshot already exists
run solr snapshot-create -c films --snapshot-name snapshot1 --solr-url http://localhost:${SOLR_PORT}
- assert_output --partial "Successfully created snapshot with name snapshot1 for collection films"
-
+ assert_output --partial "Successfully created snapshot with name snapshot1 for collection films"
+
run solr snapshot-delete -c films --snapshot-name snapshot1 --solr-url http://localhost:${SOLR_PORT}
assert_output --partial "Successfully deleted snapshot with name snapshot1 for collection films"
-
+
# make sure you can create it again!
run solr snapshot-create -c films --snapshot-name snapshot1 -z localhost:${ZK_PORT}
assert_output --partial "Successfully created snapshot with name snapshot1 for collection films"
-
- run solr snapshot-delete -c films --snapshot-name snapshot1
+
+ run solr snapshot-delete -c films --snapshot-name snapshot1
assert_output --partial "Successfully deleted snapshot with name snapshot1 for collection films"
}
-@test "snapshot list" {
+@test "snapshot list" {
solr snapshot-create -c films --snapshot-name snapshot3 --solr-url http://localhost:${SOLR_PORT}
-
+
# Confirm that we continue to normalize away the /solr ending.
run solr snapshot-list -c films -s http://localhost:${SOLR_PORT}/solr
assert_output --partial "snapshot3"
-
+
run solr snapshot-delete -c films --snapshot-name snapshot3 -s http://localhost:${SOLR_PORT}
assert_output --partial "Successfully deleted snapshot with name snapshot3 for collection films"
}
-@test "snapshot describe" {
+@test "snapshot list via --solr-connection" {
+ solr snapshot-create -c films --snapshot-name snapshot3 --solr-connection http://localhost:${SOLR_PORT}/solr
+
+ # Confirm that we continue to normalize away the /solr ending.
+ run solr snapshot-list -c films --solr-connection http://localhost:${SOLR_PORT}/solr
+ assert_output --partial "snapshot3"
+
+ run solr snapshot-delete -c films --snapshot-name snapshot3 --solr-connection http://localhost:${SOLR_PORT}/solr
+ assert_output --partial "Successfully deleted snapshot with name snapshot3 for collection films"
+}
+
+@test "snapshot describe" {
solr snapshot-create -c films --snapshot-name snapshot4 -s http://localhost:${SOLR_PORT}
-
+
run solr snapshot-describe -c films --snapshot-name snapshot4
assert_output --partial "Name: snapshot4"
-
+
run solr snapshot-delete -c films --snapshot-name snapshot4
assert_output --partial "Successfully deleted snapshot with name snapshot4 for collection films"
}
+
+
+@test "snapshot describe via --solr-connection" {
+ solr snapshot-create -c films --snapshot-name snapshot4 --solr-connection http://localhost:${SOLR_PORT}/solr
+
+ run solr snapshot-describe -c films --snapshot-name snapshot4 --solr-connection http://localhost:${SOLR_PORT}/solr
+ assert_output --partial "Name: snapshot4"
+
+ run solr snapshot-delete -c films --snapshot-name snapshot4 --solr-connection http://localhost:${SOLR_PORT}/solr
+ assert_output --partial "Successfully deleted snapshot with name snapshot4 for collection films"
+}
diff --git a/solr/packaging/test/test_status.bats b/solr/packaging/test/test_status.bats
index 5399a0b9fd6..69a5278aca1 100644
--- a/solr/packaging/test/test_status.bats
+++ b/solr/packaging/test/test_status.bats
@@ -55,7 +55,7 @@ teardown() {
@test "multiple connection options are prevented" {
run solr status --port ${SOLR_PORT} --solr-url http://localhost:${SOLR_PORT}
- assert_output --partial "The option 's' was specified but an option from this group has already been selected: 'p'"
+ assert_output --partial "The option 'solr-url' was specified but an option from this group has already been selected: 'p'"
}
@test "status with invalid --solr-url from user" {
diff --git a/solr/packaging/test/test_stream.bats b/solr/packaging/test/test_stream.bats
index 2043d9c0c32..b1a9a27c7cc 100644
--- a/solr/packaging/test/test_stream.bats
+++ b/solr/packaging/test/test_stream.bats
@@ -38,14 +38,14 @@ teardown() {
}
@test "searching solr via locally executed streaming expression" {
-
+
local solr_stream_file="${BATS_TEST_TMPDIR}/search.expr"
echo 'search(techproducts,' > "${solr_stream_file}"
echo 'q="name:memory",' >> "${solr_stream_file}"
echo 'fl="name,price",' >> "${solr_stream_file}"
echo 'sort="price desc"' >> "${solr_stream_file}"
- echo ')' >> "${solr_stream_file}"
-
+ echo ')' >> "${solr_stream_file}"
+
run solr stream --execution local --header --credentials name:password ${solr_stream_file}
assert_output --partial 'name price'
@@ -53,15 +53,15 @@ teardown() {
refute_output --partial 'ERROR'
}
-@test "searching solr via remotely executed streaming expression" {
-
+@test "searching solr via remotely executed streaming expression by solr-url" {
+
local solr_stream_file="${BATS_TEST_TMPDIR}/search.expr"
echo 'search(techproducts,' > "${solr_stream_file}"
echo 'q="name:memory",' >> "${solr_stream_file}"
echo 'fl="name,price",' >> "${solr_stream_file}"
echo 'sort="price desc"' >> "${solr_stream_file}"
echo ')' >> "${solr_stream_file}"
-
+
run solr stream --name techproducts --solr-url http://localhost:${SOLR_PORT} --header --credentials name:password ${solr_stream_file}
assert_output --partial 'name price'
@@ -69,15 +69,31 @@ teardown() {
refute_output --partial 'ERROR'
}
+@test "searching solr via remotely executed streaming expression by solr connection" {
+
+ local solr_stream_file="${BATS_TEST_TMPDIR}/search.expr"
+ echo 'search(techproducts,' > "${solr_stream_file}"
+ echo 'q="name:memory",' >> "${solr_stream_file}"
+ echo 'fl="name,price",' >> "${solr_stream_file}"
+ echo 'sort="price desc"' >> "${solr_stream_file}"
+ echo ')' >> "${solr_stream_file}"
+
+ run solr stream --name techproducts --solr-connection http://localhost:${SOLR_PORT}/solr --header --credentials name:password ${solr_stream_file}
+
+ assert_output --partial 'name price'
+ assert_output --partial 'CORSAIR XMS'
+ refute_output --partial 'ERROR'
+}
+
@test "variable interpolation" {
-
+
local solr_stream_file="${BATS_TEST_TMPDIR}/search.expr"
echo 'search(techproducts,' > "${solr_stream_file}"
echo 'q="name:$1",' >> "${solr_stream_file}"
echo 'fl="name,price",' >> "${solr_stream_file}"
echo 'sort="price $2"' >> "${solr_stream_file}"
echo ')' >> "${solr_stream_file}"
-
+
run solr stream --execution local --header --credentials name:password ${solr_stream_file} apple asc
assert_output --partial 'name price'
diff --git a/solr/packaging/test/test_zk.bats b/solr/packaging/test/test_zk.bats
index 11ee3a7a76d..4cb77a6f590 100644
--- a/solr/packaging/test/test_zk.bats
+++ b/solr/packaging/test/test_zk.bats
@@ -69,6 +69,9 @@ teardown() {
run solr zk ls / --solr-url http://localhost:${SOLR_PORT}
assert_output --partial "aliases.json"
+ run solr zk ls / --solr-connection http://localhost:${SOLR_PORT}
+ assert_output --partial "aliases.json"
+
run solr zk ls / -s http://localhost:${SOLR_PORT}
assert_output --partial "aliases.json"
diff --git a/solr/solr-ref-guide/modules/deployment-guide/pages/solr-control-script-reference.adoc b/solr/solr-ref-guide/modules/deployment-guide/pages/solr-control-script-reference.adoc
index d50c3bbdb2f..f507216396b 100644
--- a/solr/solr-ref-guide/modules/deployment-guide/pages/solr-control-script-reference.adoc
+++ b/solr/solr-ref-guide/modules/deployment-guide/pages/solr-control-script-reference.adoc
@@ -559,7 +559,18 @@ Name of the collection to run a healthcheck against.
+
*Example*: `bin/solr healthcheck -c gettingstarted`
-`-s <url>` or `--solr-url <url>`::
+`-s <connectionString>` or `--solr-connection <connectionString>`::
++
+[%autowidth,frame=none]
+|===
+|Optional |Default: none
+|===
++
+Unified connection target: accepts either a Solr base URL (e.g. `http://localhost:8983`) or a ZooKeeper connection string (e.g. `localhost:9983/solr`). The CLI auto-detects which it is.
++
+If omitted, the CLI falls back to `--solr-url` / `--zk-host`, and finally to `http://localhost:8983`.
+
+`--solr-url <url>`::
+
[%autowidth,frame=none]
|===
@@ -727,17 +738,20 @@ It is possible to override this warning with the --force parameter.
+
*Example*: `bin/solr create -c foo --force`
-`-z <zkHost>` or `--zk-host <zkHost>`::
+`-s <connectionString>` or `--solr-connection <connectionString>`::
+
[%autowidth,frame=none]
|===
-|Optional |Default: `localhost:9983`
+|Optional |Default: none
|===
+
-The ZooKeeper connection string, usable in SolrCloud mode.
-Unnecessary if `ZK_HOST` is defined in `solr.in.sh` or `solr.in.cmd`.
+Unified connection target: accepts either a Solr base URL (e.g. `http://localhost:8983`) or a ZooKeeper connection string (e.g. `localhost:9983/solr`). The CLI auto-detects which it is.
++
+If omitted, the CLI falls back to `--solr-url` / `--zk-host`, and finally to `http://localhost:8983`.
++
+*Example*: `bin/solr create -c gettingstarted -s http://localhost:8983`
-`-s <url>` or `--solr-url <url>`::
+`--solr-url <url>`::
+
[%autowidth,frame=none]
|===
@@ -746,6 +760,16 @@ Unnecessary if `ZK_HOST` is defined in `solr.in.sh` or `solr.in.cmd`.
+
Base Solr URL, which can be used in SolrCloud mode to determine the ZooKeeper connection string if that's not known.
+`-z <zkHost>` or `--zk-host <zkHost>`::
++
+[%autowidth,frame=none]
+|===
+|Optional |Default: `localhost:9983`
+|===
++
+The ZooKeeper connection string, usable in SolrCloud mode.
+Unnecessary if `ZK_HOST` is defined in `solr.in.sh` or `solr.in.cmd`.
+
`-u <user:pass>` or `--credentials <user:pass>`::
+
[%autowidth,frame=none]
@@ -846,17 +870,18 @@ If the configuration directory is being used by another collection, then it will
+
Skip safety checks when deleting the configuration directory used by a collection.
-`-z <zkHost>` or `--zk-host <zkHost>`::
+`-s <connectionString>` or `--solr-connection <connectionString>`::
+
[%autowidth,frame=none]
|===
-|Optional |Default: `localhost:9983`
+|Optional |Default: none
|===
+
-The ZooKeeper connection string, usable in SolrCloud mode.
-Unnecessary if `ZK_HOST` is defined in `solr.in.sh` or `solr.in.cmd`.
+Unified connection target: accepts either a Solr base URL (e.g. `http://localhost:8983`) or a ZooKeeper connection string (e.g. `localhost:9983/solr`). The CLI auto-detects which it is.
++
+If omitted, the CLI falls back to `--solr-url` / `--zk-host`, and finally to `http://localhost:8983`.
-`-s <url>` or `--solr-url <url>`::
+`--solr-url <url>`::
+
[%autowidth,frame=none]
|===
@@ -865,6 +890,16 @@ Unnecessary if `ZK_HOST` is defined in `solr.in.sh` or `solr.in.cmd`.
+
Base Solr URL, which can be used in SolrCloud mode to determine the ZooKeeper connection string if that's not known.
+`-z <zkHost>` or `--zk-host <zkHost>`::
++
+[%autowidth,frame=none]
+|===
+|Optional |Default: `localhost:9983`
+|===
++
+The ZooKeeper connection string, usable in SolrCloud mode.
+Unnecessary if `ZK_HOST` is defined in `solr.in.sh` or `solr.in.cmd`.
+
`-u <user:pass>` or `--credentials <user:pass>`::
+
[%autowidth,frame=none]
@@ -1090,17 +1125,18 @@ Name of the Config API property to apply the action to, such as: 'updateHandler.
+
Set the property to this value; accepts JSON objects and strings.
-`-z <zkHost>` or `--zk-host <zkHost>`::
+`-s <connectionString>` or `--solr-connection <connectionString>`::
+
[%autowidth,frame=none]
|===
-|Optional |Default: `localhost:9983`
+|Optional |Default: none
|===
+
-The ZooKeeper connection string, usable in SolrCloud mode.
-Unnecessary if `ZK_HOST` is defined in `solr.in.sh` or `solr.in.cmd`.
+Unified connection target: accepts either a Solr base URL (e.g. `http://localhost:8983`) or a ZooKeeper connection string (e.g. `localhost:9983/solr`). The CLI auto-detects which it is.
++
+If omitted, the CLI falls back to `--solr-url` / `--zk-host`, and finally to `http://localhost:8983`.
-`-s <url>` or `--solr-url <url>`::
+`--solr-url <url>`::
+
[%autowidth,frame=none]
|===
@@ -1109,6 +1145,16 @@ Unnecessary if `ZK_HOST` is defined in `solr.in.sh` or `solr.in.cmd`.
+
Base Solr URL, which can be used in SolrCloud mode to determine the ZooKeeper connection string if that's not known.
+`-z <zkHost>` or `--zk-host <zkHost>`::
++
+[%autowidth,frame=none]
+|===
+|Optional |Default: `localhost:9983`
+|===
++
+The ZooKeeper connection string, usable in SolrCloud mode.
+Unnecessary if `ZK_HOST` is defined in `solr.in.sh` or `solr.in.cmd`.
+
`-s <scheme>` or `-scheme <scheme>`::
+
[%autowidth,frame=none]
@@ -1210,18 +1256,18 @@ An absolute path may be supplied instead.
* `-d directory_under_configsets`
* `-d /path/to/configset/source`
-`-z <zkHost>` or `--zk-host <zkHost>`::
+`-s <connectionString>` or `--solr-connection <connectionString>`::
+
[%autowidth,frame=none]
|===
-|Optional |Default: `localhost:2181` if `ZK_HOST` env var not set
+|Optional |Default: none
|===
+
-The ZooKeeper connection string.
+Unified connection target: accepts either a Solr base URL (e.g. `http://localhost:8983`) or a ZooKeeper connection string (e.g. `localhost:9983/solr`). The CLI auto-detects which it is.
+
-*Example*: `-z 123.321.23.43:2181`
+If omitted, the CLI falls back to `--solr-url` / `--zk-host`, and finally to `http://localhost:8983`.
-`-s <url>` or `--solr-url <url>`::
+`--solr-url <url>`::
+
[%autowidth,frame=none]
|===
@@ -1230,6 +1276,17 @@ The ZooKeeper connection string.
+
Base Solr URL, which can be used in SolrCloud mode to determine the ZooKeeper connection string if that's not known.
+`-z <zkHost>` or `--zk-host <zkHost>`::
++
+[%autowidth,frame=none]
+|===
+|Optional |Default: `localhost:2181` if `ZK_HOST` env var not set
+|===
++
+The ZooKeeper connection string.
++
+*Example*: `-z 123.321.23.43:2181`
+
An example of this command with all of the parameters is:
[source,bash]
@@ -1281,18 +1338,18 @@ In either case, _pre-existing configurations at the destination will be overwrit
* `-d directory_under_configsets`
* `-d /path/to/configset/destination`
-`-z <zkHost>` or `--zk-host <zkHost>`::
+`-s <connectionString>` or `--solr-connection <connectionString>`::
+
[%autowidth,frame=none]
|===
-|Optional |Default: `localhost:2181` if `ZK_HOST` env var not set
+|Optional |Default: none
|===
+
-The ZooKeeper connection string.
+Unified connection target: accepts either a Solr base URL (e.g. `http://localhost:8983`) or a ZooKeeper connection string (e.g. `localhost:9983/solr`). The CLI auto-detects which it is.
+
-*Example*: `-z 123.321.23.43:2181`
+If omitted, the CLI falls back to `--solr-url` / `--zk-host`, and finally to `http://localhost:8983`.
-`-s <url>` or `--solr-url <url>`::
+`--solr-url <url>`::
+
[%autowidth,frame=none]
|===
@@ -1301,6 +1358,17 @@ The ZooKeeper connection string.
+
Base Solr URL, which can be used in SolrCloud mode to determine the ZooKeeper connection string if that's not known.
+`-z <zkHost>` or `--zk-host <zkHost>`::
++
+[%autowidth,frame=none]
+|===
+|Optional |Default: `localhost:2181` if `ZK_HOST` env var not set
+|===
++
+The ZooKeeper connection string.
++
+*Example*: `-z 123.321.23.43:2181`
+
An example of this command with all parameters is:
[source,bash]
@@ -1364,18 +1432,18 @@ If `<dest>` ends in a slash character it names a directory.
* `zk:/configs/myconfigs/solrconfig.xml`
* `file:/Users/apache/configs/src`
-`-z <zkHost>` or `--zk-host <zkHost>`::
+`-s <connectionString>` or `--solr-connection <connectionString>`::
+
[%autowidth,frame=none]
|===
-|Optional |Default: `localhost:2181` if `ZK_HOST` env var not set
+|Optional |Default: none
|===
+
-The ZooKeeper connection string.
+Unified connection target: accepts either a Solr base URL (e.g. `http://localhost:8983`) or a ZooKeeper connection string (e.g. `localhost:9983/solr`). The CLI auto-detects which it is.
+
-*Example*: `-z 123.321.23.43:2181`
+If omitted, the CLI falls back to `--solr-url` / `--zk-host`, and finally to `http://localhost:8983`.
-`-s <url>` or `--solr-url <url>`::
+`--solr-url <url>`::
+
[%autowidth,frame=none]
|===
@@ -1384,6 +1452,17 @@ The ZooKeeper connection string.
+
Base Solr URL, which can be used in SolrCloud mode to determine the ZooKeeper connection string if that's not known.
+`-z <zkHost>` or `--zk-host <zkHost>`::
++
+[%autowidth,frame=none]
+|===
+|Optional |Default: `localhost:2181` if `ZK_HOST` env var not set
+|===
++
+The ZooKeeper connection string.
++
+*Example*: `-z 123.321.23.43:2181`
+
When `<src>` is a zk resource, `<dest>` may be '.'.
If `<dest>` ends with '/', then `<dest>` will be a local folder or parent znode and the last element of the <src> path will be appended unless `<src>` also ends in a slash.
`<dest>` may be `zk:`, which may be useful when using the `cp -r` form to backup/restore the entire zk state.
@@ -1446,18 +1525,18 @@ The path is assumed to be a ZooKeeper node, no `zk:` prefix is necessary.
* `/configs/myconfigset`
* `/configs/myconfigset/solrconfig.xml`
-`-z <zkHost>` or `--zk-host <zkHost>`::
+`-s <connectionString>` or `--solr-connection <connectionString>`::
+
[%autowidth,frame=none]
|===
-|Optional |Default: `localhost:2181` if `ZK_HOST` env var not set
+|Optional |Default: none
|===
+
-The ZooKeeper connection string.
+Unified connection target: accepts either a Solr base URL (e.g. `http://localhost:8983`) or a ZooKeeper connection string (e.g. `localhost:9983/solr`). The CLI auto-detects which it is.
+
-*Example*: `-z 123.321.23.43:2181`
+If omitted, the CLI falls back to `--solr-url` / `--zk-host`, and finally to `http://localhost:8983`.
-`-s <url>` or `--solr-url <url>`::
+`--solr-url <url>`::
+
[%autowidth,frame=none]
|===
@@ -1466,6 +1545,17 @@ The ZooKeeper connection string.
+
Base Solr URL, which can be used in SolrCloud mode to determine the ZooKeeper connection string if that's not known.
+`-z <zkHost>` or `--zk-host <zkHost>`::
++
+[%autowidth,frame=none]
+|===
+|Optional |Default: `localhost:2181` if `ZK_HOST` env var not set
+|===
++
+The ZooKeeper connection string.
++
+*Example*: `-z 123.321.23.43:2181`
+
Examples of this command with the parameters are:
`bin/solr zk rm -r /configs`
@@ -1503,22 +1593,18 @@ The `zk:` prefix is assumed.
+
*Example*: `/configs/newconfigset`
-`-z <zkHost>` or `--zk-host <zkHost>`::
+`-s <connectionString>` or `--solr-connection <connectionString>`::
+
[%autowidth,frame=none]
|===
-|Optional |Default: `localhost:2181` if `ZK_HOST` env var not set
+|Optional |Default: none
|===
+
-The ZooKeeper connection string.
+Unified connection target: accepts either a Solr base URL (e.g. `http://localhost:8983`) or a ZooKeeper connection string (e.g. `localhost:9983/solr`). The CLI auto-detects which it is.
+
-*Example*: `-z 123.321.23.43:2181`
-
-An example of this command is:
+If omitted, the CLI falls back to `--solr-url` / `--zk-host`, and finally to `http://localhost:8983`.
-`bin/solr zk mv /configs/oldconfigset /configs/newconfigset`
-
-`-s <url>` or `--solr-url <url>`::
+`--solr-url <url>`::
+
[%autowidth,frame=none]
|===
@@ -1527,6 +1613,21 @@ An example of this command is:
+
Base Solr URL, which can be used in SolrCloud mode to determine the ZooKeeper connection string if that's not known.
+`-z <zkHost>` or `--zk-host <zkHost>`::
++
+[%autowidth,frame=none]
+|===
+|Optional |Default: `localhost:2181` if `ZK_HOST` env var not set
+|===
++
+The ZooKeeper connection string.
++
+*Example*: `-z 123.321.23.43:2181`
+
+An example of this command is:
+
+`bin/solr zk mv /configs/oldconfigset /configs/newconfigset`
+
=== List a ZooKeeper znode's Children
@@ -1557,18 +1658,18 @@ The path on ZooKeeper to list.
+
*Example*: `/collections/mycollection`
-`-z <zkHost>` or `--zk-host <zkHost>`::
+`-s <connectionString>` or `--solr-connection <connectionString>`::
+
[%autowidth,frame=none]
|===
-|Optional |Default: `localhost:2181` if `ZK_HOST` env var not set
+|Optional |Default: none
|===
+
-The ZooKeeper connection string.
+Unified connection target: accepts either a Solr base URL (e.g. `http://localhost:8983`) or a ZooKeeper connection string (e.g. `localhost:9983/solr`). The CLI auto-detects which it is.
+
-*Example*: `-z 123.321.23.43:2181`
+If omitted, the CLI falls back to `--solr-url` / `--zk-host`, and finally to `http://localhost:8983`.
-`-s <url>` or `--solr-url <url>`::
+`--solr-url <url>`::
+
[%autowidth,frame=none]
|===
@@ -1577,6 +1678,17 @@ The ZooKeeper connection string.
+
Base Solr URL, which can be used in SolrCloud mode to determine the ZooKeeper connection string if that's not known.
+`-z <zkHost>` or `--zk-host <zkHost>`::
++
+[%autowidth,frame=none]
+|===
+|Optional |Default: `localhost:2181` if `ZK_HOST` env var not set
+|===
++
+The ZooKeeper connection string.
++
+*Example*: `-z 123.321.23.43:2181`
+
An example of this command with the parameters is:
`bin/solr zk ls -r /collections/mycollection`
@@ -1605,18 +1717,18 @@ A leading slash is assumed if not present.
+
*Example*: `/solr`
-`-z <zkHost>` or `--zk-host <zkHost>`::
+`-s <connectionString>` or `--solr-connection <connectionString>`::
+
[%autowidth,frame=none]
|===
-|Optional |Default: `localhost:2181` if `ZK_HOST` env var not set
+|Optional |Default: none
|===
+
-The ZooKeeper connection string.
+Unified connection target: accepts either a Solr base URL (e.g. `http://localhost:8983`) or a ZooKeeper connection string (e.g. `localhost:9983/solr`). The CLI auto-detects which it is.
+
-*Example*: `-z 123.321.23.43:2181`
+If omitted, the CLI falls back to `--solr-url` / `--zk-host`, and finally to `http://localhost:8983`.
-`-s <url>` or `--solr-url <url>`::
+`--solr-url <url>`::
+
[%autowidth,frame=none]
|===
@@ -1625,6 +1737,17 @@ The ZooKeeper connection string.
+
Base Solr URL, which can be used in SolrCloud mode to determine the ZooKeeper connection string if that's not known.
+`-z <zkHost>` or `--zk-host <zkHost>`::
++
+[%autowidth,frame=none]
+|===
+|Optional |Default: `localhost:2181` if `ZK_HOST` env var not set
+|===
++
+The ZooKeeper connection string.
++
+*Example*: `-z 123.321.23.43:2181`
+
Examples of this command:
`bin/solr zk mkroot /solr -z 123.321.23.43:2181`
@@ -1648,7 +1771,18 @@ NOTE: The `export` command only works with Solr running in cloud mode.
The `bin/solr export` command takes the following parameters:
-`-s <url>` or `--solr-url <url>`::
+`-s <connectionString>` or `--solr-connection <connectionString>`::
++
+[%autowidth,frame=none]
+|===
+|Optional |Default: none
+|===
++
+Unified connection target: accepts either a Solr base URL (e.g. `http://localhost:8983`) or a ZooKeeper connection string (e.g. `localhost:9983/solr`). The CLI auto-detects which it is.
++
+If omitted, the CLI falls back to `--solr-url` / `--zk-host`, and finally to `http://localhost:8983`.
+
+`--solr-url <url>`::
+
[%autowidth,frame=none]
|===
@@ -1814,7 +1948,7 @@ If you have configured basicAuth or TLS with your Solr you may find this easier
The `bin/solr api` command takes the following parameters:
-`-s <url>` or `--solr-url <url>`::
+`--solr-url <url>`::
+
[%autowidth,frame=none]
|===
diff --git a/solr/solr-ref-guide/modules/query-guide/pages/join-query-parser.adoc b/solr/solr-ref-guide/modules/query-guide/pages/join-query-parser.adoc
index 1b116c8c5a8..ac39ceed751 100644
--- a/solr/solr-ref-guide/modules/query-guide/pages/join-query-parser.adoc
+++ b/solr/solr-ref-guide/modules/query-guide/pages/join-query-parser.adoc
@@ -296,6 +296,17 @@ s|Required |Default: none
+
The name of the external Solr collection to be queried to retrieve the set of join key values.
+`solrConnection`::
++
+[%autowidth,frame=none]
+|===
+|Optional |Default: none
+|===
++
+The connection string to be used to connect to SolrCloud cluster via ZooKeeper or HTTP(s).
+`solrConnection`, `zkHost` and `solrUrl` are optional parameters, and at most one of them should be specified.
+If neither `solrConnection`, `zkHost` nor `solrUrl` are specified, the local ZooKeeper cluster will be used.
+
`zkHost`::
+
[%autowidth,frame=none]
@@ -306,6 +317,7 @@ The name of the external Solr collection to be queried to retrieve the set of jo
The connection string to be used to connect to ZooKeeper.
`zkHost` and `solrUrl` are both optional parameters, and at most one of them should be specified.
If neither `zkHost` nor `solrUrl` are specified, the local ZooKeeper cluster will be used.
+This parameter is deprecated. Use `solrConnection` instead.
`solrUrl`::
+
diff --git a/solr/solr-ref-guide/modules/query-guide/pages/sql-query.adoc b/solr/solr-ref-guide/modules/query-guide/pages/sql-query.adoc
index a67678f105f..76502cf5545 100644
--- a/solr/solr-ref-guide/modules/query-guide/pages/sql-query.adoc
+++ b/solr/solr-ref-guide/modules/query-guide/pages/sql-query.adoc
@@ -548,11 +548,34 @@ Please refer to the https://search.maven.org/artifact/org.apache.solr/solr-solrj
If you are using Maven, the `org.apache.solr.solr-solrj` artifact contains the required jars.
-Once the jars are available on the classpath, the Solr JDBC driver name is `org.apache.solr.client.solrj.io.sql.DriverImpl` and a connection can be made with the following connection string format:
+Once the jars are available on the classpath, the Solr JDBC driver name is `org.apache.solr.client.solrj.io.sql.DriverImpl` and a connection can be made with the following connection string formats:
+==== HTTP-based JDBC URL
+[source,plain]
+----
+jdbc:solr:http://SOLR_HTTP_CONNECTION_STRING?collection=COLLECTION_NAME
+----
+
+For example:
+
+[source,plain]
+----
+jdbc:solr:http://solr1.example.com:8983/solr?collection=COLLECTION_NAME
+----
+
+
+==== ZooKeeper-based JDBC URL
[source,plain]
----
jdbc:solr://SOLR_ZK_CONNECTION_STRING?collection=COLLECTION_NAME
----
+For example:
+
+[source,plain]
+----
+jdbc:solr://zoo.example.com:2181/solr?collection=COLLECTION_NAME
+----
+
+
There are other parameters that can be optionally added to the connection string like `aggregationMode` and `numWorkers`.
diff --git a/solr/solr-ref-guide/modules/query-guide/pages/stream-source-reference.adoc b/solr/solr-ref-guide/modules/query-guide/pages/stream-source-reference.adoc
index 0f39d3a812b..c23af69f8b4 100644
--- a/solr/solr-ref-guide/modules/query-guide/pages/stream-source-reference.adoc
+++ b/solr/solr-ref-guide/modules/query-guide/pages/stream-source-reference.adoc
@@ -35,7 +35,9 @@ To read more about the `/export` handler requirements review the section xref:ex
* `q`: (Mandatory) The query to perform on the Solr index.
* `fl`: (Mandatory) The list of fields to return.
* `sort`: (Mandatory) The sort criteria.
-* `zkHost`: Only needs to be defined if the collection being searched is found in a different zkHost than the local stream handler.
+* `solrConnection`: (Optional) Only needs to be defined if the collection being queried resides in a different Solr cluster than the local stream handler. The connection can be provided either as an HTTP(S) URL list or as a ZooKeeper connection string.
+When using a zookeeper connection string, zookeeper credentials and ACLs will only be included if the same zookeeper host is used as the Solr instance that you are connecting to (the `chroot` can be different).
+* `zkHost`: (Deprecated, use `solrConnection`) Only needs to be defined if the collection being searched is found in a different zkHost than the local stream handler.
Zookeeper Credentials and ACLs will only be included if the same ZkHost is used as the Solr instance that you are connecting to (the `chroot` can be different).
* `qt`: Specifies the query type, or request handler, to use.
Set this to `/export` to work with large result sets.
@@ -51,7 +53,7 @@ See the xref:stream-decorator-reference.adoc#parallel[parallel] function for det
[source,text]
----
expr=search(collection1,
- zkHost="localhost:9983",
+ solrConnection="localhost:9983",
qt="/export",
q="*:*",
fl="id,a_s,a_i,a_f",
@@ -484,7 +486,9 @@ When used in parallel mode the partitionKeys parameter must be provided.
* `q`: (Mandatory) The query to perform on the Solr index.
* `fl`: (Mandatory) The list of fields to return.
* `sort`: (Mandatory) The sort criteria.
-* `zkHost`: Only needs to be defined if the collection being searched is found in a different zkHost than the local stream handler.
+* `solrConnection` (Optional): Only needs to be defined if the collection being queried resides in a different Solr cluster than the local stream handler. The connection can be provided either as an HTTP(S) URL list or as a ZooKeeper connection string.
+When using a zookeeper connection string, zookeeper credentials and ACLs will only be included if the same zookeeper host is used as the Solr instance that you are connecting to (the `chroot` can be different).
+* `zkHost`: (Deprecated, use `solrConnection`) Only needs to be defined if the collection being searched is found in a different zkHost than the local stream handler.
Zookeeper Credentials and ACLs will only be included if the same ZkHost is used as the Solr instance that you are connecting to (the `chroot` can be different).
* `partitionKeys`: Comma delimited list of keys to partition the search results by.
To be used with the parallel function for parallelizing operations across worker nodes.
@@ -649,7 +653,9 @@ The checkpoints will be saved under this id.
* `initialCheckpoint`: (Optional) Sets the initial Solr `\_version_` number to start reading from the queue.
If not set, it defaults to the highest version in the index.
Setting to 0 will process all records that match query in the index.
-* `zkHost`: (Optional) Only needs to be defined if the collection being searched is found in a different zkHost than the local stream handler.
+* `solrConnection` (Optional): Only needs to be defined if the collection being queried resides in a different Solr cluster than the local stream handler. The connection can be provided either as an HTTP(S) URL list or as a ZooKeeper connection string.
+When using a zookeeper connection string, zookeeper credentials and ACLs will only be included if the same zookeeper host is used as the Solr instance that you are connecting to (the `chroot` can be different).
+* `zkHost`: (Deprecated, use `solrConnection`) Only needs to be defined if the collection being searched is found in a different zkHost than the local stream handler.
Zookeeper Credentials and ACLs will only be included if the same ZkHost is used as the Solr instance that you are connecting to (the `chroot` can be different).
=== topic Syntax
diff --git a/solr/solr-ref-guide/modules/query-guide/pages/stream-tool.adoc b/solr/solr-ref-guide/modules/query-guide/pages/stream-tool.adoc
index acb5d6964e7..3d4dd842bd8 100644
--- a/solr/solr-ref-guide/modules/query-guide/pages/stream-tool.adoc
+++ b/solr/solr-ref-guide/modules/query-guide/pages/stream-tool.adoc
@@ -18,7 +18,7 @@
The Stream tool allows you to run a xref:streaming-expressions.adoc[] in Solr and see the results from the command line.
It is very similar to the xref:stream-screen.adoc[], but is part of the `bin/solr` CLI.
-Being a CLI, you can pipe content into it similar to other Unix style tools, as well as run actually RUN many kinds of expressions locally as well.
+Being a CLI, you can pipe content into it similar to other Unix style tools, as well as run actually RUN many kinds of expressions locally as well.
NOTE: The Stream Tool is classified as "experimental".
It may change in backwards-incompatible ways as it evolves to cover additional functionality.
@@ -30,7 +30,7 @@ To run it, open a terminal and enter:
$ bin/solr stream -c techproducts --header --fields price,name --delimiter=\| 'search(techproducts,q="iPod",fl="name,price")'
----
-This will run the provided streaming expression on the `techproducts` collection on your local Solr and produce:
+This will run the provided streaming expression on the `techproducts` collection on your local Solr and produce:
[,console]
----
@@ -110,8 +110,11 @@ List of options:
defaults to: http://localhost:8983.
-u,--credentials <credentials> Credentials in the format username:password. Example: --credentials solr:SolrRocks
-v,--verbose Enable verbose command output.
+ -sc,--solr-connection <HOST> Zookeeper or HTTP(S) connection string; unnecessary if SOLR_CONNECTION is defined in solr.in.sh;
+ otherwise, defaults to localhost:9983.
-z,--zk-host <HOST> Zookeeper connection string; unnecessary if ZK_HOST is defined in solr.in.sh;
otherwise, defaults to localhost:9983.
+ Deprecated: use --solr-connection option
----
== Examples Using bin/solr stream
@@ -121,7 +124,7 @@ This section presents several examples.
=== Executing Expression Locally
-Streaming Expressions by default are executed in the Solr cluster.
+Streaming Expressions by default are executed in the Solr cluster.
However there are use cases where you want to interact with data in your local environment, or even run a streaming expression independent of Solr.
The Stream Tool allows you to specify `--execution local` to process the expression in the Solr CLI's JVM.
diff --git a/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-10.adoc b/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-10.adoc
index 9dcec0644e9..627816636c5 100644
--- a/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-10.adoc
+++ b/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-10.adoc
@@ -40,6 +40,26 @@ For SSL (https), it's no longer necessary to set the "urlScheme" cluster propert
These are now honored by CloudSolrClient, as well as scheme detection from the connection string / hosts.
The "urlScheme" cluster property and httpShardHandlerFactory configuration is likely to be deprecated; feedback welcome.
+=== Universal connection string support
+
+Introduced a universal Solr connection string for SolrCloud connections.
+
+Connections can now be configured via HTTP(S) without exposing ZooKeeper details, while the legacy ZooKeeper-based connection method remains fully supported.
+
+Examples:
+`solrConnection=http://solr1:8983/solr,http://solr2:8983/solr`
+`solrConnection=zoo1:2181,zoo2:2181,zoo3:2181/solr`
+
+The universal connection string is now supported in the following components and entry points:
+
+* Added `CloudSolrClient.Builder(String)` constructor in SolrJ for configuring SolrCloud clients using either HTTP(S)-based or ZooKeeper-based connection strings.
+* Added `solrConnection` parameter to all streaming functions in the SolrJ Streaming module. The existing `zkHost` parameter remains supported.
+* Added `withDefaultSolrConnection` and `withCollectionSolrConnection` methods to `StreamFactory` in the SolrJ Streaming module.
+* Solr SQL JDBC driver now supports both HTTP-based (`jdbc:solr:http://solr1.example.com:8983/solr?collection=COLLECTION_NAME`) and ZooKeeper-based (`jdbc:solr://zoo.example.com:2181/solr?collection=COLLECTION_NAME`) JDBC URLs.
+* Added `--solr-connection` option to the CLI tools.
+* Updated Solr CLI `-s` short option to invoke `--solr-connection` instead of `--solr-url`, which is a backwards compatible change.
+* Added `solrConnection` parameter to the Join Query Parser.
+
=== v2 API
Starting in Solr 10.1 it is no longer possible for users to disable the v2 API by use of the `solr.api.v2.enabled` system property, and the Solr server and tooling (`bin/solr`, Admin UI, etc.) will start using these APIs internally.
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/Lang.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/Lang.java
index 2c0e3a4de7a..d95616c73cd 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/Lang.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/Lang.java
@@ -371,8 +371,6 @@ public class Lang {
.withFunctionName("nodes", GatherNodesStream.class)
.withFunctionName("select", SelectStream.class)
.withFunctionName("shortestPath", ShortestPathStream.class)
- .withFunctionName("gatherNodes", GatherNodesStream.class)
- .withFunctionName("nodes", GatherNodesStream.class)
.withFunctionName("scoreNodes", ScoreNodesStream.class)
.withFunctionName("model", ModelStream.class)
.withFunctionName("fetch", FetchStream.class)
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/ModelCache.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/ModelCache.java
index 1f22acdde33..e6e19b648b8 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/ModelCache.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/ModelCache.java
@@ -23,6 +23,7 @@ import java.io.IOException;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.stream.CloudSolrStream;
import org.apache.solr.client.solrj.io.stream.StreamContext;
import org.apache.solr.common.params.ModifiableSolrParams;
@@ -31,20 +32,27 @@ import org.apache.solr.common.params.ModifiableSolrParams;
public class ModelCache {
private LRU models;
- private String defaultZkHost;
+ private CloudSolrClient.CloudSolrClientConnection solrConnection;
private SolrClientCache solrClientCache;
- public ModelCache(int size, String defaultZkHost, SolrClientCache solrClientCache) {
+ public ModelCache(
+ int size,
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
+ SolrClientCache solrClientCache) {
this.models = new LRU(size);
- this.defaultZkHost = defaultZkHost;
+ this.solrConnection = solrConnection;
this.solrClientCache = solrClientCache;
}
public Tuple getModel(String collection, String modelID, long checkMillis) throws IOException {
- return getModel(defaultZkHost, collection, modelID, checkMillis);
+ return getModel(solrConnection, collection, modelID, checkMillis);
}
- public Tuple getModel(String zkHost, String collection, String modelID, long checkMillis)
+ public Tuple getModel(
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
+ String collection,
+ String modelID,
+ long checkMillis)
throws IOException {
Model model = null;
long currentTime = new Date().getTime();
@@ -67,7 +75,7 @@ public class ModelCache {
params.set(SORT, "iteration_i desc");
StreamContext streamContext = new StreamContext();
streamContext.setSolrClientCache(solrClientCache);
- CloudSolrStream stream = new CloudSolrStream(zkHost, collection, params);
+ CloudSolrStream stream = new CloudSolrStream(solrConnection, collection, params);
stream.setStreamContext(streamContext);
Tuple tuple = null;
try {
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/SolrClientCache.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/SolrClientCache.java
index 3aa7748bc01..3503bdb9079 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/SolrClientCache.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/SolrClientCache.java
@@ -46,7 +46,9 @@ public class SolrClientCache implements Closeable {
protected String basicAuthCredentials = null; // Only support with the httpJettySolrClient
- private final Map<String, SolrClient> solrClients = new HashMap<>();
+ private final Map<String, SolrClient> httpSolrClients = new HashMap<>();
+ private final Map<CloudSolrClient.CloudSolrClientConnection, CloudSolrClient> cloudSolClients =
+ new HashMap<>();
private final HttpSolrClient httpSolrClient;
private final AtomicBoolean isClosed = new AtomicBoolean(false);
private final AtomicReference<String> defaultZkHost = new AtomicReference<>();
@@ -74,36 +76,41 @@ public class SolrClientCache implements Closeable {
}
}
- public synchronized CloudSolrClient getCloudSolrClient(String connectionString) {
+ /**
+ * @deprecated use {@link #getCloudSolrClient(CloudSolrClient.CloudSolrClientConnection)}
+ */
+ @Deprecated
+ public CloudSolrClient getCloudSolrClient(String solrConnectionString) {
+ var solrConnection = CloudSolrClient.CloudSolrClientConnection.parse(solrConnectionString);
+ return getCloudSolrClient(solrConnection);
+ }
+
+ public synchronized CloudSolrClient getCloudSolrClient(
+ CloudSolrClient.CloudSolrClientConnection solrConnection) {
ensureOpen();
- Objects.requireNonNull(connectionString, "Connection string cannot be null!");
- if (solrClients.containsKey(connectionString)) {
- return (CloudSolrClient) solrClients.get(connectionString);
- }
- // Can only use ZK ACLs if there is a default ZK Host, and the given ZK host contains that
- // default.
- // Basically the ZK ACLs are assumed to be only used for the default ZK host,
- // thus we should only provide the ACLs to that Zookeeper instance.
+ return cloudSolClients.computeIfAbsent(
+ solrConnection, sc -> newCloudSolrClient(sc, httpSolrClient, useAclForZookeeper(sc)));
+ }
+
+ // Can only use ZK ACLs if there is a default ZK Host, and the given ZK host contains that
+ // default.
+ // Basically the ZK ACLs are assumed to be only used for the default ZK host,
+ // thus we should only provide the ACLs to that Zookeeper instance.
+ private boolean useAclForZookeeper(CloudSolrClient.CloudSolrClientConnection solrConnection) {
boolean canUseACLs = false;
- var cloudClientConnection = CloudSolrClient.CloudSolrClientConnection.parse(connectionString);
- if (cloudClientConnection.isZk()) {
- String chroot = cloudClientConnection.zkChroot();
- String zkHostNoChroot =
- chroot != null && connectionString.endsWith(chroot)
- ? connectionString.substring(0, connectionString.length() - chroot.length())
- : connectionString;
+ if (solrConnection.isZookeeper()) {
+ String zkHostNoChroot = String.join(",", solrConnection.quorumItems());
canUseACLs =
Optional.ofNullable(defaultZkHost.get()).map(zkHostNoChroot::equals).orElse(false);
}
-
- final var client = newCloudSolrClient(connectionString, httpSolrClient, canUseACLs);
- solrClients.put(connectionString, client);
- return client;
+ return canUseACLs;
}
protected CloudSolrClient newCloudSolrClient(
- String connectionString, HttpSolrClient httpSolrClient, boolean canUseACLs) {
- var builder = new CloudSolrClient.Builder(connectionString);
+ CloudSolrClient.CloudSolrClientConnection cloudClientConnection,
+ HttpSolrClient httpSolrClient,
+ boolean canUseACLs) {
+ var builder = new CloudSolrClient.Builder(cloudClientConnection);
builder.canUseZkACLs(canUseACLs);
// using internal builder to ensure the internal client gets closed
builder = builder.withHttpClientBuilder(newHttpSolrClientBuilder(null, httpSolrClient));
@@ -128,12 +135,8 @@ public class SolrClientCache implements Closeable {
public synchronized SolrClient getHttpSolrClient(String baseUrl) {
ensureOpen();
Objects.requireNonNull(baseUrl, "Url cannot be null!");
- if (solrClients.containsKey(baseUrl)) {
- return solrClients.get(baseUrl);
- }
- final var client = newHttpSolrClientBuilder(baseUrl, httpSolrClient).build();
- solrClients.put(baseUrl, client);
- return client;
+ return httpSolrClients.computeIfAbsent(
+ baseUrl, url -> newHttpSolrClientBuilder(url, httpSolrClient).build());
}
@SuppressWarnings({"unchecked", "rawtypes"})
@@ -162,10 +165,14 @@ public class SolrClientCache implements Closeable {
@Override
public synchronized void close() {
if (isClosed.compareAndSet(false, true)) {
- for (Map.Entry<String, SolrClient> entry : solrClients.entrySet()) {
- IOUtils.closeQuietly(entry.getValue());
+ for (SolrClient solrClient : httpSolrClients.values()) {
+ IOUtils.closeQuietly(solrClient);
+ }
+ httpSolrClients.clear();
+ for (CloudSolrClient solrClient : cloudSolClients.values()) {
+ IOUtils.closeQuietly(solrClient);
}
- solrClients.clear();
+ cloudSolClients.clear();
}
}
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/graph/GatherNodesStream.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/graph/GatherNodesStream.java
index a6cde6685ab..8c00cae342d 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/graph/GatherNodesStream.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/graph/GatherNodesStream.java
@@ -28,6 +28,7 @@ import java.time.Instant;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
@@ -40,6 +41,7 @@ import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.comp.StreamComparator;
import org.apache.solr.client.solrj.io.eq.FieldEqualitor;
@@ -58,6 +60,7 @@ import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionValue;
import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
import org.apache.solr.client.solrj.io.stream.metrics.Metric;
import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.ExecutorUtil;
import org.apache.solr.common.util.SolrNamedThreadFactory;
import org.slf4j.Logger;
@@ -68,10 +71,10 @@ import org.slf4j.LoggerFactory;
*/
public class GatherNodesStream extends TupleStream implements Expressible {
- private String zkHost;
+ private CloudSolrClient.CloudSolrClientConnection solrConnection;
private String collection;
private StreamContext streamContext;
- private Map<String, String> queryParams;
+ private SolrParams queryParams;
private String traverseFrom;
private String traverseTo;
private String gather;
@@ -97,20 +100,20 @@ public class GatherNodesStream extends TupleStream implements Expressible {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
public GatherNodesStream(
- String zkHost,
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
String collection,
TupleStream tupleStream,
String traverseFrom,
String traverseTo,
String gather,
- Map<String, String> queryParams,
+ SolrParams queryParams,
List<Metric> metrics,
boolean trackTraversal,
Set<Traversal.Scatter> scatter,
int maxDocFreq) {
init(
- zkHost,
+ solrConnection,
collection,
tupleStream,
traverseFrom,
@@ -130,7 +133,6 @@ public class GatherNodesStream extends TupleStream implements Expressible {
String collectionName = factory.getValueOperand(expression, 0);
List<StreamExpressionNamedParameter> namedParams = factory.getNamedOperands(expression);
- StreamExpressionNamedParameter zkHostExpression = factory.getNamedOperand(expression, "zkHost");
List<StreamExpression> streamExpressions =
factory.getExpressionOperandsRepresentingTypes(
@@ -273,43 +275,24 @@ public class GatherNodesStream extends TupleStream implements Expressible {
Integer.parseInt(((StreamExpressionValue) docFreqExpression.getParameter()).getValue());
}
- Map<String, String> params = new HashMap<String, String>();
- for (StreamExpressionNamedParameter namedParam : namedParams) {
- if (!namedParam.getName().equals("zkHost")
- && !namedParam.getName().equals("gather")
- && !namedParam.getName().equals("walk")
- && !namedParam.getName().equals("scatter")
- && !namedParam.getName().equals("maxDocFreq")
- && !namedParam.getName().equals("trackTraversal")
- && !namedParam.getName().equals("window")
- && !namedParam.getName().equals("lag")) {
- params.put(namedParam.getName(), namedParam.getParameter().toString().trim());
- }
- }
+ SolrParams params =
+ buildSolrParamsExcept(
+ namedParams,
+ Set.of(
+ "zkHost",
+ "solrConnection",
+ "gather",
+ "walk",
+ "scatter",
+ "maxDocFreq",
+ "trackTraversal",
+ "window",
+ "lag"));
- // zkHost, optional - if not provided then will look into factory list to get
- String zkHost = null;
- if (null == zkHostExpression) {
- zkHost = factory.getCollectionZkHost(collectionName);
- if (zkHost == null) {
- zkHost = factory.getDefaultZkHost();
- }
- } else if (zkHostExpression.getParameter() instanceof StreamExpressionValue) {
- zkHost = ((StreamExpressionValue) zkHostExpression.getParameter()).getValue();
- }
+ var solrConnection = factory.buildSolrConnection(expression, collectionName);
- if (null == zkHost) {
- throw new IOException(
- String.format(
- Locale.ROOT,
- "invalid expression %s - zkHost not found for collection '%s'",
- expression,
- collectionName));
- }
-
- // We've got all the required items
init(
- zkHost,
+ solrConnection,
collectionName,
stream,
traverseFrom,
@@ -326,13 +309,13 @@ public class GatherNodesStream extends TupleStream implements Expressible {
}
private void init(
- String zkHost,
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
String collection,
TupleStream tupleStream,
String traverseFrom,
String traverseTo,
String gather,
- Map<String, String> queryParams,
+ SolrParams queryParams,
List<Metric> metrics,
boolean trackTraversal,
Set<Traversal.Scatter> scatter,
@@ -340,7 +323,7 @@ public class GatherNodesStream extends TupleStream implements Expressible {
int window,
int lag,
int interval) {
- this.zkHost = zkHost;
+ this.solrConnection = solrConnection;
this.collection = collection;
this.tupleStream = tupleStream;
this.traverseFrom = traverseFrom;
@@ -385,18 +368,15 @@ public class GatherNodesStream extends TupleStream implements Expressible {
expression.addParameter("<stream>");
}
- Set<Map.Entry<String, String>> entries = queryParams.entrySet();
- // parameters
- for (Map.Entry<String, String> param : entries) {
+ for (Map.Entry<String, String[]> param : queryParams) {
assert param.getKey() != null && param.getValue() != null : "Bad types passed";
- String value = param.getValue().toString();
-
- // SOLR-8409: This is a special case where the params contain a " character
- // Do note that in any other BASE streams with parameters where a " might come into play
- // that this same replacement needs to take place.
- value = value.replace("\"", "\\\"");
-
- expression.addParameter(new StreamExpressionNamedParameter(param.getKey().toString(), value));
+ for (String paramValue : param.getValue()) {
+ // SOLR-8409: This is a special case where the params contain a " character
+ // Do note that in any other BASE streams with parameters where a " might come into play
+ // that this same replacement needs to take place.
+ paramValue = paramValue.replace("\"", "\\\"");
+ expression.addParameter(new StreamExpressionNamedParameter(param.getKey(), paramValue));
+ }
}
if (metrics != null) {
@@ -405,8 +385,9 @@ public class GatherNodesStream extends TupleStream implements Expressible {
}
}
- expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
- expression.addParameter(new StreamExpressionNamedParameter("gather", zkHost));
+ expression.addParameter(
+ new StreamExpressionNamedParameter("solrConnection", solrConnection.toString()));
+ expression.addParameter(new StreamExpressionNamedParameter("gather", gather));
if (maxDocFreq > -1) {
expression.addParameter(
new StreamExpressionNamedParameter("maxDocFreq", Integer.toString(maxDocFreq)));
@@ -454,10 +435,14 @@ public class GatherNodesStream extends TupleStream implements Expressible {
child.setFunctionName("solr (graph)");
child.setImplementingClass("Solr/Lucene");
child.setExpressionType(ExpressionType.DATASTORE);
- child.setExpression(
- queryParams.entrySet().stream()
- .map(e -> String.format(Locale.ROOT, "%s=%s", e.getKey(), e.getValue()))
- .collect(Collectors.joining(",")));
+ String expression =
+ queryParams.stream()
+ .flatMap(
+ e ->
+ Arrays.stream(e.getValue())
+ .map(v -> String.format(Locale.ROOT, "%s=%s", e.getKey(), v)))
+ .collect(Collectors.joining(","));
+ child.setExpression(expression);
explanation.addChild(child);
if (null != metrics) {
@@ -536,7 +521,7 @@ public class GatherNodesStream extends TupleStream implements Expressible {
}
}
- if (queryParams.containsKey("fl")) {
+ if (queryParams.get("fl") != null) {
String flString = queryParams.get("fl");
String[] flArray = flString.split(",");
for (String f : flArray) {
@@ -553,8 +538,7 @@ public class GatherNodesStream extends TupleStream implements Expressible {
}
}
- ModifiableSolrParams joinSParams = new ModifiableSolrParams();
- queryParams.forEach(joinSParams::add);
+ ModifiableSolrParams joinSParams = new ModifiableSolrParams(queryParams);
joinSParams.set("fl", buf.toString());
joinSParams.set("qt", "/export");
joinSParams.set(SORT, gather + " asc," + traverseTo + " asc");
@@ -582,7 +566,7 @@ public class GatherNodesStream extends TupleStream implements Expressible {
try {
stream =
new UniqueStream(
- new CloudSolrStream(zkHost, collection, joinSParams),
+ new CloudSolrStream(solrConnection, collection, joinSParams),
new MultipleFieldEqualitor(
new FieldEqualitor(gather), new FieldEqualitor(traverseTo)));
stream.setStreamContext(streamContext);
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/graph/ShortestPathStream.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/graph/ShortestPathStream.java
index 5d508cd2e4f..58964a9b621 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/graph/ShortestPathStream.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/graph/ShortestPathStream.java
@@ -35,6 +35,7 @@ import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.comp.StreamComparator;
import org.apache.solr.client.solrj.io.eq.FieldEqualitor;
@@ -70,7 +71,7 @@ public class ShortestPathStream extends TupleStream implements Expressible {
private String toField;
private int joinBatchSize;
private int maxDepth;
- private String zkHost;
+ private CloudSolrClient.CloudSolrClientConnection solrConnection;
private String collection;
private final Deque<Tuple> shortestPaths = new ArrayDeque<>();
private boolean found;
@@ -79,7 +80,7 @@ public class ShortestPathStream extends TupleStream implements Expressible {
private SolrParams queryParams;
public ShortestPathStream(
- String zkHost,
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
String collection,
String fromNode,
String toNode,
@@ -91,7 +92,7 @@ public class ShortestPathStream extends TupleStream implements Expressible {
int maxDepth) {
init(
- zkHost,
+ solrConnection,
collection,
fromNode,
toNode,
@@ -107,7 +108,6 @@ public class ShortestPathStream extends TupleStream implements Expressible {
String collectionName = factory.getValueOperand(expression, 0);
List<StreamExpressionNamedParameter> namedParams = factory.getNamedOperands(expression);
- StreamExpressionNamedParameter zkHostExpression = factory.getNamedOperand(expression, "zkHost");
// Collection Name
if (null == collectionName) {
@@ -194,42 +194,23 @@ public class ShortestPathStream extends TupleStream implements Expressible {
Integer.parseInt(((StreamExpressionValue) depthExpression.getParameter()).getValue());
}
- ModifiableSolrParams params = new ModifiableSolrParams();
- for (StreamExpressionNamedParameter namedParam : namedParams) {
- if (!namedParam.getName().equals("zkHost")
- && !namedParam.getName().equals("to")
- && !namedParam.getName().equals("from")
- && !namedParam.getName().equals("edge")
- && !namedParam.getName().equals("maxDepth")
- && !namedParam.getName().equals("threads")
- && !namedParam.getName().equals("partitionSize")) {
- params.set(namedParam.getName(), namedParam.getParameter().toString().trim());
- }
- }
-
- // zkHost, optional - if not provided then will look into factory list to get
- String zkHost = null;
- if (null == zkHostExpression) {
- zkHost = factory.getCollectionZkHost(collectionName);
- if (zkHost == null) {
- zkHost = factory.getDefaultZkHost();
- }
- } else if (zkHostExpression.getParameter() instanceof StreamExpressionValue) {
- zkHost = ((StreamExpressionValue) zkHostExpression.getParameter()).getValue();
- }
+ ModifiableSolrParams params =
+ buildSolrParamsExcept(
+ namedParams,
+ Set.of(
+ "solrConnection",
+ "zkHost",
+ "to",
+ "from",
+ "edge",
+ "maxDepth",
+ "threads",
+ "partitionSize"));
+
+ var solrConnection = factory.buildSolrConnection(expression, collectionName);
- if (null == zkHost) {
- throw new IOException(
- String.format(
- Locale.ROOT,
- "invalid expression %s - zkHost not found for collection '%s'",
- expression,
- collectionName));
- }
-
- // We've got all the required items
init(
- zkHost,
+ solrConnection,
collectionName,
fromNode,
toNode,
@@ -242,7 +223,7 @@ public class ShortestPathStream extends TupleStream implements Expressible {
}
private void init(
- String zkHost,
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
String collection,
String fromNode,
String toNode,
@@ -252,7 +233,7 @@ public class ShortestPathStream extends TupleStream implements Expressible {
int joinBatchSize,
int threads,
int maxDepth) {
- this.zkHost = zkHost;
+ this.solrConnection = solrConnection;
this.collection = collection;
this.fromNode = fromNode;
this.toNode = toNode;
@@ -282,10 +263,11 @@ public class ShortestPathStream extends TupleStream implements Expressible {
// that this same replacement needs to take place.
value = value.replace("\"", "\\\"");
- expression.addParameter(new StreamExpressionNamedParameter(param.getKey().toString(), value));
+ expression.addParameter(new StreamExpressionNamedParameter(param.getKey(), value));
}
- expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
+ expression.addParameter(
+ new StreamExpressionNamedParameter("solrConnection", solrConnection.toString()));
expression.addParameter(
new StreamExpressionNamedParameter("maxDepth", Integer.toString(maxDepth)));
expression.addParameter(
@@ -497,7 +479,7 @@ public class ShortestPathStream extends TupleStream implements Expressible {
try {
stream =
new UniqueStream(
- new CloudSolrStream(zkHost, collection, joinParams),
+ new CloudSolrStream(solrConnection, collection, joinParams),
new MultipleFieldEqualitor(
new FieldEqualitor(toField), new FieldEqualitor(fromField)));
stream.setStreamContext(streamContext);
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/sql/ConnectionImpl.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/sql/ConnectionImpl.java
index ec942a44edb..09ae6a0a186 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/sql/ConnectionImpl.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/sql/ConnectionImpl.java
@@ -56,10 +56,14 @@ class ConnectionImpl implements Connection {
private boolean closed;
private SQLWarning currentWarning;
- ConnectionImpl(String url, String zkHost, String collection, Properties properties)
+ ConnectionImpl(
+ String url,
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
+ String collection,
+ Properties properties)
throws SQLException {
this.url = url;
- this.client = this.solrClientCache.getCloudSolrClient(zkHost);
+ this.client = this.solrClientCache.getCloudSolrClient(solrConnection);
this.collection = collection;
this.properties = properties;
this.connectionStatement = createStatement();
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/sql/DriverImpl.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/sql/DriverImpl.java
index 073a223606c..a6f07878937 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/sql/DriverImpl.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/sql/DriverImpl.java
@@ -25,14 +25,18 @@ import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
+import java.util.Locale;
import java.util.Properties;
import java.util.logging.Logger;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.common.util.SuppressForbidden;
/**
* Get a Connection with an url and properties.
*
* <p>jdbc:solr://zkhost:port?collection=collection&amp;aggregationMode=map_reduce
+ *
+ * <p>jdbc:solr:http://solrHost:port?collection=collection&amp;aggregationMode=map_reduce
*/
public class DriverImpl implements Driver {
@@ -49,27 +53,12 @@ public class DriverImpl implements Driver {
if (!acceptsURL(url)) {
return null;
}
-
- URI uri = processUrl(url);
-
- loadParams(uri, props);
-
- if (!props.containsKey("collection")) {
- throw new SQLException(
- "The connection url has no connection properties. At a minimum the collection must be specified.");
- }
- String collection = (String) props.remove("collection");
-
- if (!props.containsKey("aggregationMode")) {
- props.setProperty("aggregationMode", "facet");
- }
-
- // JDBC requires metadata like field names from the SQLHandler. Force this property to be true.
- props.setProperty("includeMetadata", "true");
-
- String zkHost = uri.getAuthority() + uri.getPath();
-
- return new ConnectionImpl(url, zkHost, collection, props);
+ var jdbcConnMetadata = JdbcConnectionMetadata.parse(url, props);
+ return new ConnectionImpl(
+ jdbcConnMetadata.originalUrl(),
+ jdbcConnMetadata.solrConnection(),
+ jdbcConnMetadata.collection(),
+ jdbcConnMetadata.properties());
}
public Connection connect(String url) throws SQLException {
@@ -107,31 +96,86 @@ public class DriverImpl implements Driver {
return null;
}
- protected URI processUrl(String url) throws SQLException {
- URI uri;
- try {
- uri = new URI(url.replaceFirst("jdbc:", ""));
- } catch (URISyntaxException e) {
- throw new SQLException(e);
+ record JdbcConnectionMetadata(
+ String originalUrl,
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
+ String collection,
+ Properties properties) {
+
+ static JdbcConnectionMetadata parse(String jdbcUrl, Properties properties) throws SQLException {
+ URI uri = toURI(jdbcUrl);
+
+ Properties effectiveProps = new Properties();
+ effectiveProps.putAll(properties);
+ loadParams(uri, effectiveProps);
+
+ String collection = effectiveProps.getProperty("collection");
+ if (collection == null) {
+ throw new SQLException("Missing required property 'collection' in JDBC URL or properties.");
+ }
+ effectiveProps.remove("collection");
+ effectiveProps.putIfAbsent("aggregationMode", "facet");
+ effectiveProps.setProperty("includeMetadata", "true");
+
+ String connectionString =
+ isHttpScheme(uri.getScheme())
+ ? uri.getScheme() + "://" + uri.getAuthority() + uri.getPath()
+ : uri.getAuthority() + uri.getPath();
+
+ var solrConnection = CloudSolrClient.CloudSolrClientConnection.parse(connectionString);
+
+ return new JdbcConnectionMetadata(jdbcUrl, solrConnection, collection, effectiveProps);
}
- if (uri.getAuthority() == null) {
- throw new SQLException("The zkHost must not be null");
+ private static URI toURI(String url) throws SQLException {
+ String uriString = removePrefix(url);
+ URI uri;
+ try {
+ uri = new URI(uriString);
+ } catch (URISyntaxException e) {
+ throw new SQLException(String.format(Locale.ROOT, "Invalid JDBC URL '%s'.", url), e);
+ }
+ if (uri.getAuthority() == null) {
+ throw new SQLException(
+ String.format(Locale.ROOT, "Invalid JDBC URL '%s': missing host.", url));
+ }
+
+ return uri;
}
- return uri;
- }
+ /** Removes the {@code jdbc:solr:} prefix from a Solr JDBC URL */
+ private static String removePrefix(String url) throws SQLException {
+ String uriString;
+ if (url.startsWith("jdbc:solr://")) {
+ uriString = url.substring("jdbc:".length());
+ } else if (url.startsWith("jdbc:solr:http://") || url.startsWith("jdbc:solr:https://")) {
+ uriString = url.substring("jdbc:solr:".length());
+ } else {
+ throw new SQLException(
+ String.format(
+ Locale.ROOT,
+ "Invalid JDBC URL '%s'. Expected prefixes: "
+ + "'jdbc:solr://', 'jdbc:solr:http://', or 'jdbc:solr:https://'.",
+ url));
+ }
+ return uriString;
+ }
- /** Decode the uri query parameters and put them onto {@code props}. */
- private void loadParams(URI uri, Properties props) {
- String query = uri.getRawQuery();
- if (query != null) {
- for (String param : query.split("&")) {
- String[] pair = param.split("=", 2);
- String key = URLDecoder.decode(pair[0], StandardCharsets.UTF_8);
- String value = pair.length > 1 ? URLDecoder.decode(pair[1], StandardCharsets.UTF_8) : "";
- props.put(key, value);
+ /** Decode the uri query parameters and put them onto {@code props}. */
+ private static void loadParams(URI uri, Properties props) {
+ String query = uri.getRawQuery();
+ if (query != null) {
+ for (String param : query.split("&")) {
+ String[] pair = param.split("=", 2);
+ String key = URLDecoder.decode(pair[0], StandardCharsets.UTF_8);
+ String value = pair.length > 1 ? URLDecoder.decode(pair[1], StandardCharsets.UTF_8) : "";
+ props.put(key, value);
+ }
}
}
+
+ private static boolean isHttpScheme(String scheme) {
+ return "http".equals(scheme) || "https".equals(scheme);
+ }
}
}
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/CloudSolrStream.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/CloudSolrStream.java
index 9c1277aed33..f61ccba0548 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/CloudSolrStream.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/CloudSolrStream.java
@@ -31,6 +31,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
+import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;
@@ -66,9 +67,9 @@ public class CloudSolrStream extends TupleStream implements Expressible {
private static final long serialVersionUID = 1;
- protected String zkHost;
+ protected CloudSolrClient.CloudSolrClientConnection solrConnection;
protected String collection;
- protected ModifiableSolrParams params;
+ protected SolrParams params;
protected Map<String, String> fieldMappings;
protected StreamComparator comp;
private boolean trace;
@@ -81,14 +82,17 @@ public class CloudSolrStream extends TupleStream implements Expressible {
protected CloudSolrStream() {}
/**
- * @param zkHost Zookeeper ensemble connection string
+ * @param solrConnection Zookeeper or HTTPS(s) ensemble connection string
* @param collectionName Name of the collection to operate on
* @param params Map&lt;String, String[]&gt; of parameter/value pairs
* @throws IOException Something went wrong
*/
- public CloudSolrStream(String zkHost, String collectionName, SolrParams params)
+ public CloudSolrStream(
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
+ String collectionName,
+ SolrParams params)
throws IOException {
- init(collectionName, zkHost, params);
+ init(solrConnection, collectionName, params);
}
public CloudSolrStream(StreamExpression expression, StreamFactory factory) throws IOException {
@@ -96,7 +100,6 @@ public class CloudSolrStream extends TupleStream implements Expressible {
String collectionName = factory.getValueOperand(expression, 0);
List<StreamExpressionNamedParameter> namedParams = factory.getNamedOperands(expression);
StreamExpressionNamedParameter aliasExpression = factory.getNamedOperand(expression, "aliases");
- StreamExpressionNamedParameter zkHostExpression = factory.getNamedOperand(expression, "zkHost");
// Collection Name
if (null == collectionName) {
@@ -107,8 +110,8 @@ public class CloudSolrStream extends TupleStream implements Expressible {
expression));
}
- // Validate there are no unknown parameters - zkHost and alias are namedParameter, so we don't
- // need to count it twice
+ // Validate there are no unknown parameters - solrConnection/zkHost and alias are
+ // namedParameter, so we don't need to count it twice
if (expression.getParameters().size() != 1 + namedParams.size()) {
throw new IOException(
String.format(Locale.ROOT, "invalid expression %s - unknown operands found", expression));
@@ -123,12 +126,8 @@ public class CloudSolrStream extends TupleStream implements Expressible {
expression));
}
- ModifiableSolrParams mParams = new ModifiableSolrParams();
- for (StreamExpressionNamedParameter namedParam : namedParams) {
- if (!namedParam.getName().equals("zkHost") && !namedParam.getName().equals("aliases")) {
- mParams.add(namedParam.getName(), namedParam.getParameter().toString().trim());
- }
- }
+ ModifiableSolrParams mParams =
+ buildSolrParamsExcept(namedParams, Set.of("solrConnection", "zkHost", "aliases"));
// Aliases, optional, if provided then need to split
if (null != aliasExpression
@@ -149,19 +148,9 @@ public class CloudSolrStream extends TupleStream implements Expressible {
}
}
- // zkHost, optional - if not provided then will look into factory list to get
- String zkHost = null;
- if (null == zkHostExpression) {
- zkHost = factory.getCollectionZkHost(collectionName);
- if (zkHost == null) {
- zkHost = factory.getDefaultZkHost();
- }
- } else if (zkHostExpression.getParameter() instanceof StreamExpressionValue) {
- zkHost = ((StreamExpressionValue) zkHostExpression.getParameter()).getValue();
- }
+ var solrConnection = factory.buildSolrConnection(expression, collectionName);
- // We've got all the required items
- init(collectionName, zkHost, mParams);
+ init(solrConnection, collectionName, mParams);
}
@Override
@@ -179,7 +168,7 @@ public class CloudSolrStream extends TupleStream implements Expressible {
expression.addParameter(collection);
}
- for (Entry<String, String[]> param : params.getMap().entrySet()) {
+ for (Entry<String, String[]> param : params) {
for (String val : param.getValue()) {
// SOLR-8409: Escaping the " is a special case.
// Do note that in any other BASE streams with parameters where a " might come into play
@@ -189,8 +178,8 @@ public class CloudSolrStream extends TupleStream implements Expressible {
}
}
- // zkHost
- expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
+ expression.addParameter(
+ new StreamExpressionNamedParameter("solrConnection", solrConnection.toString()));
// aliases
if (null != fieldMappings && 0 != fieldMappings.size()) {
@@ -241,16 +230,20 @@ public class CloudSolrStream extends TupleStream implements Expressible {
return explanation;
}
- void init(String collectionName, String zkHost, SolrParams params) throws IOException {
- this.zkHost = zkHost;
+ void init(
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
+ String collectionName,
+ SolrParams params)
+ throws IOException {
+ this.solrConnection = solrConnection;
this.collection = collectionName;
this.params = new ModifiableSolrParams(params);
// If the comparator is null then it was not explicitly set, so we will create one using the
- // sort
- // parameter of the query. While doing this we will also take into account any aliases such that
- // if we are sorting on fieldA but fieldA is aliased to alias.fieldA then the comparator will be
- // against alias.fieldA.
+ // sort parameter of the query.
+ // While doing this we will also take into account any aliases such that if we are sorting on
+ // fieldA but fieldA is aliased to alias.fieldA then the comparator will be against
+ // alias.fieldA.
if (params.get("q") == null) {
throw new IOException("q param expected for search function");
@@ -384,17 +377,17 @@ public class CloudSolrStream extends TupleStream implements Expressible {
if (streamContext != null && streamContext.get("shards") != null) {
// stream of shard url with core
final List<String> shards =
- getShards(this.zkHost, this.collection, this.streamContext, mParams);
+ getShards(this.solrConnection, this.collection, this.streamContext, mParams);
if (shards.isEmpty())
- throw new IOException("No shards available from ZooKeeper: " + this.zkHost);
+ throw new IOException("No shards available from ZooKeeper: " + this.solrConnection);
streamOfSolrStream = shards.stream().map(s -> new SolrStream(s, mParams));
} else {
// stream of replicas to reuse the same SolrHttpClient per baseUrl
// avoids re-parsing data we already have in the replicas
final List<Replica> replicas =
- getReplicas(this.zkHost, this.collection, this.streamContext, mParams);
+ getReplicas(this.solrConnection, this.collection, this.streamContext, mParams);
if (replicas.isEmpty())
- throw new IOException("No replicas available from ZooKeeper: " + this.zkHost);
+ throw new IOException("No replicas available from ZooKeeper: " + this.solrConnection);
streamOfSolrStream =
replicas.stream().map(r -> new SolrStream(r.getBaseUrl(), mParams, r.getCoreName()));
}
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/CommitStream.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/CommitStream.java
index 6ed5d3a06c7..8312390f0b1 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/CommitStream.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/CommitStream.java
@@ -22,6 +22,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.SolrClientCache;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.comp.StreamComparator;
@@ -31,7 +32,6 @@ import org.apache.solr.client.solrj.io.stream.expr.Expressible;
import org.apache.solr.client.solrj.io.stream.expr.StreamExplanation;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter;
-import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionValue;
import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -47,7 +47,7 @@ public class CommitStream extends TupleStream implements Expressible {
// Part of expression / passed in
private String collection;
- private String zkHost;
+ private CloudSolrClient.CloudSolrClientConnection solrConnection;
private boolean waitFlush;
private boolean waitSearcher;
private boolean softCommit;
@@ -61,12 +61,6 @@ public class CommitStream extends TupleStream implements Expressible {
public CommitStream(StreamExpression expression, StreamFactory factory) throws IOException {
String collectionName = factory.getValueOperand(expression, 0);
- String zkHost = findZkHost(factory, collectionName, expression);
- int batchSize = factory.getIntOperand(expression, "batchSize", 0);
- boolean waitFlush = factory.getBooleanOperand(expression, "waitFlush", false);
- boolean waitSearcher = factory.getBooleanOperand(expression, "waitSearcher", false);
- boolean softCommit = factory.getBooleanOperand(expression, "softCommit", false);
-
if (null == collectionName) {
throw new IOException(
String.format(
@@ -74,14 +68,12 @@ public class CommitStream extends TupleStream implements Expressible {
"invalid expression %s - collectionName expected as first operand",
expression));
}
- if (null == zkHost) {
- throw new IOException(
- String.format(
- Locale.ROOT,
- "invalid expression %s - zkHost not found for collection '%s'",
- expression,
- collectionName));
- }
+ var solrConnection = factory.buildSolrConnection(expression, collectionName);
+ int batchSize = factory.getIntOperand(expression, "batchSize", 0);
+ boolean waitFlush = factory.getBooleanOperand(expression, "waitFlush", false);
+ boolean waitSearcher = factory.getBooleanOperand(expression, "waitSearcher", false);
+ boolean softCommit = factory.getBooleanOperand(expression, "softCommit", false);
+
if (batchSize < 0) {
throw new IOException(
String.format(
@@ -106,9 +98,9 @@ public class CommitStream extends TupleStream implements Expressible {
StreamExpression sourceStreamExpression = streamExpressions.get(0);
init(
+ solrConnection,
collectionName,
factory.constructStream(sourceStreamExpression),
- zkHost,
batchSize,
waitFlush,
waitSearcher,
@@ -118,7 +110,7 @@ public class CommitStream extends TupleStream implements Expressible {
public CommitStream(
String collectionName,
TupleStream tupleSource,
- String zkHost,
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
int batchSize,
boolean waitFlush,
boolean waitSearcher,
@@ -128,19 +120,26 @@ public class CommitStream extends TupleStream implements Expressible {
throw new IOException(
String.format(Locale.ROOT, "batchSize '%d' cannot be less than 0.", batchSize));
}
- init(collectionName, tupleSource, zkHost, batchSize, waitFlush, waitSearcher, softCommit);
+ init(
+ solrConnection,
+ collectionName,
+ tupleSource,
+ batchSize,
+ waitFlush,
+ waitSearcher,
+ softCommit);
}
private void init(
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
String collectionName,
TupleStream tupleSource,
- String zkHost,
int batchSize,
boolean waitFlush,
boolean waitSearcher,
boolean softCommit) {
this.collection = collectionName;
- this.zkHost = zkHost;
+ this.solrConnection = solrConnection;
this.commitBatchSize = batchSize;
this.waitFlush = waitFlush;
this.waitSearcher = waitSearcher;
@@ -226,7 +225,8 @@ public class CommitStream extends TupleStream implements Expressible {
throws IOException {
StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
expression.addParameter(collection);
- expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
+ expression.addParameter(
+ new StreamExpressionNamedParameter("solrConnection", solrConnection.toString()));
expression.addParameter(
new StreamExpressionNamedParameter("batchSize", Integer.toString(commitBatchSize)));
expression.addParameter(
@@ -286,28 +286,11 @@ public class CommitStream extends TupleStream implements Expressible {
this.tupleSource.setStreamContext(context);
}
- private String findZkHost(
- StreamFactory factory, String collectionName, StreamExpression expression) {
- StreamExpressionNamedParameter zkHostExpression = factory.getNamedOperand(expression, "zkHost");
- if (null == zkHostExpression) {
- String zkHost = factory.getCollectionZkHost(collectionName);
- if (zkHost == null) {
- return factory.getDefaultZkHost();
- } else {
- return zkHost;
- }
- } else if (zkHostExpression.getParameter() instanceof StreamExpressionValue) {
- return ((StreamExpressionValue) zkHostExpression.getParameter()).getValue();
- }
-
- return null;
- }
-
private void sendCommit() throws IOException {
try {
clientCache
- .getCloudSolrClient(zkHost)
+ .getCloudSolrClient(solrConnection)
.commit(collection, waitFlush, waitSearcher, softCommit);
} catch (SolrServerException | IOException e) {
log.warn(
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/DeepRandomStream.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/DeepRandomStream.java
index 0be344a0921..ffd4edbe70a 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/DeepRandomStream.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/DeepRandomStream.java
@@ -34,8 +34,10 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Random;
+import java.util.Set;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.comp.StreamComparator;
import org.apache.solr.client.solrj.io.stream.expr.Explanation;
@@ -60,7 +62,7 @@ public class DeepRandomStream extends TupleStream implements Expressible {
private static final long serialVersionUID = 1;
- protected String zkHost;
+ protected CloudSolrClient.CloudSolrClientConnection solrConnection;
protected String collection;
protected ModifiableSolrParams params;
protected Map<String, String> fieldMappings;
@@ -76,14 +78,17 @@ public class DeepRandomStream extends TupleStream implements Expressible {
}
/**
- * @param zkHost Zookeeper ensemble connection string
+ * @param solrConnection Zookeeper or HTTPS(s) ensemble connection string
* @param collectionName Name of the collection to operate on
* @param params Map&lt;String, String[]&gt; of parameter/value pairs
* @throws IOException Something went wrong
*/
- public DeepRandomStream(String zkHost, String collectionName, SolrParams params)
+ public DeepRandomStream(
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
+ String collectionName,
+ SolrParams params)
throws IOException {
- init(collectionName, zkHost, params);
+ init(solrConnection, collectionName, params);
}
public DeepRandomStream(StreamExpression expression, StreamFactory factory) throws IOException {
@@ -91,7 +96,6 @@ public class DeepRandomStream extends TupleStream implements Expressible {
String collectionName = factory.getValueOperand(expression, 0);
List<StreamExpressionNamedParameter> namedParams = factory.getNamedOperands(expression);
StreamExpressionNamedParameter aliasExpression = factory.getNamedOperand(expression, "aliases");
- StreamExpressionNamedParameter zkHostExpression = factory.getNamedOperand(expression, "zkHost");
// Collection Name
if (null == collectionName) {
@@ -102,8 +106,8 @@ public class DeepRandomStream extends TupleStream implements Expressible {
expression));
}
- // Validate there are no unknown parameters - zkHost and alias are namedParameter, so we don't
- // need to count it twice
+ // Validate there are no unknown parameters - solrConnection and alias are namedParameter,
+ // so we don't need to count it twice
if (expression.getParameters().size() != 1 + namedParams.size()) {
throw new IOException(
String.format(Locale.ROOT, "invalid expression %s - unknown operands found", expression));
@@ -118,12 +122,8 @@ public class DeepRandomStream extends TupleStream implements Expressible {
expression));
}
- ModifiableSolrParams mParams = new ModifiableSolrParams();
- for (StreamExpressionNamedParameter namedParam : namedParams) {
- if (!namedParam.getName().equals("zkHost") && !namedParam.getName().equals("aliases")) {
- mParams.add(namedParam.getName(), namedParam.getParameter().toString().trim());
- }
- }
+ ModifiableSolrParams mParams =
+ buildSolrParamsExcept(namedParams, Set.of("zkHost", "solrConnection", "aliases"));
// Aliases, optional, if provided then need to split
if (null != aliasExpression
@@ -144,24 +144,9 @@ public class DeepRandomStream extends TupleStream implements Expressible {
}
}
- // zkHost, optional - if not provided then will look into factory list to get
- String zkHost = null;
- if (null == zkHostExpression) {
- zkHost = factory.getCollectionZkHost(collectionName);
- if (zkHost == null) {
- zkHost = factory.getDefaultZkHost();
- }
- } else if (zkHostExpression.getParameter() instanceof StreamExpressionValue) {
- zkHost = ((StreamExpressionValue) zkHostExpression.getParameter()).getValue();
- }
- /*
- if(null == zkHost){
- throw new IOException(String.format(Locale.ROOT,"invalid expression %s - zkHost not found for collection '%s'",expression,collectionName));
- }
- */
+ var solrConnection = factory.buildSolrConnection(expression, collectionName);
- // We've got all the required items
- init(collectionName, zkHost, mParams);
+ init(solrConnection, collectionName, mParams);
}
@Override
@@ -187,8 +172,8 @@ public class DeepRandomStream extends TupleStream implements Expressible {
}
}
- // zkHost
- expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
+ expression.addParameter(
+ new StreamExpressionNamedParameter("solrConnection", solrConnection.toString()));
// aliases
if (null != fieldMappings && 0 != fieldMappings.size()) {
@@ -239,8 +224,12 @@ public class DeepRandomStream extends TupleStream implements Expressible {
return explanation;
}
- void init(String collectionName, String zkHost, SolrParams params) throws IOException {
- this.zkHost = zkHost;
+ void init(
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
+ String collectionName,
+ SolrParams params)
+ throws IOException {
+ this.solrConnection = solrConnection;
this.collection = collectionName;
this.params = new ModifiableSolrParams(params);
@@ -286,7 +275,8 @@ public class DeepRandomStream extends TupleStream implements Expressible {
mParams = adjustParams(mParams);
mParams.set(DISTRIB, "false"); // We are the aggregator.
- List<String> shardUrls = getShards(this.zkHost, this.collection, this.streamContext, mParams);
+ List<String> shardUrls =
+ getShards(this.solrConnection, this.collection, this.streamContext, mParams);
String rows = mParams.get(ROWS);
int r = Integer.parseInt(rows);
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/DeleteStream.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/DeleteStream.java
index d00908792ed..3ff44ef5e25 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/DeleteStream.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/DeleteStream.java
@@ -79,7 +79,7 @@ public final class DeleteStream extends UpdateStream implements Expressible {
final Long version = getVersion(doc);
req.deleteById(id, version);
}
- var cloudSolrClient = clientCache.getCloudSolrClient(zkHost);
+ var cloudSolrClient = clientCache.getCloudSolrClient(solrConnection);
req.process(cloudSolrClient, getCollectionName());
} catch (SolrServerException | NumberFormatException | IOException e) {
log.warn("Unable to delete documents from collection due to unexpected error.", e);
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/DrillStream.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/DrillStream.java
index 355fb09c952..2312aa52c44 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/DrillStream.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/DrillStream.java
@@ -25,6 +25,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.comp.FieldComparator;
import org.apache.solr.client.solrj.io.comp.StreamComparator;
@@ -48,7 +49,7 @@ public class DrillStream extends CloudSolrStream implements Expressible {
private String q;
public DrillStream(
- String zkHost,
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
String collection,
TupleStream tupleStream,
StreamComparator comp,
@@ -56,11 +57,11 @@ public class DrillStream extends CloudSolrStream implements Expressible {
String flParam,
String qParam)
throws IOException {
- init(zkHost, collection, tupleStream, comp, sortParam, flParam, qParam);
+ init(solrConnection, collection, tupleStream, comp, sortParam, flParam, qParam);
}
public DrillStream(
- String zkHost,
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
String collection,
String expressionString,
StreamComparator comp,
@@ -69,7 +70,7 @@ public class DrillStream extends CloudSolrStream implements Expressible {
String qParam)
throws IOException {
TupleStream tStream = this.streamFactory.constructStream(expressionString);
- init(zkHost, collection, tStream, comp, sortParam, flParam, qParam);
+ init(solrConnection, collection, tStream, comp, sortParam, flParam, qParam);
}
public void setStreamFactory(StreamFactory streamFactory) {
@@ -86,8 +87,6 @@ public class DrillStream extends CloudSolrStream implements Expressible {
StreamExpressionNamedParameter qExpression = factory.getNamedOperand(expression, Q);
StreamExpressionNamedParameter flExpression = factory.getNamedOperand(expression, FL);
- StreamExpressionNamedParameter zkHostExpression = factory.getNamedOperand(expression, "zkHost");
-
// Collection Name
if (null == collectionName) {
throw new IOException(
@@ -147,26 +146,8 @@ public class DrillStream extends CloudSolrStream implements Expressible {
qParam = ((StreamExpressionValue) qExpression.getParameter()).getValue();
}
- // zkHost, optional - if not provided then will look into factory list to get
- String zkHost = null;
- if (null == zkHostExpression) {
- zkHost = factory.getCollectionZkHost(collectionName);
- if (zkHost == null) {
- zkHost = factory.getDefaultZkHost();
- }
- } else if (zkHostExpression.getParameter() instanceof StreamExpressionValue) {
- zkHost = ((StreamExpressionValue) zkHostExpression.getParameter()).getValue();
- }
- if (null == zkHost) {
- throw new IOException(
- String.format(
- Locale.ROOT,
- "invalid expression %s - zkHost not found for collection '%s'",
- expression,
- collectionName));
- }
+ var solrConnection = factory.buildSolrConnection(expression, collectionName);
- // We've got all the required items
StreamFactory localFactory = (StreamFactory) factory.clone();
localFactory.withDefaultSort(sortParam);
TupleStream stream = localFactory.constructStream(streamExpressions.get(0));
@@ -175,11 +156,11 @@ public class DrillStream extends CloudSolrStream implements Expressible {
((StreamExpressionValue) sortExpression.getParameter()).getValue(),
FieldComparator.class);
streamFactory = factory;
- init(zkHost, collectionName, stream, comp, sortParam, flParam, qParam);
+ init(solrConnection, collectionName, stream, comp, sortParam, flParam, qParam);
}
private void init(
- String zkHost,
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
String collection,
TupleStream tupleStream,
StreamComparator comp,
@@ -187,7 +168,7 @@ public class DrillStream extends CloudSolrStream implements Expressible {
String flParam,
String qParam)
throws IOException {
- this.zkHost = zkHost;
+ this.solrConnection = solrConnection;
this.collection = collection;
this.comp = comp;
this.tupleStream = tupleStream;
@@ -228,8 +209,8 @@ public class DrillStream extends CloudSolrStream implements Expressible {
// sort
expression.addParameter(new StreamExpressionNamedParameter(SORT, comp.toExpression(factory)));
- // zkHost
- expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
+ expression.addParameter(
+ new StreamExpressionNamedParameter("solrConnection", solrConnection.toString()));
return expression;
}
@@ -285,7 +266,7 @@ public class DrillStream extends CloudSolrStream implements Expressible {
paramsLoc.set("fl", fl);
paramsLoc.set("sort", sort);
paramsLoc.set("q", q);
- getReplicas(this.zkHost, this.collection, this.streamContext, paramsLoc)
+ getReplicas(this.solrConnection, this.collection, this.streamContext, paramsLoc)
.forEach(
r -> {
SolrStream solrStream = new SolrStream(r.getBaseUrl(), paramsLoc, r.getCoreName());
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/Facet2DStream.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/Facet2DStream.java
index 878dee75af4..bfbdb51f994 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/Facet2DStream.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/Facet2DStream.java
@@ -23,9 +23,10 @@ import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
-import java.util.Map.Entry;
+import java.util.Set;
import java.util.stream.Collectors;
import org.apache.solr.client.solrj.SolrRequest;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.SolrClientCache;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.comp.ComparatorOrder;
@@ -53,11 +54,11 @@ public class Facet2DStream extends TupleStream implements Expressible {
private static final long serialVersionUID = 1;
private String collection;
- private ModifiableSolrParams params;
+ private SolrParams params;
private Bucket x;
private Bucket y;
private Metric metric;
- private String zkHost;
+ private CloudSolrClient.CloudSolrClientConnection solrConnection;
private Iterator<Tuple> out;
private List<Tuple> tuples = new ArrayList<Tuple>();
private int dimensionX;
@@ -68,7 +69,7 @@ public class Facet2DStream extends TupleStream implements Expressible {
private transient boolean doCloseCache;
public Facet2DStream(
- String zkHost,
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
String collection,
ModifiableSolrParams params,
Bucket x,
@@ -89,7 +90,7 @@ public class Facet2DStream extends TupleStream implements Expressible {
String bucketSortString = metric.getIdentifier() + " desc";
this.bucketSort = parseBucketSort(bucketSortString, x, y);
- init(collection, params, x, y, bucketSort, dimensionX, dimensionY, metric, zkHost);
+ init(solrConnection, collection, params, x, y, bucketSort, dimensionX, dimensionY, metric);
}
public Facet2DStream(StreamExpression expression, StreamFactory factory) throws IOException {
@@ -107,7 +108,6 @@ public class Facet2DStream extends TupleStream implements Expressible {
factory.getNamedOperand(expression, "dimensions");
List<StreamExpression> metricExpression =
factory.getExpressionOperandsRepresentingTypes(expression, Expressible.class, Metric.class);
- StreamExpressionNamedParameter zkHostExpression = factory.getNamedOperand(expression, "zkHost");
if (collectionName == null) {
throw new IOException(
@@ -117,15 +117,9 @@ public class Facet2DStream extends TupleStream implements Expressible {
expression));
}
- ModifiableSolrParams params = new ModifiableSolrParams();
- for (StreamExpressionNamedParameter namedParam : namedParams) {
- if (!namedParam.getName().equals("x")
- && !namedParam.getName().equals("y")
- && !namedParam.getName().equals("dimensions")
- && !namedParam.getName().equals("zkHost")) {
- params.add(namedParam.getName(), namedParam.getParameter().toString().trim());
- }
- }
+ ModifiableSolrParams params =
+ buildSolrParamsExcept(
+ namedParams, Set.of("x", "y", "dimensions", "zkHost", "solrConnection"));
if (params.get("q") == null) {
params.set("q", "*:*");
@@ -184,26 +178,9 @@ public class Facet2DStream extends TupleStream implements Expressible {
}
}
- String zkHost = null;
- if (zkHostExpression == null) {
- zkHost = factory.getCollectionZkHost(collectionName);
- if (zkHost == null) {
- zkHost = factory.getDefaultZkHost();
- }
- } else if (zkHostExpression.getParameter() instanceof StreamExpressionValue) {
- zkHost = ((StreamExpressionValue) zkHostExpression.getParameter()).getValue();
- }
-
- if (zkHost == null) {
- throw new IOException(
- String.format(
- Locale.ROOT,
- "invalid expression %s - zkHost not found for collection '%s'",
- expression,
- collectionName));
- }
+ var solrConnection = factory.buildSolrConnection(expression, collectionName);
- init(collectionName, params, x, y, bucketSort, dimensionX, dimensionY, metric, zkHost);
+ init(solrConnection, collectionName, params, x, y, bucketSort, dimensionX, dimensionY, metric);
}
private FieldComparator parseBucketSort(String bucketSortString, Bucket x, Bucket y)
@@ -215,6 +192,7 @@ public class Facet2DStream extends TupleStream implements Expressible {
}
private void init(
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
String collection,
SolrParams params,
Bucket x,
@@ -222,8 +200,8 @@ public class Facet2DStream extends TupleStream implements Expressible {
FieldComparator bucketSort,
int dimensionX,
int dimensionY,
- Metric metric,
- String zkHost) {
+ Metric metric) {
+ this.solrConnection = solrConnection;
this.collection = collection;
this.params = new ModifiableSolrParams(params);
this.x = x;
@@ -232,7 +210,6 @@ public class Facet2DStream extends TupleStream implements Expressible {
this.dimensionY = dimensionY;
this.metric = metric;
this.bucketSort = bucketSort;
- this.zkHost = zkHost;
}
@Override
@@ -260,50 +237,16 @@ public class Facet2DStream extends TupleStream implements Expressible {
@Override
public StreamExpressionParameter toExpression(StreamFactory factory) throws IOException {
- StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
-
- // collection
- if (collection.indexOf(',') > -1) {
- expression.addParameter("\"" + collection + "\"");
- } else {
- expression.addParameter(collection);
- }
-
- // parameters for q,fl etc
- for (Entry<String, String[]> param : params.getMap().entrySet()) {
- for (String val : param.getValue()) {
- expression.addParameter(new StreamExpressionNamedParameter(param.getKey(), val));
- }
- }
-
- // bucket x
- {
- StringBuilder builder = new StringBuilder();
-
- builder.append(x.toString());
- expression.addParameter(new StreamExpressionNamedParameter("x", builder.toString()));
- }
-
- // bucket y
- {
- StringBuilder builder = new StringBuilder();
-
- builder.append(y.toString());
- expression.addParameter(new StreamExpressionNamedParameter("y", builder.toString()));
- }
-
- // dimensions
- expression.addParameter(
- new StreamExpressionNamedParameter(
- "dimensions", Integer.toString(dimensionX) + "," + Integer.toString(dimensionY)));
-
- // metric
- expression.addParameter(metric.toExpression(factory));
-
- // zkHost
- expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
-
- return expression;
+ return new StreamExpression(factory.getFunctionName(this.getClass()))
+ .withParameter(collection.indexOf(',') > -1 ? "\"" + collection + "\"" : collection)
+ .withMoreParameters(params)
+ .withParameter(new StreamExpressionNamedParameter("x", x.toString()))
+ .withParameter(new StreamExpressionNamedParameter("y", y.toString()))
+ .withParameter(
+ new StreamExpressionNamedParameter("dimensions", dimensionX + "," + dimensionY))
+ .withParameter(metric.toExpression(factory))
+ .withParameter(
+ new StreamExpressionNamedParameter("solrConnection", solrConnection.toString()));
}
@Override
@@ -335,7 +278,7 @@ public class Facet2DStream extends TupleStream implements Expressible {
QueryRequest request = new QueryRequest(paramsLoc, SolrRequest.METHOD.POST);
try {
- var cloudSolrClient = clientCache.getCloudSolrClient(zkHost);
+ var cloudSolrClient = clientCache.getCloudSolrClient(solrConnection);
NamedList<Object> response = cloudSolrClient.request(request, collection);
getTuples(response, x, y, metric);
this.out = tuples.iterator();
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/FacetStream.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/FacetStream.java
index f1bb705820f..e34647a106b 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/FacetStream.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/FacetStream.java
@@ -24,8 +24,10 @@ import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
+import java.util.Set;
import java.util.stream.Collectors;
import org.apache.solr.client.solrj.SolrRequest;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.ClusterStateProvider;
import org.apache.solr.client.solrj.io.SolrClientCache;
import org.apache.solr.client.solrj.io.Tuple;
@@ -80,7 +82,7 @@ public class FacetStream extends TupleStream implements Expressible, ParallelMet
private FieldComparator[] bucketSorts;
private List<Tuple> tuples = new ArrayList<Tuple>();
private int index;
- private String zkHost;
+ private CloudSolrClient.CloudSolrClientConnection solrConnection;
private ModifiableSolrParams params;
private String collection;
private boolean resortNeeded;
@@ -92,7 +94,7 @@ public class FacetStream extends TupleStream implements Expressible, ParallelMet
protected transient StreamContext context;
public FacetStream(
- String zkHost,
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
String collection,
SolrParams params,
Bucket[] buckets,
@@ -105,6 +107,7 @@ public class FacetStream extends TupleStream implements Expressible, ParallelMet
bucketSizeLimit = Integer.MAX_VALUE;
}
init(
+ solrConnection,
collection,
params,
buckets,
@@ -116,8 +119,7 @@ public class FacetStream extends TupleStream implements Expressible, ParallelMet
false,
null,
true,
- 0,
- zkHost);
+ 0);
}
public FacetStream(StreamExpression expression, StreamFactory factory) throws IOException {
@@ -137,7 +139,6 @@ public class FacetStream extends TupleStream implements Expressible, ParallelMet
factory.getExpressionOperandsRepresentingTypes(expression, Expressible.class, Metric.class);
StreamExpressionNamedParameter bucketLimitExpression =
factory.getNamedOperand(expression, "bucketSizeLimit");
- StreamExpressionNamedParameter zkHostExpression = factory.getNamedOperand(expression, "zkHost");
StreamExpressionNamedParameter rowsExpression = factory.getNamedOperand(expression, "rows");
StreamExpressionNamedParameter offsetExpression = factory.getNamedOperand(expression, "offset");
StreamExpressionNamedParameter overfetchExpression =
@@ -170,20 +171,20 @@ public class FacetStream extends TupleStream implements Expressible, ParallelMet
}
// pull out known named params
- ModifiableSolrParams params = new ModifiableSolrParams();
- for (StreamExpressionNamedParameter namedParam : namedParams) {
- if (!namedParam.getName().equals("zkHost")
- && !namedParam.getName().equals("buckets")
- && !namedParam.getName().equals("bucketSorts")
- && !namedParam.getName().equals("bucketSizeLimit")
- && !namedParam.getName().equals("method")
- && !namedParam.getName().equals("offset")
- && !namedParam.getName().equals("rows")
- && !namedParam.getName().equals("refine")
- && !namedParam.getName().equals("overfetch")) {
- params.add(namedParam.getName(), namedParam.getParameter().toString().trim());
- }
- }
+ ModifiableSolrParams params =
+ buildSolrParamsExcept(
+ namedParams,
+ Set.of(
+ "zkHost",
+ "solrConnection",
+ "buckets",
+ "bucketSorts",
+ "bucketSizeLimit",
+ "method",
+ "offset",
+ "rows",
+ "refine",
+ "overfetch"));
if (params.get("q") == null) {
params.set("q", "*:*");
@@ -358,28 +359,10 @@ public class FacetStream extends TupleStream implements Expressible, ParallelMet
}
}
- // zkHost, optional - if not provided then will look into factory list to get
- String zkHost = null;
- if (null == zkHostExpression) {
- zkHost = factory.getCollectionZkHost(collectionName);
- if (zkHost == null) {
- zkHost = factory.getDefaultZkHost();
- }
- } else if (zkHostExpression.getParameter() instanceof StreamExpressionValue) {
- zkHost = ((StreamExpressionValue) zkHostExpression.getParameter()).getValue();
- }
-
- if (null == zkHost) {
- throw new IOException(
- String.format(
- Locale.ROOT,
- "invalid expression %s - zkHost not found for collection '%s'",
- expression,
- collectionName));
- }
+ var solrConnection = factory.buildSolrConnection(expression, collectionName);
- // We've got all the required items
init(
+ solrConnection,
collectionName,
params,
buckets,
@@ -391,8 +374,7 @@ public class FacetStream extends TupleStream implements Expressible, ParallelMet
refine,
methodStr,
bucketLimitSet,
- overfetchInt,
- zkHost);
+ overfetchInt);
}
// see usage in parallelize method
@@ -485,6 +467,7 @@ public class FacetStream extends TupleStream implements Expressible, ParallelMet
}
private void init(
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
String collection,
SolrParams params,
Bucket[] buckets,
@@ -496,10 +479,9 @@ public class FacetStream extends TupleStream implements Expressible, ParallelMet
boolean refine,
String method,
boolean serializeBucketSizeLimit,
- int overfetch,
- String zkHost)
+ int overfetch)
throws IOException {
- this.zkHost = zkHost;
+ this.solrConnection = solrConnection;
this.params = new ModifiableSolrParams(params);
this.buckets = buckets;
this.metrics = metrics;
@@ -606,8 +588,8 @@ public class FacetStream extends TupleStream implements Expressible, ParallelMet
expression.addParameter(new StreamExpressionNamedParameter("method", this.method));
}
- // zkHost
- expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
+ expression.addParameter(
+ new StreamExpressionNamedParameter("solrConnection", solrConnection.toString()));
return expression;
}
@@ -661,7 +643,7 @@ public class FacetStream extends TupleStream implements Expressible, ParallelMet
} else {
doCloseCache = false;
}
- var cloudSolrClient = clientCache.getCloudSolrClient(zkHost);
+ var cloudSolrClient = clientCache.getCloudSolrClient(solrConnection);
// Parallelize the facet expression across multiple collections for an alias using plist if
// possible
@@ -1018,6 +1000,7 @@ public class FacetStream extends TupleStream implements Expressible, ParallelMet
for (int p = 0; p < streams.length; p++) {
FacetStream cloned = new FacetStream();
cloned.init(
+ solrConnection,
partitions.get(p), /* each collection */
withoutTieredParam, /* removes the tiered param */
buckets,
@@ -1029,8 +1012,7 @@ public class FacetStream extends TupleStream implements Expressible, ParallelMet
refine,
method,
serializeBucketSizeLimit,
- overfetch,
- zkHost);
+ overfetch);
streams[p] = cloned;
}
return streams;
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/FeaturesSelectionStream.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/FeaturesSelectionStream.java
index ecae4363206..1b669068851 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/FeaturesSelectionStream.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/FeaturesSelectionStream.java
@@ -18,7 +18,6 @@
package org.apache.solr.client.solrj.io.stream;
import static org.apache.solr.client.solrj.io.stream.StreamExecutorHelper.submitAllAndAwaitAggregatingExceptions;
-import static org.apache.solr.common.params.CommonParams.DISTRIB;
import static org.apache.solr.common.params.CommonParams.ID;
import java.io.IOException;
@@ -37,6 +36,7 @@ import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.SolrClientCache;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.comp.StreamComparator;
@@ -46,13 +46,14 @@ import org.apache.solr.client.solrj.io.stream.expr.StreamExplanation;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionParameter;
-import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionValue;
import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
import org.apache.solr.client.solrj.request.QueryRequest;
+import org.apache.solr.client.solrj.request.SolrQuery;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.cloud.Replica;
import org.apache.solr.common.cloud.Slice;
import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
/**
@@ -62,9 +63,9 @@ public class FeaturesSelectionStream extends TupleStream implements Expressible
private static final long serialVersionUID = 1;
- protected String zkHost;
+ protected CloudSolrClient.CloudSolrClientConnection solrConnection;
protected String collection;
- protected Map<String, String> params;
+ protected SolrParams params;
protected Iterator<Tuple> tupleIterator;
protected String field;
protected String outcome;
@@ -76,9 +77,9 @@ public class FeaturesSelectionStream extends TupleStream implements Expressible
private transient boolean doCloseCache;
public FeaturesSelectionStream(
- String zkHost,
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
String collectionName,
- Map<String, String> params,
+ ModifiableSolrParams params,
String field,
String outcome,
String featureSet,
@@ -86,19 +87,28 @@ public class FeaturesSelectionStream extends TupleStream implements Expressible
int numTerms)
throws IOException {
- init(collectionName, zkHost, params, field, outcome, featureSet, positiveLabel, numTerms);
+ init(
+ solrConnection,
+ collectionName,
+ params,
+ field,
+ outcome,
+ featureSet,
+ positiveLabel,
+ numTerms);
}
- /** logit(collection, zkHost="", features="a,b,c,d,e,f,g", outcome="y", maxIteration="20") */
+ /**
+ * logit(collection, solrConnection="", features="a,b,c,d,e,f,g", outcome="y", maxIteration="20")
+ */
public FeaturesSelectionStream(StreamExpression expression, StreamFactory factory)
throws IOException {
// grab all parameters out
String collectionName = factory.getValueOperand(expression, 0);
List<StreamExpressionNamedParameter> namedParams = factory.getNamedOperands(expression);
- StreamExpressionNamedParameter zkHostExpression = factory.getNamedOperand(expression, "zkHost");
- // Validate there are no unknown parameters - zkHost and alias are namedParameter, so we don't
- // need to count it twice
+ // Validate there are no unknown parameters - solrConnection and alias are namedParameter,
+ // so we don't need to count it twice
if (expression.getParameters().size() != 1 + namedParams.size()) {
throw new IOException(
String.format(Locale.ROOT, "invalid expression %s - unknown operands found", expression));
@@ -122,12 +132,8 @@ public class FeaturesSelectionStream extends TupleStream implements Expressible
expression));
}
- Map<String, String> params = new HashMap<>();
- for (StreamExpressionNamedParameter namedParam : namedParams) {
- if (!namedParam.getName().equals("zkHost")) {
- params.put(namedParam.getName(), namedParam.getParameter().toString().trim());
- }
- }
+ ModifiableSolrParams params =
+ buildSolrParamsExcept(namedParams, Set.of("zkHost", "solrConnection"));
String fieldParam = params.get("field");
if (fieldParam != null) {
@@ -166,26 +172,11 @@ public class FeaturesSelectionStream extends TupleStream implements Expressible
throw new IOException("numTerms param cannot be null for FeaturesSelectionStream");
}
- // zkHost, optional - if not provided then will look into factory list to get
- String zkHost = null;
- if (null == zkHostExpression) {
- zkHost = factory.getCollectionZkHost(collectionName);
- } else if (zkHostExpression.getParameter() instanceof StreamExpressionValue) {
- zkHost = ((StreamExpressionValue) zkHostExpression.getParameter()).getValue();
- }
- if (null == zkHost) {
- throw new IOException(
- String.format(
- Locale.ROOT,
- "invalid expression %s - zkHost not found for collection '%s'",
- expression,
- collectionName));
- }
+ var solrConnection = factory.buildSolrConnection(expression, collectionName);
- // We've got all the required items
init(
+ solrConnection,
collectionName,
- zkHost,
params,
fieldParam,
outcomeParam,
@@ -198,43 +189,31 @@ public class FeaturesSelectionStream extends TupleStream implements Expressible
public StreamExpressionParameter toExpression(StreamFactory factory) throws IOException {
// functionName(collectionName, param1, param2, ..., paramN, sort="comp",
// [aliases="field=alias,..."])
-
- // function name
- StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
-
- // collection
- expression.addParameter(collection);
-
- // parameters
- for (Map.Entry<String, String> param : params.entrySet()) {
- expression.addParameter(new StreamExpressionNamedParameter(param.getKey(), param.getValue()));
- }
-
- expression.addParameter(new StreamExpressionNamedParameter("field", field));
- expression.addParameter(new StreamExpressionNamedParameter("outcome", outcome));
- expression.addParameter(new StreamExpressionNamedParameter("featureSet", featureSet));
- expression.addParameter(
- new StreamExpressionNamedParameter("positiveLabel", String.valueOf(positiveLabel)));
- expression.addParameter(
- new StreamExpressionNamedParameter("numTerms", String.valueOf(numTerms)));
-
- // zkHost
- expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
-
- return expression;
+ return new StreamExpression(factory.getFunctionName(this.getClass()))
+ .withParameter(collection)
+ .withMoreParameters(params)
+ .withParameter(new StreamExpressionNamedParameter("field", field))
+ .withParameter(new StreamExpressionNamedParameter("field", field))
+ .withParameter(new StreamExpressionNamedParameter("outcome", outcome))
+ .withParameter(new StreamExpressionNamedParameter("featureSet", featureSet))
+ .withParameter(
+ new StreamExpressionNamedParameter("positiveLabel", String.valueOf(positiveLabel)))
+ .withParameter(new StreamExpressionNamedParameter("numTerms", String.valueOf(numTerms)))
+ .withParameter(
+ new StreamExpressionNamedParameter("solrConnection", solrConnection.toString()));
}
private void init(
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
String collectionName,
- String zkHost,
- Map<String, String> params,
+ ModifiableSolrParams params,
String field,
String outcome,
String featureSet,
int positiveLabel,
int numTopTerms)
throws IOException {
- this.zkHost = zkHost;
+ this.solrConnection = solrConnection;
this.collection = collectionName;
this.params = params;
this.field = field;
@@ -267,7 +246,7 @@ public class FeaturesSelectionStream extends TupleStream implements Expressible
private List<String> getShardUrls() throws IOException {
try {
- var cloudSolrClient = clientCache.getCloudSolrClient(zkHost);
+ var cloudSolrClient = clientCache.getCloudSolrClient(solrConnection);
List<Slice> slices = CloudSolrStream.getSlices(this.collection, cloudSolrClient, false);
Set<String> liveNodes = cloudSolrClient.getClusterState().getLiveNodes();
@@ -400,14 +379,14 @@ public class FeaturesSelectionStream extends TupleStream implements Expressible
private final String baseUrl;
private final String outcome;
private final String field;
- private final Map<String, String> paramsMap;
+ private final SolrParams params;
private final int positiveLabel;
private final int numTerms;
private final SolrClientCache clientCache;
public FeaturesSelectionCall(
String baseUrl,
- Map<String, String> paramsMap,
+ SolrParams params,
String field,
String outcome,
int positiveLabel,
@@ -416,7 +395,7 @@ public class FeaturesSelectionStream extends TupleStream implements Expressible
this.baseUrl = baseUrl;
this.outcome = outcome;
this.field = field;
- this.paramsMap = paramsMap;
+ this.params = params;
this.positiveLabel = positiveLabel;
this.numTerms = numTerms;
this.clientCache = clientCache;
@@ -424,22 +403,20 @@ public class FeaturesSelectionStream extends TupleStream implements Expressible
@Override
public NamedList<?> call() throws Exception {
- ModifiableSolrParams params = new ModifiableSolrParams();
+ SolrQuery queryParams = new SolrQuery();
SolrClient solrClient = clientCache.getHttpSolrClient(baseUrl);
- params.add(DISTRIB, "false");
- params.add("fq", "{!igain}");
+ queryParams.setDistrib(false);
+ queryParams.setFilterQueries("{!igain}");
- for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
- params.add(entry.getKey(), entry.getValue());
- }
+ queryParams.add(params);
- params.add("outcome", outcome);
- params.add("positiveLabel", Integer.toString(positiveLabel));
- params.add("field", field);
- params.add("numTerms", String.valueOf(numTerms));
+ queryParams.add("outcome", outcome);
+ queryParams.add("positiveLabel", Integer.toString(positiveLabel));
+ queryParams.add("field", field);
+ queryParams.add("numTerms", String.valueOf(numTerms));
- QueryRequest request = new QueryRequest(params);
+ QueryRequest request = new QueryRequest(queryParams);
QueryResponse response = request.process(solrClient);
NamedList<?> res = response.getResponse();
return res;
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/FetchStream.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/FetchStream.java
index 2b8a4aea1bc..4f740539f80 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/FetchStream.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/FetchStream.java
@@ -28,6 +28,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.comp.StreamComparator;
import org.apache.solr.client.solrj.io.stream.expr.Explanation;
@@ -53,7 +54,7 @@ public class FetchStream extends TupleStream implements Expressible {
private static final long serialVersionUID = 1;
- protected String zkHost;
+ protected CloudSolrClient.CloudSolrClientConnection solrConnection;
private TupleStream stream;
private StreamContext streamContext;
private Iterator<Tuple> tuples;
@@ -68,14 +69,14 @@ public class FetchStream extends TupleStream implements Expressible {
private boolean appendKey = true;
public FetchStream(
- String zkHost,
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
String collection,
TupleStream tupleStream,
String on,
String fieldList,
int batchSize)
throws IOException {
- init(zkHost, collection, tupleStream, on, fieldList, batchSize);
+ init(solrConnection, collection, tupleStream, on, fieldList, batchSize);
}
public FetchStream(StreamExpression expression, StreamFactory factory) throws IOException {
@@ -88,7 +89,6 @@ public class FetchStream extends TupleStream implements Expressible {
StreamExpressionNamedParameter flParam = factory.getNamedOperand(expression, "fl");
StreamExpressionNamedParameter batchSizeParam =
factory.getNamedOperand(expression, "batchSize");
- StreamExpressionNamedParameter zkHostExpression = factory.getNamedOperand(expression, "zkHost");
String on = null;
String fl = null;
@@ -122,36 +122,20 @@ public class FetchStream extends TupleStream implements Expressible {
TupleStream stream = factory.constructStream(streamExpressions.get(0));
- String zkHost = null;
- if (null == zkHostExpression) {
- zkHost = factory.getCollectionZkHost(collectionName);
- if (zkHost == null) {
- zkHost = factory.getDefaultZkHost();
- }
- } else if (zkHostExpression.getParameter() instanceof StreamExpressionValue) {
- zkHost = ((StreamExpressionValue) zkHostExpression.getParameter()).getValue();
- }
- if (null == zkHost) {
- throw new IOException(
- String.format(
- Locale.ROOT,
- "invalid expression %s - zkHost not found for collection '%s'",
- expression,
- collectionName));
- }
+ var solrConnection = factory.buildSolrConnection(expression, collectionName);
- init(zkHost, collectionName, stream, on, fl, batchSize);
+ init(solrConnection, collectionName, stream, on, fl, batchSize);
}
private void init(
- String zkHost,
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
String collection,
TupleStream tupleStream,
String on,
String fieldList,
int batchSize)
throws IOException {
- this.zkHost = zkHost;
+ this.solrConnection = solrConnection;
this.collection = collection;
this.stream = tupleStream;
this.batchSize = batchSize;
@@ -264,7 +248,7 @@ public class FetchStream extends TupleStream implements Expressible {
params.add("rows", Integer.toString(batchSize));
params.add(SORT, "_version_ desc");
- CloudSolrStream cloudSolrStream = new CloudSolrStream(zkHost, collection, params);
+ CloudSolrStream cloudSolrStream = new CloudSolrStream(solrConnection, collection, params);
StreamContext newContext = new StreamContext();
newContext.setSolrClientCache(streamContext.getSolrClientCache());
newContext.setObjectCache(streamContext.getObjectCache());
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/KnnStream.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/KnnStream.java
index b88867e73b6..2b013061120 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/KnnStream.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/KnnStream.java
@@ -22,13 +22,14 @@ import static org.apache.solr.common.params.CommonParams.ROWS;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
-import java.util.Map;
import java.util.Map.Entry;
+import java.util.Set;
import java.util.stream.Collectors;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.SolrClientCache;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.comp.StreamComparator;
@@ -45,8 +46,8 @@ import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
-import org.apache.solr.common.params.MapSolrParams;
import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.params.SolrParams;
/**
* @since 7.0.0
@@ -57,24 +58,27 @@ public class KnnStream extends TupleStream implements Expressible {
"qf", "mintf", "mindf", "maxdf", "minwl", "maxwl", "maxqt", "maxntp", "boost"
};
- private String zkHost;
- private Map<String, String> props;
+ private CloudSolrClient.CloudSolrClientConnection solrConnection;
+ private SolrParams props;
private String collection;
private transient SolrClientCache clientCache;
private transient boolean doCloseCache;
private Iterator<SolrDocument> documentIterator;
private String id;
- public KnnStream(String zkHost, String collection, String id, Map<String, String> props)
+ public KnnStream(
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
+ String collection,
+ String id,
+ SolrParams props)
throws IOException {
- init(zkHost, collection, id, props);
+ init(solrConnection, collection, id, props);
}
public KnnStream(StreamExpression expression, StreamFactory factory) throws IOException {
// grab all parameters out
String collectionName = factory.getValueOperand(expression, 0);
List<StreamExpressionNamedParameter> namedParams = factory.getNamedOperands(expression);
- StreamExpressionNamedParameter zkHostExpression = factory.getNamedOperand(expression, "zkHost");
StreamExpressionNamedParameter idExpression = factory.getNamedOperand(expression, "id");
StreamExpressionNamedParameter qfExpression = factory.getNamedOperand(expression, "qf");
@@ -97,12 +101,8 @@ public class KnnStream extends TupleStream implements Expressible {
}
// pull out known named params
- Map<String, String> params = new HashMap<>();
- for (StreamExpressionNamedParameter namedParam : namedParams) {
- if (!namedParam.getName().equals("zkHost") && !namedParam.getName().equals("id")) {
- params.put(namedParam.getName(), namedParam.getParameter().toString().trim());
- }
- }
+ ModifiableSolrParams params =
+ buildSolrParamsExcept(namedParams, Set.of("solrConnection", "zkHost", "id"));
String id = null;
if (idExpression != null) {
@@ -115,32 +115,18 @@ public class KnnStream extends TupleStream implements Expressible {
throw new IOException("qf parameter is expected for KnnStream");
}
- // zkHost, optional - if not provided then will look into factory list to get
- String zkHost = null;
- if (null == zkHostExpression) {
- zkHost = factory.getCollectionZkHost(collectionName);
- if (zkHost == null) {
- zkHost = factory.getDefaultZkHost();
- }
- } else if (zkHostExpression.getParameter() instanceof StreamExpressionValue) {
- zkHost = ((StreamExpressionValue) zkHostExpression.getParameter()).getValue();
- }
- if (null == zkHost) {
- throw new IOException(
- String.format(
- Locale.ROOT,
- "invalid expression %s - zkHost not found for collection '%s'",
- expression,
- collectionName));
- }
+ var solrConnection = factory.buildSolrConnection(expression, collectionName);
- // We've got all the required items
- init(zkHost, collectionName, id, params);
+ init(solrConnection, collectionName, id, params);
}
- private void init(String zkHost, String collection, String id, Map<String, String> props)
+ private void init(
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
+ String collection,
+ String id,
+ SolrParams props)
throws IOException {
- this.zkHost = zkHost;
+ this.solrConnection = solrConnection;
this.props = props;
this.collection = collection;
this.id = id;
@@ -155,12 +141,14 @@ public class KnnStream extends TupleStream implements Expressible {
expression.addParameter(collection);
// parameters
- for (Entry<String, String> param : props.entrySet()) {
- expression.addParameter(new StreamExpressionNamedParameter(param.getKey(), param.getValue()));
+ for (Entry<String, String[]> param : props) {
+ for (String paramValue : param.getValue()) {
+ expression.addParameter(new StreamExpressionNamedParameter(param.getKey(), paramValue));
+ }
}
- // zkHost
- expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
+ expression.addParameter(
+ new StreamExpressionNamedParameter("solrConnection", solrConnection.toString()));
return expression;
}
@@ -181,10 +169,14 @@ public class KnnStream extends TupleStream implements Expressible {
child.setImplementingClass("Solr/Lucene");
child.setExpressionType(ExpressionType.DATASTORE);
if (null != props) {
- child.setExpression(
- props.entrySet().stream()
- .map(e -> String.format(Locale.ROOT, "%s=%s", e.getKey(), e.getValue()))
- .collect(Collectors.joining(",")));
+ String expression =
+ props.stream()
+ .flatMap(
+ e ->
+ Arrays.stream(e.getValue())
+ .map(v -> String.format(Locale.ROOT, "%s=%s", e.getKey(), v)))
+ .collect(Collectors.joining(","));
+ child.setExpression(expression);
}
explanation.addChild(child);
@@ -211,7 +203,7 @@ public class KnnStream extends TupleStream implements Expressible {
doCloseCache = false;
}
- var params = new ModifiableSolrParams(new MapSolrParams(this.props)); // copy
+ var params = new ModifiableSolrParams(props); // copy
StringBuilder builder = new StringBuilder();
@@ -233,7 +225,8 @@ public class KnnStream extends TupleStream implements Expressible {
QueryRequest request = new QueryRequest(params);
try {
- QueryResponse response = request.process(clientCache.getCloudSolrClient(zkHost), collection);
+ QueryResponse response =
+ request.process(clientCache.getCloudSolrClient(solrConnection), collection);
SolrDocumentList docs = response.getResults();
documentIterator = docs.iterator();
} catch (Exception e) {
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/ModelStream.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/ModelStream.java
index ce3e37fdbab..df5be7abaa0 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/ModelStream.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/ModelStream.java
@@ -21,10 +21,10 @@ import static org.apache.solr.common.params.CommonParams.ID;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Locale;
-import java.util.Map;
+import java.util.Set;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.ModelCache;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.comp.StreamComparator;
@@ -34,8 +34,8 @@ import org.apache.solr.client.solrj.io.stream.expr.StreamExplanation;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionParameter;
-import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionValue;
import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
+import org.apache.solr.common.params.SolrParams;
/**
* The ModelStream retrieves a stored model from a Solr Cloud collection.
@@ -48,24 +48,27 @@ public class ModelStream extends TupleStream implements Expressible {
private static final long serialVersionUID = 1;
- protected String zkHost;
+ protected CloudSolrClient.CloudSolrClientConnection solrConnection;
protected String collection;
protected String modelID;
protected ModelCache modelCache;
protected Tuple model;
protected long cacheMillis;
- public ModelStream(String zkHost, String collectionName, String modelID, long cacheMillis)
+ public ModelStream(
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
+ String collectionName,
+ String modelID,
+ long cacheMillis)
throws IOException {
- init(collectionName, zkHost, modelID, cacheMillis);
+ init(solrConnection, collectionName, modelID, cacheMillis);
}
public ModelStream(StreamExpression expression, StreamFactory factory) throws IOException {
// grab all parameters out
String collectionName = factory.getValueOperand(expression, 0);
List<StreamExpressionNamedParameter> namedParams = factory.getNamedOperands(expression);
- StreamExpressionNamedParameter zkHostExpression = factory.getNamedOperand(expression, "zkHost");
// Collection Name
if (null == collectionName) {
@@ -85,12 +88,7 @@ public class ModelStream extends TupleStream implements Expressible {
expression));
}
- Map<String, String> params = new HashMap<>();
- for (StreamExpressionNamedParameter namedParam : namedParams) {
- if (!namedParam.getName().equals("zkHost")) {
- params.put(namedParam.getName(), namedParam.getParameter().toString().trim());
- }
- }
+ SolrParams params = buildSolrParamsExcept(namedParams, Set.of("zkHost", "solrConnection"));
String modelID = params.get(ID);
if (modelID == null) {
@@ -104,29 +102,9 @@ public class ModelStream extends TupleStream implements Expressible {
cacheMillis = Long.parseLong(cacheMillisParam);
}
- // zkHost, optional - if not provided then will look into factory list to get
- String zkHost = null;
- if (null == zkHostExpression) {
- zkHost = factory.getCollectionZkHost(collectionName);
- } else if (zkHostExpression.getParameter() instanceof StreamExpressionValue) {
- zkHost = ((StreamExpressionValue) zkHostExpression.getParameter()).getValue();
- }
-
- if (zkHost == null) {
- zkHost = factory.getDefaultZkHost();
- }
-
- if (null == zkHost) {
- throw new IOException(
- String.format(
- Locale.ROOT,
- "invalid expression %s - zkHost not found for collection '%s'",
- expression,
- collectionName));
- }
+ var solrConnection = factory.buildSolrConnection(expression, collectionName);
- // We've got all the required items
- init(collectionName, zkHost, modelID, cacheMillis);
+ init(solrConnection, collectionName, modelID, cacheMillis);
}
@Override
@@ -141,8 +119,8 @@ public class ModelStream extends TupleStream implements Expressible {
// collection
expression.addParameter(collection);
- // zkHost
- expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
+ expression.addParameter(
+ new StreamExpressionNamedParameter("solrConnection", solrConnection.toString()));
expression.addParameter(new StreamExpressionNamedParameter(ID, modelID));
expression.addParameter(
new StreamExpressionNamedParameter("cacheMillis", Long.toString(cacheMillis)));
@@ -150,9 +128,13 @@ public class ModelStream extends TupleStream implements Expressible {
return expression;
}
- private void init(String collectionName, String zkHost, String modelID, long cacheMillis)
+ private void init(
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
+ String collectionName,
+ String modelID,
+ long cacheMillis)
throws IOException {
- this.zkHost = zkHost;
+ this.solrConnection = solrConnection;
this.collection = collectionName;
this.modelID = modelID;
this.cacheMillis = cacheMillis;
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/ParallelStream.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/ParallelStream.java
index bc385c72354..1c28b4f3316 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/ParallelStream.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/ParallelStream.java
@@ -23,6 +23,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.comp.FieldComparator;
import org.apache.solr.client.solrj.io.comp.StreamComparator;
@@ -50,16 +51,24 @@ public class ParallelStream extends CloudSolrStream implements Expressible {
private transient StreamFactory streamFactory;
public ParallelStream(
- String zkHost, String collection, TupleStream tupleStream, int workers, StreamComparator comp)
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
+ String collection,
+ TupleStream tupleStream,
+ int workers,
+ StreamComparator comp)
throws IOException {
- init(zkHost, collection, tupleStream, workers, comp);
+ init(solrConnection, collection, tupleStream, workers, comp);
}
public ParallelStream(
- String zkHost, String collection, String expressionString, int workers, StreamComparator comp)
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
+ String collection,
+ String expressionString,
+ int workers,
+ StreamComparator comp)
throws IOException {
TupleStream tStream = this.streamFactory.constructStream(expressionString);
- init(zkHost, collection, tStream, workers, comp);
+ init(solrConnection, collection, tStream, workers, comp);
}
public void setStreamFactory(StreamFactory streamFactory) {
@@ -75,11 +84,15 @@ public class ParallelStream extends CloudSolrStream implements Expressible {
expression, Expressible.class, TupleStream.class);
StreamExpressionNamedParameter sortExpression = factory.getNamedOperand(expression, SORT);
StreamExpressionNamedParameter zkHostExpression = factory.getNamedOperand(expression, "zkHost");
+ StreamExpressionNamedParameter solrConnectionExpression =
+ factory.getNamedOperand(expression, "solrConnection");
// validate expression contains only what we want.
if (expression.getParameters().size()
- != streamExpressions.size() + 3 + (null != zkHostExpression ? 1 : 0)) {
+ != streamExpressions.size()
+ + 3
+ + (null != zkHostExpression || null != solrConnectionExpression ? 1 : 0)) {
throw new IOException(
String.format(Locale.ROOT, "Invalid expression %s - unknown operands found", expression));
}
@@ -144,39 +157,25 @@ public class ParallelStream extends CloudSolrStream implements Expressible {
expression));
}
- // zkHost, optional - if not provided then will look into factory list to get
- String zkHost = null;
- if (null == zkHostExpression) {
- zkHost = factory.getCollectionZkHost(collectionName);
- if (zkHost == null) {
- zkHost = factory.getDefaultZkHost();
- }
- } else if (zkHostExpression.getParameter() instanceof StreamExpressionValue) {
- zkHost = ((StreamExpressionValue) zkHostExpression.getParameter()).getValue();
- }
- if (null == zkHost) {
- throw new IOException(
- String.format(
- Locale.ROOT,
- "invalid expression %s - zkHost not found for collection '%s'",
- expression,
- collectionName));
- }
+ var solrConnection = factory.buildSolrConnection(expression, collectionName);
- // We've got all the required items
TupleStream stream = factory.constructStream(streamExpressions.get(0));
StreamComparator comp =
factory.constructComparator(
((StreamExpressionValue) sortExpression.getParameter()).getValue(),
FieldComparator.class);
streamFactory = factory;
- init(zkHost, collectionName, stream, workersInt, comp);
+ init(solrConnection, collectionName, stream, workersInt, comp);
}
private void init(
- String zkHost, String collection, TupleStream tupleStream, int workers, StreamComparator comp)
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
+ String collection,
+ TupleStream tupleStream,
+ int workers,
+ StreamComparator comp)
throws IOException {
- this.zkHost = zkHost;
+ this.solrConnection = solrConnection;
this.collection = collection;
this.workers = workers;
this.comp = comp;
@@ -219,8 +218,8 @@ public class ParallelStream extends CloudSolrStream implements Expressible {
// sort
expression.addParameter(new StreamExpressionNamedParameter(SORT, comp.toExpression(factory)));
- // zkHost
- expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
+ expression.addParameter(
+ new StreamExpressionNamedParameter("solrConnection", solrConnection.toString()));
return expression;
}
@@ -289,7 +288,7 @@ public class ParallelStream extends CloudSolrStream implements Expressible {
try {
Object pushStream = ((Expressible) tupleStream).toExpression(streamFactory);
- List<String> shardUrls = getShards(this.zkHost, this.collection, this.streamContext);
+ List<String> shardUrls = getShards(this.solrConnection, this.collection, this.streamContext);
for (int w = 0; w < workers; w++) {
ModifiableSolrParams paramsLoc = new ModifiableSolrParams();
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/RandomFacadeStream.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/RandomFacadeStream.java
index 2b0ddaba92b..8bf112c831a 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/RandomFacadeStream.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/RandomFacadeStream.java
@@ -20,10 +20,9 @@ package org.apache.solr.client.solrj.io.stream;
import static org.apache.solr.common.params.CommonParams.ROWS;
import java.io.IOException;
-import java.util.HashMap;
import java.util.List;
import java.util.Locale;
-import java.util.Map;
+import java.util.Set;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.comp.StreamComparator;
import org.apache.solr.client.solrj.io.stream.expr.Explanation;
@@ -31,10 +30,8 @@ import org.apache.solr.client.solrj.io.stream.expr.Expressible;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionParameter;
-import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionValue;
import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
import org.apache.solr.common.params.ModifiableSolrParams;
-import org.apache.solr.common.params.SolrParams;
public class RandomFacadeStream extends TupleStream implements Expressible {
@@ -44,7 +41,6 @@ public class RandomFacadeStream extends TupleStream implements Expressible {
// grab all parameters out
String collectionName = factory.getValueOperand(expression, 0);
List<StreamExpressionNamedParameter> namedParams = factory.getNamedOperands(expression);
- StreamExpressionNamedParameter zkHostExpression = factory.getNamedOperand(expression, "zkHost");
// Collection Name
if (null == collectionName) {
@@ -56,75 +52,44 @@ public class RandomFacadeStream extends TupleStream implements Expressible {
}
// pull out known named params
- Map<String, String> params = new HashMap<>();
- for (StreamExpressionNamedParameter namedParam : namedParams) {
- if (!namedParam.getName().equals("zkHost")
- && !namedParam.getName().equals("buckets")
- && !namedParam.getName().equals("bucketSorts")
- && !namedParam.getName().equals("limit")) {
- params.put(namedParam.getName(), namedParam.getParameter().toString().trim());
- }
- }
+ ModifiableSolrParams params =
+ buildSolrParamsExcept(
+ namedParams, Set.of("solrConnection", "zkHost", "buckets", "bucketSorts", "limit"));
// Add sensible defaults
- if (!params.containsKey("q")) {
- params.put("q", "*:*");
+ if (params.get("q") == null) {
+ params.add("q", "*:*");
}
- if (!params.containsKey("fl")) {
- params.put("fl", "*");
+ if (params.get("fl") == null) {
+ params.add("fl", "*");
}
- if (!params.containsKey("rows")) {
- params.put("rows", "500");
+ if (params.get("rows") == null) {
+ params.add("rows", "500");
}
- // zkHost, optional - if not provided then will look into factory list to get
- String zkHost = null;
- if (null == zkHostExpression) {
- zkHost = factory.getCollectionZkHost(collectionName);
- if (zkHost == null) {
- zkHost = factory.getDefaultZkHost();
- }
- } else if (zkHostExpression.getParameter() instanceof StreamExpressionValue) {
- zkHost = ((StreamExpressionValue) zkHostExpression.getParameter()).getValue();
- }
- if (null == zkHost) {
- throw new IOException(
- String.format(
- Locale.ROOT,
- "invalid expression %s - zkHost not found for collection '%s'",
- expression,
- collectionName));
- }
+ var solrConnection = factory.buildSolrConnection(expression, collectionName);
if (params.get(ROWS) != null) {
int rows = Integer.parseInt(params.get(ROWS));
if (rows >= 5000) {
DeepRandomStream deepRandomStream = new DeepRandomStream();
- deepRandomStream.init(collectionName, zkHost, toSolrParams(params));
+ deepRandomStream.init(solrConnection, collectionName, params);
this.innerStream = deepRandomStream;
} else {
RandomStream randomStream = new RandomStream();
- randomStream.init(zkHost, collectionName, params);
+ randomStream.init(solrConnection, collectionName, params);
this.innerStream = randomStream;
}
} else {
RandomStream randomStream = new RandomStream();
- randomStream.init(zkHost, collectionName, params);
+ randomStream.init(solrConnection, collectionName, params);
this.innerStream = randomStream;
}
}
- private SolrParams toSolrParams(Map<String, String> props) {
- ModifiableSolrParams sp = new ModifiableSolrParams();
- for (Map.Entry<String, String> entry : props.entrySet()) {
- sp.add(entry.getKey(), entry.getValue());
- }
- return sp;
- }
-
@Override
public StreamExpressionParameter toExpression(StreamFactory factory) throws IOException {
return ((Expressible) innerStream).toExpression(factory);
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/RandomStream.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/RandomStream.java
index de7db9b6b2c..89ead7328c7 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/RandomStream.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/RandomStream.java
@@ -21,15 +21,16 @@ import static org.apache.solr.common.params.CommonParams.SORT;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
-import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
+import java.util.Set;
import java.util.stream.Collectors;
import org.apache.solr.client.solrj.SolrRequest;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.SolrClientCache;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.comp.StreamComparator;
@@ -40,15 +41,14 @@ import org.apache.solr.client.solrj.io.stream.expr.StreamExplanation;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionParameter;
-import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionValue;
import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.params.CommonParams;
-import org.apache.solr.common.params.MapSolrParams;
import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.params.SolrParams;
/**
* The RandomStream emits a stream of pseudo random Tuples that match the query parameters. Sample
@@ -58,8 +58,8 @@ import org.apache.solr.common.params.ModifiableSolrParams;
*/
public class RandomStream extends TupleStream implements Expressible {
- private String zkHost;
- private Map<String, String> props;
+ private CloudSolrClient.CloudSolrClientConnection solrConnection;
+ private SolrParams props;
private String collection;
private Iterator<SolrDocument> documentIterator;
private int x;
@@ -72,16 +72,16 @@ public class RandomStream extends TupleStream implements Expressible {
// Used by the RandomFacade
}
- public RandomStream(String zkHost, String collection, Map<String, String> props)
+ public RandomStream(
+ CloudSolrClient.CloudSolrClientConnection solrConnection, String collection, SolrParams props)
throws IOException {
- init(zkHost, collection, props);
+ init(solrConnection, collection, props);
}
public RandomStream(StreamExpression expression, StreamFactory factory) throws IOException {
// grab all parameters out
String collectionName = factory.getValueOperand(expression, 0);
List<StreamExpressionNamedParameter> namedParams = factory.getNamedOperands(expression);
- StreamExpressionNamedParameter zkHostExpression = factory.getNamedOperand(expression, "zkHost");
// Collection Name
if (null == collectionName) {
@@ -93,44 +93,22 @@ public class RandomStream extends TupleStream implements Expressible {
}
// pull out known named params
- Map<String, String> params = new HashMap<>();
- for (StreamExpressionNamedParameter namedParam : namedParams) {
- if (!namedParam.getName().equals("zkHost")
- && !namedParam.getName().equals("buckets")
- && !namedParam.getName().equals("bucketSorts")
- && !namedParam.getName().equals("limit")) {
- params.put(namedParam.getName(), namedParam.getParameter().toString().trim());
- }
- }
+ SolrParams params =
+ buildSolrParamsExcept(
+ namedParams, Set.of("zkHost", "solrConnection", "buckets", "bucketSorts", "limit"));
- // zkHost, optional - if not provided then will look into factory list to get
- String zkHost = null;
- if (null == zkHostExpression) {
- zkHost = factory.getCollectionZkHost(collectionName);
- if (zkHost == null) {
- zkHost = factory.getDefaultZkHost();
- }
- } else if (zkHostExpression.getParameter() instanceof StreamExpressionValue) {
- zkHost = ((StreamExpressionValue) zkHostExpression.getParameter()).getValue();
- }
- if (null == zkHost) {
- throw new IOException(
- String.format(
- Locale.ROOT,
- "invalid expression %s - zkHost not found for collection '%s'",
- expression,
- collectionName));
- }
+ var solrConnection = factory.buildSolrConnection(expression, collectionName);
- // We've got all the required items
- init(zkHost, collectionName, params);
+ init(solrConnection, collectionName, params);
}
- void init(String zkHost, String collection, Map<String, String> props) throws IOException {
- this.zkHost = zkHost;
+ void init(
+ CloudSolrClient.CloudSolrClientConnection solrConnection, String collection, SolrParams props)
+ throws IOException {
+ this.solrConnection = solrConnection;
this.props = props;
this.collection = collection;
- if (props.containsKey(CommonParams.FL)) {
+ if (props.get(CommonParams.FL) != null) {
String fl = props.get(CommonParams.FL);
if (fl != null) {
if (fl.equals("*")) {
@@ -160,12 +138,14 @@ public class RandomStream extends TupleStream implements Expressible {
expression.addParameter(collection);
// parameters
- for (Entry<String, String> param : props.entrySet()) {
- expression.addParameter(new StreamExpressionNamedParameter(param.getKey(), param.getValue()));
+ for (Entry<String, String[]> param : props) {
+ for (String paramValue : param.getValue()) {
+ expression.addParameter(new StreamExpressionNamedParameter(param.getKey(), paramValue));
+ }
}
- // zkHost
- expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
+ expression.addParameter(
+ new StreamExpressionNamedParameter("solrConnection", solrConnection.toString()));
return expression;
}
@@ -186,10 +166,14 @@ public class RandomStream extends TupleStream implements Expressible {
child.setImplementingClass("Solr/Lucene");
child.setExpressionType(ExpressionType.DATASTORE);
if (null != props) {
- child.setExpression(
- props.entrySet().stream()
- .map(e -> String.format(Locale.ROOT, "%s=%s", e.getKey(), e.getValue()))
- .collect(Collectors.joining(",")));
+ String expression =
+ props.stream()
+ .flatMap(
+ e ->
+ Arrays.stream(e.getValue())
+ .map(v -> String.format(Locale.ROOT, "%s=%s", e.getKey(), v)))
+ .collect(Collectors.joining(","));
+ child.setExpression(expression);
}
explanation.addChild(child);
@@ -216,7 +200,7 @@ public class RandomStream extends TupleStream implements Expressible {
doCloseCache = false;
}
- var params = new ModifiableSolrParams(new MapSolrParams(this.props)); // copy
+ var params = new ModifiableSolrParams(props); // copy
params.remove(SORT); // Override any sort.
@@ -228,7 +212,7 @@ public class RandomStream extends TupleStream implements Expressible {
QueryRequest request = new QueryRequest(params, SolrRequest.METHOD.POST);
try {
- var cloudSolrClient = clientCache.getCloudSolrClient(zkHost);
+ var cloudSolrClient = clientCache.getCloudSolrClient(solrConnection);
QueryResponse response = request.process(cloudSolrClient, collection);
SolrDocumentList docs = response.getResults();
documentIterator = docs.iterator();
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/ScoreNodesStream.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/ScoreNodesStream.java
index 2b3847dfa5c..1d3e42231ea 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/ScoreNodesStream.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/ScoreNodesStream.java
@@ -58,7 +58,7 @@ public class ScoreNodesStream extends TupleStream implements Expressible {
private static final long serialVersionUID = 1;
- protected String zkHost;
+ protected CloudSolrClient.CloudSolrClientConnection solrConnection;
private TupleStream stream;
private Map<String, Tuple> nodes = new HashMap<>();
private Iterator<Tuple> tuples;
@@ -96,10 +96,10 @@ public class ScoreNodesStream extends TupleStream implements Expressible {
streamExpressions.size()));
}
- zkHost = factory.getDefaultZkHost();
+ solrConnection = factory.getDefaultSolrConnection();
- if (null == zkHost) {
- throw new IOException("zkHost not found");
+ if (null == solrConnection) {
+ throw new IOException("solrConnection not found");
}
TupleStream stream = factory.constructStream(streamExpressions.get(0));
@@ -220,7 +220,7 @@ public class ScoreNodesStream extends TupleStream implements Expressible {
builder.append(nodeId);
}
- CloudSolrClient client = clientCache.getCloudSolrClient(zkHost);
+ CloudSolrClient client = clientCache.getCloudSolrClient(solrConnection);
ModifiableSolrParams params = new ModifiableSolrParams();
params.add(CommonParams.QT, "/terms");
params.add(TermsParams.TERMS_FIELD, field);
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/SearchFacadeStream.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/SearchFacadeStream.java
index b240821bc90..2bf2fc61974 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/SearchFacadeStream.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/SearchFacadeStream.java
@@ -19,6 +19,7 @@ package org.apache.solr.client.solrj.io.stream;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
+import java.util.Set;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.comp.StreamComparator;
import org.apache.solr.client.solrj.io.stream.expr.Explanation;
@@ -26,7 +27,6 @@ import org.apache.solr.client.solrj.io.stream.expr.Expressible;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionParameter;
-import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionValue;
import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams;
@@ -53,7 +53,6 @@ public class SearchFacadeStream extends TupleStream implements Expressible {
}
List<StreamExpressionNamedParameter> namedParams = factory.getNamedOperands(expression);
- StreamExpressionNamedParameter zkHostExpression = factory.getNamedOperand(expression, "zkHost");
// Collection Name
if (null == collectionName) {
@@ -64,32 +63,14 @@ public class SearchFacadeStream extends TupleStream implements Expressible {
expression));
}
- ModifiableSolrParams mParams = new ModifiableSolrParams();
- for (StreamExpressionNamedParameter namedParam : namedParams) {
- if (!namedParam.getName().equals("zkHost") && !namedParam.getName().equals("aliases")) {
- mParams.add(namedParam.getName(), namedParam.getParameter().toString().trim());
- }
- }
+ ModifiableSolrParams mParams =
+ buildSolrParamsExcept(namedParams, Set.of("zkHost", "solrConnection", "aliases"));
- // zkHost, optional - if not provided then will look into factory list to get
- String zkHost = null;
- if (null == zkHostExpression) {
- zkHost = factory.getCollectionZkHost(collectionName);
- if (zkHost == null) {
- zkHost = factory.getDefaultZkHost();
- }
- } else if (zkHostExpression.getParameter() instanceof StreamExpressionValue) {
- zkHost = ((StreamExpressionValue) zkHostExpression.getParameter()).getValue();
- }
- /*
- if(null == zkHost){
- throw new IOException(String.format(Locale.ROOT,"invalid expression %s - zkHost not found for collection '%s'",expression,collectionName));
- }
- */
+ var solrConnection = factory.buildSolrConnection(expression, collectionName);
if (mParams.get(CommonParams.QT) != null && mParams.get(CommonParams.QT).equals("/export")) {
CloudSolrStream cloudSolrStream = new CloudSolrStream();
- cloudSolrStream.init(collectionName, zkHost, mParams);
+ cloudSolrStream.init(solrConnection, collectionName, mParams);
this.innerStream = cloudSolrStream;
} else {
@@ -99,7 +80,7 @@ public class SearchFacadeStream extends TupleStream implements Expressible {
}
SearchStream searchStream = new SearchStream();
- searchStream.init(zkHost, collectionName, mParams);
+ searchStream.init(solrConnection, collectionName, mParams);
this.innerStream = searchStream;
}
}
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/SearchStream.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/SearchStream.java
index a00e5fb8bd5..0b787c73c41 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/SearchStream.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/SearchStream.java
@@ -24,7 +24,9 @@ import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map.Entry;
+import java.util.Set;
import org.apache.solr.client.solrj.SolrRequest;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.SolrClientCache;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.comp.ComparatorOrder;
@@ -38,7 +40,6 @@ import org.apache.solr.client.solrj.io.stream.expr.StreamExplanation;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionParameter;
-import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionValue;
import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.response.QueryResponse;
@@ -49,7 +50,7 @@ import org.apache.solr.common.params.ModifiableSolrParams;
public class SearchStream extends TupleStream implements Expressible {
- private String zkHost;
+ private CloudSolrClient.CloudSolrClientConnection solrConnection;
private ModifiableSolrParams params;
private String collection;
private Iterator<SolrDocument> documentIterator;
@@ -64,7 +65,6 @@ public class SearchStream extends TupleStream implements Expressible {
// grab all parameters out
String collectionName = factory.getValueOperand(expression, 0);
List<StreamExpressionNamedParameter> namedParams = factory.getNamedOperands(expression);
- StreamExpressionNamedParameter zkHostExpression = factory.getNamedOperand(expression, "zkHost");
// Collection Name
if (null == collectionName) {
@@ -85,41 +85,21 @@ public class SearchStream extends TupleStream implements Expressible {
}
// pull out known named params
- ModifiableSolrParams params = new ModifiableSolrParams();
- for (StreamExpressionNamedParameter namedParam : namedParams) {
- if (!namedParam.getName().equals("zkHost")
- && !namedParam.getName().equals("buckets")
- && !namedParam.getName().equals("bucketSorts")
- && !namedParam.getName().equals("limit")) {
- params.add(namedParam.getName(), namedParam.getParameter().toString().trim());
- }
- }
+ ModifiableSolrParams params =
+ buildSolrParamsExcept(
+ namedParams, Set.of("zkHost", "solrConnection", "buckets", "bucketSorts", "limit"));
- // zkHost, optional - if not provided then will look into factory list to get
- String zkHost = null;
- if (null == zkHostExpression) {
- zkHost = factory.getCollectionZkHost(collectionName);
- if (zkHost == null) {
- zkHost = factory.getDefaultZkHost();
- }
- } else if (zkHostExpression.getParameter() instanceof StreamExpressionValue) {
- zkHost = ((StreamExpressionValue) zkHostExpression.getParameter()).getValue();
- }
- if (null == zkHost) {
- throw new IOException(
- String.format(
- Locale.ROOT,
- "invalid expression %s - zkHost not found for collection '%s'",
- expression,
- collectionName));
- }
+ var solrConnection = factory.buildSolrConnection(expression, collectionName);
- // We've got all the required items
- init(zkHost, collectionName, params);
+ init(solrConnection, collectionName, params);
}
- void init(String zkHost, String collection, ModifiableSolrParams params) throws IOException {
- this.zkHost = zkHost;
+ void init(
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
+ String collection,
+ ModifiableSolrParams params)
+ throws IOException {
+ this.solrConnection = solrConnection;
this.params = params;
if (this.params.get(CommonParams.Q) == null) {
@@ -153,8 +133,8 @@ public class SearchStream extends TupleStream implements Expressible {
}
}
- // zkHost
- expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
+ expression.addParameter(
+ new StreamExpressionNamedParameter("solrConnection", solrConnection.toString()));
return expression;
}
@@ -202,7 +182,7 @@ public class SearchStream extends TupleStream implements Expressible {
QueryRequest request = new QueryRequest(params, SolrRequest.METHOD.POST);
try {
- var cloudSolrClient = clientCache.getCloudSolrClient(zkHost);
+ var cloudSolrClient = clientCache.getCloudSolrClient(solrConnection);
QueryResponse response = request.process(cloudSolrClient, collection);
SolrDocumentList docs = response.getResults();
documentIterator = docs.iterator();
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/ShuffleStream.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/ShuffleStream.java
index 8e62902c98c..eb04029d8d1 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/ShuffleStream.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/ShuffleStream.java
@@ -22,6 +22,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Set;
import java.util.stream.Collectors;
import org.apache.solr.client.solrj.io.stream.expr.Explanation;
import org.apache.solr.client.solrj.io.stream.expr.Expressible;
@@ -43,7 +44,6 @@ public class ShuffleStream extends CloudSolrStream implements Expressible {
String collectionName = factory.getValueOperand(expression, 0);
List<StreamExpressionNamedParameter> namedParams = factory.getNamedOperands(expression);
StreamExpressionNamedParameter aliasExpression = factory.getNamedOperand(expression, "aliases");
- StreamExpressionNamedParameter zkHostExpression = factory.getNamedOperand(expression, "zkHost");
// Collection Name
if (null == collectionName) {
@@ -54,8 +54,8 @@ public class ShuffleStream extends CloudSolrStream implements Expressible {
expression));
}
- // Validate there are no unknown parameters - zkHost and alias are namedParameter, so we don't
- // need to count it twice
+ // Validate there are no unknown parameters - solrConnection/zkHost and alias are
+ // namedParameter, so we don't need to count it twice
if (expression.getParameters().size() != 1 + namedParams.size()) {
throw new IOException(
String.format(Locale.ROOT, "invalid expression %s - unknown operands found", expression));
@@ -70,12 +70,8 @@ public class ShuffleStream extends CloudSolrStream implements Expressible {
expression));
}
- ModifiableSolrParams mParams = new ModifiableSolrParams();
- for (StreamExpressionNamedParameter namedParam : namedParams) {
- if (!namedParam.getName().equals("zkHost") && !namedParam.getName().equals("aliases")) {
- mParams.add(namedParam.getName(), namedParam.getParameter().toString().trim());
- }
- }
+ ModifiableSolrParams mParams =
+ buildSolrParamsExcept(namedParams, Set.of("zkHost", "solrConnection", "aliases"));
// Aliases, optional, if provided then need to split
if (null != aliasExpression
@@ -96,27 +92,9 @@ public class ShuffleStream extends CloudSolrStream implements Expressible {
}
}
- // zkHost, optional - if not provided then will look into factory list to get
- String zkHost = null;
- if (null == zkHostExpression) {
- zkHost = factory.getCollectionZkHost(collectionName);
- if (zkHost == null) {
- zkHost = factory.getDefaultZkHost();
- }
- } else if (zkHostExpression.getParameter() instanceof StreamExpressionValue) {
- zkHost = ((StreamExpressionValue) zkHostExpression.getParameter()).getValue();
- }
- if (null == zkHost) {
- throw new IOException(
- String.format(
- Locale.ROOT,
- "invalid expression %s - zkHost not found for collection '%s'",
- expression,
- collectionName));
- }
+ var solrConnection = factory.buildSolrConnection(expression, collectionName);
- // We've got all the required items
- init(collectionName, zkHost, mParams);
+ init(solrConnection, collectionName, mParams);
}
@Override
@@ -130,7 +108,7 @@ public class ShuffleStream extends CloudSolrStream implements Expressible {
// collection
expression.addParameter(collection);
- for (Map.Entry<String, String[]> param : params.getMap().entrySet()) {
+ for (Map.Entry<String, String[]> param : params) {
for (String val : param.getValue()) {
// SOLR-8409: Escaping the " is a special case.
// Do note that in any other BASE streams with parameters where a " might come into play
@@ -140,8 +118,8 @@ public class ShuffleStream extends CloudSolrStream implements Expressible {
}
}
- // zkHost
- expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
+ expression.addParameter(
+ new StreamExpressionNamedParameter("solrConnection", solrConnection.toString()));
// aliases
if (null != fieldMappings && 0 != fieldMappings.size()) {
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/SignificantTermsStream.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/SignificantTermsStream.java
index e362d34c73b..df4ad40ac9a 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/SignificantTermsStream.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/SignificantTermsStream.java
@@ -18,7 +18,6 @@
package org.apache.solr.client.solrj.io.stream;
import static org.apache.solr.client.solrj.io.stream.StreamExecutorHelper.submitAllAndAwaitAggregatingExceptions;
-import static org.apache.solr.common.params.CommonParams.DISTRIB;
import java.io.IOException;
import java.util.ArrayList;
@@ -29,9 +28,11 @@ import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Set;
import java.util.concurrent.Callable;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrRequest;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.SolrClientCache;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.comp.StreamComparator;
@@ -41,12 +42,13 @@ import org.apache.solr.client.solrj.io.stream.expr.StreamExplanation;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionParameter;
-import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionValue;
import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
import org.apache.solr.client.solrj.request.QueryRequest;
+import org.apache.solr.client.solrj.request.SolrQuery;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
/**
@@ -56,9 +58,9 @@ public class SignificantTermsStream extends TupleStream implements Expressible {
private static final long serialVersionUID = 1;
- protected String zkHost;
+ protected CloudSolrClient.CloudSolrClientConnection solrConnection;
protected String collection;
- protected Map<String, String> params;
+ protected SolrParams params;
protected Iterator<Tuple> tupleIterator;
protected String field;
protected int numTerms;
@@ -71,9 +73,9 @@ public class SignificantTermsStream extends TupleStream implements Expressible {
private transient StreamContext streamContext;
public SignificantTermsStream(
- String zkHost,
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
String collectionName,
- Map<String, String> params,
+ SolrParams params,
String field,
float minDocFreq,
float maxDocFreq,
@@ -81,7 +83,15 @@ public class SignificantTermsStream extends TupleStream implements Expressible {
int numTerms)
throws IOException {
- init(collectionName, zkHost, params, field, minDocFreq, maxDocFreq, minTermLength, numTerms);
+ init(
+ solrConnection,
+ collectionName,
+ params,
+ field,
+ minDocFreq,
+ maxDocFreq,
+ minTermLength,
+ numTerms);
}
public SignificantTermsStream(StreamExpression expression, StreamFactory factory)
@@ -89,10 +99,9 @@ public class SignificantTermsStream extends TupleStream implements Expressible {
// grab all parameters out
String collectionName = factory.getValueOperand(expression, 0);
List<StreamExpressionNamedParameter> namedParams = factory.getNamedOperands(expression);
- StreamExpressionNamedParameter zkHostExpression = factory.getNamedOperand(expression, "zkHost");
- // Validate there are no unknown parameters - zkHost and alias are namedParameter, so we don't
- // need to count it twice
+ // Validate there are no unknown parameters - solrConnection/zkHost and alias are
+ // namedParameter, so we don't need to count it twice
if (expression.getParameters().size() != 1 + namedParams.size()) {
throw new IOException(
String.format(Locale.ROOT, "invalid expression %s - unknown operands found", expression));
@@ -116,12 +125,8 @@ public class SignificantTermsStream extends TupleStream implements Expressible {
expression));
}
- Map<String, String> params = new HashMap<>();
- for (StreamExpressionNamedParameter namedParam : namedParams) {
- if (!namedParam.getName().equals("zkHost")) {
- params.put(namedParam.getName(), namedParam.getParameter().toString().trim());
- }
- }
+ ModifiableSolrParams params =
+ buildSolrParamsExcept(namedParams, Set.of("zkHost", "solrConnection"));
String fieldParam = params.get("field");
if (fieldParam != null) {
@@ -158,22 +163,11 @@ public class SignificantTermsStream extends TupleStream implements Expressible {
params.remove("maxDocFreq");
}
- // zkHost, optional - if not provided then will look into factory list to get
- String zkHost = null;
- if (null == zkHostExpression) {
- zkHost = factory.getCollectionZkHost(collectionName);
- } else if (zkHostExpression.getParameter() instanceof StreamExpressionValue) {
- zkHost = ((StreamExpressionValue) zkHostExpression.getParameter()).getValue();
- }
-
- if (zkHost == null) {
- zkHost = factory.getDefaultZkHost();
- }
+ var solrConnection = factory.buildSolrConnection(expression, collectionName);
- // We've got all the required items
init(
+ solrConnection,
collectionName,
- zkHost,
params,
fieldParam,
minDocFreq,
@@ -186,45 +180,29 @@ public class SignificantTermsStream extends TupleStream implements Expressible {
public StreamExpressionParameter toExpression(StreamFactory factory) throws IOException {
// functionName(collectionName, param1, param2, ..., paramN, sort="comp",
// [aliases="field=alias,..."])
-
- // function name
- StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
-
- // collection
- expression.addParameter(collection);
-
- // parameters
- for (Map.Entry<String, String> param : params.entrySet()) {
- expression.addParameter(new StreamExpressionNamedParameter(param.getKey(), param.getValue()));
- }
-
- expression.addParameter(new StreamExpressionNamedParameter("field", field));
- expression.addParameter(
- new StreamExpressionNamedParameter("minDocFreq", Float.toString(minDocFreq)));
- expression.addParameter(
- new StreamExpressionNamedParameter("maxDocFreq", Float.toString(maxDocFreq)));
- expression.addParameter(
- new StreamExpressionNamedParameter("numTerms", String.valueOf(numTerms)));
- expression.addParameter(
- new StreamExpressionNamedParameter("minTermLength", String.valueOf(minTermLength)));
-
- // zkHost
- expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
-
- return expression;
+ return new StreamExpression(factory.getFunctionName(this.getClass()))
+ .withParameter(collection)
+ .withMoreParameters(params)
+ .withParameter(new StreamExpressionNamedParameter("field", field))
+ .withParameter(new StreamExpressionNamedParameter("minDocFreq", Float.toString(minDocFreq)))
+ .withParameter(new StreamExpressionNamedParameter("numTerms", String.valueOf(numTerms)))
+ .withParameter(
+ new StreamExpressionNamedParameter("minTermLength", String.valueOf(minTermLength)))
+ .withParameter(
+ new StreamExpressionNamedParameter("solrConnection", solrConnection.toString()));
}
private void init(
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
String collectionName,
- String zkHost,
- Map<String, String> params,
+ SolrParams params,
String field,
float minDocFreq,
float maxDocFreq,
int minTermLength,
int numTerms)
throws IOException {
- this.zkHost = zkHost;
+ this.solrConnection = solrConnection;
this.collection = collectionName;
this.params = params;
this.field = field;
@@ -303,7 +281,8 @@ public class SignificantTermsStream extends TupleStream implements Expressible {
Map<String, int[]> mergeFreqs = new HashMap<>();
long numDocs = 0;
long resultCount = 0;
- for (NamedList<?> fullResp : callShards(getShards(zkHost, collection, streamContext))) {
+ for (NamedList<?> fullResp :
+ callShards(getShards(solrConnection, collection, streamContext))) {
Map<?, ?> stResp = (Map<?, ?>) fullResp.get("significantTerms");
@SuppressWarnings({"unchecked"})
@@ -382,13 +361,13 @@ public class SignificantTermsStream extends TupleStream implements Expressible {
private final float maxDocFreq;
private final int numTerms;
private final int minTermLength;
- private final Map<String, String> paramsMap;
+ private final SolrParams params;
private final boolean isLocal;
private final SolrClientCache clientCache;
public SignificantTermsCall(
String baseUrl,
- Map<String, String> paramsMap,
+ SolrParams params,
String field,
float minDocFreq,
float maxDocFreq,
@@ -401,7 +380,7 @@ public class SignificantTermsStream extends TupleStream implements Expressible {
this.field = field;
this.minDocFreq = minDocFreq;
this.maxDocFreq = maxDocFreq;
- this.paramsMap = paramsMap;
+ this.params = params;
this.numTerms = numTerms;
this.minTermLength = minTermLength;
this.isLocal = isLocal;
@@ -410,29 +389,27 @@ public class SignificantTermsStream extends TupleStream implements Expressible {
@Override
public NamedList<?> call() throws Exception {
- ModifiableSolrParams params = new ModifiableSolrParams();
+ SolrQuery queryRequestParams = new SolrQuery();
SolrClient solrClient = clientCache.getHttpSolrClient(baseUrl);
- params.add(DISTRIB, "false");
- params.add("fq", "{!significantTerms}");
+ queryRequestParams.setDistrib(false);
+ queryRequestParams.setFilterQueries("{!significantTerms}");
- for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
- params.add(entry.getKey(), entry.getValue());
- }
+ queryRequestParams.add(params);
- params.add("minDocFreq", Float.toString(minDocFreq));
- params.add("maxDocFreq", Float.toString(maxDocFreq));
- params.add("minTermLength", Integer.toString(minTermLength));
- params.add("field", field);
- params.add("numTerms", String.valueOf(numTerms * 5));
+ queryRequestParams.add("minDocFreq", Float.toString(minDocFreq));
+ queryRequestParams.add("maxDocFreq", Float.toString(maxDocFreq));
+ queryRequestParams.add("minTermLength", Integer.toString(minTermLength));
+ queryRequestParams.add("field", field);
+ queryRequestParams.add("numTerms", String.valueOf(numTerms * 5));
if (isLocal) {
- params.add("distrib", "false");
+ // TODO: 'distrib' is never true. 'isLocal' doesn't matter. It is correctly?
+ queryRequestParams.setDistrib(false);
}
- QueryRequest request = new QueryRequest(params, SolrRequest.METHOD.POST);
+ QueryRequest request = new QueryRequest(queryRequestParams, SolrRequest.METHOD.POST);
QueryResponse response = request.process(solrClient);
- NamedList<?> res = response.getResponse();
- return res;
+ return response.getResponse();
}
}
}
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/SqlStream.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/SqlStream.java
index 24560cb61ae..8b5ad3bf306 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/SqlStream.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/SqlStream.java
@@ -23,7 +23,9 @@ import java.util.List;
import java.util.Locale;
import java.util.Map.Entry;
import java.util.Random;
+import java.util.Set;
import java.util.stream.Collectors;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.comp.StreamComparator;
import org.apache.solr.client.solrj.io.stream.expr.Explanation;
@@ -32,7 +34,6 @@ import org.apache.solr.client.solrj.io.stream.expr.Expressible;
import org.apache.solr.client.solrj.io.stream.expr.StreamExplanation;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter;
-import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionValue;
import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams;
@@ -45,31 +46,34 @@ public class SqlStream extends TupleStream implements Expressible {
private static final long serialVersionUID = 1;
- protected String zkHost;
+ protected CloudSolrClient.CloudSolrClientConnection solrConnection;
protected String collection;
protected SolrParams params;
protected transient TupleStream tupleStream;
protected transient StreamContext streamContext;
/**
- * @param zkHost Zookeeper ensemble connection string
+ * @param solrConnection Zookeeper or HTTPS(s) ensemble connection string
* @param collectionName Name of the collection to operate on
* @param params Map&lt;String, String&gt; of parameter/value pairs
* @throws IOException Something went wrong
* <p>This form does not allow specifying multiple clauses, say "fq" clauses, use the form
* that takes a SolrParams. Transition code can call the preferred method that takes
- * SolrParams by calling CloudSolrStream(zkHost, collectionName, new
+ * SolrParams by calling CloudSolrStream(solrConnection, collectionName, new
* ModifiableSolrParams(SolrParams.toMultiMap(new NamedList(Map&lt;String, String&gt;)));
*/
- public SqlStream(String zkHost, String collectionName, SolrParams params) throws IOException {
- init(collectionName, zkHost, params);
+ public SqlStream(
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
+ String collectionName,
+ SolrParams params)
+ throws IOException {
+ init(solrConnection, collectionName, params);
}
public SqlStream(StreamExpression expression, StreamFactory factory) throws IOException {
// grab all parameters out
String collectionName = factory.getValueOperand(expression, 0);
List<StreamExpressionNamedParameter> namedParams = factory.getNamedOperands(expression);
- StreamExpressionNamedParameter zkHostExpression = factory.getNamedOperand(expression, "zkHost");
// Collection Name
if (null == collectionName) {
@@ -85,31 +89,12 @@ public class SqlStream extends TupleStream implements Expressible {
expression));
}
- ModifiableSolrParams mParams = new ModifiableSolrParams();
- for (StreamExpressionNamedParameter namedParam : namedParams) {
- if (!namedParam.getName().equals("zkHost") && !namedParam.getName().equals("aliases")) {
- mParams.add(namedParam.getName(), namedParam.getParameter().toString().trim());
- }
- }
+ ModifiableSolrParams mParams =
+ buildSolrParamsExcept(namedParams, Set.of("zkHost", "solrConnection", "aliases"));
- // zkHost, optional - if not provided then will look into factory list to get
- String zkHost = null;
- if (null == zkHostExpression) {
- zkHost = factory.getCollectionZkHost(collectionName);
- if (zkHost == null) {
- zkHost = factory.getDefaultZkHost();
- }
- } else if (zkHostExpression.getParameter() instanceof StreamExpressionValue) {
- zkHost = ((StreamExpressionValue) zkHostExpression.getParameter()).getValue();
- }
- /*
- if(null == zkHost){
- throw new IOException(String.format(Locale.ROOT,"invalid expression %s - zkHost not found for collection '%s'",expression,collectionName));
- }
- */
+ var solrConnection = factory.buildSolrConnection(expression, collectionName);
- // We've got all the required items
- init(collectionName, zkHost, mParams);
+ init(solrConnection, collectionName, mParams);
}
@Override
@@ -136,8 +121,8 @@ public class SqlStream extends TupleStream implements Expressible {
expression.addParameter(new StreamExpressionNamedParameter(param.getKey(), value));
}
- // zkHost
- expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
+ expression.addParameter(
+ new StreamExpressionNamedParameter("solrConnection", solrConnection.toString()));
return expression;
}
@@ -173,8 +158,12 @@ public class SqlStream extends TupleStream implements Expressible {
return explanation;
}
- protected void init(String collectionName, String zkHost, SolrParams params) throws IOException {
- this.zkHost = zkHost;
+ protected void init(
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
+ String collectionName,
+ SolrParams params)
+ throws IOException {
+ this.solrConnection = solrConnection;
this.collection = collectionName;
this.params = new ModifiableSolrParams(params);
@@ -202,7 +191,7 @@ public class SqlStream extends TupleStream implements Expressible {
protected void constructStream() throws IOException {
try {
- List<String> shardUrls = getShards(this.zkHost, this.collection, this.streamContext);
+ List<String> shardUrls = getShards(this.solrConnection, this.collection, this.streamContext);
Collections.shuffle(shardUrls, new Random());
String url = shardUrls.get(0);
ModifiableSolrParams mParams = new ModifiableSolrParams(params);
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/StatsStream.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/StatsStream.java
index 507dc3820fd..cbdd62b0139 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/StatsStream.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/StatsStream.java
@@ -27,9 +27,11 @@ import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
+import java.util.Set;
import java.util.stream.Collectors;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrRequest;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.ClusterStateProvider;
import org.apache.solr.client.solrj.io.SolrClientCache;
import org.apache.solr.client.solrj.io.Tuple;
@@ -41,7 +43,6 @@ import org.apache.solr.client.solrj.io.stream.expr.StreamExplanation;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionParameter;
-import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionValue;
import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
import org.apache.solr.client.solrj.io.stream.metrics.Bucket;
import org.apache.solr.client.solrj.io.stream.metrics.CountMetric;
@@ -65,7 +66,7 @@ public class StatsStream extends TupleStream implements Expressible, ParallelMet
private Metric[] metrics;
private Tuple tuple;
private int index;
- private String zkHost;
+ private CloudSolrClient.CloudSolrClientConnection solrConnection;
private SolrParams params;
private String collection;
@@ -74,9 +75,13 @@ public class StatsStream extends TupleStream implements Expressible, ParallelMet
private transient StreamContext context;
protected transient TupleStream parallelizedStream;
- public StatsStream(String zkHost, String collection, SolrParams params, Metric[] metrics)
+ public StatsStream(
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
+ String collection,
+ SolrParams params,
+ Metric[] metrics)
throws IOException {
- init(collection, params, metrics, zkHost);
+ init(solrConnection, collection, params, metrics);
}
public StatsStream(StreamExpression expression, StreamFactory factory) throws IOException {
@@ -89,7 +94,6 @@ public class StatsStream extends TupleStream implements Expressible, ParallelMet
List<StreamExpressionNamedParameter> namedParams = factory.getNamedOperands(expression);
- StreamExpressionNamedParameter zkHostExpression = factory.getNamedOperand(expression, "zkHost");
List<StreamExpression> metricExpressions =
factory.getExpressionOperandsRepresentingTypes(expression, Expressible.class, Metric.class);
@@ -115,39 +119,28 @@ public class StatsStream extends TupleStream implements Expressible, ParallelMet
}
// pull out known named params
- ModifiableSolrParams params = new ModifiableSolrParams();
- for (StreamExpressionNamedParameter namedParam : namedParams) {
- if (!namedParam.getName().equals("zkHost")) {
- params.add(namedParam.getName(), namedParam.getParameter().toString().trim());
- }
- }
-
+ ModifiableSolrParams params =
+ buildSolrParamsExcept(namedParams, Set.of("zkHost", "solrConnection"));
if (params.get("q") == null) {
params.set("q", "*:*");
}
- // zkHost, optional - if not provided then will look into factory list to get
- String zkHost = null;
- if (null == zkHostExpression) {
- zkHost = factory.getCollectionZkHost(collectionName);
- if (zkHost == null) {
- zkHost = factory.getDefaultZkHost();
- }
- } else if (zkHostExpression.getParameter() instanceof StreamExpressionValue) {
- zkHost = ((StreamExpressionValue) zkHostExpression.getParameter()).getValue();
- }
+ var solrConnection = factory.buildSolrConnection(expression, collectionName);
- // We've got all the required items
- init(collectionName, params, metrics, zkHost);
+ init(solrConnection, collectionName, params, metrics);
}
public String getCollection() {
return this.collection;
}
- private void init(String collection, SolrParams params, Metric[] metrics, String zkHost)
+ private void init(
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
+ String collection,
+ SolrParams params,
+ Metric[] metrics)
throws IOException {
- this.zkHost = zkHost;
+ this.solrConnection = solrConnection;
this.collection = collection;
this.metrics = metrics;
this.params = params;
@@ -177,8 +170,8 @@ public class StatsStream extends TupleStream implements Expressible, ParallelMet
expression.addParameter(metric.toExpression(factory));
}
- // zkHost
- expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
+ expression.addParameter(
+ new StreamExpressionNamedParameter("solrConnection", solrConnection.toString()));
return expression;
}
@@ -239,7 +232,7 @@ public class StatsStream extends TupleStream implements Expressible, ParallelMet
// Parallelize the stats stream across multiple collections for an alias using plist if possible
if (shardsMap == null && params.getBool(TIERED_PARAM, defaultTieredEnabled)) {
ClusterStateProvider clusterStateProvider =
- clientCache.getCloudSolrClient(zkHost).getClusterStateProvider();
+ clientCache.getCloudSolrClient(solrConnection).getClusterStateProvider();
final List<String> resolved =
clusterStateProvider != null ? clusterStateProvider.resolveAlias(collection) : null;
if (resolved != null && resolved.size() > 1) {
@@ -261,7 +254,7 @@ public class StatsStream extends TupleStream implements Expressible, ParallelMet
if (shardsMap == null) {
QueryRequest request = new QueryRequest(paramsLoc, SolrRequest.METHOD.POST);
- var cloudSolrClient = clientCache.getCloudSolrClient(zkHost);
+ var cloudSolrClient = clientCache.getCloudSolrClient(solrConnection);
try {
NamedList<?> response = cloudSolrClient.request(request, collection);
getTuples(response, metrics);
@@ -415,7 +408,7 @@ public class StatsStream extends TupleStream implements Expressible, ParallelMet
TupleStream[] streams = new TupleStream[partitions.size()];
for (int p = 0; p < streams.length; p++) {
- streams[p] = new StatsStream(zkHost, partitions.get(p), withoutTieredParam, metrics);
+ streams[p] = new StatsStream(solrConnection, partitions.get(p), withoutTieredParam, metrics);
}
return streams;
}
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/TextLogitStream.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/TextLogitStream.java
index bd6bce7c31b..5708ec3fa5e 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/TextLogitStream.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/TextLogitStream.java
@@ -30,12 +30,12 @@ import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.Callable;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrRequest;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.ClassificationEvaluation;
import org.apache.solr.client.solrj.io.SolrClientCache;
import org.apache.solr.client.solrj.io.Tuple;
@@ -46,13 +46,13 @@ import org.apache.solr.client.solrj.io.stream.expr.StreamExplanation;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionParameter;
-import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionValue;
import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.cloud.Replica;
import org.apache.solr.common.cloud.Slice;
import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
/**
@@ -62,9 +62,9 @@ public class TextLogitStream extends TupleStream implements Expressible {
private static final long serialVersionUID = 1;
- protected String zkHost;
+ protected CloudSolrClient.CloudSolrClientConnection solrConnection;
protected String collection;
- protected Map<String, String> params;
+ protected SolrParams params;
protected String field;
protected String name;
protected String outcome;
@@ -88,9 +88,9 @@ public class TextLogitStream extends TupleStream implements Expressible {
private double lastError = 0;
public TextLogitStream(
- String zkHost,
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
String collectionName,
- Map<String, String> params,
+ SolrParams params,
String name,
String field,
TupleStream termsStream,
@@ -102,8 +102,8 @@ public class TextLogitStream extends TupleStream implements Expressible {
throws IOException {
init(
+ solrConnection,
collectionName,
- zkHost,
params,
name,
field,
@@ -116,18 +116,20 @@ public class TextLogitStream extends TupleStream implements Expressible {
iteration);
}
- /** logit(collection, zkHost="", features="a,b,c,d,e,f,g", outcome="y", maxIteration="20") */
+ /**
+ * logit(collection, solrConnection="", features="a,b,c,d,e,f,g", outcome="y", maxIteration="20")
+ */
public TextLogitStream(StreamExpression expression, StreamFactory factory) throws IOException {
// grab all parameters out
String collectionName = factory.getValueOperand(expression, 0);
List<StreamExpressionNamedParameter> namedParams = factory.getNamedOperands(expression);
- StreamExpressionNamedParameter zkHostExpression = factory.getNamedOperand(expression, "zkHost");
List<StreamExpression> streamExpressions =
factory.getExpressionOperandsRepresentingTypes(
expression, Expressible.class, TupleStream.class);
- // Validate there are no unknown parameters - zkHost and alias are namedParameter, so we don't
- // need to count it twice
+ // Validate there are no unknown parameters - solrConnection/zkHost and alias are
+ // namedParameter,
+ // so we don't need to count it twice
if (expression.getParameters().size() != 1 + namedParams.size() + streamExpressions.size()) {
throw new IOException(
String.format(Locale.ROOT, "invalid expression %s - unknown operands found", expression));
@@ -151,12 +153,8 @@ public class TextLogitStream extends TupleStream implements Expressible {
expression));
}
- Map<String, String> params = new HashMap<>();
- for (StreamExpressionNamedParameter namedParam : namedParams) {
- if (!namedParam.getName().equals("zkHost")) {
- params.put(namedParam.getName(), namedParam.getParameter().toString().trim());
- }
- }
+ ModifiableSolrParams params =
+ buildSolrParamsExcept(namedParams, Set.of("solrConnection", "zkHost"));
String name = params.get("name");
if (name != null) {
@@ -229,26 +227,11 @@ public class TextLogitStream extends TupleStream implements Expressible {
params.remove("weights");
}
- // zkHost, optional - if not provided then will look into factory list to get
- String zkHost = null;
- if (null == zkHostExpression) {
- zkHost = factory.getCollectionZkHost(collectionName);
- } else if (zkHostExpression.getParameter() instanceof StreamExpressionValue) {
- zkHost = ((StreamExpressionValue) zkHostExpression.getParameter()).getValue();
- }
- if (null == zkHost) {
- throw new IOException(
- String.format(
- Locale.ROOT,
- "invalid expression %s - zkHost not found for collection '%s'",
- expression,
- collectionName));
- }
+ var solrConnection = factory.buildSolrConnection(expression, collectionName);
- // We've got all the required items
init(
+ solrConnection,
collectionName,
- zkHost,
params,
name,
feature,
@@ -284,9 +267,7 @@ public class TextLogitStream extends TupleStream implements Expressible {
}
// parameters
- for (Entry<String, String> param : params.entrySet()) {
- expression.addParameter(new StreamExpressionNamedParameter(param.getKey(), param.getValue()));
- }
+ expression.withMoreParameters(params);
expression.addParameter(new StreamExpressionNamedParameter("field", field));
expression.addParameter(new StreamExpressionNamedParameter("name", name));
@@ -312,16 +293,16 @@ public class TextLogitStream extends TupleStream implements Expressible {
expression.addParameter(
new StreamExpressionNamedParameter("threshold", Double.toString(threshold)));
- // zkHost
- expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
+ expression.addParameter(
+ new StreamExpressionNamedParameter("solrConnection", solrConnection.toString()));
return expression;
}
private void init(
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
String collectionName,
- String zkHost,
- Map<String, String> params,
+ SolrParams params,
String name,
String feature,
TupleStream termsStream,
@@ -332,7 +313,7 @@ public class TextLogitStream extends TupleStream implements Expressible {
int maxIterations,
int iteration)
throws IOException {
- this.zkHost = zkHost;
+ this.solrConnection = solrConnection;
this.collection = collectionName;
this.params = params;
this.name = name;
@@ -373,7 +354,7 @@ public class TextLogitStream extends TupleStream implements Expressible {
protected List<String> getShardUrls() throws IOException {
try {
- var cloudSolrClient = clientCache.getCloudSolrClient(zkHost);
+ var cloudSolrClient = clientCache.getCloudSolrClient(solrConnection);
List<Slice> slices = CloudSolrStream.getSlices(this.collection, cloudSolrClient, false);
Set<String> liveNodes = cloudSolrClient.getClusterState().getLiveNodes();
@@ -634,14 +615,14 @@ public class TextLogitStream extends TupleStream implements Expressible {
private String outcome;
private int positiveLabel;
private double learningRate;
- private Map<String, String> paramsMap;
+ private SolrParams params;
private double threshold;
private List<Double> idfs;
private SolrClientCache clientCache;
public LogitCall(
String baseUrl,
- Map<String, String> paramsMap,
+ SolrParams params,
String feature,
List<String> terms,
List<Double> weights,
@@ -661,7 +642,7 @@ public class TextLogitStream extends TupleStream implements Expressible {
this.outcome = outcome;
this.positiveLabel = positiveLabel;
this.learningRate = learningRate;
- this.paramsMap = paramsMap;
+ this.params = params;
this.threshold = threshold;
this.idfs = idfs;
this.clientCache = clientCache;
@@ -669,30 +650,28 @@ public class TextLogitStream extends TupleStream implements Expressible {
@Override
public Tuple call() throws Exception {
- ModifiableSolrParams params = new ModifiableSolrParams();
+ ModifiableSolrParams queryRequestParams = new ModifiableSolrParams();
SolrClient solrClient = clientCache.getHttpSolrClient(baseUrl);
- params.add(DISTRIB, "false");
- params.add("fq", "{!tlogit}");
- params.add("feature", feature);
- params.add("terms", TextLogitStream.toString(terms));
- params.add("idfs", TextLogitStream.toString(idfs));
+ queryRequestParams.add(DISTRIB, "false");
+ queryRequestParams.add("fq", "{!tlogit}");
+ queryRequestParams.add("feature", feature);
+ queryRequestParams.add("terms", TextLogitStream.toString(terms));
+ queryRequestParams.add("idfs", TextLogitStream.toString(idfs));
- for (Entry<String, String> entry : paramsMap.entrySet()) {
- params.add(entry.getKey(), entry.getValue());
- }
+ queryRequestParams.add(params);
if (weights != null) {
- params.add("weights", TextLogitStream.toString(weights));
+ queryRequestParams.add("weights", TextLogitStream.toString(weights));
}
- params.add("iteration", Integer.toString(iteration));
- params.add("outcome", outcome);
- params.add("positiveLabel", Integer.toString(positiveLabel));
- params.add("threshold", Double.toString(threshold));
- params.add("alpha", Double.toString(learningRate));
+ queryRequestParams.add("iteration", Integer.toString(iteration));
+ queryRequestParams.add("outcome", outcome);
+ queryRequestParams.add("positiveLabel", Integer.toString(positiveLabel));
+ queryRequestParams.add("threshold", Double.toString(threshold));
+ queryRequestParams.add("alpha", Double.toString(learningRate));
- QueryRequest request = new QueryRequest(params, SolrRequest.METHOD.POST);
+ QueryRequest request = new QueryRequest(queryRequestParams, SolrRequest.METHOD.POST);
QueryResponse response = request.process(solrClient);
NamedList<?> res = response.getResponse();
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/TimeSeriesStream.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/TimeSeriesStream.java
index 2218e4577aa..4e64d742fe6 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/TimeSeriesStream.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/TimeSeriesStream.java
@@ -26,8 +26,10 @@ import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map.Entry;
+import java.util.Set;
import java.util.stream.Collectors;
import org.apache.solr.client.solrj.SolrRequest;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.SolrClientCache;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.comp.StreamComparator;
@@ -66,14 +68,14 @@ public class TimeSeriesStream extends TupleStream implements Expressible {
private Metric[] metrics;
private List<Tuple> tuples = new ArrayList<>();
private int index;
- private String zkHost;
+ private CloudSolrClient.CloudSolrClientConnection solrConnection;
private SolrParams params;
private String collection;
private transient SolrClientCache clientCache;
private transient boolean doCloseCache;
public TimeSeriesStream(
- String zkHost,
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
String collection,
SolrParams params,
Metric[] metrics,
@@ -83,7 +85,7 @@ public class TimeSeriesStream extends TupleStream implements Expressible {
String gap,
String format)
throws IOException {
- init(collection, params, field, metrics, start, end, gap, format, null, null, zkHost);
+ init(solrConnection, collection, params, field, metrics, start, end, gap, format, null, null);
}
public TimeSeriesStream(StreamExpression expression, StreamFactory factory) throws IOException {
@@ -103,7 +105,6 @@ public class TimeSeriesStream extends TupleStream implements Expressible {
StreamExpressionNamedParameter splitExpression = factory.getNamedOperand(expression, "split");
StreamExpressionNamedParameter limitExpression = factory.getNamedOperand(expression, "limit");
- StreamExpressionNamedParameter zkHostExpression = factory.getNamedOperand(expression, "zkHost");
List<StreamExpression> metricExpressions =
factory.getExpressionOperandsRepresentingTypes(expression, Expressible.class, Metric.class);
@@ -195,41 +196,27 @@ public class TimeSeriesStream extends TupleStream implements Expressible {
}
// pull out known named params
- ModifiableSolrParams params = new ModifiableSolrParams();
- for (StreamExpressionNamedParameter namedParam : namedParams) {
- if (!namedParam.getName().equals("zkHost")
- && !namedParam.getName().equals("start")
- && !namedParam.getName().equals("end")
- && !namedParam.getName().equals("gap")) {
- params.add(namedParam.getName(), namedParam.getParameter().toString().trim());
- }
- }
-
+ ModifiableSolrParams params =
+ buildSolrParamsExcept(
+ namedParams, Set.of("zkHost", "solrConnection", "start", "end", "gap"));
if (params.get("q") == null) {
params.set("q", "*:*");
}
- // zkHost, optional - if not provided then will look into factory list to get
- String zkHost = null;
- if (null == zkHostExpression) {
- zkHost = factory.getCollectionZkHost(collectionName);
- if (zkHost == null) {
- zkHost = factory.getDefaultZkHost();
- }
- } else if (zkHostExpression.getParameter() instanceof StreamExpressionValue) {
- zkHost = ((StreamExpressionValue) zkHostExpression.getParameter()).getValue();
- }
- if (null == zkHost) {
- throw new IOException(
- String.format(
- Locale.ROOT,
- "invalid expression %s - zkHost not found for collection '%s'",
- expression,
- collectionName));
- }
-
- // We've got all the required items
- init(collectionName, params, field, metrics, start, end, gap, format, split, limit, zkHost);
+ var solrConnection = factory.buildSolrConnection(expression, collectionName);
+
+ init(
+ solrConnection,
+ collectionName,
+ params,
+ field,
+ metrics,
+ start,
+ end,
+ gap,
+ format,
+ split,
+ limit);
}
public String getCollection() {
@@ -237,6 +224,7 @@ public class TimeSeriesStream extends TupleStream implements Expressible {
}
private void init(
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
String collection,
SolrParams params,
String field,
@@ -246,10 +234,9 @@ public class TimeSeriesStream extends TupleStream implements Expressible {
String gap,
String format,
String split,
- String limit,
- String zkHost)
+ String limit)
throws IOException {
- this.zkHost = zkHost;
+ this.solrConnection = solrConnection;
this.collection = collection;
this.start = start;
this.gap = gap;
@@ -298,8 +285,8 @@ public class TimeSeriesStream extends TupleStream implements Expressible {
expression.addParameter(new StreamExpressionNamedParameter("field", gap));
expression.addParameter(new StreamExpressionNamedParameter("format", format));
- // zkHost
- expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
+ expression.addParameter(
+ new StreamExpressionNamedParameter("solrConnection", solrConnection.toString()));
return expression;
}
@@ -361,7 +348,7 @@ public class TimeSeriesStream extends TupleStream implements Expressible {
QueryRequest request = new QueryRequest(paramsLoc, SolrRequest.METHOD.POST);
try {
- var cloudSolrClient = clientCache.getCloudSolrClient(zkHost);
+ var cloudSolrClient = clientCache.getCloudSolrClient(solrConnection);
NamedList<?> response = cloudSolrClient.request(request, collection);
getTuples(response, field, metrics);
} catch (Exception e) {
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/TopicStream.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/TopicStream.java
index 0d2e4a46d1b..797e80a91c3 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/TopicStream.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/TopicStream.java
@@ -40,6 +40,7 @@ import java.util.TreeSet;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;
import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.SolrClientCache;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.comp.ComparatorOrder;
@@ -80,25 +81,32 @@ public class TopicStream extends CloudSolrStream implements Expressible {
private transient boolean doCloseCache;
public TopicStream(
- String zkHost,
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
String checkpointCollection,
String collection,
String id,
long initialCheckpoint,
long checkpointEvery,
SolrParams params) {
- init(zkHost, checkpointCollection, collection, id, initialCheckpoint, checkpointEvery, params);
+ init(
+ solrConnection,
+ checkpointCollection,
+ collection,
+ id,
+ initialCheckpoint,
+ checkpointEvery,
+ params);
}
private void init(
- String zkHost,
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
String checkpointCollection,
String collection,
String id,
long initialCheckpoint,
long checkpointEvery,
SolrParams params) {
- this.zkHost = zkHost;
+ this.solrConnection = solrConnection;
ModifiableSolrParams mParams = new ModifiableSolrParams(params);
if (mParams.getParams("rows") == null) {
@@ -119,7 +127,6 @@ public class TopicStream extends CloudSolrStream implements Expressible {
String checkpointCollectionName = factory.getValueOperand(expression, 0);
String collectionName = factory.getValueOperand(expression, 1);
List<StreamExpressionNamedParameter> namedParams = factory.getNamedOperands(expression);
- StreamExpressionNamedParameter zkHostExpression = factory.getNamedOperand(expression, "zkHost");
StreamExpressionNamedParameter idParam = factory.getNamedOperand(expression, ID);
if (null == idParam) {
@@ -178,37 +185,14 @@ public class TopicStream extends CloudSolrStream implements Expressible {
expression));
}
- ModifiableSolrParams params = new ModifiableSolrParams();
- for (StreamExpressionNamedParameter namedParam : namedParams) {
- if (!namedParam.getName().equals("zkHost")
- && !namedParam.getName().equals(ID)
- && !namedParam.getName().equals("checkpointEvery")) {
- params.set(namedParam.getName(), namedParam.getParameter().toString().trim());
- }
- }
+ ModifiableSolrParams params =
+ buildSolrParamsExcept(
+ namedParams, Set.of("zkHost", "solrConnection", ID, "checkpointEvery"));
- // zkHost, optional - if not provided then will look into factory list to get
- String zkHost = null;
- if (null == zkHostExpression) {
- zkHost = factory.getCollectionZkHost(collectionName);
- if (zkHost == null) {
- zkHost = factory.getDefaultZkHost();
- }
- } else if (zkHostExpression.getParameter() instanceof StreamExpressionValue) {
- zkHost = ((StreamExpressionValue) zkHostExpression.getParameter()).getValue();
- }
- if (null == zkHost) {
- throw new IOException(
- String.format(
- Locale.ROOT,
- "invalid expression %s - zkHost not found for collection '%s'",
- expression,
- collectionName));
- }
+ var solrConnection = factory.buildSolrConnection(expression, collectionName);
- // We've got all the required items
init(
- zkHost,
+ solrConnection,
checkpointCollectionName,
collectionName,
((StreamExpressionValue) idParam.getParameter()).getValue(),
@@ -238,8 +222,8 @@ public class TopicStream extends CloudSolrStream implements Expressible {
expression.addParameter(new StreamExpressionNamedParameter(param.getKey(), value));
}
- // zkHost
- expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
+ expression.addParameter(
+ new StreamExpressionNamedParameter("solrConnection", solrConnection.toString()));
expression.addParameter(new StreamExpressionNamedParameter(ID, id));
if (initialCheckpoint > -1) {
expression.addParameter(
@@ -407,7 +391,7 @@ public class TopicStream extends CloudSolrStream implements Expressible {
}
private void getCheckpoints() throws IOException {
- var cloudSolrClient = clientCache.getCloudSolrClient(zkHost);
+ var cloudSolrClient = clientCache.getCloudSolrClient(solrConnection);
this.checkpoints = new HashMap<>();
List<Slice> slices = CloudSolrStream.getSlices(this.collection, cloudSolrClient, false);
Set<String> liveNodes = cloudSolrClient.getClusterState().getLiveNodes();
@@ -469,7 +453,7 @@ public class TopicStream extends CloudSolrStream implements Expressible {
return;
}
- var cloudSolrClient = clientCache.getCloudSolrClient(zkHost);
+ var cloudSolrClient = clientCache.getCloudSolrClient(solrConnection);
UpdateRequest request = new UpdateRequest();
request.setParam("collection", checkpointCollection);
SolrInputDocument doc = new SolrInputDocument();
@@ -488,7 +472,7 @@ public class TopicStream extends CloudSolrStream implements Expressible {
}
private void getPersistedCheckpoints() throws IOException {
- var cloudSolrClient = clientCache.getCloudSolrClient(zkHost);
+ var cloudSolrClient = clientCache.getCloudSolrClient(solrConnection);
List<Slice> slices = CloudSolrStream.getSlices(checkpointCollection, cloudSolrClient, false);
Set<String> liveNodes = cloudSolrClient.getClusterState().getLiveNodes();
@@ -522,7 +506,7 @@ public class TopicStream extends CloudSolrStream implements Expressible {
@Override
protected void constructStreams() throws IOException {
- var cloudSolrClient = clientCache.getCloudSolrClient(zkHost);
+ var cloudSolrClient = clientCache.getCloudSolrClient(solrConnection);
List<Slice> slices = CloudSolrStream.getSlices(this.collection, cloudSolrClient, false);
ModifiableSolrParams mParams = new ModifiableSolrParams(params);
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/TupleStream.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/TupleStream.java
index 78398713e74..3dc3ceb6f78 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/TupleStream.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/TupleStream.java
@@ -32,6 +32,7 @@ import org.apache.solr.client.solrj.io.SolrClientCache;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.comp.StreamComparator;
import org.apache.solr.client.solrj.io.stream.expr.Explanation;
+import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter;
import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
import org.apache.solr.client.solrj.routing.ReplicaListTransformer;
import org.apache.solr.client.solrj.routing.RequestReplicaListTransformerGenerator;
@@ -119,18 +120,24 @@ public abstract class TupleStream implements Closeable, Serializable, MapWriter
}
public static List<String> getShards(
- String zkHost, String collection, StreamContext streamContext) throws IOException {
- return getShards(zkHost, collection, streamContext, new ModifiableSolrParams());
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
+ String collection,
+ StreamContext streamContext)
+ throws IOException {
+ return getShards(solrConnection, collection, streamContext, new ModifiableSolrParams());
}
static List<Replica> getReplicas(
- String zkHost, String collection, StreamContext streamContext, SolrParams requestParams)
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
+ String collection,
+ StreamContext streamContext,
+ SolrParams requestParams)
throws IOException {
- if (zkHost == null) {
+ if (solrConnection == null) {
throw new IOException(
String.format(
Locale.ROOT,
- "invalid expression - zkHost not found for collection '%s'",
+ "invalid expression - solrConnection or zkHost not found for collection '%s'",
collection));
}
@@ -149,7 +156,7 @@ public abstract class TupleStream implements Closeable, Serializable, MapWriter
}
try {
- CloudSolrClient cloudSolrClient = solrClientCache.getCloudSolrClient(zkHost);
+ CloudSolrClient cloudSolrClient = solrClientCache.getCloudSolrClient(solrConnection);
ClusterState clusterState = cloudSolrClient.getClusterStateProvider().getClusterState();
List<Slice> slices = CloudSolrStream.getSlices(collection, cloudSolrClient, true);
Set<String> liveNodes = clusterState.getLiveNodes();
@@ -197,7 +204,10 @@ public abstract class TupleStream implements Closeable, Serializable, MapWriter
}
public static List<String> getShards(
- String zkHost, String collection, StreamContext streamContext, SolrParams requestParams)
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
+ String collection,
+ StreamContext streamContext,
+ SolrParams requestParams)
throws IOException {
List<String> shards;
@@ -213,7 +223,7 @@ public abstract class TupleStream implements Closeable, Serializable, MapWriter
}
} else {
shards =
- getReplicas(zkHost, collection, streamContext, requestParams).stream()
+ getReplicas(solrConnection, collection, streamContext, requestParams).stream()
.map(Replica::getCoreUrl)
.collect(Collectors.toList());
}
@@ -221,6 +231,19 @@ public abstract class TupleStream implements Closeable, Serializable, MapWriter
return shards;
}
+ public static ModifiableSolrParams buildSolrParamsExcept(
+ List<StreamExpressionNamedParameter> namedParams, Set<String> excluded) {
+ ModifiableSolrParams mParams = new ModifiableSolrParams();
+
+ for (StreamExpressionNamedParameter namedParam : namedParams) {
+ if (!excluded.contains(namedParam.getName())) {
+ mParams.add(namedParam.getName(), namedParam.getParameter().toString().trim());
+ }
+ }
+
+ return mParams;
+ }
+
public static class IgnoreException extends IOException {
@Override
public void printStackTrace(PrintWriter pw) {
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/UpdateStream.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/UpdateStream.java
index 7d10407ee68..08e062cf365 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/UpdateStream.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/UpdateStream.java
@@ -22,6 +22,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.SolrClientCache;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.comp.StreamComparator;
@@ -49,7 +50,7 @@ public class UpdateStream extends TupleStream implements Expressible {
// field name in summary tuple for #docs updated in batch
public static String BATCH_INDEXED_FIELD_NAME = "batchIndexed";
private String collection;
- protected String zkHost;
+ protected CloudSolrClient.CloudSolrClientConnection solrConnection;
private int updateBatchSize;
/**
@@ -72,8 +73,7 @@ public class UpdateStream extends TupleStream implements Expressible {
String collectionName = factory.getValueOperand(expression, 0);
verifyCollectionName(collectionName, expression);
- String zkHost = findZkHost(factory, collectionName, expression);
- verifyZkHost(zkHost, collectionName, expression);
+ var solrConnection = factory.buildSolrConnection(expression, collectionName);
int updateBatchSize = extractBatchSize(expression, factory);
pruneVersionField =
@@ -92,24 +92,34 @@ public class UpdateStream extends TupleStream implements Expressible {
streamExpressions.size()));
}
StreamExpression sourceStreamExpression = streamExpressions.get(0);
- init(collectionName, factory.constructStream(sourceStreamExpression), zkHost, updateBatchSize);
+ init(
+ solrConnection,
+ collectionName,
+ factory.constructStream(sourceStreamExpression),
+ updateBatchSize);
}
public UpdateStream(
- String collectionName, TupleStream tupleSource, String zkHost, int updateBatchSize)
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
+ String collectionName,
+ TupleStream tupleSource,
+ int updateBatchSize)
throws IOException {
if (updateBatchSize <= 0) {
throw new IOException(
String.format(Locale.ROOT, "batchSize '%d' must be greater than 0.", updateBatchSize));
}
pruneVersionField = defaultPruneVersionField();
- init(collectionName, tupleSource, zkHost, updateBatchSize);
+ init(solrConnection, collectionName, tupleSource, updateBatchSize);
}
private void init(
- String collectionName, TupleStream tupleSource, String zkHost, int updateBatchSize) {
+ CloudSolrClient.CloudSolrClientConnection solrConnection,
+ String collectionName,
+ TupleStream tupleSource,
+ int updateBatchSize) {
this.collection = collectionName;
- this.zkHost = zkHost;
+ this.solrConnection = solrConnection;
this.updateBatchSize = updateBatchSize;
this.tupleSource = new PushBackStream(tupleSource);
}
@@ -184,7 +194,8 @@ public class UpdateStream extends TupleStream implements Expressible {
throws IOException {
StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
expression.addParameter(collection);
- expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
+ expression.addParameter(
+ new StreamExpressionNamedParameter("solrConnection", solrConnection.toString()));
expression.addParameter(
new StreamExpressionNamedParameter("batchSize", Integer.toString(updateBatchSize)));
@@ -246,35 +257,6 @@ public class UpdateStream extends TupleStream implements Expressible {
}
}
- private String findZkHost(
- StreamFactory factory, String collectionName, StreamExpression expression) {
- StreamExpressionNamedParameter zkHostExpression = factory.getNamedOperand(expression, "zkHost");
- if (null == zkHostExpression) {
- String zkHost = factory.getCollectionZkHost(collectionName);
- if (zkHost == null) {
- return factory.getDefaultZkHost();
- } else {
- return zkHost;
- }
- } else if (zkHostExpression.getParameter() instanceof StreamExpressionValue) {
- return ((StreamExpressionValue) zkHostExpression.getParameter()).getValue();
- }
-
- return null;
- }
-
- private void verifyZkHost(String zkHost, String collectionName, StreamExpression expression)
- throws IOException {
- if (null == zkHost) {
- throw new IOException(
- String.format(
- Locale.ROOT,
- "invalid expression %s - zkHost not found for collection '%s'",
- expression,
- collectionName));
- }
- }
-
private int extractBatchSize(StreamExpression expression, StreamFactory factory)
throws IOException {
StreamExpressionNamedParameter batchSizeParam =
@@ -352,7 +334,7 @@ public class UpdateStream extends TupleStream implements Expressible {
}
try {
- var cloudSolrClient = clientCache.getCloudSolrClient(zkHost);
+ var cloudSolrClient = clientCache.getCloudSolrClient(solrConnection);
cloudSolrClient.add(collection, documentBatch);
} catch (SolrServerException | IOException e) {
// TODO: it would be nice if there was an option to "skipFailedBatches"
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/expr/StreamExpression.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/expr/StreamExpression.java
index 77fbb57c6d0..843c8c8ac79 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/expr/StreamExpression.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/expr/StreamExpression.java
@@ -18,7 +18,9 @@ package org.apache.solr.client.solrj.io.stream.expr;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import java.util.Objects;
+import org.apache.solr.common.params.SolrParams;
/** Expression containing a function and set of parameters */
public class StreamExpression implements StreamExpressionParameter {
@@ -76,6 +78,15 @@ public class StreamExpression implements StreamExpressionParameter {
this.parameters = parameters;
}
+ public StreamExpression withMoreParameters(SolrParams parameters) {
+ for (Map.Entry<String, String[]> parameter : parameters) {
+ for (String value : parameter.getValue()) {
+ addParameter(new StreamExpressionNamedParameter(parameter.getKey(), value));
+ }
+ }
+ return this;
+ }
+
public StreamExpression withParameters(List<StreamExpressionParameter> parameters) {
setParameters(parameters);
return this;
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/expr/StreamFactory.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/expr/StreamFactory.java
index dfc2a391d82..c1b349f5f99 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/expr/StreamFactory.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/expr/StreamFactory.java
@@ -29,6 +29,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.function.Supplier;
import java.util.stream.Collectors;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.comp.ComparatorOrder;
import org.apache.solr.client.solrj.io.comp.MultipleFieldComparator;
import org.apache.solr.client.solrj.io.comp.StreamComparator;
@@ -42,24 +43,37 @@ import org.apache.solr.client.solrj.io.stream.metrics.Metric;
/** Used to convert strings into stream expressions */
public class StreamFactory implements Serializable {
- private transient HashMap<String, String> collectionZkHosts;
+ private transient HashMap<String, CloudSolrClient.CloudSolrClientConnection>
+ collectionSolrConnection;
private transient HashMap<String, Supplier<Class<? extends Expressible>>> functionNames;
- private transient String defaultZkHost;
+ private transient CloudSolrClient.CloudSolrClientConnection defaultSolrConnection;
private transient String defaultCollection;
private transient String defaultSort;
public StreamFactory() {
- collectionZkHosts = new HashMap<>();
+ collectionSolrConnection = new HashMap<>();
functionNames = new HashMap<>();
}
public StreamFactory(HashMap<String, Supplier<Class<? extends Expressible>>> functionNames) {
this.functionNames = functionNames;
- collectionZkHosts = new HashMap<>();
+ collectionSolrConnection = new HashMap<>();
}
+ /**
+ * @deprecated use {@link #withCollectionUseThisConnection(String,
+ * CloudSolrClient.CloudSolrClientConnection)}
+ */
+ @Deprecated
public StreamFactory withCollectionZkHost(String collectionName, String zkHost) {
- this.collectionZkHosts.put(collectionName, zkHost);
+ var solrConnection = zkHostToSolrConnection(zkHost);
+ return withCollectionUseThisConnection(collectionName, solrConnection);
+ }
+
+ /** If an expressions references this collection, then use the specified Solr connection. */
+ public StreamFactory withCollectionUseThisConnection(
+ String collectionName, CloudSolrClient.CloudSolrClientConnection solrConnection) {
+ this.collectionSolrConnection.put(collectionName, solrConnection);
this.defaultCollection = collectionName;
return this;
}
@@ -68,17 +82,75 @@ public class StreamFactory implements Serializable {
return defaultCollection;
}
+ /**
+ * @deprecated use {@link #withDefaultSolrConnection(CloudSolrClient.CloudSolrClientConnection)}
+ */
+ @Deprecated
public StreamFactory withDefaultZkHost(String zkHost) {
- this.defaultZkHost = zkHost;
+ var solrConnection = zkHostToSolrConnection(zkHost);
+ return withDefaultSolrConnection(solrConnection);
+ }
+
+ public StreamFactory withDefaultSolrConnection(
+ CloudSolrClient.CloudSolrClientConnection solrConnection) {
+ this.defaultSolrConnection = solrConnection;
return this;
}
+ public CloudSolrClient.CloudSolrClientConnection buildSolrConnection(
+ StreamExpression streamExpression, String collectionName) throws IOException {
+
+ var solrConnectionExpression = getNamedOperand(streamExpression, "solrConnection");
+ var zkHostExpression = getNamedOperand(streamExpression, "zkHost");
+
+ CloudSolrClient.CloudSolrClientConnection solrConnection = null;
+
+ if (zkHostExpression == null && solrConnectionExpression == null) {
+ solrConnection = getConnectionForCollection(collectionName);
+ } else if (solrConnectionExpression != null
+ && solrConnectionExpression.getParameter() instanceof StreamExpressionValue exprValue) {
+ solrConnection = CloudSolrClient.CloudSolrClientConnection.parse(exprValue.getValue());
+ } else if (zkHostExpression != null
+ && zkHostExpression.getParameter() instanceof StreamExpressionValue exprValue) {
+ solrConnection = CloudSolrClient.CloudSolrClientConnection.parse(exprValue.getValue());
+ if (!solrConnection.isZookeeper()) {
+ throw new IOException(
+ String.format(
+ Locale.ROOT,
+ "Expected ZooKeeper connection string, but got: '%s'. "
+ + "Use 'solrConnection' for pass HTTP(s) quorum",
+ solrConnection));
+ }
+ }
+
+ if (solrConnection == null) {
+ throw new IOException(
+ String.format(
+ Locale.ROOT,
+ "invalid expression %s - solrConnection or zkHost not found for collection '%s'",
+ streamExpression,
+ collectionName));
+ }
+
+ return solrConnection;
+ }
+
+ private static CloudSolrClient.CloudSolrClientConnection zkHostToSolrConnection(String zkHost) {
+ var solrConnection = CloudSolrClient.CloudSolrClientConnection.parse(zkHost);
+ if (!solrConnection.isZookeeper()) {
+ throw new IllegalArgumentException(
+ String.format(
+ Locale.ROOT, "Expected ZooKeeper connection string, but got: '%s'.", zkHost));
+ }
+ return solrConnection;
+ }
+
@Override
public Object clone() {
// Shallow copy
StreamFactory clone = new StreamFactory(functionNames);
return clone
- .withCollectionZkHost(defaultCollection, defaultZkHost)
+ .withCollectionUseThisConnection(defaultCollection, defaultSolrConnection)
.withDefaultSort(defaultSort);
}
@@ -91,15 +163,33 @@ public class StreamFactory implements Serializable {
return this.defaultSort;
}
+ /**
+ * @deprecated use {@link #buildSolrConnection(StreamExpression, String)} ()}
+ */
+ @Deprecated
public String getDefaultZkHost() {
- return this.defaultZkHost;
+ return getDefaultSolrConnection().toString();
}
+ public CloudSolrClient.CloudSolrClientConnection getDefaultSolrConnection() {
+ return this.defaultSolrConnection;
+ }
+
+ /**
+ * @deprecated use {@link #buildSolrConnection(StreamExpression, String)}
+ */
+ @Deprecated
public String getCollectionZkHost(String collectionName) {
- if (this.collectionZkHosts.containsKey(collectionName)) {
- return this.collectionZkHosts.get(collectionName);
- }
- return null;
+ return getConnectionForCollection(collectionName).toString();
+ }
+
+ /**
+ * Gets a SolrConnection using collection-to-connection configuration. Defaults to {@link
+ * #getDefaultSolrConnection()}
+ */
+ private CloudSolrClient.CloudSolrClientConnection getConnectionForCollection(
+ String collectionName) {
+ return this.collectionSolrConnection.getOrDefault(collectionName, defaultSolrConnection);
}
public Map<String, Supplier<Class<? extends Expressible>>> getFunctionNames() {
diff --git a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/SolrClientCacheTest.java b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/SolrClientCacheTest.java
index f38bc577651..809a6abe363 100644
--- a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/SolrClientCacheTest.java
+++ b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/SolrClientCacheTest.java
@@ -35,15 +35,19 @@ public class SolrClientCacheTest extends SolrCloudTestCase {
private static final Map<String, String> sysProps =
Map.of(
SolrZkClient.ZK_CREDENTIALS_INJECTOR_CLASS_NAME_VM_PARAM_NAME,
- VMParamsZkCredentialsInjector.class.getName(),
+ VMParamsZkCredentialsInjector.class.getName(),
SolrZkClient.ZK_CRED_PROVIDER_CLASS_NAME_VM_PARAM_NAME,
- DigestZkCredentialsProvider.class.getName(),
+ DigestZkCredentialsProvider.class.getName(),
SolrZkClient.ZK_ACL_PROVIDER_CLASS_NAME_VM_PARAM_NAME,
- DigestZkACLProvider.class.getName(),
- VMParamsZkCredentialsInjector.DEFAULT_DIGEST_USERNAME_VM_PARAM_NAME, "admin-user",
- VMParamsZkCredentialsInjector.DEFAULT_DIGEST_PASSWORD_VM_PARAM_NAME, "pass",
- VMParamsZkCredentialsInjector.DEFAULT_DIGEST_READONLY_USERNAME_VM_PARAM_NAME, "read-user",
- VMParamsZkCredentialsInjector.DEFAULT_DIGEST_READONLY_PASSWORD_VM_PARAM_NAME, "pass");
+ DigestZkACLProvider.class.getName(),
+ VMParamsZkCredentialsInjector.DEFAULT_DIGEST_USERNAME_VM_PARAM_NAME,
+ "admin-user",
+ VMParamsZkCredentialsInjector.DEFAULT_DIGEST_PASSWORD_VM_PARAM_NAME,
+ "pass",
+ VMParamsZkCredentialsInjector.DEFAULT_DIGEST_READONLY_USERNAME_VM_PARAM_NAME,
+ "read-user",
+ VMParamsZkCredentialsInjector.DEFAULT_DIGEST_READONLY_PASSWORD_VM_PARAM_NAME,
+ "pass");
@BeforeClass
public static void before() throws Exception {
@@ -65,7 +69,11 @@ public class SolrClientCacheTest extends SolrCloudTestCase {
// This ZK Host is fake, thus the ZK ACLs should not be used
cache.setDefaultZKHost("test:2181");
expectThrows(
- SolrException.class, () -> cache.getCloudSolrClient(zkClient().getZkServerAddress()));
+ SolrException.class,
+ () ->
+ cache.getCloudSolrClient(
+ CloudSolrClient.CloudSolrClientConnection.parse(
+ zkClient().getZkServerAddress())));
}
}
@@ -73,7 +81,8 @@ public class SolrClientCacheTest extends SolrCloudTestCase {
public void testGetClientWithHttp() {
String solrUrl = cluster.getJettySolrRunner(0).getBaseUrl().toString();
try (SolrClientCache cache = new SolrClientCache()) {
- CloudSolrClient cloudSolrClient = cache.getCloudSolrClient(solrUrl);
+ CloudSolrClient cloudSolrClient =
+ cache.getCloudSolrClient(CloudSolrClient.CloudSolrClientConnection.parse(solrUrl));
ClusterState clusterState = cloudSolrClient.getClusterStateProvider().getClusterState();
Assert.assertEquals(1, clusterState.getLiveNodes().size());
}
@@ -84,7 +93,9 @@ public class SolrClientCacheTest extends SolrCloudTestCase {
String zkConnectionString = zkClient().getZkServerAddress();
try (SolrClientCache cache = new SolrClientCache()) {
cache.setDefaultZKHost(zkClient().getZkServerAddress());
- CloudSolrClient cloudSolrClient = cache.getCloudSolrClient(zkConnectionString);
+ CloudSolrClient cloudSolrClient =
+ cache.getCloudSolrClient(
+ CloudSolrClient.CloudSolrClientConnection.parse(zkConnectionString));
ClusterState clusterState = cloudSolrClient.getClusterStateProvider().getClusterState();
Assert.assertEquals(1, clusterState.getLiveNodes().size());
}
@@ -95,7 +106,8 @@ public class SolrClientCacheTest extends SolrCloudTestCase {
try (SolrClientCache cache = new SolrClientCache()) {
// The same ZK Host is used, so the ZK ACLs should still be applied
cache.setDefaultZKHost(zkClient().getZkServerAddress() + "/random/chroot");
- cache.getCloudSolrClient(zkClient().getZkServerAddress());
+ cache.getCloudSolrClient(
+ CloudSolrClient.CloudSolrClientConnection.parse(zkClient().getZkServerAddress()));
}
}
}
diff --git a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/graph/GraphExpressionTest.java b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/graph/GraphExpressionTest.java
index 9b190864c86..a33c66ff019 100644
--- a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/graph/GraphExpressionTest.java
+++ b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/graph/GraphExpressionTest.java
@@ -30,6 +30,7 @@ import java.util.Set;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrRequest;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.SolrClientCache;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.comp.ComparatorOrder;
@@ -125,9 +126,11 @@ public class GraphExpressionTest extends SolrCloudTestCase {
SolrClientCache cache = new SolrClientCache();
context.setSolrClientCache(cache);
+ var solrConnection =
+ CloudSolrClient.CloudSolrClientConnection.parse(cluster.getZkServer().getZkAddress());
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("collection1", solrConnection)
.withFunctionName("shortestPath", ShortestPathStream.class);
stream =
@@ -417,9 +420,11 @@ public class GraphExpressionTest extends SolrCloudTestCase {
SolrClientCache cache = new SolrClientCache();
context.setSolrClientCache(cache);
+ var solrConnection =
+ CloudSolrClient.CloudSolrClientConnection.parse(cluster.getZkServer().getZkAddress());
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("collection1", solrConnection)
.withFunctionName("gatherNodes", GatherNodesStream.class)
.withFunctionName("nodes", GatherNodesStream.class)
.withFunctionName("search", CloudSolrStream.class)
@@ -743,10 +748,12 @@ public class GraphExpressionTest extends SolrCloudTestCase {
SolrClientCache cache = new SolrClientCache();
context.setSolrClientCache(cache);
+ var solrConnection =
+ CloudSolrClient.CloudSolrClientConnection.parse(cluster.getZkServer().getZkAddress());
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())
- .withDefaultZkHost(cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("collection1", solrConnection)
+ .withDefaultSolrConnection(solrConnection)
.withFunctionName("gatherNodes", GatherNodesStream.class)
.withFunctionName("scoreNodes", ScoreNodesStream.class)
.withFunctionName("search", CloudSolrStream.class)
@@ -906,10 +913,12 @@ public class GraphExpressionTest extends SolrCloudTestCase {
SolrClientCache cache = new SolrClientCache();
context.setSolrClientCache(cache);
+ var solrConnection =
+ CloudSolrClient.CloudSolrClientConnection.parse(cluster.getZkServer().getZkAddress());
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())
- .withDefaultZkHost(cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("collection1", solrConnection)
+ .withDefaultSolrConnection(solrConnection)
.withFunctionName("gatherNodes", GatherNodesStream.class)
.withFunctionName("scoreNodes", ScoreNodesStream.class)
.withFunctionName("search", CloudSolrStream.class)
@@ -973,9 +982,11 @@ public class GraphExpressionTest extends SolrCloudTestCase {
SolrClientCache cache = new SolrClientCache();
context.setSolrClientCache(cache);
+ var solrConnection =
+ CloudSolrClient.CloudSolrClientConnection.parse(cluster.getZkServer().getZkAddress());
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("collection1", solrConnection)
.withFunctionName("gatherNodes", GatherNodesStream.class)
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("count", CountMetric.class)
diff --git a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/graph/GraphTest.java b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/graph/GraphTest.java
index e16c2692fc0..ae3f3ebd642 100644
--- a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/graph/GraphTest.java
+++ b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/graph/GraphTest.java
@@ -23,6 +23,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.lucene.tests.util.LuceneTestCase;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.SolrClientCache;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.stream.StreamContext;
@@ -92,6 +93,7 @@ public class GraphTest extends SolrCloudTestCase {
Set<String> paths = null;
ShortestPathStream stream = null;
String zkHost = cluster.getZkServer().getZkAddress();
+ var solrConnection = CloudSolrClient.CloudSolrClientConnection.parse(zkHost);
StreamContext context = new StreamContext();
SolrClientCache cache = new SolrClientCache();
context.setSolrClientCache(cache);
@@ -100,7 +102,7 @@ public class GraphTest extends SolrCloudTestCase {
stream =
new ShortestPathStream(
- zkHost, "collection1", "jim", "steve", "from_s", "to_s", sParams, 20, 3, 6);
+ solrConnection, "collection1", "jim", "steve", "from_s", "to_s", sParams, 20, 3, 6);
stream.setStreamContext(context);
paths = new HashSet<>();
@@ -121,7 +123,7 @@ public class GraphTest extends SolrCloudTestCase {
stream =
new ShortestPathStream(
- zkHost, "collection1", "jim", "steve", "from_s", "to_s", sParams, 1, 3, 6);
+ solrConnection, "collection1", "jim", "steve", "from_s", "to_s", sParams, 1, 3, 6);
stream.setStreamContext(context);
paths = new HashSet<>();
@@ -142,7 +144,7 @@ public class GraphTest extends SolrCloudTestCase {
stream =
new ShortestPathStream(
- zkHost, "collection1", "jim", "steve", "from_s", "to_s", sParams, 1, 3, 6);
+ solrConnection, "collection1", "jim", "steve", "from_s", "to_s", sParams, 1, 3, 6);
stream.setStreamContext(context);
tuples = getTuples(stream);
@@ -155,7 +157,7 @@ public class GraphTest extends SolrCloudTestCase {
stream =
new ShortestPathStream(
- zkHost, "collection1", "jim", "steve", "from_s", "to_s", sParams, 1, 3, 2);
+ solrConnection, "collection1", "jim", "steve", "from_s", "to_s", sParams, 1, 3, 2);
stream.setStreamContext(context);
tuples = getTuples(stream);
@@ -167,7 +169,7 @@ public class GraphTest extends SolrCloudTestCase {
stream =
new ShortestPathStream(
- zkHost, "collection1", "jim", "steve", "from_s", "to_s", sParams, 10, 3, 6);
+ solrConnection, "collection1", "jim", "steve", "from_s", "to_s", sParams, 10, 3, 6);
stream.setStreamContext(context);
paths = new HashSet<>();
diff --git a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/sql/JdbcConnectionMetadataTest.java b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/sql/JdbcConnectionMetadataTest.java
new file mode 100644
index 00000000000..5099b07efa6
--- /dev/null
+++ b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/sql/JdbcConnectionMetadataTest.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.client.solrj.io.sql;
+
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import org.apache.solr.SolrTestCase;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class JdbcConnectionMetadataTest extends SolrTestCase {
+
+ private static final Map<String, List<String>> ZOOKEEPERS =
+ Map.of(
+ "zoo1", List.of("zoo1"),
+ "zoo1,zoo2,zoo3", List.of("zoo1", "zoo2", "zoo3"),
+ "zoo1:9983,zoo2:9983,zoo3:9983", List.of("zoo1:9983", "zoo2:9983", "zoo3:9983"));
+ private static final List<String> CHROOTS = List.of("", "/", "/foo", "/foo/bar");
+ private static final Map<String, Map<String, String>> PARAMS =
+ Map.of(
+ "collection=collection1", Map.of("collection", "collection1"),
+ "collection=collection1&test=test1",
+ Map.of("collection", "collection1", "test", "test1"));
+
+ private static final List<String> HTTP_URLS =
+ List.of(
+ "http://solr1/solr",
+ "http://solr2:8080/solr",
+ "http://solr3/foo/bar",
+ "https://solr4/solr",
+ "https://solr5:8443/solr",
+ "https://solr6:8443/foo/bar");
+
+ private static <T> boolean collectionEqual(Collection<T> coll, Collection<T> coll2) {
+ return coll.size() == coll2.size()
+ && Set.copyOf(coll).containsAll(coll2)
+ && Set.copyOf(coll2).containsAll(coll);
+ }
+
+ @Test
+ public void testProcessZookeeperUrl() throws Exception {
+ for (String zkHostString : ZOOKEEPERS.keySet()) {
+ for (String chroot : CHROOTS) {
+ for (String paramString : PARAMS.keySet()) {
+ String url = "jdbc:solr://" + zkHostString + chroot + "?" + paramString;
+
+ var jdbcConnectionMetadata =
+ DriverImpl.JdbcConnectionMetadata.parse(url, new Properties());
+ var solrConnection = jdbcConnectionMetadata.solrConnection();
+ List<String> expectedZookeepers = ZOOKEEPERS.get(zkHostString);
+ Assert.assertTrue(solrConnection.isZookeeper());
+ Assert.assertTrue(collectionEqual(expectedZookeepers, solrConnection.quorumItems()));
+ String expectedChroot = chroot.isBlank() ? null : chroot;
+ Assert.assertEquals(expectedChroot, solrConnection.zkChroot());
+
+ verifyParams(jdbcConnectionMetadata.properties(), PARAMS.get(paramString));
+ }
+ }
+ }
+ }
+
+ @Test
+ public void testProcessHttpUrl() throws SQLException {
+ for (String httpString : HTTP_URLS) {
+ for (String paramString : PARAMS.keySet()) {
+ String url = "jdbc:solr:" + httpString + "?" + paramString;
+
+ var jdbcConnectionMetadata = DriverImpl.JdbcConnectionMetadata.parse(url, new Properties());
+ var solrConnection = jdbcConnectionMetadata.solrConnection();
+ Assert.assertFalse(solrConnection.isZookeeper());
+ Assert.assertEquals(1, solrConnection.quorumItems().size());
+ Assert.assertEquals(httpString, solrConnection.quorumItems().getFirst());
+
+ verifyParams(jdbcConnectionMetadata.properties(), PARAMS.get(paramString));
+ }
+ }
+ }
+
+ private static void verifyParams(Properties actualProps, Map<String, String> expectedProps) {
+ Assert.assertFalse(actualProps.containsKey("collection"));
+ for (Map.Entry<String, String> param : expectedProps.entrySet()) {
+ if (!"collection".equals(param.getKey())) {
+ Assert.assertEquals(param.getValue(), actualProps.getProperty(param.getKey()));
+ }
+ }
+ }
+}
diff --git a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/sql/JdbcDriverTest.java b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/sql/JdbcDriverTest.java
index d7c764e2e62..b55ee657244 100644
--- a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/sql/JdbcDriverTest.java
+++ b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/sql/JdbcDriverTest.java
@@ -16,12 +16,9 @@
*/
package org.apache.solr.client.solrj.io.sql;
-import java.net.URI;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
-import java.util.Arrays;
-import java.util.List;
import java.util.Properties;
import org.apache.solr.SolrTestCaseJ4;
import org.junit.Test;
@@ -55,29 +52,4 @@ public class JdbcDriverTest extends SolrTestCaseJ4 {
DriverManager.getConnection(
"solr:jdbc://" + sampleZkHost + "?collection=collection1", new Properties());
}
-
- @Test
- public void testProcessUrl() throws Exception {
- DriverImpl driver = new DriverImpl();
-
- List<String> zkHostStrings =
- Arrays.asList("zoo1", "zoo1:9983", "zoo1,zoo2,zoo3", "zoo1:9983,zoo2:9983,zoo3:9983");
- List<String> chroots = Arrays.asList("", "/", "/foo", "/foo/bar");
- List<String> paramStrings =
- Arrays.asList("", "collection=collection1", "collection=collection1&test=test1");
-
- for (String zkHostString : zkHostStrings) {
- for (String chroot : chroots) {
- for (String paramString : paramStrings) {
- String url = "jdbc:solr://" + zkHostString + chroot + "?" + paramString;
-
- URI uri = driver.processUrl(url);
-
- assertEquals(zkHostString, uri.getAuthority());
- assertEquals(chroot, uri.getPath());
- assertEquals(paramString, uri.getQuery());
- }
- }
- }
- }
}
diff --git a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/BadClusterTest.java b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/BadClusterTest.java
index 089f85e1bc5..386631c2e7d 100644
--- a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/BadClusterTest.java
+++ b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/BadClusterTest.java
@@ -22,6 +22,7 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeoutException;
import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter;
@@ -47,6 +48,7 @@ public class BadClusterTest extends SolrCloudTestCase {
new StreamFactory().withFunctionName("search", CloudSolrStream.class);
private static String zkHost;
+ private static CloudSolrClient.CloudSolrClientConnection solrConnection;
@BeforeClass
public static void configureCluster() throws Exception {
@@ -65,7 +67,8 @@ public class BadClusterTest extends SolrCloudTestCase {
cluster.waitForActiveCollection(collection, 1, 1);
zkHost = cluster.getZkServer().getZkAddress();
- streamFactory.withCollectionZkHost(collection, zkHost);
+ solrConnection = CloudSolrClient.CloudSolrClientConnection.parse(zkHost);
+ streamFactory.withCollectionUseThisConnection(collection, solrConnection);
}
// test order is important because the cluster progressively gets worse, but it is only created
@@ -122,7 +125,8 @@ public class BadClusterTest extends SolrCloudTestCase {
}
private List<Replica> getReplicas() throws IOException {
- return TupleStream.getReplicas(zkHost, collection, null, new MultiMapSolrParams(Map.of()));
+ return TupleStream.getReplicas(
+ solrConnection, collection, null, new MultiMapSolrParams(Map.of()));
}
private List<Tuple> getTuples(TupleStream tupleStream) throws IOException {
diff --git a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/JDBCStreamTest.java b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/JDBCStreamTest.java
index 2dd63e664ba..1674fa6900d 100644
--- a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/JDBCStreamTest.java
+++ b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/JDBCStreamTest.java
@@ -283,7 +283,7 @@ public class JDBCStreamTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("search", CloudSolrStream.class);
List<Tuple> tuples;
@@ -336,7 +336,7 @@ public class JDBCStreamTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("select", SelectStream.class)
.withFunctionName("innerJoin", InnerJoinStream.class)
@@ -458,7 +458,7 @@ public class JDBCStreamTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("select", SelectStream.class)
.withFunctionName("innerJoin", InnerJoinStream.class)
@@ -631,7 +631,7 @@ public class JDBCStreamTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("select", SelectStream.class)
.withFunctionName("hashJoin", HashJoinStream.class)
diff --git a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/ParallelFacetStreamOverAliasTest.java b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/ParallelFacetStreamOverAliasTest.java
index caad026da65..dbc1b89f31a 100644
--- a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/ParallelFacetStreamOverAliasTest.java
+++ b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/ParallelFacetStreamOverAliasTest.java
@@ -37,6 +37,7 @@ import org.apache.commons.math3.util.Precision;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.SolrClientCache;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
@@ -273,6 +274,7 @@ public class ParallelFacetStreamOverAliasTest extends SolrCloudTestCase {
};
String zkHost = cluster.getZkServer().getZkAddress();
+ var solrConnection = CloudSolrClient.CloudSolrClientConnection.parse(zkHost);
StreamContext streamContext = new StreamContext();
streamContext.setSolrClientCache(solrClientCache);
@@ -281,7 +283,7 @@ public class ParallelFacetStreamOverAliasTest extends SolrCloudTestCase {
solrParams.add(TIERED_PARAM, "true");
// tiered stats stream
- StatsStream statsStream = new StatsStream(zkHost, ALIAS_NAME, solrParams, metrics);
+ StatsStream statsStream = new StatsStream(solrConnection, ALIAS_NAME, solrParams, metrics);
statsStream.setStreamContext(streamContext);
List<Tuple> tieredTuples = getTuples(statsStream);
assertEquals(1, tieredTuples.size());
@@ -290,7 +292,7 @@ public class ParallelFacetStreamOverAliasTest extends SolrCloudTestCase {
solrParams = new ModifiableSolrParams();
solrParams.add(CommonParams.Q, "*:*");
solrParams.add(TIERED_PARAM, "false");
- statsStream = new StatsStream(zkHost, ALIAS_NAME, solrParams, metrics);
+ statsStream = new StatsStream(solrConnection, ALIAS_NAME, solrParams, metrics);
statsStream.setStreamContext(streamContext);
// tiered should match non-tiered results
assertListOfTuplesEquals(tieredTuples, getTuples(statsStream));
@@ -304,7 +306,7 @@ public class ParallelFacetStreamOverAliasTest extends SolrCloudTestCase {
StreamContext streamContext = new StreamContext();
streamContext.setSolrClientCache(solrClientCache);
StreamFactory factory =
- new SolrDefaultStreamFactory().withDefaultZkHost(cluster.getZkServer().getZkAddress());
+ new SolrDefaultStreamFactory().withDefaultSolrConnection(getSolrConnection());
TupleStream stream = factory.constructStream(facetExpr);
stream.setStreamContext(streamContext);
diff --git a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/SelectWithEvaluatorsTest.java b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/SelectWithEvaluatorsTest.java
index 15785b4101a..edcd60561e0 100644
--- a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/SelectWithEvaluatorsTest.java
+++ b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/SelectWithEvaluatorsTest.java
@@ -99,7 +99,7 @@ public class SelectWithEvaluatorsTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("collection1", getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("select", SelectStream.class)
.withFunctionName("add", AddEvaluator.class)
diff --git a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamDecoratorTest.java b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamDecoratorTest.java
index e8b9538c33f..612370ccfe2 100644
--- a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamDecoratorTest.java
+++ b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamDecoratorTest.java
@@ -143,7 +143,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("unique", UniqueStream.class);
@@ -224,7 +224,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
try {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("sort", SortStream.class);
@@ -285,7 +285,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
streamContext.setSolrClientCache(solrClientCache);
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("null", NullStream.class);
@@ -323,10 +323,9 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamContext streamContext = new StreamContext();
SolrClientCache solrClientCache = new SolrClientCache();
streamContext.setSolrClientCache(solrClientCache);
-
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("null", NullStream.class)
.withFunctionName("parallel", ParallelStream.class);
@@ -372,7 +371,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("unique", UniqueStream.class)
.withFunctionName("merge", MergeStream.class);
@@ -497,7 +496,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("unique", UniqueStream.class)
.withFunctionName("top", RankStream.class);
@@ -601,7 +600,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("reduce", ReducerStream.class)
.withFunctionName("group", GroupOperation.class);
@@ -691,7 +690,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("having", HavingStream.class)
.withFunctionName("rollup", RollupStream.class)
@@ -820,7 +819,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("having", HavingStream.class)
.withFunctionName("rollup", RollupStream.class)
@@ -965,7 +964,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("fetch", FetchStream.class);
@@ -1089,7 +1088,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("parallel", ParallelStream.class)
.withFunctionName("fetch", FetchStream.class);
@@ -1186,7 +1185,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("rollup", RollupStream.class)
.withFunctionName("sum", SumMetric.class)
@@ -1313,7 +1312,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("topic", TopicStream.class)
.withFunctionName("daemon", DaemonStream.class);
@@ -1357,7 +1356,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("rollup", RollupStream.class)
.withFunctionName("sum", SumMetric.class)
@@ -1505,7 +1504,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("hashRollup", HashRollupStream.class)
.withFunctionName("sum", SumMetric.class)
@@ -1653,10 +1652,9 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
.add(id, "8", "a_s", "hello1", "a_i", "13", "a_f", "4")
.commit(cluster.getSolrClient(), COLLECTIONORALIAS);
- String zkHost = cluster.getZkServer().getZkAddress();
StreamFactory streamFactory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, zkHost)
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("unique", UniqueStream.class)
.withFunctionName("top", RankStream.class)
@@ -1673,8 +1671,8 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
streamFactory.constructStream(
"parallel("
+ COLLECTIONORALIAS
- + ", unique(search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\", partitionKeys=\"a_f\", qt=\"/export\"), over=\"a_f\"), workers=\"2\", zkHost=\""
- + zkHost
+ + ", unique(search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\", partitionKeys=\"a_f\", qt=\"/export\"), over=\"a_f\"), workers=\"2\", solrConnection=\""
+ + getSolrConnection().toString()
+ "\", sort=\"a_f asc\")");
pstream.setStreamContext(streamContext);
List<Tuple> tuples = getTuples(pstream);
@@ -1757,10 +1755,9 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
SolrClientCache solrClientCache = new SolrClientCache();
streamContext.setSolrClientCache(solrClientCache);
- String zkHost = cluster.getZkServer().getZkAddress();
StreamFactory streamFactory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, zkHost)
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("shuffle", ShuffleStream.class)
.withFunctionName("unique", UniqueStream.class)
.withFunctionName("parallel", ParallelStream.class);
@@ -1771,8 +1768,8 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
streamFactory.constructStream(
"parallel("
+ COLLECTIONORALIAS
- + ", unique(shuffle(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\", partitionKeys=\"a_f\"), over=\"a_f\"), workers=\"2\", zkHost=\""
- + zkHost
+ + ", unique(shuffle(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\", partitionKeys=\"a_f\"), over=\"a_f\"), workers=\"2\", solrConnection=\""
+ + getSolrConnection().toString()
+ "\", sort=\"a_f asc\")");
pstream.setStreamFactory(streamFactory);
pstream.setStreamContext(streamContext);
@@ -1810,10 +1807,9 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
SolrClientCache solrClientCache = new SolrClientCache();
streamContext.setSolrClientCache(solrClientCache);
- String zkHost = cluster.getZkServer().getZkAddress();
StreamFactory streamFactory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, zkHost)
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("group", GroupOperation.class)
.withFunctionName("reduce", ReducerStream.class)
@@ -1832,8 +1828,8 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
+ ", q=\"*:*\", fl=\"id,a_s,a_i,a_f\", sort=\"a_s asc,a_f asc\", partitionKeys=\"a_s\", qt=\"/export\"), "
+ "by=\"a_s\","
+ "group(sort=\"a_i asc\", n=\"5\")), "
- + "workers=\"2\", zkHost=\""
- + zkHost
+ + "workers=\"2\", solrConnection=\""
+ + getSolrConnection().toString()
+ "\", sort=\"a_s asc\")");
pstream.setStreamContext(streamContext);
@@ -1866,8 +1862,8 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
+ ", q=\"*:*\", fl=\"id,a_s,a_i,a_f\", sort=\"a_s desc,a_f asc\", partitionKeys=\"a_s\", qt=\"/export\"), "
+ "by=\"a_s\", "
+ "group(sort=\"a_i desc\", n=\"5\")),"
- + "workers=\"2\", zkHost=\""
- + zkHost
+ + "workers=\"2\", solrConnection=\""
+ + getSolrConnection().toString()
+ "\", sort=\"a_s desc\")");
pstream.setStreamContext(streamContext);
@@ -1907,10 +1903,9 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
.add(id, "10", "a_s", "hello1", "a_i", "10", "a_f", "1")
.commit(cluster.getSolrClient(), COLLECTIONORALIAS);
- String zkHost = cluster.getZkServer().getZkAddress();
StreamFactory streamFactory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, zkHost)
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("unique", UniqueStream.class)
.withFunctionName("top", RankStream.class)
@@ -1932,8 +1927,8 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
+ COLLECTIONORALIAS
+ ", q=\"*:*\", fl=\"id,a_s,a_i\", sort=\"a_i asc\", partitionKeys=\"a_i\", qt=\"/export\"), "
+ "n=\"11\", "
- + "sort=\"a_i desc\"), workers=\"2\", zkHost=\""
- + zkHost
+ + "sort=\"a_i desc\"), workers=\"2\", solrConnection=\""
+ + getSolrConnection().toString()
+ "\", sort=\"a_i desc\")");
pstream.setStreamContext(streamContext);
List<Tuple> tuples = getTuples(pstream);
@@ -1961,10 +1956,9 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
.add(id, "9", "a_s", "hello1", "a_i", "100", "a_f", "1")
.commit(cluster.getSolrClient(), COLLECTIONORALIAS);
- String zkHost = cluster.getZkServer().getZkAddress();
StreamFactory streamFactory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, zkHost)
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("unique", UniqueStream.class)
.withFunctionName("top", RankStream.class)
@@ -1986,8 +1980,8 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
+ COLLECTIONORALIAS
+ ", q=\"id:(4 1 8 7 9)\", fl=\"id,a_s,a_i\", sort=\"a_i asc\", partitionKeys=\"a_i\", qt=\"/export\"), search("
+ COLLECTIONORALIAS
- + ", q=\"id:(0 2 3 6)\", fl=\"id,a_s,a_i\", sort=\"a_i asc\", partitionKeys=\"a_i\", qt=\"/export\"), on=\"a_i asc\"), workers=\"2\", zkHost=\""
- + zkHost
+ + ", q=\"id:(0 2 3 6)\", fl=\"id,a_s,a_i\", sort=\"a_i asc\", partitionKeys=\"a_i\", qt=\"/export\"), on=\"a_i asc\"), workers=\"2\", solrConnection=\""
+ + getSolrConnection().toString()
+ "\", sort=\"a_i asc\")");
pstream.setStreamContext(streamContext);
List<Tuple> tuples = getTuples(pstream);
@@ -2006,8 +2000,8 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
+ COLLECTIONORALIAS
+ ", q=\"id:(4 1 8 9)\", fl=\"id,a_s,a_i\", sort=\"a_i desc\", partitionKeys=\"a_i\", qt=\"/export\"), search("
+ COLLECTIONORALIAS
- + ", q=\"id:(0 2 3 6)\", fl=\"id,a_s,a_i\", sort=\"a_i desc\", partitionKeys=\"a_i\", qt=\"/export\"), on=\"a_i desc\"), workers=\"2\", zkHost=\""
- + zkHost
+ + ", q=\"id:(0 2 3 6)\", fl=\"id,a_s,a_i\", sort=\"a_i desc\", partitionKeys=\"a_i\", qt=\"/export\"), on=\"a_i desc\"), workers=\"2\", solrConnection=\""
+ + getSolrConnection().toString()
+ "\", sort=\"a_i desc\")");
pstream.setStreamContext(streamContext);
tuples = getTuples(pstream);
@@ -2037,7 +2031,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("parallel", ParallelStream.class)
.withFunctionName("rollup", RollupStream.class)
@@ -2076,8 +2070,8 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
+ "avg(a_f),"
+ "count(*)"
+ "),"
- + "workers=\"2\", zkHost=\""
- + cluster.getZkServer().getZkAddress()
+ + "workers=\"2\", solrConnection=\""
+ + getSolrConnection().toString()
+ "\", sort=\"a_s asc\")");
stream = factory.constructStream(expression);
@@ -2179,7 +2173,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("parallel", ParallelStream.class)
.withFunctionName("hashRollup", HashRollupStream.class)
@@ -2219,8 +2213,8 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
+ "avg(a_f),"
+ "count(*)"
+ "),"
- + "workers=\"2\", zkHost=\""
- + cluster.getZkServer().getZkAddress()
+ + "workers=\"2\", solrConnection=\""
+ + getSolrConnection().toString()
+ "\", sort=\"a_s asc\"), by=\"avg(a_f) asc\")");
stream = factory.constructStream(expression);
@@ -2349,7 +2343,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("innerJoin", InnerJoinStream.class);
@@ -2471,7 +2465,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("leftOuterJoin", LeftOuterJoinStream.class);
@@ -2611,7 +2605,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("fullOuterJoin", FullOuterJoinStream.class);
@@ -2751,7 +2745,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("hashJoin", HashJoinStream.class);
try {
@@ -2829,7 +2823,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("hashJoin", HashJoinStream.class);
try {
@@ -2869,7 +2863,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("outerHashJoin", OuterHashJoinStream.class);
try {
@@ -2938,7 +2932,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("collection1", getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("outerHashJoin", OuterHashJoinStream.class);
try {
@@ -3044,7 +3038,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("collection1", getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("innerJoin", InnerJoinStream.class)
.withFunctionName("select", SelectStream.class)
@@ -3181,7 +3175,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("collection1", getSolrConnection())
.withFunctionName("topic", TopicStream.class)
.withFunctionName("priority", PriorityStream.class);
@@ -3246,7 +3240,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("collection1", getSolrConnection())
.withFunctionName("topic", TopicStream.class)
.withFunctionName("parallel", ParallelStream.class)
.withFunctionName("priority", PriorityStream.class);
@@ -3327,8 +3321,8 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())
- .withCollectionZkHost("destinationCollection", cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("collection1", getSolrConnection())
+ .withCollectionUseThisConnection("destinationCollection", getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("update", UpdateStream.class);
@@ -3436,12 +3430,10 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
SolrClientCache solrClientCache = new SolrClientCache();
streamContext.setSolrClientCache(solrClientCache);
- String zkHost = cluster.getZkServer().getZkAddress();
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())
- .withCollectionZkHost(
- "parallelDestinationCollection", cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("collection1", getSolrConnection())
+ .withCollectionUseThisConnection("parallelDestinationCollection", getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("update", UpdateStream.class)
.withFunctionName("parallel", ParallelStream.class);
@@ -3454,8 +3446,8 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
factory.constructStream(
"parallel(collection1, "
+ updateExpression
- + ", workers=\"2\", zkHost=\""
- + zkHost
+ + ", workers=\"2\", solrConnection=\""
+ + getSolrConnection()
+ "\", sort=\"batchNumber asc\")");
parallelUpdateStream.setStreamContext(streamContext);
List<Tuple> tuples = getTuples(parallelUpdateStream);
@@ -3557,12 +3549,10 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
SolrClientCache solrClientCache = new SolrClientCache();
streamContext.setSolrClientCache(solrClientCache);
- String zkHost = cluster.getZkServer().getZkAddress();
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())
- .withCollectionZkHost(
- "parallelDestinationCollection1", cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("collection1", getSolrConnection())
+ .withCollectionUseThisConnection("parallelDestinationCollection1", getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("update", UpdateStream.class)
.withFunctionName("parallel", ParallelStream.class)
@@ -3576,8 +3566,8 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
factory.constructStream(
"parallel(collection1, "
+ updateExpression
- + ", workers=\"2\", zkHost=\""
- + zkHost
+ + ", workers=\"2\", solrConnection=\""
+ + getSolrConnection().toString()
+ "\", sort=\"batchNumber asc\")");
parallelUpdateStream.setStreamContext(streamContext);
List<Tuple> tuples = getTuples(parallelUpdateStream);
@@ -3756,12 +3746,10 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
SolrClientCache solrClientCache = new SolrClientCache();
streamContext.setSolrClientCache(solrClientCache);
- String zkHost = cluster.getZkServer().getZkAddress();
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())
- .withCollectionZkHost(
- "parallelDestinationCollection1", cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("collection1", getSolrConnection())
+ .withCollectionUseThisConnection("parallelDestinationCollection1", getSolrConnection())
.withFunctionName("topic", TopicStream.class)
.withFunctionName("update", UpdateStream.class)
.withFunctionName("parallel", ParallelStream.class)
@@ -3775,8 +3763,8 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
factory.constructStream(
"parallel(collection1, "
+ updateExpression
- + ", workers=\"2\", zkHost=\""
- + zkHost
+ + ", workers=\"2\", solrConnection=\""
+ + getSolrConnection().toString()
+ "\", sort=\"batchNumber asc\")");
parallelUpdateStream.setStreamContext(streamContext);
List<Tuple> tuples = getTuples(parallelUpdateStream);
@@ -3967,8 +3955,8 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())
- .withCollectionZkHost("destinationCollection", cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("collection1", getSolrConnection())
+ .withCollectionUseThisConnection("destinationCollection", getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("update", UpdateStream.class)
.withFunctionName("commit", CommitStream.class);
@@ -4075,12 +4063,10 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
SolrClientCache solrClientCache = new SolrClientCache();
streamContext.setSolrClientCache(solrClientCache);
- String zkHost = cluster.getZkServer().getZkAddress();
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())
- .withCollectionZkHost(
- "parallelDestinationCollection", cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("collection1", getSolrConnection())
+ .withCollectionUseThisConnection("parallelDestinationCollection", getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("update", UpdateStream.class)
.withFunctionName("commit", CommitStream.class)
@@ -4089,15 +4075,15 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
try {
// Copy all docs to destinationCollection
String updateExpression =
- "commit(parallelDestinationCollection, batchSize=0, zkHost=\""
- + cluster.getZkServer().getZkAddress()
+ "commit(parallelDestinationCollection, batchSize=0, solrConnection=\""
+ + getSolrConnection().toString()
+ "\", update(parallelDestinationCollection, batchSize=2, search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f,s_multi,i_multi\", sort=\"a_f asc, a_i asc\", partitionKeys=\"a_f\", qt=\"/export\")))";
TupleStream parallelUpdateStream =
factory.constructStream(
"parallel(collection1, "
+ updateExpression
- + ", workers=\"2\", zkHost=\""
- + zkHost
+ + ", workers=\"2\", solrConnection=\""
+ + getSolrConnection().toString()
+ "\", sort=\"batchNumber asc\")");
parallelUpdateStream.setStreamContext(streamContext);
List<Tuple> tuples = getTuples(parallelUpdateStream);
@@ -4198,12 +4184,10 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
SolrClientCache solrClientCache = new SolrClientCache();
streamContext.setSolrClientCache(solrClientCache);
- String zkHost = cluster.getZkServer().getZkAddress();
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())
- .withCollectionZkHost(
- "parallelDestinationCollection1", cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("collection1", getSolrConnection())
+ .withCollectionUseThisConnection("parallelDestinationCollection1", getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("update", UpdateStream.class)
.withFunctionName("commit", CommitStream.class)
@@ -4213,15 +4197,15 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
try {
// Copy all docs to destinationCollection
String updateExpression =
- "daemon(commit(parallelDestinationCollection1, batchSize=0, zkHost=\""
- + cluster.getZkServer().getZkAddress()
+ "daemon(commit(parallelDestinationCollection1, batchSize=0, solrConnection=\""
+ + getSolrConnection().toString()
+ "\", update(parallelDestinationCollection1, batchSize=2, search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f,s_multi,i_multi\", sort=\"a_f asc, a_i asc\", partitionKeys=\"a_f\", qt=\"/export\"))), runInterval=\"1000\", id=\"test\")";
TupleStream parallelUpdateStream =
factory.constructStream(
"parallel(collection1, "
+ updateExpression
- + ", workers=\"2\", zkHost=\""
- + zkHost
+ + ", workers=\"2\", solrConnection=\""
+ + getSolrConnection().toString()
+ "\", sort=\"batchNumber asc\")");
parallelUpdateStream.setStreamContext(streamContext);
List<Tuple> tuples = getTuples(parallelUpdateStream);
@@ -4387,7 +4371,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("collection1", getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("intersect", IntersectStream.class);
@@ -4457,9 +4441,9 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())
- .withCollectionZkHost("modelCollection", cluster.getZkServer().getZkAddress())
- .withCollectionZkHost("uknownCollection", cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("collection1", getSolrConnection())
+ .withCollectionUseThisConnection("modelCollection", getSolrConnection())
+ .withCollectionUseThisConnection("uknownCollection", getSolrConnection())
.withFunctionName("features", FeaturesSelectionStream.class)
.withFunctionName("train", TextLogitStream.class)
.withFunctionName("search", CloudSolrStream.class)
@@ -4697,9 +4681,9 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost("workQueue", cluster.getZkServer().getZkAddress())
- .withCollectionZkHost("mainCorpus", cluster.getZkServer().getZkAddress())
- .withCollectionZkHost("destination", cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("workQueue", getSolrConnection())
+ .withCollectionUseThisConnection("mainCorpus", getSolrConnection())
+ .withCollectionUseThisConnection("destination", getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("executor", ExecutorStream.class)
.withFunctionName("update", UpdateStream.class);
@@ -4779,9 +4763,9 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost("workQueue1", cluster.getZkServer().getZkAddress())
- .withCollectionZkHost("mainCorpus1", cluster.getZkServer().getZkAddress())
- .withCollectionZkHost("destination1", cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("workQueue1", getSolrConnection())
+ .withCollectionUseThisConnection("mainCorpus1", getSolrConnection())
+ .withCollectionUseThisConnection("destination1", getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("executor", ExecutorStream.class)
.withFunctionName("parallel", ParallelStream.class)
@@ -4847,7 +4831,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory streamFactory =
new StreamFactory()
- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("collection1", getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("intersect", IntersectStream.class)
.withFunctionName("parallel", ParallelStream.class);
@@ -4858,7 +4842,6 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
streamContext.setSolrClientCache(solrClientCache);
try {
- String zkHost = cluster.getZkServer().getZkAddress();
final TupleStream stream =
streamFactory.constructStream(
"parallel("
@@ -4867,8 +4850,8 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
+ "search(collection1, q=a_s:(setA || setAB), fl=\"id,a_s,a_i\", sort=\"a_i asc, a_s asc\", partitionKeys=\"a_i\", qt=\"/export\"),"
+ "search(collection1, q=a_s:(setB || setAB), fl=\"id,a_s,a_i\", sort=\"a_i asc\", partitionKeys=\"a_i\", qt=\"/export\"),"
+ "on=\"a_i\"),"
- + "workers=\"2\", zkHost=\""
- + zkHost
+ + "workers=\"2\", solrConnection=\""
+ + getSolrConnection().toString()
+ "\", sort=\"a_i asc\")");
stream.setStreamContext(streamContext);
@@ -4906,7 +4889,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("collection1", getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("complement", ComplementStream.class);
@@ -4948,7 +4931,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("collection1", getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("cartesian", CartesianProductStream.class);
@@ -5101,7 +5084,7 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
StreamFactory streamFactory =
new StreamFactory()
- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("collection1", getSolrConnection())
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("complement", ComplementStream.class)
.withFunctionName("parallel", ParallelStream.class);
@@ -5111,7 +5094,6 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
streamContext.setSolrClientCache(solrClientCache);
try {
- final String zkHost = cluster.getZkServer().getZkAddress();
final TupleStream stream =
streamFactory.constructStream(
"parallel("
@@ -5120,8 +5102,8 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
+ "search(collection1, q=a_s:(setA || setAB), fl=\"id,a_s,a_i\", sort=\"a_i asc, a_s asc\", partitionKeys=\"a_i\", qt=\"/export\"),"
+ "search(collection1, q=a_s:(setB || setAB), fl=\"id,a_s,a_i\", sort=\"a_i asc\", partitionKeys=\"a_i\", qt=\"/export\"),"
+ "on=\"a_i\"),"
- + "workers=\"2\", zkHost=\""
- + zkHost
+ + "workers=\"2\", solrConnection=\""
+ + getSolrConnection().toString()
+ "\", sort=\"a_i asc\")");
stream.setStreamContext(streamContext);
diff --git a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java
index c38ce4adaa5..4ef5a73ccef 100644
--- a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java
+++ b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java
@@ -38,6 +38,7 @@ import java.util.zip.GZIPOutputStream;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.ClassificationEvaluation;
import org.apache.solr.client.solrj.io.SolrClientCache;
import org.apache.solr.client.solrj.io.Tuple;
@@ -76,6 +77,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {
private static final String id = "id";
private static boolean useAlias;
+ private static CloudSolrClient.CloudSolrClientConnection solrConnection;
@BeforeClass
public static void setupCluster() throws Exception {
@@ -113,6 +115,8 @@ public class StreamExpressionTest extends SolrCloudTestCase {
CollectionAdminRequest.createCollection(FILESTREAM_COLLECTION, "conf", 1, 1)
.process(cluster.getSolrClient());
cluster.waitForActiveCollection(FILESTREAM_COLLECTION, 1, 1);
+ solrConnection =
+ CloudSolrClient.CloudSolrClientConnection.parse(cluster.getZkServer().getZkAddress());
final Path dataDir = findUserFilesDataDir();
populateFileStreamData(dataDir);
}
@@ -135,7 +139,8 @@ public class StreamExpressionTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress());
+ .withDefaultSolrConnection(solrConnection)
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, solrConnection);
StreamExpression expression;
CloudSolrStream stream;
List<Tuple> tuples;
@@ -229,7 +234,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {
List<String> shardUrls =
TupleStream.getShards(
- cluster.getZkServer().getZkAddress(), COLLECTIONORALIAS, streamContext);
+ StreamExpressionTest.solrConnection, COLLECTIONORALIAS, streamContext);
Map<String, List<String>> shardsMap = new HashMap<>();
shardsMap.put("myCollection", shardUrls);
@@ -293,8 +298,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {
SolrClientCache solrClientCache = new SolrClientCache();
streamContext.setSolrClientCache(solrClientCache);
List<String> shardUrls =
- TupleStream.getShards(
- cluster.getZkServer().getZkAddress(), COLLECTIONORALIAS, streamContext);
+ TupleStream.getShards(solrConnection, COLLECTIONORALIAS, streamContext);
try {
StringBuilder buf = new StringBuilder();
@@ -354,8 +358,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {
SolrClientCache solrClientCache = new SolrClientCache();
streamContext.setSolrClientCache(solrClientCache);
List<String> shardUrls =
- TupleStream.getShards(
- cluster.getZkServer().getZkAddress(), COLLECTIONORALIAS, streamContext);
+ TupleStream.getShards(solrConnection, COLLECTIONORALIAS, streamContext);
try {
StringBuilder buf = new StringBuilder();
@@ -417,9 +420,9 @@ public class StreamExpressionTest extends SolrCloudTestCase {
StreamExpressionParser.parse(
"search("
+ COLLECTIONORALIAS
- + ", zkHost="
- + cluster.getZkServer().getZkAddress()
- + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\")");
+ + ", solrConnection=\""
+ + getSolrConnection().toString()
+ + "\", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\")");
stream = new CloudSolrStream(expression, factory);
stream.setStreamContext(streamContext);
tuples = getTuples(stream);
@@ -433,9 +436,9 @@ public class StreamExpressionTest extends SolrCloudTestCase {
StreamExpressionParser.parse(
"search("
+ COLLECTIONORALIAS
- + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\", aliases=\"a_i=alias_a_i, a_s=name\", zkHost="
- + cluster.getZkServer().getZkAddress()
- + ")");
+ + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\", aliases=\"a_i=alias_a_i, a_s=name\", solrConnection=\""
+ + getSolrConnection().toString()
+ + "\")");
stream = new CloudSolrStream(expression, factory);
stream.setStreamContext(streamContext);
tuples = getTuples(stream);
@@ -450,9 +453,9 @@ public class StreamExpressionTest extends SolrCloudTestCase {
StreamExpressionParser.parse(
"search("
+ COLLECTIONORALIAS
- + ", q=\"id:(0 3 4)\", fl=\"id,a_s,a_i,a_f\", zkHost="
- + cluster.getZkServer().getZkAddress()
- + ", sort=\"a_f asc, a_i asc\")");
+ + ", q=\"id:(0 3 4)\", fl=\"id,a_s,a_i,a_f\", solrConnection=\""
+ + getSolrConnection().toString()
+ + "\", sort=\"a_f asc, a_i asc\")");
stream = new CloudSolrStream(expression, factory);
stream.setStreamContext(streamContext);
tuples = getTuples(stream);
@@ -465,9 +468,9 @@ public class StreamExpressionTest extends SolrCloudTestCase {
expression =
StreamExpressionParser.parse(
"search(collection1, fq=\"a_s:hello0\", fq=\"a_s:hello1\", q=\"id:(*)\", "
- + "zkHost="
- + cluster.getZkServer().getZkAddress()
- + ", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\")");
+ + "solrConnection=\""
+ + getSolrConnection().toString()
+ + "\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\")");
stream = new CloudSolrStream(expression, factory);
stream.setStreamContext(streamContext);
tuples = getTuples(stream);
@@ -477,9 +480,9 @@ public class StreamExpressionTest extends SolrCloudTestCase {
expression =
StreamExpressionParser.parse(
"search(collection1, fq=\"a_s:(hello0 OR hello1)\", q=\"id:(*)\", "
- + "zkHost="
- + cluster.getZkServer().getZkAddress()
- + ", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\")");
+ + "solrConnection=\""
+ + getSolrConnection().toString()
+ + "\", fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\")");
stream = new CloudSolrStream(expression, factory);
stream.setStreamContext(streamContext);
tuples = getTuples(stream);
@@ -573,10 +576,9 @@ public class StreamExpressionTest extends SolrCloudTestCase {
StreamContext streamContext = new StreamContext();
SolrClientCache solrClientCache = new SolrClientCache();
streamContext.setSolrClientCache(solrClientCache);
-
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, solrConnection)
.withFunctionName("search", CloudSolrStream.class);
try {
// Basic test
@@ -652,7 +654,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, solrConnection)
.withFunctionName("random", RandomFacadeStream.class);
StreamContext context = new StreamContext();
@@ -873,7 +875,8 @@ public class StreamExpressionTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
+ .withDefaultSolrConnection(solrConnection)
+ .withCollectionUseThisConnection(COLLECTIONORALIAS, solrConnection)
.withFunctionName("stats", StatsStream.class)
.withFunctionName("sum", SumMetric.class)
.withFunctionName("min", MinMetric.class)
@@ -986,7 +989,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {
// Test with shards parameter
List<String> shardUrls =
TupleStream.getShards(
- cluster.getZkServer().getZkAddress(), COLLECTIONORALIAS, streamContext);
+ StreamExpressionTest.solrConnection, COLLECTIONORALIAS, streamContext);
expr =
"stats(myCollection, q=*:*, sum(a_i), sum(a_f), min(a_i), min(a_f), max(a_i), max(a_f), avg(a_i), avg(a_f), std(a_i), std(a_f), per(a_i, 50), per(a_f, 50), count(*))";
Map<String, List<String>> shardsMap = new HashMap<>();
@@ -1349,10 +1352,9 @@ public class StreamExpressionTest extends SolrCloudTestCase {
String clause;
TupleStream stream;
List<Tuple> tuples;
-
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("collection1", solrConnection)
.withFunctionName("facet", FacetStream.class)
.withFunctionName("sum", SumMetric.class)
.withFunctionName("min", MinMetric.class)
@@ -2163,8 +2165,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {
SolrClientCache solrClientCache = new SolrClientCache();
streamContext.setSolrClientCache(solrClientCache);
List<String> shardUrls =
- TupleStream.getShards(
- cluster.getZkServer().getZkAddress(), COLLECTIONORALIAS, streamContext);
+ TupleStream.getShards(solrConnection, COLLECTIONORALIAS, streamContext);
try {
StringBuilder buf = new StringBuilder();
@@ -2273,7 +2274,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("collection1", solrConnection)
.withFunctionName("facet", FacetStream.class)
.withFunctionName("sum", SumMetric.class)
.withFunctionName("min", MinMetric.class)
@@ -2549,7 +2550,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("collection1", solrConnection)
.withFunctionName("topic", TopicStream.class)
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("daemon", DaemonStream.class);
@@ -2728,7 +2729,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("collection1", solrConnection)
.withFunctionName("topic", TopicStream.class)
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("parallel", ParallelStream.class)
@@ -3683,8 +3684,8 @@ public class StreamExpressionTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())
- .withCollectionZkHost("destinationCollection", cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("collection1", solrConnection)
+ .withCollectionUseThisConnection("destinationCollection", solrConnection)
.withFunctionName("features", FeaturesSelectionStream.class)
.withFunctionName("train", TextLogitStream.class)
.withFunctionName("search", CloudSolrStream.class)
@@ -3812,8 +3813,8 @@ public class StreamExpressionTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())
- .withCollectionZkHost("destinationCollection", cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("collection1", solrConnection)
+ .withCollectionUseThisConnection("destinationCollection", solrConnection)
.withFunctionName("featuresSelection", FeaturesSelectionStream.class)
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("update", UpdateStream.class);
@@ -3891,8 +3892,8 @@ public class StreamExpressionTest extends SolrCloudTestCase {
StreamFactory factory =
new StreamFactory()
- .withCollectionZkHost("collection1", cluster.getZkServer().getZkAddress())
- .withDefaultZkHost(cluster.getZkServer().getZkAddress())
+ .withCollectionUseThisConnection("collection1", solrConnection)
+ .withDefaultSolrConnection(solrConnection)
.withFunctionName("significantTerms", SignificantTermsStream.class);
StreamContext streamContext = new StreamContext();
@@ -4007,7 +4008,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {
// Test with shards parameter
List<String> shardUrls =
TupleStream.getShards(
- cluster.getZkServer().getZkAddress(), COLLECTIONORALIAS, streamContext);
+ StreamExpressionTest.solrConnection, COLLECTIONORALIAS, streamContext);
Map<String, List<String>> shardsMap = new HashMap<>();
shardsMap.put("myCollection", shardUrls);
diff --git a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionToExplanationTest.java b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionToExplanationTest.java
index 178f7e08ee6..a203cac8cd4 100644
--- a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionToExplanationTest.java
+++ b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionToExplanationTest.java
@@ -17,6 +17,7 @@
package org.apache.solr.client.solrj.io.stream;
import org.apache.solr.SolrTestCase;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.ops.GroupOperation;
import org.apache.solr.client.solrj.io.stream.expr.Explanation;
import org.apache.solr.client.solrj.io.stream.expr.StreamExplanation;
@@ -38,10 +39,11 @@ public class StreamExpressionToExplanationTest extends SolrTestCase {
public StreamExpressionToExplanationTest() {
super();
+ var solrConnection = CloudSolrClient.CloudSolrClientConnection.parse("testhost:1234");
factory =
new StreamFactory()
- .withCollectionZkHost("collection1", "testhost:1234")
- .withCollectionZkHost("collection2", "testhost:1234")
+ .withCollectionUseThisConnection("collection1", solrConnection)
+ .withCollectionUseThisConnection("collection2", solrConnection)
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("select", SelectStream.class)
.withFunctionName("merge", MergeStream.class)
diff --git a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionToExpressionTest.java b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionToExpressionTest.java
index 178592c481c..89afa3a3870 100644
--- a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionToExpressionTest.java
+++ b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionToExpressionTest.java
@@ -17,6 +17,7 @@
package org.apache.solr.client.solrj.io.stream;
import org.apache.solr.SolrTestCase;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.ops.GroupOperation;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionParser;
@@ -37,11 +38,11 @@ public class StreamExpressionToExpressionTest extends SolrTestCase {
public StreamExpressionToExpressionTest() {
super();
-
+ var solrConnection = CloudSolrClient.CloudSolrClientConnection.parse("testhost:1234");
factory =
new StreamFactory()
- .withCollectionZkHost("collection1", "testhost:1234")
- .withCollectionZkHost("collection2", "testhost:1234")
+ .withCollectionUseThisConnection("collection1", solrConnection)
+ .withCollectionUseThisConnection("collection2", solrConnection)
.withFunctionName("search", CloudSolrStream.class)
.withFunctionName("select", SelectStream.class)
.withFunctionName("merge", MergeStream.class)
diff --git a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamingTest.java b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamingTest.java
index 2720b6e5a49..c838af76ca4 100644
--- a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamingTest.java
+++ b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamingTest.java
@@ -31,6 +31,7 @@ import java.util.Set;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.SolrClientCache;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.comp.ComparatorOrder;
@@ -90,6 +91,7 @@ public class StreamingTest extends SolrCloudTestCase {
.withFunctionName("parallel", ParallelStream.class);
private static String zkHost;
+ private static CloudSolrClient.CloudSolrClientConnection solrConnection;
private static int numWorkers;
private static boolean useAlias;
@@ -124,7 +126,8 @@ public class StreamingTest extends SolrCloudTestCase {
}
zkHost = cluster.getZkServer().getZkAddress();
- streamFactory.withCollectionZkHost(COLLECTIONORALIAS, zkHost);
+ solrConnection = CloudSolrClient.CloudSolrClientConnection.parse(zkHost);
+ streamFactory.withCollectionUseThisConnection(COLLECTIONORALIAS, solrConnection);
// Set up multi-replica collection
if (useAlias) {
@@ -139,7 +142,7 @@ public class StreamingTest extends SolrCloudTestCase {
CollectionAdminRequest.createAlias(MULTI_REPLICA_COLLECTIONORALIAS, collection)
.process(cluster.getSolrClient());
}
- streamFactory.withCollectionZkHost(MULTI_REPLICA_COLLECTIONORALIAS, zkHost);
+ streamFactory.withCollectionUseThisConnection(MULTI_REPLICA_COLLECTIONORALIAS, solrConnection);
}
private static final String id = "id";
@@ -180,7 +183,7 @@ public class StreamingTest extends SolrCloudTestCase {
streamContext.setSolrClientCache(solrClientCache);
try {
SolrParams sParams = params("q", "*:*", "fl", "id,a_s,a_i,a_f", "sort", "a_f asc,a_i asc");
- CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);
+ CloudSolrStream stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParams);
UniqueStream ustream = new UniqueStream(stream, new FieldEqualitor("a_f"));
ustream.setStreamContext(streamContext);
List<Tuple> tuples = getTuples(ustream);
@@ -201,7 +204,7 @@ public class StreamingTest extends SolrCloudTestCase {
// The constructor will throw an exception if the sort fields do not the
// a value in the field list.
- CloudSolrStream stream = new CloudSolrStream("", "collection1", sParams);
+ CloudSolrStream stream = new CloudSolrStream(solrConnection, "collection1", sParams);
stream.close();
}
@@ -226,7 +229,7 @@ public class StreamingTest extends SolrCloudTestCase {
"none",
"qt",
"/export");
- CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
+ CloudSolrStream stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsA);
ParallelStream pstream =
parallelStream(stream, new FieldComparator("a_s", ComparatorOrder.ASCENDING));
attachStreamFactory(pstream);
@@ -272,7 +275,7 @@ public class StreamingTest extends SolrCloudTestCase {
"a_f",
"qt",
"/export");
- CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);
+ CloudSolrStream stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParams);
UniqueStream ustream = new UniqueStream(stream, new FieldEqualitor("a_f"));
ParallelStream pstream =
parallelStream(ustream, new FieldComparator("a_f", ComparatorOrder.ASCENDING));
@@ -306,7 +309,7 @@ public class StreamingTest extends SolrCloudTestCase {
.add(id, "8", "a_ss", "hello1", "a_i", "13", "a_f", "4")
.commit(cluster.getSolrClient(), COLLECTIONORALIAS);
- streamFactory.withCollectionZkHost(COLLECTIONORALIAS, zkHost);
+ streamFactory.withCollectionUseThisConnection(COLLECTIONORALIAS, solrConnection);
StreamContext streamContext = new StreamContext();
SolrClientCache solrClientCache = new SolrClientCache();
@@ -326,7 +329,7 @@ public class StreamingTest extends SolrCloudTestCase {
"a_ss:hello0",
"fq",
"a_ss:hello1"));
- CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, params);
+ CloudSolrStream stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, params);
stream.setStreamContext(streamContext);
List<Tuple> tuples = getTuples(stream);
assertEquals("Multiple fq clauses should have been honored", 1, tuples.size());
@@ -352,7 +355,7 @@ public class StreamingTest extends SolrCloudTestCase {
streamContext.setSolrClientCache(solrClientCache);
try {
SolrParams sParams = params("q", "*:*", "fl", "id,a_s,a_i", "sort", "a_i asc");
- CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);
+ CloudSolrStream stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParams);
RankStream rstream =
new RankStream(stream, 3, new FieldComparator("a_i", ComparatorOrder.DESCENDING));
rstream.setStreamContext(streamContext);
@@ -396,7 +399,7 @@ public class StreamingTest extends SolrCloudTestCase {
"a_i",
"qt",
"/export");
- CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);
+ CloudSolrStream stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParams);
RankStream rstream =
new RankStream(stream, 11, new FieldComparator("a_i", ComparatorOrder.DESCENDING));
ParallelStream pstream =
@@ -425,7 +428,7 @@ public class StreamingTest extends SolrCloudTestCase {
// Test with spaces in the parameter lists.
SolrParams sParamsA =
params("q", "*:*", "fl", "id,a_s, a_i,a_f", "sort", "a_s asc,a_f asc");
- CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
+ CloudSolrStream stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsA);
stream.setTrace(true);
stream.setStreamContext(streamContext);
List<Tuple> tuples = getTuples(stream);
@@ -451,7 +454,7 @@ public class StreamingTest extends SolrCloudTestCase {
// Test with spaces in the parameter lists.
SolrParams sParamsA =
params("q", "*:*", "fl", "id,a_s, a_i, a_f", "sort", "a_s asc , a_f asc");
- CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
+ CloudSolrStream stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsA);
ReducerStream rstream =
new ReducerStream(
stream,
@@ -477,7 +480,7 @@ public class StreamingTest extends SolrCloudTestCase {
// Test with spaces in the parameter lists using a comparator
sParamsA = params("q", "*:*", "fl", "id,a_s, a_i, a_f", "sort", "a_s asc , a_f asc");
- stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
+ stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsA);
rstream =
new ReducerStream(
stream,
@@ -518,7 +521,7 @@ public class StreamingTest extends SolrCloudTestCase {
// Test with spaces in the parameter lists.
SolrParams sParamsA =
params("q", "blah", "fl", "id,a_s, a_i, a_f", "sort", "a_s asc , a_f asc");
- CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
+ CloudSolrStream stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsA);
ReducerStream rstream =
new ReducerStream(
stream,
@@ -555,7 +558,7 @@ public class StreamingTest extends SolrCloudTestCase {
"a_s",
"qt",
"/export");
- CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
+ CloudSolrStream stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsA);
ReducerStream rstream =
new ReducerStream(
@@ -596,7 +599,7 @@ public class StreamingTest extends SolrCloudTestCase {
"a_s",
"qt",
"/export");
- stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
+ stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsA);
rstream =
new ReducerStream(
@@ -637,7 +640,7 @@ public class StreamingTest extends SolrCloudTestCase {
try {
// Test an error that originates from the /select handler
SolrParams sParamsA = params("q", "*:*", "fl", "a_s,a_i,a_f,blah", "sort", "blah asc");
- CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
+ CloudSolrStream stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsA);
ExceptionStream estream = new ExceptionStream(stream);
estream.setStreamContext(streamContext);
Tuple t = getTuple(estream);
@@ -646,7 +649,7 @@ public class StreamingTest extends SolrCloudTestCase {
assertTrue(t.getException().contains("sort param field can't be found: blah"));
sParamsA = params("q", "*:*", "fl", "a_s,a_i,a_f,blah", "sort", "blah asc", "wt", "javabin");
- stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
+ stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsA);
estream = new ExceptionStream(stream);
estream.setStreamContext(streamContext);
t = getTuple(estream);
@@ -656,7 +659,7 @@ public class StreamingTest extends SolrCloudTestCase {
// Test an error that originates from the /export handler
sParamsA = params("q", "*:*", "fl", "a_s,a_i,a_f,blah", "sort", "blah asc", "qt", "/export");
- stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
+ stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsA);
estream = new ExceptionStream(stream);
estream.setStreamContext(streamContext);
t = getTuple(estream);
@@ -677,7 +680,7 @@ public class StreamingTest extends SolrCloudTestCase {
"/export",
"wt",
"javabin");
- stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
+ stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsA);
estream = new ExceptionStream(stream);
estream.setStreamContext(streamContext);
t = getTuple(estream);
@@ -696,10 +699,10 @@ public class StreamingTest extends SolrCloudTestCase {
helloDocsUpdateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);
SolrParams sParamsA = params("q", "*:*", "fl", "a_s,a_i,a_f,blah", "sort", "blah asc");
- CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
+ CloudSolrStream stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsA);
ParallelStream pstream =
new ParallelStream(
- zkHost,
+ solrConnection,
COLLECTIONORALIAS,
stream,
2,
@@ -724,10 +727,10 @@ public class StreamingTest extends SolrCloudTestCase {
"a_s",
"qt",
"/export");
- stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
+ stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsA);
pstream =
new ParallelStream(
- zkHost,
+ solrConnection,
COLLECTIONORALIAS,
stream,
2,
@@ -751,10 +754,10 @@ public class StreamingTest extends SolrCloudTestCase {
"/export",
"partitionKeys",
"a_s");
- stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
+ stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsA);
pstream =
new ParallelStream(
- zkHost,
+ solrConnection,
COLLECTIONORALIAS,
stream,
2,
@@ -791,7 +794,8 @@ public class StreamingTest extends SolrCloudTestCase {
new CountMetric()
};
- StatsStream statsStream = new StatsStream(zkHost, COLLECTIONORALIAS, sParamsA, metrics);
+ StatsStream statsStream =
+ new StatsStream(solrConnection, COLLECTIONORALIAS, sParamsA, metrics);
statsStream.setStreamContext(streamContext);
List<Tuple> tuples = getTuples(statsStream);
@@ -854,7 +858,8 @@ public class StreamingTest extends SolrCloudTestCase {
FieldComparator[] sorts = {new FieldComparator("sum(a_i)", ComparatorOrder.ASCENDING)};
FacetStream facetStream =
- new FacetStream(zkHost, COLLECTIONORALIAS, sParamsA, buckets, metrics, sorts, 100);
+ new FacetStream(
+ solrConnection, COLLECTIONORALIAS, sParamsA, buckets, metrics, sorts, 100);
List<Tuple> tuples = getTuples(facetStream);
@@ -936,7 +941,8 @@ public class StreamingTest extends SolrCloudTestCase {
sorts[0] = new FieldComparator("sum(a_i)", ComparatorOrder.DESCENDING);
facetStream =
- new FacetStream(zkHost, COLLECTIONORALIAS, sParamsA, buckets, metrics, sorts, 100);
+ new FacetStream(
+ solrConnection, COLLECTIONORALIAS, sParamsA, buckets, metrics, sorts, 100);
tuples = getTuples(facetStream);
@@ -1018,7 +1024,8 @@ public class StreamingTest extends SolrCloudTestCase {
sorts[0] = new FieldComparator("a_s", ComparatorOrder.DESCENDING);
facetStream =
- new FacetStream(zkHost, COLLECTIONORALIAS, sParamsA, buckets, metrics, sorts, 100);
+ new FacetStream(
+ solrConnection, COLLECTIONORALIAS, sParamsA, buckets, metrics, sorts, 100);
facetStream.setStreamContext(streamContext);
tuples = getTuples(facetStream);
@@ -1099,7 +1106,8 @@ public class StreamingTest extends SolrCloudTestCase {
sorts[0] = new FieldComparator("a_s", ComparatorOrder.ASCENDING);
facetStream =
- new FacetStream(zkHost, COLLECTIONORALIAS, sParamsA, buckets, metrics, sorts, 100);
+ new FacetStream(
+ solrConnection, COLLECTIONORALIAS, sParamsA, buckets, metrics, sorts, 100);
facetStream.setStreamContext(streamContext);
tuples = getTuples(facetStream);
@@ -1177,7 +1185,7 @@ public class StreamingTest extends SolrCloudTestCase {
sorts[0] = new FieldComparator("a_s", ComparatorOrder.ASCENDING);
facetStream =
- new FacetStream(zkHost, COLLECTIONORALIAS, sParamsA, buckets, metrics, sorts, -1);
+ new FacetStream(solrConnection, COLLECTIONORALIAS, sParamsA, buckets, metrics, sorts, -1);
facetStream.setStreamContext(streamContext);
tuples = getTuples(facetStream);
@@ -1240,7 +1248,8 @@ public class StreamingTest extends SolrCloudTestCase {
// }
// SolrParams exportParams = params("q", "*:*", "qt", "/export", "fl", "id," + field, "sort",
// field + " " + sortDir + ",id asc");
- // try (CloudSolrStream solrStream = new CloudSolrStream(zkHost, COLLECTIONORALIAS,
+ // try (CloudSolrStream solrStream = new CloudSolrStream(solrClientConnection,
+ // COLLECTIONORALIAS,
// exportParams)) {
// List<Tuple> tuples = getTuples(solrStream);
// assertEquals("There should be exactly 32 responses returned", 32, tuples.size());
@@ -1276,7 +1285,7 @@ public class StreamingTest extends SolrCloudTestCase {
SolrClientCache solrClientCache = new SolrClientCache();
streamContext.setSolrClientCache(solrClientCache);
try (CloudSolrStream solrStream =
- new CloudSolrStream(zkHost, COLLECTIONORALIAS, exportParams)) {
+ new CloudSolrStream(solrConnection, COLLECTIONORALIAS, exportParams)) {
solrStream.setStreamContext(streamContext);
List<Tuple> tuples = getTuples(solrStream);
assertEquals("There should be exactly 32 responses returned", 32, tuples.size());
@@ -1326,7 +1335,8 @@ public class StreamingTest extends SolrCloudTestCase {
SolrClientCache solrClientCache = new SolrClientCache();
streamContext.setSolrClientCache(solrClientCache);
- try (CloudSolrStream solrStream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams)) {
+ try (CloudSolrStream solrStream =
+ new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParams)) {
solrStream.setStreamContext(streamContext);
List<Tuple> tuples = getTuples(solrStream);
assertEquals("There should be exactly 32 responses returned", 32, tuples.size());
@@ -1490,7 +1500,8 @@ public class StreamingTest extends SolrCloudTestCase {
};
FacetStream facetStream =
- new FacetStream(zkHost, COLLECTIONORALIAS, sParamsA, buckets, metrics, sorts, 100);
+ new FacetStream(
+ solrConnection, COLLECTIONORALIAS, sParamsA, buckets, metrics, sorts, 100);
facetStream.setStreamContext(streamContext);
List<Tuple> tuples = getTuples(facetStream);
assertEquals(6, tuples.size());
@@ -1564,7 +1575,8 @@ public class StreamingTest extends SolrCloudTestCase {
sorts[0] = new FieldComparator("level1_s", ComparatorOrder.DESCENDING);
sorts[1] = new FieldComparator("level2_s", ComparatorOrder.DESCENDING);
facetStream =
- new FacetStream(zkHost, COLLECTIONORALIAS, sParamsA, buckets, metrics, sorts, 100);
+ new FacetStream(
+ solrConnection, COLLECTIONORALIAS, sParamsA, buckets, metrics, sorts, 100);
facetStream.setStreamContext(streamContext);
tuples = getTuples(facetStream);
assertEquals(6, tuples.size());
@@ -1649,7 +1661,7 @@ public class StreamingTest extends SolrCloudTestCase {
try {
SolrParams sParamsA = params("q", "*:*", "fl", "a_s,a_i,a_f,b_f", "sort", "a_s asc");
- CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
+ CloudSolrStream stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsA);
Bucket[] buckets = {new Bucket("a_s")};
@@ -1787,7 +1799,7 @@ public class StreamingTest extends SolrCloudTestCase {
.commit(cluster.getSolrClient(), COLLECTIONORALIAS);
sParamsA = params("q", "*:*", "fl", "a_s,a_i,a_f,b_f", "sort", "a_s asc", "qt", "/export");
- stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
+ stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsA);
Bucket[] buckets1 = {new Bucket("a_s")};
Metric[] metrics1 = {
@@ -1856,7 +1868,13 @@ public class StreamingTest extends SolrCloudTestCase {
TopicStream topicStream =
new TopicStream(
- zkHost, COLLECTIONORALIAS, COLLECTIONORALIAS, "50000000", -1, 1000000, sParams);
+ solrConnection,
+ COLLECTIONORALIAS,
+ COLLECTIONORALIAS,
+ "50000000",
+ -1,
+ 1000000,
+ sParams);
DaemonStream daemonStream = new DaemonStream(topicStream, "daemon1", 1000, 500);
daemonStream.setStreamContext(context);
@@ -1958,7 +1976,7 @@ public class StreamingTest extends SolrCloudTestCase {
"a_s",
"qt",
"/export");
- CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
+ CloudSolrStream stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsA);
Bucket[] buckets = {new Bucket("a_s")};
@@ -1980,8 +1998,7 @@ public class StreamingTest extends SolrCloudTestCase {
assertEquals(3, tuples.size());
List<String> shardUrls =
- TupleStream.getShards(
- cluster.getZkServer().getZkAddress(), COLLECTIONORALIAS, streamContext);
+ TupleStream.getShards(solrConnection, COLLECTIONORALIAS, streamContext);
ModifiableSolrParams solrParams = new ModifiableSolrParams();
solrParams.add("qt", "/stream");
solrParams.add(
@@ -2060,7 +2077,7 @@ public class StreamingTest extends SolrCloudTestCase {
"a_s",
"qt",
"/export");
- CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
+ CloudSolrStream stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsA);
Bucket[] buckets = {new Bucket("a_s")};
@@ -2188,7 +2205,7 @@ public class StreamingTest extends SolrCloudTestCase {
"a_s",
"qt",
"/export");
- CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
+ CloudSolrStream stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsA);
ReducerStream rstream =
new ReducerStream(
stream,
@@ -2221,7 +2238,7 @@ public class StreamingTest extends SolrCloudTestCase {
try {
SolrParams sParams =
params("q", "*:*", "fl", "id,a_s,a_i,a_f,s_multi,i_multi,f_multi", "sort", "a_s asc");
- CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);
+ CloudSolrStream stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParams);
stream.setStreamContext(streamContext);
List<Tuple> tuples = getTuples(stream);
Tuple tuple = tuples.get(0);
@@ -2269,10 +2286,10 @@ public class StreamingTest extends SolrCloudTestCase {
try {
// Test ascending
SolrParams sParamsA = params("q", "id:(4 1)", "fl", "id,a_s,a_i", "sort", "a_i asc");
- CloudSolrStream streamA = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
+ CloudSolrStream streamA = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsA);
SolrParams sParamsB = params("q", "id:(0 2 3)", "fl", "id,a_s,a_i", "sort", "a_i asc");
- CloudSolrStream streamB = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsB);
+ CloudSolrStream streamB = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsB);
MergeStream mstream =
new MergeStream(streamA, streamB, new FieldComparator("a_i", ComparatorOrder.ASCENDING));
@@ -2284,10 +2301,10 @@ public class StreamingTest extends SolrCloudTestCase {
// Test descending
sParamsA = params("q", "id:(4 1)", "fl", "id,a_s,a_i", "sort", "a_i desc");
- streamA = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
+ streamA = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsA);
sParamsB = params("q", "id:(0 2 3)", "fl", "id,a_s,a_i", "sort", "a_i desc");
- streamB = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsB);
+ streamB = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsB);
mstream =
new MergeStream(streamA, streamB, new FieldComparator("a_i", ComparatorOrder.DESCENDING));
@@ -2300,10 +2317,10 @@ public class StreamingTest extends SolrCloudTestCase {
// Test compound sort
sParamsA = params("q", "id:(2 4 1)", "fl", "id,a_s,a_i,a_f", "sort", "a_f asc,a_i asc");
- streamA = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
+ streamA = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsA);
sParamsB = params("q", "id:(0 3)", "fl", "id,a_s,a_i,a_f", "sort", "a_f asc,a_i asc");
- streamB = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsB);
+ streamB = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsB);
mstream =
new MergeStream(
@@ -2319,10 +2336,10 @@ public class StreamingTest extends SolrCloudTestCase {
assertOrder(tuples, 0, 2, 1, 3, 4);
sParamsA = params("q", "id:(2 4 1)", "fl", "id,a_s,a_i,a_f", "sort", "a_f asc,a_i desc");
- streamA = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
+ streamA = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsA);
sParamsB = params("q", "id:(0 3)", "fl", "id,a_s,a_i,a_f", "sort", "a_f asc,a_i desc");
- streamB = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsB);
+ streamB = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsB);
mstream =
new MergeStream(
@@ -2375,7 +2392,7 @@ public class StreamingTest extends SolrCloudTestCase {
"a_i",
"qt",
"/export");
- CloudSolrStream streamA = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
+ CloudSolrStream streamA = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsA);
SolrParams sParamsB =
params(
@@ -2389,7 +2406,7 @@ public class StreamingTest extends SolrCloudTestCase {
"a_i",
"qt",
"/export");
- CloudSolrStream streamB = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsB);
+ CloudSolrStream streamB = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsB);
MergeStream mstream =
new MergeStream(streamA, streamB, new FieldComparator("a_i", ComparatorOrder.ASCENDING));
@@ -2415,7 +2432,7 @@ public class StreamingTest extends SolrCloudTestCase {
"a_i",
"qt",
"/export");
- streamA = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
+ streamA = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsA);
sParamsB =
params(
@@ -2429,7 +2446,7 @@ public class StreamingTest extends SolrCloudTestCase {
"a_i",
"qt",
"/export");
- streamB = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsB);
+ streamB = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsB);
mstream =
new MergeStream(streamA, streamB, new FieldComparator("a_i", ComparatorOrder.DESCENDING));
@@ -2479,7 +2496,7 @@ public class StreamingTest extends SolrCloudTestCase {
"a_i",
"qt",
"/export");
- CloudSolrStream streamA = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
+ CloudSolrStream streamA = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsA);
SolrParams sParamsB =
params(
@@ -2493,7 +2510,7 @@ public class StreamingTest extends SolrCloudTestCase {
"a_i",
"qt",
"/export");
- CloudSolrStream streamB = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsB);
+ CloudSolrStream streamB = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParamsB);
MergeStream mstream =
new MergeStream(streamA, streamB, new FieldComparator("a_i", ComparatorOrder.ASCENDING));
@@ -2529,7 +2546,7 @@ public class StreamingTest extends SolrCloudTestCase {
try {
SolrParams sParams = params("q", "*:*", "fl", "id,a_s,a_i", "sort", "a_i desc");
- CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);
+ CloudSolrStream stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParams);
stream.setStreamContext(streamContext);
List<Tuple> tuples = getTuples(stream);
@@ -2538,7 +2555,7 @@ public class StreamingTest extends SolrCloudTestCase {
// With Ascending Sort
sParams = params("q", "*:*", "fl", "id,a_s,a_i", "sort", "a_i asc");
- stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);
+ stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParams);
stream.setStreamContext(streamContext);
tuples = getTuples(stream);
@@ -2547,7 +2564,7 @@ public class StreamingTest extends SolrCloudTestCase {
// Test compound sort
sParams = params("q", "*:*", "fl", "id,a_s,a_i,a_f", "sort", "a_f asc,a_i desc");
- stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);
+ stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParams);
stream.setStreamContext(streamContext);
tuples = getTuples(stream);
@@ -2555,7 +2572,7 @@ public class StreamingTest extends SolrCloudTestCase {
assertOrder(tuples, 2, 0, 1, 3, 4);
sParams = params("q", "*:*", "fl", "id,a_s,a_i,a_f", "sort", "a_f asc,a_i asc");
- stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);
+ stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParams);
stream.setStreamContext(streamContext);
tuples = getTuples(stream);
@@ -2599,7 +2616,7 @@ public class StreamingTest extends SolrCloudTestCase {
try {
SolrParams sParams = params("q", "*:*", "fl", "id,a_s,a_i", "sort", "a_i desc");
- CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);
+ CloudSolrStream stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParams);
stream.setStreamContext(streamContext);
List<Tuple> tuples = getTuples(stream);
@@ -2620,7 +2637,7 @@ public class StreamingTest extends SolrCloudTestCase {
// With Ascending Sort
sParams = params("q", "*:*", "fl", "id,a_s,a_i", "sort", "a_i asc");
- stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);
+ stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParams);
stream.setStreamContext(streamContext);
tuples = getTuples(stream);
@@ -2641,7 +2658,7 @@ public class StreamingTest extends SolrCloudTestCase {
// Test compound sort
sParams = params("q", "*:*", "fl", "id,a_s,a_i,a_f", "sort", "a_f asc,a_i desc");
- stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);
+ stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParams);
stream.setStreamContext(streamContext);
tuples = getTuples(stream);
@@ -2661,7 +2678,7 @@ public class StreamingTest extends SolrCloudTestCase {
}
sParams = params("q", "*:*", "fl", "id,a_s,a_i,a_f", "sort", "a_f asc,a_i asc");
- stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);
+ stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParams);
stream.setStreamContext(streamContext);
tuples = getTuples(stream);
@@ -2708,7 +2725,7 @@ public class StreamingTest extends SolrCloudTestCase {
StreamContext streamContext = new StreamContext();
SolrClientCache solrClientCache = new SolrClientCache();
streamContext.setSolrClientCache(solrClientCache);
- CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);
+ CloudSolrStream stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParams);
try {
stream.setStreamContext(streamContext);
@@ -2719,7 +2736,7 @@ public class StreamingTest extends SolrCloudTestCase {
// Basic CloudSolrStream Test bools desc
sParams = params("q", "*:*", "qt", which, "fl", "id,b_sing", "sort", "b_sing desc,id desc");
- stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);
+ stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParams);
stream.setStreamContext(streamContext);
tuples = getTuples(stream);
@@ -2728,7 +2745,7 @@ public class StreamingTest extends SolrCloudTestCase {
// Basic CloudSolrStream Test dates desc
sParams = params("q", "*:*", "qt", which, "fl", "id,dt_sing", "sort", "dt_sing desc,id asc");
- stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);
+ stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParams);
stream.setStreamContext(streamContext);
tuples = getTuples(stream);
@@ -2737,7 +2754,7 @@ public class StreamingTest extends SolrCloudTestCase {
// Basic CloudSolrStream Test ates desc
sParams = params("q", "*:*", "qt", which, "fl", "id,dt_sing", "sort", "dt_sing asc,id desc");
- stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams);
+ stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParams);
stream.setStreamContext(streamContext);
tuples = getTuples(stream);
@@ -2822,7 +2839,7 @@ public class StreamingTest extends SolrCloudTestCase {
"id,i_sing,i_multi,l_sing,l_multi,f_sing,f_multi,d_sing,d_multi,dt_sing,dt_multi,s_sing,s_multi,b_sing,b_multi",
"sort",
"i_sing asc");
- try (CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams)) {
+ try (CloudSolrStream stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParams)) {
stream.setStreamContext(streamContext);
Tuple tuple = getTuple(stream);
@@ -2940,10 +2957,7 @@ public class StreamingTest extends SolrCloudTestCase {
throws Exception {
List<String> shards =
TupleStream.getShards(
- cluster.getZkClient().getZkServerAddress(),
- MULTI_REPLICA_COLLECTIONORALIAS,
- streamContext,
- solrParams);
+ solrConnection, MULTI_REPLICA_COLLECTIONORALIAS, streamContext, solrParams);
for (String shard : shards) {
assertEquals(
shard,
@@ -3017,12 +3031,12 @@ public class StreamingTest extends SolrCloudTestCase {
private ParallelStream parallelStream(TupleStream stream, FieldComparator comparator)
throws IOException {
- return new ParallelStream(zkHost, COLLECTIONORALIAS, stream, numWorkers, comparator);
+ return new ParallelStream(solrConnection, COLLECTIONORALIAS, stream, numWorkers, comparator);
}
public void testCloudSolrStreamWithoutStreamContext() throws Exception {
SolrParams sParams = params("q", "*:*", "fl", "id", "sort", "id asc");
- try (CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParams)) {
+ try (CloudSolrStream stream = new CloudSolrStream(solrConnection, COLLECTIONORALIAS, sParams)) {
stream.open();
}
}
@@ -3032,7 +3046,7 @@ public class StreamingTest extends SolrCloudTestCase {
StreamContext streamContext = new StreamContext();
SolrClientCache solrClientCache = new SolrClientCache();
- solrClientCache.getCloudSolrClient(zkHost);
+ solrClientCache.getCloudSolrClient(solrConnection);
streamContext.setSolrClientCache(solrClientCache);
String expr =
@@ -3081,7 +3095,8 @@ public class StreamingTest extends SolrCloudTestCase {
Replica rr = zkStateReader.getCollection(coll).getReplicas().get(0);
streamContext.put("core", rr.core);
List<Replica> replicas =
- TupleStream.getReplicas(zkHost, coll, streamContext, new ModifiableSolrParams());
+ TupleStream.getReplicas(
+ solrConnection, coll, streamContext, new ModifiableSolrParams());
assertEquals(
"core filter for " + rr.core + " not applied for " + coll + "; replicas: " + replicas,
1,
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
index e701b68b726..69e5c8d5809 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
@@ -229,8 +229,17 @@ public abstract class CloudSolrClient extends SolrClient {
* @throws IllegalArgumentException if string is null, empty, or malformed
*/
public Builder(String connectionString) {
- CloudSolrClientConnection connection = CloudSolrClientConnection.parse(connectionString);
- if (connection.isZk()) {
+ this(CloudSolrClientConnection.parse(connectionString));
+ }
+
+ /**
+ * Creates a client builder from a {@link CloudSolrClientConnection}.
+ *
+ * @param connection instance of {@link CloudSolrClientConnection}, which can be obtained from
+ * the solr connection string or created via the constructor
+ */
+ public Builder(CloudSolrClientConnection connection) {
+ if (connection.isZookeeper()) {
this.zkHosts = connection.quorumItems();
this.zkChroot = connection.zkChroot();
} else {
@@ -1826,7 +1835,8 @@ public abstract class CloudSolrClient extends SolrClient {
}
/** Universal connection string parser logic. */
- public record CloudSolrClientConnection(boolean isZk, List<String> quorumItems, String zkChroot) {
+ public record CloudSolrClientConnection(
+ boolean isZookeeper, List<String> quorumItems, String zkChroot) {
public CloudSolrClientConnection {
if (quorumItems == null || quorumItems.isEmpty()) {
@@ -1871,5 +1881,10 @@ public abstract class CloudSolrClient extends SolrClient {
}
return new CloudSolrClientConnection(false, quorumItems, null);
}
+
+ @Override
+ public String toString() {
+ return String.join(",", quorumItems) + (isZookeeper && zkChroot != null ? zkChroot : "");
+ }
}
}
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientConnectionTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientConnectionTest.java
index f65a83cfe0e..d1c921b61d8 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientConnectionTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientConnectionTest.java
@@ -36,10 +36,11 @@ public class CloudSolrClientConnectionTest extends SolrTestCase {
CloudSolrClient.CloudSolrClientConnection parsed =
CloudSolrClient.CloudSolrClientConnection.parse(
"zookeeper1:2181,zookeeper2:2181,zookeeper3:2181/solr");
- Assert.assertTrue(parsed.isZk());
+ Assert.assertTrue(parsed.isZookeeper());
List<String> expectedQuorum = List.of("zookeeper1:2181", "zookeeper2:2181", "zookeeper3:2181");
Assert.assertTrue(collectionEqual(expectedQuorum, parsed.quorumItems()));
Assert.assertEquals("/solr", parsed.zkChroot());
+ Assert.assertEquals("zookeeper1:2181,zookeeper2:2181,zookeeper3:2181/solr", parsed.toString());
}
@Test
@@ -47,10 +48,11 @@ public class CloudSolrClientConnectionTest extends SolrTestCase {
CloudSolrClient.CloudSolrClientConnection parsed =
CloudSolrClient.CloudSolrClientConnection.parse(
"192.0.2.10:2181,192.0.2.11:2181,192.0.2.12:2181/solr");
- Assert.assertTrue(parsed.isZk());
+ Assert.assertTrue(parsed.isZookeeper());
List<String> expectedQuorum = List.of("192.0.2.10:2181", "192.0.2.11:2181", "192.0.2.12:2181");
Assert.assertTrue(collectionEqual(expectedQuorum, parsed.quorumItems()));
Assert.assertEquals("/solr", parsed.zkChroot());
+ Assert.assertEquals("192.0.2.10:2181,192.0.2.11:2181,192.0.2.12:2181/solr", parsed.toString());
}
@Test
@@ -60,7 +62,7 @@ public class CloudSolrClientConnectionTest extends SolrTestCase {
"[2001:db8:85a3::8a2e:370:7334]:2181,"
+ "[2001:db8:85a3::8a2e:370:7335]:2181,"
+ "[2001:db8:85a3::8a2e:370:7336]:2181/solr");
- Assert.assertTrue(parsed.isZk());
+ Assert.assertTrue(parsed.isZookeeper());
List<String> expectedQuorum =
List.of(
"[2001:db8:85a3::8a2e:370:7334]:2181",
@@ -68,6 +70,11 @@ public class CloudSolrClientConnectionTest extends SolrTestCase {
"[2001:db8:85a3::8a2e:370:7336]:2181");
Assert.assertTrue(collectionEqual(expectedQuorum, parsed.quorumItems()));
Assert.assertEquals("/solr", parsed.zkChroot());
+ Assert.assertEquals(
+ "[2001:db8:85a3::8a2e:370:7334]:2181,"
+ + "[2001:db8:85a3::8a2e:370:7335]:2181,"
+ + "[2001:db8:85a3::8a2e:370:7336]:2181/solr",
+ parsed.toString());
}
@Test
@@ -75,10 +82,11 @@ public class CloudSolrClientConnectionTest extends SolrTestCase {
CloudSolrClient.CloudSolrClientConnection parsed =
CloudSolrClient.CloudSolrClientConnection.parse(
"zookeeper1:2181,zookeeper2:2181,zookeeper3:2181");
- Assert.assertTrue(parsed.isZk());
+ Assert.assertTrue(parsed.isZookeeper());
List<String> expectedQuorum = List.of("zookeeper1:2181", "zookeeper2:2181", "zookeeper3:2181");
Assert.assertTrue(collectionEqual(expectedQuorum, parsed.quorumItems()));
Assert.assertNull(parsed.zkChroot());
+ Assert.assertEquals("zookeeper1:2181,zookeeper2:2181,zookeeper3:2181", parsed.toString());
}
@Test
@@ -86,11 +94,13 @@ public class CloudSolrClientConnectionTest extends SolrTestCase {
CloudSolrClient.CloudSolrClientConnection parsed =
CloudSolrClient.CloudSolrClientConnection.parse(
"http://solr1:8983/solr,http://solr2:8983/solr,http://solr3:8983/solr");
- Assert.assertFalse(parsed.isZk());
+ Assert.assertFalse(parsed.isZookeeper());
List<String> expectedQuorum =
List.of("http://solr1:8983/solr", "http://solr2:8983/solr", "http://solr3:8983/solr");
Assert.assertTrue(collectionEqual(expectedQuorum, parsed.quorumItems()));
Assert.assertNull(parsed.zkChroot());
+ Assert.assertEquals(
+ "http://solr1:8983/solr,http://solr2:8983/solr,http://solr3:8983/solr", parsed.toString());
}
@Test
@@ -98,11 +108,14 @@ public class CloudSolrClientConnectionTest extends SolrTestCase {
CloudSolrClient.CloudSolrClientConnection parsed =
CloudSolrClient.CloudSolrClientConnection.parse(
"https://solr1:8983/solr,https://solr2:8983/solr,https://solr3:8983/solr");
- Assert.assertFalse(parsed.isZk());
+ Assert.assertFalse(parsed.isZookeeper());
List<String> expectedQuorum =
List.of("https://solr1:8983/solr", "https://solr2:8983/solr", "https://solr3:8983/solr");
Assert.assertTrue(collectionEqual(expectedQuorum, parsed.quorumItems()));
Assert.assertNull(parsed.zkChroot());
+ Assert.assertEquals(
+ "https://solr1:8983/solr,https://solr2:8983/solr,https://solr3:8983/solr",
+ parsed.toString());
}
@Test
@@ -112,7 +125,7 @@ public class CloudSolrClientConnectionTest extends SolrTestCase {
"http://192.0.2.10:8983/solr,"
+ "http://192.0.2.11:8983/solr,"
+ "http://192.0.2.12:8983/solr");
- Assert.assertFalse(parsed.isZk());
+ Assert.assertFalse(parsed.isZookeeper());
List<String> expectedQuorum =
List.of(
"http://192.0.2.10:8983/solr",
@@ -120,6 +133,11 @@ public class CloudSolrClientConnectionTest extends SolrTestCase {
"http://192.0.2.12:8983/solr");
Assert.assertTrue(collectionEqual(expectedQuorum, parsed.quorumItems()));
Assert.assertNull(parsed.zkChroot());
+ Assert.assertEquals(
+ "http://192.0.2.10:8983/solr,"
+ + "http://192.0.2.11:8983/solr,"
+ + "http://192.0.2.12:8983/solr",
+ parsed.toString());
}
@Test
@@ -129,7 +147,7 @@ public class CloudSolrClientConnectionTest extends SolrTestCase {
"http://[2001:db8:85a3::8a2e:370:7334]:8983/solr,"
+ "http://[2001:db8:85a3::8a2e:370:7334]:8983/solr,"
+ "http://[2001:db8:85a3::8a2e:370:7334]:8983/solr");
- Assert.assertFalse(parsed.isZk());
+ Assert.assertFalse(parsed.isZookeeper());
List<String> expectedQuorum =
List.of(
"http://[2001:db8:85a3::8a2e:370:7334]:8983/solr",
@@ -137,6 +155,11 @@ public class CloudSolrClientConnectionTest extends SolrTestCase {
"http://[2001:db8:85a3::8a2e:370:7334]:8983/solr");
Assert.assertTrue(collectionEqual(expectedQuorum, parsed.quorumItems()));
Assert.assertNull(parsed.zkChroot());
+ Assert.assertEquals(
+ "http://[2001:db8:85a3::8a2e:370:7334]:8983/solr,"
+ + "http://[2001:db8:85a3::8a2e:370:7334]:8983/solr,"
+ + "http://[2001:db8:85a3::8a2e:370:7334]:8983/solr",
+ parsed.toString());
}
@Test
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudTestCase.java b/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudTestCase.java
index 6f14fda6d15..0e5189d1f8e 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudTestCase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudTestCase.java
@@ -26,6 +26,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.invoke.MethodHandles;
+import java.net.URL;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
@@ -40,11 +41,13 @@ import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Predicate;
+import java.util.stream.Collectors;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.api.model.CoreStatusResponse;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.CoreAdminRequest;
import org.apache.solr.common.cloud.CollectionStatePredicate;
@@ -97,6 +100,23 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
return cluster.getZkStateReader().getZkClient();
}
+ protected CloudSolrClient.CloudSolrClientConnection getZookeeperSolrConnection() {
+ return CloudSolrClient.CloudSolrClientConnection.parse(cluster.getZkServer().getZkAddress());
+ }
+
+ protected CloudSolrClient.CloudSolrClientConnection getHttpSolrConnection() {
+ String connectionString =
+ cluster.getJettySolrRunners().stream()
+ .map(JettySolrRunner::getBaseUrl)
+ .map(URL::toString)
+ .collect(Collectors.joining(","));
+ return CloudSolrClient.CloudSolrClientConnection.parse(connectionString);
+ }
+
+ protected CloudSolrClient.CloudSolrClientConnection getSolrConnection() {
+ return random().nextBoolean() ? getHttpSolrConnection() : getZookeeperSolrConnection();
+ }
+
/**
* if the system property is not specified, default to false. The SystemProperty will be set in a
* beforeClass method.