1818
1919set -xeou pipefail
2020
21- # ######################
22- # 1. PLUGIN EXTENSION #
23- # ######################
24- # The directory /opt/tez/plugins is intended to be a volume mount point.
25- # If custom jars are present, we add them to classpath.
21+ # ###############################################
22+ # 1. Mocking DAGAppMaster#main() env variables #
23+ # ###############################################
2624
27- PLUGIN_DIR=" /opt/tez/plugins"
28- PLUGIN_CLASSPATH=" "
25+ export CONTAINER_ID=${CONTAINER_ID:- " container_1700000000000_0001_01_000001" }
26+ export USER=${USER:- " tez" }
27+ export HADOOP_USER_NAME=${HADOOP_USER_NAME:- " tez" }
2928
30- if [ -d " $PLUGIN_DIR " ]; then
31- count=$( find " $PLUGIN_DIR " -maxdepth 1 -name " *.jar" 2> /dev/null | wc -l)
32- if [ " $count " != " 0" ]; then
33- echo " --> Found $count custom jars in $PLUGIN_DIR . Adding to classpath..."
34- PLUGIN_CLASSPATH=" $PLUGIN_DIR /*"
35- else
36- echo " --> Plugin directory exists but contains no jars."
37- fi
29+ export NM_HOST=${NM_HOST:- " localhost" }
30+ export NM_PORT=${NM_PORT:- " 12345" }
31+ export NM_HTTP_PORT=${NM_HTTP_PORT:- " 8042" }
32+
33+ export LOCAL_DIRS=${LOCAL_DIRS:- " /tmp" }
34+ export LOG_DIRS=${LOG_DIRS:- " /opt/tez/logs" }
35+ export APP_SUBMIT_TIME_ENV=${APP_SUBMIT_TIME_ENV:- $(($(date +% s) * 1000))}
36+
37+ export TEZ_AM_EXTERNAL_ID=${TEZ_AM_EXTERNAL_ID:- " tez-session-$( hostname) " }
38+
39+ if [ ! -f " tez-conf.pb" ]; then
40+ touch " tez-conf.pb"
41+ echo " --> Created dummy tez-conf.pb"
3842fi
3943
40- # =========================================================================
41- # 2. CONFIGURATION HANDLING
42- # =========================================================================
43- # 1. Custom Conf Dir: If mounted, symlink it to use it directly.
44- # 2. Templates: If not custom, use envsubst to generate configs from ENV.
44+ mkdir -p " $LOG_DIRS "
45+
46+ # #########################
47+ # CONFIGURATION HANDLING #
48+ # #########################
4549
46- # Point HADOOP_CONF_DIR to TEZ_CONF_DIR, we need to populate it
47- # with defaults from the Hadoop installation if they aren't provided by the user.
50+ # Symlink hadoop conf in tez conf dir
4851if [ -d " $HADOOP_HOME /etc/hadoop" ]; then
4952 echo " --> Linking missing Hadoop configs to $TEZ_CONF_DIR ..."
5053 for f in " $HADOOP_HOME /etc/hadoop" /* ; do
6366if [ -n " ${TEZ_CUSTOM_CONF_DIR:- } " ] && [ -d " $TEZ_CUSTOM_CONF_DIR " ]; then
6467 echo " --> Using custom configuration directory: $TEZ_CUSTOM_CONF_DIR "
6568 find " ${TEZ_CUSTOM_CONF_DIR} " -type f -exec \
66- ln -sfn {} " ${TEZ_CONF_DIR} " / \;
67- else
68- echo " --> Generating configuration from templates..."
69- # Set defaults for template variables if not provided
70- export TEZ_AM_RPC_PORT=${TEZ_AM_RPC_PORT:- 10001}
71- export TEZ_AM_RESOURCE_MEMORY=${TEZ_AM_RESOURCE_MEMORY:- 1024}
72-
73- # Process templates
69+ ln -sf {} " ${TEZ_CONF_DIR} " / \;
70+
71+ # Remove template keyword if it exist
7472 if [ -f " $TEZ_CONF_DIR /tez-site.xml.template" ]; then
7573 envsubst < " $TEZ_CONF_DIR /tez-site.xml.template" > " $TEZ_CONF_DIR /tez-site.xml"
7674 fi
7775fi
7876
7977
80- # ###################
81- # Find TEZ DAG JAR #
82- # ###################
83- TEZ_DAG_JAR=$( find " $TEZ_HOME " -maxdepth 1 -name " tez-dag-*.jar" ! -name " *-tests.jar" | head -n 1)
84-
85- if [ -z " $TEZ_DAG_JAR " ]; then
86- echo " Error: Could not find tez-dag-*.jar in $TEZ_HOME "
87- ls -l " $TEZ_HOME "
88- exit 1
89- fi
90-
91- # #############################################
92- # YARN ENVIRONMENT SIMULATION () #
93- # #############################################
94- export APP_SUBMIT_TIME_ENV=${APP_SUBMIT_TIME_ENV:- $(($(date +% s) * 1000))}
95-
96- # 2. Container ID
97- export CONTAINER_ID=${CONTAINER_ID:- " container_1700000000000_0001_01_000001" }
98-
99- # 3. NodeManager Details
100- export NM_HOST=${NM_HOST:- " localhost" }
101- export NM_PORT=${NM_PORT:- " 12345" }
102- export NM_HTTP_PORT=${NM_HTTP_PORT:- " 8042" }
103- export LOCAL_DIRS=${LOCAL_DIRS:- " /tmp" }
104- export LOG_DIRS=${LOG_DIRS:- " /opt/tez/logs" }
105-
106- # 4. User Identity
107- export HADOOP_USER_NAME=${HADOOP_USER_NAME:- " tez" }
108- export USER=${HADOOP_USER_NAME}
109-
110- export TEZ_AM_EXTERNAL_ID=${TEZ_AM_EXTERNAL_ID:- " tez-session-$( hostname) " }
111-
112- echo " --> Mocked YARN Environment:"
113- echo " APP_SUBMIT_TIME_ENV: $APP_SUBMIT_TIME_ENV "
114- echo " CONTAINER_ID: $CONTAINER_ID "
115- echo " USER: $USER "
116-
117- mkdir -p " $LOG_DIRS "
118-
119- if [ ! -f " tez-conf.pb" ]; then
120- touch " tez-conf.pb"
121- echo " --> Created dummy tez-conf.pb"
122- fi
123-
12478# ############
125- # EXECUTION #
79+ # CLASSPATH #
12680# ############
12781
128- CLASSPATH=" ${TEZ_CONF_DIR} :${TEZ_HOME} /*:${TEZ_HOME} /lib/*"
82+ export HADOOP_USER_CLASSPATH_FIRST=true
83+ # Order is: conf -> plugins -> tez jars -> hadoop jars
84+ CLASSPATH=" ${TEZ_CONF_DIR} "
12985
130- if [ -n " $PLUGIN_CLASSPATH " ]; then
131- CLASSPATH=" ${CLASSPATH} :${PLUGIN_CLASSPATH} "
86+ # Custom Plugins
87+ # This allows mounting a volume at /opt/tez/plugins containing aux jars
88+ PLUGIN_DIR=" /opt/tez/plugins"
89+ if [ -d " $PLUGIN_DIR " ]; then
90+ count=$( find " $PLUGIN_DIR " -maxdepth 1 -name " *.jar" 2> /dev/null | wc -l)
91+ if [ " $count " != " 0" ]; then
92+ echo " --> Found $count plugin jars. Prepending to classpath."
93+ CLASSPATH=" ${CLASSPATH} :${PLUGIN_DIR} /*"
94+ fi
13295fi
13396
134- export HADOOP_USER_CLASSPATH_FIRST=true
97+ # Tez Jars
98+ CLASSPATH=" ${CLASSPATH} :${TEZ_HOME} /*:${TEZ_HOME} /lib/*"
13599
100+ # Hadoop Jars
136101CLASSPATH=" ${CLASSPATH} :${HADOOP_HOME} /share/hadoop/common/*"
137102CLASSPATH=" ${CLASSPATH} :${HADOOP_HOME} /share/hadoop/common/lib/*"
138103CLASSPATH=" ${CLASSPATH} :${HADOOP_HOME} /share/hadoop/hdfs/*"
@@ -142,18 +107,36 @@ CLASSPATH="${CLASSPATH}:${HADOOP_HOME}/share/hadoop/yarn/lib/*"
142107CLASSPATH=" ${CLASSPATH} :${HADOOP_HOME} /share/hadoop/mapreduce/*"
143108CLASSPATH=" ${CLASSPATH} :${HADOOP_HOME} /share/hadoop/mapreduce/lib/*"
144109
145- echo " --> Starting DAGAppMaster with JAR: $TEZ_DAG_JAR "
110+ # ############
111+ # Execution #
112+ # ############
113+ TEZ_DAG_JAR=$( find " $TEZ_HOME " -maxdepth 1 -name " tez-dag-*.jar" ! -name " *-tests.jar" | head -n 1)
114+
115+ if [ -z " $TEZ_DAG_JAR " ]; then
116+ echo " Error: Could not find tez-dag-*.jar in $TEZ_HOME "
117+ exit 1
118+ fi
119+
120+ echo " --> Starting DAGAppMaster..."
146121echo " --> HADOOP_CONF_DIR: $HADOOP_CONF_DIR "
147122
148- exec java \
149- --add-opens java.base/java.lang=ALL-UNNAMED \
123+ # Check for Log4j2 Configuration
124+ JAVA_OPTS=" ${JAVA_OPTS:- " -Xmx1024m" } "
125+ LOG4J2_FILE=" $TEZ_CONF_DIR /log4j2.properties"
126+ if [ -f " $LOG4J2_FILE " ]; then
127+ echo " --> [TEZ-AM] Found Log4j2 configuration: $LOG4J2_FILE "
128+ JAVA_OPTS=" $JAVA_OPTS -Dlog4j.configurationFile=file:$LOG4J2_FILE "
129+ fi
130+
131+ JAVA_ADD_OPENS=" --add-opens java.base/java.lang=ALL-UNNAMED \
150132 --add-opens java.base/java.util=ALL-UNNAMED \
151133 --add-opens java.base/java.lang.reflect=ALL-UNNAMED \
152134 --add-opens java.base/java.text=ALL-UNNAMED \
153135 --add-opens java.base/java.nio=ALL-UNNAMED \
154136 --add-opens java.base/sun.nio.ch=ALL-UNNAMED \
155- --add-opens java.base/java.util.concurrent=ALL-UNNAMED \
156- --add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED \
137+ --add-opens java.base/java.util.concurrent=ALL-UNNAMED"
138+
139+ exec java $JAVA_OPTS $JAVA_ADD_OPENS \
157140 -Duser.name=" $HADOOP_USER_NAME " \
158141 -Djava.library.path=" $HADOOP_HOME /lib/native" \
159142 -Dhadoop.home.dir=" $HADOOP_HOME " \
0 commit comments