sql-client.sh 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. ################################################################################
  20. # Adopted from "flink" bash script
  21. ################################################################################
  22. target="$0"
  23. # For the case, the executable has been directly symlinked, figure out
  24. # the correct bin path by following its symlink up to an upper bound.
  25. # Note: we can't use the readlink utility here if we want to be POSIX
  26. # compatible.
  27. iteration=0
  28. while [ -L "$target" ]; do
  29. if [ "$iteration" -gt 100 ]; then
  30. echo "Cannot resolve path: You have a cyclic symlink in $target."
  31. break
  32. fi
  33. ls=`ls -ld -- "$target"`
  34. target=`expr "$ls" : '.* -> \(.*\)$'`
  35. iteration=$((iteration + 1))
  36. done
  37. # Convert relative path to absolute path
  38. bin=`dirname "$target"`
  39. # get flink config
  40. . "$bin"/config.sh
  41. if [ "$FLINK_IDENT_STRING" = "" ]; then
  42. FLINK_IDENT_STRING="$USER"
  43. fi
  44. CC_CLASSPATH=`constructFlinkClassPath`
  45. ################################################################################
  46. # SQL client specific logic
  47. ################################################################################
  48. log=$FLINK_LOG_DIR/flink-$FLINK_IDENT_STRING-sql-client-$HOSTNAME.log
  49. log_setting=(-Dlog.file="$log" -Dlog4j.configuration=file:"$FLINK_CONF_DIR"/log4j-cli.properties -Dlog4j.configurationFile=file:"$FLINK_CONF_DIR"/log4j-cli.properties -Dlogback.configurationFile=file:"$FLINK_CONF_DIR"/logback.xml)
  50. # get path of jar in /opt if it exist
  51. FLINK_SQL_CLIENT_JAR=$(find "$FLINK_OPT_DIR" -regex ".*flink-sql-client.*.jar")
  52. # add flink-python jar to the classpath
  53. if [[ ! "$CC_CLASSPATH" =~ .*flink-python.*.jar ]]; then
  54. FLINK_PYTHON_JAR=$(find "$FLINK_OPT_DIR" -regex ".*flink-python.*.jar")
  55. if [ -n "$FLINK_PYTHON_JAR" ]; then
  56. CC_CLASSPATH="$CC_CLASSPATH:$FLINK_PYTHON_JAR"
  57. fi
  58. fi
  59. # add flink-sql-gateway jar to the classpath
  60. if [[ ! "$CC_CLASSPATH" =~ .*flink-sql-gateway.*.jar ]]; then
  61. FLINK_SQL_GATEWAY_JAR=$(find "$FLINK_OPT_DIR" -regex ".*flink-sql-gateway.*.jar")
  62. if [ -n "$FLINK_SQL_GATEWAY_JAR" ]; then
  63. CC_CLASSPATH="$CC_CLASSPATH:$FLINK_SQL_GATEWAY_JAR"
  64. fi
  65. fi
  66. FLINK_ENV_JAVA_OPTS="${FLINK_ENV_JAVA_OPTS} ${FLINK_ENV_JAVA_OPTS_CLI}"
  67. # check if SQL client is already in classpath and must not be shipped manually
  68. if [[ "$CC_CLASSPATH" =~ .*flink-sql-client.*.jar ]]; then
  69. # start client without jar
  70. exec "$JAVA_RUN" $FLINK_ENV_JAVA_OPTS $JVM_ARGS "${log_setting[@]}" -classpath "`manglePathList "$CC_CLASSPATH:$INTERNAL_HADOOP_CLASSPATHS"`" org.apache.flink.table.client.SqlClient "$@"
  71. # check if SQL client jar is in /opt
  72. elif [ -n "$FLINK_SQL_CLIENT_JAR" ]; then
  73. # start client with jar
  74. exec "$JAVA_RUN" $FLINK_ENV_JAVA_OPTS $JVM_ARGS "${log_setting[@]}" -classpath "`manglePathList "$CC_CLASSPATH:$FLINK_SQL_CLIENT_JAR:$INTERNAL_HADOOP_CLASSPATHS"`" org.apache.flink.table.client.SqlClient "$@" --jar "`manglePath $FLINK_SQL_CLIENT_JAR`"
  75. # write error message to stderr
  76. else
  77. (>&2 echo "[ERROR] Flink SQL Client JAR file 'flink-sql-client*.jar' neither found in classpath nor /opt directory should be located in $FLINK_OPT_DIR.")
  78. # exit to force process failure
  79. exit 1
  80. fi