Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zhangjian1949
apollo
提交
1af04408
apollo
项目概览
zhangjian1949
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
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,发现更多精彩内容 >>
提交
1af04408
编写于
3月 25, 2016
作者:
Y
Yiming Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Integrate service discovery in portal
上级
bebe9de4
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
393 addition
and
380 deletion
+393
-380
apollo-portal/src/main/java/com/ctrip/apollo/portal/entity/AppConfigVO.java
...main/java/com/ctrip/apollo/portal/entity/AppConfigVO.java
+1
-1
apollo-portal/src/main/java/com/ctrip/apollo/portal/enums/Env.java
...rtal/src/main/java/com/ctrip/apollo/portal/enums/Env.java
+0
-33
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ConfigService.java
...n/java/com/ctrip/apollo/portal/service/ConfigService.java
+267
-9
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ServiceLocator.java
.../java/com/ctrip/apollo/portal/service/ServiceLocator.java
+54
-0
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/impl/ConfigServiceImpl.java
...m/ctrip/apollo/portal/service/impl/ConfigServiceImpl.java
+0
-270
apollo-portal/src/test/java/com/ctrip/apollo/portal/service/ConfigServiceTest.java
...va/com/ctrip/apollo/portal/service/ConfigServiceTest.java
+70
-66
pom.xml
pom.xml
+1
-1
未找到文件。
apollo-portal/src/main/java/com/ctrip/apollo/portal/entity/AppConfigVO.java
浏览文件 @
1af04408
package
com.ctrip.apollo.portal.entity
;
package
com.ctrip.apollo.portal.entity
;
import
com.ctrip.apollo.Apollo.Env
;
import
com.ctrip.apollo.core.dto.ConfigItemDTO
;
import
com.ctrip.apollo.core.dto.ConfigItemDTO
;
import
com.ctrip.apollo.portal.enums.Env
;
import
java.util.LinkedList
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.List
;
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/enums/Env.java
已删除
100644 → 0
浏览文件 @
bebe9de4
package
com.ctrip.apollo.portal.enums
;
public
enum
Env
{
DEV
(
"dev"
),
FWS
(
"fws"
),
FAT
(
"fat"
),
UAT
(
"uat"
),
LPT
(
"lpt"
),
PROD
(
"prod"
),
TOOLS
(
"tools"
),
UN_KNOW
(
""
);
private
String
value
;
Env
(
String
value
)
{
this
.
value
=
value
;
}
public
static
Env
valueFrom
(
String
env
)
{
if
(
env
==
null
||
""
.
equals
(
env
))
{
return
UN_KNOW
;
}
else
if
(
"dev"
.
equals
(
env
))
{
return
DEV
;
}
else
if
(
"fws"
.
equals
(
env
))
{
return
FWS
;
}
else
if
(
"fat"
.
equals
(
env
))
{
return
FAT
;
}
else
if
(
"uat"
.
equals
(
env
))
{
return
UAT
;
}
else
if
(
"prod"
.
equals
(
env
))
{
return
PROD
;
}
else
if
(
"tools"
.
equals
(
env
))
{
return
TOOLS
;
}
else
{
return
UN_KNOW
;
}
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ConfigService.java
浏览文件 @
1af04408
package
com.ctrip.apollo.portal.service
;
package
com.ctrip.apollo.portal.service
;
import
java.io.IOException
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.ctrip.apollo.Apollo.Env
;
import
com.ctrip.apollo.core.Constants
;
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
com.ctrip.apollo.core.serivce.ApolloService
;
import
com.ctrip.apollo.portal.RestUtils
;
import
com.ctrip.apollo.portal.constants.PortalConstants
;
import
com.ctrip.apollo.portal.entity.AppConfigVO
;
import
com.ctrip.apollo.portal.entity.AppConfigVO
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.google.common.collect.Maps
;
public
interface
ConfigService
{
@Service
public
class
ConfigService
{
/**
@Autowired
* load config info by appId and versionId
private
ServiceLocator
serviceLocator
;
*/
AppConfigVO
loadReleaseConfig
(
long
appId
,
long
versionId
);
private
ObjectMapper
objectMapper
=
new
ObjectMapper
();
public
String
getAdminServiceUrl
()
{
List
<
ApolloService
>
services
=
serviceLocator
.
getAdminServices
(
Env
.
DEV
);
if
(
services
.
size
()
==
0
)
{
throw
new
RuntimeException
(
"No available admin service"
);
}
return
services
.
get
(
0
).
getHomepageUrl
();
}
public
AppConfigVO
loadReleaseConfig
(
long
appId
,
long
versionId
)
{
if
(
appId
<=
0
||
versionId
<=
0
)
{
return
null
;
}
long
releaseId
=
getReleaseIdFromVersionId
(
versionId
);
String
serviceHost
=
getAdminServiceUrl
();
ReleaseSnapshotDTO
[]
releaseSnapShots
=
RestUtils
.
exchangeInGET
(
serviceHost
+
"/configs/release/"
+
releaseId
,
ReleaseSnapshotDTO
[].
class
);
if
(
releaseSnapShots
==
null
||
releaseSnapShots
.
length
==
0
)
{
return
null
;
}
AppConfigVO
appConfigVO
=
AppConfigVO
.
newInstance
(
appId
,
versionId
);
for
(
ReleaseSnapshotDTO
snapShot
:
releaseSnapShots
)
{
// default cluster
if
(
Constants
.
DEFAULT_CLUSTER_NAME
.
equals
(
snapShot
.
getClusterName
()))
{
collectDefaultClusterConfigs
(
appId
,
snapShot
,
appConfigVO
);
}
else
{
// cluster special configs
collectSpecialClusterConfigs
(
appId
,
snapShot
,
appConfigVO
);
}
}
return
appConfigVO
;
}
private
long
getReleaseIdFromVersionId
(
long
versionId
)
{
String
serviceHost
=
getAdminServiceUrl
();
VersionDTO
version
=
RestUtils
.
exchangeInGET
(
serviceHost
+
"/version/"
+
versionId
,
VersionDTO
.
class
);
if
(
version
==
null
)
{
return
-
1
;
}
return
version
.
getReleaseId
();
}
private
void
collectDefaultClusterConfigs
(
long
appId
,
ReleaseSnapshotDTO
snapShot
,
AppConfigVO
appConfigVO
)
{
Map
<
Long
,
List
<
ConfigItemDTO
>>
groupedConfigs
=
groupConfigsByApp
(
snapShot
.
getConfigurations
());
List
<
AppConfigVO
.
OverrideAppConfig
>
overrideAppConfigs
=
appConfigVO
.
getOverrideAppConfigs
();
for
(
Map
.
Entry
<
Long
,
List
<
ConfigItemDTO
>>
entry
:
groupedConfigs
.
entrySet
())
{
long
configAppId
=
entry
.
getKey
();
List
<
ConfigItemDTO
>
kvs
=
entry
.
getValue
();
if
(
configAppId
==
appId
)
{
appConfigVO
.
setDefaultClusterConfigs
(
kvs
);
}
else
{
AppConfigVO
.
OverrideAppConfig
overrideAppConfig
=
new
AppConfigVO
.
OverrideAppConfig
();
overrideAppConfig
.
setAppId
(
configAppId
);
overrideAppConfig
.
setConfigs
(
kvs
);
overrideAppConfigs
.
add
(
overrideAppConfig
);
}
}
}
/**
/**
*
* appId -> List<KV>
* @param appId
* @return
*/
*/
AppConfigVO
loadLatestConfig
(
long
appId
);
private
Map
<
Long
,
List
<
ConfigItemDTO
>>
groupConfigsByApp
(
String
configJson
)
{
if
(
configJson
==
null
||
""
.
equals
(
configJson
))
{
return
Maps
.
newHashMap
();
}
Map
<
Long
,
List
<
ConfigItemDTO
>>
appIdMapKVs
=
new
HashMap
<>();
String
key
;
Object
value
;
Map
<
String
,
String
>
kvMaps
=
null
;
try
{
kvMaps
=
objectMapper
.
readValue
(
configJson
,
Map
.
class
);
}
catch
(
IOException
e
)
{
// todo log
}
for
(
Map
.
Entry
<
String
,
String
>
entry
:
kvMaps
.
entrySet
())
{
key
=
entry
.
getKey
();
value
=
entry
.
getValue
();
Long
appId
=
getAppIdFromKey
(
key
);
List
<
ConfigItemDTO
>
kvs
=
appIdMapKVs
.
get
(
appId
);
if
(
kvs
==
null
)
{
kvs
=
new
LinkedList
<>();
appIdMapKVs
.
put
(
appId
,
kvs
);
}
kvs
.
add
(
new
ConfigItemDTO
(
key
,
value
.
toString
()));
}
return
appIdMapKVs
;
}
private
Long
getAppIdFromKey
(
String
key
)
{
return
Long
.
valueOf
(
key
.
substring
(
0
,
key
.
indexOf
(
"."
)));
}
private
void
collectSpecialClusterConfigs
(
long
appId
,
ReleaseSnapshotDTO
snapShot
,
AppConfigVO
appConfigVO
)
{
List
<
AppConfigVO
.
OverrideClusterConfig
>
overrideClusterConfigs
=
appConfigVO
.
getOverrideClusterConfigs
();
AppConfigVO
.
OverrideClusterConfig
overrideClusterConfig
=
new
AppConfigVO
.
OverrideClusterConfig
();
overrideClusterConfig
.
setClusterName
(
snapShot
.
getClusterName
());
// todo step1: cluster special config can't override other app config
overrideClusterConfig
.
setConfigs
(
groupConfigsByApp
(
snapShot
.
getConfigurations
()).
get
(
appId
));
overrideClusterConfigs
.
add
(
overrideClusterConfig
);
}
public
AppConfigVO
loadLatestConfig
(
long
appId
)
{
if
(
appId
<=
0
)
{
return
null
;
}
String
serviceHost
=
getAdminServiceUrl
();
ClusterDTO
[]
clusters
=
RestUtils
.
exchangeInGET
(
serviceHost
+
"/cluster/app/"
+
appId
,
ClusterDTO
[].
class
);
if
(
clusters
==
null
||
clusters
.
length
==
0
)
{
return
null
;
}
StringBuilder
sb
=
new
StringBuilder
();
for
(
ClusterDTO
cluster
:
clusters
)
{
sb
.
append
(
cluster
.
getId
()).
append
(
","
);
}
ConfigItemDTO
[]
configItems
=
RestUtils
.
exchangeInGET
(
serviceHost
+
"/configs/latest?clusterIds="
+
sb
.
substring
(
0
,
sb
.
length
()
-
1
),
ConfigItemDTO
[].
class
);
return
buildAPPConfigVO
(
appId
,
Arrays
.
asList
(
configItems
));
}
private
AppConfigVO
buildAPPConfigVO
(
long
appId
,
List
<
ConfigItemDTO
>
configItems
)
{
if
(
configItems
==
null
||
configItems
.
size
()
==
0
)
{
return
null
;
}
Map
<
String
,
List
<
ConfigItemDTO
>>
groupedClusterConfigs
=
groupConfigByCluster
(
configItems
);
AppConfigVO
appConfigVO
=
AppConfigVO
.
newInstance
(
appId
,
PortalConstants
.
LASTEST_VERSION_ID
);
groupConfigByAppAndEnrichDTO
(
groupedClusterConfigs
,
appConfigVO
);
return
appConfigVO
;
}
private
Map
<
String
,
List
<
ConfigItemDTO
>>
groupConfigByCluster
(
List
<
ConfigItemDTO
>
configItems
)
{
Map
<
String
,
List
<
ConfigItemDTO
>>
groupedClusterConfigs
=
new
HashMap
<>();
String
clusterName
;
for
(
ConfigItemDTO
configItem
:
configItems
)
{
clusterName
=
configItem
.
getClusterName
();
List
<
ConfigItemDTO
>
clusterConfigs
=
groupedClusterConfigs
.
get
(
clusterName
);
if
(
clusterConfigs
==
null
)
{
clusterConfigs
=
new
LinkedList
<>();
groupedClusterConfigs
.
put
(
clusterName
,
clusterConfigs
);
}
clusterConfigs
.
add
(
configItem
);
}
return
groupedClusterConfigs
;
}
private
void
groupConfigByAppAndEnrichDTO
(
Map
<
String
,
List
<
ConfigItemDTO
>>
groupedClusterConfigs
,
AppConfigVO
appConfigVO
)
{
long
appId
=
appConfigVO
.
getAppId
();
List
<
ConfigItemDTO
>
defaultClusterConfigs
=
appConfigVO
.
getDefaultClusterConfigs
();
List
<
AppConfigVO
.
OverrideAppConfig
>
overrideAppConfigs
=
appConfigVO
.
getOverrideAppConfigs
();
List
<
AppConfigVO
.
OverrideClusterConfig
>
overrideClusterConfigs
=
appConfigVO
.
getOverrideClusterConfigs
();
String
clusterName
;
List
<
ConfigItemDTO
>
clusterConfigs
;
for
(
Map
.
Entry
<
String
,
List
<
ConfigItemDTO
>>
entry
:
groupedClusterConfigs
.
entrySet
())
{
clusterName
=
entry
.
getKey
();
clusterConfigs
=
entry
.
getValue
();
if
(
Constants
.
DEFAULT_CLUSTER_NAME
.
equals
(
clusterName
))
{
// default cluster configs
collectDefaultClusterConfigs
(
appId
,
clusterConfigs
,
defaultClusterConfigs
,
overrideAppConfigs
);
}
else
{
// override cluster configs
collectSpecialClusterConfigs
(
clusterName
,
clusterConfigs
,
overrideClusterConfigs
);
}
}
}
private
void
collectDefaultClusterConfigs
(
long
appId
,
List
<
ConfigItemDTO
>
clusterConfigs
,
List
<
ConfigItemDTO
>
defaultClusterConfigs
,
List
<
AppConfigVO
.
OverrideAppConfig
>
overrideAppConfigs
)
{
Map
<
Long
,
AppConfigVO
.
OverrideAppConfig
>
appIdMapOverrideAppConfig
=
null
;
for
(
ConfigItemDTO
config
:
clusterConfigs
)
{
long
targetAppId
=
config
.
getAppId
();
if
(
appId
==
targetAppId
)
{
// app self's configs
defaultClusterConfigs
.
add
(
config
);
}
else
{
// override other app configs
if
(
appIdMapOverrideAppConfig
==
null
)
{
appIdMapOverrideAppConfig
=
new
HashMap
<>();
}
AppConfigVO
.
OverrideAppConfig
overrideAppConfig
=
appIdMapOverrideAppConfig
.
get
(
targetAppId
);
if
(
overrideAppConfig
==
null
)
{
overrideAppConfig
=
new
AppConfigVO
.
OverrideAppConfig
();
appIdMapOverrideAppConfig
.
put
(
targetAppId
,
overrideAppConfig
);
overrideAppConfigs
.
add
(
overrideAppConfig
);
}
overrideAppConfig
.
setAppId
(
targetAppId
);
overrideAppConfig
.
addConfig
(
config
);
}
}
}
private
void
collectSpecialClusterConfigs
(
String
clusterName
,
List
<
ConfigItemDTO
>
clusterConfigs
,
List
<
AppConfigVO
.
OverrideClusterConfig
>
overrideClusterConfigs
)
{
AppConfigVO
.
OverrideClusterConfig
overrideClusterConfig
=
new
AppConfigVO
.
OverrideClusterConfig
();
overrideClusterConfig
.
setClusterName
(
clusterName
);
overrideClusterConfig
.
setConfigs
(
clusterConfigs
);
overrideClusterConfigs
.
add
(
overrideClusterConfig
);
}
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ServiceLocator.java
0 → 100644
浏览文件 @
1af04408
package
com.ctrip.apollo.portal.service
;
import
java.net.URI
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
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
;
/**
*
* @author liuym
*
*/
@Service
public
class
ServiceLocator
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ServiceLocator
.
class
);
private
RestTemplate
restTemplate
=
new
RestTemplate
();
private
List
<
ApolloService
>
serviceCaches
=
new
ArrayList
<>();
public
List
<
ApolloService
>
getAdminServices
(
Env
env
)
{
return
getServices
(
env
,
"admin"
);
}
public
List
<
ApolloService
>
getConfigServices
(
Env
env
)
{
return
getServices
(
env
,
"config"
);
}
private
List
<
ApolloService
>
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
);
if
(
services
!=
null
&&
services
.
length
>
0
)
{
serviceCaches
.
clear
();
for
(
ApolloService
service
:
services
)
{
serviceCaches
.
add
(
service
);
}
}
}
catch
(
Exception
ex
)
{
logger
.
warn
(
ex
.
getMessage
());
}
return
serviceCaches
;
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/impl/ConfigServiceImpl.java
已删除
100644 → 0
浏览文件 @
bebe9de4
package
com.ctrip.apollo.portal.service.impl
;
import
com.google.common.collect.Maps
;
import
com.ctrip.apollo.core.Constants
;
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
com.ctrip.apollo.portal.RestUtils
;
import
com.ctrip.apollo.portal.constants.PortalConstants
;
import
com.ctrip.apollo.portal.entity.AppConfigVO
;
import
com.ctrip.apollo.portal.service.ConfigService
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
org.springframework.stereotype.Service
;
import
java.io.IOException
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
@Service
public
class
ConfigServiceImpl
implements
ConfigService
{
public
static
final
String
ADMIN_SERVICE_HOST
=
"http://localhost:8090"
;
private
ObjectMapper
objectMapper
=
new
ObjectMapper
();
@Override
public
AppConfigVO
loadReleaseConfig
(
long
appId
,
long
versionId
)
{
if
(
appId
<=
0
||
versionId
<=
0
)
{
return
null
;
}
long
releaseId
=
getReleaseIdFromVersionId
(
versionId
);
ReleaseSnapshotDTO
[]
releaseSnapShots
=
RestUtils
.
exchangeInGET
(
ADMIN_SERVICE_HOST
+
"/configs/release/"
+
releaseId
,
ReleaseSnapshotDTO
[].
class
);
if
(
releaseSnapShots
==
null
||
releaseSnapShots
.
length
==
0
)
{
return
null
;
}
AppConfigVO
appConfigVO
=
AppConfigVO
.
newInstance
(
appId
,
versionId
);
for
(
ReleaseSnapshotDTO
snapShot
:
releaseSnapShots
)
{
//default cluster
if
(
Constants
.
DEFAULT_CLUSTER_NAME
.
equals
(
snapShot
.
getClusterName
()))
{
collectDefaultClusterConfigs
(
appId
,
snapShot
,
appConfigVO
);
}
else
{
//cluster special configs
collectSpecialClusterConfigs
(
appId
,
snapShot
,
appConfigVO
);
}
}
return
appConfigVO
;
}
private
long
getReleaseIdFromVersionId
(
long
versionId
)
{
VersionDTO
version
=
RestUtils
.
exchangeInGET
(
ADMIN_SERVICE_HOST
+
"/version/"
+
versionId
,
VersionDTO
.
class
);
if
(
version
==
null
)
{
return
-
1
;
}
return
version
.
getReleaseId
();
}
private
void
collectDefaultClusterConfigs
(
long
appId
,
ReleaseSnapshotDTO
snapShot
,
AppConfigVO
appConfigVO
)
{
Map
<
Long
,
List
<
ConfigItemDTO
>>
groupedConfigs
=
groupConfigsByApp
(
snapShot
.
getConfigurations
());
List
<
AppConfigVO
.
OverrideAppConfig
>
overrideAppConfigs
=
appConfigVO
.
getOverrideAppConfigs
();
for
(
Map
.
Entry
<
Long
,
List
<
ConfigItemDTO
>>
entry
:
groupedConfigs
.
entrySet
())
{
long
configAppId
=
entry
.
getKey
();
List
<
ConfigItemDTO
>
kvs
=
entry
.
getValue
();
if
(
configAppId
==
appId
)
{
appConfigVO
.
setDefaultClusterConfigs
(
kvs
);
}
else
{
AppConfigVO
.
OverrideAppConfig
overrideAppConfig
=
new
AppConfigVO
.
OverrideAppConfig
();
overrideAppConfig
.
setAppId
(
configAppId
);
overrideAppConfig
.
setConfigs
(
kvs
);
overrideAppConfigs
.
add
(
overrideAppConfig
);
}
}
}
/**
* appId -> List<KV>
*/
private
Map
<
Long
,
List
<
ConfigItemDTO
>>
groupConfigsByApp
(
String
configJson
)
{
if
(
configJson
==
null
||
""
.
equals
(
configJson
))
{
return
Maps
.
newHashMap
();
}
Map
<
Long
,
List
<
ConfigItemDTO
>>
appIdMapKVs
=
new
HashMap
<>();
String
key
;
Object
value
;
Map
<
String
,
String
>
kvMaps
=
null
;
try
{
kvMaps
=
objectMapper
.
readValue
(
configJson
,
Map
.
class
);
}
catch
(
IOException
e
)
{
//todo log
}
for
(
Map
.
Entry
<
String
,
String
>
entry
:
kvMaps
.
entrySet
())
{
key
=
entry
.
getKey
();
value
=
entry
.
getValue
();
Long
appId
=
getAppIdFromKey
(
key
);
List
<
ConfigItemDTO
>
kvs
=
appIdMapKVs
.
get
(
appId
);
if
(
kvs
==
null
)
{
kvs
=
new
LinkedList
<>();
appIdMapKVs
.
put
(
appId
,
kvs
);
}
kvs
.
add
(
new
ConfigItemDTO
(
key
,
value
.
toString
()));
}
return
appIdMapKVs
;
}
private
Long
getAppIdFromKey
(
String
key
)
{
return
Long
.
valueOf
(
key
.
substring
(
0
,
key
.
indexOf
(
"."
)));
}
private
void
collectSpecialClusterConfigs
(
long
appId
,
ReleaseSnapshotDTO
snapShot
,
AppConfigVO
appConfigVO
)
{
List
<
AppConfigVO
.
OverrideClusterConfig
>
overrideClusterConfigs
=
appConfigVO
.
getOverrideClusterConfigs
();
AppConfigVO
.
OverrideClusterConfig
overrideClusterConfig
=
new
AppConfigVO
.
OverrideClusterConfig
();
overrideClusterConfig
.
setClusterName
(
snapShot
.
getClusterName
());
//todo step1: cluster special config can't override other app config
overrideClusterConfig
.
setConfigs
(
groupConfigsByApp
(
snapShot
.
getConfigurations
()).
get
(
appId
));
overrideClusterConfigs
.
add
(
overrideClusterConfig
);
}
@Override
public
AppConfigVO
loadLatestConfig
(
long
appId
)
{
if
(
appId
<=
0
)
{
return
null
;
}
ClusterDTO
[]
clusters
=
RestUtils
.
exchangeInGET
(
ADMIN_SERVICE_HOST
+
"/cluster/app/"
+
appId
,
ClusterDTO
[].
class
);
if
(
clusters
==
null
||
clusters
.
length
==
0
)
{
return
null
;
}
StringBuilder
sb
=
new
StringBuilder
();
for
(
ClusterDTO
cluster
:
clusters
)
{
sb
.
append
(
cluster
.
getId
()).
append
(
","
);
}
ConfigItemDTO
[]
configItems
=
RestUtils
.
exchangeInGET
(
ADMIN_SERVICE_HOST
+
"/configs/latest?clusterIds="
+
sb
.
substring
(
0
,
sb
.
length
()
-
1
),
ConfigItemDTO
[].
class
);
return
buildAPPConfigVO
(
appId
,
Arrays
.
asList
(
configItems
));
}
private
AppConfigVO
buildAPPConfigVO
(
long
appId
,
List
<
ConfigItemDTO
>
configItems
)
{
if
(
configItems
==
null
||
configItems
.
size
()
==
0
)
{
return
null
;
}
Map
<
String
,
List
<
ConfigItemDTO
>>
groupedClusterConfigs
=
groupConfigByCluster
(
configItems
);
AppConfigVO
appConfigVO
=
AppConfigVO
.
newInstance
(
appId
,
PortalConstants
.
LASTEST_VERSION_ID
);
groupConfigByAppAndEnrichDTO
(
groupedClusterConfigs
,
appConfigVO
);
return
appConfigVO
;
}
private
Map
<
String
,
List
<
ConfigItemDTO
>>
groupConfigByCluster
(
List
<
ConfigItemDTO
>
configItems
)
{
Map
<
String
,
List
<
ConfigItemDTO
>>
groupedClusterConfigs
=
new
HashMap
<>();
String
clusterName
;
for
(
ConfigItemDTO
configItem
:
configItems
)
{
clusterName
=
configItem
.
getClusterName
();
List
<
ConfigItemDTO
>
clusterConfigs
=
groupedClusterConfigs
.
get
(
clusterName
);
if
(
clusterConfigs
==
null
)
{
clusterConfigs
=
new
LinkedList
<>();
groupedClusterConfigs
.
put
(
clusterName
,
clusterConfigs
);
}
clusterConfigs
.
add
(
configItem
);
}
return
groupedClusterConfigs
;
}
private
void
groupConfigByAppAndEnrichDTO
(
Map
<
String
,
List
<
ConfigItemDTO
>>
groupedClusterConfigs
,
AppConfigVO
appConfigVO
)
{
long
appId
=
appConfigVO
.
getAppId
();
List
<
ConfigItemDTO
>
defaultClusterConfigs
=
appConfigVO
.
getDefaultClusterConfigs
();
List
<
AppConfigVO
.
OverrideAppConfig
>
overrideAppConfigs
=
appConfigVO
.
getOverrideAppConfigs
();
List
<
AppConfigVO
.
OverrideClusterConfig
>
overrideClusterConfigs
=
appConfigVO
.
getOverrideClusterConfigs
();
String
clusterName
;
List
<
ConfigItemDTO
>
clusterConfigs
;
for
(
Map
.
Entry
<
String
,
List
<
ConfigItemDTO
>>
entry
:
groupedClusterConfigs
.
entrySet
())
{
clusterName
=
entry
.
getKey
();
clusterConfigs
=
entry
.
getValue
();
if
(
Constants
.
DEFAULT_CLUSTER_NAME
.
equals
(
clusterName
))
{
//default cluster configs
collectDefaultClusterConfigs
(
appId
,
clusterConfigs
,
defaultClusterConfigs
,
overrideAppConfigs
);
}
else
{
//override cluster configs
collectSpecialClusterConfigs
(
clusterName
,
clusterConfigs
,
overrideClusterConfigs
);
}
}
}
private
void
collectDefaultClusterConfigs
(
long
appId
,
List
<
ConfigItemDTO
>
clusterConfigs
,
List
<
ConfigItemDTO
>
defaultClusterConfigs
,
List
<
AppConfigVO
.
OverrideAppConfig
>
overrideAppConfigs
)
{
Map
<
Long
,
AppConfigVO
.
OverrideAppConfig
>
appIdMapOverrideAppConfig
=
null
;
for
(
ConfigItemDTO
config
:
clusterConfigs
)
{
long
targetAppId
=
config
.
getAppId
();
if
(
appId
==
targetAppId
)
{
//app self's configs
defaultClusterConfigs
.
add
(
config
);
}
else
{
//override other app configs
if
(
appIdMapOverrideAppConfig
==
null
)
{
appIdMapOverrideAppConfig
=
new
HashMap
<>();
}
AppConfigVO
.
OverrideAppConfig
overrideAppConfig
=
appIdMapOverrideAppConfig
.
get
(
targetAppId
);
if
(
overrideAppConfig
==
null
)
{
overrideAppConfig
=
new
AppConfigVO
.
OverrideAppConfig
();
appIdMapOverrideAppConfig
.
put
(
targetAppId
,
overrideAppConfig
);
overrideAppConfigs
.
add
(
overrideAppConfig
);
}
overrideAppConfig
.
setAppId
(
targetAppId
);
overrideAppConfig
.
addConfig
(
config
);
}
}
}
private
void
collectSpecialClusterConfigs
(
String
clusterName
,
List
<
ConfigItemDTO
>
clusterConfigs
,
List
<
AppConfigVO
.
OverrideClusterConfig
>
overrideClusterConfigs
)
{
AppConfigVO
.
OverrideClusterConfig
overrideClusterConfig
=
new
AppConfigVO
.
OverrideClusterConfig
();
overrideClusterConfig
.
setClusterName
(
clusterName
);
overrideClusterConfig
.
setConfigs
(
clusterConfigs
);
overrideClusterConfigs
.
add
(
overrideClusterConfig
);
}
}
apollo-portal/src/test/java/com/ctrip/apollo/portal/service/ConfigServiceTest.java
浏览文件 @
1af04408
package
com.ctrip.apollo.portal.service
;
package
com.ctrip.apollo.portal.service
;
import
com.ctrip.apollo.core.dto.ClusterDTO
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
com.ctrip.apollo.core.dto.ConfigItemDTO
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
com.ctrip.apollo.core.dto.ReleaseSnapshotDTO
;
import
static
org
.
mockito
.
Matchers
.
eq
;
import
com.ctrip.apollo.core.dto.VersionDTO
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
com.ctrip.apollo.portal.RestUtils
;
import
com.ctrip.apollo.portal.constants.PortalConstants
;
import
java.util.ArrayList
;
import
com.ctrip.apollo.portal.entity.AppConfigVO
;
import
java.util.List
;
import
com.ctrip.apollo.portal.service.impl.ConfigServiceImpl
;
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.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.Mockito
;
import
org.mockito.Spy
;
import
org.mockito.runners.MockitoJUnitRunner
;
import
org.mockito.runners.MockitoJUnitRunner
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
...
@@ -21,10 +24,15 @@ import org.springframework.http.ResponseEntity;
...
@@ -21,10 +24,15 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.test.util.ReflectionTestUtils
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.client.RestTemplate
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
com.ctrip.apollo.Apollo.Env
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
com.ctrip.apollo.core.dto.ClusterDTO
;
import
static
org
.
mockito
.
Matchers
.
eq
;
import
com.ctrip.apollo.core.dto.ConfigItemDTO
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
com.ctrip.apollo.core.dto.ReleaseSnapshotDTO
;
import
com.ctrip.apollo.core.dto.VersionDTO
;
import
com.ctrip.apollo.core.serivce.ApolloService
;
import
com.ctrip.apollo.portal.RestUtils
;
import
com.ctrip.apollo.portal.constants.PortalConstants
;
import
com.ctrip.apollo.portal.entity.AppConfigVO
;
@RunWith
(
MockitoJUnitRunner
.
class
)
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
ConfigServiceTest
{
public
class
ConfigServiceTest
{
...
@@ -40,12 +48,20 @@ public class ConfigServiceTest {
...
@@ -40,12 +48,20 @@ public class ConfigServiceTest {
@Mock
@Mock
private
ResponseEntity
configItemResponse
;
private
ResponseEntity
configItemResponse
;
private
ConfigServiceImpl
configService
;
@InjectMocks
private
ConfigService
configService
;
@Spy
private
ServiceLocator
serviceLocator
;
@Before
@Before
public
void
setUp
()
{
public
void
setUp
()
{
ReflectionTestUtils
.
setField
(
RestUtils
.
class
,
"restTemplate"
,
restTemplate
);
ReflectionTestUtils
.
setField
(
RestUtils
.
class
,
"restTemplate"
,
restTemplate
);
configService
=
new
ConfigServiceImpl
();
ApolloService
defaultAdminService
=
new
ApolloService
();
defaultAdminService
.
setHomepageUrl
(
"http://localhost:8090"
);
List
<
ApolloService
>
services
=
new
ArrayList
<>();
services
.
add
(
defaultAdminService
);
Mockito
.
doReturn
(
services
).
when
(
serviceLocator
).
getAdminServices
(
Env
.
DEV
);
}
}
@Test
@Test
...
@@ -57,11 +73,11 @@ public class ConfigServiceTest {
...
@@ -57,11 +73,11 @@ public class ConfigServiceTest {
VersionDTO
someVersion
=
assembleVersion
(
appId
,
"1.0"
,
releaseId
);
VersionDTO
someVersion
=
assembleVersion
(
appId
,
"1.0"
,
releaseId
);
ReleaseSnapshotDTO
[]
someReleaseSnapShots
=
assembleReleaseSnapShots
();
ReleaseSnapshotDTO
[]
someReleaseSnapShots
=
assembleReleaseSnapShots
();
restInvoke
(
ConfigServiceImpl
.
ADMIN_SERVICE_HOST
+
"/configs/release/"
restInvoke
(
configService
.
getAdminServiceUrl
()
+
"/configs/release/"
+
releaseId
,
+
releaseId
,
ReleaseSnapshotDTO
[].
class
,
someReleaseSnapShots
,
releaseSnapShotResponse
);
ReleaseSnapshotDTO
[].
class
,
someReleaseSnapShots
,
releaseSnapShotResponse
);
restInvoke
(
ConfigServiceImpl
.
ADMIN_SERVICE_HOST
+
"/version/"
restInvoke
(
configService
.
getAdminServiceUrl
()
+
"/version/"
+
versionId
,
VersionDTO
.
class
,
+
versionId
,
VersionDTO
.
class
,
someVersion
,
versionResponse
);
someVersion
,
versionResponse
);
AppConfigVO
appConfigVO
=
configService
.
loadReleaseConfig
(
appId
,
versionId
);
AppConfigVO
appConfigVO
=
configService
.
loadReleaseConfig
(
appId
,
versionId
);
...
@@ -80,15 +96,14 @@ public class ConfigServiceTest {
...
@@ -80,15 +96,14 @@ public class ConfigServiceTest {
VersionDTO
someVersion
=
assembleVersion
(
appId
,
"1.0"
,
releaseId
);
VersionDTO
someVersion
=
assembleVersion
(
appId
,
"1.0"
,
releaseId
);
ReleaseSnapshotDTO
[]
releaseSnapShots
=
new
ReleaseSnapshotDTO
[
1
];
ReleaseSnapshotDTO
[]
releaseSnapShots
=
new
ReleaseSnapshotDTO
[
1
];
releaseSnapShots
[
0
]
=
releaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
"default-cluster-name"
,
assembleReleaseSnapShot
(
11111
,
"default-cluster-name"
,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}"
);
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}"
);
restInvoke
(
ConfigServiceImpl
.
ADMIN_SERVICE_HOST
+
"/configs/release/"
restInvoke
(
configService
.
getAdminServiceUrl
()
+
"/configs/release/"
+
releaseId
,
+
releaseId
,
ReleaseSnapshotDTO
[].
class
,
releaseSnapShots
,
releaseSnapShotResponse
);
ReleaseSnapshotDTO
[].
class
,
releaseSnapShots
,
releaseSnapShotResponse
);
restInvoke
(
ConfigServiceImpl
.
ADMIN_SERVICE_HOST
+
"/version/"
restInvoke
(
configService
.
getAdminServiceUrl
()
+
"/version/"
+
versionId
,
VersionDTO
.
class
,
+
versionId
,
VersionDTO
.
class
,
someVersion
,
versionResponse
);
someVersion
,
versionResponse
);
AppConfigVO
appConfigVO
=
configService
.
loadReleaseConfig
(
appId
,
versionId
);
AppConfigVO
appConfigVO
=
configService
.
loadReleaseConfig
(
appId
,
versionId
);
...
@@ -106,15 +121,14 @@ public class ConfigServiceTest {
...
@@ -106,15 +121,14 @@ public class ConfigServiceTest {
long
releaseId
=
11111
;
long
releaseId
=
11111
;
VersionDTO
someVersion
=
assembleVersion
(
appId
,
"1.0"
,
releaseId
);
VersionDTO
someVersion
=
assembleVersion
(
appId
,
"1.0"
,
releaseId
);
ReleaseSnapshotDTO
[]
releaseSnapShots
=
new
ReleaseSnapshotDTO
[
1
];
ReleaseSnapshotDTO
[]
releaseSnapShots
=
new
ReleaseSnapshotDTO
[
1
];
releaseSnapShots
[
0
]
=
releaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
"default-cluster-name"
,
assembleReleaseSnapShot
(
11111
,
"default-cluster-name"
,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\", \"5555.bar\":\"demo2\", \"22.bar\":\"demo2\"}"
);
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\", \"5555.bar\":\"demo2\", \"22.bar\":\"demo2\"}"
);
restInvoke
(
ConfigServiceImpl
.
ADMIN_SERVICE_HOST
+
"/configs/release/"
restInvoke
(
configService
.
getAdminServiceUrl
()
+
"/configs/release/"
+
releaseId
,
+
releaseId
,
ReleaseSnapshotDTO
[].
class
,
releaseSnapShots
,
releaseSnapShotResponse
);
ReleaseSnapshotDTO
[].
class
,
releaseSnapShots
,
releaseSnapShotResponse
);
restInvoke
(
ConfigServiceImpl
.
ADMIN_SERVICE_HOST
+
"/version/"
restInvoke
(
configService
.
getAdminServiceUrl
()
+
"/version/"
+
versionId
,
VersionDTO
.
class
,
+
versionId
,
VersionDTO
.
class
,
someVersion
,
versionResponse
);
someVersion
,
versionResponse
);
AppConfigVO
appConfigVO
=
configService
.
loadReleaseConfig
(
appId
,
versionId
);
AppConfigVO
appConfigVO
=
configService
.
loadReleaseConfig
(
appId
,
versionId
);
...
@@ -132,18 +146,16 @@ public class ConfigServiceTest {
...
@@ -132,18 +146,16 @@ public class ConfigServiceTest {
long
releaseId
=
11111
;
long
releaseId
=
11111
;
VersionDTO
someVersion
=
assembleVersion
(
appId
,
"1.0"
,
releaseId
);
VersionDTO
someVersion
=
assembleVersion
(
appId
,
"1.0"
,
releaseId
);
ReleaseSnapshotDTO
[]
releaseSnapShots
=
new
ReleaseSnapshotDTO
[
2
];
ReleaseSnapshotDTO
[]
releaseSnapShots
=
new
ReleaseSnapshotDTO
[
2
];
releaseSnapShots
[
0
]
=
releaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
"default-cluster-name"
,
assembleReleaseSnapShot
(
11111
,
"default-cluster-name"
,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}"
);
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}"
);
releaseSnapShots
[
1
]
=
assembleReleaseSnapShot
(
11112
,
"cluster1"
,
releaseSnapShots
[
1
]
=
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}"
);
assembleReleaseSnapShot
(
11112
,
"cluster1"
,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}"
);
restInvoke
(
ConfigServiceImpl
.
ADMIN_SERVICE_HOST
+
"/configs/release/"
restInvoke
(
configService
.
getAdminServiceUrl
()
+
"/configs/release/"
+
releaseId
,
+
releaseId
,
ReleaseSnapshotDTO
[].
class
,
releaseSnapShots
,
releaseSnapShotResponse
);
ReleaseSnapshotDTO
[].
class
,
releaseSnapShots
,
releaseSnapShotResponse
);
restInvoke
(
ConfigServiceImpl
.
ADMIN_SERVICE_HOST
+
"/version/"
restInvoke
(
configService
.
getAdminServiceUrl
()
+
"/version/"
+
versionId
,
VersionDTO
.
class
,
+
versionId
,
VersionDTO
.
class
,
someVersion
,
versionResponse
);
someVersion
,
versionResponse
);
AppConfigVO
appConfigVO
=
configService
.
loadReleaseConfig
(
appId
,
versionId
);
AppConfigVO
appConfigVO
=
configService
.
loadReleaseConfig
(
appId
,
versionId
);
...
@@ -160,12 +172,11 @@ public class ConfigServiceTest {
...
@@ -160,12 +172,11 @@ public class ConfigServiceTest {
ClusterDTO
[]
someClusters
=
assembleClusters
();
ClusterDTO
[]
someClusters
=
assembleClusters
();
ConfigItemDTO
[]
someConfigItem
=
assembleConfigItems
();
ConfigItemDTO
[]
someConfigItem
=
assembleConfigItems
();
restInvoke
(
ConfigServiceImpl
.
ADMIN_SERVICE_HOST
+
"/cluster/app/"
restInvoke
(
configService
.
getAdminServiceUrl
()
+
"/cluster/app/"
+
appId
,
ClusterDTO
[].
class
,
+
appId
,
ClusterDTO
[].
class
,
someClusters
,
clusterResponse
);
someClusters
,
clusterResponse
);
restInvoke
(
ConfigServiceImpl
.
ADMIN_SERVICE_HOST
restInvoke
(
configService
.
getAdminServiceUrl
()
+
"/configs/latest?clusterIds=100,101"
,
+
"/configs/latest?clusterIds=100,101"
,
ConfigItemDTO
[].
class
,
someConfigItem
,
ConfigItemDTO
[].
class
,
someConfigItem
,
configItemResponse
);
configItemResponse
);
AppConfigVO
appConfigVO
=
configService
.
loadLatestConfig
(
appId
);
AppConfigVO
appConfigVO
=
configService
.
loadLatestConfig
(
appId
);
...
@@ -177,10 +188,10 @@ public class ConfigServiceTest {
...
@@ -177,10 +188,10 @@ public class ConfigServiceTest {
}
}
private
<
T
>
void
restInvoke
(
String
url
,
Class
<
T
>
responseType
,
T
result
,
private
<
T
>
void
restInvoke
(
String
url
,
Class
<
T
>
responseType
,
T
result
,
ResponseEntity
someResponse
)
{
ResponseEntity
someResponse
)
{
when
(
when
(
restTemplate
.
exchange
(
eq
(
url
),
eq
(
HttpMethod
.
GET
),
any
(
HttpEntity
.
class
),
eq
(
responseType
)))
restTemplate
.
exchange
(
eq
(
url
),
eq
(
HttpMethod
.
GET
),
any
(
HttpEntity
.
class
),
eq
(
responseType
)))
.
thenReturn
(
someResponse
);
.
thenReturn
(
someResponse
);
when
(
someResponse
.
getStatusCode
()).
thenReturn
(
HttpStatus
.
OK
);
when
(
someResponse
.
getStatusCode
()).
thenReturn
(
HttpStatus
.
OK
);
when
(
someResponse
.
getBody
()).
thenReturn
(
result
);
when
(
someResponse
.
getBody
()).
thenReturn
(
result
);
}
}
...
@@ -195,18 +206,15 @@ public class ConfigServiceTest {
...
@@ -195,18 +206,15 @@ public class ConfigServiceTest {
private
ReleaseSnapshotDTO
[]
assembleReleaseSnapShots
()
{
private
ReleaseSnapshotDTO
[]
assembleReleaseSnapShots
()
{
ReleaseSnapshotDTO
[]
releaseSnapShots
=
new
ReleaseSnapshotDTO
[
3
];
ReleaseSnapshotDTO
[]
releaseSnapShots
=
new
ReleaseSnapshotDTO
[
3
];
releaseSnapShots
[
0
]
=
releaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
"default-cluster-name"
,
assembleReleaseSnapShot
(
11111
,
"default-cluster-name"
,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\",\"3333.foo\":\"1008\",\"4444.bar\":\"99901\"}"
);
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\",\"3333.foo\":\"1008\",\"4444.bar\":\"99901\"}"
);
releaseSnapShots
[
1
]
=
assembleReleaseSnapShot
(
11111
,
"cluster1"
,
"{\"6666.foo\":\"demo1\"}"
);
releaseSnapShots
[
1
]
=
releaseSnapShots
[
2
]
=
assembleReleaseSnapShot
(
11111
,
"cluster2"
,
"{\"6666.bar\":\"bar2222\"}"
);
assembleReleaseSnapShot
(
11111
,
"cluster1"
,
"{\"6666.foo\":\"demo1\"}"
);
releaseSnapShots
[
2
]
=
assembleReleaseSnapShot
(
11111
,
"cluster2"
,
"{\"6666.bar\":\"bar2222\"}"
);
return
releaseSnapShots
;
return
releaseSnapShots
;
}
}
private
ReleaseSnapshotDTO
assembleReleaseSnapShot
(
long
releaseId
,
String
clusterName
,
private
ReleaseSnapshotDTO
assembleReleaseSnapShot
(
long
releaseId
,
String
clusterName
,
String
configurations
)
{
String
configurations
)
{
ReleaseSnapshotDTO
releaseSnapShot
=
new
ReleaseSnapshotDTO
();
ReleaseSnapshotDTO
releaseSnapShot
=
new
ReleaseSnapshotDTO
();
releaseSnapShot
.
setReleaseId
(
releaseId
);
releaseSnapShot
.
setReleaseId
(
releaseId
);
releaseSnapShot
.
setClusterName
(
clusterName
);
releaseSnapShot
.
setClusterName
(
clusterName
);
...
@@ -231,20 +239,16 @@ public class ConfigServiceTest {
...
@@ -231,20 +239,16 @@ public class ConfigServiceTest {
private
ConfigItemDTO
[]
assembleConfigItems
()
{
private
ConfigItemDTO
[]
assembleConfigItems
()
{
ConfigItemDTO
[]
configItems
=
new
ConfigItemDTO
[
5
];
ConfigItemDTO
[]
configItems
=
new
ConfigItemDTO
[
5
];
configItems
[
0
]
=
configItems
[
0
]
=
assembleConfigItem
(
100
,
"default-cluster-name"
,
6666
,
"6666.k1"
,
"6666.v1"
);
assembleConfigItem
(
100
,
"default-cluster-name"
,
6666
,
"6666.k1"
,
"6666.v1"
);
configItems
[
1
]
=
assembleConfigItem
(
100
,
"default-cluster-name"
,
6666
,
"6666.k2"
,
"6666.v2"
);
configItems
[
1
]
=
configItems
[
2
]
=
assembleConfigItem
(
100
,
"default-cluster-name"
,
6666
,
"6666.k3"
,
"6666.v3"
);
assembleConfigItem
(
100
,
"default-cluster-name"
,
6666
,
"6666.k2"
,
"6666.v2"
);
configItems
[
3
]
=
assembleConfigItem
(
100
,
"default-cluster-name"
,
5555
,
"5555.k1"
,
"5555.v1"
);
configItems
[
2
]
=
assembleConfigItem
(
100
,
"default-cluster-name"
,
6666
,
"6666.k3"
,
"6666.v3"
);
configItems
[
3
]
=
assembleConfigItem
(
100
,
"default-cluster-name"
,
5555
,
"5555.k1"
,
"5555.v1"
);
configItems
[
4
]
=
assembleConfigItem
(
101
,
"cluster1"
,
6666
,
"6666.k1"
,
"6666.v1"
);
configItems
[
4
]
=
assembleConfigItem
(
101
,
"cluster1"
,
6666
,
"6666.k1"
,
"6666.v1"
);
return
configItems
;
return
configItems
;
}
}
private
ConfigItemDTO
assembleConfigItem
(
long
clusterId
,
String
clusterName
,
int
appId
,
private
ConfigItemDTO
assembleConfigItem
(
long
clusterId
,
String
clusterName
,
int
appId
,
String
key
,
String
value
)
{
String
key
,
String
value
)
{
ConfigItemDTO
configItem
=
new
ConfigItemDTO
();
ConfigItemDTO
configItem
=
new
ConfigItemDTO
();
configItem
.
setClusterName
(
clusterName
);
configItem
.
setClusterName
(
clusterName
);
configItem
.
setClusterId
(
clusterId
);
configItem
.
setClusterId
(
clusterId
);
...
...
pom.xml
浏览文件 @
1af04408
...
@@ -164,7 +164,7 @@
...
@@ -164,7 +164,7 @@
<plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-war-plugin
</artifactId>
<artifactId>
maven-war-plugin
</artifactId>
<version>
2.
3
</version>
<version>
2.
6
</version>
<configuration>
<configuration>
<failOnMissingWebXml>
false
</failOnMissingWebXml>
<failOnMissingWebXml>
false
</failOnMissingWebXml>
</configuration>
</configuration>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录