Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
superrain51
apollo
提交
d175be44
apollo
项目概览
superrain51
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
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,发现更多精彩内容 >>
提交
d175be44
编写于
4月 15, 2016
作者:
L
lepdou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
规范异常处理
上级
d1c7c2a2
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
46 addition
and
125 deletion
+46
-125
apollo-portal/src/main/java/com/ctrip/apollo/portal/api/AdminServiceAPI.java
...ain/java/com/ctrip/apollo/portal/api/AdminServiceAPI.java
+4
-2
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/ConfigController.java
.../com/ctrip/apollo/portal/controller/ConfigController.java
+8
-22
apollo-portal/src/main/java/com/ctrip/apollo/portal/entity/form/NamespaceTextModel.java
...m/ctrip/apollo/portal/entity/form/NamespaceTextModel.java
+1
-1
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ConfigService.java
...n/java/com/ctrip/apollo/portal/service/ConfigService.java
+14
-34
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/txtresolver/ConfigTextResolver.java
...apollo/portal/service/txtresolver/ConfigTextResolver.java
+3
-2
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/txtresolver/PropertyResolver.java
...p/apollo/portal/service/txtresolver/PropertyResolver.java
+13
-23
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/txtresolver/TextResolverResult.java
...apollo/portal/service/txtresolver/TextResolverResult.java
+0
-38
apollo-portal/src/main/resources/static/scripts/controller/app/AppConfigController.js
...rces/static/scripts/controller/app/AppConfigController.js
+2
-2
apollo-portal/src/main/resources/static/views/app.html
apollo-portal/src/main/resources/static/views/app.html
+1
-1
未找到文件。
apollo-portal/src/main/java/com/ctrip/apollo/portal/api/AdminServiceAPI.java
浏览文件 @
d175be44
...
...
@@ -8,6 +8,7 @@ import com.ctrip.apollo.core.dto.ItemChangeSets;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
com.ctrip.apollo.core.dto.NamespaceDTO
;
import
com.ctrip.apollo.core.dto.ReleaseDTO
;
import
com.ctrip.apollo.core.exception.ServiceException
;
import
com.ctrip.apollo.core.utils.StringUtils
;
import
org.slf4j.Logger
;
...
...
@@ -145,8 +146,9 @@ public class AdminServiceAPI {
if
(
response
!=
null
&&
response
.
getStatusCode
()
==
HttpStatus
.
OK
){
return
response
.
getBody
();
}
else
{
logger
.
error
(
"release fail.id:{}, env:{}, clusterName:{}, namespace:{},releaseBy{}"
,
appId
,
env
,
clusterName
,
namespace
,
releaseBy
);
return
null
;
logger
.
error
(
"createRelease fail.id:{}, env:{}, clusterName:{}, namespace:{},releaseBy{}"
,
appId
,
env
,
clusterName
,
namespace
,
releaseBy
);
throw
new
ServiceException
(
"call create createRelease api error."
);
}
}
}
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/ConfigController.java
浏览文件 @
d175be44
...
...
@@ -5,15 +5,12 @@ import com.ctrip.apollo.Apollo;
import
com.ctrip.apollo.core.dto.ReleaseDTO
;
import
com.ctrip.apollo.core.exception.BadRequestException
;
import
com.ctrip.apollo.core.utils.StringUtils
;
import
com.ctrip.apollo.portal.entity.form.Namespace
Modify
Model
;
import
com.ctrip.apollo.portal.entity.form.Namespace
Text
Model
;
import
com.ctrip.apollo.portal.entity.NamespaceVO
;
import
com.ctrip.apollo.portal.entity.SimpleMsg
;
import
com.ctrip.apollo.portal.entity.form.NamespaceReleaseModel
;
import
com.ctrip.apollo.portal.service.ConfigService
;
import
com.ctrip.apollo.portal.service.txtresolver.TextResolverResult
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
...
...
@@ -34,7 +31,7 @@ public class ConfigController {
public
List
<
NamespaceVO
>
findNamespaces
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@PathVariable
String
clusterName
)
{
if
(
StringUtils
.
isContainEmpty
(
appId
,
env
,
clusterName
))
{
throw
new
IllegalArgumen
tException
(
"app id and cluster name can not be empty"
);
throw
new
BadReques
tException
(
"app id and cluster name can not be empty"
);
}
return
configService
.
findNampspaces
(
appId
,
Apollo
.
Env
.
valueOf
(
env
),
clusterName
);
...
...
@@ -42,9 +39,9 @@ public class ConfigController {
@RequestMapping
(
value
=
"/apps/{appId}/env/{env}/clusters/{clusterName}/namespaces/{namespaceName}/items"
,
method
=
RequestMethod
.
PUT
,
consumes
=
{
"application/json"
})
public
ResponseEntity
<
SimpleMsg
>
modifyItems
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
public
ResponseEntity
modifyItems
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
,
@RequestBody
Namespace
Modify
Model
model
)
{
@RequestBody
Namespace
Text
Model
model
)
{
if
(
model
==
null
)
{
throw
new
BadRequestException
(
"request payload shoud not be null"
);
...
...
@@ -58,18 +55,13 @@ public class ConfigController {
throw
new
BadRequestException
(
"request model is invalid"
);
}
TextResolverResult
result
=
configService
.
resolveConfigText
(
model
);
if
(
result
.
isResolveSuccess
())
{
return
ResponseEntity
.
ok
().
body
(
new
SimpleMsg
(
"success"
));
}
else
{
return
ResponseEntity
.
badRequest
().
body
(
new
SimpleMsg
(
result
.
getMsg
()));
}
configService
.
updateConfigItemByText
(
model
);
return
ResponseEntity
.
ok
().
build
();
}
@RequestMapping
(
value
=
"/apps/{appId}/env/{env}/clusters/{clusterName}/namespaces/{namespaceName}/release"
,
method
=
RequestMethod
.
POST
,
consumes
=
{
"application/json"
})
public
Re
sponseEntity
<
SimpleMsg
>
createRelease
(
@PathVariable
String
appId
,
public
Re
leaseDTO
createRelease
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
,
@RequestBody
NamespaceReleaseModel
model
)
{
if
(
model
==
null
)
{
...
...
@@ -84,14 +76,8 @@ public class ConfigController {
throw
new
BadRequestException
(
"request model is invalid"
);
}
ReleaseDTO
release
=
configService
.
r
elease
(
model
);
return
configService
.
createR
elease
(
model
);
if
(
release
==
null
)
{
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
)
.
body
(
new
SimpleMsg
(
"oops! some error in server."
));
}
else
{
return
ResponseEntity
.
ok
().
body
(
new
SimpleMsg
(
"success"
));
}
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/entity/form/Namespace
Modify
Model.java
→
apollo-portal/src/main/java/com/ctrip/apollo/portal/entity/form/Namespace
Text
Model.java
浏览文件 @
d175be44
...
...
@@ -4,7 +4,7 @@ package com.ctrip.apollo.portal.entity.form;
import
com.ctrip.apollo.Apollo
;
import
com.ctrip.apollo.core.utils.StringUtils
;
public
class
Namespace
Modify
Model
implements
FormModel
{
public
class
Namespace
Text
Model
implements
FormModel
{
private
String
appId
;
private
String
env
;
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ConfigService.java
浏览文件 @
d175be44
...
...
@@ -11,13 +11,13 @@ import com.ctrip.apollo.core.dto.ItemChangeSets;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
com.ctrip.apollo.core.dto.NamespaceDTO
;
import
com.ctrip.apollo.core.dto.ReleaseDTO
;
import
com.ctrip.apollo.core.exception.ServiceException
;
import
com.ctrip.apollo.core.utils.StringUtils
;
import
com.ctrip.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.apollo.portal.entity.form.Namespace
Modify
Model
;
import
com.ctrip.apollo.portal.entity.form.Namespace
Text
Model
;
import
com.ctrip.apollo.portal.entity.NamespaceVO
;
import
com.ctrip.apollo.portal.entity.form.NamespaceReleaseModel
;
import
com.ctrip.apollo.portal.service.txtresolver.ConfigTextResolver
;
import
com.ctrip.apollo.portal.service.txtresolver.TextResolverResult
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
java.io.IOException
;
...
...
@@ -86,20 +86,20 @@ public class ConfigService {
String
namespaceName
=
namespace
.
getNamespaceName
();
//latest
r
elease
//latest
createR
elease
ReleaseDTO
release
=
releaseAPI
.
loadLatestRelease
(
appId
,
env
,
clusterName
,
namespaceName
);
Map
<
String
,
String
>
releaseItems
=
new
HashMap
<>();
if
(
release
!=
null
)
{
try
{
releaseItems
=
objectMapper
.
readValue
(
release
.
getConfigurations
(),
Map
.
class
);
}
catch
(
IOException
e
)
{
logger
.
error
(
"parse
r
elease json error. appId:{},env:{},clusterName:{},namespace:{}"
,
appId
,
logger
.
error
(
"parse
createR
elease json error. appId:{},env:{},clusterName:{},namespace:{}"
,
appId
,
env
,
clusterName
,
namespaceName
);
return
namespaceVO
;
}
}
//not
r
elease config items
//not
createR
elease config items
List
<
ItemDTO
>
items
=
itemAPI
.
findItems
(
appId
,
env
,
clusterName
,
namespaceName
);
int
modifiedItemCnt
=
0
;
for
(
ItemDTO
itemDTO
:
items
)
{
...
...
@@ -135,7 +135,7 @@ public class ConfigService {
* parse config text and update config items
* @return parse result
*/
public
TextResolverResult
resolveConfigText
(
NamespaceModify
Model
model
)
{
public
void
updateConfigItemByText
(
NamespaceText
Model
model
)
{
String
appId
=
model
.
getAppId
();
Apollo
.
Env
env
=
model
.
getEnv
();
String
clusterName
=
model
.
getClusterName
();
...
...
@@ -143,36 +143,16 @@ public class ConfigService {
long
namespaceId
=
model
.
getNamespaceId
();
String
configText
=
model
.
getConfigText
();
TextResolverResult
result
=
new
TextResolverResult
();
ItemChangeSets
changeSets
=
resolver
.
resolve
(
namespaceId
,
configText
,
itemAPI
.
findItems
(
appId
,
env
,
clusterName
,
namespaceName
));
try
{
result
=
resolver
.
resolve
(
namespaceId
,
configText
,
itemAPI
.
findItems
(
appId
,
env
,
clusterName
,
namespaceName
));
changeSets
.
setModifyBy
(
model
.
getModifyBy
());
enrichChangeSetBaseInfo
(
changeSets
);
itemAPI
.
updateItems
(
appId
,
env
,
clusterName
,
namespaceName
,
changeSets
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"resolve config text error. app id:{}, env:{}, clusterName:{}, namespace:{}"
,
appId
,
env
,
clusterName
,
namespaceName
,
e
);
result
.
setResolveSuccess
(
false
);
result
.
setMsg
(
"oops! server resolveConfigText config text error."
);
return
result
;
}
if
(
result
.
isResolveSuccess
())
{
try
{
ItemChangeSets
changeSets
=
result
.
getChangeSets
();
changeSets
.
setModifyBy
(
model
.
getModifyBy
());
enrichChangeSetBaseInfo
(
changeSets
);
itemAPI
.
updateItems
(
appId
,
env
,
clusterName
,
namespaceName
,
changeSets
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"resolve config text error. app id:{}, env:{}, clusterName:{}, namespace:{}"
,
appId
,
env
,
clusterName
,
namespaceName
,
e
);
result
.
setResolveSuccess
(
false
);
result
.
setMsg
(
"oops! server update config error."
);
return
result
;
}
}
else
{
logger
.
warn
(
"resolve config text error by format error. app id:{}, env:{}, clusterName:{}, namespace:{},cause:{}"
,
appId
,
env
,
clusterName
,
namespaceName
,
result
.
getMsg
());
throw
new
ServiceException
(
"oops! call admin service config error. "
);
}
return
result
;
}
private
void
enrichChangeSetBaseInfo
(
ItemChangeSets
changeSets
){
...
...
@@ -182,10 +162,10 @@ public class ConfigService {
}
/**
*
r
elease config items
*
createR
elease config items
* @return
*/
public
ReleaseDTO
r
elease
(
NamespaceReleaseModel
model
){
public
ReleaseDTO
createR
elease
(
NamespaceReleaseModel
model
){
return
releaseAPI
.
release
(
model
.
getAppId
(),
model
.
getEnv
(),
model
.
getClusterName
(),
model
.
getNamespaceName
(),
model
.
getReleaseBy
(),
model
.
getReleaseComment
());
}
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/txtresolver/ConfigTextResolver.java
浏览文件 @
d175be44
package
com.ctrip.apollo.portal.service.txtresolver
;
import
com.ctrip.apollo.core.dto.ItemChangeSets
;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
java.util.List
;
/**
* users can modify config in text mode.so need
resolveConfig
Text text.
* users can modify config in text mode.so need
updateConfigItemBy
Text text.
*/
public
interface
ConfigTextResolver
{
TextResolverResult
resolve
(
long
namespaceId
,
String
configText
,
List
<
ItemDTO
>
baseItems
);
ItemChangeSets
resolve
(
long
namespaceId
,
String
configText
,
List
<
ItemDTO
>
baseItems
);
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/txtresolver/PropertyResolver.java
浏览文件 @
d175be44
...
...
@@ -2,6 +2,7 @@ package com.ctrip.apollo.portal.service.txtresolver;
import
com.ctrip.apollo.core.dto.ItemChangeSets
;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
com.ctrip.apollo.core.exception.BadRequestException
;
import
com.ctrip.apollo.core.utils.StringUtils
;
import
com.ctrip.apollo.portal.util.BeanUtils
;
...
...
@@ -25,13 +26,10 @@ public class PropertyResolver implements ConfigTextResolver {
private
static
final
String
ITEM_SEPARATOR
=
"\n"
;
@Override
public
TextResolverResult
resolve
(
long
namespaceId
,
String
configText
,
List
<
ItemDTO
>
baseItems
)
{
public
ItemChangeSets
resolve
(
long
namespaceId
,
String
configText
,
List
<
ItemDTO
>
baseItems
)
{
TextResolverResult
result
=
new
TextResolverResult
();
if
(
StringUtils
.
isEmpty
(
configText
)){
result
.
setResolveSuccess
(
false
);
result
.
setMsg
(
"config text can not be empty"
);
return
result
;
throw
new
BadRequestException
(
"config text can not be empty"
);
}
Map
<
Integer
,
ItemDTO
>
oldLineNumMapItem
=
BeanUtils
.
mapByKey
(
"lineNum"
,
baseItems
);
...
...
@@ -43,13 +41,10 @@ public class PropertyResolver implements ConfigTextResolver {
String
[]
newItems
=
configText
.
split
(
ITEM_SEPARATOR
);
if
(
isHasRepeatKey
(
newItems
)){
result
.
setResolveSuccess
(
false
);
result
.
setMsg
(
"config text has repeat key please check."
);
return
result
;
throw
new
BadRequestException
(
"config text has repeat key please check."
);
}
ItemChangeSets
changeSets
=
new
ItemChangeSets
();
result
.
setChangeSets
(
changeSets
);
Map
<
Integer
,
String
>
newLineNumMapItem
=
new
HashMap
();
//use for delete blank and comment item
int
lineCounter
=
1
;
for
(
String
newItem
:
newItems
)
{
...
...
@@ -69,9 +64,7 @@ public class PropertyResolver implements ConfigTextResolver {
//normal item
}
else
{
if
(!
handleNormalLine
(
namespaceId
,
oldKeyMapItem
,
newItem
,
lineCounter
,
result
))
{
return
result
;
}
handleNormalLine
(
namespaceId
,
oldKeyMapItem
,
newItem
,
lineCounter
,
changeSets
);
}
lineCounter
++;
...
...
@@ -80,13 +73,12 @@ public class PropertyResolver implements ConfigTextResolver {
deleteCommentAndBlankItem
(
oldLineNumMapItem
,
newLineNumMapItem
,
changeSets
);
deleteNormalKVItem
(
oldKeyMapItem
,
changeSets
);
result
.
setResolveSuccess
(
true
);
return
result
;
return
changeSets
;
}
private
boolean
isHasRepeatKey
(
String
[]
newItems
){
Set
<
String
>
keys
=
new
HashSet
<>();
int
lineCounter
=
1
;
int
keyCount
=
0
;
for
(
String
item:
newItems
){
if
(!
isCommentItem
(
item
)
&&
!
isBlankItem
(
item
)){
...
...
@@ -94,8 +86,11 @@ public class PropertyResolver implements ConfigTextResolver {
String
[]
kv
=
parseKeyValueFromItem
(
item
);
if
(
kv
!=
null
)
{
keys
.
add
(
kv
[
0
]);
}
else
{
throw
new
BadRequestException
(
"line:"
+
lineCounter
+
" key value must separate by '='"
);
}
}
lineCounter
++;
}
return
keyCount
>
keys
.
size
();
...
...
@@ -127,17 +122,13 @@ public class PropertyResolver implements ConfigTextResolver {
}
}
private
boolean
handleNormalLine
(
Long
namespaceId
,
Map
<
String
,
ItemDTO
>
keyMapOldItem
,
String
newItem
,
int
lineCounter
,
TextResolverResult
result
)
{
ItemChangeSets
changeSets
=
result
.
getChangeSets
();
private
void
handleNormalLine
(
Long
namespaceId
,
Map
<
String
,
ItemDTO
>
keyMapOldItem
,
String
newItem
,
int
lineCounter
,
ItemChangeSets
changeSets
)
{
String
[]
kv
=
parseKeyValueFromItem
(
newItem
);
if
(
kv
==
null
)
{
result
.
setResolveSuccess
(
false
);
result
.
setMsg
(
" line:"
+
lineCounter
+
" key value must separate by '='"
);
return
false
;
throw
new
BadRequestException
(
"line:"
+
lineCounter
+
" key value must separate by '='"
);
}
String
newKey
=
kv
[
0
];
...
...
@@ -153,7 +144,6 @@ public class PropertyResolver implements ConfigTextResolver {
lineCounter
));
}
keyMapOldItem
.
remove
(
newKey
);
return
true
;
}
private
boolean
isCommentItem
(
ItemDTO
item
)
{
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/txtresolver/TextResolverResult.java
已删除
100644 → 0
浏览文件 @
d1c7c2a2
package
com.ctrip.apollo.portal.service.txtresolver
;
import
com.ctrip.apollo.core.dto.ItemChangeSets
;
public
class
TextResolverResult
{
private
boolean
isResolveSuccess
;
/**
* error msg
*/
private
String
msg
=
""
;
private
ItemChangeSets
changeSets
;
public
boolean
isResolveSuccess
()
{
return
isResolveSuccess
;
}
public
void
setResolveSuccess
(
boolean
resolveSuccess
)
{
isResolveSuccess
=
resolveSuccess
;
}
public
String
getMsg
()
{
return
msg
;
}
public
void
setMsg
(
String
msg
)
{
this
.
msg
=
msg
;
}
public
ItemChangeSets
getChangeSets
()
{
return
changeSets
;
}
public
void
setChangeSets
(
ItemChangeSets
changeSets
)
{
this
.
changeSets
=
changeSets
;
}
}
apollo-portal/src/main/resources/static/scripts/controller/app/AppConfigController.js
浏览文件 @
d175be44
...
...
@@ -141,7 +141,7 @@ application_module.controller("AppConfigController",
$scope
.
toggleTextEditStatus
(
$scope
.
draft
);
},
function
(
result
)
{
toastr
.
error
(
result
.
data
.
m
sg
,
"
更新失败
"
);
toastr
.
error
(
result
.
data
.
m
essage
,
"
更新失败
"
);
}
);
...
...
@@ -189,7 +189,7 @@ application_module.controller("AppConfigController",
refreshNamespaces
();
},
function
(
result
)
{
toastr
.
error
(
result
.
data
.
m
sg
,
"
发布失败
"
);
toastr
.
error
(
result
.
data
.
m
essage
,
"
发布失败
"
);
}
);
...
...
apollo-portal/src/main/resources/static/views/app.html
浏览文件 @
d175be44
...
...
@@ -250,7 +250,7 @@
</div>
</div>
<!--
r
elease modal-->
<!--
createR
elease modal-->
<div
class=
"modal fade"
id=
"releaseModal"
tabindex=
"-1"
role=
"dialog"
aria-labelledby=
"myModalLabel3"
>
<div
class=
"modal-dialog"
role=
"document"
>
<div
class=
"modal-content"
>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录