Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apollo
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
apollo
Commits
d1c7c2a2
Commit
d1c7c2a2
authored
Apr 15, 2016
by
lepdou
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #91 from yiming187/ex_update
Refactor Exception
parents
d93d3cc0
5f99ea3f
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
94 additions
and
55 deletions
+94
-55
AbstractBaseException.java
...om/ctrip/apollo/core/exception/AbstractBaseException.java
+32
-0
BadRequestException.java
.../com/ctrip/apollo/core/exception/BadRequestException.java
+14
-0
NotFoundException.java
...va/com/ctrip/apollo/core/exception/NotFoundException.java
+3
-6
ServiceException.java
...ava/com/ctrip/apollo/core/exception/ServiceException.java
+2
-2
AppController.java
...ava/com/ctrip/apollo/portal/controller/AppController.java
+11
-20
ConfigController.java
.../com/ctrip/apollo/portal/controller/ConfigController.java
+23
-19
GlobalDefaultExceptionHandler.java
...ollo/portal/controller/GlobalDefaultExceptionHandler.java
+8
-3
AppService.java
...main/java/com/ctrip/apollo/portal/service/AppService.java
+1
-4
ClusterService.java
.../java/com/ctrip/apollo/portal/service/ClusterService.java
+0
-1
No files found.
apollo-core/src/main/java/com/ctrip/apollo/core/exception/AbstractBaseException.java
0 → 100644
View file @
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
View file @
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
View file @
d1c7c2a2
package
com
.
ctrip
.
apollo
.
core
.
exception
;
package
com
.
ctrip
.
apollo
.
core
.
exception
;
public
class
NotFoundException
extends
Runtim
eException
{
public
class
NotFoundException
extends
AbstractBas
eException
{
/**
/**
*
*
*/
*/
private
static
final
long
serialVersionUID
=
7611357629749481796L
;
private
static
final
long
serialVersionUID
=
7611357629749481796L
;
public
NotFoundException
(){
public
NotFoundException
(
String
str
)
{
}
public
NotFoundException
(
String
str
){
super
(
str
);
super
(
str
);
}
}
}
}
apollo-core/src/main/java/com/ctrip/apollo/core/exception/ServiceException.java
View file @
d1c7c2a2
package
com
.
ctrip
.
apollo
.
core
.
exception
;
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
)
{
public
ServiceException
(
String
str
)
{
super
(
str
);
super
(
str
);
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/AppController.java
View file @
d1c7c2a2
package
com
.
ctrip
.
apollo
.
portal
.
controller
;
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.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.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
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
@RestController
@RequestMapping
(
"/apps"
)
@RequestMapping
(
"/apps"
)
public
class
AppController
{
public
class
AppController
{
...
@@ -26,30 +24,23 @@ public class AppController {
...
@@ -26,30 +24,23 @@ public class AppController {
@RequestMapping
(
"/{appId}/navtree"
)
@RequestMapping
(
"/{appId}/navtree"
)
public
ClusterNavTree
nav
(
@PathVariable
String
appId
)
{
public
ClusterNavTree
nav
(
@PathVariable
String
appId
)
{
if
(
Strings
.
isNullOrEmpty
(
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
);
return
appService
.
buildClusterNavTree
(
appId
);
}
}
@RequestMapping
(
value
=
""
,
method
=
RequestMethod
.
POST
,
consumes
=
{
"application/json"
})
@RequestMapping
(
value
=
""
,
method
=
RequestMethod
.
POST
,
consumes
=
{
"application/json"
})
public
ResponseEntity
<
AppDTO
>
create
(
@RequestBody
AppDTO
app
)
{
public
AppDTO
create
(
@RequestBody
AppDTO
app
)
{
if
(
isInvalidApp
(
app
)){
if
(
isInvalidApp
(
app
)){
return
ResponseEntity
.
badRequest
().
body
(
null
);
throw
new
BadRequestException
(
"request payload contains empty"
);
}
}
AppDTO
createdApp
=
appService
.
save
(
app
);
AppDTO
createdApp
=
appService
.
save
(
app
);
if
(
createdApp
!=
null
){
return
createdApp
;
return
ResponseEntity
.
ok
().
body
(
createdApp
);
}
else
{
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
null
);
}
}
}
private
boolean
isInvalidApp
(
AppDTO
app
)
{
private
boolean
isInvalidApp
(
AppDTO
app
)
{
return
StringUtils
.
isContainEmpty
(
app
.
getName
(),
app
.
getAppId
(),
app
.
getOwnerEmail
(),
app
.
getOwnerName
());
return
StringUtils
.
isContainEmpty
(
app
.
getName
(),
app
.
getAppId
(),
app
.
getOwnerEmail
(),
app
.
getOwnerName
());
}
}
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/ConfigController.java
View file @
d1c7c2a2
...
@@ -3,6 +3,7 @@ package com.ctrip.apollo.portal.controller;
...
@@ -3,6 +3,7 @@ package com.ctrip.apollo.portal.controller;
import
com.ctrip.apollo.Apollo
;
import
com.ctrip.apollo.Apollo
;
import
com.ctrip.apollo.core.dto.ReleaseDTO
;
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.core.utils.StringUtils
;
import
com.ctrip.apollo.portal.entity.form.NamespaceModifyModel
;
import
com.ctrip.apollo.portal.entity.form.NamespaceModifyModel
;
import
com.ctrip.apollo.portal.entity.NamespaceVO
;
import
com.ctrip.apollo.portal.entity.NamespaceVO
;
...
@@ -31,7 +32,7 @@ public class ConfigController {
...
@@ -31,7 +32,7 @@ public class ConfigController {
@RequestMapping
(
"/apps/{appId}/env/{env}/clusters/{clusterName}/namespaces"
)
@RequestMapping
(
"/apps/{appId}/env/{env}/clusters/{clusterName}/namespaces"
)
public
List
<
NamespaceVO
>
findNamespaces
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
public
List
<
NamespaceVO
>
findNamespaces
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@PathVariable
String
clusterName
)
{
@PathVariable
String
clusterName
)
{
if
(
StringUtils
.
isContainEmpty
(
appId
,
env
,
clusterName
))
{
if
(
StringUtils
.
isContainEmpty
(
appId
,
env
,
clusterName
))
{
throw
new
IllegalArgumentException
(
"app id and cluster name can not be empty"
);
throw
new
IllegalArgumentException
(
"app id and cluster name can not be empty"
);
}
}
...
@@ -39,21 +40,22 @@ public class ConfigController {
...
@@ -39,21 +40,22 @@ public class ConfigController {
return
configService
.
findNampspaces
(
appId
,
Apollo
.
Env
.
valueOf
(
env
),
clusterName
);
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
,
public
ResponseEntity
<
SimpleMsg
>
modifyItems
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
,
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
,
@RequestBody
NamespaceModifyModel
model
)
{
@RequestBody
NamespaceModifyModel
model
)
{
if
(
model
==
null
){
if
(
model
==
null
)
{
return
ResponseEntity
.
badRequest
().
body
(
new
SimpleMsg
(
"form data exception."
)
);
throw
new
BadRequestException
(
"request payload shoud not be null"
);
}
}
model
.
setAppId
(
appId
);
model
.
setAppId
(
appId
);
model
.
setClusterName
(
clusterName
);
model
.
setClusterName
(
clusterName
);
model
.
setEnv
(
env
);
model
.
setEnv
(
env
);
model
.
setNamespaceName
(
namespaceName
);
model
.
setNamespaceName
(
namespaceName
);
if
(
model
.
isInvalid
()){
if
(
model
.
isInvalid
())
{
return
ResponseEntity
.
badRequest
().
body
(
new
SimpleMsg
(
"form data exception."
)
);
throw
new
BadRequestException
(
"request model is invalid"
);
}
}
TextResolverResult
result
=
configService
.
resolveConfigText
(
model
);
TextResolverResult
result
=
configService
.
resolveConfigText
(
model
);
...
@@ -65,27 +67,29 @@ public class ConfigController {
...
@@ -65,27 +67,29 @@ public class ConfigController {
}
}
}
}
@RequestMapping
(
value
=
"/apps/{appId}/env/{env}/clusters/{clusterName}/namespaces/{namespaceName}/release"
,
method
=
RequestMethod
.
POST
,
consumes
=
{
"application/json"
})
@RequestMapping
(
value
=
"/apps/{appId}/env/{env}/clusters/{clusterName}/namespaces/{namespaceName}/release"
,
method
=
RequestMethod
.
POST
,
consumes
=
{
public
ResponseEntity
<
SimpleMsg
>
createRelease
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
"application/json"
})
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
,
public
ResponseEntity
<
SimpleMsg
>
createRelease
(
@PathVariable
String
appId
,
@RequestBody
NamespaceReleaseModel
model
){
@PathVariable
String
env
,
@PathVariable
String
clusterName
,
if
(
model
==
null
){
@PathVariable
String
namespaceName
,
@RequestBody
NamespaceReleaseModel
model
)
{
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
.
setAppId
(
appId
);
model
.
setClusterName
(
clusterName
);
model
.
setClusterName
(
clusterName
);
model
.
setEnv
(
env
);
model
.
setEnv
(
env
);
model
.
setNamespaceName
(
namespaceName
);
model
.
setNamespaceName
(
namespaceName
);
if
(
model
.
isInvalid
()){
if
(
model
.
isInvalid
())
{
return
ResponseEntity
.
badRequest
().
body
(
new
SimpleMsg
(
"form data exception."
)
);
throw
new
BadRequestException
(
"request model is invalid"
);
}
}
ReleaseDTO
release
=
configService
.
release
(
model
);
ReleaseDTO
release
=
configService
.
release
(
model
);
if
(
release
==
null
){
if
(
release
==
null
)
{
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
new
SimpleMsg
(
"oops! some error in server."
));
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
)
}
else
{
.
body
(
new
SimpleMsg
(
"oops! some error in server."
));
}
else
{
return
ResponseEntity
.
ok
().
body
(
new
SimpleMsg
(
"success"
));
return
ResponseEntity
.
ok
().
body
(
new
SimpleMsg
(
"success"
));
}
}
}
}
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/GlobalDefaultExceptionHandler.java
View file @
d1c7c2a2
...
@@ -7,8 +7,8 @@ import org.springframework.web.HttpMediaTypeException;
...
@@ -7,8 +7,8 @@ import org.springframework.web.HttpMediaTypeException;
import
org.springframework.web.HttpRequestMethodNotSupportedException
;
import
org.springframework.web.HttpRequestMethodNotSupportedException
;
import
org.springframework.web.bind.annotation.ControllerAdvice
;
import
org.springframework.web.bind.annotation.ControllerAdvice
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
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
com.ctrip.apollo.core.exception.NotFoundException
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
...
@@ -58,8 +58,13 @@ public class GlobalDefaultExceptionHandler {
...
@@ -58,8 +58,13 @@ public class GlobalDefaultExceptionHandler {
}
}
@ExceptionHandler
(
NotFoundException
.
class
)
@ExceptionHandler
(
NotFoundException
.
class
)
@ResponseStatus
(
value
=
NOT_FOUND
)
public
ResponseEntity
<
Map
<
String
,
Object
>>
notFound
(
HttpServletRequest
request
,
NotFoundException
ex
)
{
public
void
notFound
(
HttpServletRequest
req
,
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
)
{
private
Throwable
resolveError
(
Throwable
ex
)
{
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/AppService.java
View file @
d1c7c2a2
...
@@ -10,12 +10,9 @@ import org.springframework.stereotype.Service;
...
@@ -10,12 +10,9 @@ import org.springframework.stereotype.Service;
import
com.ctrip.apollo.Apollo.Env
;
import
com.ctrip.apollo.Apollo.Env
;
import
com.ctrip.apollo.core.dto.AppDTO
;
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.PortalSettings
;
import
com.ctrip.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.apollo.portal.entity.ClusterNavTree
;
import
com.ctrip.apollo.portal.entity.ClusterNavTree
;
import
com.ctrip.apollo.portal.entity.SimpleMsg
;
@Service
@Service
public
class
AppService
{
public
class
AppService
{
...
@@ -52,7 +49,7 @@ public class AppService {
...
@@ -52,7 +49,7 @@ public class AppService {
return
appAPI
.
save
(
Env
.
LOCAL
,
app
);
return
appAPI
.
save
(
Env
.
LOCAL
,
app
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
error
(
"oops! save app error. app id:{}"
,
app
.
getAppId
(),
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
View file @
d1c7c2a2
...
@@ -7,7 +7,6 @@ import com.ctrip.apollo.portal.api.AdminServiceAPI;
...
@@ -7,7 +7,6 @@ import com.ctrip.apollo.portal.api.AdminServiceAPI;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.List
;
@Service
@Service
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment