You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ep...@apache.org on 2023/08/21 11:33:57 UTC

[solr] branch main updated: Add/fix wrong/missing "solr.home" to zkcli scripts (#1798)

This is an automated email from the ASF dual-hosted git repository.

epugh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/main by this push:
     new e0462e75a5c Add/fix wrong/missing "solr.home" to zkcli scripts (#1798)
e0462e75a5c is described below

commit e0462e75a5cf848b1a3ae83ed6c95243785e21d6
Author: Lamine <10...@users.noreply.github.com>
AuthorDate: Mon Aug 21 06:33:50 2023 -0500

    Add/fix wrong/missing "solr.home" to zkcli scripts (#1798)
    
    ---------
    
    Co-authored-by: Lamine Idjeraoui <li...@apple.com>
---
 solr/core/src/java/org/apache/solr/cloud/ZkCLI.java |  9 ++++++++-
 solr/packaging/test/test_zk.bats                    | 18 ++++++++++++++++++
 solr/server/scripts/cloud-scripts/zkcli.bat         |  6 ++++--
 solr/server/scripts/cloud-scripts/zkcli.sh          |  4 ++--
 4 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java b/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java
index c1f9b826529..07c66805068 100644
--- a/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java
+++ b/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java
@@ -86,6 +86,7 @@ public class ZkCLI implements CLIO {
   private static final String CMD = "cmd";
   private static final String CLUSTERPROP = "clusterprop";
   private static final String UPDATEACLS = "updateacls";
+  private static final String VERBOSE = "verbose";
 
   @VisibleForTesting
   public static void setStdout(PrintStream stdout) {
@@ -174,12 +175,14 @@ public class ZkCLI implements CLIO {
     options.addOption("h", HELP, false, "bring up this help page");
     options.addOption(NAME, true, "name of the cluster property to set");
     options.addOption(VALUE_LONG, true, "value of the cluster to set");
+    options.addOption("v", VERBOSE, false, "enable verbose mode");
 
     try {
       // parse the command line arguments
       CommandLine line = parser.parse(options, args);
 
-      if (line.hasOption(HELP) || !line.hasOption(ZKHOST) || !line.hasOption(CMD)) {
+      if ((line.hasOption(HELP) || !line.hasOption(ZKHOST) || !line.hasOption(CMD))
+          && !line.hasOption(VERBOSE)) {
         // automatically generate the help statement
         HelpFormatter formatter = new HelpFormatter();
         formatter.printHelp(ZK_CLI_NAME, options);
@@ -243,6 +246,10 @@ public class ZkCLI implements CLIO {
       if (StrUtils.isNullOrEmpty(solrHome)) {
         solrHome = System.getProperty("solr.home");
       }
+      if (line.hasOption(VERBOSE)) {
+        stdout.println("Using " + SOLRHOME + "=" + solrHome);
+        return;
+      }
 
       String solrPort = null;
       if (line.hasOption(RUNZK)) {
diff --git a/solr/packaging/test/test_zk.bats b/solr/packaging/test/test_zk.bats
index 4e9a8bdd047..686437d914e 100644
--- a/solr/packaging/test/test_zk.bats
+++ b/solr/packaging/test/test_zk.bats
@@ -75,3 +75,21 @@ teardown() {
   assert_output --partial '"configSets":["_default","techproducts2"]'
 
 }
+
+@test "zkcli.sh gets 'solrhome' from 'solr.home' system property" {
+  sleep 1
+  run "${SOLR_TIP}/server/scripts/cloud-scripts/zkcli.sh" -v
+  local extracted_solrhome=$(echo "$output" | grep -oE "solrhome=[^ ]+")
+  # remove 'solrhome='
+  local path_value=${extracted_solrhome#*=}
+  [[ $path_value == *"/server/scripts/cloud-scripts/../../solr" ]] || [[ $path_value == *"/server/solr" ]]
+}
+
+@test "zkcli.sh gets 'solrhome' from 'solrhome' command line option" {
+  sleep 1
+  run "${SOLR_TIP}/server/scripts/cloud-scripts/zkcli.sh" -v -s /path/to/solr/home
+  local extracted_solrhome=$(echo "$output" | grep -oE "solrhome=[^ ]+")
+  # remove 'solrhome='
+  local path_value=${extracted_solrhome#*=}
+  [[ $path_value == "/path/to/solr/home" ]]
+}
diff --git a/solr/server/scripts/cloud-scripts/zkcli.bat b/solr/server/scripts/cloud-scripts/zkcli.bat
index 63c0eb108e7..0eb40faa8ea 100644
--- a/solr/server/scripts/cloud-scripts/zkcli.bat
+++ b/solr/server/scripts/cloud-scripts/zkcli.bat
@@ -1,6 +1,6 @@
 @echo off
 REM You can override pass the following parameters to this script:
-REM 
+REM
 
 set JVM=java
 
@@ -8,6 +8,8 @@ REM  Find location of this script
 
 set SDIR=%~dp0
 if "%SDIR:~-1%"=="\" set SDIR=%SDIR:~0,-1%
+set SOLR_INSTALL_DIR=%SDIR%\..\..\..
+set SOLR_HOME=%SOLR_INSTALL_DIR%\server\solr
 
 set "LOG4J_CONFIG=file:///%SDIR%\..\..\resources\log4j2-console.xml"
 
@@ -21,5 +23,5 @@ REM optionally, you can use using a a Java properties file 'zkDigestCredentialsF
 REM ...
 REM   -DzkDigestCredentialsFile=/path/to/zkDigestCredentialsFile.properties
 REM ...
-"%JVM%" %SOLR_ZK_CREDS_AND_ACLS% %ZKCLI_JVM_FLAGS% -Dlog4j.configurationFile="%LOG4J_CONFIG%" ^
+"%JVM%" %SOLR_ZK_CREDS_AND_ACLS% %ZKCLI_JVM_FLAGS% -Dlog4j.configurationFile="%LOG4J_CONFIG%" -Dsolr.home=%SOLR_HOME% ^
 -classpath "%SDIR%\..\..\solr-webapp\webapp\WEB-INF\lib\*;%SDIR%\..\..\lib\ext\*;%SDIR%\..\..\lib\*" org.apache.solr.cloud.ZkCLI %*
diff --git a/solr/server/scripts/cloud-scripts/zkcli.sh b/solr/server/scripts/cloud-scripts/zkcli.sh
index 4477df48634..4986d21c029 100755
--- a/solr/server/scripts/cloud-scripts/zkcli.sh
+++ b/solr/server/scripts/cloud-scripts/zkcli.sh
@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 
 # You can override pass the following parameters to this script:
-# 
+#
 
 JVM="java"
 
@@ -23,6 +23,6 @@ solr_home="$sdir/../../solr"
 #...
 #   -DzkDigestCredentialsFile=/path/to/zkDigestCredentialsFile.properties
 #...
-PATH=$JAVA_HOME/bin:$PATH $JVM $SOLR_ZK_CREDS_AND_ACLS $ZKCLI_JVM_FLAGS -Dlog4j.configurationFile=$log4j_config -DsolrHome=$solr_home \
+PATH=$JAVA_HOME/bin:$PATH $JVM $SOLR_ZK_CREDS_AND_ACLS $ZKCLI_JVM_FLAGS -Dlog4j.configurationFile=$log4j_config -Dsolr.home=$solr_home \
 -classpath "$sdir/../../solr-webapp/webapp/WEB-INF/lib/*:$sdir/../../lib/ext/*:$sdir/../../lib/*" org.apache.solr.cloud.ZkCLI ${1+"$@"}