From 06ae548d451f84a38f2df5c3ba684588706c8bf5 Mon Sep 17 00:00:00 2001 From: wforget <643348094@qq.com> Date: Fri, 1 Dec 2023 11:19:20 +0800 Subject: [PATCH] Support nacos discovery --- linkis-commons/linkis-module/pom.xml | 80 ++++++++++++++++++- .../linkis-engineconn-manager-server/pom.xml | 6 ++ linkis-dist/bin/checkEnv.sh | 6 +- linkis-dist/bin/install.sh | 54 +++++++++---- linkis-dist/deploy-config/linkis-env.sh | 7 ++ .../{ => eureka}/application-engineconn.yml | 0 .../conf/{ => eureka}/application-eureka.yml | 0 .../conf/{ => eureka}/application-linkis.yml | 0 .../conf/nacos/application-engineconn.yml | 38 +++++++++ .../package/conf/nacos/application-linkis.yml | 59 ++++++++++++++ linkis-dist/package/sbin/common.sh | 2 + linkis-dist/package/sbin/linkis-start-all.sh | 8 +- linkis-dist/package/sbin/linkis-stop-all.sh | 8 +- pom.xml | 6 ++ 14 files changed, 247 insertions(+), 27 deletions(-) rename linkis-dist/package/conf/{ => eureka}/application-engineconn.yml (100%) rename linkis-dist/package/conf/{ => eureka}/application-eureka.yml (100%) rename linkis-dist/package/conf/{ => eureka}/application-linkis.yml (100%) create mode 100644 linkis-dist/package/conf/nacos/application-engineconn.yml create mode 100644 linkis-dist/package/conf/nacos/application-linkis.yml diff --git a/linkis-commons/linkis-module/pom.xml b/linkis-commons/linkis-module/pom.xml index d4ffc38e2c..f92edb8216 100644 --- a/linkis-commons/linkis-module/pom.xml +++ b/linkis-commons/linkis-module/pom.xml @@ -64,10 +64,6 @@ - - org.springframework.cloud - spring-cloud-starter-netflix-eureka-client - org.springframework.boot @@ -277,4 +273,80 @@ + + + eureka + + true + + discovery + eureka + + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + + + nacos + + + discovery + nacos + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + org.springframework.boot + * + + + org.springframework.cloud + spring-cloud-commons + + + org.springframework.cloud + spring-cloud-context + + + org.springframework.boot + spring-boot-starter + + + com.fasterxml.jackson.core + jackson-core + + + com.fasterxml.jackson.core + jackson-databind + + + com.google.code.findbugs + jsr305 + + + org.yaml + snakeyaml + + + io.prometheus + simpleclient + + + com.google.guava + guava + + + + + + + diff --git a/linkis-computation-governance/linkis-engineconn-manager/linkis-engineconn-manager-server/pom.xml b/linkis-computation-governance/linkis-engineconn-manager/linkis-engineconn-manager-server/pom.xml index 41022d30da..99458c8afc 100644 --- a/linkis-computation-governance/linkis-engineconn-manager/linkis-engineconn-manager-server/pom.xml +++ b/linkis-computation-governance/linkis-engineconn-manager/linkis-engineconn-manager-server/pom.xml @@ -51,6 +51,12 @@ linkis-rpc ${project.version} provided + + + com.google.guava + guava + + diff --git a/linkis-dist/bin/checkEnv.sh b/linkis-dist/bin/checkEnv.sh index cca13ac301..aea783cd7d 100644 --- a/linkis-dist/bin/checkEnv.sh +++ b/linkis-dist/bin/checkEnv.sh @@ -203,8 +203,10 @@ echo -e "\n<-----End to check service status---->" # --- check Service Port echo -e "\n3. <-----Start to check service Port---->" -SERVER_PORT=$EUREKA_PORT -check_service_port +if [ "$DISCOVERY" == "EUREKA" ]; then + SERVER_PORT=$EUREKA_PORT + check_service_port +fi SERVER_PORT=$GATEWAY_PORT check_service_port diff --git a/linkis-dist/bin/install.sh b/linkis-dist/bin/install.sh index d6e50221d5..5db6b5224a 100644 --- a/linkis-dist/bin/install.sh +++ b/linkis-dist/bin/install.sh @@ -110,6 +110,14 @@ else isSuccess "cp ${LINKIS_PACKAGE} to $LINKIS_HOME" fi +if [ "$DISCOVERY" == "NACOS" ]; then + mv $LINKIS_HOME/conf/nacos/* $LINKIS_HOME/conf +else + mv $LINKIS_HOME/conf/eureka/* $LINKIS_HOME/conf +fi +rm -rf $LINKIS_HOME/conf/nacos +rm -rf $LINKIS_HOME/conf/eureka + cp ${LINKIS_CONFIG_PATH} $LINKIS_HOME/conf cp ${LINKIS_DB_CONFIG_PATH} $LINKIS_HOME/conf @@ -407,34 +415,50 @@ fi currentTime=`date +%Y%m%d%H%M%S` -##eureka -sed -i ${txt} "s#defaultZone:.*#defaultZone: $EUREKA_URL#g" $LINKIS_HOME/conf/application-eureka.yml -sed -i ${txt} "s#port:.*#port: $EUREKA_PORT#g" $LINKIS_HOME/conf/application-eureka.yml sed -i ${txt} "s#linkis.app.version:.*#linkis.app.version: $LINKIS_VERSION-$currentTime#g" $LINKIS_HOME/conf/application-eureka.yml - -##server application.yml -sed -i ${txt} "s#defaultZone:.*#defaultZone: $EUREKA_URL#g" $LINKIS_HOME/conf/application-linkis.yml sed -i ${txt} "s#linkis.app.version:.*#linkis.app.version: $LINKIS_VERSION-$currentTime#g" $LINKIS_HOME/conf/application-linkis.yml - -sed -i ${txt} "s#defaultZone:.*#defaultZone: $EUREKA_URL#g" $LINKIS_HOME/conf/application-engineconn.yml sed -i ${txt} "s#linkis.app.version:.*#linkis.app.version: $LINKIS_VERSION-$currentTime#g" $LINKIS_HOME/conf/application-engineconn.yml -if [ "$EUREKA_PREFER_IP" == "true" ]; then - sed -i ${txt} "s/# prefer-ip-address:/prefer-ip-address:/g" $LINKIS_HOME/conf/application-eureka.yml +sed -i ${txt} "s#DISCOVERY=.*#DISCOVERY=$DISCOVERY#g" $LINKIS_HOME/sbin/common.sh + +if [ "$DISCOVERY" == "EUREKA" ]; then + ##eureka + sed -i ${txt} "s#defaultZone:.*#defaultZone: $EUREKA_URL#g" $LINKIS_HOME/conf/application-eureka.yml + sed -i ${txt} "s#port:.*#port: $EUREKA_PORT#g" $LINKIS_HOME/conf/application-eureka.yml + sed -i ${txt} "s#linkis.app.version:.*#linkis.app.version: $LINKIS_VERSION-$currentTime#g" $LINKIS_HOME/conf/application-eureka.yml + + ##server application.yml + sed -i ${txt} "s#defaultZone:.*#defaultZone: $EUREKA_URL#g" $LINKIS_HOME/conf/application-linkis.yml - sed -i ${txt} "s/# prefer-ip-address:/prefer-ip-address:/g" $LINKIS_HOME/conf/application-linkis.yml - sed -i ${txt} "s/# instance-id:/instance-id:/g" $LINKIS_HOME/conf/application-linkis.yml + sed -i ${txt} "s#defaultZone:.*#defaultZone: $EUREKA_URL#g" $LINKIS_HOME/conf/application-engineconn.yml - sed -i ${txt} "s/# prefer-ip-address:/prefer-ip-address:/g" $LINKIS_HOME/conf/application-engineconn.yml - sed -i ${txt} "s/# instance-id:/instance-id:/g" $LINKIS_HOME/conf/application-linkis.yml + if [ "$EUREKA_PREFER_IP" == "true" ]; then + sed -i ${txt} "s/# prefer-ip-address:/prefer-ip-address:/g" $LINKIS_HOME/conf/application-eureka.yml + + sed -i ${txt} "s/# prefer-ip-address:/prefer-ip-address:/g" $LINKIS_HOME/conf/application-linkis.yml + sed -i ${txt} "s/# instance-id:/instance-id:/g" $LINKIS_HOME/conf/application-linkis.yml + + sed -i ${txt} "s/# prefer-ip-address:/prefer-ip-address:/g" $LINKIS_HOME/conf/application-engineconn.yml + sed -i ${txt} "s/# instance-id:/instance-id:/g" $LINKIS_HOME/conf/application-linkis.yml + + sed -i ${txt} "s#linkis.discovery.prefer-ip-address.*#linkis.discovery.prefer-ip-address=true#g" $common_conf + fi + export DISCOVERY_SERVER_ADDRES=$EUREKA_INSTALL_IP:$EUREKA_POR +fi + +if [ "$DISCOVERY" == "NACOS" ]; then + sed -i ${txt} "s#server-addr:.*#server-addr: $NACOS_SERVER_ADDR#g" $LINKIS_HOME/conf/application-linkis.yml + sed -i ${txt} "s#server-addr:.*#server-addr: $NACOS_SERVER_ADDR#g" $LINKIS_HOME/conf/application-engineconn.yml sed -i ${txt} "s#linkis.discovery.prefer-ip-address.*#linkis.discovery.prefer-ip-address=true#g" $common_conf + + export DISCOVERY_SERVER_ADDRES=$NACOS_SERVER_ADDR fi echo "update conf $common_conf" sed -i ${txt} "s#wds.linkis.server.version.*#wds.linkis.server.version=$LINKIS_SERVER_VERSION#g" $common_conf sed -i ${txt} "s#wds.linkis.gateway.url.*#wds.linkis.gateway.url=http://$GATEWAY_INSTALL_IP:$GATEWAY_PORT#g" $common_conf -sed -i ${txt} "s#linkis.discovery.server-address.*#linkis.discovery.server-address=http://$EUREKA_INSTALL_IP:$EUREKA_PORT#g" $common_conf +sed -i ${txt} "s#linkis.discovery.server-address.*#linkis.discovery.server-address=http://$DISCOVERY_SERVER_ADDRES#g" $common_conf if [[ 'postgresql' = "$dbType" ]];then sed -i ${txt} "s#wds.linkis.server.mybatis.datasource.url.*#wds.linkis.server.mybatis.datasource.url=jdbc:postgresql://${PG_HOST}:${PG_PORT}/${PG_DB}?currentSchema=${PG_SCHEMA}\&stringtype=unspecified#g" $common_conf sed -i ${txt} "s#wds.linkis.server.mybatis.datasource.username.*#wds.linkis.server.mybatis.datasource.username=$PG_USER#g" $common_conf diff --git a/linkis-dist/deploy-config/linkis-env.sh b/linkis-dist/deploy-config/linkis-env.sh index f37d0720a8..fed49826b5 100644 --- a/linkis-dist/deploy-config/linkis-env.sh +++ b/linkis-dist/deploy-config/linkis-env.sh @@ -111,6 +111,9 @@ SPARK_CONF_DIR=/appcom/config/spark-config # Linkis in a distributed manner and set the following microservice parameters # +### DISCOVERY +DISCOVERY=EUREKA + ### EUREKA install information ### You can access it in your browser at the address below:http://${EUREKA_INSTALL_IP}:${EUREKA_PORT} #EUREKA: Microservices Service Registration Discovery Center @@ -119,6 +122,10 @@ EUREKA_PORT=20303 export EUREKA_PREFER_IP=false #EUREKA_HEAP_SIZE="512M" +### NACOS install information +### NACOS +NACOS_SERVER_ADDR=127.0.0.1:8848 + ##linkis-mg-gateway #GATEWAY_INSTALL_IP=127.0.0.1 GATEWAY_PORT=9001 diff --git a/linkis-dist/package/conf/application-engineconn.yml b/linkis-dist/package/conf/eureka/application-engineconn.yml similarity index 100% rename from linkis-dist/package/conf/application-engineconn.yml rename to linkis-dist/package/conf/eureka/application-engineconn.yml diff --git a/linkis-dist/package/conf/application-eureka.yml b/linkis-dist/package/conf/eureka/application-eureka.yml similarity index 100% rename from linkis-dist/package/conf/application-eureka.yml rename to linkis-dist/package/conf/eureka/application-eureka.yml diff --git a/linkis-dist/package/conf/application-linkis.yml b/linkis-dist/package/conf/eureka/application-linkis.yml similarity index 100% rename from linkis-dist/package/conf/application-linkis.yml rename to linkis-dist/package/conf/eureka/application-linkis.yml diff --git a/linkis-dist/package/conf/nacos/application-engineconn.yml b/linkis-dist/package/conf/nacos/application-engineconn.yml new file mode 100644 index 0000000000..0cf4dd90b9 --- /dev/null +++ b/linkis-dist/package/conf/nacos/application-engineconn.yml @@ -0,0 +1,38 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +spring: + application: + name: linkis-cg-engineconn + servlet: + multipart: + max-file-size: 500MB + max-request-size: 500MB + file-size-threshold: 50MB + cloud: + nacos: + discovery: + server-addr: 127.0.0.1:8848 + metadata: + prometheus.path: ${prometheus.path:/api/rest_j/v1/actuator/prometheus} + linkis.app.version: ${linkis.app.version} + +management: + endpoints: + web: + exposure: + include: refresh,info,health,metrics + +logging: + config: classpath:log4j2.xml diff --git a/linkis-dist/package/conf/nacos/application-linkis.yml b/linkis-dist/package/conf/nacos/application-linkis.yml new file mode 100644 index 0000000000..07dc8adeb3 --- /dev/null +++ b/linkis-dist/package/conf/nacos/application-linkis.yml @@ -0,0 +1,59 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +nacos: + discovery: + server-addr: 127.0.0.1:8848 + metadata: + prometheus.path: ${prometheus.path:/api/rest_j/v1/actuator/prometheus} + linkis.app.version: ${linkis.app.version} + +management: + endpoints: + web: + exposure: + include: refresh,info,health,metrics + +logging: + config: classpath:log4j2.xml + +pagehelper: + helper-dialect: mysql + reasonable: true + support-methods-arguments: true + params: countSql + +spring: + servlet: + multipart: + max-file-size: 500MB + max-request-size: 500MB + file-size-threshold: 50MB +#ribbon: +# ReadTimeout: 10000 +# ConnectTimeout: 10000 + cloud: + nacos: + discovery: + server-addr: 127.0.0.1:8848 + metadata: + prometheus.path: ${prometheus.path:/api/rest_j/v1/actuator/prometheus} + linkis.app.version: ${linkis.app.version} + + +##disable kinif4j.production when you want to use apidoc during development +knife4j: + enable: true + production: true diff --git a/linkis-dist/package/sbin/common.sh b/linkis-dist/package/sbin/common.sh index 6a9acb207f..f3f0555933 100644 --- a/linkis-dist/package/sbin/common.sh +++ b/linkis-dist/package/sbin/common.sh @@ -27,6 +27,8 @@ NC='\033[0m' # No Color GREEN='\033[0;32m' #used as: echo -e "Apache ${RED}Linkis ${NC} Test \n" +export DISCOVERY=EUREKA + function isLocal(){ if [ "$1" == "127.0.0.1" ];then return 0 diff --git a/linkis-dist/package/sbin/linkis-start-all.sh b/linkis-dist/package/sbin/linkis-start-all.sh index c9bd380619..55c1ba684e 100644 --- a/linkis-dist/package/sbin/linkis-start-all.sh +++ b/linkis-dist/package/sbin/linkis-start-all.sh @@ -131,9 +131,11 @@ sleep 3 } #linkis-mg-eureka -export SERVER_NAME="mg-eureka" -SERVER_IP=$EUREKA_INSTALL_IP -checkServer +if [ "$DISCOVERY" == "EUREKA" ]; then + export SERVER_NAME="mg-eureka" + SERVER_IP=$EUREKA_INSTALL_IP + checkServer +fi #linkis-mg-gateway diff --git a/linkis-dist/package/sbin/linkis-stop-all.sh b/linkis-dist/package/sbin/linkis-stop-all.sh index a560075a95..4302cf7af1 100644 --- a/linkis-dist/package/sbin/linkis-stop-all.sh +++ b/linkis-dist/package/sbin/linkis-stop-all.sh @@ -103,8 +103,10 @@ SERVER_IP=$MANAGER_INSTALL_IP stopApp #linkis-mg-eureka -export SERVER_NAME="mg-eureka" -SERVER_IP=$EUREKA_INSTALL_IP -stopApp +if [ "$DISCOVERY" == "EUREKA" ]; then + export SERVER_NAME="mg-eureka" + SERVER_IP=$EUREKA_INSTALL_IP + stopApp +fi echo "stop-all shell script executed completely" diff --git a/pom.xml b/pom.xml index eec3219c1a..327a455a30 100644 --- a/pom.xml +++ b/pom.xml @@ -217,6 +217,7 @@ 2.3.12.RELEASE 2.2.9.RELEASE Hoxton.SR12 + 2.2.9.RELEASE UTF-8 @@ -1355,6 +1356,11 @@ + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + ${spring.cloud.nacos.version} +