Skip to content

Commit

Permalink
Merge branch 'branch_9x' into SOLR-17450-backport-9x
Browse files Browse the repository at this point in the history
# Conflicts:
#	solr/bin/solr
  • Loading branch information
janhoy committed Oct 23, 2024
2 parents c6d187a + 7892085 commit 7016e39
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 129 deletions.
21 changes: 17 additions & 4 deletions solr/bin/solr
Original file line number Diff line number Diff line change
Expand Up @@ -724,8 +724,16 @@ if [ $# -gt 0 ]; then
-c|--cloud|-cloud)
SOLR_MODE="solrcloud"
PASS_TO_RUN_EXAMPLE+=("-c")

echo -e "Solr will start in SolrCloud mode by default in version 10, and you will no longer need to pass in -c or --cloud flag.\n"
shift
;;
--user-managed)
# Allow the user to use the user-managed flag to suppress the warning about th change
# of the default mode in v10.
SOLR_MODE="user-managed"
shift
;;
-d|--dir|-dir|--server-dir)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Server directory is required when using the $1 option!"
Expand Down Expand Up @@ -1130,12 +1138,19 @@ if [[ -n "${ZK_HOST:-}" ]]; then
SOLR_MODE="solrcloud"
fi

if [[ -z ${SOLR_MODE:-} ]]; then
# User has not provided any option for the mode (--cloud/--user-managed), therefore
# stay on user-managed mode in 9.x to avoid behavior changing / breaking changes
SOLR_MODE="user-managed"
# and notify that staying the default option (not providing --user-managed) will affect
# future execution
echo -e "Solr will start in SolrCloud mode by default in version 10, and you will have to provide --user-managed if you want to stay on the user-managed (aka. standalone) mode.\n"
fi

if [ "${SOLR_MODE:-}" == 'solrcloud' ]; then
: "${ZK_CLIENT_TIMEOUT:=30000}"
CLOUD_MODE_OPTS=("-DzkClientTimeout=$ZK_CLIENT_TIMEOUT")

echo -e "\nSolr will start in SolrCloud mode by default in version 10, even if no -c or --cloud flag is specified.\n"

if [ -n "${ZK_HOST:-}" ]; then
CLOUD_MODE_OPTS+=("-DzkHost=$ZK_HOST")
else
Expand Down Expand Up @@ -1167,8 +1182,6 @@ else
echo -e "\nSolr home directory $SOLR_HOME must contain a solr.xml file!\n"
exit 1
fi

echo -e "\nSolr will start in SolrCloud mode by default in version 10. You will need to pass in --user-managed flag to run in User Managed (aka Standalone) mode.\n"
fi

# Exit if old syntax found
Expand Down
19 changes: 16 additions & 3 deletions solr/bin/solr.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ IF "%1"=="--quiet" goto set_warn
IF "%1"=="-c" goto set_cloud_mode
IF "%1"=="-cloud" goto set_cloud_mode
IF "%1"=="--cloud" goto set_cloud_mode
IF "%1"=="--user-managed" goto set_user_managed_mode
IF "%1"=="-d" goto set_server_dir
IF "%1"=="--dir" goto set_server_dir
IF "%1"=="--server-dir" goto set_server_dir
Expand Down Expand Up @@ -507,6 +508,13 @@ goto parse_args

:set_cloud_mode
set SOLR_MODE=solrcloud
REM Notify user in 9.x about the default mode change if cloud flag is used.
@echo Solr will start in SolrCloud mode by default in version 10, and you will no longer need to pass in -c or --cloud flag.
SHIFT
goto parse_args

:set_user_managed_mode
set SOLR_MODE=user-managed
SHIFT
goto parse_args

Expand Down Expand Up @@ -950,10 +958,16 @@ if !JAVA_MAJOR_VERSION! LSS 9 (
)

IF NOT "%ZK_HOST%"=="" set SOLR_MODE=solrcloud
IF "%SOLR_MODE%"=="" (
REM User has not provided any option for the mode (--cloud/--user-managed), therefore
REM stay on user-managed mode in 9.x to avoid behavior changing / breaking changes
set SOLR_MODE="user-managed"
REM and notify that staying the default option (not providing --user-managed) will affect
REM future execution
echo Solr will start in SolrCloud mode by default in version 10, and you will have to provide --user-managed if you want to stay on the user-managed (aka. standalone) mode.
)

IF "%SOLR_MODE%"=="solrcloud" (
@echo Solr will start in SolrCloud mode by default in version 10, and you will no longer need to pass in -c or --cloud flag.
@echo.
IF "%ZK_CLIENT_TIMEOUT%"=="" set "ZK_CLIENT_TIMEOUT=30000"

set "CLOUD_MODE_OPTS=-DzkClientTimeout=!ZK_CLIENT_TIMEOUT!"
Expand Down Expand Up @@ -988,7 +1002,6 @@ IF "%SOLR_MODE%"=="solrcloud" (
IF EXIST "%SOLR_HOME%\collection1\core.properties" set "CLOUD_MODE_OPTS=!CLOUD_MODE_OPTS! -Dbootstrap_confdir=./solr/collection1/conf -Dcollection.configName=myconf -DnumShards=1"
) ELSE (
set CLOUD_MODE_OPTS=
@echo Solr will start in SolrCloud mode by default in version 10. You will need to pass in --user-managed flag to run in User Managed (aka Standalone) mode.
IF NOT EXIST "%SOLR_HOME%\solr.xml" (
IF "%SOLR_SOLRXML_REQUIRED%"=="true" (
set "SCRIPT_ERROR=Solr home directory %SOLR_HOME% must contain solr.xml!"
Expand Down
48 changes: 18 additions & 30 deletions solr/core/src/java/org/apache/solr/cli/PostTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static java.nio.charset.StandardCharsets.US_ASCII;
import static java.nio.charset.StandardCharsets.UTF_8;

import jakarta.ws.rs.core.UriBuilder;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -330,15 +331,24 @@ public void runImpl(CommandLine cli) throws Exception {
}

solrUrl = SolrCLI.normalizeSolrUrl(solrUrl, true, hostContext) + hostContext;
String url = solrUrl + "/" + cli.getOptionValue("name") + "/update";
solrUpdateUrl = new URI(url);

solrUpdateUrl =
UriBuilder.fromUri(SolrCLI.normalizeSolrUrl(solrUrl, true, hostContext))
.path(hostContext)
.path(cli.getOptionValue("name"))
.path("update")
.build();

} else if (cli.hasOption("solr-update-url")) {
String url = cli.getOptionValue("solr-update-url");
solrUpdateUrl = new URI(url);
} else if (cli.hasOption("name")) {
String url = SolrCLI.getDefaultSolrUrl() + "/solr/" + cli.getOptionValue("name") + "/update";
solrUpdateUrl = new URI(url);
solrUpdateUrl =
UriBuilder.fromUri(SolrCLI.getDefaultSolrUrl())
.path("solr")
.path(cli.getOptionValue("name"))
.path("update")
.build();
} else {
throw new IllegalArgumentException(
"Must specify either --solr-update-url or -c parameter to post documents.");
Expand Down Expand Up @@ -450,7 +460,7 @@ private void doWebMode() {
}

// Set Extracting handler as default
solrUpdateUrl = appendUrlPath(solrUpdateUrl, "/extract");
solrUpdateUrl = UriBuilder.fromUri(solrUpdateUrl).path("extract").build();

info("Posting web pages to Solr url " + solrUpdateUrl);
auto = true;
Expand Down Expand Up @@ -896,7 +906,7 @@ public void postFile(File file, OutputStream output, String type)
// TODO: from being interpreted as Solr documents internally
if (type.equals("application/json") && !PostTool.FORMAT_SOLR.equals(format)) {
suffix = "/json/docs";
String urlStr = appendUrlPath(solrUpdateUrl, suffix).toString();
String urlStr = UriBuilder.fromUri(solrUpdateUrl).path(suffix).build().toString();
uri = new URI(urlStr);
} else if (type.equals("application/xml")
|| type.equals("text/csv")
Expand All @@ -905,7 +915,8 @@ public void postFile(File file, OutputStream output, String type)
} else {
// SolrCell
suffix = "/extract";
String urlStr = appendUrlPath(solrUpdateUrl, suffix).toString();
String urlStr = UriBuilder.fromUri(solrUpdateUrl).path(suffix).build().toString();
;
if (!urlStr.contains("resource.name")) {
urlStr =
appendParam(
Expand Down Expand Up @@ -953,29 +964,6 @@ public void postFile(File file, OutputStream output, String type)
}
}

/**
* Appends to the path of the URL
*
* @param uri the URI
* @param append the path to append
* @return the final URL version
*/
protected static URI appendUrlPath(URI uri, String append) {
if (append == null || append.isEmpty()) {
return uri;
}
if (append.startsWith("/")) {
append = append.substring(1);
}
if (uri.getQuery() != null && !uri.getQuery().isEmpty()) {
append += "?" + uri.getQuery();
}
if (!uri.getPath().endsWith("/")) {
append = uri.getPath() + "/" + append;
}
return uri.resolve(append);
}

/**
* Guesses the type of file, based on file name suffix Returns "application/octet-stream" if no
* corresponding mimeMap type.
Expand Down
72 changes: 28 additions & 44 deletions solr/core/src/java/org/apache/solr/cli/SimplePostTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static java.nio.charset.StandardCharsets.US_ASCII;
import static java.nio.charset.StandardCharsets.UTF_8;

import jakarta.ws.rs.core.UriBuilder;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -377,38 +378,34 @@ private void doArgsMode() {
private void doWebMode() {
reset();
int numPagesPosted = 0;
try {
if (type != null) {
fatal("Specifying content-type with \"-Ddata=web\" is not supported");
}
if (args[0].equals("-")) {
// Skip posting url if special param "-" given
return;
}
// Set Extracting handler as default
solrUrl = appendUrlPath(solrUrl, "/extract");
if (type != null) {
fatal("Specifying content-type with \"-Ddata=web\" is not supported");
}
if (args[0].equals("-")) {
// Skip posting url if special param "-" given
return;
}
// Set Extracting handler as default
solrUrl = UriBuilder.fromUri(solrUrl).path("/extract").build();

info("Posting web pages to Solr url " + solrUrl);
auto = true;
info(
"Entering auto mode. Indexing pages with content-types corresponding to file endings "
+ fileTypes);
if (recursive > 0) {
if (recursive > MAX_WEB_DEPTH) {
recursive = MAX_WEB_DEPTH;
warn("Too large recursion depth for web mode, limiting to " + MAX_WEB_DEPTH + "...");
}
if (delay < DEFAULT_WEB_DELAY) {
warn(
"Never crawl an external web site faster than every 10 seconds, your IP will probably be blocked");
}
info("Entering recursive mode, depth=" + recursive + ", delay=" + delay + "s");
info("Posting web pages to Solr url " + solrUrl);
auto = true;
info(
"Entering auto mode. Indexing pages with content-types corresponding to file endings "
+ fileTypes);
if (recursive > 0) {
if (recursive > MAX_WEB_DEPTH) {
recursive = MAX_WEB_DEPTH;
warn("Too large recursion depth for web mode, limiting to " + MAX_WEB_DEPTH + "...");
}
numPagesPosted = postWebPages(args, 0, out);
info(numPagesPosted + " web pages indexed.");
} catch (URISyntaxException e) {
fatal("Wrong URL trying to append /extract to " + solrUrl);
if (delay < DEFAULT_WEB_DELAY) {
warn(
"Never crawl an external web site faster than every 10 seconds, your IP will probably be blocked");
}
info("Entering recursive mode, depth=" + recursive + ", delay=" + delay + "s");
}
numPagesPosted = postWebPages(args, 0, out);
info(numPagesPosted + " web pages indexed.");
}

private void doStdinMode() {
Expand Down Expand Up @@ -862,7 +859,7 @@ public void postFile(File file, OutputStream output, String type) {
// TODO: from being interpreted as Solr documents internally
if (type.equals("application/json") && !FORMAT_SOLR.equals(format)) {
suffix = "/json/docs";
String urlStr = appendUrlPath(solrUrl, suffix).toString();
String urlStr = UriBuilder.fromUri(solrUrl).path(suffix).build().toString();
url = URI.create(urlStr);
} else if (type.equals("application/xml")
|| type.equals("text/csv")
Expand All @@ -871,7 +868,7 @@ public void postFile(File file, OutputStream output, String type) {
} else {
// SolrCell
suffix = "/extract";
String urlStr = appendUrlPath(solrUrl, suffix).toString();
String urlStr = UriBuilder.fromUri(solrUrl).path(suffix).build().toString();
if (!urlStr.contains("resource.name")) {
urlStr =
appendParam(
Expand All @@ -898,8 +895,6 @@ public void postFile(File file, OutputStream output, String type) {
+ (mockMode ? " MOCK!" : ""));
is = new FileInputStream(file);
postData(is, file.length(), output, type, url);
} catch (URISyntaxException e) {
warn("Not valid URL");
} catch (IOException e) {
warn("Can't open/read file: " + file);
} finally {
Expand All @@ -913,17 +908,6 @@ public void postFile(File file, OutputStream output, String type) {
}
}

/**
* Appends to the path of the URI
*
* @param uri the URI
* @param append the path to append
* @return the final URI version
*/
protected static URI appendUrlPath(URI uri, String append) throws URISyntaxException {
return PostTool.appendUrlPath(uri, append);
}

/**
* Guesses the type of file, based on file name suffix Returns "application/octet-stream" if no
* corresponding mimeMap type.
Expand Down
2 changes: 1 addition & 1 deletion solr/core/src/java/org/apache/solr/cli/SolrCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ public static String normalizeSolrUrl(
hostContext = hostContext.substring(0, hostContext.length() - 1);
}
// Only consider URI path component when normalizing hostContext
if (urlPath.contains(hostContext)) {
if (hostContext != null && !hostContext.isBlank() && urlPath.contains(hostContext)) {
String newSolrUrl =
uri.resolve(urlPath.substring(0, urlPath.indexOf(hostContext)) + "/").toString();
if (logUrlFormatWarning) {
Expand Down
22 changes: 0 additions & 22 deletions solr/core/src/test/org/apache/solr/cli/PostToolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,28 +239,6 @@ public void testAppendParam() {
PostTool.appendParam("http://[ff01::114]/?a=b", "foo=bar"));
}

@Test
public void testAppendUrlPath() {
assertEquals(
URI.create("http://[ff01::114]/a?foo=bar"),
PostTool.appendUrlPath(URI.create("http://[ff01::114]?foo=bar"), "/a"));
assertEquals(
URI.create("http://[ff01::114]/a?foo=bar"),
PostTool.appendUrlPath(URI.create("http://[ff01::114]/?foo=bar"), "/a"));
assertEquals(
URI.create("http://[ff01::114]/a/b?foo=bar"),
PostTool.appendUrlPath(URI.create("http://[ff01::114]/a?foo=bar"), "/b"));
assertEquals(
URI.create("http://[ff01::114]/a/b?foo=bar"),
PostTool.appendUrlPath(URI.create("http://[ff01::114]/a/?foo=bar"), "/b"));
assertEquals(
URI.create("http://[ff01::114]/a/b?foo=bar"),
PostTool.appendUrlPath(URI.create("http://[ff01::114]/a?foo=bar"), "b"));
assertEquals(
URI.create("http://[ff01::114]/a/b?foo=bar"),
PostTool.appendUrlPath(URI.create("http://[ff01::114]/a/?foo=bar"), "b"));
}

@Test
public void testGuessType() {
File f = new File("foo.doc");
Expand Down
22 changes: 0 additions & 22 deletions solr/core/src/test/org/apache/solr/cli/SimplePostToolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,28 +155,6 @@ public void testAppendParam() {
SimplePostTool.appendParam("http://[ff01::114]/?a=b", "foo=bar"));
}

@Test
public void testAppendUrlPath() throws URISyntaxException {
assertEquals(
URI.create("http://[ff01::114]/a?foo=bar"),
SimplePostTool.appendUrlPath(URI.create("http://[ff01::114]?foo=bar"), "/a"));
assertEquals(
URI.create("http://[ff01::114]/a?foo=bar"),
SimplePostTool.appendUrlPath(URI.create("http://[ff01::114]/?foo=bar"), "/a"));
assertEquals(
URI.create("http://[ff01::114]/a/b?foo=bar"),
SimplePostTool.appendUrlPath(URI.create("http://[ff01::114]/a?foo=bar"), "/b"));
assertEquals(
URI.create("http://[ff01::114]/a/b?foo=bar"),
SimplePostTool.appendUrlPath(URI.create("http://[ff01::114]/a/?foo=bar"), "/b"));
assertEquals(
URI.create("http://[ff01::114]/a/b?foo=bar"),
SimplePostTool.appendUrlPath(URI.create("http://[ff01::114]/a?foo=bar"), "b"));
assertEquals(
URI.create("http://[ff01::114]/a/b?foo=bar"),
SimplePostTool.appendUrlPath(URI.create("http://[ff01::114]/a/?foo=bar"), "b"));
}

@Test
public void testGuessType() {
File f = new File("foo.doc");
Expand Down
Loading

0 comments on commit 7016e39

Please sign in to comment.