Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wrr-cat
apollo
提交
c46f561c
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,发现更多精彩内容 >>
提交
c46f561c
编写于
3月 29, 2016
作者:
J
Jason Song
浏览文件
操作
浏览文件
下载
差异文件
Support reading Envs in Portal
上级
48c3bb83
0fce28d6
变更
20
隐藏空白更改
内联
并排
Showing
20 changed file
with
159 addition
and
101 deletion
+159
-101
apollo-biz/src/main/java/com/ctrip/apollo/biz/utils/ApolloBeanUtils.java
...main/java/com/ctrip/apollo/biz/utils/ApolloBeanUtils.java
+20
-6
apollo-biz/src/main/java/com/ctrip/apollo/biz/utils/ConverterUtils.java
.../main/java/com/ctrip/apollo/biz/utils/ConverterUtils.java
+0
-24
apollo-client/src/main/java/com/ctrip/apollo/client/loader/ConfigServiceLocator.java
.../com/ctrip/apollo/client/loader/ConfigServiceLocator.java
+5
-5
apollo-client/src/main/java/com/ctrip/apollo/client/loader/impl/RemoteConfigLoader.java
...m/ctrip/apollo/client/loader/impl/RemoteConfigLoader.java
+2
-2
apollo-client/src/test/java/com/ctrip/apollo/client/loader/impl/RemoteConfigLoaderTest.java
...rip/apollo/client/loader/impl/RemoteConfigLoaderTest.java
+3
-3
apollo-configservice/src/main/java/com/ctrip/apollo/metaservice/controller/ServiceController.java
...trip/apollo/metaservice/controller/ServiceController.java
+10
-10
apollo-core/src/main/java/com/ctrip/apollo/core/ConfigConsts.java
...ore/src/main/java/com/ctrip/apollo/core/ConfigConsts.java
+1
-1
apollo-core/src/main/java/com/ctrip/apollo/core/ServiceNameConsts.java
...rc/main/java/com/ctrip/apollo/core/ServiceNameConsts.java
+5
-5
apollo-core/src/main/java/com/ctrip/apollo/core/dto/ServiceDTO.java
...e/src/main/java/com/ctrip/apollo/core/dto/ServiceDTO.java
+2
-2
apollo-core/src/main/java/com/ctrip/apollo/core/exception/ServiceException.java
...ava/com/ctrip/apollo/core/exception/ServiceException.java
+14
-0
apollo-core/src/main/java/com/ctrip/apollo/core/utils/ResourceUtils.java
.../main/java/com/ctrip/apollo/core/utils/ResourceUtils.java
+9
-3
apollo-core/src/main/resources/apollo-env.properties
apollo-core/src/main/resources/apollo-env.properties
+1
-1
apollo-core/src/test/java/com/ctrip/apollo/core/MetaDomainTest.java
...e/src/test/java/com/ctrip/apollo/core/MetaDomainTest.java
+5
-4
apollo-core/src/test/resources/apollo-env.properties
apollo-core/src/test/resources/apollo-env.properties
+2
-1
apollo-portal/src/main/java/com/ctrip/apollo/portal/PortalSettings.java
...src/main/java/com/ctrip/apollo/portal/PortalSettings.java
+31
-0
apollo-portal/src/main/java/com/ctrip/apollo/portal/api/API.java
...portal/src/main/java/com/ctrip/apollo/portal/api/API.java
+10
-4
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ConfigService.java
...n/java/com/ctrip/apollo/portal/service/ConfigService.java
+3
-3
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ServiceLocator.java
.../java/com/ctrip/apollo/portal/service/ServiceLocator.java
+16
-15
apollo-portal/src/main/resources/application.yml
apollo-portal/src/main/resources/application.yml
+4
-0
apollo-portal/src/test/java/com/ctrip/apollo/portal/service/ConfigServiceTest.java
...va/com/ctrip/apollo/portal/service/ConfigServiceTest.java
+16
-12
未找到文件。
apollo-biz/src/main/java/com/ctrip/apollo/biz/utils/ApolloBeanUtils.java
浏览文件 @
c46f561c
package
com.ctrip.apollo.biz.utils
;
import
org.springframework.beans.BeanWrapper
;
import
org.springframework.beans.BeanWrapperImpl
;
import
org.springframework.util.CollectionUtils
;
import
java.lang.reflect.Field
;
...
...
@@ -48,11 +50,23 @@ public class ApolloBeanUtils {
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
org
.
springframework
.
beans
.
BeanUtils
.
copyProperties
(
src
,
instance
,
ConverterUtils
.
getNullPropertyNames
(
src
));
org
.
springframework
.
beans
.
BeanUtils
.
copyProperties
(
src
,
instance
,
getNullPropertyNames
(
src
));
return
instance
;
}
static
String
[]
getNullPropertyNames
(
Object
source
)
{
final
BeanWrapper
src
=
new
BeanWrapperImpl
(
source
);
java
.
beans
.
PropertyDescriptor
[]
pds
=
src
.
getPropertyDescriptors
();
Set
<
String
>
emptyNames
=
new
HashSet
<
String
>();
for
(
java
.
beans
.
PropertyDescriptor
pd
:
pds
)
{
Object
srcValue
=
src
.
getPropertyValue
(
pd
.
getName
());
if
(
srcValue
==
null
)
emptyNames
.
add
(
pd
.
getName
());
}
String
[]
result
=
new
String
[
emptyNames
.
size
()];
return
emptyNames
.
toArray
(
result
);
}
/**
* 用于将一个列表转换为列表中的对象的某个属性映射到列表中的对象
*
...
...
@@ -92,7 +106,7 @@ public class ApolloBeanUtils {
*/
public
static
<
K
,
V
>
Map
<
K
,
List
<
V
>>
aggByKeyToList
(
String
key
,
List
list
)
{
Map
<
K
,
List
<
V
>>
map
=
new
HashMap
<
K
,
List
<
V
>>();
if
(
CollectionUtils
.
isEmpty
(
list
))
{
//防止外面传入空list
if
(
CollectionUtils
.
isEmpty
(
list
))
{
//
防止外面传入空list
return
map
;
}
try
{
...
...
@@ -122,7 +136,7 @@ public class ApolloBeanUtils {
*/
public
static
Set
toPropertySet
(
String
key
,
List
list
)
{
Set
set
=
new
HashSet
();
if
(
CollectionUtils
.
isEmpty
(
list
))
{
//防止外面传入空list
if
(
CollectionUtils
.
isEmpty
(
list
))
{
//
防止外面传入空list
return
set
;
}
try
{
...
...
@@ -168,7 +182,7 @@ public class ApolloBeanUtils {
return
field
.
get
(
obj
);
}
}
catch
(
Exception
e
)
{
//ig
//
ig
}
return
null
;
}
...
...
@@ -184,7 +198,7 @@ public class ApolloBeanUtils {
field
.
set
(
obj
,
value
);
}
}
catch
(
Exception
e
)
{
//ig
//
ig
}
}
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/utils/ConverterUtils.java
已删除
100644 → 0
浏览文件 @
48c3bb83
package
com.ctrip.apollo.biz.utils
;
import
java.util.HashSet
;
import
java.util.Set
;
import
org.springframework.beans.BeanWrapper
;
import
org.springframework.beans.BeanWrapperImpl
;
public
class
ConverterUtils
{
static
String
[]
getNullPropertyNames
(
Object
source
)
{
final
BeanWrapper
src
=
new
BeanWrapperImpl
(
source
);
java
.
beans
.
PropertyDescriptor
[]
pds
=
src
.
getPropertyDescriptors
();
Set
<
String
>
emptyNames
=
new
HashSet
<
String
>();
for
(
java
.
beans
.
PropertyDescriptor
pd
:
pds
)
{
Object
srcValue
=
src
.
getPropertyValue
(
pd
.
getName
());
if
(
srcValue
==
null
)
emptyNames
.
add
(
pd
.
getName
());
}
String
[]
result
=
new
String
[
emptyNames
.
size
()];
return
emptyNames
.
toArray
(
result
);
}
}
apollo-client/src/main/java/com/ctrip/apollo/client/loader/ConfigServiceLocator.java
浏览文件 @
c46f561c
package
com.ctrip.apollo.client.loader
;
import
com.ctrip.apollo.client.env.ClientEnvironment
;
import
com.ctrip.apollo.core.
serivce.ApolloService
;
import
com.ctrip.apollo.core.
dto.ServiceDTO
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -17,17 +17,17 @@ public class ConfigServiceLocator {
private
RestTemplate
restTemplate
=
new
RestTemplate
();
private
List
<
ApolloService
>
serviceCaches
=
new
ArrayList
<>();
private
List
<
ServiceDTO
>
serviceCaches
=
new
ArrayList
<>();
public
List
<
ApolloService
>
getConfigServices
()
{
public
List
<
ServiceDTO
>
getConfigServices
()
{
ClientEnvironment
env
=
ClientEnvironment
.
getInstance
();
String
domainName
=
env
.
getMetaServerDomainName
();
String
url
=
domainName
+
"/services/config"
;
try
{
ApolloService
[]
services
=
restTemplate
.
getForObject
(
new
URI
(
url
),
ApolloService
[].
class
);
ServiceDTO
[]
services
=
restTemplate
.
getForObject
(
new
URI
(
url
),
ServiceDTO
[].
class
);
if
(
services
!=
null
&&
services
.
length
>
0
)
{
serviceCaches
.
clear
();
for
(
ApolloService
service
:
services
)
{
for
(
ServiceDTO
service
:
services
)
{
serviceCaches
.
add
(
service
);
}
}
...
...
apollo-client/src/main/java/com/ctrip/apollo/client/loader/impl/RemoteConfigLoader.java
浏览文件 @
c46f561c
...
...
@@ -6,7 +6,7 @@ import com.ctrip.apollo.client.loader.ConfigServiceLocator;
import
com.ctrip.apollo.client.model.ApolloRegistry
;
import
com.ctrip.apollo.client.util.ConfigUtil
;
import
com.ctrip.apollo.core.dto.ApolloConfig
;
import
com.ctrip.apollo.core.
serivce.ApolloService
;
import
com.ctrip.apollo.core.
dto.ServiceDTO
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -96,7 +96,7 @@ public class RemoteConfigLoader extends AbstractConfigLoader {
}
private
String
getConfigServiceUrl
()
{
List
<
ApolloService
>
services
=
serviceLocator
.
getConfigServices
();
List
<
ServiceDTO
>
services
=
serviceLocator
.
getConfigServices
();
if
(
services
.
size
()
==
0
)
{
throw
new
RuntimeException
(
"No available config service"
);
}
...
...
apollo-client/src/test/java/com/ctrip/apollo/client/loader/impl/RemoteConfigLoaderTest.java
浏览文件 @
c46f561c
...
...
@@ -4,7 +4,7 @@ import com.ctrip.apollo.client.loader.ConfigServiceLocator;
import
com.ctrip.apollo.client.model.ApolloRegistry
;
import
com.ctrip.apollo.client.util.ConfigUtil
;
import
com.ctrip.apollo.core.dto.ApolloConfig
;
import
com.ctrip.apollo.core.
serivce.ApolloService
;
import
com.ctrip.apollo.core.
dto.ServiceDTO
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -60,9 +60,9 @@ public class RemoteConfigLoaderTest {
ApolloRegistry
apolloRegistry
=
assembleSomeApolloRegistry
(
someAppId
,
"someVersion"
);
ApolloConfig
previousConfig
=
null
;
ApolloService
someService
=
new
ApolloService
();
ServiceDTO
someService
=
new
ServiceDTO
();
someService
.
setHomepageUrl
(
someServerUrl
);
List
<
ApolloService
>
someServices
=
new
ArrayList
<>();
List
<
ServiceDTO
>
someServices
=
new
ArrayList
<>();
someServices
.
add
(
someService
);
when
(
serviceLocater
.
getConfigServices
()).
thenReturn
(
someServices
);
when
(
configUtil
.
getCluster
()).
thenReturn
(
someCluster
);
...
...
apollo-configservice/src/main/java/com/ctrip/apollo/metaservice/controller/ServiceController.java
浏览文件 @
c46f561c
package
com.ctrip.apollo.metaservice.controller
;
import
com.ctrip.apollo.core.
serivce.ApolloService
;
import
com.ctrip.apollo.core.
dto.ServiceDTO
;
import
com.ctrip.apollo.metaservice.service.DiscoveryService
;
import
com.netflix.appinfo.InstanceInfo
;
...
...
@@ -20,11 +20,11 @@ public class ServiceController {
@RequestMapping
(
"/meta"
)
public
List
<
ApolloService
>
getMetaService
()
{
public
List
<
ServiceDTO
>
getMetaService
()
{
List
<
InstanceInfo
>
instances
=
discoveryService
.
getMetaServiceInstances
();
List
<
ApolloService
>
result
=
new
ArrayList
<
ApolloService
>();
List
<
ServiceDTO
>
result
=
new
ArrayList
<
ServiceDTO
>();
for
(
InstanceInfo
instance
:
instances
)
{
ApolloService
service
=
new
ApolloService
();
ServiceDTO
service
=
new
ServiceDTO
();
service
.
setAppName
(
instance
.
getAppName
());
service
.
setInstanceId
(
instance
.
getInstanceId
());
service
.
setHomepageUrl
(
instance
.
getHomePageUrl
());
...
...
@@ -34,11 +34,11 @@ public class ServiceController {
}
@RequestMapping
(
"/config"
)
public
List
<
ApolloService
>
getConfigService
()
{
public
List
<
ServiceDTO
>
getConfigService
()
{
List
<
InstanceInfo
>
instances
=
discoveryService
.
getConfigServiceInstances
();
List
<
ApolloService
>
result
=
new
ArrayList
<
ApolloService
>();
List
<
ServiceDTO
>
result
=
new
ArrayList
<
ServiceDTO
>();
for
(
InstanceInfo
instance
:
instances
)
{
ApolloService
service
=
new
ApolloService
();
ServiceDTO
service
=
new
ServiceDTO
();
service
.
setAppName
(
instance
.
getAppName
());
service
.
setInstanceId
(
instance
.
getInstanceId
());
service
.
setHomepageUrl
(
instance
.
getHomePageUrl
());
...
...
@@ -48,11 +48,11 @@ public class ServiceController {
}
@RequestMapping
(
"/admin"
)
public
List
<
ApolloService
>
getAdminService
()
{
public
List
<
ServiceDTO
>
getAdminService
()
{
List
<
InstanceInfo
>
instances
=
discoveryService
.
getAdminServiceInstances
();
List
<
ApolloService
>
result
=
new
ArrayList
<
ApolloService
>();
List
<
ServiceDTO
>
result
=
new
ArrayList
<
ServiceDTO
>();
for
(
InstanceInfo
instance
:
instances
)
{
ApolloService
service
=
new
ApolloService
();
ServiceDTO
service
=
new
ServiceDTO
();
service
.
setAppName
(
instance
.
getAppName
());
service
.
setInstanceId
(
instance
.
getInstanceId
());
service
.
setHomepageUrl
(
instance
.
getHomePageUrl
());
...
...
apollo-core/src/main/java/com/ctrip/apollo/core/Con
stan
ts.java
→
apollo-core/src/main/java/com/ctrip/apollo/core/Con
figCons
ts.java
浏览文件 @
c46f561c
package
com.ctrip.apollo.core
;
public
interface
Con
stan
ts
{
public
interface
Con
figCons
ts
{
String
DEFAULT_CLUSTER_NAME
=
"default"
;
...
...
apollo-core/src/main/java/com/ctrip/apollo/core/ServiceNameConsts.java
浏览文件 @
c46f561c
package
com.ctrip.apollo.core
;
public
class
ServiceNameConsts
{
public
interface
ServiceNameConsts
{
public
static
final
String
APOLLO_METASERVICE
=
"apollo-metaservice"
;
final
String
APOLLO_METASERVICE
=
"apollo-metaservice"
;
public
static
final
String
APOLLO_CONFIGSERVICE
=
"apollo-configservice"
;
final
String
APOLLO_CONFIGSERVICE
=
"apollo-configservice"
;
public
static
final
String
APOLLO_ADMINSERVICE
=
"apollo-adminservice"
;
final
String
APOLLO_ADMINSERVICE
=
"apollo-adminservice"
;
public
static
final
String
APOLLO_PORTAL
=
"apollo-portal"
;
final
String
APOLLO_PORTAL
=
"apollo-portal"
;
}
apollo-core/src/main/java/com/ctrip/apollo/core/
serivce/ApolloService
.java
→
apollo-core/src/main/java/com/ctrip/apollo/core/
dto/ServiceDTO
.java
浏览文件 @
c46f561c
package
com.ctrip.apollo.core.
serivce
;
package
com.ctrip.apollo.core.
dto
;
public
class
ApolloService
{
public
class
ServiceDTO
{
private
String
appName
;
...
...
apollo-core/src/main/java/com/ctrip/apollo/core/exception/ServiceException.java
0 → 100644
浏览文件 @
c46f561c
package
com.ctrip.apollo.core.exception
;
public
class
ServiceException
extends
Exception
{
/**
*
*/
private
static
final
long
serialVersionUID
=
1L
;
public
ServiceException
(
String
str
)
{
super
(
str
);
}
}
apollo-core/src/main/java/com/ctrip/apollo/core/utils/ResourceUtils.java
浏览文件 @
c46f561c
...
...
@@ -15,7 +15,7 @@ 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
);
...
...
@@ -28,6 +28,8 @@ public class ResourceUtils {
if
(
Files
.
isReadable
(
path
))
{
in
=
new
FileInputStream
(
path
.
toFile
());
logger
.
info
(
"Reading config from file {} "
,
path
);
}
else
{
logger
.
info
(
"Could not find available config file"
);
}
}
if
(
defaults
!=
null
)
{
...
...
@@ -51,12 +53,16 @@ public class ResourceUtils {
}
StringBuilder
sb
=
new
StringBuilder
();
for
(
Enumeration
<
String
>
e
=
(
Enumeration
<
String
>)
props
.
propertyNames
();
e
.
hasMoreElements
();
)
{
.
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
());
if
(
sb
.
length
()
>
0
)
{
logger
.
info
(
"Reading properties: \n"
+
sb
.
toString
());
}
else
{
logger
.
info
(
"No available properties"
);
}
return
props
;
}
}
apollo-core/src/main/resources/apollo-env.properties
浏览文件 @
c46f561c
local.meta
=
http://localhost:8090
\ No newline at end of file
local.meta
=
http://localhost:8080
\ No newline at end of file
apollo-core/src/test/java/com/ctrip/apollo/core/MetaDomainTest.java
浏览文件 @
c46f561c
package
com.ctrip.apollo.core
;
import
org.junit.Assert
;
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
));
public
void
testGetMetaDomain
()
{
Assert
.
assertEquals
(
"http://localhost:8090"
,
MetaDomainConsts
.
getDomain
(
Env
.
LOCAL
));
Assert
.
assertEquals
(
"http://dev:8080"
,
MetaDomainConsts
.
getDomain
(
Env
.
DEV
));
Assert
.
assertNull
(
MetaDomainConsts
.
getDomain
(
Env
.
PRO
));
}
}
apollo-core/src/test/resources/apollo-env.properties
浏览文件 @
c46f561c
local.meta
=
http://localhost:8090
\ No newline at end of file
local.meta
=
http://localhost:8090
dev.meta
=
http://dev:8080
\ No newline at end of file
apollo-portal/src/main/java/com/ctrip/apollo/portal/PortalSettings.java
0 → 100644
浏览文件 @
c46f561c
package
com.ctrip.apollo.portal
;
import
java.util.ArrayList
;
import
java.util.List
;
import
javax.annotation.PostConstruct
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
com.ctrip.apollo.Apollo.Env
;
@Component
public
class
PortalSettings
{
@Value
(
"#{'${apollo.portal.env}'.split(',')}"
)
private
List
<
String
>
env
;
private
List
<
Env
>
envs
=
new
ArrayList
<
Env
>();
@PostConstruct
private
void
postConstruct
()
{
for
(
String
e
:
env
)
{
envs
.
add
(
Env
.
valueOf
(
e
.
toUpperCase
()));
}
}
public
List
<
Env
>
getEnvs
()
{
return
envs
;
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/api/API.java
浏览文件 @
c46f561c
package
com.ctrip.apollo.portal.api
;
import
com.ctrip.apollo.Apollo
;
import
com.ctrip.apollo.core.exception.ServiceException
;
import
com.ctrip.apollo.portal.service.ServiceLocator
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -13,9 +14,14 @@ public class API {
protected
RestTemplate
restTemplate
=
new
RestTemplate
();
public
String
getAdminServiceHost
(
Apollo
.
Env
env
){
//本地测试用
// return "http://localhost:8090";
return
serviceLocator
.
getAdminService
(
env
);
public
String
getAdminServiceHost
(
Apollo
.
Env
env
)
{
// 本地测试用
// return "http://localhost:8090";
try
{
return
serviceLocator
.
getAdminService
(
env
).
getHomepageUrl
();
}
catch
(
ServiceException
e
)
{
e
.
printStackTrace
();
}
return
""
;
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ConfigService.java
浏览文件 @
c46f561c
...
...
@@ -14,7 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Service
;
import
com.ctrip.apollo.Apollo.Env
;
import
com.ctrip.apollo.core.Con
stan
ts
;
import
com.ctrip.apollo.core.Con
figCons
ts
;
import
com.ctrip.apollo.core.dto.ClusterDTO
;
import
com.ctrip.apollo.core.dto.ConfigItemDTO
;
import
com.ctrip.apollo.core.dto.ReleaseSnapshotDTO
;
...
...
@@ -61,7 +61,7 @@ public class ConfigService {
for
(
ReleaseSnapshotDTO
snapShot
:
releaseSnapShots
)
{
// default cluster
if
(
Con
stan
ts
.
DEFAULT_CLUSTER_NAME
.
equals
(
snapShot
.
getClusterName
()))
{
if
(
Con
figCons
ts
.
DEFAULT_CLUSTER_NAME
.
equals
(
snapShot
.
getClusterName
()))
{
collectDefaultClusterConfigs
(
appId
,
snapShot
,
appConfigVO
);
...
...
@@ -223,7 +223,7 @@ public class ConfigService {
clusterName
=
entry
.
getKey
();
clusterConfigs
=
entry
.
getValue
();
if
(
Con
stan
ts
.
DEFAULT_CLUSTER_NAME
.
equals
(
clusterName
))
{
if
(
Con
figCons
ts
.
DEFAULT_CLUSTER_NAME
.
equals
(
clusterName
))
{
// default cluster configs
collectDefaultClusterConfigs
(
appId
,
clusterConfigs
,
defaultClusterConfigs
,
overrideAppConfigs
);
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ServiceLocator.java
浏览文件 @
c46f561c
...
...
@@ -11,7 +11,8 @@ import org.springframework.web.client.RestTemplate;
import
com.ctrip.apollo.Apollo.Env
;
import
com.ctrip.apollo.core.MetaDomainConsts
;
import
com.ctrip.apollo.core.serivce.ApolloService
;
import
com.ctrip.apollo.core.dto.ServiceDTO
;
import
com.ctrip.apollo.core.exception.ServiceException
;
/**
* @author liuym
...
...
@@ -23,32 +24,32 @@ public class ServiceLocator {
private
RestTemplate
restTemplate
=
new
RestTemplate
();
private
List
<
ApolloService
>
serviceCaches
=
new
ArrayList
<>();
private
List
<
ServiceDTO
>
serviceCaches
=
new
ArrayList
<>();
public
List
<
ApolloService
>
getAdminServices
(
Env
env
)
{
return
getServices
(
env
,
"admin"
);
}
public
String
getAdminService
(
Env
env
)
{
List
<
ApolloService
>
services
=
getAdminServices
(
env
);
public
ServiceDTO
getAdminService
(
Env
env
)
throws
ServiceException
{
List
<
ServiceDTO
>
services
=
getServices
(
env
,
"admin"
);
if
(
services
.
size
()
==
0
)
{
throw
new
Runtim
eException
(
"No available admin service"
);
throw
new
Servic
eException
(
"No available admin service"
);
}
return
services
.
get
(
0
)
.
getHomepageUrl
()
;
return
services
.
get
(
0
);
}
public
List
<
ApolloService
>
getConfigServices
(
Env
env
)
{
return
getServices
(
env
,
"config"
);
public
ServiceDTO
getConfigService
(
Env
env
)
throws
ServiceException
{
List
<
ServiceDTO
>
services
=
getServices
(
env
,
"config"
);
if
(
services
.
size
()
==
0
)
{
throw
new
ServiceException
(
"No available config service"
);
}
return
services
.
get
(
0
);
}
private
List
<
ApolloService
>
getServices
(
Env
env
,
String
serviceUrl
)
{
private
List
<
ServiceDTO
>
getServices
(
Env
env
,
String
serviceUrl
)
{
String
domainName
=
MetaDomainConsts
.
getDomain
(
env
);
String
url
=
domainName
+
"/services/"
+
serviceUrl
;
try
{
ApolloService
[]
services
=
restTemplate
.
getForObject
(
new
URI
(
url
),
ApolloService
[].
class
);
ServiceDTO
[]
services
=
restTemplate
.
getForObject
(
new
URI
(
url
),
ServiceDTO
[].
class
);
if
(
services
!=
null
&&
services
.
length
>
0
)
{
serviceCaches
.
clear
();
for
(
ApolloService
service
:
services
)
{
for
(
ServiceDTO
service
:
services
)
{
serviceCaches
.
add
(
service
);
}
}
...
...
apollo-portal/src/main/resources/application.yml
浏览文件 @
c46f561c
...
...
@@ -17,3 +17,7 @@ logging:
ctrip
:
appid
:
100003173
apollo
:
portal
:
env
:
dev,fws,uat
apollo-portal/src/test/java/com/ctrip/apollo/portal/service/ConfigServiceTest.java
浏览文件 @
c46f561c
...
...
@@ -15,11 +15,13 @@ import org.springframework.test.util.ReflectionTestUtils;
import
org.springframework.web.client.RestTemplate
;
import
com.ctrip.apollo.Apollo.Env
;
import
com.ctrip.apollo.core.Con
stan
ts
;
import
com.ctrip.apollo.core.Con
figCons
ts
;
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.ServiceDTO
;
import
com.ctrip.apollo.core.dto.VersionDTO
;
import
com.ctrip.apollo.core.exception.ServiceException
;
import
com.ctrip.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.apollo.portal.constants.PortalConstants
;
import
com.ctrip.apollo.portal.entity.AppConfigVO
;
...
...
@@ -47,7 +49,7 @@ public class ConfigServiceTest {
@Before
public
void
setUp
()
{
public
void
setUp
()
throws
ServiceException
{
ReflectionTestUtils
.
setField
(
versionAPI
,
"restTemplate"
,
restTemplate
);
ReflectionTestUtils
.
setField
(
clusterAPI
,
"restTemplate"
,
restTemplate
);
ReflectionTestUtils
.
setField
(
configAPI
,
"restTemplate"
,
restTemplate
);
...
...
@@ -57,7 +59,9 @@ public class ConfigServiceTest {
ReflectionTestUtils
.
setField
(
configAPI
,
"serviceLocator"
,
serviceLocator
);
String
defaultAdminService
=
"http://localhost:8090"
;
Mockito
.
doReturn
(
defaultAdminService
).
when
(
serviceLocator
).
getAdminService
(
Env
.
DEV
);
ServiceDTO
service
=
new
ServiceDTO
();
service
.
setHomepageUrl
(
defaultAdminService
);
Mockito
.
doReturn
(
service
).
when
(
serviceLocator
).
getAdminService
(
Env
.
DEV
);
}
@Test
...
...
@@ -89,7 +93,7 @@ public class ConfigServiceTest {
VersionDTO
someVersion
=
assembleVersion
(
appId
,
"1.0"
,
releaseId
);
ReleaseSnapshotDTO
[]
someReleaseSnapShots
=
new
ReleaseSnapshotDTO
[
1
];
someReleaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
Con
stan
ts
.
DEFAULT_CLUSTER_NAME
,
someReleaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
Con
figCons
ts
.
DEFAULT_CLUSTER_NAME
,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}"
);
when
(
versionAPI
.
getVersionById
(
Env
.
DEV
,
versionId
)).
thenReturn
(
someVersion
);
...
...
@@ -111,7 +115,7 @@ public class ConfigServiceTest {
long
releaseId
=
11111
;
VersionDTO
someVersion
=
assembleVersion
(
appId
,
"1.0"
,
releaseId
);
ReleaseSnapshotDTO
[]
someReleaseSnapShots
=
new
ReleaseSnapshotDTO
[
1
];
someReleaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
Con
stan
ts
.
DEFAULT_CLUSTER_NAME
,
someReleaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
Con
figCons
ts
.
DEFAULT_CLUSTER_NAME
,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\", \"5555.bar\":\"demo2\", \"22.bar\":\"demo2\"}"
);
when
(
versionAPI
.
getVersionById
(
Env
.
DEV
,
versionId
)).
thenReturn
(
someVersion
);
...
...
@@ -133,7 +137,7 @@ public class ConfigServiceTest {
long
releaseId
=
11111
;
VersionDTO
someVersion
=
assembleVersion
(
appId
,
"1.0"
,
releaseId
);
ReleaseSnapshotDTO
[]
someReleaseSnapShots
=
new
ReleaseSnapshotDTO
[
2
];
someReleaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
Con
stan
ts
.
DEFAULT_CLUSTER_NAME
,
someReleaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
Con
figCons
ts
.
DEFAULT_CLUSTER_NAME
,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}"
);
someReleaseSnapShots
[
1
]
=
assembleReleaseSnapShot
(
11112
,
"cluster1"
,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}"
);
...
...
@@ -179,7 +183,7 @@ public class ConfigServiceTest {
private
ReleaseSnapshotDTO
[]
assembleReleaseSnapShots
()
{
ReleaseSnapshotDTO
[]
releaseSnapShots
=
new
ReleaseSnapshotDTO
[
3
];
releaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
Con
stan
ts
.
DEFAULT_CLUSTER_NAME
,
releaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
Con
figCons
ts
.
DEFAULT_CLUSTER_NAME
,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\",\"3333.foo\":\"1008\",\"4444.bar\":\"99901\"}"
);
releaseSnapShots
[
1
]
=
assembleReleaseSnapShot
(
11111
,
"cluster1"
,
"{\"6666.foo\":\"demo1\"}"
);
releaseSnapShots
[
2
]
=
assembleReleaseSnapShot
(
11111
,
"cluster2"
,
"{\"6666.bar\":\"bar2222\"}"
);
...
...
@@ -197,7 +201,7 @@ public class ConfigServiceTest {
private
ClusterDTO
[]
assembleClusters
()
{
ClusterDTO
[]
clusters
=
new
ClusterDTO
[
2
];
clusters
[
0
]
=
assembleCluster
(
100
,
"6666"
,
Con
stan
ts
.
DEFAULT_CLUSTER_NAME
);
clusters
[
0
]
=
assembleCluster
(
100
,
"6666"
,
Con
figCons
ts
.
DEFAULT_CLUSTER_NAME
);
clusters
[
1
]
=
assembleCluster
(
101
,
"6666"
,
"cluster1"
);
return
clusters
;
}
...
...
@@ -212,10 +216,10 @@ public class ConfigServiceTest {
private
ConfigItemDTO
[]
assembleConfigItems
()
{
ConfigItemDTO
[]
configItems
=
new
ConfigItemDTO
[
5
];
configItems
[
0
]
=
assembleConfigItem
(
100
,
Con
stan
ts
.
DEFAULT_CLUSTER_NAME
,
"6666"
,
"6666.k1"
,
"6666.v1"
);
configItems
[
1
]
=
assembleConfigItem
(
100
,
Con
stan
ts
.
DEFAULT_CLUSTER_NAME
,
"6666"
,
"6666.k2"
,
"6666.v2"
);
configItems
[
2
]
=
assembleConfigItem
(
100
,
Con
stan
ts
.
DEFAULT_CLUSTER_NAME
,
"6666"
,
"6666.k3"
,
"6666.v3"
);
configItems
[
3
]
=
assembleConfigItem
(
100
,
Con
stan
ts
.
DEFAULT_CLUSTER_NAME
,
"5555"
,
"5555.k1"
,
"5555.v1"
);
configItems
[
0
]
=
assembleConfigItem
(
100
,
Con
figCons
ts
.
DEFAULT_CLUSTER_NAME
,
"6666"
,
"6666.k1"
,
"6666.v1"
);
configItems
[
1
]
=
assembleConfigItem
(
100
,
Con
figCons
ts
.
DEFAULT_CLUSTER_NAME
,
"6666"
,
"6666.k2"
,
"6666.v2"
);
configItems
[
2
]
=
assembleConfigItem
(
100
,
Con
figCons
ts
.
DEFAULT_CLUSTER_NAME
,
"6666"
,
"6666.k3"
,
"6666.v3"
);
configItems
[
3
]
=
assembleConfigItem
(
100
,
Con
figCons
ts
.
DEFAULT_CLUSTER_NAME
,
"5555"
,
"5555.k1"
,
"5555.v1"
);
configItems
[
4
]
=
assembleConfigItem
(
101
,
"cluster1"
,
"6666"
,
"6666.k1"
,
"6666.v1"
);
return
configItems
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录