sql-client.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. # check if SQL client is already in classpath and must not be shipped manually
  67. if [[ "$CC_CLASSPATH" =~ .*flink-sql-client.*.jar ]]; then
  68. # start client without jar
  69. exec "$JAVA_RUN" $JVM_ARGS "${log_setting[@]}" -classpath "`manglePathList "$CC_CLASSPATH:$INTERNAL_HADOOP_CLASSPATHS"`" org.apache.flink.table.client.SqlClient "$@"
  70. # check if SQL client jar is in /opt
  71. elif [ -n "$FLINK_SQL_CLIENT_JAR" ]; then
  72. # start client with jar
  73. exec "$JAVA_RUN" $JVM_ARGS "${log_setting[@]}" -classpath "`manglePathList "$CC_CLASSPATH:$INTERNAL_HADOOP_CLASSPATHS:$FLINK_SQL_CLIENT_JAR"`" org.apache.flink.table.client.SqlClient "$@" --jar "`manglePath $FLINK_SQL_CLIENT_JAR`"
  74. # write error message to stderr
  75. else
  76. (>&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.")
  77. # exit to force process failure
  78. exit 1
  79. fi