Skip to content

Refactor CLI StreamTool SolrClientCache usage#4513

Open
dsmiley wants to merge 5 commits into
apache:mainfrom
dsmiley:StreamToolRefactor
Open

Refactor CLI StreamTool SolrClientCache usage#4513
dsmiley wants to merge 5 commits into
apache:mainfrom
dsmiley:StreamToolRefactor

Conversation

@dsmiley

@dsmiley dsmiley commented Jun 9, 2026

Copy link
Copy Markdown
Contributor
  • don't call SolrClientCache.setBasicAuthCredentials, to be deprecated soon (primary motivation). Instead set this on the client passed into SCC.
  • insist on a StreamContext, even if "remote mode". Code was a bit of a mess, doing redundant things or not doing what it "should" do

* don't call SolrClientCache.setBasicAuthCredentials
* insist on a StreamContext, even if "remote mode"
@dsmiley dsmiley requested a review from epugh June 9, 2026 13:38
@dsmiley

dsmiley commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Disclaimer: I haven't tested or even used it in a realistic way.

* @return the solrUrl in the format that Solr expects to see internally.
* @return a URL without any path, e.g. {@code http://localhost:8983}
*/
public static String normalizeSolrUrl(String solrUrl) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO these "normalize" methods are non-obvious since the URL normalization I'm used to seeing within Solr produce Solr URLs ending with "/solr". The javadoc here refers to what I'm used to as "legacy". Wow... am I a dinosaur or has v2 taken over? SolrJ didn't get the memo, I can tell you that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a little bit dinosaur... But not a lot dinosaur... We've been trying to simpliy users lives so they don't have to think about /solr or /v2 or /api all the time, unless is critical. So, we normalize to the root version, and then whatever tool can append what it needs...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO URL utility methods should be centralized to URLUtil. And naming reconsidered. If this method produces URLs without any path, then this is an opportunity to very simply state that in the method name rather than ambiguous "normalization", (it once wasn't ambiguous but in our transition period, is ambiguous).

@epugh

epugh commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Is #4510 potentially overlapping with this work?

}
HttpJettySolrClient client = jettyClientBuilder.build();

// subclass so we can ensure our client is closed when the cache is closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is some magic! If this isn't there, do we see errors?

}
return new PushBackStream(solrStream);
return new PushBackStream(
new SolrStream(solrUrl + "/solr/" + collection, params("qt", "/stream", "expr", expr)));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i feel like this should be "/solr/" + collection + "/stream", params("expr",expr)... but that is a bigger change.

Signed-off-by: Eric Pugh <epugh@opensourceconnections.com>
@epugh epugh self-assigned this Jun 10, 2026
@epugh

epugh commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

@dsmiley make sure after my chagnes we still are doing what you watned... I had to move some things around to make it work. Took opportunity to imrpvoe where validation of inputs takes place.

I marked it as no-changelog as this isnt' user facing.

@dsmiley dsmiley left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one little suggested change but looks good to me. Have you tried this code in any way? I have not.

Comment thread solr/core/src/java/org/apache/solr/cli/StreamTool.java Outdated
@epugh epugh requested a review from Copilot June 18, 2026 14:03
@epugh

epugh commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

i have tried it... so if thet ests all pass, I'll merge.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the bin/solr stream CLI implementation to stop using SolrClientCache.setBasicAuthCredentials (noted as soon-to-be deprecated) by instead wiring auth onto the HTTP client provided to SolrClientCache, and to consistently construct/use a StreamContext for both local and remote execution paths.

Changes:

  • Reworked StreamTool to always create a StreamContext (with a DefaultStreamFactory) and to pass a client-backed SolrClientCache through that context.
  • Removed direct credential setting on SolrStream in remote mode; credentials are now applied via the shared HTTP client/cached clients.
  • Updated CLIUtils.normalizeSolrUrl Javadocs to clarify the return shape (bare base URL without path).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
solr/core/src/java/org/apache/solr/cli/StreamTool.java Refactors StreamContext/SolrClientCache lifecycle, credential handling, and local vs remote stream construction.
solr/core/src/java/org/apache/solr/cli/CLIUtils.java Javadoc clarification for normalized Solr URL return format.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +174 to +177
if (expr.toLowerCase(Locale.ROOT).contains("stdin(")) {
throw new IllegalStateException(
"The stdin() expression is only usable with --worker local set up.");
}
Comment on lines +254 to +258
String credentials = cli.getOptionValue(CommonCLIOptions.CREDENTIALS_OPTION);
if (credentials != null) {
String[] userPass = credentials.split(":");
jettyClientBuilder.withBasicAuthCredentials(userPass[0], userPass[1]);
}
Comment on lines +264 to +268
@Override
public synchronized void close() {
super.close();
client.close();
}
Comment on lines +271 to +280
var solrConnection = CLIUtils.getSolrConnection(cli);
echoIfVerbose("Connecting to Solr at " + solrConnection);

StreamContext streamContext = new StreamContext();
streamContext.setSolrClientCache(solrClientCache);

StreamFactory streamFactory = new DefaultStreamFactory();
streamFactory.withDefaultSolrConnection(solrConnection);
streamContext.setStreamFactory(streamFactory);
return streamContext;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants