Skip to content

SOLR-16711: Extract SolrCLI tool implementations into their own package and classes#1476

Closed
epugh wants to merge 27 commits intoapache:mainfrom
epugh:SOLR-16711
Closed

SOLR-16711: Extract SolrCLI tool implementations into their own package and classes#1476
epugh wants to merge 27 commits intoapache:mainfrom
epugh:SOLR-16711

Conversation

@epugh
Copy link
Copy Markdown
Contributor

@epugh epugh commented Mar 20, 2023

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

Description

SolrCLI.java is overwhelming to work with.

Solution

Extract tools into their own package.

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:

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

@epugh epugh requested review from HoustonPutman and risdenk March 20, 2023 17:47
Copy link
Copy Markdown
Contributor

@janhoy janhoy left a comment

Choose a reason for hiding this comment

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

Wow, this is soo over due :) Looks great!

} // end HealthcheckTool

private static final Option[] CREATE_COLLECTION_OPTIONS =
public static final Option[] CREATE_COLLECTION_OPTIONS =
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

MutablePublicArray: Non-empty arrays are mutable, so this public static final array is not a constant and can be modified by clients of this class. Prefer an ImmutableList, or provide an accessor method that returns a defensive copy.


ℹ️ 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.


Help us improve LIFT! (Sonatype LiftBot external survey)

Was this a good recommendation for you? Answering this survey will not impact your Lift settings.

[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

protected boolean isPortAvailable(int port) {
Socket s = null;
try {
s = new Socket("localhost", port);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

UNENCRYPTED_SOCKET: Unencrypted socket to org.apache.solr.util.cli.RunExampleTool (instead of SSLSocket)


ℹ️ 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.


Help us improve LIFT! (Sonatype LiftBot external survey)

Was this a good recommendation for you? Answering this survey will not impact your Lift settings.

[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

if (excMsg != null) {
CLIO.err("\nERROR: " + excMsg + "\n");
if (verbose) {
exc.printStackTrace(CLIO.getErrStream());
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

0% of developers fix this issue

INFORMATION_EXPOSURE_THROUGH_AN_ERROR_MESSAGE: Possible information exposure through an error message


ℹ️ 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.


Help us improve LIFT! (Sonatype LiftBot external survey)

Was this a good recommendation for you? Answering this survey will not impact your Lift settings.

[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

throw new IllegalArgumentException(
"Value of -serverDir option is invalid! " + zooCfg.getAbsolutePath() + " not found!");

File solrHomeDir = new File(exampleParentDir, dirName + "/solr");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

5% of developers fix this issue

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

❗❗ 24 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/util/cli/AssertTool.java 275
solr/core/src/java/org/apache/solr/util/cli/AuthTool.java 432
solr/core/src/java/org/apache/solr/util/cli/RunExampleTool.java 201
solr/core/src/java/org/apache/solr/util/cli/CreateCoreTool.java 71
solr/core/src/java/org/apache/solr/util/cli/AuthTool.java 440
solr/core/src/java/org/apache/solr/util/cli/ConfigSetDownloadTool.java 73
solr/core/src/java/org/apache/solr/util/cli/CreateCoreTool.java 79
solr/core/src/java/org/apache/solr/util/cli/ConfigSetDownloadTool.java 69
solr/core/src/java/org/apache/solr/util/cli/RunExampleTool.java 481
solr/core/src/java/org/apache/solr/util/cli/AuthTool.java 235

Showing 10 of 24 findings. Visit the Lift Web Console to see all.


ℹ️ 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.


Help us improve LIFT! (Sonatype LiftBot external survey)

Was this a good recommendation for you? Answering this survey will not impact your Lift settings.

[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

}

public static int assertNotRootUser() throws Exception {
if (currentUser().equals("root")) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

15% of developers fix this issue

NULL_DEREFERENCE: object returned by currentUser() could be null and is dereferenced at line 308.

❗❗ 4 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/util/cli/AssertTool.java 277
solr/core/src/java/org/apache/solr/util/cli/StatusTool.java 141
solr/core/src/java/org/apache/solr/util/cli/StatusTool.java 169
solr/core/src/java/org/apache/solr/util/cli/AssertTool.java 301

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.


Help us improve LIFT! (Sonatype LiftBot external survey)

Was this a good recommendation for you? Answering this survey will not impact your Lift settings.

[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

if (excMsg != null) {
CLIO.err("\nERROR: " + excMsg + "\n");
if (verbose) {
exc.printStackTrace(CLIO.getErrStream());
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

0% of developers fix this issue

INFORMATION_EXPOSURE_THROUGH_AN_ERROR_MESSAGE: Possible information exposure through an error message


ℹ️ 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.


Help us improve LIFT! (Sonatype LiftBot external survey)

Was this a good recommendation for you? Answering this survey will not impact your Lift settings.

[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

protected boolean isPortAvailable(int port) {
Socket s = null;
try {
s = new Socket("localhost", port);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

UNENCRYPTED_SOCKET: Unencrypted socket to org.apache.solr.util.cli.RunExampleTool (instead of SSLSocket)


ℹ️ 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.


Help us improve LIFT! (Sonatype LiftBot external survey)

Was this a good recommendation for you? Answering this survey will not impact your Lift settings.

[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

// we try to be nice about having the "conf" in the directory, and we create it if it's not
// there.
if (!configSetPath.endsWith("/conf")) {
configSetPath = Paths.get(configSetPath.toString(), "conf");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

5% of developers fix this issue

PATH_TRAVERSAL_IN: This API (java/nio/file/Paths.get(Ljava/lang/String;[Ljava/lang/String;)Ljava/nio/file/Path;) reads a file whose location might be specified by user input

❗❗ 24 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/util/cli/RunExampleTool.java 212
solr/core/src/java/org/apache/solr/util/cli/CreateCoreTool.java 94
solr/core/src/java/org/apache/solr/util/cli/RunExampleTool.java 932
solr/core/src/java/org/apache/solr/util/cli/CreateCoreTool.java 91
solr/core/src/java/org/apache/solr/util/cli/AuthTool.java 441
solr/core/src/java/org/apache/solr/util/cli/RunExampleTool.java 628
solr/core/src/java/org/apache/solr/util/cli/ConfigSetDownloadTool.java 89
solr/core/src/java/org/apache/solr/util/cli/RunExampleTool.java 182
solr/core/src/java/org/apache/solr/util/cli/RunExampleTool.java 890
solr/core/src/java/org/apache/solr/util/cli/RunExampleTool.java 211

Showing 10 of 24 findings. Visit the Lift Web Console to see all.


ℹ️ 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.


Help us improve LIFT! (Sonatype LiftBot external survey)

Was this a good recommendation for you? Answering this survey will not impact your Lift settings.

[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

status.put("solr_home", solrHome != null ? solrHome : "?");
status.put("version", SolrCLI.asString("/lucene/solr-impl-version", info));
status.put("startTime", SolrCLI.asString("/jvm/jmx/startTime", info));
status.put("uptime", SolrCLI.uptime(SolrCLI.asLong("/jvm/jmx/upTimeMS", info)));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

15% of developers fix this issue

NULL_DEREFERENCE: object returned by asLong("/jvm/jmx/upTimeMS",info) could be null and is dereferenced at line 154.

❗❗ 4 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/util/cli/AssertTool.java 318
solr/core/src/java/org/apache/solr/util/cli/AssertTool.java 294
solr/core/src/java/org/apache/solr/util/cli/AssertTool.java 325
solr/core/src/java/org/apache/solr/util/cli/StatusTool.java 182

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.


Help us improve LIFT! (Sonatype LiftBot external survey)

Was this a good recommendation for you? Answering this survey will not impact your Lift settings.

[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

@epugh
Copy link
Copy Markdown
Contributor Author

epugh commented Mar 21, 2023

Getting to done on this... A question, should I move SolrCLI.java into the .utils.cli package and update the scripts etc? Any other changes that folks think need doing to call this "done" and ready for review/commit?

epugh and others added 3 commits March 21, 2023 14:09
Co-authored-by: sonatype-lift[bot] <37194012+sonatype-lift[bot]@users.noreply.github.com>
@epugh
Copy link
Copy Markdown
Contributor Author

epugh commented Mar 22, 2023

Getting to done on this... A question, should I move SolrCLI.java into the .utils.cli package and update the scripts etc? Any other changes that folks think need doing to call this "done" and ready for review/commit?

@janhoy @risdenk just wanted your opinons on making this change or not, and then I think I'm ready to commit ;-)

@epugh
Copy link
Copy Markdown
Contributor Author

epugh commented Apr 17, 2023

Merging in #1182 made this too hard to update... So I started over again in #1568. Going to close this one in favour of the new one.

@epugh epugh closed this Apr 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants