Skip to content
Merged
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
3 changes: 2 additions & 1 deletion gradle/java/javac.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ allprojects {
"-Xlint:text-blocks",
"-proc:none", // proc:none was added because of LOG4J2-1925 / JDK-8186647
"-Xlint:removal",
"--should-stop=ifError=FLOW" // error-prone 2.41
"--should-stop=ifError=FLOW", // error-prone 2.41
"-Aproject=${project.group}/${project.name}"
]

if (propertyOrDefault("javac.failOnWarnings", true).toBoolean()) {
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ ow2-asm-tree = { module = "org.ow2.asm:asm-tree", version.ref = "ow2-asm" }
# @keep transitive dependency for version alignment
perfmark-api = { module = "io.perfmark:perfmark-api", version.ref = "perfmark" }
picocli = { module = "info.picocli:picocli", version.ref = "picocli" }
picocli-codegen = { module = "info.picocli:picocli-codegen", version.ref = "picocli" }
prometheus-metrics-expositionformats = { module = "io.prometheus:prometheus-metrics-exposition-formats", version.ref = "prometheus-metrics" }
prometheus-metrics-model = { module = "io.prometheus:prometheus-metrics-model", version.ref = "prometheus-metrics" }
prometheus-simpleclient = { module = "io.prometheus:simpleclient", version.ref = "prometheus-simpleclient" }
Expand Down
6 changes: 5 additions & 1 deletion solr/bin/solr
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,11 @@ if [ $# -gt 0 ]; then
shift 2
;;
-h|--help)
print_usage "$SCRIPT_CMD"
if [[ "${SOLR_PICOCLI:-}" == "true" ]]; then
run_tool "$SCRIPT_CMD" --help
else
print_usage "$SCRIPT_CMD"
fi
exit 0
;;
-y|--no-prompt)
Expand Down
18 changes: 16 additions & 2 deletions solr/bin/solr.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,22 @@ IF "%1"=="--all" goto set_stop_all
:parse_general_args

REM Print usage of command in case help option included
IF "%1"=="--help" goto usage
IF "%1"=="-h" goto usage
IF "%1"=="--help" goto check_picocli_help
IF "%1"=="-h" goto check_picocli_help
goto after_help_check

:check_picocli_help
IF "%SOLR_PICOCLI%"=="true" goto run_picocli_help
goto usage

:run_picocli_help
"%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% %SOLR_TOOL_OPTS% -Dsolr.install.dir="%SOLR_TIP%" ^
-Dlog4j.configurationFile="file:///%DEFAULT_SERVER_DIR%\resources\log4j2-console.xml" ^
-classpath "%SOLR_TIP%\lib\*;%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
org.apache.solr.cli.SolrCLI %SCRIPT_CMD% --help
goto done

:after_help_check

REM other args supported by all special commands
IF "%1"=="-p" goto set_port
Expand Down
2 changes: 1 addition & 1 deletion solr/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ dependencies {

implementation libs.commonscli.commonscli
implementation libs.picocli
permitUnusedDeclared libs.picocli // will be used when CLI is migrated to picocli
annotationProcessor libs.picocli.codegen

implementation libs.locationtech.spatial4j

Expand Down
3 changes: 2 additions & 1 deletion solr/core/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ com.tdunning:t-digest:3.3=compileClasspath,jarValidation,runtimeClasspath,runtim
commons-cli:commons-cli:1.10.0=compileClasspath,jarValidation,runtimeClasspath,runtimeLibs,testCompileClasspath,testRuntimeClasspath
commons-codec:commons-codec:1.19.0=compileClasspath,jarValidation,runtimeClasspath,runtimeLibs,testCompileClasspath,testRuntimeClasspath
commons-io:commons-io:2.20.0=apiHelper,compileClasspath,jarValidation,runtimeClasspath,runtimeLibs,testCompileClasspath,testRuntimeClasspath
info.picocli:picocli:4.7.6=compileClasspath,jarValidation,permitUnusedDeclared,runtimeClasspath,runtimeLibs,testCompileClasspath,testRuntimeClasspath
info.picocli:picocli-codegen:4.7.6=annotationProcessor
info.picocli:picocli:4.7.6=annotationProcessor,compileClasspath,jarValidation,runtimeClasspath,runtimeLibs,testCompileClasspath,testRuntimeClasspath
io.dropwizard.metrics:metrics-annotation:4.2.26=jarValidation,testRuntimeClasspath
io.dropwizard.metrics:metrics-core:4.2.26=compileClasspath,jarValidation,runtimeClasspath,runtimeLibs,testCompileClasspath,testRuntimeClasspath
io.dropwizard.metrics:metrics-jetty12-ee10:4.2.26=jarValidation,testRuntimeClasspath
Expand Down
5 changes: 5 additions & 0 deletions solr/core/src/java/org/apache/solr/cli/ApiTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,9 @@ public static ModifiableSolrParams getSolrParamsFromUri(URI uri) {
}
return paramsMap;
}

@Override
public int callTool() throws Exception {
throw new UnsupportedOperationException("This tool does not yet support PicoCli");
}
}
5 changes: 5 additions & 0 deletions solr/core/src/java/org/apache/solr/cli/AssertTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,11 @@ private static boolean runningSolrIsCloud(String url, String credentials) throws
}
}

@Override
public int callTool() throws Exception {
throw new UnsupportedOperationException("This tool does not yet support PicoCli");
}

public static class AssertionFailureException extends Exception {
public AssertionFailureException(String message) {
super(message);
Expand Down
5 changes: 5 additions & 0 deletions solr/core/src/java/org/apache/solr/cli/AuthTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -452,4 +452,9 @@ public void runImpl(CommandLine cli) throws Exception {
throw new IllegalStateException("Only type=basicAuth supported at the moment.");
}
}

@Override
public int callTool() throws Exception {
throw new UnsupportedOperationException("This tool does not yet support PicoCli");
}
}
1 change: 1 addition & 0 deletions solr/core/src/java/org/apache/solr/cli/CLIUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ public static String normalizeSolrUrl(String solrUrl, boolean logUrlFormatWarnin
* Get the base URL of a live Solr instance from either the --solr-url command-line option or from
* ZooKeeper.
*/
@Deprecated
public static String normalizeSolrUrl(CommandLine cli) throws Exception {
String solrUrl = cli.getOptionValue(CommonCLIOptions.SOLR_URL_OPTION);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.cli;

import static org.apache.solr.cli.CLIUtils.getCloudSolrClient;
import static org.apache.solr.cli.CLIUtils.normalizeSolrUrl;

import java.util.Set;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.util.EnvUtils;
import picocli.CommandLine;

/** Provides default values for CLI arguments. */
public class CliDefaultValueProvider implements CommandLine.IDefaultValueProvider {
@Override
public String defaultValue(CommandLine.Model.ArgSpec argSpec) throws Exception {
return switch (argSpec.paramLabel()) {
case "<zkHost>" -> EnvUtils.getProperty("zkHost");
case "<solrUrl>" -> {
String val = EnvUtils.getProperty("solr.url");
yield val != null ? val : resolveSolrUrlViaZkHost(argSpec);
}
case "<port>" -> EnvUtils.getProperty("solr.port", "8983");
case "<maxWaitSecs>" -> EnvUtils.getProperty("solr.max.wait.seconds", "0");
default -> null;
};
}

/**
* If no solrUrl is provided on the command line, and SOLR_URL is not set, this method will be
* used to determine the solrUrl from the zkHost.
*
* @param argSpec the argSpec for the solrUrl option
* @return the solrUrl
* @throws Exception if an error occurs
*/
public static String resolveSolrUrlViaZkHost(picocli.CommandLine.Model.ArgSpec argSpec)
throws Exception {
// Find value of zkHost from command line options. The argSpec passed in will be for the
// solrUrl option.
CommandLine.Model.OptionSpec zkHostOption = argSpec.command().findOption("--zk-host");

String zkHost = zkHostOption != null ? zkHostOption.getValue() : null;
if (zkHost == null) {
return null;
}

String solrUrl;
try (CloudSolrClient cloudSolrClient = getCloudSolrClient(zkHost)) {
cloudSolrClient.connect();
Set<String> liveNodes = cloudSolrClient.getClusterState().getLiveNodes();
if (liveNodes.isEmpty())
throw new IllegalStateException(
"No live nodes found! Cannot determine 'solrUrl' from ZooKeeper: " + zkHost);

String firstLiveNode = liveNodes.iterator().next();
solrUrl = ZkStateReader.from(cloudSolrClient).getBaseUrlForNodeName(firstLiveNode);
solrUrl = normalizeSolrUrl(solrUrl, false);
}
solrUrl = normalizeSolrUrl(solrUrl);
return solrUrl;
}
}
5 changes: 5 additions & 0 deletions solr/core/src/java/org/apache/solr/cli/ClusterTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,9 @@ public void runImpl(CommandLine cli) throws Exception {
}
}
}

@Override
public int callTool() throws Exception {
throw new UnsupportedOperationException("This tool does not yet support PicoCli");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,9 @@ public void runImpl(CommandLine cli) throws Exception {
throw (e);
}
}

@Override
public int callTool() throws Exception {
throw new UnsupportedOperationException("This tool does not yet support PicoCli");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,9 @@ public void runImpl(CommandLine cli) throws Exception {
throw (e);
}
}

@Override
public int callTool() throws Exception {
throw new UnsupportedOperationException("This tool does not yet support PicoCli");
}
}
5 changes: 5 additions & 0 deletions solr/core/src/java/org/apache/solr/cli/ConfigTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,9 @@ public void runImpl(CommandLine cli) throws Exception {
}
}
}

@Override
public int callTool() throws Exception {
throw new UnsupportedOperationException("This tool does not yet support PicoCli");
}
}
5 changes: 5 additions & 0 deletions solr/core/src/java/org/apache/solr/cli/CreateTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -352,4 +352,9 @@ private void printDefaultConfigsetWarningIfNecessary(CommandLine cli) {
echo(" " + configCommand);
}
}

@Override
public int callTool() throws Exception {
throw new UnsupportedOperationException("This tool does not yet support PicoCli");
}
}
5 changes: 5 additions & 0 deletions solr/core/src/java/org/apache/solr/cli/DeleteTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,9 @@ protected void deleteCore(CommandLine cli, SolrClient solrClient) throws Excepti
throw new Exception("Failed to delete core '" + coreName + "' due to: " + sse.getMessage());
}
}

@Override
public int callTool() throws Exception {
throw new UnsupportedOperationException("This tool does not yet support PicoCli");
}
}
5 changes: 5 additions & 0 deletions solr/core/src/java/org/apache/solr/cli/ExportTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -707,4 +707,9 @@ static long getDocCount(String coreName, SolrClient client, String query)
SolrDocumentList sdl = (SolrDocumentList) res.get("response");
return sdl.getNumFound();
}

@Override
public int callTool() throws Exception {
throw new UnsupportedOperationException("This tool does not yet support PicoCli");
}
}
5 changes: 5 additions & 0 deletions solr/core/src/java/org/apache/solr/cli/HealthcheckTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ protected void runCloudTool(CloudSolrClient cloudSolrClient, CommandLine cli) th
new JSONWriter(arr, 2).write(report);
echo(arr.toString());
}

@Override
public int callTool() throws Exception {
throw new UnsupportedOperationException("This tool does not yet support PicoCli");
}
}

class ReplicaHealth implements Comparable<ReplicaHealth> {
Expand Down
5 changes: 5 additions & 0 deletions solr/core/src/java/org/apache/solr/cli/PackageTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -378,4 +378,9 @@ public Options getOptions() {
.addOption(CommonCLIOptions.CREDENTIALS_OPTION)
.addOptionGroup(getConnectionOptions());
}

@Override
public int callTool() throws Exception {
throw new UnsupportedOperationException("This tool does not yet support PicoCli");
}
}
5 changes: 5 additions & 0 deletions solr/core/src/java/org/apache/solr/cli/PostLogsTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -626,4 +626,9 @@ public static String[] getRequestPurposeNames(Integer reqPurpose) {
map.put(ShardRequest.PURPOSE_GET_TERM_STATS, "GET_TERM_STATS");
purposes = Collections.unmodifiableMap(map);
}

@Override
public int callTool() throws Exception {
throw new UnsupportedOperationException("This tool does not yet support PicoCli");
}
}
5 changes: 5 additions & 0 deletions solr/core/src/java/org/apache/solr/cli/PostTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,11 @@ protected Set<URI> getLinksFromWebPage(URL url, InputStream is, String type, URI
}
}

@Override
public int callTool() throws Exception {
throw new UnsupportedOperationException("This tool does not yet support PicoCli");
}

/** Utility class to hold the result form a page fetch */
public static class PageFetcherResult {
int httpStatus = 200;
Expand Down
5 changes: 5 additions & 0 deletions solr/core/src/java/org/apache/solr/cli/RunExampleTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,11 @@ protected void copyIfNeeded(Path src, Path dest) throws IOException {
throw new IllegalStateException("Required file " + dest.toAbsolutePath() + " not found!");
}

@Override
public int callTool() throws Exception {
throw new UnsupportedOperationException("This tool does not yet support PicoCli");
}

protected boolean isPortAvailable(int port) {
try (Socket s = new Socket("localhost", port)) {
assert s != null; // To allow compilation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,9 @@ public void createSnapshot(SolrClient solrClient, String collectionName, String
+ e.getLocalizedMessage());
}
}

@Override
public int callTool() throws Exception {
throw new UnsupportedOperationException("This tool does not yet support PicoCli");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,9 @@ public void deleteSnapshot(SolrClient solrClient, String collectionName, String
+ e.getLocalizedMessage());
}
}

@Override
public int callTool() throws Exception {
throw new UnsupportedOperationException("This tool does not yet support PicoCli");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,9 @@ private Collection<CollectionSnapshotMetaData> listCollectionSnapshots(

return result;
}

@Override
public int callTool() throws Exception {
throw new UnsupportedOperationException("This tool does not yet support PicoCli");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,9 @@ public void exportSnapshot(
+ e.getLocalizedMessage());
}
}

@Override
public int callTool() throws Exception {
throw new UnsupportedOperationException("This tool does not yet support PicoCli");
}
}
5 changes: 5 additions & 0 deletions solr/core/src/java/org/apache/solr/cli/SnapshotListTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,9 @@ public void listSnapshots(SolrClient solrClient, String collectionName) {
+ e.getLocalizedMessage());
}
}

@Override
public int callTool() throws Exception {
throw new UnsupportedOperationException("This tool does not yet support PicoCli");
}
}
Loading