Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOLR-16829: Delegate arg parsing and help usage to java. (Round 1) #1670

Merged
merged 62 commits into from
Jul 6, 2023

Conversation

epugh
Copy link
Contributor

@epugh epugh commented May 29, 2023

https://issues.apache.org/jira/browse/SOLR-16829

Description

Going thorugh and attempting to remove the help usage (which seems to require also removing the arg parsing!)

I have migrated on the *nix side these commands:

bin/solr (by itself)
create
create_core
create_collection
delete
healthcheck
status

@Willdotwhite has done the same on the Windows side.

Solution

Please provide a short description of the approach taken to implement your solution.

Tests

Please describe the tests you've developed or run to confirm this patch implements the feature or solves the problem.

Checklist

Please review the following and check all that apply:

  • I have reviewed the guidelines for How to Contribute and my code conforms to the standards described there to the best of my ability.
  • I have created a Jira issue and added the issue ID to my pull request title.
  • I have given Solr maintainers access to contribute to my PR branch. (optional but recommended)
  • I have developed this patch against the main branch.
  • I have run ./gradlew check.
  • I have added tests for my changes.
  • I have added documentation for the Reference Guide

@epugh epugh marked this pull request as draft May 29, 2023 23:06

private String ensureConfDirExists(String confDirName, String solrInstallDir) {
final String fullConfDir = solrInstallDir + "/server/solr/configsets/" + confDirName;
if (!new File(fullConfDir).isDirectory()) {
Copy link

Choose a reason for hiding this comment

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

9% of developers fix this issue

PATH_TRAVERSAL_IN: This API (java/io/File.(Ljava/lang/String;)V) reads a file whose location might be specified by user input


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.

cli.getOptionValue("confdir", SolrCLI.DEFAULT_CONFIG_SET); // CREATE_CONFDIR

// we allow them to pass a directory instead of a configset name
File configsetDir = new File(confDirName);
Copy link

Choose a reason for hiding this comment

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

9% of developers fix this issue

PATH_TRAVERSAL_IN: This API (java/io/File.(Ljava/lang/String;)V) reads a file whose location might be specified by user input

❗❗ 2 similar findings have been found in this PR

🔎 Expand here to view all instances of this finding
File Path Line Number
solr/core/src/java/org/apache/solr/cli/CreateCoreTool.java 127
solr/core/src/java/org/apache/solr/cli/CreateCoreTool.java 166

Visit the Lift Web Console to find more details in your report.


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.

* solrInstallDir.
*/
private void ensureConfDirExists(String confDirName, String solrInstallDir) {
if (!new File(confDirName).isDirectory()) {
Copy link

Choose a reason for hiding this comment

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

9% of developers fix this issue

PATH_TRAVERSAL_IN: This API (java/io/File.(Ljava/lang/String;)V) reads a file whose location might be specified by user input


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.

private void ensureConfDirExists(String confDirName, String solrInstallDir) {
if (!new File(confDirName).isDirectory()) {
final String fullConfDir = solrInstallDir + "/server/solr/configsets/" + confDirName;
if (!new File(fullConfDir).isDirectory()) {
Copy link

Choose a reason for hiding this comment

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

9% of developers fix this issue

PATH_TRAVERSAL_IN: This API (java/io/File.(Ljava/lang/String;)V) reads a file whose location might be specified by user input


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.

@epugh
Copy link
Contributor Author

epugh commented Jun 22, 2023

@mkhludnev I've chased down the latest merge conflicts ;-). Let me know how it goes, and if you want to do a pairing session, I can jump on next week.

@epugh
Copy link
Contributor Author

epugh commented Jun 23, 2023

@Willdotwhite @mkhludnev so what is the best way to bring in the changes that both of you have made? main...mkhludnev:solr:SOLR-16829 shows some great improvments from each of you? Do you each propose a PR to the branch that I have in my github.com/epugh/solr? Just not sure how to get those commits into the PR? @Willdotwhite are the changes you've made ready to go once status is done?

@epugh
Copy link
Contributor Author

epugh commented Jun 28, 2023

@Willdotwhite I had a thought which is that maybe I'll back out the bin/solr statuscommand changes, since that was giving you some problems, and move that to the Round 2 of work, which then would make this committable?

Willdotwhite and others added 3 commits June 28, 2023 22:17
Original source: 718c5ef
curtesy of @mkhludnev

Manually copied ignoring existing fixes to `healthcheck`
Update solr.cmd for round #1 migration to SolrCLI
@epugh
Copy link
Contributor Author

epugh commented Jun 28, 2023

@Willdotwhite can we delete the method status_usage ? Line 282 has:

IF "%SCRIPT_CMD%"=="status" goto status_usage

@epugh
Copy link
Contributor Author

epugh commented Jun 29, 2023

okay @Willdotwhite I had to restore a change to StatusTool.java to make it work on Unix.. Is it possible that we have the .cmd and the .sh somewhat working at cross purposes in how we decide to output the help?

@Willdotwhite
Copy link
Contributor

Willdotwhite commented Jun 30, 2023

okay @Willdotwhite I had to restore a change to StatusTool.java to make it work on Unix.. Is it possible that we have the .cmd and the .sh somewhat working at cross purposes in how we decide to output the help?

Sorry @epugh , I think I was just a bit too tired yesterday and flubbed my testing - I've just put the condition back to if ((cli.getOptions().length == 0 && cli.getArgs().length == 0) || cli.hasOption("h") || cli.hasOption("help")) { on my machine and the status checks work as before; not really sure what happened there 🤔

I think NIX and Windows status checks are inline, just retested the Windows side locally from this branch and it's working as expected.

By the way, a bit of copypasta has slipped through the net on the hashbang of solr.sh just here beginning 'test_telp'

@epugh
Copy link
Contributor Author

epugh commented Jul 6, 2023

I think we are finally there... Responding to the last bits of feedback.

@epugh epugh merged commit fb6e879 into apache:main Jul 6, 2023
3 of 5 checks passed
Copy link
Contributor

@gerlowskija gerlowskija left a comment

Choose a reason for hiding this comment

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

Awesome to see so many lines in bin/solr and bin/solr.cmd get nuked, though I have some concerns around backcompat and the user experience. See inline comments for more details...

-help|-h)
print_usage ""
-help|-h)
run_tool ""
Copy link
Contributor

Choose a reason for hiding this comment

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

[Q] Does nothing in tidy/check complain about trailing whitespace? I don't care much, but I'm surprised given how we've leaned into code-formatting in recent years.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not that I know of... Maybe because this is shell? I didn't run shellcheck after making changes...

@@ -60,11 +60,11 @@ public List<Option> getOptions() {
SolrCLI.OPTION_SOLRURL,
SolrCLI.OPTION_ZKHOST,
Option.builder("c")
.argName("COLLECTION")
.longOpt("name")
.argName("NAME")
.hasArg()
.required(false)
Copy link
Contributor

Choose a reason for hiding this comment

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

[-1] AFAICT from this bin/solr code, the collection parameter should be required for the healthcheck tool.

Prior to this commit, we enforced this requirement in the bash/Windows-scripts, but now that we don't parse args or enforce required params there any more - we should update the .required(...) call here to be correct.

(Assuming I'm reading the old bin/solr code correctly at least; always possible I'm wrong.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://issues.apache.org/jira/browse/SOLR-16882 for fixing this... I will investigate the .bats test...

@@ -60,11 +60,11 @@ public List<Option> getOptions() {
SolrCLI.OPTION_SOLRURL,
SolrCLI.OPTION_ZKHOST,
Option.builder("c")
.argName("COLLECTION")
.longOpt("name")
Copy link
Contributor

Choose a reason for hiding this comment

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

[Q] I've picked HealthcheckTool's handling of its "collection" parameter as a concrete example, but the concern below applies in a number of places.


Historically, bin/solr healthcheck has accepted the collection name using either -c or -collection. But with this PR, AFAICT it now accepts -c and --collection (note the double-dash in the longopt).

Personally, I like the new syntax better - double-dashes on longopts are pretty ubiquitous in other CLI tools, and Solr's usage of -longoptName always struck me as quirky. That said though, it's a backwards incompatible change so we need to roll it out carefully.

If you do plan on committing some form of this to branch_9x, do you have plans for addressing backcompat? (i.e. Would the branch_9x version accept both --collection and -collection as longopt forms?)

If you don't plan on committing some form of this to branch_9x, things are better from a backcompat perspective but we'd still need to call out the syntax changes in CHANGES.txt or our Upgrade Notes, presumably?Do you have a general sense or (even better) a list of the syntax changes that'd need documented?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for jumping on this... https://issues.apache.org/jira/browse/SOLR-16824 was opened to specifically track that conversion to the --collection approach. I agree on the syntax changes needing tracking in Upgrade Notes. I might start with the Upgrade Notes for 10.x, but if we back port, then bring them back to that version of Upgrade Notes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also... one more thing is that the long name is actually --name.. I was struggling with the CreateTool which used --name since it can do core or collection. Can't use --collection for a Core!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

LIkewise the same thinking with the DeleteTool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants