Skip to content

Commit c2ef12f

Browse files
SAMZA-2653: Write pathing jar of run-class.sh into its own directory (#1498)
Issue: Currently, the pathing.jar file used to specify the classpath for run-class.sh is written directly into the top-level working directory of the app. When using container images, there may be some predefined permissions set on the working directory. This may cause permission issues with being able to write the pathing.jar file. Changes: Create a separate directory for writing classpath-related files (manifest.txt, pathing.jar) and write the pathing.jar to that separate directory. Update the classpath arguments to use the new location of the pathing.jar. API changes, usage/upgrade instructions: N/A See #1498 for more context about a use case for this change.
1 parent 96b09b5 commit c2ef12f

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

samza-shell/src/main/bash/run-class.sh

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,21 @@ else
6868
JAR="$JAVA_HOME/bin/jar"
6969
fi
7070

71+
# Create a separate directory for writing files related to classpath management. It is easier to manage
72+
# permissions for the classpath-related files when they are in their own directory. An example of where
73+
# this is helpful is when using container images which might have predefined permissions for certain
74+
# directories.
75+
CLASSPATH_WORKSPACE_DIR=$base_dir/classpath_workspace
76+
mkdir -p $CLASSPATH_WORKSPACE_DIR
77+
# file containing the classpath string; used to avoid passing long classpaths directly to the jar command
78+
PATHING_MANIFEST_FILE=$CLASSPATH_WORKSPACE_DIR/manifest.txt
79+
# jar file to include on the classpath for running the main class
80+
PATHING_JAR_FILE=$CLASSPATH_WORKSPACE_DIR/pathing.jar
81+
7182
# Newlines and spaces are intended to ensure proper parsing of manifest in pathing jar
72-
printf "Class-Path: \n $CLASSPATH \n" > manifest.txt
83+
printf "Class-Path: \n $CLASSPATH \n" > $PATHING_MANIFEST_FILE
7384
# Creates a new archive and adds custom manifest information to pathing.jar
74-
eval "$JAR -cvmf manifest.txt pathing.jar"
85+
eval "$JAR -cvmf $PATHING_MANIFEST_FILE $PATHING_JAR_FILE"
7586

7687
if [ -z "$JAVA_HOME" ]; then
7788
JAVA="java"
@@ -151,11 +162,11 @@ fi
151162
[[ $JAVA_OPTS != *-d64* ]] && check_and_enable_64_bit_mode
152163

153164
# HADOOP_CONF_DIR should be supplied to classpath explicitly for Yarn to parse configs
154-
echo $JAVA $JAVA_OPTS -cp $HADOOP_CONF_DIR:pathing.jar "$@"
165+
echo $JAVA $JAVA_OPTS -cp $HADOOP_CONF_DIR:$PATHING_JAR_FILE "$@"
155166

156167
## If localized resource lib directory is defined, then include it in the classpath.
157168
if [[ -z "${ADDITIONAL_CLASSPATH_DIR}" ]]; then
158-
exec $JAVA $JAVA_OPTS -cp $HADOOP_CONF_DIR:pathing.jar "$@"
169+
exec $JAVA $JAVA_OPTS -cp $HADOOP_CONF_DIR:$PATHING_JAR_FILE "$@"
159170
else
160-
exec $JAVA $JAVA_OPTS -cp $HADOOP_CONF_DIR:pathing.jar:$ADDITIONAL_CLASSPATH_DIR "$@"
171+
exec $JAVA $JAVA_OPTS -cp $HADOOP_CONF_DIR:$PATHING_JAR_FILE:$ADDITIONAL_CLASSPATH_DIR "$@"
161172
fi

0 commit comments

Comments
 (0)