config.sh 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. #!/usr/bin/env bash
  2. ################################################################################
  3. # Licensed to the Apache Software Foundation (ASF) under one
  4. # or more contributor license agreements. See the NOTICE file
  5. # distributed with this work for additional information
  6. # regarding copyright ownership. The ASF licenses this file
  7. # to you under the Apache License, Version 2.0 (the
  8. # "License"); you may not use this file except in compliance
  9. # with the License. You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. ################################################################################
  19. constructFlinkClassPath() {
  20. local FLINK_DIST
  21. local FLINK_CLASSPATH
  22. while read -d '' -r jarfile ; do
  23. if [[ "$jarfile" =~ .*/flink-dist[^/]*.jar$ ]]; then
  24. FLINK_DIST="$FLINK_DIST":"$jarfile"
  25. elif [[ "$FLINK_CLASSPATH" == "" ]]; then
  26. FLINK_CLASSPATH="$jarfile";
  27. else
  28. FLINK_CLASSPATH="$FLINK_CLASSPATH":"$jarfile"
  29. fi
  30. done < <(find "$FLINK_LIB_DIR" ! -type d -name '*.jar' -print0 | sort -z)
  31. local FLINK_DIST_COUNT
  32. FLINK_DIST_COUNT="$(echo "$FLINK_DIST" | tr -s ':' '\n' | grep -v '^$' | wc -l)"
  33. # If flink-dist*.jar cannot be resolved write error messages to stderr since stdout is stored
  34. # as the classpath and exit function with empty classpath to force process failure
  35. if [[ "$FLINK_DIST" == "" ]]; then
  36. (>&2 echo "[ERROR] Flink distribution jar not found in $FLINK_LIB_DIR.")
  37. exit 1
  38. elif [[ "$FLINK_DIST_COUNT" -gt 1 ]]; then
  39. (>&2 echo "[ERROR] Multiple flink-dist*.jar found in $FLINK_LIB_DIR. Please resolve.")
  40. exit 1
  41. fi
  42. echo "$FLINK_CLASSPATH""$FLINK_DIST"
  43. }
  44. findSqlGatewayJar() {
  45. local SQL_GATEWAY
  46. SQL_GATEWAY="$(find "$FLINK_OPT_DIR" -name 'flink-sql-gateway*.jar')"
  47. local SQL_GATEWAY_COUNT
  48. SQL_GATEWAY_COUNT="$(echo "$SQL_GATEWAY" | wc -l)"
  49. # If flink-sql-gateway*.jar cannot be resolved write error messages to stderr since stdout is stored
  50. # as the classpath and exit function with empty classpath to force process failure
  51. if [[ "$SQL_GATEWAY" == "" ]]; then
  52. (>&2 echo "[ERROR] Flink sql gateway jar not found in $FLINK_OPT_DIR.")
  53. exit 1
  54. elif [[ "$SQL_GATEWAY_COUNT" -gt 1 ]]; then
  55. (>&2 echo "[ERROR] Multiple flink-sql-gateway*.jar found in $FLINK_OPT_DIR. Please resolve.")
  56. exit 1
  57. fi
  58. echo "$SQL_GATEWAY"
  59. }
  60. findFlinkPythonJar() {
  61. local FLINK_PYTHON
  62. FLINK_PYTHON="$(find "$FLINK_OPT_DIR" -name 'flink-python*.jar')"
  63. local FLINK_PYTHON_COUNT
  64. FLINK_PYTHON_COUNT="$(echo "FLINK_PYTHON" | wc -l)"
  65. # If flink-python*.jar cannot be resolved write error messages to stderr since stdout is stored
  66. # as the classpath and exit function with empty classpath to force process failure
  67. if [[ "$FLINK_PYTHON" == "" ]]; then
  68. echo "[WARN] Flink python jar not found in $FLINK_OPT_DIR."
  69. elif [[ "$FLINK_PYTHON_COUNT" -gt 1 ]]; then
  70. (>&2 echo "[ERROR] Multiple flink-python*.jar found in $FLINK_OPT_DIR. Please resolve.")
  71. exit 1
  72. fi
  73. echo "$FLINK_PYTHON"
  74. }
  75. # These are used to mangle paths that are passed to java when using
  76. # cygwin. Cygwin paths are like linux paths, i.e. /path/to/somewhere
  77. # but the windows java version expects them in Windows Format, i.e. C:\bla\blub.
  78. # "cygpath" can do the conversion.
  79. manglePath() {
  80. UNAME=$(uname -s)
  81. if [ "${UNAME:0:6}" == "CYGWIN" ]; then
  82. echo `cygpath -w "$1"`
  83. else
  84. echo $1
  85. fi
  86. }
  87. # Looks up a config value by key from a simple YAML-style key-value map.
  88. # $1: key to look up
  89. # $2: default value to return if key does not exist
  90. # $3: config file to read from
  91. readFromConfig() {
  92. local key=$1
  93. local defaultValue=$2
  94. local configuration=$3
  95. local value=$(echo "$configuration" | grep "^[ ]*${key}[ ]*:" | cut -d ':' -f2- | sed "s/^ *//;s/ *$//" | tail -n 1)
  96. [ -z "$value" ] && echo "$defaultValue" || echo "$value"
  97. }
  98. ########################################################################################################################
  99. # DEFAULT CONFIG VALUES: These values will be used when nothing has been specified in conf/config.yaml
  100. # -or- the respective environment variables are not set.
  101. ########################################################################################################################
  102. # WARNING !!! , these values are only used if there is nothing else is specified in
  103. # conf/config.yaml
  104. DEFAULT_ENV_PID_DIR="/tmp" # Directory to store *.pid files to
  105. DEFAULT_ENV_LOG_MAX=10 # Maximum number of old log files to keep
  106. DEFAULT_ENV_LOG_LEVEL="INFO" # Level of the root logger
  107. DEFAULT_ENV_JAVA_OPTS="" # Optional JVM args
  108. DEFAULT_ENV_JAVA_OPTS_JM="" # Optional JVM args (JobManager)
  109. DEFAULT_ENV_JAVA_OPTS_TM="" # Optional JVM args (TaskManager)
  110. DEFAULT_ENV_JAVA_OPTS_HS="" # Optional JVM args (HistoryServer)
  111. DEFAULT_ENV_JAVA_OPTS_CLI="" # Optional JVM args (Client)
  112. DEFAULT_ENV_JAVA_OPTS_SQL_GATEWAY="" # Optional JVM args (Sql-Gateway)
  113. DEFAULT_ENV_SSH_OPTS="" # Optional SSH parameters running in cluster mode
  114. DEFAULT_YARN_CONF_DIR="" # YARN Configuration Directory, if necessary
  115. DEFAULT_HADOOP_CONF_DIR="" # Hadoop Configuration Directory, if necessary
  116. DEFAULT_HBASE_CONF_DIR="" # HBase Configuration Directory, if necessary
  117. ########################################################################################################################
  118. # CONFIG KEYS: The default values can be overwritten by the following keys in conf/config.yaml
  119. ########################################################################################################################
  120. KEY_TASKM_COMPUTE_NUMA="taskmanager.compute.numa"
  121. KEY_ENV_PID_DIR="env.pid.dir"
  122. KEY_ENV_LOG_DIR="env.log.dir"
  123. KEY_ENV_LOG_MAX="env.log.max"
  124. KEY_ENV_LOG_LEVEL="env.log.level"
  125. KEY_ENV_STD_REDIRECT_TO_FILE="env.stdout-err.redirect-to-file"
  126. KEY_ENV_YARN_CONF_DIR="env.yarn.conf.dir"
  127. KEY_ENV_HADOOP_CONF_DIR="env.hadoop.conf.dir"
  128. KEY_ENV_HBASE_CONF_DIR="env.hbase.conf.dir"
  129. KEY_ENV_JAVA_HOME="env.java.home"
  130. KEY_ENV_JAVA_OPTS="env.java.opts.all"
  131. KEY_ENV_JAVA_OPTS_JM="env.java.opts.jobmanager"
  132. KEY_ENV_JAVA_OPTS_TM="env.java.opts.taskmanager"
  133. KEY_ENV_JAVA_OPTS_HS="env.java.opts.historyserver"
  134. KEY_ENV_JAVA_OPTS_CLI="env.java.opts.client"
  135. KEY_ENV_JAVA_OPTS_SQL_GATEWAY="env.java.opts.sql-gateway"
  136. KEY_ENV_JAVA_DEFAULT_OPTS="env.java.default-opts.all"
  137. KEY_ENV_JAVA_DEFAULT_OPTS_JM="env.java.default-opts.jobmanager"
  138. KEY_ENV_JAVA_DEFAULT_OPTS_TM="env.java.default-opts.taskmanager"
  139. KEY_ENV_SSH_OPTS="env.ssh.opts"
  140. KEY_HIGH_AVAILABILITY="high-availability.type"
  141. KEY_ZK_HEAP_MB="zookeeper.heap.mb"
  142. ########################################################################################################################
  143. # PATHS AND CONFIG
  144. ########################################################################################################################
  145. target="$0"
  146. # For the case, the executable has been directly symlinked, figure out
  147. # the correct bin path by following its symlink up to an upper bound.
  148. # Note: we can't use the readlink utility here if we want to be POSIX
  149. # compatible.
  150. iteration=0
  151. while [ -L "$target" ]; do
  152. if [ "$iteration" -gt 100 ]; then
  153. echo "Cannot resolve path: You have a cyclic symlink in $target."
  154. break
  155. fi
  156. ls=`ls -ld -- "$target"`
  157. target=`expr "$ls" : '.* -> \(.*\)$'`
  158. iteration=$((iteration + 1))
  159. done
  160. # Convert relative path to absolute path and resolve directory symlinks
  161. bin=`dirname "$target"`
  162. SYMLINK_RESOLVED_BIN=`cd "$bin"; pwd -P`
  163. # Define the main directory of the flink installation
  164. # If config.sh is called by pyflink-shell.sh in python bin directory(pip installed), then do not need to set the FLINK_HOME here.
  165. if [ -z "$_FLINK_HOME_DETERMINED" ]; then
  166. FLINK_HOME=`dirname "$SYMLINK_RESOLVED_BIN"`
  167. fi
  168. if [ -z "$FLINK_LIB_DIR" ]; then FLINK_LIB_DIR=$FLINK_HOME/lib; fi
  169. if [ -z "$FLINK_PLUGINS_DIR" ]; then FLINK_PLUGINS_DIR=$FLINK_HOME/plugins; fi
  170. if [ -z "$FLINK_OPT_DIR" ]; then FLINK_OPT_DIR=$FLINK_HOME/opt; fi
  171. # These need to be mangled because they are directly passed to java.
  172. # The above lib path is used by the shell script to retrieve jars in a
  173. # directory, so it needs to be unmangled.
  174. FLINK_HOME_DIR_MANGLED=`manglePath "$FLINK_HOME"`
  175. if [ -z "$FLINK_CONF_DIR" ]; then FLINK_CONF_DIR=$FLINK_HOME_DIR_MANGLED/conf; fi
  176. FLINK_BIN_DIR=$FLINK_HOME_DIR_MANGLED/bin
  177. DEFAULT_FLINK_LOG_DIR=$FLINK_HOME_DIR_MANGLED/log
  178. ### Exported environment variables ###
  179. export FLINK_CONF_DIR
  180. export FLINK_BIN_DIR
  181. export FLINK_PLUGINS_DIR
  182. # export /lib dir to access it during deployment of the Yarn staging files
  183. export FLINK_LIB_DIR
  184. # export /opt dir to access it for the SQL client
  185. export FLINK_OPT_DIR
  186. source "${FLINK_BIN_DIR}/bash-java-utils.sh"
  187. setJavaRun "$FLINK_CONF_DIR"
  188. YAML_CONF=$(updateAndGetFlinkConfiguration "${FLINK_CONF_DIR}" "${FLINK_BIN_DIR}" ${FLINK_LIB_DIR} -flatten)
  189. ########################################################################################################################
  190. # ENVIRONMENT VARIABLES
  191. ########################################################################################################################
  192. # Define HOSTNAME if it is not already set
  193. if [ -z "${HOSTNAME}" ]; then
  194. HOSTNAME=`hostname`
  195. fi
  196. IS_NUMBER="^[0-9]+$"
  197. # Verify that NUMA tooling is available
  198. command -v numactl >/dev/null 2>&1
  199. if [[ $? -ne 0 ]]; then
  200. FLINK_TM_COMPUTE_NUMA="false"
  201. else
  202. # Define FLINK_TM_COMPUTE_NUMA if it is not already set
  203. if [ -z "${FLINK_TM_COMPUTE_NUMA}" ]; then
  204. FLINK_TM_COMPUTE_NUMA=$(readFromConfig ${KEY_TASKM_COMPUTE_NUMA} "false" "${YAML_CONF}")
  205. fi
  206. fi
  207. if [ -z "${MAX_LOG_FILE_NUMBER}" ]; then
  208. MAX_LOG_FILE_NUMBER=$(readFromConfig ${KEY_ENV_LOG_MAX} ${DEFAULT_ENV_LOG_MAX} "${YAML_CONF}")
  209. export MAX_LOG_FILE_NUMBER
  210. fi
  211. if [ -z "${ROOT_LOG_LEVEL}" ]; then
  212. ROOT_LOG_LEVEL=$(readFromConfig ${KEY_ENV_LOG_LEVEL} "${DEFAULT_ENV_LOG_LEVEL}" "${YAML_CONF}")
  213. export ROOT_LOG_LEVEL
  214. fi
  215. if [ -z "${STD_REDIRECT_TO_FILE}" ]; then
  216. STD_REDIRECT_TO_FILE=$(readFromConfig ${KEY_ENV_STD_REDIRECT_TO_FILE} "false" "${YAML_CONF}")
  217. fi
  218. if [ -z "${FLINK_LOG_DIR}" ]; then
  219. FLINK_LOG_DIR=$(readFromConfig ${KEY_ENV_LOG_DIR} "${DEFAULT_FLINK_LOG_DIR}" "${YAML_CONF}")
  220. fi
  221. if [ -z "${YARN_CONF_DIR}" ]; then
  222. YARN_CONF_DIR=$(readFromConfig ${KEY_ENV_YARN_CONF_DIR} "${DEFAULT_YARN_CONF_DIR}" "${YAML_CONF}")
  223. fi
  224. if [ -z "${HADOOP_CONF_DIR}" ]; then
  225. HADOOP_CONF_DIR=$(readFromConfig ${KEY_ENV_HADOOP_CONF_DIR} "${DEFAULT_HADOOP_CONF_DIR}" "${YAML_CONF}")
  226. fi
  227. if [ -z "${HBASE_CONF_DIR}" ]; then
  228. HBASE_CONF_DIR=$(readFromConfig ${KEY_ENV_HBASE_CONF_DIR} "${DEFAULT_HBASE_CONF_DIR}" "${YAML_CONF}")
  229. fi
  230. if [ -z "${FLINK_PID_DIR}" ]; then
  231. FLINK_PID_DIR=$(readFromConfig ${KEY_ENV_PID_DIR} "${DEFAULT_ENV_PID_DIR}" "${YAML_CONF}")
  232. fi
  233. if [ -z "${FLINK_ENV_JAVA_OPTS}" ]; then
  234. FLINK_ENV_JAVA_DEFAULT_OPTS=$(readFromConfig ${KEY_ENV_JAVA_DEFAULT_OPTS} "" "${YAML_CONF}")
  235. FLINK_ENV_JAVA_OPTS=$(readFromConfig ${KEY_ENV_JAVA_OPTS} "" "${YAML_CONF}")
  236. if [ -z "${FLINK_ENV_JAVA_OPTS}" ]; then
  237. # try deprecated key
  238. FLINK_ENV_JAVA_OPTS=$(readFromConfig "env.java.opts" "${DEFAULT_ENV_JAVA_OPTS}" "${YAML_CONF}")
  239. fi
  240. FLINK_ENV_JAVA_OPTS="${FLINK_ENV_JAVA_DEFAULT_OPTS} ${FLINK_ENV_JAVA_OPTS}"
  241. # Remove leading and ending double quotes (if present) of value
  242. FLINK_ENV_JAVA_OPTS="-XX:+IgnoreUnrecognizedVMOptions $( echo "${FLINK_ENV_JAVA_OPTS}" | sed -e 's/^"//' -e 's/"$//' )"
  243. JAVA_SPEC_VERSION=`"${JAVA_RUN}" -XshowSettings:properties 2>&1 | grep "java.specification.version" | cut -d "=" -f 2 | tr -d '[:space:]' | rev | cut -d "." -f 1 | rev`
  244. if [[ $(( $JAVA_SPEC_VERSION > 17 )) == 1 ]]; then
  245. # set security manager property to allow calls to System.setSecurityManager() at runtime
  246. FLINK_ENV_JAVA_OPTS="$FLINK_ENV_JAVA_OPTS -Djava.security.manager=allow"
  247. fi
  248. fi
  249. if [ -z "${FLINK_ENV_JAVA_OPTS_JM}" ]; then
  250. FLINK_ENV_JAVA_DEFAULT_OPTS_JM=$(readFromConfig ${KEY_ENV_JAVA_DEFAULT_OPTS_JM} "" "${YAML_CONF}")
  251. FLINK_ENV_JAVA_OPTS_JM=$(readFromConfig ${KEY_ENV_JAVA_OPTS_JM} "${DEFAULT_ENV_JAVA_OPTS_JM}" "${YAML_CONF}")
  252. FLINK_ENV_JAVA_OPTS_JM="${FLINK_ENV_JAVA_DEFAULT_OPTS_JM} ${FLINK_ENV_JAVA_OPTS_JM}"
  253. # Remove leading and ending double quotes (if present) of value
  254. FLINK_ENV_JAVA_OPTS_JM="$( echo "${FLINK_ENV_JAVA_OPTS_JM}" | sed -e 's/^"//' -e 's/"$//' )"
  255. fi
  256. if [ -z "${FLINK_ENV_JAVA_OPTS_TM}" ]; then
  257. FLINK_ENV_JAVA_DEFAULT_OPTS_TM=$(readFromConfig ${KEY_ENV_JAVA_DEFAULT_OPTS_TM} "" "${YAML_CONF}")
  258. FLINK_ENV_JAVA_OPTS_TM=$(readFromConfig ${KEY_ENV_JAVA_OPTS_TM} "${DEFAULT_ENV_JAVA_OPTS_TM}" "${YAML_CONF}")
  259. FLINK_ENV_JAVA_OPTS_TM="${FLINK_ENV_JAVA_DEFAULT_OPTS_TM} ${FLINK_ENV_JAVA_OPTS_TM}"
  260. # Remove leading and ending double quotes (if present) of value
  261. FLINK_ENV_JAVA_OPTS_TM="$( echo "${FLINK_ENV_JAVA_OPTS_TM}" | sed -e 's/^"//' -e 's/"$//' )"
  262. fi
  263. if [ -z "${FLINK_ENV_JAVA_OPTS_HS}" ]; then
  264. FLINK_ENV_JAVA_OPTS_HS=$(readFromConfig ${KEY_ENV_JAVA_OPTS_HS} "${DEFAULT_ENV_JAVA_OPTS_HS}" "${YAML_CONF}")
  265. # Remove leading and ending double quotes (if present) of value
  266. FLINK_ENV_JAVA_OPTS_HS="$( echo "${FLINK_ENV_JAVA_OPTS_HS}" | sed -e 's/^"//' -e 's/"$//' )"
  267. fi
  268. if [ -z "${FLINK_ENV_JAVA_OPTS_CLI}" ]; then
  269. FLINK_ENV_JAVA_OPTS_CLI=$(readFromConfig ${KEY_ENV_JAVA_OPTS_CLI} "${DEFAULT_ENV_JAVA_OPTS_CLI}" "${YAML_CONF}")
  270. # Remove leading and ending double quotes (if present) of value
  271. FLINK_ENV_JAVA_OPTS_CLI="$( echo "${FLINK_ENV_JAVA_OPTS_CLI}" | sed -e 's/^"//' -e 's/"$//' )"
  272. fi
  273. if [ -z "${FLINK_ENV_JAVA_OPTS_SQL_GATEWAY}" ]; then
  274. FLINK_ENV_JAVA_OPTS_SQL_GATEWAY=$(readFromConfig ${KEY_ENV_JAVA_OPTS_SQL_GATEWAY} "${DEFAULT_ENV_JAVA_OPTS_SQL_GATEWAY}" "${YAML_CONF}")
  275. # Remove leading and ending double quotes (if present) of value
  276. FLINK_ENV_JAVA_OPTS_SQL_GATEWAY="$( echo "${FLINK_ENV_JAVA_OPTS_SQL_GATEWAY}" | sed -e 's/^"//' -e 's/"$//' )"
  277. fi
  278. if [ -z "${FLINK_SSH_OPTS}" ]; then
  279. FLINK_SSH_OPTS=$(readFromConfig ${KEY_ENV_SSH_OPTS} "${DEFAULT_ENV_SSH_OPTS}" "${YAML_CONF}")
  280. fi
  281. # Define ZK_HEAP if it is not already set
  282. if [ -z "${ZK_HEAP}" ]; then
  283. ZK_HEAP=$(readFromConfig ${KEY_ZK_HEAP_MB} 0 "${YAML_CONF}")
  284. fi
  285. # High availability
  286. if [ -z "${HIGH_AVAILABILITY}" ]; then
  287. HIGH_AVAILABILITY=$(readFromConfig ${KEY_HIGH_AVAILABILITY} "" "${YAML_CONF}")
  288. if [ -z "${HIGH_AVAILABILITY}" ]; then
  289. # Try deprecated value
  290. DEPRECATED_HA=$(readFromConfig "high-availability" "$(readFromConfig "recovery.mode" "" "${YAML_CONF}")" "${YAML_CONF}")
  291. if [ -z "${DEPRECATED_HA}" ]; then
  292. HIGH_AVAILABILITY="none"
  293. elif [ ${DEPRECATED_HA} == "standalone" ]; then
  294. # Standalone is now 'none'
  295. HIGH_AVAILABILITY="none"
  296. else
  297. HIGH_AVAILABILITY=${DEPRECATED_HA}
  298. fi
  299. fi
  300. fi
  301. # Arguments for the JVM. Used for job and task manager JVMs.
  302. # DO NOT USE FOR MEMORY SETTINGS! Use conf/config.yaml with keys
  303. # JobManagerOptions#TOTAL_PROCESS_MEMORY and TaskManagerOptions#TOTAL_PROCESS_MEMORY for that!
  304. if [ -z "${JVM_ARGS}" ]; then
  305. JVM_ARGS=""
  306. fi
  307. # Check if deprecated HADOOP_HOME is set, and specify config path to HADOOP_CONF_DIR if it's empty.
  308. if [ -z "$HADOOP_CONF_DIR" ]; then
  309. if [ -n "$HADOOP_HOME" ]; then
  310. # HADOOP_HOME is set. Check if its a Hadoop 1.x or 2.x HADOOP_HOME path
  311. if [ -d "$HADOOP_HOME/conf" ]; then
  312. # It's Hadoop 1.x
  313. HADOOP_CONF_DIR="$HADOOP_HOME/conf"
  314. fi
  315. if [ -d "$HADOOP_HOME/etc/hadoop" ]; then
  316. # It's Hadoop 2.2+
  317. HADOOP_CONF_DIR="$HADOOP_HOME/etc/hadoop"
  318. fi
  319. fi
  320. fi
  321. # if neither HADOOP_CONF_DIR nor HADOOP_CLASSPATH are set, use some common default (if available)
  322. if [ -z "$HADOOP_CONF_DIR" ] && [ -z "$HADOOP_CLASSPATH" ]; then
  323. if [ -d "/etc/hadoop/conf" ]; then
  324. echo "Setting HADOOP_CONF_DIR=/etc/hadoop/conf because no HADOOP_CONF_DIR or HADOOP_CLASSPATH was set."
  325. HADOOP_CONF_DIR="/etc/hadoop/conf"
  326. fi
  327. fi
  328. # Check if deprecated HBASE_HOME is set, and specify config path to HBASE_CONF_DIR if it's empty.
  329. if [ -z "$HBASE_CONF_DIR" ]; then
  330. if [ -n "$HBASE_HOME" ]; then
  331. # HBASE_HOME is set.
  332. if [ -d "$HBASE_HOME/conf" ]; then
  333. HBASE_CONF_DIR="$HBASE_HOME/conf"
  334. fi
  335. fi
  336. fi
  337. # try and set HBASE_CONF_DIR to some common default if it's not set
  338. if [ -z "$HBASE_CONF_DIR" ]; then
  339. if [ -d "/etc/hbase/conf" ]; then
  340. echo "Setting HBASE_CONF_DIR=/etc/hbase/conf because no HBASE_CONF_DIR was set."
  341. HBASE_CONF_DIR="/etc/hbase/conf"
  342. fi
  343. fi
  344. INTERNAL_HADOOP_CLASSPATHS="${HADOOP_CLASSPATH}:${HADOOP_CONF_DIR}:${YARN_CONF_DIR}"
  345. if [ -n "${HBASE_CONF_DIR}" ]; then
  346. INTERNAL_HADOOP_CLASSPATHS="${INTERNAL_HADOOP_CLASSPATHS}:${HBASE_CONF_DIR}"
  347. fi
  348. # Auxiliary function which extracts the name of host from a line which
  349. # also potentially includes topology information and the taskManager type
  350. extractHostName() {
  351. # handle comments: extract first part of string (before first # character)
  352. WORKER=`echo $1 | cut -d'#' -f 1`
  353. # Extract the hostname from the network hierarchy
  354. if [[ "$WORKER" =~ ^.*/([0-9a-zA-Z.-]+)$ ]]; then
  355. WORKER=${BASH_REMATCH[1]}
  356. fi
  357. echo $WORKER
  358. }
  359. readMasters() {
  360. MASTERS_FILE="${FLINK_CONF_DIR}/masters"
  361. if [[ ! -f "${MASTERS_FILE}" ]]; then
  362. echo "No masters file. Please specify masters in 'conf/masters'."
  363. exit 1
  364. fi
  365. MASTERS=()
  366. WEBUIPORTS=()
  367. MASTERS_ALL_LOCALHOST=true
  368. GOON=true
  369. while $GOON; do
  370. read line || GOON=false
  371. HOSTWEBUIPORT=$( extractHostName $line)
  372. if [ -n "$HOSTWEBUIPORT" ]; then
  373. HOST=$(echo $HOSTWEBUIPORT | cut -f1 -d:)
  374. WEBUIPORT=$(echo $HOSTWEBUIPORT | cut -s -f2 -d:)
  375. MASTERS+=(${HOST})
  376. if [ -z "$WEBUIPORT" ]; then
  377. WEBUIPORTS+=(0)
  378. else
  379. WEBUIPORTS+=(${WEBUIPORT})
  380. fi
  381. if [ "${HOST}" != "localhost" ] && [ "${HOST}" != "127.0.0.1" ] ; then
  382. MASTERS_ALL_LOCALHOST=false
  383. fi
  384. fi
  385. done < "$MASTERS_FILE"
  386. }
  387. readWorkers() {
  388. WORKERS_FILE="${FLINK_CONF_DIR}/workers"
  389. if [[ ! -f "$WORKERS_FILE" ]]; then
  390. echo "No workers file. Please specify workers in 'conf/workers'."
  391. exit 1
  392. fi
  393. WORKERS=()
  394. WORKERS_ALL_LOCALHOST=true
  395. GOON=true
  396. while $GOON; do
  397. read line || GOON=false
  398. HOST=$( extractHostName $line)
  399. if [ -n "$HOST" ] ; then
  400. WORKERS+=(${HOST})
  401. if [ "${HOST}" != "localhost" ] && [ "${HOST}" != "127.0.0.1" ] ; then
  402. WORKERS_ALL_LOCALHOST=false
  403. fi
  404. fi
  405. done < "$WORKERS_FILE"
  406. }
  407. # starts or stops TMs on all workers
  408. # TMWorkers start|stop
  409. TMWorkers() {
  410. CMD=$1
  411. readWorkers
  412. if [ ${WORKERS_ALL_LOCALHOST} = true ] ; then
  413. # all-local setup
  414. for worker in ${WORKERS[@]}; do
  415. "${FLINK_BIN_DIR}"/taskmanager.sh "${CMD}"
  416. done
  417. else
  418. # non-local setup
  419. # start/stop TaskManager instance(s) using pdsh (Parallel Distributed Shell) when available
  420. command -v pdsh >/dev/null 2>&1
  421. if [[ $? -ne 0 ]]; then
  422. for worker in ${WORKERS[@]}; do
  423. ssh -n $FLINK_SSH_OPTS $worker -- "nohup /bin/bash -l \"${FLINK_BIN_DIR}/taskmanager.sh\" \"${CMD}\" &"
  424. done
  425. else
  426. PDSH_SSH_ARGS="" PDSH_SSH_ARGS_APPEND=$FLINK_SSH_OPTS pdsh -w $(IFS=, ; echo "${WORKERS[*]}") \
  427. "nohup /bin/bash -l \"${FLINK_BIN_DIR}/taskmanager.sh\" \"${CMD}\""
  428. fi
  429. fi
  430. }
  431. parseJmArgsAndExportLogs() {
  432. parseResourceParamsAndExportLogs GET_JM_RESOURCE_PARAMS "$@"
  433. }
  434. parseTmArgsAndExportLogs() {
  435. parseResourceParamsAndExportLogs GET_TM_RESOURCE_PARAMS "$@"
  436. }