Commit 07227940 by Yiming Liu

support eureka configuration with multiple envs

parent d57dd58a
......@@ -25,12 +25,6 @@
<scope>test</scope>
</dependency>
<!-- end of apollo -->
<!-- eureka -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<!-- end of eureka -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
......
......@@ -7,53 +7,41 @@
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<moduleSets>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<fileSets>
<!--scripts -->
<fileSet>
<directory>src/main/scripts</directory>
<outputDirectory>bin</outputDirectory>
<includes>
<include>*:apollo-buildtools:*</include>
<include>*:apollo-adminservice:*</include>
<include>*.sh</include>
</includes>
<sources>
<includeModuleDirectory>false</includeModuleDirectory>
<fileSets>
<!--scripts -->
<fileSet>
<directory>src/main/scripts</directory>
<outputDirectory>bin</outputDirectory>
<includes>
<include>*.sh</include>
</includes>
<fileMode>0755</fileMode>
<lineEnding>unix</lineEnding>
</fileSet>
<fileSet>
<directory>src/main/config</directory>
<outputDirectory>config</outputDirectory>
<excludes>
<exclude>apollo-adminservice.conf</exclude>
</excludes>
<lineEnding>unix</lineEnding>
</fileSet>
<fileSet>
<directory>src/main/config</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>apollo-adminservice.conf</include>
</includes>
<lineEnding>unix</lineEnding>
</fileSet>
<!--artifact -->
<fileSet>
<directory>target</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>${project.artifactId}-*.jar</include>
</includes>
<fileMode>0755</fileMode>
</fileSet>
</fileSets>
</sources>
</moduleSet>
</moduleSets>
<fileMode>0755</fileMode>
<lineEnding>unix</lineEnding>
</fileSet>
<fileSet>
<directory>src/main/config</directory>
<outputDirectory>config</outputDirectory>
<excludes>
<exclude>apollo-adminservice.conf</exclude>
</excludes>
<lineEnding>unix</lineEnding>
</fileSet>
<fileSet>
<directory>src/main/config</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>apollo-adminservice.conf</include>
</includes>
<lineEnding>unix</lineEnding>
</fileSet>
<!--artifact -->
<fileSet>
<directory>target</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>${project.artifactId}-*.jar</include>
</includes>
<fileMode>0755</fileMode>
</fileSet>
</fileSets>
</assembly>
\ No newline at end of file
......@@ -5,4 +5,11 @@ eureka:
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:8080/eureka/
healthcheck:
enabled: true
\ No newline at end of file
enabled: true
ctrip:
eureka:
dev: http://${ctrip_eureka_dev:localhost}:8080/eureka/
fat: http://${ctrip_eureka_fat:localhost}:8080/eureka/
uat: http://${ctrip_eureka_uat:localhost}:8080/eureka/
pro: http://${ctrip_eureka_pro:localhost}:8080/eureka/
\ No newline at end of file
......@@ -22,6 +22,12 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- eureka -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<!-- end of eureka -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
......
package com.ctrip.apollo.biz.eureka;
import java.util.Arrays;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.eureka.EurekaClientConfigBean;
import org.springframework.stereotype.Component;
@Component
public class CtripEurekaClientConfig extends EurekaClientConfigBean {
@Autowired
private CtripEurekaSettings eurekaSettings;
/**
* Assert only one zone: defaultZone, but multiple environments.
*/
public List<String> getEurekaServerServiceUrls(String myZone) {
String serviceUrls = eurekaSettings.getDefaultEurekaUrl(myZone);
if (serviceUrls != null) {
return Arrays.asList(serviceUrls.split(","));
}else{
return super.getEurekaServerServiceUrls(myZone);
}
}
}
package com.ctrip.apollo.biz.eureka;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import com.ctrip.apollo.core.enums.Env;
import com.ctrip.apollo.core.enums.EnvUtils;
import com.ctrip.framework.foundation.Foundation;
@Component
public class CtripEurekaSettings {
@Value("${ctrip.eureka.dev:localhost}")
private String devEureka;
@Value("${ctrip.eureka.fat:localhost}")
private String fatEureka;
@Value("${ctrip.eureka.uat:localhost}")
private String uatEureka;
@Value("${ctrip.eureka.pro:localhost}")
private String proEureka;
public String getDefaultEurekaUrl(String zone) {
Env env = EnvUtils.transformEnv(Foundation.server().getEnvType());
if (env == null) {
return null;
}
switch (env) {
case LOCAL:
return null;
case DEV:
return devEureka;
case FAT:
case FWS:
return fatEureka;
case UAT:
return uatEureka;
case TOOLS:
case PRO:
return proEureka;
default:
return null;
}
}
}
......@@ -7,53 +7,41 @@
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<moduleSets>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<fileSets>
<!--scripts -->
<fileSet>
<directory>src/main/scripts</directory>
<outputDirectory>bin</outputDirectory>
<includes>
<include>*:apollo-buildtools:*</include>
<include>*:apollo-configservice:*</include>
<include>*.sh</include>
</includes>
<sources>
<includeModuleDirectory>false</includeModuleDirectory>
<fileSets>
<!--scripts -->
<fileSet>
<directory>src/main/scripts</directory>
<outputDirectory>bin</outputDirectory>
<includes>
<include>*.sh</include>
</includes>
<fileMode>0755</fileMode>
<lineEnding>unix</lineEnding>
</fileSet>
<fileSet>
<directory>src/main/config</directory>
<outputDirectory>config</outputDirectory>
<excludes>
<exclude>apollo-configservice.conf</exclude>
</excludes>
<lineEnding>unix</lineEnding>
</fileSet>
<fileSet>
<directory>src/main/config</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>apollo-configservice.conf</include>
</includes>
<lineEnding>unix</lineEnding>
</fileSet>
<!--artifact -->
<fileSet>
<directory>target</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>${project.artifactId}-*.jar</include>
</includes>
<fileMode>0755</fileMode>
</fileSet>
</fileSets>
</sources>
</moduleSet>
</moduleSets>
<fileMode>0755</fileMode>
<lineEnding>unix</lineEnding>
</fileSet>
<fileSet>
<directory>src/main/config</directory>
<outputDirectory>config</outputDirectory>
<excludes>
<exclude>apollo-configservice.conf</exclude>
</excludes>
<lineEnding>unix</lineEnding>
</fileSet>
<fileSet>
<directory>src/main/config</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>apollo-configservice.conf</include>
</includes>
<lineEnding>unix</lineEnding>
</fileSet>
<!--artifact -->
<fileSet>
<directory>target</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>${project.artifactId}-*.jar</include>
</includes>
<fileMode>0755</fileMode>
</fileSet>
</fileSets>
</assembly>
\ No newline at end of file
......@@ -6,4 +6,11 @@ eureka:
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:8080/eureka/
healthcheck:
enabled: true
\ No newline at end of file
enabled: true
ctrip:
eureka:
dev: http://${ctrip_eureka_dev:localhost}:8080/eureka/
fat: http://${ctrip_eureka_fat:localhost}:8080/eureka/
uat: http://${ctrip_eureka_uat:localhost}:8080/eureka/
pro: http://${ctrip_eureka_pro:localhost}:8080/eureka/
\ No newline at end of file
......@@ -7,53 +7,41 @@
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<moduleSets>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<fileSets>
<!--scripts -->
<fileSet>
<directory>src/main/scripts</directory>
<outputDirectory>bin</outputDirectory>
<includes>
<include>*:apollo-buildtools:*</include>
<include>*:apollo-portal:*</include>
<include>*.sh</include>
</includes>
<sources>
<includeModuleDirectory>false</includeModuleDirectory>
<fileSets>
<!--scripts -->
<fileSet>
<directory>src/main/scripts</directory>
<outputDirectory>bin</outputDirectory>
<includes>
<include>*.sh</include>
</includes>
<fileMode>0755</fileMode>
<lineEnding>unix</lineEnding>
</fileSet>
<fileSet>
<directory>src/main/config</directory>
<outputDirectory>config</outputDirectory>
<excludes>
<exclude>apollo-portal.conf</exclude>
</excludes>
<lineEnding>unix</lineEnding>
</fileSet>
<fileSet>
<directory>src/main/config</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>apollo-portal.conf</include>
</includes>
<lineEnding>unix</lineEnding>
</fileSet>
<!--artifact -->
<fileSet>
<directory>target</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>${project.artifactId}-*.jar</include>
</includes>
<fileMode>0755</fileMode>
</fileSet>
</fileSets>
</sources>
</moduleSet>
</moduleSets>
<fileMode>0755</fileMode>
<lineEnding>unix</lineEnding>
</fileSet>
<fileSet>
<directory>src/main/config</directory>
<outputDirectory>config</outputDirectory>
<excludes>
<exclude>apollo-portal.conf</exclude>
</excludes>
<lineEnding>unix</lineEnding>
</fileSet>
<fileSet>
<directory>src/main/config</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>apollo-portal.conf</include>
</includes>
<lineEnding>unix</lineEnding>
</fileSet>
<!--artifact -->
<fileSet>
<directory>target</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>${project.artifactId}-*.jar</include>
</includes>
<fileMode>0755</fileMode>
</fileSet>
</fileSets>
</assembly>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment