Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wrr-cat
apollo
提交
7ea0ac2a
apollo
项目概览
wrr-cat
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7ea0ac2a
编写于
4月 27, 2016
作者:
J
Jason Song
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #149 from yiming187/build_env
Support build parameters by env
上级
29b8f4c4
b908fd9b
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
147 addition
and
63 deletion
+147
-63
.gitignore
.gitignore
+1
-4
apollo-adminservice/src/main/resources/application.yml
apollo-adminservice/src/main/resources/application.yml
+3
-1
apollo-biz/pom.xml
apollo-biz/pom.xml
+8
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/datasource/TitanCondition.java
.../java/com/ctrip/apollo/biz/datasource/TitanCondition.java
+5
-1
apollo-biz/src/main/java/com/ctrip/apollo/biz/datasource/TitanSettings.java
...n/java/com/ctrip/apollo/biz/datasource/TitanSettings.java
+46
-13
apollo-biz/src/main/resources/application-ctrip.properties
apollo-biz/src/main/resources/application-ctrip.properties
+7
-0
apollo-biz/src/main/resources/application.properties
apollo-biz/src/main/resources/application.properties
+10
-0
apollo-client/src/main/java/com/ctrip/apollo/util/ConfigUtil.java
...lient/src/main/java/com/ctrip/apollo/util/ConfigUtil.java
+2
-25
apollo-configservice/src/main/resources/application.yml
apollo-configservice/src/main/resources/application.yml
+2
-0
apollo-core/src/main/java/com/ctrip/apollo/core/MetaDomainConsts.java
...src/main/java/com/ctrip/apollo/core/MetaDomainConsts.java
+24
-10
apollo-core/src/main/java/com/ctrip/apollo/core/enums/EnvUtils.java
...e/src/main/java/com/ctrip/apollo/core/enums/EnvUtils.java
+29
-0
apollo-core/src/main/resources/apollo-env.properties
apollo-core/src/main/resources/apollo-env.properties
+4
-5
apollo-core/src/test/java/com/ctrip/apollo/core/MetaDomainTest.java
...e/src/test/java/com/ctrip/apollo/core/MetaDomainTest.java
+1
-1
apollo-portal/src/main/resources/application.yml
apollo-portal/src/main/resources/application.yml
+3
-1
pom.xml
pom.xml
+2
-2
未找到文件。
.gitignore
浏览文件 @
7ea0ac2a
...
...
@@ -25,7 +25,4 @@ target
# git
*.orig
dev
fat
uat
prd
application-dev.properties
\ No newline at end of file
apollo-adminservice/src/main/resources/application.yml
浏览文件 @
7ea0ac2a
spring
:
application
:
name
:
apollo-adminservice
profiles
:
active
:
ctrip
server
:
port
:
${port:8090}
...
...
apollo-biz/pom.xml
浏览文件 @
7ea0ac2a
...
...
@@ -36,4 +36,12 @@
<scope>
test
</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>
src/main/resources
</directory>
<filtering>
true
</filtering>
</resource>
</resources>
</build>
</project>
apollo-biz/src/main/java/com/ctrip/apollo/biz/datasource/TitanCondition.java
浏览文件 @
7ea0ac2a
...
...
@@ -10,7 +10,11 @@ public class TitanCondition implements Condition {
@Override
public
boolean
matches
(
ConditionContext
context
,
AnnotatedTypeMetadata
metadata
)
{
if
(!
StringUtils
.
isEmpty
(
context
.
getEnvironment
().
getProperty
(
"titan.url"
)))
{
if
(!
StringUtils
.
isEmpty
(
context
.
getEnvironment
().
getProperty
(
"fat.titan.url"
)))
{
return
true
;
}
else
if
(!
StringUtils
.
isEmpty
(
context
.
getEnvironment
().
getProperty
(
"uat.titan.url"
)))
{
return
true
;
}
else
if
(!
StringUtils
.
isEmpty
(
context
.
getEnvironment
().
getProperty
(
"pro.titan.url"
)))
{
return
true
;
}
return
false
;
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/datasource/TitanSettings.java
浏览文件 @
7ea0ac2a
...
...
@@ -3,28 +3,61 @@ package com.ctrip.apollo.biz.datasource;
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
TitanSettings
{
@Value
(
"${titan.url:}"
)
private
String
t
itanUrl
;
@Value
(
"${
fat.
titan.url:}"
)
private
String
fatT
itanUrl
;
@Value
(
"${
titan.dbname
:}"
)
private
String
titanDbname
;
@Value
(
"${
uat.titan.url
:}"
)
private
String
uatTitanUrl
;
public
String
getTitanUrl
()
{
return
titanUrl
;
}
@Value
(
"${pro.titan.url:}"
)
private
String
proTitanUrl
;
@Value
(
"${fat.titan.dbname:}"
)
private
String
fatTitanDbname
;
public
void
setTitanUrl
(
String
titanUrl
)
{
this
.
titanUrl
=
titanUrl
;
@Value
(
"${uat.titan.dbname:}"
)
private
String
uatTitanDbname
;
@Value
(
"${pro.titan.dbname:}"
)
private
String
proTitanDbname
;
public
String
getTitanUrl
()
{
Env
env
=
EnvUtils
.
transformEnv
(
Foundation
.
server
().
getEnvType
());
switch
(
env
)
{
case
FAT:
case
FWS:
return
fatTitanUrl
;
case
UAT:
return
uatTitanUrl
;
case
TOOLS:
case
PRO:
return
proTitanUrl
;
default
:
return
""
;
}
}
public
String
getTitanDbname
()
{
return
titanDbname
;
Env
env
=
EnvUtils
.
transformEnv
(
Foundation
.
server
().
getEnvType
());
switch
(
env
)
{
case
FAT:
case
FWS:
return
fatTitanDbname
;
case
UAT:
return
uatTitanDbname
;
case
TOOLS:
case
PRO:
return
proTitanDbname
;
default
:
return
""
;
}
}
public
void
setTitanDbname
(
String
titanDbname
)
{
this
.
titanDbname
=
titanDbname
;
}
}
apollo-biz/src/main/resources/application-ctrip.properties
0 → 100644
浏览文件 @
7ea0ac2a
# Titan Datasource (Ctrip only)
fat.titan.url
=
${fat_titan_url}
fat.titan.dbname
=
${fat_titan_dbname}
uat.titan.url
=
${uat_titan_url}
uat.titan.dbname
=
${uat_titan_dbname}
pro.titan.url
=
${pro_titan_url}
pro.titan.dbname
=
${pro_titan_dbname}
apollo-biz/src/main/resources/application.properties
0 → 100644
浏览文件 @
7ea0ac2a
# DataSource
spring.datasource.testWhileIdle
=
true
spring.datasource.testOnBorrow
=
true
spring.datasource.validationQuery
=
SELECT 1
# Naming strategy
spring.jpa.hibernate.naming_strategy
=
org.hibernate.cfg.EJB3NamingStrategy
spring.jpa.hibernate.globally_quoted_identifiers
=
true
spring.jpa.properties.hibernate.globally_quoted_identifiers
=
true
spring.jpa.properties.hibernate.show_sql
=
true
apollo-client/src/main/java/com/ctrip/apollo/util/ConfigUtil.java
浏览文件 @
7ea0ac2a
package
com.ctrip.apollo.util
;
import
com.google.common.base.Preconditions
;
import
com.google.common.base.Strings
;
import
com.ctrip.apollo.core.ConfigConsts
;
import
com.ctrip.apollo.core.MetaDomainConsts
;
import
com.ctrip.apollo.core.enums.Env
;
import
com.ctrip.apollo.core.enums.EnvUtils
;
import
com.ctrip.framework.foundation.Foundation
;
import
org.unidal.lookup.annotation.Named
;
...
...
@@ -60,34 +60,11 @@ public class ConfigUtil {
* @throws IllegalStateException if env is set
*/
public
Env
getApolloEnv
()
{
Env
env
=
transformEnv
(
Foundation
.
server
().
getEnvType
());
Env
env
=
EnvUtils
.
transformEnv
(
Foundation
.
server
().
getEnvType
());
Preconditions
.
checkState
(
env
!=
null
,
"env is not set"
);
return
env
;
}
private
Env
transformEnv
(
String
envName
)
{
if
(
Strings
.
isNullOrEmpty
(
envName
))
{
return
null
;
}
switch
(
envName
.
toUpperCase
())
{
case
"LPT"
:
return
Env
.
LPT
;
case
"FAT"
:
case
"FWS"
:
return
Env
.
FAT
;
case
"UAT"
:
return
Env
.
UAT
;
case
"PRO"
:
return
Env
.
PRO
;
case
"DEV"
:
return
Env
.
DEV
;
case
"LOCAL"
:
return
Env
.
LOCAL
;
default
:
return
null
;
}
}
public
String
getMetaServerDomainName
()
{
return
MetaDomainConsts
.
getDomain
(
getApolloEnv
());
}
...
...
apollo-configservice/src/main/resources/application.yml
浏览文件 @
7ea0ac2a
spring
:
application
:
name
:
apollo-configservice
profiles
:
active
:
ctrip
server
:
port
:
${port:8080}
...
...
apollo-core/src/main/java/com/ctrip/apollo/core/MetaDomainConsts.java
浏览文件 @
7ea0ac2a
...
...
@@ -7,24 +7,38 @@ import java.util.Properties;
import
com.ctrip.apollo.core.enums.Env
;
import
com.ctrip.apollo.core.utils.ResourceUtils
;
/**
* The meta domain will load the meta server from System environment first, if not exist, will load
* from apollo-env.properties. If neither exists, will load the default meta url.
*
* Currently, apollo supports local/dev/fat/uat/lpt/pro environments.
*/
@SuppressWarnings
({
"rawtypes"
,
"unchecked"
})
public
class
MetaDomainConsts
{
private
static
Map
<
Env
,
String
>
domains
=
new
HashMap
<>();
private
static
Map
<
Env
,
Object
>
domains
=
new
HashMap
<>();
public
static
final
String
DEFAULT_META_URL
=
"http://localhost:8080"
;
static
{
Properties
prop
=
new
Properties
();
prop
=
ResourceUtils
.
readConfigFile
(
"apollo-env.properties"
,
prop
);
domains
.
put
(
Env
.
LOCAL
,
prop
.
getProperty
(
"local.meta"
,
"http://localhost:8080"
));
domains
.
put
(
Env
.
DEV
,
prop
.
getProperty
(
"dev.meta"
));
domains
.
put
(
Env
.
FAT
,
prop
.
getProperty
(
"fat.meta"
));
domains
.
put
(
Env
.
FWS
,
prop
.
getProperty
(
"fws.meta"
));
domains
.
put
(
Env
.
UAT
,
prop
.
getProperty
(
"uat.meta"
));
domains
.
put
(
Env
.
LPT
,
prop
.
getProperty
(
"lpt.meta"
));
domains
.
put
(
Env
.
TOOLS
,
prop
.
getProperty
(
"tools.meta"
));
domains
.
put
(
Env
.
PRO
,
prop
.
getProperty
(
"pro.meta"
));
Map
env
=
System
.
getProperties
();
domains
.
put
(
Env
.
LOCAL
,
env
.
getOrDefault
(
"local_meta"
,
prop
.
getProperty
(
"local.meta"
,
DEFAULT_META_URL
)));
domains
.
put
(
Env
.
DEV
,
env
.
getOrDefault
(
"dev_meta"
,
prop
.
getProperty
(
"dev.meta"
,
DEFAULT_META_URL
)));
domains
.
put
(
Env
.
FAT
,
env
.
getOrDefault
(
"fat_meta"
,
prop
.
getProperty
(
"fat.meta"
,
DEFAULT_META_URL
)));
domains
.
put
(
Env
.
UAT
,
env
.
getOrDefault
(
"uat_meta"
,
prop
.
getProperty
(
"uat.meta"
,
DEFAULT_META_URL
)));
domains
.
put
(
Env
.
LPT
,
env
.
getOrDefault
(
"lpt_meta"
,
prop
.
getProperty
(
"lpt.meta"
,
DEFAULT_META_URL
)));
domains
.
put
(
Env
.
PRO
,
env
.
getOrDefault
(
"pro_meta"
,
prop
.
getProperty
(
"pro.meta"
,
DEFAULT_META_URL
)));
}
public
static
String
getDomain
(
Env
env
)
{
return
domains
.
get
(
env
);
return
String
.
valueOf
(
domains
.
get
(
env
)
);
}
}
apollo-core/src/main/java/com/ctrip/apollo/core/enums/EnvUtils.java
0 → 100644
浏览文件 @
7ea0ac2a
package
com.ctrip.apollo.core.enums
;
import
com.ctrip.apollo.core.utils.StringUtils
;
public
final
class
EnvUtils
{
public
static
Env
transformEnv
(
String
envName
)
{
if
(
StringUtils
.
isBlank
(
envName
))
{
return
null
;
}
switch
(
envName
.
toUpperCase
())
{
case
"LPT"
:
return
Env
.
LPT
;
case
"FAT"
:
case
"FWS"
:
return
Env
.
FAT
;
case
"UAT"
:
return
Env
.
UAT
;
case
"PRO"
:
return
Env
.
PRO
;
case
"DEV"
:
return
Env
.
DEV
;
case
"LOCAL"
:
return
Env
.
LOCAL
;
default
:
return
null
;
}
}
}
apollo-core/src/main/resources/apollo-env.properties
浏览文件 @
7ea0ac2a
local.meta
=
http://localhost:8080
dev.meta
=
${dev}
fat.meta
=
${fat}
uat.meta
=
${uat}
lpt.meta
=
${lpt}
pro.meta
=
${pro}
dev.meta
=
${dev_meta}
fat.meta
=
${fat_meta}
uat.meta
=
${uat_meta}
pro.meta
=
${pro_meta}
apollo-core/src/test/java/com/ctrip/apollo/core/MetaDomainTest.java
浏览文件 @
7ea0ac2a
...
...
@@ -11,6 +11,6 @@ public class MetaDomainTest {
public
void
testGetMetaDomain
()
{
Assert
.
assertEquals
(
"http://localhost:8080"
,
MetaDomainConsts
.
getDomain
(
Env
.
LOCAL
));
Assert
.
assertEquals
(
"http://dev:8080"
,
MetaDomainConsts
.
getDomain
(
Env
.
DEV
));
Assert
.
assert
Null
(
MetaDomainConsts
.
getDomain
(
Env
.
PRO
));
Assert
.
assert
Equals
(
MetaDomainConsts
.
DEFAULT_META_URL
,
MetaDomainConsts
.
getDomain
(
Env
.
PRO
));
}
}
apollo-portal/src/main/resources/application.yml
浏览文件 @
7ea0ac2a
...
...
@@ -4,7 +4,9 @@ server:
spring
:
application
:
name
:
apollo-portal
profiles
:
active
:
ctrip
logging
:
level
:
org.springframework.cloud
:
'
DEBUG'
...
...
pom.xml
浏览文件 @
7ea0ac2a
...
...
@@ -124,12 +124,12 @@
<dependency>
<groupId>
com.ctrip.framework
</groupId>
<artifactId>
framework-foundation
</artifactId>
<version>
1.1.
4
</version>
<version>
1.1.
5
</version>
</dependency>
<dependency>
<groupId>
com.dianping.cat
</groupId>
<artifactId>
cat-client
</artifactId>
<version>
1.
4.6
</version>
<version>
1.
5.0
</version>
</dependency>
<dependency>
<groupId>
com.ctrip.platform
</groupId>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录