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
5efb7c4e
Commit
5efb7c4e
authored
Mar 29, 2016
by
Jason Song
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor
parent
7692e147
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
151 additions
and
192 deletions
+151
-192
.gitignore
.gitignore
+1
-0
ConfigController.java
...trip/apollo/adminservice/controller/ConfigController.java
+6
-5
VersionController.java
...rip/apollo/adminservice/controller/VersionController.java
+4
-7
AdminConfigService.java
...java/com/ctrip/apollo/biz/service/AdminConfigService.java
+43
-13
AdminReleaseService.java
...ava/com/ctrip/apollo/biz/service/AdminReleaseService.java
+8
-48
ConfigService.java
...main/java/com/ctrip/apollo/biz/service/ConfigService.java
+64
-4
ConfigServiceImpl.java
.../com/ctrip/apollo/biz/service/impl/ConfigServiceImpl.java
+0
-79
AllTests.java
apollo-biz/src/test/java/com/ctrip/apollo/biz/AllTests.java
+2
-2
ConfigServiceTest.java
.../java/com/ctrip/apollo/biz/service/ConfigServiceTest.java
+5
-4
ApolloConfigManager.java
...ain/java/com/ctrip/apollo/client/ApolloConfigManager.java
+0
-1
ConfigUtil.java
...rc/main/java/com/ctrip/apollo/client/util/ConfigUtil.java
+10
-15
RemoteConfigLoaderTest.java
...rip/apollo/client/loader/impl/RemoteConfigLoaderTest.java
+1
-1
ConfigUtilTest.java
...est/java/com/ctrip/apollo/client/util/ConfigUtilTest.java
+3
-7
ConfigController.java
...rip/apollo/configservice/controller/ConfigController.java
+2
-2
ClassLoaderUtil.java
...ain/java/com/ctrip/apollo/core/utils/ClassLoaderUtil.java
+1
-1
ResourceUtils.java
.../main/java/com/ctrip/apollo/core/utils/ResourceUtils.java
+1
-1
apollo-env.properties
apollo-core/src/main/resources/apollo-env.properties
+0
-2
No files found.
.gitignore
View file @
5efb7c4e
...
@@ -28,3 +28,4 @@ dev
...
@@ -28,3 +28,4 @@ dev
fat
fat
uat
uat
prd
prd
apollo-env.properties
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ConfigController.java
View file @
5efb7c4e
package
com
.
ctrip
.
apollo
.
adminservice
.
controller
;
package
com
.
ctrip
.
apollo
.
adminservice
.
controller
;
import
com.ctrip.apollo.biz.service.AdminConfigService
;
import
com.ctrip.apollo.biz.service.AdminConfigService
;
import
com.ctrip.apollo.biz.service.AdminReleaseService
;
import
com.ctrip.apollo.core.dto.ConfigItemDTO
;
import
com.ctrip.apollo.core.dto.ConfigItemDTO
;
import
com.ctrip.apollo.core.dto.ReleaseSnapshotDTO
;
import
com.ctrip.apollo.core.dto.ReleaseSnapshotDTO
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RequestParam
;
...
@@ -11,19 +13,18 @@ import org.springframework.web.bind.annotation.RestController;
...
@@ -11,19 +13,18 @@ import org.springframework.web.bind.annotation.RestController;
import
java.util.List
;
import
java.util.List
;
import
javax.annotation.Resource
;
@RestController
@RestController
@RequestMapping
(
"/configs"
)
@RequestMapping
(
"/configs"
)
public
class
ConfigController
{
public
class
ConfigController
{
@
Resource
(
name
=
"adminConfigService"
)
@
Autowired
private
AdminConfigService
adminConfigService
;
private
AdminConfigService
adminConfigService
;
@Autowired
private
AdminReleaseService
adminReleaseService
;
@RequestMapping
(
"/release/{releaseId}"
)
@RequestMapping
(
"/release/{releaseId}"
)
public
List
<
ReleaseSnapshotDTO
>
getRelaseSnapshot
(
@PathVariable
long
releaseId
)
{
public
List
<
ReleaseSnapshotDTO
>
getRelaseSnapshot
(
@PathVariable
long
releaseId
)
{
return
admin
Config
Service
.
findReleaseSnapshotByReleaseId
(
releaseId
);
return
admin
Release
Service
.
findReleaseSnapshotByReleaseId
(
releaseId
);
}
}
@RequestMapping
(
"/latest"
)
@RequestMapping
(
"/latest"
)
...
...
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/VersionController.java
View file @
5efb7c4e
package
com
.
ctrip
.
apollo
.
adminservice
.
controller
;
package
com
.
ctrip
.
apollo
.
adminservice
.
controller
;
import
com.ctrip.apollo.biz.service.Admin
Config
Service
;
import
com.ctrip.apollo.biz.service.Admin
Release
Service
;
import
com.ctrip.apollo.core.dto.VersionDTO
;
import
com.ctrip.apollo.core.dto.VersionDTO
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -15,18 +15,15 @@ import java.util.List;
...
@@ -15,18 +15,15 @@ import java.util.List;
public
class
VersionController
{
public
class
VersionController
{
@Autowired
@Autowired
private
Admin
ConfigService
adminConfig
Service
;
private
Admin
ReleaseService
adminRelease
Service
;
@RequestMapping
(
"/app/{appId}"
)
@RequestMapping
(
"/app/{appId}"
)
public
List
<
VersionDTO
>
versions
(
@PathVariable
String
appId
)
{
public
List
<
VersionDTO
>
versions
(
@PathVariable
String
appId
)
{
return
adminReleaseService
.
findVersionsByApp
(
appId
);
return
adminConfigService
.
findVersionsByApp
(
appId
);
}
}
@RequestMapping
(
"/{versionId}"
)
@RequestMapping
(
"/{versionId}"
)
public
VersionDTO
version
(
@PathVariable
long
versionId
)
{
public
VersionDTO
version
(
@PathVariable
long
versionId
)
{
return
admin
Config
Service
.
loadVersionById
(
versionId
);
return
admin
Release
Service
.
loadVersionById
(
versionId
);
}
}
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/AdminConfigService.java
View file @
5efb7c4e
package
com
.
ctrip
.
apollo
.
biz
.
service
;
package
com
.
ctrip
.
apollo
.
biz
.
service
;
import
com.google.common.base.Strings
;
import
com.ctrip.apollo.biz.entity.Cluster
;
import
com.ctrip.apollo.biz.entity.ConfigItem
;
import
com.ctrip.apollo.biz.repository.ClusterRepository
;
import
com.ctrip.apollo.biz.repository.ConfigItemRepository
;
import
com.ctrip.apollo.biz.utils.ApolloBeanUtils
;
import
com.ctrip.apollo.core.dto.ClusterDTO
;
import
com.ctrip.apollo.core.dto.ClusterDTO
;
import
com.ctrip.apollo.core.dto.ConfigItemDTO
;
import
com.ctrip.apollo.core.dto.ConfigItemDTO
;
import
com.ctrip.apollo.core.dto.ReleaseSnapshotDTO
;
import
com.ctrip.apollo.core.dto.VersionDTO
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.List
;
/**
/**
* config service for admin
* config service for admin
*/
*/
public
interface
AdminConfigService
{
@Service
(
"adminConfigService"
)
public
class
AdminConfigService
{
List
<
ReleaseSnapshotDTO
>
findReleaseSnapshotByReleaseId
(
long
releaseId
);
@Autowired
List
<
VersionDTO
>
findVersionsByApp
(
String
appId
);
private
ClusterRepository
clusterRepository
;
@Autowired
VersionDTO
loadVersionById
(
long
versionId
);
private
ConfigItemRepository
configItemRepository
;
List
<
ClusterDTO
>
findClustersByApp
(
String
appId
);
public
List
<
ClusterDTO
>
findClustersByApp
(
String
appId
)
{
List
<
ConfigItemDTO
>
findConfigItemsByClusters
(
List
<
Long
>
clusterIds
);
if
(
Strings
.
isNullOrEmpty
(
appId
))
{
return
Collections
.
EMPTY_LIST
;
}
List
<
Cluster
>
clusters
=
clusterRepository
.
findByAppId
(
appId
);
if
(
clusters
==
null
||
clusters
.
size
()
==
0
)
{
return
Collections
.
EMPTY_LIST
;
}
return
ApolloBeanUtils
.
batchTransform
(
ClusterDTO
.
class
,
clusters
);
}
public
List
<
ConfigItemDTO
>
findConfigItemsByClusters
(
List
<
Long
>
clusterIds
)
{
if
(
clusterIds
==
null
||
clusterIds
.
size
()
==
0
)
{
return
Collections
.
EMPTY_LIST
;
}
List
<
ConfigItem
>
configItems
=
configItemRepository
.
findByClusterIdIsIn
(
clusterIds
);
if
(
configItems
==
null
||
configItems
.
size
()
==
0
)
{
return
Collections
.
EMPTY_LIST
;
}
return
ApolloBeanUtils
.
batchTransform
(
ConfigItemDTO
.
class
,
configItems
);
}
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/
impl/AdminConfigServiceImpl
.java
→
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/
AdminReleaseService
.java
View file @
5efb7c4e
package
com
.
ctrip
.
apollo
.
biz
.
service
.
impl
;
package
com
.
ctrip
.
apollo
.
biz
.
service
;
import
com.google.common.base.Strings
;
import
com.google.common.base.Strings
;
import
com.ctrip.apollo.biz.entity.Cluster
;
import
com.ctrip.apollo.biz.entity.ConfigItem
;
import
com.ctrip.apollo.biz.entity.ReleaseSnapshot
;
import
com.ctrip.apollo.biz.entity.ReleaseSnapshot
;
import
com.ctrip.apollo.biz.entity.Version
;
import
com.ctrip.apollo.biz.entity.Version
;
import
com.ctrip.apollo.biz.repository.ClusterRepository
;
import
com.ctrip.apollo.biz.repository.ConfigItemRepository
;
import
com.ctrip.apollo.biz.repository.ReleaseSnapShotRepository
;
import
com.ctrip.apollo.biz.repository.ReleaseSnapShotRepository
;
import
com.ctrip.apollo.biz.repository.VersionRepository
;
import
com.ctrip.apollo.biz.repository.VersionRepository
;
import
com.ctrip.apollo.biz.service.AdminConfigService
;
import
com.ctrip.apollo.biz.utils.ApolloBeanUtils
;
import
com.ctrip.apollo.biz.utils.ApolloBeanUtils
;
import
com.ctrip.apollo.core.dto.ClusterDTO
;
import
com.ctrip.apollo.core.dto.ConfigItemDTO
;
import
com.ctrip.apollo.core.dto.ReleaseSnapshotDTO
;
import
com.ctrip.apollo.core.dto.ReleaseSnapshotDTO
;
import
com.ctrip.apollo.core.dto.VersionDTO
;
import
com.ctrip.apollo.core.dto.VersionDTO
;
...
@@ -23,19 +16,16 @@ import org.springframework.stereotype.Service;
...
@@ -23,19 +16,16 @@ import org.springframework.stereotype.Service;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.List
;
@Service
(
"adminConfigService"
)
/**
public
class
AdminConfigServiceImpl
implements
AdminConfigService
{
* @author Jason Song(song_s@ctrip.com)
*/
@Autowired
@Service
(
"adminReleaseService"
)
private
VersionRepository
versionRepository
;
public
class
AdminReleaseService
{
@Autowired
@Autowired
private
ReleaseSnapShotRepository
releaseSnapShotRepository
;
private
ReleaseSnapShotRepository
releaseSnapShotRepository
;
@Autowired
@Autowired
private
ClusterRepository
clusterRepository
;
private
VersionRepository
versionRepository
;
@Autowired
private
ConfigItemRepository
configItemRepository
;
@Override
public
List
<
ReleaseSnapshotDTO
>
findReleaseSnapshotByReleaseId
(
long
releaseId
)
{
public
List
<
ReleaseSnapshotDTO
>
findReleaseSnapshotByReleaseId
(
long
releaseId
)
{
if
(
releaseId
<=
0
)
{
if
(
releaseId
<=
0
)
{
return
Collections
.
EMPTY_LIST
;
return
Collections
.
EMPTY_LIST
;
...
@@ -50,8 +40,6 @@ public class AdminConfigServiceImpl implements AdminConfigService {
...
@@ -50,8 +40,6 @@ public class AdminConfigServiceImpl implements AdminConfigService {
return
ApolloBeanUtils
.
batchTransform
(
ReleaseSnapshotDTO
.
class
,
releaseSnapShots
);
return
ApolloBeanUtils
.
batchTransform
(
ReleaseSnapshotDTO
.
class
,
releaseSnapShots
);
}
}
@Override
public
List
<
VersionDTO
>
findVersionsByApp
(
String
appId
)
{
public
List
<
VersionDTO
>
findVersionsByApp
(
String
appId
)
{
if
(
Strings
.
isNullOrEmpty
(
appId
))
{
if
(
Strings
.
isNullOrEmpty
(
appId
))
{
return
Collections
.
EMPTY_LIST
;
return
Collections
.
EMPTY_LIST
;
...
@@ -65,43 +53,15 @@ public class AdminConfigServiceImpl implements AdminConfigService {
...
@@ -65,43 +53,15 @@ public class AdminConfigServiceImpl implements AdminConfigService {
return
ApolloBeanUtils
.
batchTransform
(
VersionDTO
.
class
,
versions
);
return
ApolloBeanUtils
.
batchTransform
(
VersionDTO
.
class
,
versions
);
}
}
@Override
public
VersionDTO
loadVersionById
(
long
versionId
)
{
public
VersionDTO
loadVersionById
(
long
versionId
)
{
if
(
versionId
<=
0
)
{
if
(
versionId
<=
0
)
{
return
null
;
return
null
;
}
}
Version
version
=
versionRepository
.
findById
(
versionId
);
Version
version
=
versionRepository
.
findById
(
versionId
);
if
(
version
==
null
){
if
(
version
==
null
)
{
return
null
;
return
null
;
}
}
VersionDTO
dto
=
ApolloBeanUtils
.
transfrom
(
VersionDTO
.
class
,
version
);
VersionDTO
dto
=
ApolloBeanUtils
.
transfrom
(
VersionDTO
.
class
,
version
);
return
dto
;
return
dto
;
}
}
@Override
public
List
<
ClusterDTO
>
findClustersByApp
(
String
appId
)
{
if
(
Strings
.
isNullOrEmpty
(
appId
))
{
return
Collections
.
EMPTY_LIST
;
}
List
<
Cluster
>
clusters
=
clusterRepository
.
findByAppId
(
appId
);
if
(
clusters
==
null
||
clusters
.
size
()
==
0
)
{
return
Collections
.
EMPTY_LIST
;
}
return
ApolloBeanUtils
.
batchTransform
(
ClusterDTO
.
class
,
clusters
);
}
@Override
public
List
<
ConfigItemDTO
>
findConfigItemsByClusters
(
List
<
Long
>
clusterIds
)
{
if
(
clusterIds
==
null
||
clusterIds
.
size
()
==
0
)
{
return
Collections
.
EMPTY_LIST
;
}
List
<
ConfigItem
>
configItems
=
configItemRepository
.
findByClusterIdIsIn
(
clusterIds
);
if
(
configItems
==
null
||
configItems
.
size
()
==
0
)
{
return
Collections
.
EMPTY_LIST
;
}
return
ApolloBeanUtils
.
batchTransform
(
ConfigItemDTO
.
class
,
configItems
);
}
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ConfigService.java
View file @
5efb7c4e
package
com
.
ctrip
.
apollo
.
biz
.
service
;
package
com
.
ctrip
.
apollo
.
biz
.
service
;
import
com.google.common.collect.Maps
;
import
com.ctrip.apollo.biz.entity.ReleaseSnapshot
;
import
com.ctrip.apollo.biz.entity.Version
;
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.dto.ApolloConfig
;
import
com.ctrip.apollo.core.dto.ApolloConfig
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.io.IOException
;
import
java.util.Map
;
/**
/**
* Config Service
* Config Service
*
*
* @author Jason Song(song_s@ctrip.com)
* @author Jason Song(song_s@ctrip.com)
*/
*/
public
interface
ConfigService
{
@Service
(
"configService"
)
public
class
ConfigService
{
@Autowired
private
VersionRepository
versionRepository
;
@Autowired
private
ReleaseSnapShotRepository
releaseSnapShotRepository
;
@Autowired
private
ObjectMapper
objectMapper
;
private
TypeReference
<
Map
<
String
,
Object
>>
configurationTypeReference
=
new
TypeReference
<
Map
<
String
,
Object
>>()
{
};
/**
/**
* Load configuration from database
* Load configuration from database
*/
*/
ApolloConfig
loadConfig
(
String
appId
,
String
clusterName
,
String
versionName
);
public
ApolloConfig
loadConfig
(
String
appId
,
String
clusterName
,
String
versionName
)
{
Version
version
=
loadVersionByAppIdAndVersionName
(
appId
,
versionName
);
if
(
version
==
null
)
{
return
null
;
}
return
loadConfigByVersionAndClusterName
(
version
,
clusterName
);
}
/**
/**
* Load Version by appId and versionName from database
* Load Version by appId and versionName from database
*/
*/
Version
loadVersionByAppIdAndVersionName
(
String
appId
,
String
versionName
);
public
Version
loadVersionByAppIdAndVersionName
(
String
appId
,
String
versionName
)
{
return
versionRepository
.
findByAppIdAndName
(
appId
,
versionName
);
}
/**
/**
* Load Config by version and clusterName from database
* Load Config by version and clusterName from database
*/
*/
ApolloConfig
loadConfigByVersionAndClusterName
(
Version
version
,
String
clusterName
);
public
ApolloConfig
loadConfigByVersionAndClusterName
(
Version
version
,
String
clusterName
)
{
ReleaseSnapshot
releaseSnapShot
=
releaseSnapShotRepository
.
findByReleaseIdAndClusterName
(
version
.
getReleaseId
(),
clusterName
);
if
(
releaseSnapShot
==
null
)
{
return
null
;
}
return
assembleConfig
(
version
,
releaseSnapShot
);
}
private
ApolloConfig
assembleConfig
(
Version
version
,
ReleaseSnapshot
releaseSnapShot
)
{
ApolloConfig
config
=
new
ApolloConfig
(
version
.
getAppId
(),
releaseSnapShot
.
getClusterName
(),
version
.
getName
(),
version
.
getReleaseId
());
config
.
setConfigurations
(
transformConfigurationToMap
(
releaseSnapShot
.
getConfigurations
()));
return
config
;
}
Map
<
String
,
Object
>
transformConfigurationToMap
(
String
configurations
)
{
try
{
return
objectMapper
.
readValue
(
configurations
,
configurationTypeReference
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
return
Maps
.
newHashMap
();
}
}
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/impl/ConfigServiceImpl.java
deleted
100644 → 0
View file @
7692e147
package
com
.
ctrip
.
apollo
.
biz
.
service
.
impl
;
import
com.google.common.collect.Maps
;
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.biz.service.ConfigService
;
import
com.ctrip.apollo.core.dto.ApolloConfig
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.io.IOException
;
import
java.util.Map
;
/**
* @author Jason Song(song_s@ctrip.com)
*/
@Service
(
"configService"
)
public
class
ConfigServiceImpl
implements
ConfigService
{
@Autowired
private
VersionRepository
versionRepository
;
@Autowired
private
ReleaseSnapShotRepository
releaseSnapShotRepository
;
@Autowired
private
ObjectMapper
objectMapper
;
private
TypeReference
<
Map
<
String
,
Object
>>
configurationTypeReference
=
new
TypeReference
<
Map
<
String
,
Object
>>()
{
};
@Override
public
ApolloConfig
loadConfig
(
String
appId
,
String
clusterName
,
String
versionName
)
{
Version
version
=
loadVersionByAppIdAndVersionName
(
appId
,
versionName
);
if
(
version
==
null
)
{
return
null
;
}
return
loadConfigByVersionAndClusterName
(
version
,
clusterName
);
}
@Override
public
Version
loadVersionByAppIdAndVersionName
(
String
appId
,
String
versionName
)
{
return
versionRepository
.
findByAppIdAndName
(
appId
,
versionName
);
}
@Override
public
ApolloConfig
loadConfigByVersionAndClusterName
(
Version
version
,
String
clusterName
)
{
ReleaseSnapshot
releaseSnapShot
=
releaseSnapShotRepository
.
findByReleaseIdAndClusterName
(
version
.
getReleaseId
(),
clusterName
);
if
(
releaseSnapShot
==
null
)
{
return
null
;
}
return
assembleConfig
(
version
,
releaseSnapShot
);
}
private
ApolloConfig
assembleConfig
(
Version
version
,
ReleaseSnapshot
releaseSnapShot
)
{
ApolloConfig
config
=
new
ApolloConfig
(
version
.
getAppId
(),
releaseSnapShot
.
getClusterName
(),
version
.
getName
(),
version
.
getReleaseId
());
config
.
setConfigurations
(
transformConfigurationToMap
(
releaseSnapShot
.
getConfigurations
()));
return
config
;
}
Map
<
String
,
Object
>
transformConfigurationToMap
(
String
configurations
)
{
try
{
return
objectMapper
.
readValue
(
configurations
,
configurationTypeReference
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
return
Maps
.
newHashMap
();
}
}
}
apollo-biz/src/test/java/com/ctrip/apollo/biz/AllTests.java
View file @
5efb7c4e
package
com
.
ctrip
.
apollo
.
biz
;
package
com
.
ctrip
.
apollo
.
biz
;
import
com.ctrip.apollo.biz.service.
impl.ConfigServiceImpl
Test
;
import
com.ctrip.apollo.biz.service.
ConfigService
Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.Suite
;
import
org.junit.runners.Suite
;
...
@@ -8,7 +8,7 @@ import org.junit.runners.Suite.SuiteClasses;
...
@@ -8,7 +8,7 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith
(
Suite
.
class
)
@RunWith
(
Suite
.
class
)
@SuiteClasses
({
@SuiteClasses
({
ConfigService
Impl
Test
.
class
})
ConfigServiceTest
.
class
})
public
class
AllTests
{
public
class
AllTests
{
}
}
apollo-biz/src/test/java/com/ctrip/apollo/biz/service/
impl/ConfigServiceImpl
Test.java
→
apollo-biz/src/test/java/com/ctrip/apollo/biz/service/
ConfigService
Test.java
View file @
5efb7c4e
package
com
.
ctrip
.
apollo
.
biz
.
service
.
impl
;
package
com
.
ctrip
.
apollo
.
biz
.
service
;
import
com.google.common.collect.Maps
;
import
com.google.common.collect.Maps
;
...
@@ -6,6 +6,7 @@ import com.ctrip.apollo.biz.entity.ReleaseSnapshot;
...
@@ -6,6 +6,7 @@ import com.ctrip.apollo.biz.entity.ReleaseSnapshot;
import
com.ctrip.apollo.biz.entity.Version
;
import
com.ctrip.apollo.biz.entity.Version
;
import
com.ctrip.apollo.biz.repository.ReleaseSnapShotRepository
;
import
com.ctrip.apollo.biz.repository.ReleaseSnapShotRepository
;
import
com.ctrip.apollo.biz.repository.VersionRepository
;
import
com.ctrip.apollo.biz.repository.VersionRepository
;
import
com.ctrip.apollo.biz.service.ConfigService
;
import
com.ctrip.apollo.core.dto.ApolloConfig
;
import
com.ctrip.apollo.core.dto.ApolloConfig
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
...
@@ -33,18 +34,18 @@ import static org.mockito.Mockito.when;
...
@@ -33,18 +34,18 @@ import static org.mockito.Mockito.when;
* @author Jason Song(song_s@ctrip.com)
* @author Jason Song(song_s@ctrip.com)
*/
*/
@RunWith
(
MockitoJUnitRunner
.
class
)
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
ConfigService
Impl
Test
{
public
class
ConfigServiceTest
{
@Mock
@Mock
private
VersionRepository
versionRepository
;
private
VersionRepository
versionRepository
;
@Mock
@Mock
private
ReleaseSnapShotRepository
releaseSnapShotRepository
;
private
ReleaseSnapShotRepository
releaseSnapShotRepository
;
@Mock
@Mock
private
ObjectMapper
objectMapper
;
private
ObjectMapper
objectMapper
;
private
ConfigService
Impl
configService
;
private
ConfigService
configService
;
@Before
@Before
public
void
setUp
()
throws
Exception
{
public
void
setUp
()
throws
Exception
{
configService
=
new
ConfigService
Impl
();
configService
=
new
ConfigService
();
ReflectionTestUtils
.
setField
(
configService
,
"versionRepository"
,
versionRepository
);
ReflectionTestUtils
.
setField
(
configService
,
"versionRepository"
,
versionRepository
);
ReflectionTestUtils
ReflectionTestUtils
.
setField
(
configService
,
"releaseSnapShotRepository"
,
releaseSnapShotRepository
);
.
setField
(
configService
,
"releaseSnapShotRepository"
,
releaseSnapShotRepository
);
...
...
apollo-client/src/main/java/com/ctrip/apollo/client/ApolloConfigManager.java
View file @
5efb7c4e
...
@@ -68,7 +68,6 @@ public class ApolloConfigManager
...
@@ -68,7 +68,6 @@ public class ApolloConfigManager
applicationContext
.
getClass
().
getName
()));
applicationContext
.
getClass
().
getName
()));
}
}
this
.
applicationContext
=
(
ConfigurableApplicationContext
)
applicationContext
;
this
.
applicationContext
=
(
ConfigurableApplicationContext
)
applicationContext
;
this
.
configUtil
.
setApplicationContext
(
applicationContext
);
}
}
/**
/**
...
...
apollo-client/src/main/java/com/ctrip/apollo/client/util/ConfigUtil.java
View file @
5efb7c4e
...
@@ -6,13 +6,13 @@ import com.google.common.collect.FluentIterable;
...
@@ -6,13 +6,13 @@ import com.google.common.collect.FluentIterable;
import
com.ctrip.apollo.client.constants.Constants
;
import
com.ctrip.apollo.client.constants.Constants
;
import
com.ctrip.apollo.client.model.ApolloRegistry
;
import
com.ctrip.apollo.client.model.ApolloRegistry
;
import
com.ctrip.apollo.core.utils.ClassLoaderUtil
;
import
org.springframework.context.ApplicationContext
;
import
org.slf4j.Logger
;
import
org.springframework.core.io.Resource
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.core.io.support.EncodedResource
;
import
org.springframework.core.io.support.PropertiesLoaderUtils
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.net.URL
;
import
java.net.URL
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.List
;
...
@@ -23,13 +23,13 @@ import java.util.concurrent.TimeUnit;
...
@@ -23,13 +23,13 @@ import java.util.concurrent.TimeUnit;
* @author Jason Song(song_s@ctrip.com)
* @author Jason Song(song_s@ctrip.com)
*/
*/
public
class
ConfigUtil
{
public
class
ConfigUtil
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ConfigUtil
.
class
);
public
static
final
String
APOLLO_PROPERTY
=
"apollo.properties"
;
public
static
final
String
APOLLO_PROPERTY
=
"apollo.properties"
;
//TODO read from config?
//TODO read from config?
private
static
final
int
refreshInterval
=
5
;
private
static
final
int
refreshInterval
=
5
;
private
static
final
TimeUnit
refreshIntervalTimeUnit
=
TimeUnit
.
MINUTES
;
private
static
final
TimeUnit
refreshIntervalTimeUnit
=
TimeUnit
.
MINUTES
;
private
static
ConfigUtil
configUtil
=
new
ConfigUtil
();
private
static
ConfigUtil
configUtil
=
new
ConfigUtil
();
private
ApplicationContext
applicationContext
;
private
ConfigUtil
()
{
private
ConfigUtil
()
{
}
}
...
@@ -43,10 +43,6 @@ public class ConfigUtil {
...
@@ -43,10 +43,6 @@ public class ConfigUtil {
return
"default"
;
return
"default"
;
}
}
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
{
this
.
applicationContext
=
applicationContext
;
}
public
int
getRefreshInterval
()
{
public
int
getRefreshInterval
()
{
return
refreshInterval
;
return
refreshInterval
;
}
}
...
@@ -77,14 +73,13 @@ public class ConfigUtil {
...
@@ -77,14 +73,13 @@ public class ConfigUtil {
}
}
Properties
loadPropertiesFromResourceURL
(
URL
resourceUrl
)
{
Properties
loadPropertiesFromResourceURL
(
URL
resourceUrl
)
{
Resource
resource
=
applicationContext
.
getResource
(
resourceUrl
.
toExternalForm
());
if
(
resource
==
null
||
!
resource
.
exists
())
{
return
null
;
}
try
{
try
{
return
PropertiesLoaderUtils
.
loadProperties
(
new
EncodedResource
(
resource
,
"UTF-8"
));
InputStream
inputStream
=
resourceUrl
.
openStream
();
Properties
prop
=
new
Properties
();
prop
.
load
(
inputStream
);
return
prop
;
}
catch
(
IOException
ex
)
{
}
catch
(
IOException
ex
)
{
ex
.
printStackTrace
(
);
logger
.
error
(
"Load properties from {} failed"
,
resourceUrl
.
toExternalForm
(),
ex
);
}
}
return
null
;
return
null
;
}
}
...
...
apollo-client/src/test/java/com/ctrip/apollo/client/loader/impl/RemoteConfigLoaderTest.java
View file @
5efb7c4e
...
@@ -39,6 +39,7 @@ public class RemoteConfigLoaderTest {
...
@@ -39,6 +39,7 @@ public class RemoteConfigLoaderTest {
private
RemoteConfigLoader
remoteConfigLoader
;
private
RemoteConfigLoader
remoteConfigLoader
;
@Mock
@Mock
private
RestTemplate
restTemplate
;
private
RestTemplate
restTemplate
;
@Mock
private
ConfigUtil
configUtil
;
private
ConfigUtil
configUtil
;
@Mock
@Mock
private
ConfigServiceLocator
serviceLocater
;
private
ConfigServiceLocator
serviceLocater
;
...
@@ -47,7 +48,6 @@ public class RemoteConfigLoaderTest {
...
@@ -47,7 +48,6 @@ public class RemoteConfigLoaderTest {
@Before
@Before
public
void
setUp
()
{
public
void
setUp
()
{
configUtil
=
spy
(
ConfigUtil
.
getInstance
());
remoteConfigLoader
=
spy
(
new
RemoteConfigLoader
(
restTemplate
,
configUtil
,
serviceLocater
));
remoteConfigLoader
=
spy
(
new
RemoteConfigLoader
(
restTemplate
,
configUtil
,
serviceLocater
));
}
}
...
...
apollo-client/src/test/java/com/ctrip/apollo/client/util/ConfigUtilTest.java
View file @
5efb7c4e
...
@@ -4,13 +4,13 @@ import com.google.common.collect.Lists;
...
@@ -4,13 +4,13 @@ import com.google.common.collect.Lists;
import
com.ctrip.apollo.client.constants.Constants
;
import
com.ctrip.apollo.client.constants.Constants
;
import
com.ctrip.apollo.client.model.ApolloRegistry
;
import
com.ctrip.apollo.client.model.ApolloRegistry
;
import
com.ctrip.apollo.core.utils.ClassLoaderUtil
;
import
org.junit.Before
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.runners.MockitoJUnitRunner
;
import
org.mockito.runners.MockitoJUnitRunner
;
import
org.springframework.
context.ConfigurableApplicationContext
;
import
org.springframework.
test.util.ReflectionTestUtils
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.net.URL
;
import
java.net.URL
;
...
@@ -34,14 +34,10 @@ import static org.mockito.Mockito.when;
...
@@ -34,14 +34,10 @@ import static org.mockito.Mockito.when;
@RunWith
(
MockitoJUnitRunner
.
class
)
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
ConfigUtilTest
{
public
class
ConfigUtilTest
{
private
ConfigUtil
configUtil
;
private
ConfigUtil
configUtil
;
@Mock
private
ConfigurableApplicationContext
applicationContext
;
@Before
@Before
public
void
setUp
()
throws
Exception
{
public
void
setUp
()
throws
Exception
{
configUtil
=
spy
(
ConfigUtil
.
getInstance
());
configUtil
=
spy
(
ConfigUtil
.
getInstance
());
configUtil
.
setApplicationContext
(
applicationContext
);
}
}
@Test
@Test
...
@@ -75,7 +71,7 @@ public class ConfigUtilTest {
...
@@ -75,7 +71,7 @@ public class ConfigUtilTest {
private
void
preparePropertiesFromLocalResource
(
Properties
someProperties
)
throws
IOException
{
private
void
preparePropertiesFromLocalResource
(
Properties
someProperties
)
throws
IOException
{
ClassLoader
someClassLoader
=
mock
(
ClassLoader
.
class
);
ClassLoader
someClassLoader
=
mock
(
ClassLoader
.
class
);
Thread
.
currentThread
().
setContextClassLoader
(
someClassLoader
);
ReflectionTestUtils
.
setField
(
ClassLoaderUtil
.
class
,
"loader"
,
someClassLoader
);
URL
someUrl
=
new
URL
(
"http"
,
"somepath/"
,
"someFile"
);
URL
someUrl
=
new
URL
(
"http"
,
"somepath/"
,
"someFile"
);
Enumeration
<
URL
>
someResourceUrls
=
Collections
.
enumeration
(
Lists
.
newArrayList
(
someUrl
));
Enumeration
<
URL
>
someResourceUrls
=
Collections
.
enumeration
(
Lists
.
newArrayList
(
someUrl
));
...
...
apollo-configservice/src/main/java/com/ctrip/apollo/configservice/controller/ConfigController.java
View file @
5efb7c4e
...
@@ -4,6 +4,7 @@ import com.ctrip.apollo.biz.entity.Version;
...
@@ -4,6 +4,7 @@ import com.ctrip.apollo.biz.entity.Version;
import
com.ctrip.apollo.biz.service.ConfigService
;
import
com.ctrip.apollo.biz.service.ConfigService
;
import
com.ctrip.apollo.core.dto.ApolloConfig
;
import
com.ctrip.apollo.core.dto.ApolloConfig
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestMethod
;
...
@@ -12,7 +13,6 @@ import org.springframework.web.bind.annotation.RestController;
...
@@ -12,7 +13,6 @@ import org.springframework.web.bind.annotation.RestController;
import
java.io.IOException
;
import
java.io.IOException
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
/**
/**
...
@@ -21,7 +21,7 @@ import javax.servlet.http.HttpServletResponse;
...
@@ -21,7 +21,7 @@ import javax.servlet.http.HttpServletResponse;
@RestController
@RestController
@RequestMapping
(
"/config"
)
@RequestMapping
(
"/config"
)
public
class
ConfigController
{
public
class
ConfigController
{
@
Resource
(
name
=
"configService"
)
@
Autowired
private
ConfigService
configService
;
private
ConfigService
configService
;
@RequestMapping
(
value
=
"/{appId}/{clusterName}/{versionName:.*}"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"/{appId}/{clusterName}/{versionName:.*}"
,
method
=
RequestMethod
.
GET
)
...
...
apollo-c
lient/src/main/java/com/ctrip/apollo/client/util
/ClassLoaderUtil.java
→
apollo-c
ore/src/main/java/com/ctrip/apollo/core/utils
/ClassLoaderUtil.java
View file @
5efb7c4e
package
com
.
ctrip
.
apollo
.
c
lient
.
util
;
package
com
.
ctrip
.
apollo
.
c
ore
.
utils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
...
...
apollo-core/src/main/java/com/ctrip/apollo/core/utils/ResourceUtils.java
View file @
5efb7c4e
...
@@ -18,7 +18,7 @@ public class ResourceUtils {
...
@@ -18,7 +18,7 @@ public class ResourceUtils {
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
public
static
Properties
readConfigFile
(
String
configPath
,
Properties
defaults
)
{
public
static
Properties
readConfigFile
(
String
configPath
,
Properties
defaults
)
{
InputStream
in
=
ClassLoader
.
getSystem
ResourceAsStream
(
configPath
);
InputStream
in
=
ClassLoader
Util
.
getLoader
().
get
ResourceAsStream
(
configPath
);
logger
.
info
(
"Reading config from resource {}"
,
configPath
);
logger
.
info
(
"Reading config from resource {}"
,
configPath
);
Properties
props
=
new
Properties
();
Properties
props
=
new
Properties
();
try
{
try
{
...
...
apollo-core/src/main/resources/apollo-env.properties
deleted
100644 → 0
View file @
7692e147
local.meta
=
http://localhost:8080
\ No newline at end of file
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