Skip to content

Commit

Permalink
Cleanup code structure.
Browse files Browse the repository at this point in the history
Remove duplicate printout "Found 1 Solr nodes:"
  • Loading branch information
janhoy committed Oct 18, 2024
1 parent 9835f06 commit 0d0ee43
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 37 deletions.
57 changes: 22 additions & 35 deletions solr/core/src/java/org/apache/solr/cli/StatusTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,46 +138,34 @@ public void runImpl(CommandLine cli) throws Exception {
System.exit(1);
} else {
solrUrl = proc.get().getLocalUrl();
if (shortFormat) {
CLIO.out(solrUrl);
} else {
printProcessStatus(proc.get(), cli);
}
System.exit(0);
}
}

if (solrUrl == null) {
if (!shortFormat) {
CLIO.out("Looking for running processes...");
}
Collection<SolrProcess> procs = processMgr.scanSolrPidFiles();
if (!shortFormat) {
CLIO.out(String.format(Locale.ROOT, "\nFound %s Solr nodes: ", procs.size()));
}
if (!procs.isEmpty()) {
for (SolrProcess process : procs) {
if (shortFormat) {
CLIO.out(process.getLocalUrl());
} else {
printProcessStatus(process, cli);
}
}
} else {
if (!shortFormat) {
CLIO.out("\nNo Solr nodes are running.\n");
// No URL or port, scan for running processes
if (!shortFormat) {
CLIO.out("Looking for running processes...");
}
Collection<SolrProcess> procs = processMgr.scanSolrPidFiles();
if (!shortFormat) {
CLIO.out(String.format(Locale.ROOT, "\nFound %s Solr nodes: ", procs.size()));
}
if (!procs.isEmpty()) {
for (SolrProcess process : procs) {
if (shortFormat) {
CLIO.out(process.getLocalUrl());
} else {
printProcessStatus(process, cli);
}
}
} else {
// We have a solrUrl
int urlPort = portFromUrl(solrUrl);
if (shortFormat) {
if (processMgr.isRunningWithPort(urlPort)) {
CLIO.out(solrUrl);
}
} else {
Optional<SolrProcess> process = processMgr.processForPort(urlPort);

if (process.isPresent()) {
CLIO.out(String.format(Locale.ROOT, "\nFound %s Solr nodes: ", 1));
printProcessStatus(process.get(), cli);
} else {
CLIO.out("\nNo Solr running on port " + urlPort + ".");
}
if (!shortFormat) {
CLIO.out("\nNo Solr nodes are running.\n");
}
}
}
Expand Down Expand Up @@ -262,7 +250,6 @@ public boolean printStatusFromRunningSolr(String solrUrl, CommandLine cli) throw
/* ignore */
}
if (statusJson != null) {
CLIO.out("Found 1 Solr nodes:");
CLIO.out(statusJson);
} else {
CLIO.err("Solr at " + solrUrl + " not online.");
Expand Down
2 changes: 0 additions & 2 deletions solr/packaging/test/test_status.bats
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,13 @@ teardown() {
@test "status with --solr-url from user" {
solr start
run solr status --solr-url http://localhost:${SOLR_PORT}
assert_output --partial "Found 1 Solr nodes:"
assert_output --partial "\"solr_home\":"
solr stop
}

@test "status with --port from user" {
solr start
run solr status --port ${SOLR_PORT}
assert_output --partial "Found 1 Solr nodes:"
assert_output --partial "running on port ${SOLR_PORT}"
solr stop
}
Expand Down

0 comments on commit 0d0ee43

Please sign in to comment.