Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions solr/core/src/java/org/apache/solr/cli/ApiTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class ApiTool extends ToolBase {
.argName("URL")
.required()
.desc("Send a GET request to a Solr API endpoint.")
.build();
.get();

public ApiTool(ToolRuntime runtime) {
super(runtime);
Expand Down Expand Up @@ -77,7 +77,7 @@ protected String callGet(String url, String credentials) throws Exception {
try (var solrClient = CLIUtils.getSolrClient(solrUrl, credentials)) {
// For path parameter we need the path without the root so from the second / char
// (because root can be configured)
// E.g URL is http://localhost:8983/solr/admin/info/system path is
// E.g. URL is http://localhost:8983/solr/admin/info/system path is
// /solr/admin/info/system and the path without root is /admin/info/system
var req =
new GenericSolrRequest(
Expand Down
44 changes: 23 additions & 21 deletions solr/core/src/java/org/apache/solr/cli/AssertTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public class AssertTool extends ToolBase {
private static Long timeoutMs = 1000L;

private static final Option IS_NOT_ROOT_OPTION =
Option.builder().desc("Asserts that we are NOT the root user.").longOpt("not-root").build();
Option.builder().desc("Asserts that we are NOT the root user.").longOpt("not-root").get();

private static final Option IS_ROOT_OPTION =
Option.builder().desc("Asserts that we are the root user.").longOpt("root").build();
Option.builder().desc("Asserts that we are the root user.").longOpt("root").get();

private static final OptionGroup ROOT_OPTION =
new OptionGroup().addOption(IS_NOT_ROOT_OPTION).addOption(IS_ROOT_OPTION);
Expand All @@ -59,15 +59,15 @@ public class AssertTool extends ToolBase {
.longOpt("not-started")
.hasArg()
.argName("url")
.build();
.get();

private static final Option IS_RUNNING_ON_OPTION =
Option.builder()
.desc("Asserts that Solr is running on a certain URL. Default timeout is 1000ms.")
.longOpt("started")
.hasArg()
.argName("url")
.build();
.get();

private static final OptionGroup RUNNING_OPTION =
new OptionGroup().addOption(IS_NOT_RUNNING_ON_OPTION).addOption(IS_RUNNING_ON_OPTION);
Expand All @@ -78,23 +78,23 @@ public class AssertTool extends ToolBase {
.longOpt("same-user")
.hasArg()
.argName("directory")
.build();
.get();

private static final Option DIRECTORY_EXISTS_OPTION =
Option.builder()
.desc("Asserts that directory <directory> exists.")
.longOpt("exists")
.hasArg()
.argName("directory")
.build();
.get();

private static final Option DIRECTORY_NOT_EXISTS_OPTION =
Option.builder()
.desc("Asserts that directory <directory> does NOT exist.")
.longOpt("not-exists")
.hasArg()
.argName("directory")
.build();
.get();

private static final OptionGroup DIRECTORY_OPTION =
new OptionGroup().addOption(DIRECTORY_EXISTS_OPTION).addOption(DIRECTORY_NOT_EXISTS_OPTION);
Expand All @@ -106,7 +106,7 @@ public class AssertTool extends ToolBase {
.longOpt("cloud")
.hasArg()
.argName("url")
.build();
.get();

private static final Option IS_NOT_CLOUD_OPTION =
Option.builder()
Expand All @@ -115,7 +115,7 @@ public class AssertTool extends ToolBase {
.longOpt("not-cloud")
.hasArg()
.argName("url")
.build();
.get();

private static final OptionGroup CLOUD_OPTION =
new OptionGroup().addOption(IS_CLOUD_OPTION).addOption(IS_NOT_CLOUD_OPTION);
Expand All @@ -126,7 +126,7 @@ public class AssertTool extends ToolBase {
.longOpt("message")
.hasArg()
.argName("message")
.build();
.get();

private static final Option TIMEOUT_OPTION =
Option.builder()
Expand All @@ -135,13 +135,13 @@ public class AssertTool extends ToolBase {
.hasArg()
.type(Long.class)
.argName("ms")
.build();
.get();

private static final Option EXIT_CODE_OPTION =
Option.builder()
.desc("Return an exit code instead of printing error message on assert fail.")
.longOpt("exitcode")
.build();
.get();

public AssertTool(ToolRuntime runtime) {
super(runtime);
Expand Down Expand Up @@ -292,9 +292,10 @@ public int assertSolrNotRunning(String url, String credentials) throws Exception
status.waitToSeeSolrUp(url, credentials, 1, TimeUnit.SECONDS);
try {
log.debug("Solr still up. Waiting before trying again to see if it was stopped");
Thread.sleep(1000L);
TimeUnit.MILLISECONDS.sleep(1000L);
} catch (InterruptedException interrupted) {
timeout = 0; // stop looping
Thread.currentThread().interrupt();
break;
}
} catch (Exception se) {
if (CLIUtils.exceptionIsAuthRelated(se)) {
Expand All @@ -312,7 +313,7 @@ public int assertSolrNotRunning(String url, String credentials) throws Exception
}

public int assertSolrRunningInCloudMode(String url, String credentials) throws Exception {
if (!isSolrRunningOn(url, credentials)) {
if (isSolrStoppedOn(url, credentials)) {
return exitOrException(
"Solr is not running on url "
+ url
Expand All @@ -328,7 +329,7 @@ public int assertSolrRunningInCloudMode(String url, String credentials) throws E
}

public int assertSolrNotRunningInCloudMode(String url, String credentials) throws Exception {
if (!isSolrRunningOn(url, credentials)) {
if (isSolrStoppedOn(url, credentials)) {
return exitOrException(
"Solr is not running on url "
+ url
Expand All @@ -344,8 +345,9 @@ public int assertSolrNotRunningInCloudMode(String url, String credentials) throw
}

public static int sameUser(String directory) throws Exception {
if (Files.exists(Path.of(directory))) {
String userForDir = userForDir(Path.of(directory));
Path path = Path.of(directory);
if (Files.exists(path)) {
String userForDir = userForDir(path);
if (!currentUser().equals(userForDir)) {
return exitOrException("Must run as user " + userForDir + ". We are " + currentUser());
}
Expand Down Expand Up @@ -405,16 +407,16 @@ private static int exitOrException(String msg) throws AssertionFailureException
}
}

private boolean isSolrRunningOn(String url, String credentials) throws Exception {
private boolean isSolrStoppedOn(String url, String credentials) throws Exception {
StatusTool status = new StatusTool(runtime);
try {
status.waitToSeeSolrUp(url, credentials, timeoutMs, TimeUnit.MILLISECONDS);
return true;
return false;
} catch (Exception se) {
if (CLIUtils.exceptionIsAuthRelated(se)) {
throw se;
}
return false;
return true;
}
}

Expand Down
Loading
Loading