Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wrr-cat
apollo
提交
fd110337
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,发现更多精彩内容 >>
提交
fd110337
编写于
3月 28, 2016
作者:
Y
Yiming Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Extract domain conf into files
上级
1d3cecb9
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
95 addition
and
85 deletion
+95
-85
apollo-client/src/main/java/com/ctrip/apollo/client/env/ClientEnvironment.java
...n/java/com/ctrip/apollo/client/env/ClientEnvironment.java
+2
-51
apollo-core/src/main/java/com/ctrip/apollo/core/MetaDomainConsts.java
...src/main/java/com/ctrip/apollo/core/MetaDomainConsts.java
+14
-34
apollo-core/src/main/java/com/ctrip/apollo/core/utils/ResourceUtils.java
.../main/java/com/ctrip/apollo/core/utils/ResourceUtils.java
+62
-0
apollo-core/src/main/resources/apollo-env.properties
apollo-core/src/main/resources/apollo-env.properties
+1
-0
apollo-core/src/test/java/com/ctrip/apollo/core/MetaDomainTest.java
...e/src/test/java/com/ctrip/apollo/core/MetaDomainTest.java
+15
-0
apollo-core/src/test/resources/apollo-env.properties
apollo-core/src/test/resources/apollo-env.properties
+1
-0
未找到文件。
apollo-client/src/main/java/com/ctrip/apollo/client/env/ClientEnvironment.java
浏览文件 @
fd110337
...
...
@@ -4,18 +4,12 @@ import com.ctrip.apollo.Apollo;
import
com.ctrip.apollo.Apollo.Env
;
import
com.ctrip.apollo.client.constants.Constants
;
import
com.ctrip.apollo.core.MetaDomainConsts
;
import
com.ctrip.apollo.core.utils.ResourceUtils
;
import
com.ctrip.apollo.core.utils.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.util.Enumeration
;
import
java.util.Properties
;
import
java.util.concurrent.atomic.AtomicReference
;
...
...
@@ -41,7 +35,7 @@ public class ClientEnvironment {
if
(
env
.
get
()
==
null
)
{
Env
resultEnv
=
Apollo
.
getEnv
();
Properties
apolloProperties
=
null
;
apolloProperties
=
readConfigFile
(
DEFAULT_FILE
,
null
);
apolloProperties
=
ResourceUtils
.
readConfigFile
(
DEFAULT_FILE
,
null
);
if
(
apolloProperties
!=
null
)
{
String
strEnv
=
apolloProperties
.
getProperty
(
Constants
.
ENV
);
if
(!
StringUtils
.
isBlank
(
strEnv
))
{
...
...
@@ -62,47 +56,4 @@ public class ClientEnvironment {
return
MetaDomainConsts
.
getDomain
(
getEnv
());
}
@SuppressWarnings
(
"unchecked"
)
private
Properties
readConfigFile
(
String
configPath
,
Properties
defaults
)
{
InputStream
in
=
this
.
getClass
().
getResourceAsStream
(
configPath
);
logger
.
info
(
"Reading config from resource {}"
,
configPath
);
Properties
props
=
new
Properties
();
try
{
if
(
in
==
null
)
{
// load outside resource under current user path
Path
path
=
new
File
(
System
.
getProperty
(
"user.dir"
)
+
configPath
).
toPath
();
if
(
Files
.
isReadable
(
path
))
{
in
=
new
FileInputStream
(
path
.
toFile
());
logger
.
info
(
"Reading config from file {} "
,
path
);
}
}
if
(
defaults
!=
null
)
{
props
.
putAll
(
defaults
);
}
if
(
in
!=
null
)
{
props
.
load
(
in
);
in
.
close
();
}
}
catch
(
Exception
ex
)
{
logger
.
warn
(
"Reading config failed: {}"
,
ex
.
getMessage
());
}
finally
{
if
(
in
!=
null
)
{
try
{
in
.
close
();
}
catch
(
IOException
ex
)
{
logger
.
warn
(
"Close config failed: {}"
,
ex
.
getMessage
());
}
}
}
StringBuilder
sb
=
new
StringBuilder
();
for
(
Enumeration
<
String
>
e
=
(
Enumeration
<
String
>)
props
.
propertyNames
();
e
.
hasMoreElements
();
)
{
String
key
=
e
.
nextElement
();
String
val
=
(
String
)
props
.
getProperty
(
key
);
sb
.
append
(
key
).
append
(
'='
).
append
(
val
).
append
(
'\n'
);
}
logger
.
info
(
"Reading properties: \n"
+
sb
.
toString
());
return
props
;
}
}
apollo-core/src/main/java/com/ctrip/apollo/core/MetaDomainConsts.java
浏览文件 @
fd110337
package
com.ctrip.apollo.core
;
import
com.ctrip.apollo.Apollo.Env
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Properties
;
public
class
MetaDomainConsts
{
public
static
final
String
DEFAULT_PORT
=
"8080"
;
public
static
final
String
LOCAL
=
"http://localhost"
+
":"
+
DEFAULT_PORT
;
public
static
final
String
DEV
=
"http://10.3.2.56"
+
":"
+
DEFAULT_PORT
;
public
static
final
String
FAT
=
"http://ws.meta.apollo.fx.fat.nt.ctripcorp.com"
+
":"
+
DEFAULT_PORT
;
public
static
final
String
FWS
=
"http://ws.meta.apollo.fx.fws.nt.ctripcorp.com"
+
":"
+
DEFAULT_PORT
;
public
static
final
String
UAT
=
"http://ws.meta.apollo.fx.uat.nt.ctripcorp.com"
+
":"
+
DEFAULT_PORT
;
public
static
final
String
LPT
=
"http://ws.meta.apollo.fx.lpt.nt.ctripcorp.com"
+
":"
+
DEFAULT_PORT
;
public
static
final
String
TOOLS
=
"http://ws.meta.apollo.fx.tools.ctripcorp.com"
+
":"
+
DEFAULT_PORT
;
import
com.ctrip.apollo.Apollo.Env
;
import
com.ctrip.apollo.core.utils.ResourceUtils
;
public
static
final
String
PRO
=
"http://ws.meta.apollo.fx.ctripcorp.com"
+
":"
+
DEFAULT_PORT
;
public
class
MetaDomainConsts
{
private
static
Map
<
Env
,
String
>
domains
=
new
HashMap
<>();
static
{
domains
.
put
(
Env
.
LOCAL
,
LOCAL
);
domains
.
put
(
Env
.
DEV
,
DEV
);
domains
.
put
(
Env
.
FAT
,
FAT
);
domains
.
put
(
Env
.
FWS
,
FWS
);
domains
.
put
(
Env
.
UAT
,
UAT
);
domains
.
put
(
Env
.
LPT
,
LPT
);
domains
.
put
(
Env
.
TOOLS
,
TOOLS
);
domains
.
put
(
Env
.
PRO
,
PRO
);
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"
));
}
public
static
String
getDomain
(
Env
env
)
{
...
...
apollo-core/src/main/java/com/ctrip/apollo/core/utils/ResourceUtils.java
0 → 100644
浏览文件 @
fd110337
package
com.ctrip.apollo.core.utils
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.util.Enumeration
;
import
java.util.Properties
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
public
class
ResourceUtils
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ResourceUtils
.
class
);
@SuppressWarnings
(
"unchecked"
)
public
static
Properties
readConfigFile
(
String
configPath
,
Properties
defaults
)
{
InputStream
in
=
ClassLoader
.
getSystemResourceAsStream
(
configPath
);
logger
.
info
(
"Reading config from resource {}"
,
configPath
);
Properties
props
=
new
Properties
();
try
{
if
(
in
==
null
)
{
// load outside resource under current user path
Path
path
=
new
File
(
System
.
getProperty
(
"user.dir"
)
+
configPath
).
toPath
();
if
(
Files
.
isReadable
(
path
))
{
in
=
new
FileInputStream
(
path
.
toFile
());
logger
.
info
(
"Reading config from file {} "
,
path
);
}
}
if
(
defaults
!=
null
)
{
props
.
putAll
(
defaults
);
}
if
(
in
!=
null
)
{
props
.
load
(
in
);
in
.
close
();
}
}
catch
(
Exception
ex
)
{
logger
.
warn
(
"Reading config failed: {}"
,
ex
.
getMessage
());
}
finally
{
if
(
in
!=
null
)
{
try
{
in
.
close
();
}
catch
(
IOException
ex
)
{
logger
.
warn
(
"Close config failed: {}"
,
ex
.
getMessage
());
}
}
}
StringBuilder
sb
=
new
StringBuilder
();
for
(
Enumeration
<
String
>
e
=
(
Enumeration
<
String
>)
props
.
propertyNames
();
e
.
hasMoreElements
();
)
{
String
key
=
e
.
nextElement
();
String
val
=
(
String
)
props
.
getProperty
(
key
);
sb
.
append
(
key
).
append
(
'='
).
append
(
val
).
append
(
'\n'
);
}
logger
.
info
(
"Reading properties: \n"
+
sb
.
toString
());
return
props
;
}
}
apollo-core/src/main/resources/apollo-env.properties
0 → 100644
浏览文件 @
fd110337
local.meta
=
http://localhost:8090
\ No newline at end of file
apollo-core/src/test/java/com/ctrip/apollo/core/MetaDomainTest.java
0 → 100644
浏览文件 @
fd110337
package
com.ctrip.apollo.core
;
import
org.junit.Test
;
import
org.springframework.util.Assert
;
import
com.ctrip.apollo.Apollo.Env
;
public
class
MetaDomainTest
{
@Test
public
void
testDefaultDomain
()
{
Assert
.
notNull
(
MetaDomainConsts
.
getDomain
(
Env
.
LOCAL
));
Assert
.
isNull
(
MetaDomainConsts
.
getDomain
(
Env
.
PRO
));
}
}
apollo-core/src/test/resources/apollo-env.properties
0 → 100644
浏览文件 @
fd110337
local.meta
=
http://localhost:8090
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录