Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wrr-cat
apollo
提交
d1c7c2a2
apollo
项目概览
wrr-cat
/
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,发现更多精彩内容 >>
提交
d1c7c2a2
编写于
4月 15, 2016
作者:
L
lepdou
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #91 from yiming187/ex_update
Refactor Exception
上级
d93d3cc0
5f99ea3f
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
94 addition
and
55 deletion
+94
-55
apollo-core/src/main/java/com/ctrip/apollo/core/exception/AbstractBaseException.java
...om/ctrip/apollo/core/exception/AbstractBaseException.java
+32
-0
apollo-core/src/main/java/com/ctrip/apollo/core/exception/BadRequestException.java
.../com/ctrip/apollo/core/exception/BadRequestException.java
+14
-0
apollo-core/src/main/java/com/ctrip/apollo/core/exception/NotFoundException.java
...va/com/ctrip/apollo/core/exception/NotFoundException.java
+3
-6
apollo-core/src/main/java/com/ctrip/apollo/core/exception/ServiceException.java
...ava/com/ctrip/apollo/core/exception/ServiceException.java
+2
-2
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/AppController.java
...ava/com/ctrip/apollo/portal/controller/AppController.java
+11
-20
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/ConfigController.java
.../com/ctrip/apollo/portal/controller/ConfigController.java
+23
-19
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/GlobalDefaultExceptionHandler.java
...ollo/portal/controller/GlobalDefaultExceptionHandler.java
+8
-3
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/AppService.java
...main/java/com/ctrip/apollo/portal/service/AppService.java
+1
-4
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ClusterService.java
.../java/com/ctrip/apollo/portal/service/ClusterService.java
+0
-1
未找到文件。
apollo-core/src/main/java/com/ctrip/apollo/core/exception/AbstractBaseException.java
0 → 100644
浏览文件 @
d1c7c2a2
package
com.ctrip.apollo.core.exception
;
public
abstract
class
AbstractBaseException
extends
RuntimeException
{
/**
*
*/
private
static
final
long
serialVersionUID
=
-
1713129594004951820L
;
private
String
errorCode
;
public
AbstractBaseException
(){
}
public
AbstractBaseException
(
String
str
){
super
(
str
);
}
public
AbstractBaseException
(
String
str
,
String
errorCode
){
super
(
str
);
this
.
setErrorCode
(
errorCode
);
}
public
String
getErrorCode
()
{
return
errorCode
;
}
public
void
setErrorCode
(
String
errorCode
)
{
this
.
errorCode
=
errorCode
;
}
}
apollo-core/src/main/java/com/ctrip/apollo/core/exception/BadRequestException.java
0 → 100644
浏览文件 @
d1c7c2a2
package
com.ctrip.apollo.core.exception
;
public
class
BadRequestException
extends
AbstractBaseException
{
/**
*
*/
private
static
final
long
serialVersionUID
=
6060826407312134068L
;
public
BadRequestException
(
String
str
)
{
super
(
str
);
}
}
apollo-core/src/main/java/com/ctrip/apollo/core/exception/NotFoundException.java
浏览文件 @
d1c7c2a2
package
com.ctrip.apollo.core.exception
;
public
class
NotFoundException
extends
Runtim
eException
{
public
class
NotFoundException
extends
AbstractBas
eException
{
/**
*
*/
private
static
final
long
serialVersionUID
=
7611357629749481796L
;
public
NotFoundException
(){
}
public
NotFoundException
(
String
str
){
public
NotFoundException
(
String
str
)
{
super
(
str
);
}
}
apollo-core/src/main/java/com/ctrip/apollo/core/exception/ServiceException.java
浏览文件 @
d1c7c2a2
package
com.ctrip.apollo.core.exception
;
public
class
ServiceException
extends
Runtim
eException
{
public
class
ServiceException
extends
AbstractBas
eException
{
/**
*
*/
private
static
final
long
serialVersionUID
=
1L
;
private
static
final
long
serialVersionUID
=
-
652912376406554779
1L
;
public
ServiceException
(
String
str
)
{
super
(
str
);
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/AppController.java
浏览文件 @
d1c7c2a2
package
com.ctrip.apollo.portal.controller
;
import
com.google.common.base.Strings
;
import
com.ctrip.apollo.core.dto.AppDTO
;
import
com.ctrip.apollo.core.utils.StringUtils
;
import
com.ctrip.apollo.portal.entity.ClusterNavTree
;
import
com.ctrip.apollo.portal.service.AppService
;
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
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.ctrip.apollo.core.dto.AppDTO
;
import
com.ctrip.apollo.core.exception.BadRequestException
;
import
com.ctrip.apollo.core.utils.StringUtils
;
import
com.ctrip.apollo.portal.entity.ClusterNavTree
;
import
com.ctrip.apollo.portal.service.AppService
;
import
com.google.common.base.Strings
;
@RestController
@RequestMapping
(
"/apps"
)
public
class
AppController
{
...
...
@@ -26,30 +24,23 @@ public class AppController {
@RequestMapping
(
"/{appId}/navtree"
)
public
ClusterNavTree
nav
(
@PathVariable
String
appId
)
{
if
(
Strings
.
isNullOrEmpty
(
appId
))
{
throw
new
IllegalArgumen
tException
(
"app id can not be empty."
);
throw
new
BadReques
tException
(
"app id can not be empty."
);
}
return
appService
.
buildClusterNavTree
(
appId
);
}
@RequestMapping
(
value
=
""
,
method
=
RequestMethod
.
POST
,
consumes
=
{
"application/json"
})
public
ResponseEntity
<
AppDTO
>
create
(
@RequestBody
AppDTO
app
)
{
public
AppDTO
create
(
@RequestBody
AppDTO
app
)
{
if
(
isInvalidApp
(
app
)){
return
ResponseEntity
.
badRequest
().
body
(
null
);
throw
new
BadRequestException
(
"request payload contains empty"
);
}
AppDTO
createdApp
=
appService
.
save
(
app
);
if
(
createdApp
!=
null
){
return
ResponseEntity
.
ok
().
body
(
createdApp
);
}
else
{
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
null
);
}
return
createdApp
;
}
private
boolean
isInvalidApp
(
AppDTO
app
)
{
return
StringUtils
.
isContainEmpty
(
app
.
getName
(),
app
.
getAppId
(),
app
.
getOwnerEmail
(),
app
.
getOwnerName
());
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/ConfigController.java
浏览文件 @
d1c7c2a2
...
...
@@ -3,6 +3,7 @@ package com.ctrip.apollo.portal.controller;
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.NamespaceModifyModel
;
import
com.ctrip.apollo.portal.entity.NamespaceVO
;
...
...
@@ -39,21 +40,22 @@ public class ConfigController {
return
configService
.
findNampspaces
(
appId
,
Apollo
.
Env
.
valueOf
(
env
),
clusterName
);
}
@RequestMapping
(
value
=
"/apps/{appId}/env/{env}/clusters/{clusterName}/namespaces/{namespaceName}/items"
,
method
=
RequestMethod
.
PUT
,
consumes
=
{
"application/json"
})
@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
,
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
,
@RequestBody
NamespaceModifyModel
model
)
{
if
(
model
==
null
){
return
ResponseEntity
.
badRequest
().
body
(
new
SimpleMsg
(
"form data exception."
)
);
if
(
model
==
null
)
{
throw
new
BadRequestException
(
"request payload shoud not be null"
);
}
model
.
setAppId
(
appId
);
model
.
setClusterName
(
clusterName
);
model
.
setEnv
(
env
);
model
.
setNamespaceName
(
namespaceName
);
if
(
model
.
isInvalid
()){
return
ResponseEntity
.
badRequest
().
body
(
new
SimpleMsg
(
"form data exception."
)
);
if
(
model
.
isInvalid
())
{
throw
new
BadRequestException
(
"request model is invalid"
);
}
TextResolverResult
result
=
configService
.
resolveConfigText
(
model
);
...
...
@@ -65,27 +67,29 @@ public class ConfigController {
}
}
@RequestMapping
(
value
=
"/apps/{appId}/env/{env}/clusters/{clusterName}/namespaces/{namespaceName}/release"
,
method
=
RequestMethod
.
POST
,
consumes
=
{
"application/json"
})
public
ResponseEntity
<
SimpleMsg
>
createRelease
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
,
@RequestBody
NamespaceReleaseModel
model
){
if
(
model
==
null
){
return
ResponseEntity
.
badRequest
().
body
(
new
SimpleMsg
(
"form data exception."
));
@RequestMapping
(
value
=
"/apps/{appId}/env/{env}/clusters/{clusterName}/namespaces/{namespaceName}/release"
,
method
=
RequestMethod
.
POST
,
consumes
=
{
"application/json"
})
public
ResponseEntity
<
SimpleMsg
>
createRelease
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
,
@RequestBody
NamespaceReleaseModel
model
)
{
if
(
model
==
null
)
{
throw
new
BadRequestException
(
"request payload shoud not be null"
);
}
model
.
setAppId
(
appId
);
model
.
setClusterName
(
clusterName
);
model
.
setEnv
(
env
);
model
.
setNamespaceName
(
namespaceName
);
if
(
model
.
isInvalid
()){
return
ResponseEntity
.
badRequest
().
body
(
new
SimpleMsg
(
"form data exception."
)
);
if
(
model
.
isInvalid
())
{
throw
new
BadRequestException
(
"request model is invalid"
);
}
ReleaseDTO
release
=
configService
.
release
(
model
);
if
(
release
==
null
){
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
new
SimpleMsg
(
"oops! some error in server."
));
}
else
{
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/controller/GlobalDefaultExceptionHandler.java
浏览文件 @
d1c7c2a2
...
...
@@ -7,8 +7,8 @@ import org.springframework.web.HttpMediaTypeException;
import
org.springframework.web.HttpRequestMethodNotSupportedException
;
import
org.springframework.web.bind.annotation.ControllerAdvice
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ResponseStatus
;
import
com.ctrip.apollo.core.exception.BadRequestException
;
import
com.ctrip.apollo.core.exception.NotFoundException
;
import
java.time.LocalDateTime
;
...
...
@@ -58,8 +58,13 @@ public class GlobalDefaultExceptionHandler {
}
@ExceptionHandler
(
NotFoundException
.
class
)
@ResponseStatus
(
value
=
NOT_FOUND
)
public
void
notFound
(
HttpServletRequest
req
,
NotFoundException
ex
)
{
public
ResponseEntity
<
Map
<
String
,
Object
>>
notFound
(
HttpServletRequest
request
,
NotFoundException
ex
)
{
return
handleError
(
request
,
NOT_FOUND
,
ex
);
}
@ExceptionHandler
(
BadRequestException
.
class
)
public
ResponseEntity
<
Map
<
String
,
Object
>>
badRequest
(
HttpServletRequest
request
,
BadRequestException
ex
){
return
handleError
(
request
,
BAD_REQUEST
,
ex
);
}
private
Throwable
resolveError
(
Throwable
ex
)
{
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/AppService.java
浏览文件 @
d1c7c2a2
...
...
@@ -10,12 +10,9 @@ import org.springframework.stereotype.Service;
import
com.ctrip.apollo.Apollo.Env
;
import
com.ctrip.apollo.core.dto.AppDTO
;
import
com.ctrip.apollo.core.utils.StringUtils
;
import
com.ctrip.apollo.portal.PortalSettings
;
import
com.ctrip.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.apollo.portal.entity.ClusterNavTree
;
import
com.ctrip.apollo.portal.entity.SimpleMsg
;
@Service
public
class
AppService
{
...
...
@@ -52,7 +49,7 @@ public class AppService {
return
appAPI
.
save
(
Env
.
LOCAL
,
app
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"oops! save app error. app id:{}"
,
app
.
getAppId
(),
e
);
return
null
;
throw
e
;
}
}
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ClusterService.java
浏览文件 @
d1c7c2a2
...
...
@@ -7,7 +7,6 @@ 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.List
;
@Service
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录