Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apollo
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
apollo
Commits
dcdd4b0d
Commit
dcdd4b0d
authored
Mar 22, 2016
by
Jason Song
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use dto namespace instead of model and updated the demo page
parent
47478b47
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
93 additions
and
46 deletions
+93
-46
ConfigService.java
...main/java/com/ctrip/apollo/biz/service/ConfigService.java
+1
-1
ConfigServiceImpl.java
.../com/ctrip/apollo/biz/service/impl/ConfigServiceImpl.java
+1
-1
ConfigServiceImplTest.java
.../ctrip/apollo/biz/service/impl/ConfigServiceImplTest.java
+1
-1
ApolloConfigManager.java
...ain/java/com/ctrip/apollo/client/ApolloConfigManager.java
+20
-8
RemoteConfigLoader.java
...m/ctrip/apollo/client/loader/impl/RemoteConfigLoader.java
+9
-15
ApolloConfigManagerTest.java
...java/com/ctrip/apollo/client/ApolloConfigManagerTest.java
+13
-2
RemoteConfigLoaderTest.java
...rip/apollo/client/loader/impl/RemoteConfigLoaderTest.java
+1
-1
ConfigController.java
...trip/apollo/configserver/controller/ConfigController.java
+1
-1
ConfigControllerTest.java
.../apollo/configserver/controller/ConfigControllerTest.java
+1
-1
ApolloConfig.java
...src/main/java/com/ctrip/apollo/core/dto/ApolloConfig.java
+1
-1
DemoController.java
...java/com/ctrip/apollo/demo/controller/DemoController.java
+6
-7
app.js
apollo-demo/src/main/webapp/s/scripts/app.js
+11
-0
list.html
apollo-demo/src/main/webapp/s/templates/list.html
+27
-7
No files found.
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ConfigService.java
View file @
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
View file @
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
View file @
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
View file @
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
View file @
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
View file @
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
View file @
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
View file @
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
View file @
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
View file @
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
View file @
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
View file @
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
View file @
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>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment