[KYUUBI #5987] Enhance KYUUBI_HOME detection in shell script to handle softlink cases

# 🔍 Description
## Issue References 🔗

This pull request fixes #5987
Modify the logic in the beeline script that specifies the KYUUBI_HOME environment variable.

## Describe Your Solution 🔧

 If the environment has already declared KYUUBI_HOME, it should use the pre-declared KYUUBI_HOME instead of forcefully specifying the parent directory of the current one.

## Types of changes 🔖

- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)

## Test Plan 🧪

#### Behavior Without This Pull Request ⚰️
1. set soft link:
 `ln -s /opt/soft/kyuubi/kyuubi/bin/beeline /usr/bin/kyuubi-beeline`
2. set env like:
`export KYUUBI_HOME=/opt/soft/kyuubi/kyuubi`
3. run kyuubi-beeline:
`kyuubi-beeline -u "jdbc:hive2://xx.xx.xx.xx:2181,xx.xx.xx.xx:2181,xx.xx.xx.xx:2181/tmp;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=kyuubi;principal=hive/_HOSTxxx"`
4. command will fail:
`/bin/kyuubi-beeline: line 27: //bin/load-kyuubi-env.sh: No such file or directory
Error: JAVA_HOME IS NOT SET! CANNOT PROCEED.`

#### Behavior With This Pull Request 🎉
1. set soft link:
 `ln -s /opt/soft/kyuubi/kyuubi/bin/beeline /usr/bin/kyuubi-beeline`
2. set env like:
`export KYUUBI_HOME=/opt/soft/kyuubi/kyuubi`
3. run kyuubi-beeline:
`kyuubi-beeline -u "jdbc:hive2://xx.xx.xx.xx:2181,xx.xx.xx.xx:2181,xx.xx.xx.xx:2181/tmp;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=kyuubi;principal=hive/_HOSTxxx"`
4. command will success
#### Related Unit Tests

---

# Checklist 📝

- [ ] This patch was not authored or co-authored using [Generative Tooling](https://www.apache.org/legal/generative-tooling.html)

**Be nice. Be informative.**

Closes #5988 from Emor-nj/kyuubi-beeline.

Closes #5987

3a988e0f7 [Emor-nj] fix KYUUBI_HOME is always empty in load-kyuubi-env.sh
cc703870f [Emor-nj] fix load-kyuubi-env.sh
a10142825 [Emor-nj] Remove unnecessary exports.
f48db3f81 [Emor-nj] uniformly modify all related scripts.
35215b978 [Emor-nj] Modify the logic in the beeline script that specifies the KYUUBI_HOME environment variable.

Authored-by: Emor-nj <emor93@foxmail.com>
Signed-off-by: Cheng Pan <chengpan@apache.org>
This commit is contained in:
Emor-nj 2024-01-17 18:00:06 +08:00 committed by Cheng Pan
parent e9e2d189ba
commit 7b388895b7
No known key found for this signature in database
GPG Key ID: 8001952629BCC75D
6 changed files with 18 additions and 8 deletions

View File

@ -19,7 +19,9 @@
## Kyuubi BeeLine Entrance
CLASS="org.apache.hive.beeline.KyuubiBeeLine"
export KYUUBI_HOME="$(cd "$(dirname "$0")"/..; pwd)"
if [ -z "${KYUUBI_HOME}" ]; then
KYUUBI_HOME="$(cd "`dirname "$0"`"/..; pwd)"
fi
. "${KYUUBI_HOME}/bin/load-kyuubi-env.sh" -s

View File

@ -62,7 +62,9 @@ function kyuubi_rotate_log() {
fi
}
export KYUUBI_HOME="$(cd "$(dirname "$0")"/..; pwd)"
if [ -z "${KYUUBI_HOME}" ]; then
KYUUBI_HOME="$(cd "`dirname "$0"`"/..; pwd)"
fi
if [[ $1 == "start" ]] || [[ $1 == "run" ]]; then
. "${KYUUBI_HOME}/bin/load-kyuubi-env.sh"

View File

@ -19,7 +19,9 @@
## Kyuubi Admin Control Client Entrance
CLASS="org.apache.kyuubi.ctl.cli.AdminControlCli"
export KYUUBI_HOME="$(cd "$(dirname "$0")"/..; pwd)"
if [ -z "${KYUUBI_HOME}" ]; then
KYUUBI_HOME="$(cd "`dirname "$0"`"/..; pwd)"
fi
. "${KYUUBI_HOME}/bin/load-kyuubi-env.sh" -s

View File

@ -19,7 +19,9 @@
## Kyuubi Control Client Entrance
CLASS="org.apache.kyuubi.ctl.cli.ControlCli"
export KYUUBI_HOME="$(cd "$(dirname "$0")"/..; pwd)"
if [ -z "${KYUUBI_HOME}" ]; then
KYUUBI_HOME="$(cd "`dirname "$0"`"/..; pwd)"
fi
. "${KYUUBI_HOME}/bin/load-kyuubi-env.sh" -s

View File

@ -19,8 +19,9 @@
## Zookeeper Shell Client Entrance
CLASS="org.apache.kyuubi.shaded.zookeeper.ZooKeeperMain"
export KYUUBI_HOME="$(cd "$(dirname "$0")"/..; pwd)"
if [ -z "${KYUUBI_HOME}" ]; then
KYUUBI_HOME="$(cd "`dirname "$0"`"/..; pwd)"
fi
. "${KYUUBI_HOME}/bin/load-kyuubi-env.sh" -s
if [[ -z ${JAVA_HOME} ]]; then

View File

@ -17,8 +17,9 @@
#
export KYUUBI_HOME="${KYUUBI_HOME:-"$(cd "$(dirname "$0")"/.. || exit; pwd)"}"
if [ -z "${KYUUBI_HOME}" ]; then
export KYUUBI_HOME="$(cd "$(dirname "$0")"/.. || exit; pwd)"
fi
export KYUUBI_CONF_DIR="${KYUUBI_CONF_DIR:-"${KYUUBI_HOME}"/conf}"
silent=0