Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wrr-cat
apollo
提交
8563b8b9
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,发现更多精彩内容 >>
提交
8563b8b9
编写于
3月 28, 2016
作者:
J
Jason Song
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #47 from lepdou/portal_optimize
重构portal api
上级
babb3c6a
ff0364c1
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
244 addition
and
158 deletion
+244
-158
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/impl/AdminConfigServiceImpl.java
...ctrip/apollo/biz/service/impl/AdminConfigServiceImpl.java
+3
-0
apollo-biz/src/main/resources/import.sql
apollo-biz/src/main/resources/import.sql
+5
-5
apollo-portal/src/main/java/com/ctrip/apollo/portal/RestUtils.java
...rtal/src/main/java/com/ctrip/apollo/portal/RestUtils.java
+0
-17
apollo-portal/src/main/java/com/ctrip/apollo/portal/api/API.java
...portal/src/main/java/com/ctrip/apollo/portal/api/API.java
+21
-0
apollo-portal/src/main/java/com/ctrip/apollo/portal/api/AdminServiceAPI.java
...ain/java/com/ctrip/apollo/portal/api/AdminServiceAPI.java
+80
-0
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ConfigService.java
...n/java/com/ctrip/apollo/portal/service/ConfigService.java
+28
-26
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ServiceLocator.java
.../java/com/ctrip/apollo/portal/service/ServiceLocator.java
+0
-2
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/VersionService.java
.../java/com/ctrip/apollo/portal/service/VersionService.java
+11
-5
apollo-portal/src/main/resources/application.yml
apollo-portal/src/main/resources/application.yml
+1
-1
apollo-portal/src/main/resources/static/styles/common-style.css
...-portal/src/main/resources/static/styles/common-style.css
+4
-0
apollo-portal/src/main/resources/static/views/app/config.html
...lo-portal/src/main/resources/static/views/app/config.html
+23
-23
apollo-portal/src/test/java/com/ctrip/apollo/portal/service/ConfigServiceTest.java
...va/com/ctrip/apollo/portal/service/ConfigServiceTest.java
+53
-72
apollo-portal/src/test/resources/application.yml
apollo-portal/src/test/resources/application.yml
+15
-7
未找到文件。
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/impl/AdminConfigServiceImpl.java
浏览文件 @
8563b8b9
...
...
@@ -77,6 +77,9 @@ public class AdminConfigServiceImpl implements AdminConfigService {
return
null
;
}
Version
version
=
versionRepository
.
findById
(
versionId
);
if
(
version
==
null
){
return
null
;
}
return
version
.
toDTO
();
}
...
...
apollo-biz/src/main/resources/import.sql
浏览文件 @
8563b8b9
...
...
@@ -15,12 +15,12 @@ INSERT INTO RELEASESNAPSHOT (ClusterName, IsDeleted, ReleaseId, Configurations)
INSERT
INTO
RELEASESNAPSHOT
(
ClusterName
,
IsDeleted
,
ReleaseId
,
Configurations
)
VALUES
(
'cluster2'
,
0
,
11111
,
'{"6666.bar":"bar2222"}'
);
INSERT
INTO
RELEASESNAPSHOT
(
ClusterName
,
IsDeleted
,
ReleaseId
,
Configurations
)
VALUES
(
'default'
,
0
,
11112
,
'{"6666.foo":"verson2.0", "6666.bar":"verson2.0","3333.foo":"1008","4444.bar":"99901"}'
);
INSERT
INTO
ConfigItem
(
ClusterId
,
ClusterName
,
AppId
,
Key
,
Value
,
comment
,
DataChange_CreatedBy
,
DataChange_CreatedTime
,
DataChange_LastModifiedBy
,
DataChange_Last
Modified
Time
,
IsDeleted
)
VALUES
(
100
,
'default'
,
6666
,
'6666.k1'
,
'6666.v1'
,
'comment1'
,
'lepdou'
,
'2016-03-23 12:00:00'
,
'王五'
,
NOW
(),
0
);
INSERT
INTO
ConfigItem
(
ClusterId
,
ClusterName
,
AppId
,
Key
,
Value
,
comment
,
DataChange_CreatedBy
,
DataChange_CreatedTime
,
DataChange_LastModifiedBy
,
DataChange_LastTime
,
IsDeleted
)
VALUES
(
100
,
'default'
,
6666
,
'6666.k1'
,
'6666.v1'
,
'comment1'
,
'lepdou'
,
'2016-03-23 12:00:00'
,
'王五'
,
NOW
(),
0
);
INSERT
INTO
ConfigItem
(
ClusterId
,
ClusterName
,
AppId
,
Key
,
Value
,
comment
,
DataChange_CreatedBy
,
DataChange_CreatedTime
,
DataChange_LastModifiedBy
,
DataChange_Last
Modified
Time
,
IsDeleted
)
VALUES
(
100
,
'default'
,
6666
,
'6666.k2'
,
'6666.v2'
,
'xxxx'
,
'lepdou'
,
'2016-03-23 12:00:00'
,
'王五1'
,
NOW
(),
0
);
INSERT
INTO
ConfigItem
(
ClusterId
,
ClusterName
,
AppId
,
Key
,
Value
,
comment
,
DataChange_CreatedBy
,
DataChange_CreatedTime
,
DataChange_LastModifiedBy
,
DataChange_LastTime
,
IsDeleted
)
VALUES
(
100
,
'default'
,
6666
,
'6666.k2'
,
'6666.v2'
,
'xxxx'
,
'lepdou'
,
'2016-03-23 12:00:00'
,
'王五1'
,
NOW
(),
0
);
INSERT
INTO
ConfigItem
(
ClusterId
,
ClusterName
,
AppId
,
Key
,
Value
,
comment
,
DataChange_CreatedBy
,
DataChange_CreatedTime
,
DataChange_LastModifiedBy
,
DataChange_Last
Modified
Time
,
IsDeleted
)
VALUES
(
100
,
'default'
,
6666
,
'6666.k3'
,
'6666.v3'
,
'yyyy'
,
'lepdou'
,
'2016-03-23 12:00:00'
,
'王五2'
,
NOW
(),
0
);
INSERT
INTO
ConfigItem
(
ClusterId
,
ClusterName
,
AppId
,
Key
,
Value
,
comment
,
DataChange_CreatedBy
,
DataChange_CreatedTime
,
DataChange_LastModifiedBy
,
DataChange_LastTime
,
IsDeleted
)
VALUES
(
100
,
'default'
,
6666
,
'6666.k3'
,
'6666.v3'
,
'yyyy'
,
'lepdou'
,
'2016-03-23 12:00:00'
,
'王五2'
,
NOW
(),
0
);
INSERT
INTO
ConfigItem
(
ClusterId
,
ClusterName
,
AppId
,
Key
,
Value
,
comment
,
DataChange_CreatedBy
,
DataChange_CreatedTime
,
DataChange_LastModifiedBy
,
DataChange_Last
Modified
Time
,
IsDeleted
)
VALUES
(
100
,
'default'
,
5555
,
'5555.k1'
,
'5555.v11'
,
'zzzz'
,
'lepdou'
,
'2016-03-23 12:00:00'
,
'王五3'
,
NOW
(),
0
);
INSERT
INTO
ConfigItem
(
ClusterId
,
ClusterName
,
AppId
,
Key
,
Value
,
comment
,
DataChange_CreatedBy
,
DataChange_CreatedTime
,
DataChange_LastModifiedBy
,
DataChange_LastTime
,
IsDeleted
)
VALUES
(
100
,
'default'
,
5555
,
'5555.k1'
,
'5555.v11'
,
'zzzz'
,
'lepdou'
,
'2016-03-23 12:00:00'
,
'王五3'
,
NOW
(),
0
);
INSERT
INTO
ConfigItem
(
ClusterId
,
ClusterName
,
AppId
,
Key
,
Value
,
comment
,
DataChange_CreatedBy
,
DataChange_CreatedTime
,
DataChange_LastModifiedBy
,
DataChange_Last
Modified
Time
,
IsDeleted
)
VALUES
(
101
,
'cluster1'
,
6666
,
'6666.k1'
,
'6666.v122'
,
'qqqqq'
,
'lepdou'
,
'2016-03-23 12:00:00'
,
'王五4'
,
NOW
(),
0
);
INSERT
INTO
ConfigItem
(
ClusterId
,
ClusterName
,
AppId
,
Key
,
Value
,
comment
,
DataChange_CreatedBy
,
DataChange_CreatedTime
,
DataChange_LastModifiedBy
,
DataChange_LastTime
,
IsDeleted
)
VALUES
(
101
,
'cluster1'
,
6666
,
'6666.k1'
,
'6666.v122'
,
'qqqqq'
,
'lepdou'
,
'2016-03-23 12:00:00'
,
'王五4'
,
NOW
(),
0
);
apollo-portal/src/main/java/com/ctrip/apollo/portal/RestUtils.java
已删除
100644 → 0
浏览文件 @
babb3c6a
package
com.ctrip.apollo.portal
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.client.RestTemplate
;
public
class
RestUtils
{
private
static
RestTemplate
restTemplate
=
new
RestTemplate
();
public
static
<
T
>
T
exchangeInGET
(
String
url
,
Class
<
T
>
responseType
)
{
ResponseEntity
<
T
>
response
=
restTemplate
.
exchange
(
url
,
HttpMethod
.
GET
,
new
HttpEntity
<
Void
>((
Void
)
null
),
responseType
);
return
response
.
getBody
();
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/api/API.java
0 → 100644
浏览文件 @
8563b8b9
package
com.ctrip.apollo.portal.api
;
import
com.ctrip.apollo.Apollo
;
import
com.ctrip.apollo.portal.service.ServiceLocator
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.client.RestTemplate
;
public
class
API
{
@Autowired
protected
ServiceLocator
serviceLocator
;
protected
RestTemplate
restTemplate
=
new
RestTemplate
();
public
String
getAdminServiceHost
(
Apollo
.
Env
env
){
//本地测试用
// return "http://localhost:8090";
return
serviceLocator
.
getAdminService
(
env
);
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/api/AdminServiceAPI.java
0 → 100644
浏览文件 @
8563b8b9
package
com.ctrip.apollo.portal.api
;
import
com.ctrip.apollo.Apollo
;
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.stereotype.Service
;
import
java.util.List
;
@Service
public
class
AdminServiceAPI
{
@Service
public
static
class
ConfigAPI
extends
API
{
public
static
String
CONFIG_RELEASE_API
=
"/configs/release/"
;
public
ReleaseSnapshotDTO
[]
getConfigByReleaseId
(
Apollo
.
Env
env
,
long
releaseId
)
{
if
(
releaseId
<=
0
)
{
return
null
;
}
return
restTemplate
.
getForObject
(
getAdminServiceHost
(
env
)
+
CONFIG_RELEASE_API
+
releaseId
,
ReleaseSnapshotDTO
[].
class
);
}
public
ConfigItemDTO
[]
getLatestConfigItemsByClusters
(
Apollo
.
Env
env
,
List
<
Long
>
clusterIds
)
{
if
(
clusterIds
==
null
||
clusterIds
.
size
()
==
0
)
{
return
null
;
}
StringBuilder
sb
=
new
StringBuilder
();
for
(
long
clusterId
:
clusterIds
)
{
sb
.
append
(
clusterId
).
append
(
","
);
}
return
restTemplate
.
getForObject
(
getAdminServiceHost
(
env
)
+
"/configs/latest?clusterIds="
+
sb
.
substring
(
0
,
sb
.
length
()
-
1
),
ConfigItemDTO
[].
class
);
}
}
@Service
public
static
class
ClusterAPI
extends
API
{
public
static
String
CLUSTER_APP_API
=
"/cluster/app/"
;
public
ClusterDTO
[]
getClustersByApp
(
Apollo
.
Env
env
,
long
appId
)
{
if
(
appId
<=
0
)
{
return
null
;
}
return
restTemplate
.
getForObject
(
getAdminServiceHost
(
env
)
+
CLUSTER_APP_API
+
appId
,
ClusterDTO
[].
class
);
}
}
@Service
public
static
class
VersionAPI
extends
API
{
public
static
String
VERSION_API
=
"/version/"
;
public
static
String
VERSION_APP_API
=
"/version/app/"
;
public
VersionDTO
getVersionById
(
Apollo
.
Env
env
,
long
versionId
){
if
(
versionId
<=
0
){
return
null
;
}
return
restTemplate
.
getForObject
(
getAdminServiceHost
(
env
)
+
VERSION_API
+
versionId
,
VersionDTO
.
class
);
}
public
VersionDTO
[]
getVersionsByApp
(
Apollo
.
Env
env
,
long
appId
){
if
(
appId
<=
0
){
return
null
;
}
return
restTemplate
.
getForObject
(
getAdminServiceHost
(
env
)
+
VERSION_APP_API
+
appId
,
VersionDTO
[].
class
);
}
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ConfigService.java
浏览文件 @
8563b8b9
package
com.ctrip.apollo.portal.service
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -16,33 +19,38 @@ 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.api.AdminServiceAPI
;
import
com.ctrip.apollo.portal.constants.PortalConstants
;
import
com.ctrip.apollo.portal.entity.AppConfigVO
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.google.common.collect.Maps
;
@Service
public
class
ConfigService
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
ConfigService
.
class
);
@Autowired
private
AdminServiceAPI
.
ConfigAPI
configAPI
;
@Autowired
private
AdminServiceAPI
.
ClusterAPI
clusterAPI
;
@Autowired
private
ServiceLocator
serviceLocator
;
private
AdminServiceAPI
.
VersionAPI
versionAPI
;
private
ObjectMapper
objectMapper
=
new
ObjectMapper
();
public
AppConfigVO
loadReleaseConfig
(
Env
env
,
long
appId
,
long
versionId
)
{
if
(
appId
<=
0
||
versionId
<=
0
)
{
return
null
;
}
long
releaseId
=
getReleaseIdFromVersionId
(
env
,
versionId
);
if
(
releaseId
==
-
1
)
{
return
null
;
}
String
serviceHost
=
serviceLocator
.
getAdminService
(
env
);
ReleaseSnapshotDTO
[]
releaseSnapShots
=
RestUtils
.
exchangeInGET
(
serviceHost
+
"/configs/release/"
+
releaseId
,
ReleaseSnapshotDTO
[].
class
);
ReleaseSnapshotDTO
[]
releaseSnapShots
=
configAPI
.
getConfigByReleaseId
(
Env
.
DEV
,
releaseId
);
if
(
releaseSnapShots
==
null
||
releaseSnapShots
.
length
==
0
)
{
return
null
;
}
...
...
@@ -63,9 +71,7 @@ public class ConfigService {
}
private
long
getReleaseIdFromVersionId
(
Env
env
,
long
versionId
)
{
String
serviceHost
=
serviceLocator
.
getAdminService
(
env
);
VersionDTO
version
=
RestUtils
.
exchangeInGET
(
serviceHost
+
"/version/"
+
versionId
,
VersionDTO
.
class
);
VersionDTO
version
=
versionAPI
.
getVersionById
(
env
,
versionId
);
if
(
version
==
null
)
{
return
-
1
;
}
...
...
@@ -73,7 +79,7 @@ public class ConfigService {
}
private
void
collectDefaultClusterConfigs
(
long
appId
,
ReleaseSnapshotDTO
snapShot
,
AppConfigVO
appConfigVO
)
{
AppConfigVO
appConfigVO
)
{
Map
<
Long
,
List
<
ConfigItemDTO
>>
groupedConfigs
=
groupConfigsByApp
(
snapShot
.
getConfigurations
());
...
...
@@ -136,7 +142,7 @@ public class ConfigService {
}
private
void
collectSpecialClusterConfigs
(
long
appId
,
ReleaseSnapshotDTO
snapShot
,
AppConfigVO
appConfigVO
)
{
AppConfigVO
appConfigVO
)
{
List
<
AppConfigVO
.
OverrideClusterConfig
>
overrideClusterConfigs
=
appConfigVO
.
getOverrideClusterConfigs
();
AppConfigVO
.
OverrideClusterConfig
overrideClusterConfig
=
...
...
@@ -152,21 +158,17 @@ public class ConfigService {
return
null
;
}
String
serviceHost
=
serviceLocator
.
getAdminService
(
env
);
ClusterDTO
[]
clusters
=
RestUtils
.
exchangeInGET
(
serviceHost
+
"/cluster/app/"
+
appId
,
ClusterDTO
[].
class
);
ClusterDTO
[]
clusters
=
clusterAPI
.
getClustersByApp
(
env
,
appId
);
if
(
clusters
==
null
||
clusters
.
length
==
0
)
{
return
null
;
}
StringBuilder
sb
=
new
StringBuilder
(
);
List
<
Long
>
clusterIds
=
new
ArrayList
<>(
clusters
.
length
);
for
(
ClusterDTO
cluster
:
clusters
)
{
sb
.
append
(
cluster
.
getId
()).
append
(
","
);
clusterIds
.
add
(
cluster
.
getId
()
);
}
ConfigItemDTO
[]
configItems
=
RestUtils
.
exchangeInGET
(
serviceHost
+
"/configs/latest?clusterIds="
+
sb
.
substring
(
0
,
sb
.
length
()
-
1
),
ConfigItemDTO
[].
class
);
ConfigItemDTO
[]
configItems
=
configAPI
.
getLatestConfigItemsByClusters
(
env
,
clusterIds
);
return
buildAPPConfigVO
(
appId
,
Arrays
.
asList
(
configItems
));
}
...
...
@@ -203,7 +205,7 @@ public class ConfigService {
}
private
void
groupConfigByAppAndEnrichDTO
(
Map
<
String
,
List
<
ConfigItemDTO
>>
groupedClusterConfigs
,
AppConfigVO
appConfigVO
)
{
AppConfigVO
appConfigVO
)
{
long
appId
=
appConfigVO
.
getAppId
();
List
<
ConfigItemDTO
>
defaultClusterConfigs
=
appConfigVO
.
getDefaultClusterConfigs
();
...
...
@@ -222,7 +224,7 @@ public class ConfigService {
if
(
Constants
.
DEFAULT_CLUSTER_NAME
.
equals
(
clusterName
))
{
// default cluster configs
collectDefaultClusterConfigs
(
appId
,
clusterConfigs
,
defaultClusterConfigs
,
overrideAppConfigs
);
overrideAppConfigs
);
}
else
{
// override cluster configs
collectSpecialClusterConfigs
(
clusterName
,
clusterConfigs
,
overrideClusterConfigs
);
...
...
@@ -231,8 +233,8 @@ public class ConfigService {
}
private
void
collectDefaultClusterConfigs
(
long
appId
,
List
<
ConfigItemDTO
>
clusterConfigs
,
List
<
ConfigItemDTO
>
defaultClusterConfigs
,
List
<
AppConfigVO
.
OverrideAppConfig
>
overrideAppConfigs
)
{
List
<
ConfigItemDTO
>
defaultClusterConfigs
,
List
<
AppConfigVO
.
OverrideAppConfig
>
overrideAppConfigs
)
{
Map
<
Long
,
AppConfigVO
.
OverrideAppConfig
>
appIdMapOverrideAppConfig
=
null
;
...
...
@@ -261,7 +263,7 @@ public class ConfigService {
}
private
void
collectSpecialClusterConfigs
(
String
clusterName
,
List
<
ConfigItemDTO
>
clusterConfigs
,
List
<
AppConfigVO
.
OverrideClusterConfig
>
overrideClusterConfigs
)
{
List
<
AppConfigVO
.
OverrideClusterConfig
>
overrideClusterConfigs
)
{
AppConfigVO
.
OverrideClusterConfig
overrideClusterConfig
=
new
AppConfigVO
.
OverrideClusterConfig
();
overrideClusterConfig
.
setClusterName
(
clusterName
);
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ServiceLocator.java
浏览文件 @
8563b8b9
...
...
@@ -30,8 +30,6 @@ public class ServiceLocator {
}
public
String
getAdminService
(
Env
env
)
{
//本地测试用
// return "http://localhost:8090";
List
<
ApolloService
>
services
=
getAdminServices
(
env
);
if
(
services
.
size
()
==
0
)
{
throw
new
RuntimeException
(
"No available admin service"
);
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/VersionService.java
浏览文件 @
8563b8b9
...
...
@@ -2,22 +2,28 @@ package com.ctrip.apollo.portal.service;
import
com.ctrip.apollo.Apollo
;
import
com.ctrip.apollo.core.dto.VersionDTO
;
import
com.ctrip.apollo.portal.
RestUtils
;
import
com.ctrip.apollo.portal.
api.AdminServiceAPI
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.List
;
@Service
public
class
VersionService
{
@Autowired
private
ServiceLocator
serviceLocator
;
private
AdminServiceAPI
.
VersionAPI
versionAPI
;
public
List
<
VersionDTO
>
findVersionsByApp
(
Apollo
.
Env
env
,
long
appId
)
{
return
RestUtils
.
exchangeInGET
(
serviceLocator
.
getAdminService
(
env
)
+
"/version/app/"
+
appId
,
List
.
class
);
VersionDTO
[]
versions
=
versionAPI
.
getVersionsByApp
(
env
,
appId
);
if
(
versions
==
null
||
versions
.
length
==
0
){
return
Collections
.
EMPTY_LIST
;
}
return
Arrays
.
asList
(
versions
);
}
}
apollo-portal/src/main/resources/application.yml
浏览文件 @
8563b8b9
...
...
@@ -13,7 +13,7 @@ spring:
logging
:
level
:
org.springframework.cloud
:
'
DEBUG'
file
:
/opt/logs/${ctrip.appid}/apollo-
adminservice
.log
file
:
/opt/logs/${ctrip.appid}/apollo-
portal
.log
ctrip
:
appid
:
100003173
apollo-portal/src/main/resources/static/styles/common-style.css
浏览文件 @
8563b8b9
...
...
@@ -7,6 +7,10 @@ body {
padding-bottom
:
50px
;
}
a
{
cursor
:
pointer
;
}
.container
{
width
:
100%
;
min-height
:
550px
;
...
...
apollo-portal/src/main/resources/static/views/app/config.html
浏览文件 @
8563b8b9
...
...
@@ -3,7 +3,7 @@
<!--环境nav-->
<ul
class=
"nav nav-pills nav-justified"
>
<li
ng-repeat=
"env in envs"
ng-class=
"{active:configLocation.env == env}"
>
<a
href=
"#"
ng-click=
"switchEnv(env)"
>
{{env}}
</a>
<a
ng-click=
"switchEnv(env)"
>
{{env}}
</a>
</li>
</ul>
...
...
@@ -14,12 +14,12 @@
<ul
class=
"nav nav-pills nav-stacked"
>
<li
class=
"dropdown-header"
>
未发布
</li>
<li
role=
"presentation"
ng-class=
"{active:configLocation.versionId == -1}"
ng-click=
"switchVersion(-1)"
><a
href=
"#"
>
latest
</a></li>
ng-click=
"switchVersion(-1)"
><a>
latest
</a></li>
<li
role=
"separator"
class=
"divider"
></li>
<li
class=
"dropdown-header"
>
已发布
</li>
<li
ng-repeat=
"version in releaseVersions"
ng-class=
"{active:configLocation.versionId == version.id}"
>
<a
href=
"#"
ng-click=
"switchVersion(version.id)"
>
{{version.name}}
</a>
<a
ng-click=
"switchVersion(version.id)"
>
{{version.name}}
</a>
</li>
</ul>
</div>
...
...
@@ -31,13 +31,13 @@
<div
class=
"col-md-6"
>
项目的基本配置
</div>
<div
class=
"col-md-6"
ng-show=
"!currentVersionIsRelease"
>
<p
class=
"text-right"
>
<a
href=
"#"
data-toggle=
"tooltip"
<a
data-toggle=
"tooltip"
data-placement=
"top"
title=
"下载配置"
>
<span
class=
"glyphicon glyphicon-save"
aria-hidden=
"true"
></span>
</a>
<a
href=
"#"
data-toggle=
"tooltip"
<a
data-toggle=
"tooltip"
data-placement=
"top"
title=
"添加配置"
>
<span
class=
"glyphicon glyphicon-plus"
aria-hidden=
"true"
></span>
...
...
@@ -93,12 +93,12 @@
</td>
<td
ng-show=
"!currentVersionIsRelease"
>
<a
href=
"#"
data-toggle=
"tooltip"
<a
data-toggle=
"tooltip"
data-placement=
"top"
title=
"修改"
>
<span
class=
"glyphicon glyphicon-edit"
aria-hidden=
"true"
></span>
</a>
<a
href=
"#"
data-toggle=
"tooltip"
<a
data-toggle=
"tooltip"
data-placement=
"top"
title=
"删除"
>
<span
class=
"glyphicon glyphicon-remove"
aria-hidden=
"true"
></span>
...
...
@@ -110,17 +110,17 @@
<nav
class=
"text-right"
>
<ul
class=
"pagination"
>
<li>
<a
href=
"#"
aria-label=
"Previous"
>
<a
aria-label=
"Previous"
>
<span
aria-hidden=
"true"
>
«
</span>
</a>
</li>
<li><a
href=
"#"
>
1
</a></li>
<li><a
href=
"#"
>
2
</a></li>
<li><a
href=
"#"
>
3
</a></li>
<li><a
href=
"#"
>
4
</a></li>
<li><a
href=
"#"
>
5
</a></li>
<li><a
>
1
</a></li>
<li><a
>
2
</a></li>
<li><a
>
3
</a></li>
<li><a
>
4
</a></li>
<li><a
>
5
</a></li>
<li>
<a
href=
"#"
aria-label=
"Next"
>
<a
aria-label=
"Next"
>
<span
aria-hidden=
"true"
>
»
</span>
</a>
</li>
...
...
@@ -135,18 +135,18 @@
<header
class=
"panel-heading"
>
<div
class=
"row"
>
<div
class=
"col-md-6"
>
重写
<a
href=
"#"
>
{{overrideAppConfig.appId}}
</a>
的配置
>
{{overrideAppConfig.appId}}
</a>
的配置
</div>
<div
class=
"col-md-6"
ng-show=
"!currentVersionIsRelease"
>
<p
class=
"text-right"
>
<a
href=
"#"
data-toggle=
"tooltip"
<a
data-toggle=
"tooltip"
data-placement=
"top"
title=
"下载配置"
>
<span
class=
"glyphicon glyphicon-save"
aria-hidden=
"true"
></span>
</a>
<a
href=
"#"
data-toggle=
"tooltip"
<a
data-toggle=
"tooltip"
data-placement=
"top"
title=
"添加配置"
>
<span
class=
"glyphicon glyphicon-plus"
...
...
@@ -202,13 +202,13 @@
</td>
<td
ng-show=
"!currentVersionIsRelease"
>
<a
href=
"#"
data-toggle=
"tooltip"
<a
data-toggle=
"tooltip"
data-placement=
"top"
title=
"修改"
>
<span
class=
"glyphicon glyphicon-edit"
aria-hidden=
"true"
></span>
</a>
<a
href=
"#"
data-toggle=
"tooltip"
<a
data-toggle=
"tooltip"
data-placement=
"top"
title=
"删除"
>
<span
class=
"glyphicon glyphicon-remove"
...
...
@@ -247,13 +247,13 @@
</div>
<div
class=
"col-md-6"
ng-show=
"!currentVersionIsRelease"
>
<p
class=
"text-right"
>
<a
href=
"#"
data-toggle=
"tooltip"
<a
data-toggle=
"tooltip"
data-placement=
"top"
title=
"下载配置"
>
<span
class=
"glyphicon glyphicon-save"
aria-hidden=
"true"
></span>
</a>
<a
href=
"#"
data-toggle=
"tooltip"
<a
data-toggle=
"tooltip"
data-placement=
"top"
title=
"添加配置"
>
<span
class=
"glyphicon glyphicon-plus"
aria-hidden=
"true"
></span>
...
...
@@ -308,13 +308,13 @@
</td>
<td
ng-show=
"!currentVersionIsRelease"
>
<a
href=
"#"
data-toggle=
"tooltip"
<a
data-toggle=
"tooltip"
data-placement=
"top"
title=
"修改"
>
<span
class=
"glyphicon glyphicon-edit"
aria-hidden=
"true"
></span>
</a>
<a
href=
"#"
data-toggle=
"tooltip"
<a
data-toggle=
"tooltip"
data-placement=
"top"
title=
"删除"
>
<span
class=
"glyphicon glyphicon-remove"
...
...
apollo-portal/src/test/java/com/ctrip/apollo/portal/service/ConfigServiceTest.java
浏览文件 @
8563b8b9
package
com.ctrip.apollo.portal.service
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Matchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -16,10 +12,6 @@ import org.mockito.Mock;
import
org.mockito.Mockito
;
import
org.mockito.Spy
;
import
org.mockito.runners.MockitoJUnitRunner
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
org.springframework.web.client.RestTemplate
;
...
...
@@ -29,34 +21,42 @@ 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.api.AdminServiceAPI
;
import
com.ctrip.apollo.portal.constants.PortalConstants
;
import
com.ctrip.apollo.portal.entity.AppConfigVO
;
import
java.util.Arrays
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
ConfigServiceTest
{
@Mock
private
RestTemplate
restTemplate
;
@Mock
private
ResponseEntity
releaseSnapShotResponse
;
@Mock
private
ResponseEntity
versionResponse
;
@Mock
private
ResponseEntity
clusterResponse
;
@Mock
private
ResponseEntity
configItemResponse
;
@InjectMocks
private
ConfigService
configService
;
@
Spy
@
Mock
private
ServiceLocator
serviceLocator
;
@Spy
private
AdminServiceAPI
.
VersionAPI
versionAPI
;
@Spy
private
AdminServiceAPI
.
ClusterAPI
clusterAPI
;
@Spy
private
AdminServiceAPI
.
ConfigAPI
configAPI
;
@Before
public
void
setUp
()
{
ReflectionTestUtils
.
setField
(
RestUtils
.
class
,
"restTemplate"
,
restTemplate
);
ReflectionTestUtils
.
setField
(
versionAPI
,
"restTemplate"
,
restTemplate
);
ReflectionTestUtils
.
setField
(
clusterAPI
,
"restTemplate"
,
restTemplate
);
ReflectionTestUtils
.
setField
(
configAPI
,
"restTemplate"
,
restTemplate
);
ReflectionTestUtils
.
setField
(
versionAPI
,
"serviceLocator"
,
serviceLocator
);
ReflectionTestUtils
.
setField
(
clusterAPI
,
"serviceLocator"
,
serviceLocator
);
ReflectionTestUtils
.
setField
(
configAPI
,
"serviceLocator"
,
serviceLocator
);
String
defaultAdminService
=
"http://localhost:8090"
;
Mockito
.
doReturn
(
defaultAdminService
).
when
(
serviceLocator
).
getAdminService
(
Env
.
DEV
);
}
...
...
@@ -70,11 +70,8 @@ public class ConfigServiceTest {
VersionDTO
someVersion
=
assembleVersion
(
appId
,
"1.0"
,
releaseId
);
ReleaseSnapshotDTO
[]
someReleaseSnapShots
=
assembleReleaseSnapShots
();
restInvoke
(
serviceLocator
.
getAdminService
(
Env
.
DEV
)
+
"/configs/release/"
+
releaseId
,
ReleaseSnapshotDTO
[].
class
,
someReleaseSnapShots
,
releaseSnapShotResponse
);
restInvoke
(
serviceLocator
.
getAdminService
(
Env
.
DEV
)
+
"/version/"
+
versionId
,
VersionDTO
.
class
,
someVersion
,
versionResponse
);
when
(
versionAPI
.
getVersionById
(
Env
.
DEV
,
versionId
)).
thenReturn
(
someVersion
);
when
(
configAPI
.
getConfigByReleaseId
(
Env
.
DEV
,
releaseId
)).
thenReturn
(
someReleaseSnapShots
);
AppConfigVO
appConfigVO
=
configService
.
loadReleaseConfig
(
Env
.
DEV
,
appId
,
versionId
);
...
...
@@ -92,15 +89,12 @@ public class ConfigServiceTest {
long
releaseId
=
11111
;
VersionDTO
someVersion
=
assembleVersion
(
appId
,
"1.0"
,
releaseId
);
ReleaseSnapshotDTO
[]
releaseSnapShots
=
new
ReleaseSnapshotDTO
[
1
];
releaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
Constants
.
DEFAULT_CLUSTER_NAME
,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}"
);
restInvoke
(
serviceLocator
.
getAdminService
(
Env
.
DEV
)
+
"/configs/release/"
+
releaseId
,
ReleaseSnapshotDTO
[].
class
,
releaseSnapShots
,
releaseSnapShotResponse
);
ReleaseSnapshotDTO
[]
someReleaseSnapShots
=
new
ReleaseSnapshotDTO
[
1
];
someReleaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
Constants
.
DEFAULT_CLUSTER_NAME
,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}"
);
restInvoke
(
serviceLocator
.
getAdminService
(
Env
.
DEV
)
+
"/version/"
+
versionId
,
VersionDTO
.
class
,
someVersion
,
versionResponse
);
when
(
versionAPI
.
getVersionById
(
Env
.
DEV
,
versionId
)).
thenReturn
(
someVersion
);
when
(
configAPI
.
getConfigByReleaseId
(
Env
.
DEV
,
releaseId
)).
thenReturn
(
someReleaseSnapShots
);
AppConfigVO
appConfigVO
=
configService
.
loadReleaseConfig
(
Env
.
DEV
,
appId
,
versionId
);
...
...
@@ -117,15 +111,12 @@ public class ConfigServiceTest {
long
versionId
=
100
;
long
releaseId
=
11111
;
VersionDTO
someVersion
=
assembleVersion
(
appId
,
"1.0"
,
releaseId
);
ReleaseSnapshotDTO
[]
r
eleaseSnapShots
=
new
ReleaseSnapshotDTO
[
1
];
r
eleaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
Constants
.
DEFAULT_CLUSTER_NAME
,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\", \"5555.bar\":\"demo2\", \"22.bar\":\"demo2\"}"
);
ReleaseSnapshotDTO
[]
someR
eleaseSnapShots
=
new
ReleaseSnapshotDTO
[
1
];
someR
eleaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
Constants
.
DEFAULT_CLUSTER_NAME
,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\", \"5555.bar\":\"demo2\", \"22.bar\":\"demo2\"}"
);
restInvoke
(
serviceLocator
.
getAdminService
(
Env
.
DEV
)
+
"/configs/release/"
+
releaseId
,
ReleaseSnapshotDTO
[].
class
,
releaseSnapShots
,
releaseSnapShotResponse
);
restInvoke
(
serviceLocator
.
getAdminService
(
Env
.
DEV
)
+
"/version/"
+
versionId
,
VersionDTO
.
class
,
someVersion
,
versionResponse
);
when
(
versionAPI
.
getVersionById
(
Env
.
DEV
,
versionId
)).
thenReturn
(
someVersion
);
when
(
configAPI
.
getConfigByReleaseId
(
Env
.
DEV
,
releaseId
)).
thenReturn
(
someReleaseSnapShots
);
AppConfigVO
appConfigVO
=
configService
.
loadReleaseConfig
(
Env
.
DEV
,
appId
,
versionId
);
...
...
@@ -142,17 +133,14 @@ public class ConfigServiceTest {
long
versionId
=
100
;
long
releaseId
=
11111
;
VersionDTO
someVersion
=
assembleVersion
(
appId
,
"1.0"
,
releaseId
);
ReleaseSnapshotDTO
[]
releaseSnapShots
=
new
ReleaseSnapshotDTO
[
2
];
releaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
Constants
.
DEFAULT_CLUSTER_NAME
,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}"
);
releaseSnapShots
[
1
]
=
assembleReleaseSnapShot
(
11112
,
"cluster1"
,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}"
);
restInvoke
(
serviceLocator
.
getAdminService
(
Env
.
DEV
)
+
"/configs/release/"
+
releaseId
,
ReleaseSnapshotDTO
[].
class
,
releaseSnapShots
,
releaseSnapShotResponse
);
ReleaseSnapshotDTO
[]
someReleaseSnapShots
=
new
ReleaseSnapshotDTO
[
2
];
someReleaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
Constants
.
DEFAULT_CLUSTER_NAME
,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}"
);
someReleaseSnapShots
[
1
]
=
assembleReleaseSnapShot
(
11112
,
"cluster1"
,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}"
);
restInvoke
(
serviceLocator
.
getAdminService
(
Env
.
DEV
)
+
"/version/"
+
versionId
,
VersionDTO
.
class
,
someVersion
,
versionResponse
);
when
(
versionAPI
.
getVersionById
(
Env
.
DEV
,
versionId
)).
thenReturn
(
someVersion
);
when
(
configAPI
.
getConfigByReleaseId
(
Env
.
DEV
,
releaseId
)).
thenReturn
(
someReleaseSnapShots
);
AppConfigVO
appConfigVO
=
configService
.
loadReleaseConfig
(
Env
.
DEV
,
appId
,
versionId
);
...
...
@@ -169,11 +157,9 @@ public class ConfigServiceTest {
ClusterDTO
[]
someClusters
=
assembleClusters
();
ConfigItemDTO
[]
someConfigItem
=
assembleConfigItems
();
restInvoke
(
serviceLocator
.
getAdminService
(
Env
.
DEV
)
+
"/cluster/app/"
+
appId
,
ClusterDTO
[].
class
,
someClusters
,
clusterResponse
);
restInvoke
(
serviceLocator
.
getAdminService
(
Env
.
DEV
)
+
"/configs/latest?clusterIds=100,101"
,
ConfigItemDTO
[].
class
,
someConfigItem
,
configItemResponse
);
when
(
clusterAPI
.
getClustersByApp
(
Env
.
DEV
,
appId
)).
thenReturn
(
someClusters
);
when
(
configAPI
.
getLatestConfigItemsByClusters
(
Env
.
DEV
,
Arrays
.
asList
(
Long
.
valueOf
(
100
),
Long
.
valueOf
(
101
)))).
thenReturn
(
someConfigItem
);
AppConfigVO
appConfigVO
=
configService
.
loadLatestConfig
(
Env
.
DEV
,
appId
);
...
...
@@ -184,15 +170,6 @@ public class ConfigServiceTest {
assertEquals
(
appConfigVO
.
getOverrideClusterConfigs
().
size
(),
1
);
}
private
<
T
>
void
restInvoke
(
String
url
,
Class
<
T
>
responseType
,
T
result
,
ResponseEntity
someResponse
)
{
when
(
restTemplate
.
exchange
(
eq
(
url
),
eq
(
HttpMethod
.
GET
),
any
(
HttpEntity
.
class
),
eq
(
responseType
)))
.
thenReturn
(
someResponse
);
when
(
someResponse
.
getStatusCode
()).
thenReturn
(
HttpStatus
.
OK
);
when
(
someResponse
.
getBody
()).
thenReturn
(
result
);
}
private
VersionDTO
assembleVersion
(
long
appId
,
String
versionName
,
long
releaseId
)
{
VersionDTO
version
=
new
VersionDTO
();
version
.
setAppId
(
appId
);
...
...
@@ -204,14 +181,14 @@ public class ConfigServiceTest {
private
ReleaseSnapshotDTO
[]
assembleReleaseSnapShots
()
{
ReleaseSnapshotDTO
[]
releaseSnapShots
=
new
ReleaseSnapshotDTO
[
3
];
releaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
Constants
.
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
[
2
]
=
assembleReleaseSnapShot
(
11111
,
"cluster2"
,
"{\"6666.bar\":\"bar2222\"}"
);
return
releaseSnapShots
;
}
private
ReleaseSnapshotDTO
assembleReleaseSnapShot
(
long
releaseId
,
String
clusterName
,
String
configurations
)
{
String
configurations
)
{
ReleaseSnapshotDTO
releaseSnapShot
=
new
ReleaseSnapshotDTO
();
releaseSnapShot
.
setReleaseId
(
releaseId
);
releaseSnapShot
.
setClusterName
(
clusterName
);
...
...
@@ -236,16 +213,20 @@ public class ConfigServiceTest {
private
ConfigItemDTO
[]
assembleConfigItems
()
{
ConfigItemDTO
[]
configItems
=
new
ConfigItemDTO
[
5
];
configItems
[
0
]
=
assembleConfigItem
(
100
,
Constants
.
DEFAULT_CLUSTER_NAME
,
6666
,
"6666.k1"
,
"6666.v1"
);
configItems
[
1
]
=
assembleConfigItem
(
100
,
Constants
.
DEFAULT_CLUSTER_NAME
,
6666
,
"6666.k2"
,
"6666.v2"
);
configItems
[
2
]
=
assembleConfigItem
(
100
,
Constants
.
DEFAULT_CLUSTER_NAME
,
6666
,
"6666.k3"
,
"6666.v3"
);
configItems
[
3
]
=
assembleConfigItem
(
100
,
Constants
.
DEFAULT_CLUSTER_NAME
,
5555
,
"5555.k1"
,
"5555.v1"
);
configItems
[
0
]
=
assembleConfigItem
(
100
,
Constants
.
DEFAULT_CLUSTER_NAME
,
6666
,
"6666.k1"
,
"6666.v1"
);
configItems
[
1
]
=
assembleConfigItem
(
100
,
Constants
.
DEFAULT_CLUSTER_NAME
,
6666
,
"6666.k2"
,
"6666.v2"
);
configItems
[
2
]
=
assembleConfigItem
(
100
,
Constants
.
DEFAULT_CLUSTER_NAME
,
6666
,
"6666.k3"
,
"6666.v3"
);
configItems
[
3
]
=
assembleConfigItem
(
100
,
Constants
.
DEFAULT_CLUSTER_NAME
,
5555
,
"5555.k1"
,
"5555.v1"
);
configItems
[
4
]
=
assembleConfigItem
(
101
,
"cluster1"
,
6666
,
"6666.k1"
,
"6666.v1"
);
return
configItems
;
}
private
ConfigItemDTO
assembleConfigItem
(
long
clusterId
,
String
clusterName
,
int
appId
,
String
key
,
String
value
)
{
String
key
,
String
value
)
{
ConfigItemDTO
configItem
=
new
ConfigItemDTO
();
configItem
.
setClusterName
(
clusterName
);
configItem
.
setClusterId
(
clusterId
);
...
...
apollo-portal/src/test/resources/application.yml
浏览文件 @
8563b8b9
server
:
port
:
80
8
0
port
:
80
7
0
spring
:
spring
:
application
:
name
:
apollo-portal
datasource
:
url
:
jdbc:h2:file:~/fxapolloportaldb
username
:
sa
password
:
sa
url
:
jdbc:h2:mem:~/fxapolloportaldb
jpa
:
show-sql
:
true
hibernate
:
naming_strategy
:
org.hibernate.cfg.EJB3NamingStrategy
logging
:
level
:
org.springframework.cloud
:
'
DEBUG'
file
:
/opt/logs/${ctrip.appid}/apollo-portal.log
ctrip
:
appid
:
100003173
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录