Skip to content

Commit a9817c9

Browse files
authored
SOLR-17482: Change long form of -r to --recursive (#2746)
Use --recursive instead of --recurse to be consistent.
1 parent 723bdc5 commit a9817c9

File tree

10 files changed

+105
-78
lines changed

10 files changed

+105
-78
lines changed

solr/bin/solr.cmd

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,7 @@ IF "%1"=="-V" (
12941294
) ELSE IF "%1"=="-n" (
12951295
goto set_config_name
12961296
) ELSE IF "%1"=="-r" (
1297-
goto set_zk_recurse
1297+
goto set_zk_recursive
12981298
) ELSE IF "%1"=="-configname" (
12991299
goto set_config_name
13001300
) ELSE IF "%1"=="-d" (
@@ -1369,8 +1369,8 @@ set ZK_DST=%~1
13691369
SHIFT
13701370
goto parse_zk_args
13711371

1372-
:set_zk_recurse
1373-
set ZK_RECURSE="true"
1372+
:set_zk_recursive
1373+
set ZK_RECURSIVE="true"
13741374
SHIFT
13751375
goto parse_zk_args
13761376

@@ -1455,7 +1455,7 @@ IF "!ZK_OP!"=="upconfig" (
14551455
"%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% %SOLR_TOOL_OPTS% -Dsolr.install.dir="%SOLR_TIP%" ^
14561456
-Dlog4j.configurationFile="file:///%DEFAULT_SERVER_DIR%\resources\log4j2-console.xml" ^
14571457
-classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
1458-
org.apache.solr.cli.SolrCLI !ZK_OP! -z !ZK_HOST! --source !ZK_SRC! --destination !ZK_DST! --recurse !ZK_RECURSE! %ZK_VERBOSE%
1458+
org.apache.solr.cli.SolrCLI !ZK_OP! -z !ZK_HOST! --source !ZK_SRC! --destination !ZK_DST! --recursive !ZK_RECURSIVE! %ZK_VERBOSE%
14591459
) ELSE IF "!ZK_OP!"=="mv" (
14601460
IF "%ZK_SRC%"=="" (
14611461
set ERROR_MSG="<src> must be specified for 'mv' command"
@@ -1477,7 +1477,7 @@ IF "!ZK_OP!"=="upconfig" (
14771477
"%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% %SOLR_TOOL_OPTS% -Dsolr.install.dir="%SOLR_TIP%" ^
14781478
-Dlog4j.configurationFile="file:///%DEFAULT_SERVER_DIR%\resources\log4j2-console.xml" ^
14791479
-classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
1480-
org.apache.solr.cli.SolrCLI !ZK_OP! -z !ZK_HOST! --path !ZK_SRC! --recurse !ZK_RECURSE! %ZK_VERBOSE%
1480+
org.apache.solr.cli.SolrCLI !ZK_OP! -z !ZK_HOST! --path !ZK_SRC! --recursive !ZK_RECURSIVE! %ZK_VERBOSE%
14811481
) ELSE IF "!ZK_OP!"=="ls" (
14821482
IF "%ZK_SRC"=="" (
14831483
set ERROR_MSG="Zookeeper path to remove must be specified when using the 'ls' command"
@@ -1486,7 +1486,7 @@ IF "!ZK_OP!"=="upconfig" (
14861486
"%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% %SOLR_TOOL_OPTS% -Dsolr.install.dir="%SOLR_TIP%" ^
14871487
-Dlog4j.configurationFile="file:///%DEFAULT_SERVER_DIR%\resources\log4j2-console.xml" ^
14881488
-classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
1489-
org.apache.solr.cli.SolrCLI !ZK_OP! -z !ZK_HOST! --path !ZK_SRC! --recurse !ZK_RECURSE! %ZK_VERBOSE%
1489+
org.apache.solr.cli.SolrCLI !ZK_OP! -z !ZK_HOST! --path !ZK_SRC! --recursive !ZK_RECURSIVE! %ZK_VERBOSE%
14901490
) ELSE IF "!ZK_OP!"=="mkroot" (
14911491
IF "%ZK_SRC"=="" (
14921492
set ERROR_MSG="Zookeeper path to create must be specified when using the 'mkroot' command"

solr/core/src/java/org/apache/solr/cli/SolrCLI.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,22 @@ public class SolrCLI implements CLIO {
172172
public static final Option OPTION_HELP =
173173
Option.builder("h").longOpt("help").required(false).desc("Print this message.").build();
174174

175-
public static final Option OPTION_RECURSE =
176-
Option.builder("r")
175+
public static final Option OPTION_RECURSE_DEPRECATED =
176+
Option.builder()
177177
.longOpt("recurse")
178+
.deprecated(
179+
DeprecatedAttributes.builder()
180+
.setForRemoval(true)
181+
.setSince("9.8")
182+
.setDescription("Use --recursive instead")
183+
.get())
184+
.required(false)
185+
.desc("Apply the command recursively.")
186+
.build();
187+
188+
public static final Option OPTION_RECURSIVE =
189+
Option.builder("r")
190+
.longOpt("recursive")
178191
.required(false)
179192
.desc("Apply the command recursively.")
180193
.build();

solr/core/src/java/org/apache/solr/cli/ZkCpTool.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ public List<Option> getOptions() {
6262
.required(false)
6363
.desc("Required to look up configuration for compressing state.json.")
6464
.build(),
65-
SolrCLI.OPTION_RECURSE,
65+
SolrCLI.OPTION_RECURSE_DEPRECATED,
66+
SolrCLI.OPTION_RECURSIVE,
6667
SolrCLI.OPTION_SOLRURL,
6768
SolrCLI.OPTION_SOLRURL_DEPRECATED,
6869
SolrCLI.OPTION_SOLRURL_DEPRECATED_SHORT,
@@ -132,7 +133,7 @@ public void runImpl(CommandLine cli) throws Exception {
132133
echoIfVerbose("\nConnecting to ZooKeeper at " + zkHost + " ...");
133134
String src = cli.getArgs()[0];
134135
String dst = cli.getArgs()[1];
135-
boolean recurse = cli.hasOption("recurse");
136+
boolean recursive = cli.hasOption("recursive") || cli.hasOption("recurse");
136137
echo("Copying from '" + src + "' to '" + dst + "'. ZooKeeper at " + zkHost);
137138

138139
boolean srcIsZk = src.toLowerCase(Locale.ROOT).startsWith("zk:");
@@ -209,7 +210,7 @@ public void runImpl(CommandLine cli) throws Exception {
209210
.withStateFileCompression(minStateByteLenForCompression, compressor)
210211
.build()) {
211212

212-
zkClient.zkTransfer(srcName, srcIsZk, dstName, dstIsZk, recurse);
213+
zkClient.zkTransfer(srcName, srcIsZk, dstName, dstIsZk, recursive);
213214

214215
} catch (Exception e) {
215216
log.error("Could not complete the zk operation for reason: ", e);

solr/core/src/java/org/apache/solr/cli/ZkLsTool.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public ZkLsTool(PrintStream stdout) {
4040
@Override
4141
public List<Option> getOptions() {
4242
return List.of(
43-
SolrCLI.OPTION_RECURSE,
43+
SolrCLI.OPTION_RECURSE_DEPRECATED,
44+
SolrCLI.OPTION_RECURSIVE,
4445
SolrCLI.OPTION_SOLRURL,
4546
SolrCLI.OPTION_SOLRURL_DEPRECATED,
4647
SolrCLI.OPTION_SOLRURL_DEPRECATED_SHORT,
@@ -69,15 +70,15 @@ public void runImpl(CommandLine cli) throws Exception {
6970
try (SolrZkClient zkClient = SolrCLI.getSolrZkClient(cli, zkHost)) {
7071
echoIfVerbose("\nConnecting to ZooKeeper at " + zkHost + " ...");
7172

72-
boolean recurse = cli.hasOption("recurse");
73+
boolean recursive = cli.hasOption("recursive") || cli.hasOption("recurse");
7374
echoIfVerbose(
7475
"Getting listing for ZooKeeper node "
7576
+ znode
7677
+ " from ZooKeeper at "
7778
+ zkHost
78-
+ " recurse: "
79-
+ recurse);
80-
stdout.print(zkClient.listZnode(znode, recurse));
79+
+ " recursive: "
80+
+ recursive);
81+
stdout.print(zkClient.listZnode(znode, recursive));
8182
} catch (Exception e) {
8283
log.error("Could not complete ls operation for reason: ", e);
8384
throw (e);

solr/core/src/java/org/apache/solr/cli/ZkRmTool.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public ZkRmTool(PrintStream stdout) {
4242
@Override
4343
public List<Option> getOptions() {
4444
return List.of(
45-
SolrCLI.OPTION_RECURSE,
45+
SolrCLI.OPTION_RECURSE_DEPRECATED,
46+
SolrCLI.OPTION_RECURSIVE,
4647
SolrCLI.OPTION_SOLRURL,
4748
SolrCLI.OPTION_SOLRURL_DEPRECATED,
4849
SolrCLI.OPTION_SOLRURL_DEPRECATED_SHORT,
@@ -67,7 +68,7 @@ public void runImpl(CommandLine cli) throws Exception {
6768
String zkHost = SolrCLI.getZkHost(cli);
6869

6970
String target = cli.getArgs()[0];
70-
boolean recurse = cli.hasOption("recurse");
71+
boolean recursive = cli.hasOption("recursive") || cli.hasOption("recurse");
7172

7273
String znode = target;
7374
if (target.toLowerCase(Locale.ROOT).startsWith("zk:")) {
@@ -78,17 +79,17 @@ public void runImpl(CommandLine cli) throws Exception {
7879
}
7980
echoIfVerbose("\nConnecting to ZooKeeper at " + zkHost + " ...");
8081
try (SolrZkClient zkClient = SolrCLI.getSolrZkClient(cli, zkHost)) {
81-
if (!recurse && zkClient.getChildren(znode, null, true).size() != 0) {
82+
if (!recursive && zkClient.getChildren(znode, null, true).size() != 0) {
8283
throw new SolrServerException(
83-
"ZooKeeper node " + znode + " has children and recurse has NOT been specified.");
84+
"ZooKeeper node " + znode + " has children and recursive has NOT been specified.");
8485
}
8586
echo(
8687
"Removing ZooKeeper node "
8788
+ znode
8889
+ " from ZooKeeper at "
8990
+ zkHost
90-
+ " recurse: "
91-
+ recurse);
91+
+ " recursive: "
92+
+ recursive);
9293
zkClient.clean(znode);
9394
} catch (Exception e) {
9495
log.error("Could not complete rm operation for reason: ", e);

solr/core/src/test/org/apache/solr/cli/SolrCLIZkToolsTest.java

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public void testCp() throws Exception {
172172
AbstractDistribZkTestBase.copyConfigUp(configSet, "cloud-subdirs", "cp1", zkAddr);
173173

174174
// Now copy it somewhere else on ZK.
175-
String[] args = new String[] {"--recurse", "--zk-host", zkAddr, "zk:/configs/cp1", "zk:/cp2"};
175+
String[] args = new String[] {"--recursive", "--zk-host", zkAddr, "zk:/configs/cp1", "zk:/cp2"};
176176

177177
ZkCpTool cpTool = new ZkCpTool();
178178

@@ -184,7 +184,7 @@ public void testCp() throws Exception {
184184
Path tmp = createTempDir("tmpNewPlace2");
185185
args =
186186
new String[] {
187-
"--recurse", "--zk-host", zkAddr, "zk:/configs/cp1", "file:" + tmp.toAbsolutePath()
187+
"--recursive", "--zk-host", zkAddr, "zk:/configs/cp1", "file:" + tmp.toAbsolutePath()
188188
};
189189

190190
res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
@@ -195,7 +195,7 @@ public void testCp() throws Exception {
195195
tmp = createTempDir("tmpNewPlace3");
196196
args =
197197
new String[] {
198-
"--recurse", "--zk-host", zkAddr, "zk:/configs/cp1", tmp.toAbsolutePath().toString()
198+
"--recursive", "--zk-host", zkAddr, "zk:/configs/cp1", tmp.toAbsolutePath().toString()
199199
};
200200

201201
res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
@@ -205,7 +205,7 @@ public void testCp() throws Exception {
205205
// try with local->zk
206206
args =
207207
new String[] {
208-
"--recurse", "--zk-host", zkAddr, srcPathCheck.toAbsolutePath().toString(), "zk:/cp3"
208+
"--recursive", "--zk-host", zkAddr, srcPathCheck.toAbsolutePath().toString(), "zk:/cp3"
209209
};
210210

211211
res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
@@ -215,19 +215,19 @@ public void testCp() throws Exception {
215215
// try with local->zk, file: specified
216216
args =
217217
new String[] {
218-
"--recurse", "--zk-host", zkAddr, "file:" + srcPathCheck.toAbsolutePath(), "zk:/cp4"
218+
"--recursive", "--zk-host", zkAddr, "file:" + srcPathCheck.toAbsolutePath(), "zk:/cp4"
219219
};
220220

221221
res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
222222
assertEquals("Copy should have succeeded.", 0, res);
223223
verifyZkLocalPathsMatch(srcPathCheck, "/cp4");
224224

225-
// try with recurse not specified, and therefore not happening
225+
// try with recursive not specified, and therefore not happening
226226
args =
227227
new String[] {"--zk-host", zkAddr, "file:" + srcPathCheck.toAbsolutePath(), "zk:/cp5Fail"};
228228

229229
res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
230-
assertTrue("Copy should NOT have succeeded, recurse not specified.", 0 != res);
230+
assertTrue("Copy should NOT have succeeded, recursive not specified.", 0 != res);
231231

232232
// NOTE: really can't test copying to '.' because the test framework doesn't allow altering the
233233
// source tree and at least IntelliJ's CWD is in the source tree.
@@ -309,7 +309,7 @@ public void testCp() throws Exception {
309309
// source path to the dst
310310
args =
311311
new String[] {
312-
"--recurse", "--zk-host", zkAddr, "file:" + srcPathCheck.toAbsolutePath(), "zk:/cp7/"
312+
"--recursive", "--zk-host", zkAddr, "file:" + srcPathCheck.toAbsolutePath(), "zk:/cp7/"
313313
};
314314

315315
res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
@@ -341,7 +341,9 @@ public void testCp() throws Exception {
341341

342342
tmp = createTempDir("cp8");
343343
args =
344-
new String[] {"--recurse", "--zk-host", zkAddr, "zk:/cp7", "file:" + tmp.toAbsolutePath()};
344+
new String[] {
345+
"--recursive", "--zk-host", zkAddr, "zk:/cp7", "file:" + tmp.toAbsolutePath()
346+
};
345347
res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
346348
assertEquals("Copy should have succeeded.", 0, res);
347349

@@ -351,7 +353,9 @@ public void testCp() throws Exception {
351353

352354
// Finally, copy up to cp8 and verify that the data is up there.
353355
args =
354-
new String[] {"--recurse", "--zk-host", zkAddr, "file:" + tmp.toAbsolutePath(), "zk:/cp9"};
356+
new String[] {
357+
"--recursive", "--zk-host", zkAddr, "file:" + tmp.toAbsolutePath(), "zk:/cp9"
358+
};
355359

356360
res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
357361
assertEquals("Copy should have succeeded.", 0, res);
@@ -394,7 +398,7 @@ public void testCp() throws Exception {
394398

395399
args =
396400
new String[] {
397-
"--recurse",
401+
"--recursive",
398402
"--zk-host",
399403
zkAddr,
400404
"file:" + emptyFile.getParent().getParent().toString(),
@@ -408,7 +412,7 @@ public void testCp() throws Exception {
408412
tmp2 = createTempDir("cp10");
409413
args =
410414
new String[] {
411-
"--recurse", "--zk-host", zkAddr, "zk:/cp10", "file:" + tmp2.toAbsolutePath()
415+
"--recursive", "--zk-host", zkAddr, "zk:/cp10", "file:" + tmp2.toAbsolutePath()
412416
};
413417
res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
414418
assertEquals("Copy should have succeeded.", 0, res);
@@ -516,7 +520,7 @@ public void testLs() throws Exception {
516520
assertFalse("Return should NOT contain a child node", content.contains("solrconfig.xml"));
517521

518522
// ls with recursion
519-
args = new String[] {"--recurse", "--zk-host", zkAddr, "/configs"};
523+
args = new String[] {"--recursive", "--zk-host", zkAddr, "/configs"};
520524

521525
res = tool.runTool(SolrCLI.processCommandLineArgs(tool, args));
522526
content = baos.toString(StandardCharsets.UTF_8);
@@ -526,7 +530,7 @@ public void testLs() throws Exception {
526530
assertTrue("Return should contain a child node", content.contains("solrconfig.xml"));
527531

528532
// Saw a case where going from root didn't work, so test it.
529-
args = new String[] {"--recurse", "--zk-host", zkAddr, "/"};
533+
args = new String[] {"--recursive", "--zk-host", zkAddr, "/"};
530534

531535
res = tool.runTool(SolrCLI.processCommandLineArgs(tool, args));
532536
content = baos.toString(StandardCharsets.UTF_8);
@@ -543,7 +547,7 @@ public void testLs() throws Exception {
543547
assertFalse("Return should not contain /zookeeper", content.contains("/zookeeper"));
544548

545549
// Saw a case where ending in slash didn't work, so test it.
546-
args = new String[] {"--recurse", "--zk-host", zkAddr, "/configs/"};
550+
args = new String[] {"--recursive", "--zk-host", zkAddr, "/configs/"};
547551

548552
res = tool.runTool(SolrCLI.processCommandLineArgs(tool, args));
549553
content = baos.toString(StandardCharsets.UTF_8);
@@ -562,43 +566,44 @@ public void testRm() throws Exception {
562566
AbstractDistribZkTestBase.copyConfigUp(configSet, "cloud-subdirs", "rm1", zkAddr);
563567
AbstractDistribZkTestBase.copyConfigUp(configSet, "cloud-subdirs", "rm2", zkAddr);
564568

565-
// Should fail if recurse not set.
569+
// Should fail if recursive not set.
566570
String[] args = new String[] {"--zk-host", zkAddr, "/configs/rm1"};
567571

568572
ZkRmTool tool = new ZkRmTool();
569573

570574
int res = tool.runTool(SolrCLI.processCommandLineArgs(tool, args));
571575

572-
assertTrue("Should have failed to remove node with children unless --recurse is set", res != 0);
576+
assertTrue(
577+
"Should have failed to remove node with children unless --recursive is set", res != 0);
573578

574579
// Are we sure all the znodes are still there?
575580
verifyZkLocalPathsMatch(srcPathCheck, "/configs/rm1");
576581

577-
// run without recurse specified
582+
// run without recursive specified
578583
args = new String[] {"--zk-host", zkAddr, "zk:/configs/rm1"};
579584

580585
res = tool.runTool(SolrCLI.processCommandLineArgs(tool, args));
581586

582587
assertTrue(
583-
"Should have failed to remove node with children if --recurse is set to false", res != 0);
588+
"Should have failed to remove node with children if --recursive is set to false", res != 0);
584589

585-
args = new String[] {"--recurse", "--zk-host", zkAddr, "/configs/rm1"};
590+
args = new String[] {"--recursive", "--zk-host", zkAddr, "/configs/rm1"};
586591

587592
res = tool.runTool(SolrCLI.processCommandLineArgs(tool, args));
588593
assertEquals("Should have removed node /configs/rm1", res, 0);
589594
assertFalse(
590595
"Znode /configs/toremove really should be gone", zkClient.exists("/configs/rm1", true));
591596

592597
// Check that zk prefix also works.
593-
args = new String[] {"--recurse", "--zk-host", zkAddr, "zk:/configs/rm2"};
598+
args = new String[] {"--recursive", "--zk-host", zkAddr, "zk:/configs/rm2"};
594599

595600
res = tool.runTool(SolrCLI.processCommandLineArgs(tool, args));
596601
assertEquals("Should have removed node /configs/rm2", res, 0);
597602
assertFalse(
598603
"Znode /configs/toremove2 really should be gone", zkClient.exists("/configs/rm2", true));
599604

600605
// This should silently just refuse to do anything to the / or /zookeeper
601-
args = new String[] {"--recurse", "--zk-host", zkAddr, "zk:/"};
606+
args = new String[] {"--recursive", "--zk-host", zkAddr, "zk:/"};
602607

603608
AbstractDistribZkTestBase.copyConfigUp(configSet, "cloud-subdirs", "rm3", zkAddr);
604609
res = tool.runTool(SolrCLI.processCommandLineArgs(tool, args));

solr/packaging/test/test_zk.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ teardown() {
6060

6161
@test "listing out files" {
6262
sleep 1
63-
run solr zk ls / -z localhost:${ZK_PORT}
63+
run solr zk ls / -z localhost:${ZK_PORT} --recursive
6464
assert_output --partial "aliases.json"
6565
}
6666

solr/solr-ref-guide/modules/deployment-guide/pages/solr-control-script-reference.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,7 @@ This command will copy from the local drive to ZooKeeper, from ZooKeeper to the
13011301

13021302
==== ZK Copy Parameters
13031303

1304-
`-r`::
1304+
`-r` or `--recursive`::
13051305
+
13061306
[%autowidth,frame=none]
13071307
|===
@@ -1401,7 +1401,7 @@ Use the `zk rm` command to remove a znode (and optionally all child nodes) from
14011401

14021402
==== ZK Remove Parameters
14031403

1404-
`-r`::
1404+
`-r` or `--recursive`::
14051405
+
14061406
[%autowidth,frame=none]
14071407
|===
@@ -1522,7 +1522,7 @@ Use the `zk ls` command to see the children of a znode.
15221522

15231523
==== ZK List Parameters
15241524

1525-
`-r`::
1525+
`-r` or `--recursive`::
15261526
+
15271527
[%autowidth,frame=none]
15281528
|===

0 commit comments

Comments
 (0)