Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-17482: Change long form of -r to --recursive (#2746)

Eric Pugha9817c9aadea
diff --git a/solr/bin/solr.cmd b/solr/bin/solr.cmd
index 71660352917..01b86d3a41f 100755
--- a/solr/bin/solr.cmd
+++ b/solr/bin/solr.cmd
@@ -1294,7 +1294,7 @@ IF "%1"=="-V" (
) ELSE IF "%1"=="-n" (
goto set_config_name
) ELSE IF "%1"=="-r" (
- goto set_zk_recurse
+ goto set_zk_recursive
) ELSE IF "%1"=="-configname" (
goto set_config_name
) ELSE IF "%1"=="-d" (
@@ -1369,8 +1369,8 @@ set ZK_DST=%~1
SHIFT
goto parse_zk_args
-:set_zk_recurse
-set ZK_RECURSE="true"
+:set_zk_recursive
+set ZK_RECURSIVE="true"
SHIFT
goto parse_zk_args
@@ -1455,7 +1455,7 @@ IF "!ZK_OP!"=="upconfig" (
"%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 "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
- org.apache.solr.cli.SolrCLI !ZK_OP! -z !ZK_HOST! --source !ZK_SRC! --destination !ZK_DST! --recurse !ZK_RECURSE! %ZK_VERBOSE%
+ org.apache.solr.cli.SolrCLI !ZK_OP! -z !ZK_HOST! --source !ZK_SRC! --destination !ZK_DST! --recursive !ZK_RECURSIVE! %ZK_VERBOSE%
) ELSE IF "!ZK_OP!"=="mv" (
IF "%ZK_SRC%"=="" (
set ERROR_MSG="<src> must be specified for 'mv' command"
@@ -1477,7 +1477,7 @@ IF "!ZK_OP!"=="upconfig" (
"%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 "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
- org.apache.solr.cli.SolrCLI !ZK_OP! -z !ZK_HOST! --path !ZK_SRC! --recurse !ZK_RECURSE! %ZK_VERBOSE%
+ org.apache.solr.cli.SolrCLI !ZK_OP! -z !ZK_HOST! --path !ZK_SRC! --recursive !ZK_RECURSIVE! %ZK_VERBOSE%
) ELSE IF "!ZK_OP!"=="ls" (
IF "%ZK_SRC"=="" (
set ERROR_MSG="Zookeeper path to remove must be specified when using the 'ls' command"
@@ -1486,7 +1486,7 @@ IF "!ZK_OP!"=="upconfig" (
"%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 "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
- org.apache.solr.cli.SolrCLI !ZK_OP! -z !ZK_HOST! --path !ZK_SRC! --recurse !ZK_RECURSE! %ZK_VERBOSE%
+ org.apache.solr.cli.SolrCLI !ZK_OP! -z !ZK_HOST! --path !ZK_SRC! --recursive !ZK_RECURSIVE! %ZK_VERBOSE%
) ELSE IF "!ZK_OP!"=="mkroot" (
IF "%ZK_SRC"=="" (
set ERROR_MSG="Zookeeper path to create must be specified when using the 'mkroot' command"
diff --git a/solr/core/src/java/org/apache/solr/cli/SolrCLI.java b/solr/core/src/java/org/apache/solr/cli/SolrCLI.java
index ade06a26d08..bfe8e66179b 100755
--- a/solr/core/src/java/org/apache/solr/cli/SolrCLI.java
+++ b/solr/core/src/java/org/apache/solr/cli/SolrCLI.java
@@ -172,9 +172,22 @@ public class SolrCLI implements CLIO {
public static final Option OPTION_HELP =
Option.builder("h").longOpt("help").required(false).desc("Print this message.").build();
- public static final Option OPTION_RECURSE =
- Option.builder("r")
+ public static final Option OPTION_RECURSE_DEPRECATED =
+ Option.builder()
.longOpt("recurse")
+ .deprecated(
+ DeprecatedAttributes.builder()
+ .setForRemoval(true)
+ .setSince("9.8")
+ .setDescription("Use --recursive instead")
+ .get())
+ .required(false)
+ .desc("Apply the command recursively.")
+ .build();
+
+ public static final Option OPTION_RECURSIVE =
+ Option.builder("r")
+ .longOpt("recursive")
.required(false)
.desc("Apply the command recursively.")
.build();
diff --git a/solr/core/src/java/org/apache/solr/cli/ZkCpTool.java b/solr/core/src/java/org/apache/solr/cli/ZkCpTool.java
index aaa04d2091b..197156c8652 100644
--- a/solr/core/src/java/org/apache/solr/cli/ZkCpTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/ZkCpTool.java
@@ -62,7 +62,8 @@ public class ZkCpTool extends ToolBase {
.required(false)
.desc("Required to look up configuration for compressing state.json.")
.build(),
- SolrCLI.OPTION_RECURSE,
+ SolrCLI.OPTION_RECURSE_DEPRECATED,
+ SolrCLI.OPTION_RECURSIVE,
SolrCLI.OPTION_SOLRURL,
SolrCLI.OPTION_SOLRURL_DEPRECATED,
SolrCLI.OPTION_SOLRURL_DEPRECATED_SHORT,
@@ -132,7 +133,7 @@ public class ZkCpTool extends ToolBase {
echoIfVerbose("\nConnecting to ZooKeeper at " + zkHost + " ...");
String src = cli.getArgs()[0];
String dst = cli.getArgs()[1];
- boolean recurse = cli.hasOption("recurse");
+ boolean recursive = cli.hasOption("recursive") || cli.hasOption("recurse");
echo("Copying from '" + src + "' to '" + dst + "'. ZooKeeper at " + zkHost);
boolean srcIsZk = src.toLowerCase(Locale.ROOT).startsWith("zk:");
@@ -209,7 +210,7 @@ public class ZkCpTool extends ToolBase {
.withStateFileCompression(minStateByteLenForCompression, compressor)
.build()) {
- zkClient.zkTransfer(srcName, srcIsZk, dstName, dstIsZk, recurse);
+ zkClient.zkTransfer(srcName, srcIsZk, dstName, dstIsZk, recursive);
} catch (Exception e) {
log.error("Could not complete the zk operation for reason: ", e);
diff --git a/solr/core/src/java/org/apache/solr/cli/ZkLsTool.java b/solr/core/src/java/org/apache/solr/cli/ZkLsTool.java
index 390a8a30988..329e8f47dc3 100644
--- a/solr/core/src/java/org/apache/solr/cli/ZkLsTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/ZkLsTool.java
@@ -40,7 +40,8 @@ public class ZkLsTool extends ToolBase {
@Override
public List<Option> getOptions() {
return List.of(
- SolrCLI.OPTION_RECURSE,
+ SolrCLI.OPTION_RECURSE_DEPRECATED,
+ SolrCLI.OPTION_RECURSIVE,
SolrCLI.OPTION_SOLRURL,
SolrCLI.OPTION_SOLRURL_DEPRECATED,
SolrCLI.OPTION_SOLRURL_DEPRECATED_SHORT,
@@ -69,15 +70,15 @@ public class ZkLsTool extends ToolBase {
try (SolrZkClient zkClient = SolrCLI.getSolrZkClient(cli, zkHost)) {
echoIfVerbose("\nConnecting to ZooKeeper at " + zkHost + " ...");
- boolean recurse = cli.hasOption("recurse");
+ boolean recursive = cli.hasOption("recursive") || cli.hasOption("recurse");
echoIfVerbose(
"Getting listing for ZooKeeper node "
+ znode
+ " from ZooKeeper at "
+ zkHost
- + " recurse: "
- + recurse);
- stdout.print(zkClient.listZnode(znode, recurse));
+ + " recursive: "
+ + recursive);
+ stdout.print(zkClient.listZnode(znode, recursive));
} catch (Exception e) {
log.error("Could not complete ls operation for reason: ", e);
throw (e);
diff --git a/solr/core/src/java/org/apache/solr/cli/ZkRmTool.java b/solr/core/src/java/org/apache/solr/cli/ZkRmTool.java
index fa8b578bf3d..bf3e408ca53 100644
--- a/solr/core/src/java/org/apache/solr/cli/ZkRmTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/ZkRmTool.java
@@ -42,7 +42,8 @@ public class ZkRmTool extends ToolBase {
@Override
public List<Option> getOptions() {
return List.of(
- SolrCLI.OPTION_RECURSE,
+ SolrCLI.OPTION_RECURSE_DEPRECATED,
+ SolrCLI.OPTION_RECURSIVE,
SolrCLI.OPTION_SOLRURL,
SolrCLI.OPTION_SOLRURL_DEPRECATED,
SolrCLI.OPTION_SOLRURL_DEPRECATED_SHORT,
@@ -67,7 +68,7 @@ public class ZkRmTool extends ToolBase {
String zkHost = SolrCLI.getZkHost(cli);
String target = cli.getArgs()[0];
- boolean recurse = cli.hasOption("recurse");
+ boolean recursive = cli.hasOption("recursive") || cli.hasOption("recurse");
String znode = target;
if (target.toLowerCase(Locale.ROOT).startsWith("zk:")) {
@@ -78,17 +79,17 @@ public class ZkRmTool extends ToolBase {
}
echoIfVerbose("\nConnecting to ZooKeeper at " + zkHost + " ...");
try (SolrZkClient zkClient = SolrCLI.getSolrZkClient(cli, zkHost)) {
- if (!recurse && zkClient.getChildren(znode, null, true).size() != 0) {
+ if (!recursive && zkClient.getChildren(znode, null, true).size() != 0) {
throw new SolrServerException(
- "ZooKeeper node " + znode + " has children and recurse has NOT been specified.");
+ "ZooKeeper node " + znode + " has children and recursive has NOT been specified.");
}
echo(
"Removing ZooKeeper node "
+ znode
+ " from ZooKeeper at "
+ zkHost
- + " recurse: "
- + recurse);
+ + " recursive: "
+ + recursive);
zkClient.clean(znode);
} catch (Exception e) {
log.error("Could not complete rm operation for reason: ", e);
diff --git a/solr/core/src/test/org/apache/solr/cli/SolrCLIZkToolsTest.java b/solr/core/src/test/org/apache/solr/cli/SolrCLIZkToolsTest.java
index 60883139e88..6644acde895 100644
--- a/solr/core/src/test/org/apache/solr/cli/SolrCLIZkToolsTest.java
+++ b/solr/core/src/test/org/apache/solr/cli/SolrCLIZkToolsTest.java
@@ -172,7 +172,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
AbstractDistribZkTestBase.copyConfigUp(configSet, "cloud-subdirs", "cp1", zkAddr);
// Now copy it somewhere else on ZK.
- String[] args = new String[] {"--recurse", "--zk-host", zkAddr, "zk:/configs/cp1", "zk:/cp2"};
+ String[] args = new String[] {"--recursive", "--zk-host", zkAddr, "zk:/configs/cp1", "zk:/cp2"};
ZkCpTool cpTool = new ZkCpTool();
@@ -184,7 +184,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
Path tmp = createTempDir("tmpNewPlace2");
args =
new String[] {
- "--recurse", "--zk-host", zkAddr, "zk:/configs/cp1", "file:" + tmp.toAbsolutePath()
+ "--recursive", "--zk-host", zkAddr, "zk:/configs/cp1", "file:" + tmp.toAbsolutePath()
};
res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
@@ -195,7 +195,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
tmp = createTempDir("tmpNewPlace3");
args =
new String[] {
- "--recurse", "--zk-host", zkAddr, "zk:/configs/cp1", tmp.toAbsolutePath().toString()
+ "--recursive", "--zk-host", zkAddr, "zk:/configs/cp1", tmp.toAbsolutePath().toString()
};
res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
@@ -205,7 +205,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
// try with local->zk
args =
new String[] {
- "--recurse", "--zk-host", zkAddr, srcPathCheck.toAbsolutePath().toString(), "zk:/cp3"
+ "--recursive", "--zk-host", zkAddr, srcPathCheck.toAbsolutePath().toString(), "zk:/cp3"
};
res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
@@ -215,19 +215,19 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
// try with local->zk, file: specified
args =
new String[] {
- "--recurse", "--zk-host", zkAddr, "file:" + srcPathCheck.toAbsolutePath(), "zk:/cp4"
+ "--recursive", "--zk-host", zkAddr, "file:" + srcPathCheck.toAbsolutePath(), "zk:/cp4"
};
res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
assertEquals("Copy should have succeeded.", 0, res);
verifyZkLocalPathsMatch(srcPathCheck, "/cp4");
- // try with recurse not specified, and therefore not happening
+ // try with recursive not specified, and therefore not happening
args =
new String[] {"--zk-host", zkAddr, "file:" + srcPathCheck.toAbsolutePath(), "zk:/cp5Fail"};
res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
- assertTrue("Copy should NOT have succeeded, recurse not specified.", 0 != res);
+ assertTrue("Copy should NOT have succeeded, recursive not specified.", 0 != res);
// NOTE: really can't test copying to '.' because the test framework doesn't allow altering the
// source tree and at least IntelliJ's CWD is in the source tree.
@@ -309,7 +309,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
// source path to the dst
args =
new String[] {
- "--recurse", "--zk-host", zkAddr, "file:" + srcPathCheck.toAbsolutePath(), "zk:/cp7/"
+ "--recursive", "--zk-host", zkAddr, "file:" + srcPathCheck.toAbsolutePath(), "zk:/cp7/"
};
res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
@@ -341,7 +341,9 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
tmp = createTempDir("cp8");
args =
- new String[] {"--recurse", "--zk-host", zkAddr, "zk:/cp7", "file:" + tmp.toAbsolutePath()};
+ new String[] {
+ "--recursive", "--zk-host", zkAddr, "zk:/cp7", "file:" + tmp.toAbsolutePath()
+ };
res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
assertEquals("Copy should have succeeded.", 0, res);
@@ -351,7 +353,9 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
// Finally, copy up to cp8 and verify that the data is up there.
args =
- new String[] {"--recurse", "--zk-host", zkAddr, "file:" + tmp.toAbsolutePath(), "zk:/cp9"};
+ new String[] {
+ "--recursive", "--zk-host", zkAddr, "file:" + tmp.toAbsolutePath(), "zk:/cp9"
+ };
res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
assertEquals("Copy should have succeeded.", 0, res);
@@ -394,7 +398,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
args =
new String[] {
- "--recurse",
+ "--recursive",
"--zk-host",
zkAddr,
"file:" + emptyFile.getParent().getParent().toString(),
@@ -408,7 +412,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
tmp2 = createTempDir("cp10");
args =
new String[] {
- "--recurse", "--zk-host", zkAddr, "zk:/cp10", "file:" + tmp2.toAbsolutePath()
+ "--recursive", "--zk-host", zkAddr, "zk:/cp10", "file:" + tmp2.toAbsolutePath()
};
res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
assertEquals("Copy should have succeeded.", 0, res);
@@ -516,7 +520,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
assertFalse("Return should NOT contain a child node", content.contains("solrconfig.xml"));
// ls with recursion
- args = new String[] {"--recurse", "--zk-host", zkAddr, "/configs"};
+ args = new String[] {"--recursive", "--zk-host", zkAddr, "/configs"};
res = tool.runTool(SolrCLI.processCommandLineArgs(tool, args));
content = baos.toString(StandardCharsets.UTF_8);
@@ -526,7 +530,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
assertTrue("Return should contain a child node", content.contains("solrconfig.xml"));
// Saw a case where going from root didn't work, so test it.
- args = new String[] {"--recurse", "--zk-host", zkAddr, "/"};
+ args = new String[] {"--recursive", "--zk-host", zkAddr, "/"};
res = tool.runTool(SolrCLI.processCommandLineArgs(tool, args));
content = baos.toString(StandardCharsets.UTF_8);
@@ -543,7 +547,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
assertFalse("Return should not contain /zookeeper", content.contains("/zookeeper"));
// Saw a case where ending in slash didn't work, so test it.
- args = new String[] {"--recurse", "--zk-host", zkAddr, "/configs/"};
+ args = new String[] {"--recursive", "--zk-host", zkAddr, "/configs/"};
res = tool.runTool(SolrCLI.processCommandLineArgs(tool, args));
content = baos.toString(StandardCharsets.UTF_8);
@@ -562,27 +566,28 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
AbstractDistribZkTestBase.copyConfigUp(configSet, "cloud-subdirs", "rm1", zkAddr);
AbstractDistribZkTestBase.copyConfigUp(configSet, "cloud-subdirs", "rm2", zkAddr);
- // Should fail if recurse not set.
+ // Should fail if recursive not set.
String[] args = new String[] {"--zk-host", zkAddr, "/configs/rm1"};
ZkRmTool tool = new ZkRmTool();
int res = tool.runTool(SolrCLI.processCommandLineArgs(tool, args));
- assertTrue("Should have failed to remove node with children unless --recurse is set", res != 0);
+ assertTrue(
+ "Should have failed to remove node with children unless --recursive is set", res != 0);
// Are we sure all the znodes are still there?
verifyZkLocalPathsMatch(srcPathCheck, "/configs/rm1");
- // run without recurse specified
+ // run without recursive specified
args = new String[] {"--zk-host", zkAddr, "zk:/configs/rm1"};
res = tool.runTool(SolrCLI.processCommandLineArgs(tool, args));
assertTrue(
- "Should have failed to remove node with children if --recurse is set to false", res != 0);
+ "Should have failed to remove node with children if --recursive is set to false", res != 0);
- args = new String[] {"--recurse", "--zk-host", zkAddr, "/configs/rm1"};
+ args = new String[] {"--recursive", "--zk-host", zkAddr, "/configs/rm1"};
res = tool.runTool(SolrCLI.processCommandLineArgs(tool, args));
assertEquals("Should have removed node /configs/rm1", res, 0);
@@ -590,7 +595,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
"Znode /configs/toremove really should be gone", zkClient.exists("/configs/rm1", true));
// Check that zk prefix also works.
- args = new String[] {"--recurse", "--zk-host", zkAddr, "zk:/configs/rm2"};
+ args = new String[] {"--recursive", "--zk-host", zkAddr, "zk:/configs/rm2"};
res = tool.runTool(SolrCLI.processCommandLineArgs(tool, args));
assertEquals("Should have removed node /configs/rm2", res, 0);
@@ -598,7 +603,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
"Znode /configs/toremove2 really should be gone", zkClient.exists("/configs/rm2", true));
// This should silently just refuse to do anything to the / or /zookeeper
- args = new String[] {"--recurse", "--zk-host", zkAddr, "zk:/"};
+ args = new String[] {"--recursive", "--zk-host", zkAddr, "zk:/"};
AbstractDistribZkTestBase.copyConfigUp(configSet, "cloud-subdirs", "rm3", zkAddr);
res = tool.runTool(SolrCLI.processCommandLineArgs(tool, args));
diff --git a/solr/packaging/test/test_zk.bats b/solr/packaging/test/test_zk.bats
index a87d8130911..f823f70c9a1 100644
--- a/solr/packaging/test/test_zk.bats
+++ b/solr/packaging/test/test_zk.bats
@@ -60,7 +60,7 @@ teardown() {
@test "listing out files" {
sleep 1
- run solr zk ls / -z localhost:${ZK_PORT}
+ run solr zk ls / -z localhost:${ZK_PORT} --recursive
assert_output --partial "aliases.json"
}
diff --git a/solr/solr-ref-guide/modules/deployment-guide/pages/solr-control-script-reference.adoc b/solr/solr-ref-guide/modules/deployment-guide/pages/solr-control-script-reference.adoc
index 6af26e74de4..1de23c1b048 100644
--- a/solr/solr-ref-guide/modules/deployment-guide/pages/solr-control-script-reference.adoc
+++ b/solr/solr-ref-guide/modules/deployment-guide/pages/solr-control-script-reference.adoc
@@ -1301,7 +1301,7 @@ This command will copy from the local drive to ZooKeeper, from ZooKeeper to the
==== ZK Copy Parameters
-`-r`::
+`-r` or `--recursive`::
+
[%autowidth,frame=none]
|===
@@ -1401,7 +1401,7 @@ Use the `zk rm` command to remove a znode (and optionally all child nodes) from
==== ZK Remove Parameters
-`-r`::
+`-r` or `--recursive`::
+
[%autowidth,frame=none]
|===
@@ -1522,7 +1522,7 @@ Use the `zk ls` command to see the children of a znode.
==== ZK List Parameters
-`-r`::
+`-r` or `--recursive`::
+
[%autowidth,frame=none]
|===
diff --git a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java
index a3fe06f4a11..55ac5cf30a8 100644
--- a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java
+++ b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java
@@ -66,28 +66,27 @@ public class ZkMaintenanceUtils {
* Lists a ZNode child and (optionally) the znodes of all the children. No data is dumped.
*
* @param path The node to remove on Zookeeper
- * @param recurse Whether to remove children.
+ * @param recursive Whether to remove children.
* @throws KeeperException Could not perform the Zookeeper operation.
* @throws InterruptedException Thread interrupted
- * @throws SolrServerException zookeeper node has children and recurse not specified.
* @return an indented list of the znodes suitable for display
*/
- public static String listZnode(SolrZkClient zkClient, String path, Boolean recurse)
- throws KeeperException, InterruptedException, SolrServerException {
+ public static String listZnode(SolrZkClient zkClient, String path, Boolean recursive)
+ throws KeeperException, InterruptedException {
String root = path;
if (path.toLowerCase(Locale.ROOT).startsWith("zk:")) {
root = path.substring(3);
}
- if (root.equals("/") == false && root.endsWith("/")) {
+ if (!root.equals("/") && root.endsWith("/")) {
root = root.substring(0, root.length() - 1);
}
StringBuilder sb = new StringBuilder();
- if (recurse == false) {
+ if (!recursive) {
for (String node : zkClient.getChildren(root, null, true)) {
- if (node.equals("zookeeper") == false) {
+ if (!node.equals("zookeeper")) {
sb.append(node).append(System.lineSeparator());
}
}
@@ -102,7 +101,9 @@ public class ZkMaintenanceUtils {
if (znode.startsWith("/zookeeper")) return; // can't do anything with this node!
int iPos = znode.lastIndexOf('/');
if (iPos > 0) {
- for (int idx = 0; idx < iPos; ++idx) sb.append(" ");
+ for (int idx = 0; idx < iPos; ++idx) {
+ sb.append(" ");
+ }
sb.append(znode.substring(iPos + 1)).append(System.lineSeparator());
} else {
sb.append(znode).append(System.lineSeparator());
@@ -117,9 +118,9 @@ public class ZkMaintenanceUtils {
* copying recursively.
*
* @param src Source to copy from. Both src and dst may be Znodes. However, both may NOT be local
- * @param dst The place to copy the files too. Both src and dst may be Znodes. However both may
+ * @param dst The place to copy the files too. Both src and dst may be Znodes. However, both may
* NOT be local
- * @param recurse if the source is a directory, reccursively copy the contents iff this is true.
+ * @param recursive if the source is a directory, recursively copy the contents iff this is true.
* @throws SolrServerException Explanatory exception due to bad params, failed operation, etc.
* @throws KeeperException Could not perform the Zookeeper operation.
* @throws InterruptedException Thread interrupted
@@ -130,19 +131,19 @@ public class ZkMaintenanceUtils {
Boolean srcIsZk,
String dst,
Boolean dstIsZk,
- Boolean recurse)
+ Boolean recursive)
throws SolrServerException, KeeperException, InterruptedException, IOException {
- if (srcIsZk == false && dstIsZk == false) {
+ if (!srcIsZk && !dstIsZk) {
throw new SolrServerException("One or both of source or destination must specify ZK nodes.");
}
- // Make sure --recurse is specified if the source has children.
- if (recurse == false) {
+ // Make sure --recursive is specified if the source has children.
+ if (!recursive) {
if (srcIsZk) {
if (zkClient.getChildren(src, null, true).size() != 0) {
throw new SolrServerException(
- "Zookeeper node " + src + " has children and recurse is false");
+ "Zookeeper node " + src + " has children and recursive is false");
}
} else if (Files.isDirectory(Paths.get(src))) {
throw new SolrServerException(
@@ -179,7 +180,7 @@ public class ZkMaintenanceUtils {
// Single file ZK -> local copy where ZK is a leaf node
if (Files.isDirectory(Paths.get(dst))) {
- if (dst.endsWith(File.separator) == false) {
+ if (!dst.endsWith(File.separator)) {
dst += File.separator;
}
dst = normalizeDest(src, dst, srcIsZk, dstIsZk);
@@ -239,13 +240,13 @@ public class ZkMaintenanceUtils {
clean(zkClient, src);
}
- // Insure that all the nodes in one path match the nodes in the other as a safety check before
+ // Ensure that all the nodes in one path match the nodes in the other as a safety check before
// removing the source in a 'mv' command.
private static void checkAllZnodesThere(SolrZkClient zkClient, String src, String dst)
throws KeeperException, InterruptedException, SolrServerException {
for (String node : zkClient.getChildren(src, null, true)) {
- if (zkClient.exists(dst + "/" + node, true) == false) {
+ if (!zkClient.exists(dst + "/" + node, true)) {
throw new SolrServerException(
"mv command did not move node " + dst + "/" + node + " source left intact");
}
@@ -440,7 +441,7 @@ public class ZkMaintenanceUtils {
try {
List<String> children = zkClient.getChildren(zkPath, null, true);
// If it has no children, it's a leaf node, write the associated data from the ZNode.
- // Otherwise, continue recursing, but write the associated data to a special file if any
+ // Otherwise, continue recursively traversing, but write any associated data to a special file
if (children.size() == 0) {
// If we didn't copy data down, then we also didn't create the file. But we still need a
// marker on the local disk so create an empty file.
@@ -460,7 +461,9 @@ public class ZkMaintenanceUtils {
for (String child : children) {
String zkChild = zkPath;
- if (zkChild.endsWith("/") == false) zkChild += "/";
+ if (!zkChild.endsWith("/")) {
+ zkChild += "/";
+ }
zkChild += child;
if (isEphemeral(zkClient, zkChild)) { // Don't copy ephemeral nodes
continue;
@@ -493,10 +496,10 @@ public class ZkMaintenanceUtils {
/**
* Recursively visit a zk tree rooted at path and apply the given visitor to each path. Exists as
- * a separate method because some of the logic can get nuanced.
+ * a separate method because the logic can get nuanced.
*
* @param path the path to start from
- * @param visitOrder whether to call the visitor at the at the ending or beginning of the run.
+ * @param visitOrder whether to call the visitor at the ending or beginning of the run.
* @param visitor the operation to perform on each path
*/
public static void traverseZkTree(
@@ -559,10 +562,12 @@ public class ZkMaintenanceUtils {
// It's possible that the relative path and file are the same, in which case
// adding the bare slash is A Bad Idea unless it's a non-leaf data node
boolean isNonLeafData = file.toFile().getName().equals(ZKNODE_DATA_FILE);
- if (relativePath.length() == 0 && isNonLeafData == false) return zkRoot;
+ if (relativePath.length() == 0 && !isNonLeafData) return zkRoot;
// Important to have this check if the source is file:whatever/ and the destination is just zk:/
- if (zkRoot.endsWith("/") == false) zkRoot += "/";
+ if (!zkRoot.endsWith("/")) {
+ zkRoot += "/";
+ }
String ret = zkRoot + relativePath;
@@ -679,8 +684,9 @@ public class ZkMaintenanceUtils {
@Override
public void visit(String path) throws InterruptedException, KeeperException {
String finalDestination = dest;
- if (path.equals(source) == false)
+ if (!path.equals(source)) {
finalDestination += "/" + path.substring(source.length() + 1);
+ }
zkClient.makePath(finalDestination, false, true);
zkClient.setData(finalDestination, zkClient.getData(path, null, null, true), true);
}
diff --git a/solr/solrj-zookeeper/src/test/org/apache/solr/common/cloud/TestZkMaintenanceUtils.java b/solr/solrj-zookeeper/src/test/org/apache/solr/common/cloud/TestZkMaintenanceUtils.java
index 89677753f76..e13004278c0 100644
--- a/solr/solrj-zookeeper/src/test/org/apache/solr/common/cloud/TestZkMaintenanceUtils.java
+++ b/solr/solrj-zookeeper/src/test/org/apache/solr/common/cloud/TestZkMaintenanceUtils.java
@@ -100,7 +100,7 @@ public class TestZkMaintenanceUtils extends SolrTestCaseJ4 {
/* CHECK */
String listZnode = zkClient.listZnode(path, false);
- // list of node must not contain file1, file2 or some_longer_file2 because they where deleted
+ // list of nodes must not contain file1, file2 or some_longer_file2 because they were deleted
assertFalse(listZnode.contains("file1"));
assertFalse(listZnode.contains("file2"));
assertFalse(listZnode.contains("some_longer_file2"));
@@ -148,7 +148,7 @@ public class TestZkMaintenanceUtils extends SolrTestCaseJ4 {
"/testTraverseZkTree/1/1",
"/testTraverseZkTree/1/2",
"/testTraverseZkTree/2"),
- getTraverseedZNodes(
+ getTraversedZNodes(
zkClient, "/testTraverseZkTree", ZkMaintenanceUtils.VISIT_ORDER.VISIT_PRE));
assertEquals(
Arrays.asList(
@@ -157,7 +157,7 @@ public class TestZkMaintenanceUtils extends SolrTestCaseJ4 {
"/testTraverseZkTree/1",
"/testTraverseZkTree/2",
"/testTraverseZkTree"),
- getTraverseedZNodes(
+ getTraversedZNodes(
zkClient, "/testTraverseZkTree", ZkMaintenanceUtils.VISIT_ORDER.VISIT_POST));
}
}
@@ -185,7 +185,7 @@ public class TestZkMaintenanceUtils extends SolrTestCaseJ4 {
}
}
- private List<String> getTraverseedZNodes(
+ private List<String> getTraversedZNodes(
SolrZkClient zkClient, String path, ZkMaintenanceUtils.VISIT_ORDER visitOrder)
throws KeeperException, InterruptedException {
List<String> result = new ArrayList<>();
@@ -196,7 +196,7 @@ public class TestZkMaintenanceUtils extends SolrTestCaseJ4 {
new ZkMaintenanceUtils.ZkVisitor() {
@Override
- public void visit(String path) throws InterruptedException, KeeperException {
+ public void visit(String path) {
result.add(path);
}
});