From 7bc8913cb8b61ce36d2b45a79be00539ba18c629 Mon Sep 17 00:00:00 2001 From: Zzm0809 <934230207@qq.com> Date: Tue, 3 Dec 2024 19:05:26 +0800 Subject: [PATCH] [Feature] Provide init tools (#3999) Co-authored-by: Zzm0809 Co-authored-by: GH Action - Upstream Sync --- deploy/docker/Dockerfile | 2 +- dinky-admin/src/main/assembly/package.xml | 2 +- dinky-assembly/src/main/assembly/package.xml | 4 +- script/bin/auto.sh | 4 +- script/bin/init_check_network.sh | 17 ++ script/bin/init_db.sh | 65 +++++ script/bin/init_flink_dependences.sh | 104 ++++++++ script/bin/init_hadoop_dependences.sh | 35 +++ script/bin/init_tools_main.sh | 238 +++++++++++++++++++ 9 files changed, 465 insertions(+), 6 deletions(-) create mode 100644 script/bin/init_check_network.sh create mode 100644 script/bin/init_db.sh create mode 100644 script/bin/init_flink_dependences.sh create mode 100644 script/bin/init_hadoop_dependences.sh create mode 100644 script/bin/init_tools_main.sh diff --git a/deploy/docker/Dockerfile b/deploy/docker/Dockerfile index 68502ff200..afa40b4379 100755 --- a/deploy/docker/Dockerfile +++ b/deploy/docker/Dockerfile @@ -52,4 +52,4 @@ RUN mkdir /opt/dinky/customJar && chmod -R 777 /opt/dinky/ && sed -i 's/-Xms512M EXPOSE 8888 -CMD ./auto.sh startOnPending \ No newline at end of file +CMD ./bin/auto.sh startOnPending \ No newline at end of file diff --git a/dinky-admin/src/main/assembly/package.xml b/dinky-admin/src/main/assembly/package.xml index 8285c49490..423bb9fce1 100644 --- a/dinky-admin/src/main/assembly/package.xml +++ b/dinky-admin/src/main/assembly/package.xml @@ -16,7 +16,7 @@ ${basedir}/src/main/bin unix - + bin 755 *.sh diff --git a/dinky-assembly/src/main/assembly/package.xml b/dinky-assembly/src/main/assembly/package.xml index 7cb907dc29..e3294655f4 100644 --- a/dinky-assembly/src/main/assembly/package.xml +++ b/dinky-assembly/src/main/assembly/package.xml @@ -26,11 +26,11 @@ ${project.parent.basedir}/script/bin - ./ + ./bin unix 0755 - auto.sh + *.sh diff --git a/script/bin/auto.sh b/script/bin/auto.sh index 55e65745fe..339b5374c8 100644 --- a/script/bin/auto.sh +++ b/script/bin/auto.sh @@ -5,7 +5,7 @@ FLINK_VERSION=${2} -DINKY_HOME=${DINKY_HOME:-$(cd `dirname $0`; pwd)} +DINKY_HOME=${DINKY_HOME:-$(cd "$(dirname "$0")"; cd ..; pwd)} JAVA_VERSION=$(java -version 2>&1 | sed '1!d' | sed -e 's/"//g' | awk '{print $3}' | awk -F'.' '{print $1"."$2}') APP_HOME="${DINKY_HOME}" @@ -34,7 +34,7 @@ if [ -z "${FLINK_VERSION}" ]; then fi fi -echo "DINKY_HOME : ${DINKY_HOME} , JAVA_VERSION : ${JAVA_VERSION} , FLINK_VERSION : ${FLINK_VERSION}" +echo "DINKY_HOME : ${APP_HOME} , JAVA_VERSION : ${JAVA_VERSION} , FLINK_VERSION : ${FLINK_VERSION}" # Check whether the flink version is specified assertIsInputVersion() { diff --git a/script/bin/init_check_network.sh b/script/bin/init_check_network.sh new file mode 100644 index 0000000000..92335059a9 --- /dev/null +++ b/script/bin/init_check_network.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +EXTERNAL_CONNECTIVITY_CHECK_URL="www.baidu.com" + +echo -e "${YELLOW}Checking whether your network can connect to the Internet properly (${EXTERNAL_CONNECTIVITY_CHECK_URL}) ...${RESET}" +if ! ping -c 1 ${EXTERNAL_CONNECTIVITY_CHECK_URL} &> /dev/null; then + echo -e "${RED}Your network cannot connect to the Internet using ping mode, please check whether your network environment is normal, and the program will try to use curl mode to detect the network connection again...${RESET}" + if ! curl -I -s --connect-timeout 5 ${EXTERNAL_CONNECTIVITY_CHECK_URL} -w '%{http_code}' | tail -n1 | grep "200" &> /dev/null; then + echo -e "${RED}Your network cannot be connected to the Internet using curl mode, please check whether your network environment is normal。${RESET}" + echo -e "${YELLOW}Note that in some network environments, firewalls or security policies may block ICMP requests (i.e., pings). If this happens, you can use curl to detect the network connection.${RESET}" + exit 1 + else + echo -e "${GREEN}Your network can use curl to connect to the Internet and proceed to the next step...${RESET}" + fi +else + echo -e "${GREEN}Your network can use ping to connect to the Internet and proceed to the next step...${RESET}" +fi \ No newline at end of file diff --git a/script/bin/init_db.sh b/script/bin/init_db.sh new file mode 100644 index 0000000000..6c706dd4fc --- /dev/null +++ b/script/bin/init_db.sh @@ -0,0 +1,65 @@ +#!/bin/bash + +DINKY_HOME=$1 + +echo -e "${GREEN}====================== The database configuration file is initialized ======================${RESET}" + +if [ -z "$DINKY_HOME" ]; then + echo -e "${RED}The parameter is wrong, please check!${RESET}" + exit 1 +fi + +while true; do + read -p "Please select a database type (1.MySQL 2.PostgresSQL):" db_type + read -p "Please enter the database address (hostname or IP, default localhost): " -i "localhost" db_host + read -p "Please enter the database port (default 3306): " -i 3306 db_port + read -p "Please enter a database name (default dinky): " -i "dinky" db_name + read -p "Please enter the database username (default dinky):" -i "dinky" db_username + read -s -p "Please enter the database password (default dinky):" -i "dinky" db_password + echo + + db_type=$(echo "$db_type" | tr -d '[:space:]') + db_host=$(echo "$db_host" | tr -d '[:space:]') + db_port=$(echo "$db_port" | tr -d '[:space:]') + db_name=$(echo "$db_name" | tr -d '[:space:]') + db_username=$(echo "$db_username" | tr -d '[:space:]') + db_password=$(echo "$db_password" | tr -d '[:space:]') + + case $db_type in + 1) + echo -e "${YELLOW}Configuring MySQL database related information...${RESET}" + config_file="${DINKY_HOME}/config/application-mysql.yml" + echo -e "${GREEN} The automatic initialization script uses the export environment variable method to support the loading of environment variables of the data source. The configuration file is:${config_file} ${RESET}" + echo "export DB_ACTIVE=mysql" >> /etc/profile + echo "export MYSQL_ADDR=${db_host}:${db_port}" >> /etc/profile + echo "export MYSQL_DATABASE=${db_name}" >> /etc/profile + echo "export MYSQL_USERNAME=${db_username}" >> /etc/profile + echo "export MYSQL_PASSWORD=${db_password}" >> /etc/profile + source /etc/profile + + echo -e "${GREEN}MySQLThe configuration of database related information is completed. Please confirm whether the following configuration is correct:${RESET}" + grep -E '^(export DB_ACTIVE|export MYSQL_ADDR|export MYSQL_DATABASE|export MYSQL_USERNAME|export MYSQL_PASSWORD)' /etc/profile | grep -v "^#" | grep -v "^$" + break + ;; + 2) + echo -e "${YELLOW}Configuring PostgresSQL database related information...${RESET}" + config_file="${DINKY_HOME}/config/application-pgsql.yml" + + echo -e "${GREEN}The automatic initialization script uses the export environment variable method to support the loading of environment variables from the data source configuration file. The configuration file is:${config_file} ${RESET}" + + echo "export DB_ACTIVE=pgsql" >> /etc/profile + echo "export POSTGRES_ADDR=${db_host}:${db_port}" >> /etc/profile + echo "export POSTGRES_DB=${db_name}" >> /etc/profile + echo "export POSTGRES_USER=${db_username}" >> /etc/profile + echo "export POSTGRES_PASSWORD=${db_password}" >> /etc/profile + source /etc/profile + + echo -e "${GREEN}PostgresSQL The configuration of database related information is completed. Please confirm whether the following configuration is correct:${RESET}" + grep -E '^(export DB_ACTIVE|export POSTGRES_ADDR|export POSTGRES_DB|export POSTGRES_USER|export POSTGRES_PASSWORD)' /etc/profile | grep -v "^#" | grep -v "^$" + break + ;; + *) + echo -e "${RED}The entered database type is incorrect, please select the correct database type again.${RESET}" + ;; + esac +done \ No newline at end of file diff --git a/script/bin/init_flink_dependences.sh b/script/bin/init_flink_dependences.sh new file mode 100644 index 0000000000..4b7092e93f --- /dev/null +++ b/script/bin/init_flink_dependences.sh @@ -0,0 +1,104 @@ +#!/bin/bash + +CURRENT_FLINK_FULL_VERSION=$1 +FLINK_VERSION_SCAN=$2 +DINKY_TMP_DIR=$3 +EXTENDS_HOME=$4 +DINKY_HOME=$5 + +echo -e "${GREEN}====================== Flink dependency initialization ======================${RESET}" + +echo -e "${BLUE}Parameters: The current Flink version is:${CURRENT_FLINK_FULL_VERSION},The scanned Flink version is:${FLINK_VERSION_SCAN} ,The temporary directory is:${DINKY_TMP_DIR} ,The expansion package directory is:${EXTENDS_HOME} ,Dinky The root directory is:${DINKY_HOME}${RESET}" + +if [ -z "$CURRENT_FLINK_FULL_VERSION" ] || [ -z "$FLINK_VERSION_SCAN" ] || [ -z "$DINKY_TMP_DIR" ] || [ -z "$EXTENDS_HOME" ] || [ -z "$DINKY_HOME" ]; then + echo -e "${RED}Parameter error, please check!${RESET}" + exit 1 +fi + +if [ -f "$DINKY_TMP_DIR/flink-${CURRENT_FLINK_FULL_VERSION}-bin-scala_2.12.tgz" ]; then + echo -e "${YELLOW}$DINKY_TMP_DIR ALREADY EXISTS flink-${CURRENT_FLINK_FULL_VERSION}-bin-scala_2.12.tgz file,To ensure completeness, delete first ${DINKY_TMP_DIR}/flink-${CURRENT_FLINK_FULL_VERSION}-bin-scala_2.12.tgz Download the file again${RESET}" + rm -rf ${DINKY_TMP_DIR}/flink-${CURRENT_FLINK_FULL_VERSION}-bin-scala_2.12.tgz + if [ -d "$DINKY_TMP_DIR/flink-${CURRENT_FLINK_FULL_VERSION}" ]; then + echo -e "${YELLOW}The flink directory already exists, delete it $DINKY_TMP_DIR/flink-${CURRENT_FLINK_FULL_VERSION}" + rm -rf $DINKY_TMP_DIR/flink-${CURRENT_FLINK_FULL_VERSION} + fi +fi + +try_tsinghua_mirror() { + local tsinghua_url="https://mirrors.tuna.tsinghua.edu.cn/apache/flink/flink-${CURRENT_FLINK_FULL_VERSION}/flink-${CURRENT_FLINK_FULL_VERSION}-bin-scala_2.12.tgz" + local apache_url="https://archive.apache.org/dist/flink/flink-${CURRENT_FLINK_FULL_VERSION}/flink-${CURRENT_FLINK_FULL_VERSION}-bin-scala_2.12.tgz" + + echo -e "${GREEN}Start downloading the Flink-${FLINK_VERSION_SCAN} installation package... Store it in the ${DINKY_TMP_DIR} directory${RESET}" + if download_file "$tsinghua_url" "$DINKY_TMP_DIR"; then + echo -e "${BLUE}The address of the currently downloaded Flink installation package is:${tsinghua_url}${RESET}" + return 0 + else + echo -e "${YELLOW}File not found in Tsinghua University mirror, try downloading from Apache official source...${RESET}" + if download_file "$apache_url" "$DINKY_TMP_DIR"; then + echo -e "${BLUE}The address of the currently downloaded Flink installation package is:${apache_url}${RESET}" + return 0 + else + echo -e "${RED}Downloading from Apache official source also failed, please check the network or download manually。${RESET}" + return 1 + fi + fi +} + +if ! try_tsinghua_mirror; then + exit 0 +fi + + +echo -e "${GREEN}Flink installation package download completed。${RESET}" +echo -e "\n${GREEN}===============================================================${RESET}\n" +echo -e "${GREEN}Start decompressing the Flink installation package...${RESET}" +tar -zxvf ${DINKY_TMP_DIR}/flink-${CURRENT_FLINK_FULL_VERSION}-bin-scala_2.12.tgz -C ${DINKY_TMP_DIR}/ +if [ $? -eq 0 ]; then + echo -e "${GREEN}Flink installation package decompression completed。${RESET}" +else + echo -e "${RED}Flink installation package failed to decompress, please check。${RESET}" + exit 1 +fi + +echo -e "\n${GREEN}===============================================================${RESET}\n" + +flink_dir_tmp=$(ls -n ${DINKY_TMP_DIR} | grep '^d' | grep flink | awk '{print $9}') +full_flink_dir_tmp="${DINKY_TMP_DIR}/${flink_dir_tmp}" +echo -e "${BLUE}Unzipped directory name:${full_flink_dir_tmp}${RESET}" + + + +echo -e "${GREEN}Process ${full_flink_dir_tmp}/lib/flink-table-planner-loader* file...${RESET}" +rm -rf ${full_flink_dir_tmp}/lib/flink-table-planner-loader* +echo -e "${GREEN}Processing completed。${RESET}" + +echo -e "${GREEN}Process ${full_flink_dir_tmp}/opt/flink-table-planner_2.12-*.jar file...${RESET}" +mv ${full_flink_dir_tmp}/opt/flink-table-planner_2.12-*.jar ${full_flink_dir_tmp}/lib/ +echo -e "${GREEN}Processing completed。${RESET}" + +echo -e "${GREEN}Process flink jar dependencies into dinky...${RESET}" +cp -r ${full_flink_dir_tmp}/lib/*.jar ${EXTENDS_HOME}/flink${FLINK_VERSION_SCAN}/ +echo -e "${GREEN}jar dependency processing completed。${RESET}" + +echo -e "${GREEN}Process flink-sql-client ...${RESET}" +cp -r ${full_flink_dir_tmp}/opt/flink-sql-client-*.jar ${EXTENDS_HOME}/flink${FLINK_VERSION_SCAN}/ +echo -e "${GREEN}Processing completed。${RESET}" + +echo -e "${GREEN}Process flink-cep-scala ...${RESET}" +cp -r ${full_flink_dir_tmp}/opt/flink-cep-scala*.jar ${EXTENDS_HOME}/flink${FLINK_VERSION_SCAN}/ +echo -e "${GREEN}Processing completed。${RESET}" + +echo -e "${GREEN}Process flink-queryable-state-runtime ...${RESET}" +cp -r ${full_flink_dir_tmp}/opt/flink-queryable-state-runtime*.jar ${EXTENDS_HOME}/flink${FLINK_VERSION_SCAN}/ +echo -e "${GREEN}Processing completed。${RESET}" + +echo -e "${GREEN}Process flink-state-processor-api ...${RESET}" +cp -r ${full_flink_dir_tmp}/opt/flink-state-processor-api*.jar ${EXTENDS_HOME}/flink${FLINK_VERSION_SCAN}/ +echo -e "${GREEN}Processing completed。${RESET}" + +echo -e "${GREEN} ================= List files in the ${EXTENDS_HOME}/flink${FLINK_VERSION_SCAN}/ directory ==============${RESET}" +ls -l ${EXTENDS_HOME}/flink${FLINK_VERSION_SCAN}/ + +echo -e "${YELLOW}Please check the above dependent files。${RESET}" + +echo -e "${GREEN}The basic dependency processing is completed, please perform subsequent operations according to the actual situation.${RESET}" \ No newline at end of file diff --git a/script/bin/init_hadoop_dependences.sh b/script/bin/init_hadoop_dependences.sh new file mode 100644 index 0000000000..e61526413c --- /dev/null +++ b/script/bin/init_hadoop_dependences.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +EXTENDS_HOME=$1 + + +echo -e "${GREEN}====================== Hadoop dependency initialization ======================${RESET}" + +read -p "Please select the Hadoop-uber version to download (enter 2 or 3):" hadoop_uber_version +hadoop_uber_version=$(echo "$hadoop_uber_version" | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]') + +case $hadoop_uber_version in + 2) + echo -e "${YELLOW}Start downloading Hadoop-uber 2 version package...${RESET}" + if [ -f "$EXTENDS_HOME/flink-shaded-hadoop-2-uber-2.8.3-10.0.jar" ]; then + echo -e "${YELLOW}The flink-shaded-hadoop-2-uber-2.8.3-10.0.jar file already exists and there is no need to download it again.${RESET}" + else + download_url="https://repo1.maven.org/maven2/org/apache/flink/flink-shaded-hadoop-2-uber/2.8.3-10.0/flink-shaded-hadoop-2-uber-2.8.3-10.0.jar" + download_file "$download_url" "$EXTENDS_HOME" + fi + ;; + 3) + if [ -f "$EXTENDS_HOME/flink-shaded-hadoop-3-uber-3.1.1.7.2.9.0-173-9.0.jar" ]; then + echo -e "${YELLOW}The flink-shaded-hadoop-3-uber-3.1.1.7.2.9.0-173-9.0.jar file already exists and there is no need to download it again.${RESET}" + else + echo -e "${YELLOW}Start downloading Hadoop-uber 3 version package...${RESET}" + download_url="https://repository.cloudera.com/artifactory/cloudera-repos/org/apache/flink/flink-shaded-hadoop-3-uber/3.1.1.7.2.9.0-173-9.0/flink-shaded-hadoop-3-uber-3.1.1.7.2.9.0-173-9.0.jar" + download_file "$download_url" "$EXTENDS_HOME" + fi + ;; + *) + echo -e "${RED}The entered version number is incorrect, please re-run the script to select the correct version.${RESET}" + ;; +esac + +echo -e "${GREEN}After the download is completed, subsequent installation and configuration operations can be performed as needed.${RESET}" \ No newline at end of file diff --git a/script/bin/init_tools_main.sh b/script/bin/init_tools_main.sh new file mode 100644 index 0000000000..dea59e73ac --- /dev/null +++ b/script/bin/init_tools_main.sh @@ -0,0 +1,238 @@ +#!/bin/bash + +export RED='\033[31m' +export GREEN='\033[32m' +export YELLOW='\033[33m' +export BLUE='\033[34m' +export MAGENTA='\033[35m' +export CYAN='\033[36m' +export RESET='\033[0m' + +echo -e "${GREEN}=====================================================================${RESET}" +echo -e "${GREEN}=====================================================================${RESET}" +echo -e "${GREEN}============ Welcome to the Dinky initialization script =============${RESET}" +echo -e "${GREEN}======================================================================${RESET}" +echo -e "${GREEN}======================================================================${RESET}" + +APP_HOME=${DINKY_HOME:-$(cd "$(dirname "$0")"; cd ..; pwd)} +export DINKY_HOME=${APP_HOME} + +sudo chmod +x "${APP_HOME}"/bin/init_*.sh + + + +EXTENDS_HOME="${APP_HOME}/extends" +if [ ! -d "${EXTENDS_HOME}" ]; then + echo -e "${RED} ${EXTENDS_HOME} Directory does not exist, please check${RESET}" + exit 1 +fi + +FLINK_VERSION_SCAN=$(ls -n "${EXTENDS_HOME}" | grep '^d' | grep flink | awk -F 'flink' '{print $2}') +if [ -z "${FLINK_VERSION_SCAN}" ]; then + echo -e "${RED}There is no Flink related version in ${EXTENDS_HOME} in the directory where Dinky is deployed. The initialization operation cannot be performed. Please check. ${RESET}" + exit 1 +fi + +DINKY_TMP_DIR="${APP_HOME}/tmp" +if [ ! -d "${DINKY_TMP_DIR}" ]; then + echo -e "${YELLOW}Create temporary directory ${DINKY_TMP_DIR}...${RESET}" + mkdir -p "${DINKY_TMP_DIR}" + echo -e "${GREEN}The temporary directory is created${RESET}" +fi + +# LIB +DINKY_LIB="${APP_HOME}/lib" +if [ ! -d "${DINKY_LIB}" ]; then + echo -e "${RED}${DINKY_LIB} Directory does not exist, please check. ${RESET}" + exit 1 +fi + +# 函数:检查命令是否存在,不存在则尝试安装 +check_command() { + local cmd="$1" + echo -e "${BLUE}Check if command: $cmd exists...${RESET}" + if ! command -v "$cmd" &> /dev/null; then + if [ "$cmd" == "yum" ]; then + echo -e "${YELLOW} Try using yum to install the missing command...${RESET}" + sudo yum install -y "$cmd" + elif [ "$cmd" == "apt-get" ]; then + echo -e "${YELLOW}Try using apt-get to install the missing command...${RESET}" + sudo apt-get install -y "$cmd" + else + echo -e "${RED} $cmd The command was not found. Please install it manually and then run this script.。${RESET}" + exit 1 + fi + fi + echo -e "${GREEN}========== Command $cmd check completed. OK, continue executing the script. ==========${RESET}" +} + +sh "${APP_HOME}/bin/init_check_network.sh" + +check_command "wget" + +echo -e "${GREEN}The pre-check is completed. Welcome to use the Dinky initialization script. The current Dinky root path is:${APP_HOME} ${RESET}" + +function download_file() { + source_url=$1 + target_file_dir=$2 + echo -e "${GREEN}Start downloading $source_url to $target_file_dir...${RESET}" + wget -P "${target_file_dir}" "${source_url}" + echo -e "${GREEN}Download completed. The downloaded file storage address is: $target_file_dir ${RESET}" +} + +export -f download_file + +echo +echo +echo -e "${GREEN} ====================== Data source driver initialization script -> Start ====================== ${RESET}" + +while true; do + echo -e "${BLUE} ========================= Please enter your database type ================================ ${RESET}" + echo -e "${BLUE} ======== (h2 comes with it by default and does not need to perform this step)=========== ${RESET}" + echo -e "${BLUE} ============================== Please select 1, 2, 3 ====================================== ${RESET}" + echo -e "${BLUE} ==================================== 1. mysql ============================================= ${RESET}" + echo -e "${BLUE} ==================================== 2. pgsql ========================================= ${RESET}" + echo -e "${BLUE} ================================ 3. Skip this step ========================================== ${RESET}" + echo -e "${BLUE} ================================ Enter number selection ================================== ${RESET}" + read -p "Please enter your database type:" db_type + case $db_type in + 1) + echo -e "${GREEN}Start downloading the mysql driver package...${RESET}" + if [ -f "${DINKY_LIB}/mysql-connector-j-8.4.0.jar" ]; then + echo -e "${GREEN}mysql The driver package already exists, no need to download it again. Skip this step。${RESET}" + else + download_file https://repo1.maven.org/maven2/com/mysql/mysql-connector-j/8.4.0/mysql-connector-j-8.4.0.jar "${DINKY_LIB}" + echo -e "${GREEN}Download is complete, please verify. The downloaded file storage address is: ${DINKY_LIB}/mysql-connector-j-8.4.0.jar${RESET}" + if [ -f "${DINKY_LIB}/mysql-connector-j-8.4.0.jar" ]; then + echo -e "${GREEN}mysql driver package downloaded successfully。${RESET}" + else + echo -e "${RED}Mysql driver package download failed, please check the network or download manually。${RESET}" + exit 1 + fi + echo -e "${GREEN}After the verification is completed, subsequent installation and configuration operations can be performed as needed.。${RESET}" + fi + break + ;; + 2) + echo -e "${GREEN}It seems that pgsql has been integrated by default, so there is no need to perform this step. Please perform subsequent installation and configuration operations as needed.${RESET}" + break + ;; + 3) + echo -e "${GREEN}Skip this step。${RESET}" + break + ;; + *) + echo -e "${RED}The entered database type is incorrect, please rerun the script to select the correct database type.${RESET}" + ;; + esac +done +echo -e "${GREEN} ====================== Data source driver initialization script -> end====================== ${RESET}" + +echo +echo + +echo -e "${GREEN} ====================== Flink depends on initialization script -> start ====================== ${RESET}" + +declare -A version_map +version_map["1.14"]="1.14.6" +version_map["1.15"]="1.15.4" +version_map["1.16"]="1.16.3" +version_map["1.17"]="1.17.2" +version_map["1.18"]="1.18.1" +version_map["1.19"]="1.19.1" +version_map["1.20"]="1.20.0" + +FLINK_VERSION_SCAN=$(ls -n "${EXTENDS_HOME}" | grep '^d' | grep flink | awk -F 'flink' '{print $2}') +if [ -z "${FLINK_VERSION_SCAN}" ]; then + echo -e "${RED}There is no Flink related version in ${EXTENDS_HOME} in the directory where Dinky is deployed. The initialization operation cannot be performed. Please check.${RESET}" + exit 1 +else + echo -e "${GREEN}The current Flink version number deployed by Dinky:${FLINK_VERSION_SCAN}${RESET}" +fi + +# 根据 Dinky 部署的Flink对应的版本号,获取对应的 Flink 版本 +CURRENT_FLINK_FULL_VERSION=${version_map[$FLINK_VERSION_SCAN]} + +echo -e "${GREEN}Obtain the version number corresponding to the deployed Flink (full version number) based on the scanned current Flink version number: flink-${CURRENT_FLINK_FULL_VERSION}${RESET}" + +# 步骤2:获取Dinky部署的Flink对应的版本号,然后下载Flink安装包 +while true; do + read -p "It is detected that the Flink version number deployed by Dinky is: ${FLINK_VERSION_SCAN}, and the Flink installation package version number that needs to be downloaded is: flink-${CURRENT_FLINK_FULL_VERSION}-bin-scala_2.12.tgz. Please choose whether to initialize Flink related dependencies?(yes/no/exit)" is_init_flink + is_init_flink=$(echo "$is_init_flink" | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]') + + case $is_init_flink in + yes | y ) + sh "${APP_HOME}"/bin/init_flink_dependences.sh "${CURRENT_FLINK_FULL_VERSION}" "${FLINK_VERSION_SCAN}" "${DINKY_TMP_DIR}" "${EXTENDS_HOME}" "${APP_HOME}" + break + ;; + no | n ) + echo -e "${GREEN}The Flink installation package download operation has been skipped. Please download manually${RESET}" + break + ;; + exit | e ) + echo -e "${GREEN}If you choose exit, the program will exit。${RESET}" + exit 0 + ;; + *) + echo -e "${RED}Invalid input, please re-enter yes/no/exit。${RESET}" + ;; + esac +done +echo -e "${GREEN} ====================== Flink depends on initialization script -> end ====================== ${RESET}" + +echo +echo + +echo -e "${GREEN} ====================== Hadoop dependency initialization script -> Start ====================== ${RESET}" + +while true; do + read -p "Is your deployment environment a Hadoop environment??(yes/no/exit)" is_hadoop + is_hadoop=$(echo "$is_hadoop" | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]') + case $is_hadoop in + yes | y ) + sh "${APP_HOME}/bin/init_hadoop_dependences.sh" "${EXTENDS_HOME}" + break + ;; + no | n ) + echo -e "${GREEN}Hadoop related operations skipped ${RESET}" + break + ;; + exit | e ) + echo -e "${GREEN}If you choose exit, the program will exit${RESET}" + exit 0 + ;; + *) + echo -e "${RED}Invalid input, please re-enter yes/no/exit。${RESET}" + ;; + esac +done +echo -e "${GREEN} ======================Hadoop dependency initialization script -> end ====================== ${RESET}" +echo + +echo -e "${GREEN} === After the environment initialization is completed, you can configure the application configuration file in Dinky's config directory to perform database-related configuration, or execute the initialization configuration file.。==== ${RESET}" +echo + +echo -e "${GREEN} ====================== Database configuration file initialization script -> Start ====================== ${RESET}" + +while true; do + read -p "Do you need to initialize the database configuration file??(yes/no):" is_init_db + is_init_db=$(echo "$is_init_db" | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]') + case $is_init_db in + yes | y ) + sh "${APP_HOME}/bin/init_db.sh" "${DINKY_HOME}" + break + ;; + no | n ) + echo -e "${GREEN}The database initialization operation has been skipped, please manually configure the database ${DINKY_HOME}/config/application.yml file and ${DINKY_HOME}/config/application-[mysql/pgsql].yml file。${RESET}" + break + ;; + exit | e ) + echo -e "${GREEN}The script has exited, please manually configure the database ${DINKY_HOME}/config/application.yml file and ${DINKY_HOME}/config/application-[mysql/pgsql].yml file。${RESET}" + exit 0 + ;; + *) + echo -e "${RED}Invalid input, please re-enter yes/no/exit。${RESET}" + ;; + esac +done +echo -e "${GREEN} ====================== Database configuration file initialization script -> End ====================== ${RESET}" \ No newline at end of file