Skip to content

Commit

Permalink
Support nacos discovery (#5008)
Browse files Browse the repository at this point in the history
  • Loading branch information
wForget authored Dec 1, 2023
1 parent ba773ff commit 60aa1c9
Show file tree
Hide file tree
Showing 14 changed files with 247 additions and 27 deletions.
80 changes: 76 additions & 4 deletions linkis-commons/linkis-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -277,4 +273,80 @@
</plugins>
</build>

<profiles>
<profile>
<id>eureka</id>
<activation>
<activeByDefault>true</activeByDefault>
<property>
<name>discovery</name>
<value>eureka</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>nacos</id>
<activation>
<property>
<name>discovery</name>
<value>nacos</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-context</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</exclusion>
<exclusion>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
</exclusion>
<exclusion>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
<artifactId>linkis-rpc</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand Down
6 changes: 4 additions & 2 deletions linkis-dist/bin/checkEnv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 39 additions & 15 deletions linkis-dist/bin/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions linkis-dist/deploy-config/linkis-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
38 changes: 38 additions & 0 deletions linkis-dist/package/conf/nacos/application-engineconn.yml
Original file line number Diff line number Diff line change
@@ -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
59 changes: 59 additions & 0 deletions linkis-dist/package/conf/nacos/application-linkis.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions linkis-dist/package/sbin/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions linkis-dist/package/sbin/linkis-start-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions linkis-dist/package/sbin/linkis-stop-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@
<spring.boot.version>2.3.12.RELEASE</spring.boot.version>
<spring-netflix.version>2.2.9.RELEASE</spring-netflix.version>
<spring-cloud.version>Hoxton.SR12</spring-cloud.version>
<spring.cloud.nacos.version>2.2.9.RELEASE</spring.cloud.nacos.version>

<!-- platform encoding override -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -1355,6 +1356,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>${spring.cloud.nacos.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down

0 comments on commit 60aa1c9

Please sign in to comment.