Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cassandra.in.sh): Refactor script for readability and consistency #17

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 56 additions & 53 deletions tools/bin/cassandra.in.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.

if [ "$SCYLLA_HOME" = "" ]; then
SCYLLA_HOME="$(dirname "$0")/../../../scylla"
SCYLLA_HOME="$(dirname "$0")"

while [ "$SCYLLA_HOME" != "/" ]; do
if [ -d "$SCYLLA_HOME/conf" ]; then
break
fi
SCYLLA_HOME="$(dirname "$SCYLLA_HOME")"
done

if [ "$SCYLLA_HOME" = "/" ]; then
echo "Error: 'conf' directory not found in any parent directory."
exit 1
fi

if [ "$SCYLLA_CONF" = "" ]; then
SCYLLA_CONF="$SCYLLA_HOME/conf"
SCYLLA_CONF="$SCYLLA_HOME/conf"
fi

# The java classpath (required)
Expand All @@ -28,13 +38,13 @@ CLASSPATH="$SCYLLA_CONF"
# This can be the path to a jar file, or a directory containing the
# compiled classes. NOTE: This isn't needed by the startup script,
# it's just used here in constructing the classpath.
if [ -d "$SCYLLA_HOME/build" ] ; then
cassandra_bin="$SCYLLA_HOME/build/classes/main"
cassandra_bin="$cassandra_bin:$SCYLLA_HOME/build/classes/thrift"
# shellcheck disable=SC2006
cassandra_bin="$cassandra_bin:`ls -1 $SCYLLA_HOME/build/apache-cassandra*.jar`"
cassandra_bin="$cassandra_bin:$SCYLLA_HOME/build/classes/stress"
CLASSPATH="$CLASSPATH:$cassandra_bin"
if [ -d "$SCYLLA_HOME/build" ]; then
cassandra_bin="$SCYLLA_HOME/build/classes/main"
cassandra_bin="$cassandra_bin:$SCYLLA_HOME/build/classes/thrift"
# shellcheck disable=SC2006
cassandra_bin="$cassandra_bin:$(ls -1 $SCYLLA_HOME/build/apache-cassandra*.jar 2>/dev/null)"
cassandra_bin="$cassandra_bin:$SCYLLA_HOME/build/classes/stress"
CLASSPATH="$CLASSPATH:$cassandra_bin"
fi

# the default location for commitlogs, sstables, and saved caches
Expand All @@ -44,77 +54,70 @@ cassandra_storagedir="$SCYLLA_HOME/data"
# JAVA_HOME can optionally be set here
#JAVA_HOME=/usr/local/jdk6


CONFIG_FILE_REALPATH=$(realpath "$SCYLLA_CONF/cassandra.yaml")
# If scylla.yaml is found - use it as the config file.
if [ -f "$SCYLLA_CONF/scylla.yaml" ]; then
CONFIG_FILE_REALPATH=$(realpath "$SCYLLA_CONF/scylla.yaml")
CONFIG_FILE_REALPATH=$(realpath "$SCYLLA_CONF/scylla.yaml")
fi

CONFIGURATION_FILE_OPT="-Dcassandra.config=file://$CONFIG_FILE_REALPATH"

for jar in "$SCYLLA_HOME"/tools/lib/*.jar; do
CLASSPATH="$CLASSPATH:$jar"
done

for jar in "$SCYLLA_HOME"/lib/*.jar; do
CLASSPATH="$CLASSPATH:$jar"
done
CLASSPATH="${CLASSPATH}:$(find "$SCYLLA_HOME/lib" "$SCYLLA_HOME/build/lib" "$SCYLLA_HOME/tools" -name '*.jar' -print 2>/dev/null | paste -sd ":" -)"
CLASSPATH="${CLASSPATH#:}"
Comment on lines +65 to +66
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Albeit odd this is to allow running from ./build, ./tools and docker

gh repo clone daniel-boll/cassandra-stress -- --depth 1 --branch fix/scripts-path
cd cassandra-stress
ant -Drelease=true artifacts
docker buildx build --build-arg='CASSANDRA_STRESS_VERSION=3.12.0' -t scylla-daniel:cassandra-stress .

Now with that the three ways

./tools/bin/cassandra-stress
./build/dist/tools/bin/cassandra-stress
docker run scylla-daniel:cassandra-stress


# Use JAVA_HOME if set, otherwise look for java in PATH
if [ -n "$JAVA_HOME" ]; then
# Why we can't have nice things: Solaris combines x86 and x86_64
# installations in the same tree, using an unconventional path for the
# 64bit JVM. Since we prefer 64bit, search the alternate path first,
# (see https://issues.apache.org/jira/browse/SCYLLA-4638).
for java in "$JAVA_HOME"/bin/amd64/java "$JAVA_HOME"/bin/java; do
if [ -x "$java" ]; then
JAVA="$java"
break
fi
done
# Why we can't have nice things: Solaris combines x86 and x86_64
# installations in the same tree, using an unconventional path for the
# 64bit JVM. Since we prefer 64bit, search the alternate path first,
# (see https://issues.apache.org/jira/browse/SCYLLA-4638).
for java in "$JAVA_HOME"/bin/amd64/java "$JAVA_HOME"/bin/java; do
if [ -x "$java" ]; then
JAVA="$java"
break
fi
done
else
JAVA=java
JAVA=java
fi

if [ -z $JAVA ] ; then
echo Unable to find java executable. Check JAVA_HOME and PATH environment variables. >&2
exit 1;
if [ -z $JAVA ]; then
echo Unable to find java executable. Check JAVA_HOME and PATH environment variables. >&2
exit 1
fi

# Determine the sort of JVM we'll be running on.
java_ver_output=$("${JAVA:-java}" -version 2>&1)
jvmver=$(echo "$java_ver_output" | grep '[openjdk|java] version' | awk -F'"' 'NR==1 {print $2}' | cut -d- -f1)
JVM_VERSION=${jvmver%_*}

if [ "$JVM_VERSION" \< "11" ] ; then
echo "Cassandra-Stress requires Java 11 (or newer)."
exit 1;
if [ "$JVM_VERSION" \< "11" ]; then
echo "Cassandra-Stress requires Java 11 (or newer)."
exit 1
fi

jvm=$(echo "$java_ver_output" | grep -A 1 '[openjdk|java] version' | awk 'NR==2 {print $1}')
case "$jvm" in
OpenJDK)
JVM_VENDOR=OpenJDK
# this will be "64-Bit" or "32-Bit"
JVM_ARCH=$(echo "$java_ver_output" | awk 'NR==3 {print $2}')
;;
"Java(TM)")
JVM_VENDOR=Oracle
# this will be "64-Bit" or "32-Bit"
JVM_ARCH=$(echo "$java_ver_output" | awk 'NR==3 {print $3}')
;;
*)
# Help fill in other JVM values
JVM_VENDOR=other
JVM_ARCH=unknown
;;
OpenJDK)
JVM_VENDOR=OpenJDK
# this will be "64-Bit" or "32-Bit"
JVM_ARCH=$(echo "$java_ver_output" | awk 'NR==3 {print $2}')
;;
"Java(TM)")
JVM_VENDOR=Oracle
# this will be "64-Bit" or "32-Bit"
JVM_ARCH=$(echo "$java_ver_output" | awk 'NR==3 {print $3}')
;;
*)
# Help fill in other JVM values
JVM_VENDOR=other
JVM_ARCH=unknown
;;
esac

# Read user-defined JVM options from jvm-server.options file
JVM_OPTS_FILE=$SCYLLA_CONF/jvm11${jvmoptions_variant:--clients}.options

for opt in $(grep "^-" "$JVM_OPTS_FILE")
do
for opt in $(grep "^-" "$JVM_OPTS_FILE"); do
JVM_OPTS="$JVM_OPTS $opt"
done