Commit 07227940 by Yiming Liu

support eureka configuration with multiple envs

parent d57dd58a
...@@ -25,12 +25,6 @@ ...@@ -25,12 +25,6 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!-- end of apollo --> <!-- end of apollo -->
<!-- eureka -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<!-- end of eureka -->
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId> <artifactId>spring-cloud-starter-eureka-server</artifactId>
......
...@@ -7,53 +7,41 @@ ...@@ -7,53 +7,41 @@
<format>zip</format> <format>zip</format>
</formats> </formats>
<includeBaseDirectory>false</includeBaseDirectory> <includeBaseDirectory>false</includeBaseDirectory>
<moduleSets> <fileSets>
<moduleSet> <!--scripts -->
<useAllReactorProjects>true</useAllReactorProjects> <fileSet>
<directory>src/main/scripts</directory>
<outputDirectory>bin</outputDirectory>
<includes> <includes>
<include>*:apollo-buildtools:*</include> <include>*.sh</include>
<include>*:apollo-adminservice:*</include>
</includes> </includes>
<sources> <fileMode>0755</fileMode>
<includeModuleDirectory>false</includeModuleDirectory> <lineEnding>unix</lineEnding>
<fileSets> </fileSet>
<!--scripts --> <fileSet>
<fileSet> <directory>src/main/config</directory>
<directory>src/main/scripts</directory> <outputDirectory>config</outputDirectory>
<outputDirectory>bin</outputDirectory> <excludes>
<includes> <exclude>apollo-adminservice.conf</exclude>
<include>*.sh</include> </excludes>
</includes> <lineEnding>unix</lineEnding>
<fileMode>0755</fileMode> </fileSet>
<lineEnding>unix</lineEnding> <fileSet>
</fileSet> <directory>src/main/config</directory>
<fileSet> <outputDirectory>/</outputDirectory>
<directory>src/main/config</directory> <includes>
<outputDirectory>config</outputDirectory> <include>apollo-adminservice.conf</include>
<excludes> </includes>
<exclude>apollo-adminservice.conf</exclude> <lineEnding>unix</lineEnding>
</excludes> </fileSet>
<lineEnding>unix</lineEnding> <!--artifact -->
</fileSet> <fileSet>
<fileSet> <directory>target</directory>
<directory>src/main/config</directory> <outputDirectory>/</outputDirectory>
<outputDirectory>/</outputDirectory> <includes>
<includes> <include>${project.artifactId}-*.jar</include>
<include>apollo-adminservice.conf</include> </includes>
</includes> <fileMode>0755</fileMode>
<lineEnding>unix</lineEnding> </fileSet>
</fileSet> </fileSets>
<!--artifact -->
<fileSet>
<directory>target</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>${project.artifactId}-*.jar</include>
</includes>
<fileMode>0755</fileMode>
</fileSet>
</fileSets>
</sources>
</moduleSet>
</moduleSets>
</assembly> </assembly>
\ No newline at end of file
...@@ -5,4 +5,11 @@ eureka: ...@@ -5,4 +5,11 @@ eureka:
serviceUrl: serviceUrl:
defaultZone: http://${eureka.instance.hostname}:8080/eureka/ defaultZone: http://${eureka.instance.hostname}:8080/eureka/
healthcheck: healthcheck:
enabled: true enabled: true
\ No newline at end of file
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 @@ ...@@ -22,6 +22,12 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId> <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency> </dependency>
<!-- eureka -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<!-- end of eureka -->
<dependency> <dependency>
<groupId>mysql</groupId> <groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId> <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 @@ ...@@ -7,53 +7,41 @@
<format>zip</format> <format>zip</format>
</formats> </formats>
<includeBaseDirectory>false</includeBaseDirectory> <includeBaseDirectory>false</includeBaseDirectory>
<moduleSets> <fileSets>
<moduleSet> <!--scripts -->
<useAllReactorProjects>true</useAllReactorProjects> <fileSet>
<directory>src/main/scripts</directory>
<outputDirectory>bin</outputDirectory>
<includes> <includes>
<include>*:apollo-buildtools:*</include> <include>*.sh</include>
<include>*:apollo-configservice:*</include>
</includes> </includes>
<sources> <fileMode>0755</fileMode>
<includeModuleDirectory>false</includeModuleDirectory> <lineEnding>unix</lineEnding>
<fileSets> </fileSet>
<!--scripts --> <fileSet>
<fileSet> <directory>src/main/config</directory>
<directory>src/main/scripts</directory> <outputDirectory>config</outputDirectory>
<outputDirectory>bin</outputDirectory> <excludes>
<includes> <exclude>apollo-configservice.conf</exclude>
<include>*.sh</include> </excludes>
</includes> <lineEnding>unix</lineEnding>
<fileMode>0755</fileMode> </fileSet>
<lineEnding>unix</lineEnding> <fileSet>
</fileSet> <directory>src/main/config</directory>
<fileSet> <outputDirectory>/</outputDirectory>
<directory>src/main/config</directory> <includes>
<outputDirectory>config</outputDirectory> <include>apollo-configservice.conf</include>
<excludes> </includes>
<exclude>apollo-configservice.conf</exclude> <lineEnding>unix</lineEnding>
</excludes> </fileSet>
<lineEnding>unix</lineEnding> <!--artifact -->
</fileSet> <fileSet>
<fileSet> <directory>target</directory>
<directory>src/main/config</directory> <outputDirectory>/</outputDirectory>
<outputDirectory>/</outputDirectory> <includes>
<includes> <include>${project.artifactId}-*.jar</include>
<include>apollo-configservice.conf</include> </includes>
</includes> <fileMode>0755</fileMode>
<lineEnding>unix</lineEnding> </fileSet>
</fileSet> </fileSets>
<!--artifact -->
<fileSet>
<directory>target</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>${project.artifactId}-*.jar</include>
</includes>
<fileMode>0755</fileMode>
</fileSet>
</fileSets>
</sources>
</moduleSet>
</moduleSets>
</assembly> </assembly>
\ No newline at end of file
...@@ -6,4 +6,11 @@ eureka: ...@@ -6,4 +6,11 @@ eureka:
serviceUrl: serviceUrl:
defaultZone: http://${eureka.instance.hostname}:8080/eureka/ defaultZone: http://${eureka.instance.hostname}:8080/eureka/
healthcheck: healthcheck:
enabled: true enabled: true
\ No newline at end of file
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 @@ ...@@ -7,53 +7,41 @@
<format>zip</format> <format>zip</format>
</formats> </formats>
<includeBaseDirectory>false</includeBaseDirectory> <includeBaseDirectory>false</includeBaseDirectory>
<moduleSets> <fileSets>
<moduleSet> <!--scripts -->
<useAllReactorProjects>true</useAllReactorProjects> <fileSet>
<directory>src/main/scripts</directory>
<outputDirectory>bin</outputDirectory>
<includes> <includes>
<include>*:apollo-buildtools:*</include> <include>*.sh</include>
<include>*:apollo-portal:*</include>
</includes> </includes>
<sources> <fileMode>0755</fileMode>
<includeModuleDirectory>false</includeModuleDirectory> <lineEnding>unix</lineEnding>
<fileSets> </fileSet>
<!--scripts --> <fileSet>
<fileSet> <directory>src/main/config</directory>
<directory>src/main/scripts</directory> <outputDirectory>config</outputDirectory>
<outputDirectory>bin</outputDirectory> <excludes>
<includes> <exclude>apollo-portal.conf</exclude>
<include>*.sh</include> </excludes>
</includes> <lineEnding>unix</lineEnding>
<fileMode>0755</fileMode> </fileSet>
<lineEnding>unix</lineEnding> <fileSet>
</fileSet> <directory>src/main/config</directory>
<fileSet> <outputDirectory>/</outputDirectory>
<directory>src/main/config</directory> <includes>
<outputDirectory>config</outputDirectory> <include>apollo-portal.conf</include>
<excludes> </includes>
<exclude>apollo-portal.conf</exclude> <lineEnding>unix</lineEnding>
</excludes> </fileSet>
<lineEnding>unix</lineEnding> <!--artifact -->
</fileSet> <fileSet>
<fileSet> <directory>target</directory>
<directory>src/main/config</directory> <outputDirectory>/</outputDirectory>
<outputDirectory>/</outputDirectory> <includes>
<includes> <include>${project.artifactId}-*.jar</include>
<include>apollo-portal.conf</include> </includes>
</includes> <fileMode>0755</fileMode>
<lineEnding>unix</lineEnding> </fileSet>
</fileSet> </fileSets>
<!--artifact -->
<fileSet>
<directory>target</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>${project.artifactId}-*.jar</include>
</includes>
<fileMode>0755</fileMode>
</fileSet>
</fileSets>
</sources>
</moduleSet>
</moduleSets>
</assembly> </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