Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
superrain51
apollo
提交
dcdd4b0d
apollo
项目概览
superrain51
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
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,发现更多精彩内容 >>
提交
dcdd4b0d
编写于
3月 22, 2016
作者:
J
Jason Song
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use dto namespace instead of model and updated the demo page
上级
47478b47
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
93 addition
and
46 deletion
+93
-46
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ConfigService.java
...main/java/com/ctrip/apollo/biz/service/ConfigService.java
+1
-1
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/impl/ConfigServiceImpl.java
.../com/ctrip/apollo/biz/service/impl/ConfigServiceImpl.java
+1
-1
apollo-biz/src/test/java/com/ctrip/apollo/biz/service/impl/ConfigServiceImplTest.java
.../ctrip/apollo/biz/service/impl/ConfigServiceImplTest.java
+1
-1
apollo-client/src/main/java/com/ctrip/apollo/client/ApolloConfigManager.java
...ain/java/com/ctrip/apollo/client/ApolloConfigManager.java
+20
-8
apollo-client/src/main/java/com/ctrip/apollo/client/loader/impl/RemoteConfigLoader.java
...m/ctrip/apollo/client/loader/impl/RemoteConfigLoader.java
+9
-15
apollo-client/src/test/java/com/ctrip/apollo/client/ApolloConfigManagerTest.java
...java/com/ctrip/apollo/client/ApolloConfigManagerTest.java
+13
-2
apollo-client/src/test/java/com/ctrip/apollo/client/loader/impl/RemoteConfigLoaderTest.java
...rip/apollo/client/loader/impl/RemoteConfigLoaderTest.java
+1
-1
apollo-configserver/src/main/java/com/ctrip/apollo/configserver/controller/ConfigController.java
...trip/apollo/configserver/controller/ConfigController.java
+1
-1
apollo-configserver/src/test/java/com/ctrip/apollo/configserver/controller/ConfigControllerTest.java
.../apollo/configserver/controller/ConfigControllerTest.java
+1
-1
apollo-core/src/main/java/com/ctrip/apollo/core/dto/ApolloConfig.java
...src/main/java/com/ctrip/apollo/core/dto/ApolloConfig.java
+1
-1
apollo-demo/src/main/java/com/ctrip/apollo/demo/controller/DemoController.java
...java/com/ctrip/apollo/demo/controller/DemoController.java
+6
-7
apollo-demo/src/main/webapp/s/scripts/app.js
apollo-demo/src/main/webapp/s/scripts/app.js
+11
-0
apollo-demo/src/main/webapp/s/templates/list.html
apollo-demo/src/main/webapp/s/templates/list.html
+27
-7
未找到文件。
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ConfigService.java
浏览文件 @
dcdd4b0d
package
com.ctrip.apollo.biz.service
;
import
com.ctrip.apollo.biz.entity.Version
;
import
com.ctrip.apollo.core.
model
.ApolloConfig
;
import
com.ctrip.apollo.core.
dto
.ApolloConfig
;
/**
* Config Service
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/impl/ConfigServiceImpl.java
浏览文件 @
dcdd4b0d
...
...
@@ -5,7 +5,7 @@ import com.ctrip.apollo.biz.entity.Version;
import
com.ctrip.apollo.biz.repository.ReleaseSnapShotRepository
;
import
com.ctrip.apollo.biz.repository.VersionRepository
;
import
com.ctrip.apollo.biz.service.ConfigService
;
import
com.ctrip.apollo.core.
model
.ApolloConfig
;
import
com.ctrip.apollo.core.
dto
.ApolloConfig
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.google.common.collect.Maps
;
...
...
apollo-biz/src/test/java/com/ctrip/apollo/biz/service/impl/ConfigServiceImplTest.java
浏览文件 @
dcdd4b0d
...
...
@@ -4,7 +4,7 @@ import com.ctrip.apollo.biz.entity.ReleaseSnapShot;
import
com.ctrip.apollo.biz.entity.Version
;
import
com.ctrip.apollo.biz.repository.ReleaseSnapShotRepository
;
import
com.ctrip.apollo.biz.repository.VersionRepository
;
import
com.ctrip.apollo.core.
model
.ApolloConfig
;
import
com.ctrip.apollo.core.
dto
.ApolloConfig
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.google.common.collect.Maps
;
...
...
apollo-client/src/main/java/com/ctrip/apollo/client/ApolloConfigManager.java
浏览文件 @
dcdd4b0d
...
...
@@ -19,6 +19,8 @@ import org.springframework.core.PriorityOrdered;
import
org.springframework.core.env.CompositePropertySource
;
import
org.springframework.core.env.MutablePropertySources
;
import
java.util.concurrent.atomic.AtomicReference
;
/**
* Client side config manager
*
...
...
@@ -26,12 +28,17 @@ import org.springframework.core.env.MutablePropertySources;
*/
public
class
ApolloConfigManager
implements
BeanDefinitionRegistryPostProcessor
,
PriorityOrdered
,
ApplicationContextAware
{
public
static
final
String
APOLLO_PROPERTY_SOURCE_NAME
=
"ApolloConfigProperties"
;
private
static
AtomicReference
<
ApolloConfigManager
>
singletonProtector
=
new
AtomicReference
<
ApolloConfigManager
>();
private
ConfigLoader
configLoader
;
private
ConfigurableApplicationContext
applicationContext
;
private
CompositePropertySource
currentPropertySource
;
public
ApolloConfigManager
()
{
if
(!
singletonProtector
.
compareAndSet
(
null
,
this
))
{
throw
new
IllegalStateException
(
"There should be only one ApolloConfigManager instance!"
);
}
this
.
configLoader
=
ConfigLoaderFactory
.
getInstance
().
getRemoteConfigLoader
();
}
...
...
@@ -53,7 +60,7 @@ public class ApolloConfigManager implements BeanDefinitionRegistryPostProcessor,
@Override
public
void
postProcessBeanDefinitionRegistry
(
BeanDefinitionRegistry
registry
)
throws
BeansException
{
registerDependentBeans
(
registry
);
prepar
ePropertySource
();
initializ
ePropertySource
();
}
/**
...
...
@@ -94,14 +101,19 @@ public class ApolloConfigManager implements BeanDefinitionRegistryPostProcessor,
* First try to load from remote
* If loading from remote failed, then fall back to local cached properties
*/
void
preparePropertySource
()
{
void
initializePropertySource
()
{
currentPropertySource
=
loadPropertySource
();
MutablePropertySources
currentPropertySources
=
applicationContext
.
getEnvironment
().
getPropertySources
();
if
(
currentPropertySources
.
contains
(
APOLLO_PROPERTY_SOURCE_NAME
))
{
currentPropertySources
.
remove
(
APOLLO_PROPERTY_SOURCE_NAME
);
if
(
currentPropertySources
.
contains
(
currentPropertySource
.
getName
()
))
{
currentPropertySources
.
remove
(
currentPropertySource
.
getName
()
);
}
currentPropertySources
.
addFirst
(
currentPropertySource
);
}
CompositePropertySource
composite
=
new
CompositePropertySource
(
APOLLO_PROPERTY_SOURCE_NAME
);
composite
.
addPropertySource
(
configLoader
.
loadPropertySource
());
currentPropertySources
.
addFirst
(
composite
);
CompositePropertySource
loadPropertySource
()
{
CompositePropertySource
compositePropertySource
=
new
CompositePropertySource
(
APOLLO_PROPERTY_SOURCE_NAME
);
compositePropertySource
.
addPropertySource
(
configLoader
.
loadPropertySource
());
return
compositePropertySource
;
}
}
apollo-client/src/main/java/com/ctrip/apollo/client/loader/impl/RemoteConfigLoader.java
浏览文件 @
dcdd4b0d
package
com.ctrip.apollo.client.loader.impl
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.concurrent.Callable
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.Future
;
import
java.util.concurrent.ThreadFactory
;
import
java.util.concurrent.atomic.AtomicLong
;
import
com.ctrip.apollo.client.loader.ConfigLoader
;
import
com.ctrip.apollo.client.model.ApolloRegistry
;
import
com.ctrip.apollo.client.util.ConfigUtil
;
import
com.ctrip.apollo.core.dto.ApolloConfig
;
import
com.google.common.collect.Lists
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.core.env.CompositePropertySource
;
...
...
@@ -21,11 +16,10 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.client.RestTemplate
;
import
com.ctrip.apollo.client.loader.ConfigLoader
;
import
com.ctrip.apollo.client.model.ApolloRegistry
;
import
com.ctrip.apollo.client.util.ConfigUtil
;
import
com.ctrip.apollo.core.model.ApolloConfig
;
import
com.google.common.collect.Lists
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.concurrent.*
;
import
java.util.concurrent.atomic.AtomicLong
;
/**
* Load config from remote config server
...
...
apollo-client/src/test/java/com/ctrip/apollo/client/ApolloConfigManagerTest.java
浏览文件 @
dcdd4b0d
package
com.ctrip.apollo.client
;
import
com.ctrip.apollo.client.loader.ConfigLoader
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.ArgumentCaptor
;
...
...
@@ -16,6 +18,8 @@ import org.springframework.core.env.ConfigurableEnvironment;
import
org.springframework.core.env.MutablePropertySources
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
java.util.concurrent.atomic.AtomicReference
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
Mockito
.*;
...
...
@@ -48,6 +52,13 @@ public class ApolloConfigManagerTest {
ReflectionTestUtils
.
setField
(
apolloConfigManager
,
"configLoader"
,
configLoader
);
}
@After
public
void
tearDown
()
throws
Exception
{
AtomicReference
<
ApolloConfigManager
>
singletonProtector
=
(
AtomicReference
<
ApolloConfigManager
>)
ReflectionTestUtils
.
getField
(
ApolloConfigManager
.
class
,
"singletonProtector"
);
singletonProtector
.
set
(
null
);
}
@Test
(
expected
=
RuntimeException
.
class
)
public
void
testInvalidApplicationContext
()
{
ApplicationContext
someInvalidApplication
=
mock
(
ApplicationContext
.
class
);
...
...
@@ -61,7 +72,7 @@ public class ApolloConfigManagerTest {
when
(
configLoader
.
loadPropertySource
()).
thenReturn
(
somePropertySource
);
apolloConfigManager
.
prepar
ePropertySource
();
apolloConfigManager
.
initializ
ePropertySource
();
verify
(
configLoader
,
times
(
1
)).
loadPropertySource
();
verify
(
mutablePropertySources
,
times
(
1
)).
addFirst
(
captor
.
capture
());
...
...
@@ -74,7 +85,7 @@ public class ApolloConfigManagerTest {
@Test
public
void
testPostProcessBeanDefinitionRegistry
()
{
doNothing
().
when
(
apolloConfigManager
).
prepar
ePropertySource
();
doNothing
().
when
(
apolloConfigManager
).
initializ
ePropertySource
();
apolloConfigManager
.
postProcessBeanDefinitionRegistry
(
beanDefinitionRegistry
);
...
...
apollo-client/src/test/java/com/ctrip/apollo/client/loader/impl/RemoteConfigLoaderTest.java
浏览文件 @
dcdd4b0d
...
...
@@ -2,7 +2,7 @@ package com.ctrip.apollo.client.loader.impl;
import
com.ctrip.apollo.client.model.ApolloRegistry
;
import
com.ctrip.apollo.client.util.ConfigUtil
;
import
com.ctrip.apollo.core.
model
.ApolloConfig
;
import
com.ctrip.apollo.core.
dto
.ApolloConfig
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
org.junit.Before
;
...
...
apollo-configserver/src/main/java/com/ctrip/apollo/configserver/controller/ConfigController.java
浏览文件 @
dcdd4b0d
...
...
@@ -2,7 +2,7 @@ package com.ctrip.apollo.configserver.controller;
import
com.ctrip.apollo.biz.entity.Version
;
import
com.ctrip.apollo.biz.service.ConfigService
;
import
com.ctrip.apollo.core.
model
.ApolloConfig
;
import
com.ctrip.apollo.core.
dto
.ApolloConfig
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
...
...
apollo-configserver/src/test/java/com/ctrip/apollo/configserver/controller/ConfigControllerTest.java
浏览文件 @
dcdd4b0d
...
...
@@ -2,7 +2,7 @@ package com.ctrip.apollo.configserver.controller;
import
com.ctrip.apollo.biz.entity.Version
;
import
com.ctrip.apollo.biz.service.ConfigService
;
import
com.ctrip.apollo.core.
model
.ApolloConfig
;
import
com.ctrip.apollo.core.
dto
.ApolloConfig
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
...
...
apollo-core/src/main/java/com/ctrip/apollo/core/
model
/ApolloConfig.java
→
apollo-core/src/main/java/com/ctrip/apollo/core/
dto
/ApolloConfig.java
浏览文件 @
dcdd4b0d
package
com.ctrip.apollo.core.
model
;
package
com.ctrip.apollo.core.
dto
;
import
com.fasterxml.jackson.annotation.JsonCreator
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
...
...
apollo-demo/src/main/java/com/ctrip/apollo/demo/controller/DemoController.java
浏览文件 @
dcdd4b0d
...
...
@@ -35,13 +35,12 @@ public class DemoController {
@RequestMapping
(
value
=
"/config/{configName:.*}"
,
method
=
RequestMethod
.
GET
)
public
Config
queryConfig
(
@PathVariable
String
configName
)
{
String
value
;
if
(
configName
.
equals
(
"foo"
))
{
value
=
demoService
.
getFoo
();
}
else
{
value
=
env
.
getProperty
(
configName
,
"undefined"
);
}
return
new
Config
(
configName
,
value
);
return
new
Config
(
configName
,
env
.
getProperty
(
configName
,
"undefined"
));
}
@RequestMapping
(
value
=
"/injected/config"
,
method
=
RequestMethod
.
GET
)
public
Config
queryInjectedConfig
()
{
return
new
Config
(
"apollo.foo"
,
demoService
.
getFoo
());
}
@RequestMapping
(
value
=
"/client/registries"
,
method
=
RequestMethod
.
GET
)
...
...
apollo-demo/src/main/webapp/s/scripts/app.js
浏览文件 @
dcdd4b0d
...
...
@@ -12,6 +12,7 @@
this
.
registries
=
{};
this
.
configQuery
=
{};
//this.refreshResult = NONE;
this
.
injectedConfigValue
=
''
;
var
self
=
this
;
...
...
@@ -35,6 +36,16 @@
});
};
this
.
queryInjectedConfig
=
function
()
{
$http
.
get
(
"
demo/injected/config
"
)
.
success
(
function
(
data
)
{
self
.
injectedConfigValue
=
data
.
value
;
})
.
error
(
function
(
data
,
status
)
{
toastr
.
error
((
data
&&
data
.
msg
)
||
'
Load injected config failed
'
);
});
};
//this.refreshConfig = function() {
// $http.post("refresh")
// .success(function(data) {
...
...
apollo-demo/src/main/webapp/s/templates/list.html
浏览文件 @
dcdd4b0d
...
...
@@ -14,14 +14,15 @@
<tr
ng-repeat=
"item in demoCtrl.registries"
>
<td>
{{item.appId}}
</td>
<td>
{{item.version}}
</td>
</tr
.
>
</tr>
</tbody>
</table>
</div>
<div
id=
"load-config-wrapper"
>
<h3>
Load Config:
</h3>
<form
name=
"loadConfigForm"
class=
"form-horizontal"
novalidate
ng-submit=
"demoCtrl.queryConfig()"
>
<form
name=
"loadConfigForm"
class=
"form-horizontal"
novalidate
ng-submit=
"demoCtrl.queryConfig()"
>
<div
class=
"form-group"
ng-class=
"{ 'has-error' : loadConfigForm.configName.$invalid && loadConfigForm.configName.$dirty}"
>
<div
id=
"input-config-wrapper"
class=
"clearfix"
>
...
...
@@ -50,12 +51,31 @@
</form>
</div>
<div>
<h3>
Load Injected Config:
</h3>
<form
name=
"loadInjectedConfigForm"
class=
"form-horizontal"
novalidate
ng-submit=
"demoCtrl.queryInjectedConfig()"
>
<div
class=
"form-group"
>
<div
class=
"clearfix"
>
<label
class=
"col-sm-2 control-label"
>
apollo.foo
</label>
<div
class=
"col-sm-3"
>
<input
type=
"text"
name=
"injectedConfigValue"
class=
"form-control"
ng-model=
"demoCtrl.injectedConfigValue"
readonly
/>
</div>
<input
type=
"submit"
class=
"btn btn-primary col-sm-1"
value=
"query"
/>
</div>
</div>
</form>
</div>
<!--<div id="refresh-config-wrapper">-->
<!--<h3>Refresh Config:</h3>-->
<!--<button type="button" class="btn btn-primary" ng-click="demoCtrl.refreshConfig()">Refresh Config</button>-->
<!--<div id="refresh-result">-->
<!--<strong>Changed Properties:</strong> {{demoCtrl.refreshResult}}-->
<!--</div>-->
<!--<h3>Refresh Config:</h3>-->
<!--<button type="button" class="btn btn-primary" ng-click="demoCtrl.refreshConfig()">Refresh Config</button>-->
<!--<div id="refresh-result">-->
<!--<strong>Changed Properties:</strong> {{demoCtrl.refreshResult}}-->
<!--</div>-->
<!--</div>-->
</div>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录