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
b271bebe
Commit
b271bebe
authored
Mar 29, 2016
by
Yiming Liu
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #55 from nobodyiam/refactor
refactor
parents
7692e147
5efb7c4e
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
152 additions
and
194 deletions
+152
-194
.gitignore
.gitignore
+2
-2
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 @
b271bebe
...
...
@@ -27,4 +27,5 @@ target
dev
fat
uat
prd
\ No newline at end of file
prd
apollo-env.properties
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ConfigController.java
View file @
b271bebe
package
com
.
ctrip
.
apollo
.
adminservice
.
controller
;
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.ReleaseSnapshotDTO
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
...
...
@@ -11,19 +13,18 @@ import org.springframework.web.bind.annotation.RestController;
import
java.util.List
;
import
javax.annotation.Resource
;
@RestController
@RequestMapping
(
"/configs"
)
public
class
ConfigController
{
@
Resource
(
name
=
"adminConfigService"
)
@
Autowired
private
AdminConfigService
adminConfigService
;
@Autowired
private
AdminReleaseService
adminReleaseService
;
@RequestMapping
(
"/release/{releaseId}"
)
public
List
<
ReleaseSnapshotDTO
>
getRelaseSnapshot
(
@PathVariable
long
releaseId
)
{
return
admin
Config
Service
.
findReleaseSnapshotByReleaseId
(
releaseId
);
return
admin
Release
Service
.
findReleaseSnapshotByReleaseId
(
releaseId
);
}
@RequestMapping
(
"/latest"
)
...
...
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/VersionController.java
View file @
b271bebe
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
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -15,18 +15,15 @@ import java.util.List;
public
class
VersionController
{
@Autowired
private
Admin
ConfigService
adminConfig
Service
;
private
Admin
ReleaseService
adminRelease
Service
;
@RequestMapping
(
"/app/{appId}"
)
public
List
<
VersionDTO
>
versions
(
@PathVariable
String
appId
)
{
return
adminConfigService
.
findVersionsByApp
(
appId
);
return
adminReleaseService
.
findVersionsByApp
(
appId
);
}
@RequestMapping
(
"/{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 @
b271bebe
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.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
;
/**
* config service for admin
*/
public
interface
AdminConfigService
{
List
<
ReleaseSnapshotDTO
>
findReleaseSnapshotByReleaseId
(
long
releaseId
);
List
<
VersionDTO
>
findVersionsByApp
(
String
appId
);
VersionDTO
loadVersionById
(
long
versionId
);
List
<
ClusterDTO
>
findClustersByApp
(
String
appId
);
List
<
ConfigItemDTO
>
findConfigItemsByClusters
(
List
<
Long
>
clusterIds
);
@Service
(
"adminConfigService"
)
public
class
AdminConfigService
{
@Autowired
private
ClusterRepository
clusterRepository
;
@Autowired
private
ConfigItemRepository
configItemRepository
;
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
);
}
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 @
b271bebe
package
com
.
ctrip
.
apollo
.
biz
.
service
.
impl
;
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.entity.ReleaseSnapshot
;
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.VersionRepository
;
import
com.ctrip.apollo.biz.service.AdminConfigService
;
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.VersionDTO
;
...
...
@@ -23,19 +16,16 @@ import org.springframework.stereotype.Service;
import
java.util.Collections
;
import
java.util.List
;
@Service
(
"adminConfigService"
)
public
class
AdminConfigServiceImpl
implements
AdminConfigService
{
@Autowired
private
VersionRepository
versionRepository
;
/**
* @author Jason Song(song_s@ctrip.com)
*/
@Service
(
"adminReleaseService"
)
public
class
AdminReleaseService
{
@Autowired
private
ReleaseSnapShotRepository
releaseSnapShotRepository
;
@Autowired
private
ClusterRepository
clusterRepository
;
@Autowired
private
ConfigItemRepository
configItemRepository
;
private
VersionRepository
versionRepository
;
@Override
public
List
<
ReleaseSnapshotDTO
>
findReleaseSnapshotByReleaseId
(
long
releaseId
)
{
if
(
releaseId
<=
0
)
{
return
Collections
.
EMPTY_LIST
;
...
...
@@ -50,8 +40,6 @@ public class AdminConfigServiceImpl implements AdminConfigService {
return
ApolloBeanUtils
.
batchTransform
(
ReleaseSnapshotDTO
.
class
,
releaseSnapShots
);
}
@Override
public
List
<
VersionDTO
>
findVersionsByApp
(
String
appId
)
{
if
(
Strings
.
isNullOrEmpty
(
appId
))
{
return
Collections
.
EMPTY_LIST
;
...
...
@@ -65,43 +53,15 @@ public class AdminConfigServiceImpl implements AdminConfigService {
return
ApolloBeanUtils
.
batchTransform
(
VersionDTO
.
class
,
versions
);
}
@Override
public
VersionDTO
loadVersionById
(
long
versionId
)
{
if
(
versionId
<=
0
)
{
return
null
;
}
Version
version
=
versionRepository
.
findById
(
versionId
);
if
(
version
==
null
){
if
(
version
==
null
)
{
return
null
;
}
VersionDTO
dto
=
ApolloBeanUtils
.
transfrom
(
VersionDTO
.
class
,
version
);
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 @
b271bebe
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.repository.ReleaseSnapShotRepository
;
import
com.ctrip.apollo.biz.repository.VersionRepository
;
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
*
* @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
*/
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
*/
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
*/
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 @
b271bebe
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.runners.Suite
;
...
...
@@ -8,7 +8,7 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith
(
Suite
.
class
)
@SuiteClasses
({
ConfigService
Impl
Test
.
class
})
ConfigServiceTest
.
class
})
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 @
b271bebe
package
com
.
ctrip
.
apollo
.
biz
.
service
.
impl
;
package
com
.
ctrip
.
apollo
.
biz
.
service
;
import
com.google.common.collect.Maps
;
...
...
@@ -6,6 +6,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.biz.service.ConfigService
;
import
com.ctrip.apollo.core.dto.ApolloConfig
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
...
...
@@ -33,18 +34,18 @@ import static org.mockito.Mockito.when;
* @author Jason Song(song_s@ctrip.com)
*/
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
ConfigService
Impl
Test
{
public
class
ConfigServiceTest
{
@Mock
private
VersionRepository
versionRepository
;
@Mock
private
ReleaseSnapShotRepository
releaseSnapShotRepository
;
@Mock
private
ObjectMapper
objectMapper
;
private
ConfigService
Impl
configService
;
private
ConfigService
configService
;
@Before
public
void
setUp
()
throws
Exception
{
configService
=
new
ConfigService
Impl
();
configService
=
new
ConfigService
();
ReflectionTestUtils
.
setField
(
configService
,
"versionRepository"
,
versionRepository
);
ReflectionTestUtils
.
setField
(
configService
,
"releaseSnapShotRepository"
,
releaseSnapShotRepository
);
...
...
apollo-client/src/main/java/com/ctrip/apollo/client/ApolloConfigManager.java
View file @
b271bebe
...
...
@@ -68,7 +68,6 @@ public class ApolloConfigManager
applicationContext
.
getClass
().
getName
()));
}
this
.
applicationContext
=
(
ConfigurableApplicationContext
)
applicationContext
;
this
.
configUtil
.
setApplicationContext
(
applicationContext
);
}
/**
...
...
apollo-client/src/main/java/com/ctrip/apollo/client/util/ConfigUtil.java
View file @
b271bebe
...
...
@@ -6,13 +6,13 @@ import com.google.common.collect.FluentIterable;
import
com.ctrip.apollo.client.constants.Constants
;
import
com.ctrip.apollo.client.model.ApolloRegistry
;
import
com.ctrip.apollo.core.utils.ClassLoaderUtil
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.core.io.Resource
;
import
org.springframework.core.io.support.EncodedResource
;
import
org.springframework.core.io.support.PropertiesLoaderUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.net.URL
;
import
java.util.Collections
;
import
java.util.List
;
...
...
@@ -23,13 +23,13 @@ import java.util.concurrent.TimeUnit;
* @author Jason Song(song_s@ctrip.com)
*/
public
class
ConfigUtil
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ConfigUtil
.
class
);
public
static
final
String
APOLLO_PROPERTY
=
"apollo.properties"
;
//TODO read from config?
private
static
final
int
refreshInterval
=
5
;
private
static
final
TimeUnit
refreshIntervalTimeUnit
=
TimeUnit
.
MINUTES
;
private
static
ConfigUtil
configUtil
=
new
ConfigUtil
();
private
ApplicationContext
applicationContext
;
private
ConfigUtil
()
{
}
...
...
@@ -43,10 +43,6 @@ public class ConfigUtil {
return
"default"
;
}
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
{
this
.
applicationContext
=
applicationContext
;
}
public
int
getRefreshInterval
()
{
return
refreshInterval
;
}
...
...
@@ -77,14 +73,13 @@ public class ConfigUtil {
}
Properties
loadPropertiesFromResourceURL
(
URL
resourceUrl
)
{
Resource
resource
=
applicationContext
.
getResource
(
resourceUrl
.
toExternalForm
());
if
(
resource
==
null
||
!
resource
.
exists
())
{
return
null
;
}
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
)
{
ex
.
printStackTrace
(
);
logger
.
error
(
"Load properties from {} failed"
,
resourceUrl
.
toExternalForm
(),
ex
);
}
return
null
;
}
...
...
apollo-client/src/test/java/com/ctrip/apollo/client/loader/impl/RemoteConfigLoaderTest.java
View file @
b271bebe
...
...
@@ -39,6 +39,7 @@ public class RemoteConfigLoaderTest {
private
RemoteConfigLoader
remoteConfigLoader
;
@Mock
private
RestTemplate
restTemplate
;
@Mock
private
ConfigUtil
configUtil
;
@Mock
private
ConfigServiceLocator
serviceLocater
;
...
...
@@ -47,7 +48,6 @@ public class RemoteConfigLoaderTest {
@Before
public
void
setUp
()
{
configUtil
=
spy
(
ConfigUtil
.
getInstance
());
remoteConfigLoader
=
spy
(
new
RemoteConfigLoader
(
restTemplate
,
configUtil
,
serviceLocater
));
}
...
...
apollo-client/src/test/java/com/ctrip/apollo/client/util/ConfigUtilTest.java
View file @
b271bebe
...
...
@@ -4,13 +4,13 @@ import com.google.common.collect.Lists;
import
com.ctrip.apollo.client.constants.Constants
;
import
com.ctrip.apollo.client.model.ApolloRegistry
;
import
com.ctrip.apollo.core.utils.ClassLoaderUtil
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.runners.MockitoJUnitRunner
;
import
org.springframework.
context.ConfigurableApplicationContext
;
import
org.springframework.
test.util.ReflectionTestUtils
;
import
java.io.IOException
;
import
java.net.URL
;
...
...
@@ -34,14 +34,10 @@ import static org.mockito.Mockito.when;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
ConfigUtilTest
{
private
ConfigUtil
configUtil
;
@Mock
private
ConfigurableApplicationContext
applicationContext
;
@Before
public
void
setUp
()
throws
Exception
{
configUtil
=
spy
(
ConfigUtil
.
getInstance
());
configUtil
.
setApplicationContext
(
applicationContext
);
}
@Test
...
...
@@ -75,7 +71,7 @@ public class ConfigUtilTest {
private
void
preparePropertiesFromLocalResource
(
Properties
someProperties
)
throws
IOException
{
ClassLoader
someClassLoader
=
mock
(
ClassLoader
.
class
);
Thread
.
currentThread
().
setContextClassLoader
(
someClassLoader
);
ReflectionTestUtils
.
setField
(
ClassLoaderUtil
.
class
,
"loader"
,
someClassLoader
);
URL
someUrl
=
new
URL
(
"http"
,
"somepath/"
,
"someFile"
);
Enumeration
<
URL
>
someResourceUrls
=
Collections
.
enumeration
(
Lists
.
newArrayList
(
someUrl
));
...
...
apollo-configservice/src/main/java/com/ctrip/apollo/configservice/controller/ConfigController.java
View file @
b271bebe
...
...
@@ -4,6 +4,7 @@ import com.ctrip.apollo.biz.entity.Version;
import
com.ctrip.apollo.biz.service.ConfigService
;
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.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
...
...
@@ -12,7 +13,6 @@ import org.springframework.web.bind.annotation.RestController;
import
java.io.IOException
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletResponse
;
/**
...
...
@@ -21,7 +21,7 @@ import javax.servlet.http.HttpServletResponse;
@RestController
@RequestMapping
(
"/config"
)
public
class
ConfigController
{
@
Resource
(
name
=
"configService"
)
@
Autowired
private
ConfigService
configService
;
@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 @
b271bebe
package
com
.
ctrip
.
apollo
.
c
lient
.
util
;
package
com
.
ctrip
.
apollo
.
c
ore
.
utils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
apollo-core/src/main/java/com/ctrip/apollo/core/utils/ResourceUtils.java
View file @
b271bebe
...
...
@@ -18,7 +18,7 @@ public class ResourceUtils {
@SuppressWarnings
(
"unchecked"
)
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
);
Properties
props
=
new
Properties
();
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