celeborn/bin/celeborn-class
Aravind Patnam cc26131f88 [CELEBORN-1572] Celeborn CLI initial REST API support
### What changes were proposed in this pull request?
Introducing the Celeborn CLI (based on this [CPIP](https://cwiki.apache.org/confluence/display/CELEBORN/CIP-7+Celeborn+CLI)). For the first iteration, adding support for querying the existing REST api endpoints.
After this will add a layer for external cluster manager support. Further improvements are needed such as pretty print, which can be added in subsequent PRs.

### Why are the changes needed?
see [CPIP](https://cwiki.apache.org/confluence/display/CELEBORN/CIP-7+Celeborn+CLI)

### Does this PR introduce _any_ user-facing change?
yes, new CLI tool.

### How was this patch tested?
added UTs and also tested internally.

Closes #2699 from akpatnam25/cli-CELEBORN-1572.

Lead-authored-by: Aravind Patnam <apatnam@linkedin.com>
Co-authored-by: Aravind Patnam <akpatnam25@gmail.com>
Signed-off-by: Mridul Muralidharan <mridul<at>gmail.com>
2024-09-05 11:15:16 -05:00

102 lines
3.1 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/*"
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[@]}"