Skip to content

Commit

Permalink
SOLR-17501: Move out CLI utils from SolrCLI (#2744)
Browse files Browse the repository at this point in the history
  • Loading branch information
malliaridis authored Nov 19, 2024
1 parent 5cc733b commit e1f56b3
Show file tree
Hide file tree
Showing 38 changed files with 594 additions and 410 deletions.
2 changes: 1 addition & 1 deletion solr/core/src/java/org/apache/solr/cli/ApiTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected String callGet(String url, String credentials) throws Exception {
URI uri = new URI(url.replace("+", "%20"));
String solrUrl = getSolrUrlFromUri(uri);
String path = uri.getPath();
try (var solrClient = SolrCLI.getSolrClient(solrUrl, credentials)) {
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
Expand Down
18 changes: 9 additions & 9 deletions solr/core/src/java/org/apache/solr/cli/AssertTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,13 @@ protected int runAssert(CommandLine cli) throws Exception {
if (cli.hasOption(IS_CLOUD_OPTION)) {
ret +=
assertSolrRunningInCloudMode(
SolrCLI.normalizeSolrUrl(cli.getOptionValue(IS_CLOUD_OPTION)),
CLIUtils.normalizeSolrUrl(cli.getOptionValue(IS_CLOUD_OPTION)),
cli.getOptionValue(CommonCLIOptions.CREDENTIALS_OPTION));
}
if (cli.hasOption(IS_NOT_CLOUD_OPTION)) {
ret +=
assertSolrNotRunningInCloudMode(
SolrCLI.normalizeSolrUrl(cli.getOptionValue(IS_NOT_CLOUD_OPTION)),
CLIUtils.normalizeSolrUrl(cli.getOptionValue(IS_NOT_CLOUD_OPTION)),
cli.getOptionValue(CommonCLIOptions.CREDENTIALS_OPTION));
}
return ret;
Expand All @@ -267,7 +267,7 @@ public static int assertSolrRunning(String url, String credentials) throws Excep
try {
status.waitToSeeSolrUp(url, credentials, timeoutMs, TimeUnit.MILLISECONDS);
} catch (Exception se) {
if (SolrCLI.exceptionIsAuthRelated(se)) {
if (CLIUtils.exceptionIsAuthRelated(se)) {
throw se;
}
return exitOrException(
Expand All @@ -284,10 +284,10 @@ public static int assertSolrNotRunning(String url, String credentials) throws Ex
StatusTool status = new StatusTool();
long timeout =
System.nanoTime() + TimeUnit.NANOSECONDS.convert(timeoutMs, TimeUnit.MILLISECONDS);
try (SolrClient solrClient = SolrCLI.getSolrClient(url, credentials)) {
try (SolrClient solrClient = CLIUtils.getSolrClient(url, credentials)) {
NamedList<Object> response = solrClient.request(new HealthCheckRequest());
Integer statusCode = (Integer) response.findRecursive("responseHeader", "status");
SolrCLI.checkCodeForAuthError(statusCode);
CLIUtils.checkCodeForAuthError(statusCode);
} catch (IOException | SolrServerException e) {
log.debug("Opening connection to {} failed, Solr does not seem to be running", url, e);
return 0;
Expand All @@ -302,7 +302,7 @@ public static int assertSolrNotRunning(String url, String credentials) throws Ex
timeout = 0; // stop looping
}
} catch (Exception se) {
if (SolrCLI.exceptionIsAuthRelated(se)) {
if (CLIUtils.exceptionIsAuthRelated(se)) {
throw se;
}
return exitOrException(se.getMessage());
Expand Down Expand Up @@ -417,16 +417,16 @@ private static boolean isSolrRunningOn(String url, String credentials) throws Ex
status.waitToSeeSolrUp(url, credentials, timeoutMs, TimeUnit.MILLISECONDS);
return true;
} catch (Exception se) {
if (SolrCLI.exceptionIsAuthRelated(se)) {
if (CLIUtils.exceptionIsAuthRelated(se)) {
throw se;
}
return false;
}
}

private static boolean runningSolrIsCloud(String url, String credentials) throws Exception {
try (final SolrClient client = SolrCLI.getSolrClient(url, credentials)) {
return SolrCLI.isCloudMode(client);
try (final SolrClient client = CLIUtils.getSolrClient(url, credentials)) {
return CLIUtils.isCloudMode(client);
}
}

Expand Down
16 changes: 8 additions & 8 deletions solr/core/src/java/org/apache/solr/cli/AuthTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private void handleKerberos(CommandLine cli) throws Exception {

if (!updateIncludeFileOnly) {
try {
zkHost = SolrCLI.getZkHost(cli);
zkHost = CLIUtils.getZkHost(cli);
} catch (Exception ex) {
CLIO.out(
"Unable to access ZooKeeper. Please add the following security.json to ZooKeeper (in case of SolrCloud):\n"
Expand All @@ -214,7 +214,7 @@ private void handleKerberos(CommandLine cli) throws Exception {

// check if security is already enabled or not
if (!zkInaccessible) {
try (SolrZkClient zkClient = SolrCLI.getSolrZkClient(cli, zkHost)) {
try (SolrZkClient zkClient = CLIUtils.getSolrZkClient(cli, zkHost)) {
checkSecurityJsonExists(zkClient);
} catch (Exception ex) {
CLIO.out(
Expand All @@ -229,7 +229,7 @@ private void handleKerberos(CommandLine cli) throws Exception {
if (!updateIncludeFileOnly) {
if (!zkInaccessible) {
echoIfVerbose("Uploading following security.json: " + securityJson);
try (SolrZkClient zkClient = SolrCLI.getSolrZkClient(cli, zkHost)) {
try (SolrZkClient zkClient = CLIUtils.getSolrZkClient(cli, zkHost)) {
zkClient.setData(
"/security.json", securityJson.getBytes(StandardCharsets.UTF_8), true);
} catch (Exception ex) {
Expand Down Expand Up @@ -309,7 +309,7 @@ private void handleBasicAuth(CommandLine cli) throws Exception {

if (!updateIncludeFileOnly) {
try {
zkHost = SolrCLI.getZkHost(cli);
zkHost = CLIUtils.getZkHost(cli);
} catch (Exception ex) {
if (cli.hasOption(CommonCLIOptions.ZK_HOST_OPTION)) {
CLIO.out(
Expand All @@ -332,7 +332,7 @@ private void handleBasicAuth(CommandLine cli) throws Exception {
}

// check if security is already enabled or not
try (SolrZkClient zkClient = SolrCLI.getSolrZkClient(cli, zkHost)) {
try (SolrZkClient zkClient = CLIUtils.getSolrZkClient(cli, zkHost)) {
checkSecurityJsonExists(zkClient);
}
}
Expand Down Expand Up @@ -381,7 +381,7 @@ private void handleBasicAuth(CommandLine cli) throws Exception {

if (!updateIncludeFileOnly) {
echoIfVerbose("Uploading following security.json: " + securityJson);
try (SolrZkClient zkClient = SolrCLI.getSolrZkClient(cli, zkHost)) {
try (SolrZkClient zkClient = CLIUtils.getSolrZkClient(cli, zkHost)) {
zkClient.setData("/security.json", securityJson.getBytes(StandardCharsets.UTF_8), true);
}
}
Expand Down Expand Up @@ -460,15 +460,15 @@ private void checkSecurityJsonExists(SolrZkClient zkClient)
private void clearSecurityJson(CommandLine cli, boolean updateIncludeFileOnly) throws Exception {
String zkHost;
if (!updateIncludeFileOnly) {
zkHost = SolrCLI.getZkHost(cli);
zkHost = CLIUtils.getZkHost(cli);
if (zkHost == null) {
stdout.print("ZK Host not found. Solr should be running in cloud mode.");
SolrCLI.exit(1);
}

echoIfVerbose("Uploading following security.json: {}");

try (SolrZkClient zkClient = SolrCLI.getSolrZkClient(cli, zkHost)) {
try (SolrZkClient zkClient = CLIUtils.getSolrZkClient(cli, zkHost)) {
zkClient.setData("/security.json", "{}".getBytes(StandardCharsets.UTF_8), true);
}
}
Expand Down
Loading

0 comments on commit e1f56b3

Please sign in to comment.