Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
apollo
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Administrator
apollo
Commits
a8a4a0d3
Unverified
Commit
a8a4a0d3
authored
Oct 21, 2018
by
Jason Song
Committed by
GitHub
Oct 21, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1586 from zouyx/master
Block delete default cluster
parents
2dbb8112
ee136b7d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
0 deletions
+58
-0
apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/ClusterController.java
...ork/apollo/adminservice/controller/ClusterController.java
+8
-0
apollo-adminservice/src/test/java/com/ctrip/framework/apollo/adminservice/controller/ClusterControllerTest.java
...apollo/adminservice/controller/ClusterControllerTest.java
+50
-0
No files found.
apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/ClusterController.java
View file @
a8a4a0d3
...
@@ -8,6 +8,7 @@ import com.ctrip.framework.apollo.common.exception.NotFoundException;
...
@@ -8,6 +8,7 @@ import com.ctrip.framework.apollo.common.exception.NotFoundException;
import
com.ctrip.framework.apollo.common.utils.BeanUtils
;
import
com.ctrip.framework.apollo.common.utils.BeanUtils
;
import
com.ctrip.framework.apollo.common.utils.InputValidator
;
import
com.ctrip.framework.apollo.common.utils.InputValidator
;
import
com.ctrip.framework.apollo.core.ConfigConsts
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
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
;
...
@@ -51,10 +52,17 @@ public class ClusterController {
...
@@ -51,10 +52,17 @@ public class ClusterController {
@RequestMapping
(
path
=
"/apps/{appId}/clusters/{clusterName:.+}"
,
method
=
RequestMethod
.
DELETE
)
@RequestMapping
(
path
=
"/apps/{appId}/clusters/{clusterName:.+}"
,
method
=
RequestMethod
.
DELETE
)
public
void
delete
(
@PathVariable
(
"appId"
)
String
appId
,
public
void
delete
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@RequestParam
String
operator
)
{
@PathVariable
(
"clusterName"
)
String
clusterName
,
@RequestParam
String
operator
)
{
Cluster
entity
=
clusterService
.
findOne
(
appId
,
clusterName
);
Cluster
entity
=
clusterService
.
findOne
(
appId
,
clusterName
);
if
(
entity
==
null
)
{
if
(
entity
==
null
)
{
throw
new
NotFoundException
(
"cluster not found for clusterName "
+
clusterName
);
throw
new
NotFoundException
(
"cluster not found for clusterName "
+
clusterName
);
}
}
if
(
ConfigConsts
.
CLUSTER_NAME_DEFAULT
.
equals
(
entity
.
getName
())){
throw
new
BadRequestException
(
"default cluster can not be delete."
);
}
clusterService
.
delete
(
entity
.
getId
(),
operator
);
clusterService
.
delete
(
entity
.
getId
(),
operator
);
}
}
...
...
apollo-adminservice/src/test/java/com/ctrip/framework/apollo/adminservice/controller/ClusterControllerTest.java
0 → 100644
View file @
a8a4a0d3
package
com
.
ctrip
.
framework
.
apollo
.
adminservice
.
controller
;
import
com.ctrip.framework.apollo.biz.entity.Cluster
;
import
com.ctrip.framework.apollo.biz.service.ClusterService
;
import
com.ctrip.framework.apollo.common.exception.BadRequestException
;
import
com.ctrip.framework.apollo.core.ConfigConsts
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.MockitoAnnotations
;
import
org.mockito.runners.MockitoJUnitRunner
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Mockito
.
when
;
public
class
ClusterControllerTest
{
ClusterController
clusterController
=
new
ClusterController
();
@Mock
ClusterService
clusterService
;
@Before
public
void
setUp
()
{
MockitoAnnotations
.
initMocks
(
this
);
ReflectionTestUtils
.
setField
(
clusterController
,
"clusterService"
,
clusterService
);
}
@Test
(
expected
=
BadRequestException
.
class
)
public
void
testDeleteDefaultFail
()
{
Cluster
cluster
=
new
Cluster
();
cluster
.
setName
(
ConfigConsts
.
CLUSTER_NAME_DEFAULT
);
when
(
clusterService
.
findOne
(
any
(
String
.
class
),
any
(
String
.
class
))).
thenReturn
(
cluster
);
clusterController
.
delete
(
"1"
,
"2"
,
"d"
);
}
@Test
()
public
void
testDeleteSuccess
()
{
Cluster
cluster
=
new
Cluster
();
when
(
clusterService
.
findOne
(
any
(
String
.
class
),
any
(
String
.
class
))).
thenReturn
(
cluster
);
clusterController
.
delete
(
"1"
,
"2"
,
"d"
);
}
}
\ No newline at end of file
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