celeborn/bin/celeborn-class
Wang, Fei d4044c5152
[CELEBORN-1682] Add java tools.jar into classpath for JVM quake
### What changes were proposed in this pull request?

Add java tools.jar into classpath for JVM quake.

### Why are the changes needed?
Meet below issue with `celeborn.worker.jvmQuake.enabled=true`, see https://github.com/apache/celeborn/pull/2061
```
24/11/03 15:51:08,453 ERROR [main] Worker: Initialize worker failed.
java.lang.NoClassDefFoundError: sun/jvmstat/monitor/HostIdentifier
    at org.apache.celeborn.service.deploy.worker.monitor.JVMQuake$.monitoredVm$lzycompute(JVMQuake.scala:180)
    at org.apache.celeborn.service.deploy.worker.monitor.JVMQuake$.monitoredVm(JVMQuake.scala:179)
    at org.apache.celeborn.service.deploy.worker.monitor.JVMQuake$.ygcExitTimeMonitor$lzycompute(JVMQuake.scala:185)
    at org.apache.celeborn.service.deploy.worker.monitor.JVMQuake$.ygcExitTimeMonitor(JVMQuake.scala:184)
    at org.apache.celeborn.service.deploy.worker.monitor.JVMQuake$.org$apache$celeborn$service$deploy$worker$monitor$JVMQuake$$getLastExitTime(JVMQuake.scala:192)
    at org.apache.celeborn.service.deploy.worker.monitor.JVMQuake.start(JVMQuake.scala:66)
    at org.apache.celeborn.service.deploy.worker.Worker.<init>(Worker.scala:360)
    at org.apache.celeborn.service.deploy.worker.Worker$.main(Worker.scala:1041)
    at org.apache.celeborn.service.deploy.worker.Worker.main(Worker.scala)
Caused by: java.lang.ClassNotFoundException: sun.jvmstat.monitor.HostIdentifier
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 9 more
```

Related code:
c12e8881ab/project/JDKTools.scala (L58-L75)

Similar issue: https://github.com/vladimirvivien/jmx-cli/issues/4

After copy the `tools.jar` into worker-jars, the issue got resolved.

It is better that to involve the `tools.jar` automatically without copy.

### Does this PR introduce _any_ user-facing change?
No.

### How was this patch tested?
<img width="1202" alt="image" src="https://github.com/user-attachments/assets/af8f6c0d-9123-4a73-93b5-69836c5f826d">

Closes #2874 from turboFei/jdk_tools.

Authored-by: Wang, Fei <fwang12@ebay.com>
Signed-off-by: SteNicholas <programgeek@163.com>
2024-11-04 11:05:10 +08:00

102 lines
3.2 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
if [ -z "${CELEBORN_HOME}" ]; then
export CELEBORN_HOME="$(cd "`dirname "$0"`"/..; pwd)"
fi
export CELEBORN_CONF_DIR="${CELEBORN_CONF_DIR:-"${CELEBORN_HOME}/conf"}"
# print launch command for debug
export CELEBORN_PRINT_LAUNCH_COMMAND="0"
if [ -z "$CELEBORN_ENV_LOADED" ]; then
export CELEBORN_ENV_LOADED=1
if [ -f "${CELEBORN_CONF_DIR}/celeborn-env.sh" ]; then
# Promote all variable declarations to environment (exported) variables
set -a
. "${CELEBORN_CONF_DIR}/celeborn-env.sh"
set +a
fi
fi
# Find CELEBORN jars.
for i in "$@"
do
if [ "$i" == "org.apache.celeborn.service.deploy.master.Master" ] ; then
LAUNCH_CLASS=org.apache.celeborn.service.deploy.master.Master
fi
if [ "$i" == "org.apache.celeborn.service.deploy.worker.Worker" ] ; then
LAUNCH_CLASS=org.apache.celeborn.service.deploy.worker.Worker
fi
if [ "$i" == "org.apache.celeborn.cli.CelebornCli" ] ; then
LAUNCH_CLASS=org.apache.celeborn.cli.CelebornCli
fi
done
if [ "${LAUNCH_CLASS}" == "org.apache.celeborn.service.deploy.master.Master" ] ; then
if [ -d "${CELEBORN_HOME}/master-jars" ]; then
CELEBORN_JARS_DIR="${CELEBORN_HOME}/master-jars"
else
CELEBORN_JARS_DIR="${CELEBORN_HOME}/master/target"
fi
fi
if [ "${LAUNCH_CLASS}" == "org.apache.celeborn.service.deploy.worker.Worker" ] ; then
if [ -d "${CELEBORN_HOME}/worker-jars" ]; then
CELEBORN_JARS_DIR="${CELEBORN_HOME}/worker-jars"
else
CELEBORN_JARS_DIR="${CELEBORN_HOME}/worker/target"
fi
fi
if [ "${LAUNCH_CLASS}" == "org.apache.celeborn.cli.CelebornCli" ] ; then
if [ -d "${CELEBORN_HOME}/cli-jars" ]; then
CELEBORN_JARS_DIR="${CELEBORN_HOME}/cli-jars"
else
CELEBORN_JARS_DIR="${CELEBORN_HOME}/cli/target"
fi
fi
if [ ! -d "$CELEBORN_JARS_DIR" ]; then
echo "Failed to find CELEBORN jars directory ($CELEBORN_JARS_DIR)." 1>&2
echo "You need to build CELEBORN with the target \"package\" before running this program." 1>&2
exit 1
else
CELEBORN_CLASSPATH="$CELEBORN_CONF_DIR:$HADOOP_CONF_DIR:$CELEBORN_JARS_DIR/*:$JAVA_TOOLS_JAR"
fi
# Turn off posix mode since it does not allow process substitution
set +o posix
CMD=()
CMD+=("$JAVA")
CMD=(${CMD[@]} "-XX:+IgnoreUnrecognizedVMOptions" "$CELEBORN_JAVA_OPTS")
CMD+=("-cp")
CMD+=("$CELEBORN_CLASSPATH")
CMD=(${CMD[@]} "$@")
COUNT=${#CMD[@]}
if [ "${CELEBORN_PRINT_LAUNCH_COMMAND}" = "1" ]; then
echo "Start to launch ${CMD[@]}"
fi
exec "${CMD[@]}"