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
39ef9ca6
Unverified
Commit
39ef9ca6
authored
Oct 05, 2018
by
Jason Song
Committed by
GitHub
Oct 05, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1533 from nobodyiam/open-api-gray-release-refactor
refactor gray release open api a little bit
parents
9bb54dd6
3481843e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
16 deletions
+33
-16
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/util/OpenApiBeanUtils.java
...ctrip/framework/apollo/openapi/util/OpenApiBeanUtils.java
+4
-16
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceBranchController.java
...ollo/openapi/v1/controller/NamespaceBranchController.java
+29
-0
No files found.
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/util/OpenApiBeanUtils.java
View file @
39ef9ca6
...
...
@@ -108,26 +108,14 @@ public class OpenApiBeanUtils {
}
public
static
OpenGrayReleaseRuleDTO
transformFromGrayReleaseRuleDTO
(
GrayReleaseRuleDTO
grayReleaseRuleDTO
){
OpenGrayReleaseRuleDTO
openGrayReleaseRuleDTO
=
new
OpenGrayReleaseRuleDTO
();
openGrayReleaseRuleDTO
.
setAppId
(
grayReleaseRuleDTO
.
getAppId
());
openGrayReleaseRuleDTO
.
setBranchName
(
grayReleaseRuleDTO
.
getBranchName
());
openGrayReleaseRuleDTO
.
setClusterName
(
grayReleaseRuleDTO
.
getClusterName
());
openGrayReleaseRuleDTO
.
setNamespaceName
(
grayReleaseRuleDTO
.
getNamespaceName
());
Set
<
GrayReleaseRuleItemDTO
>
grayReleaseRuleItemDTOSet
=
grayReleaseRuleDTO
.
getRuleItems
();
Set
<
OpenGrayReleaseRuleItemDTO
>
ruleItems
=
new
HashSet
<>();
grayReleaseRuleItemDTOSet
.
forEach
(
grayReleaseRuleItemDTO
->
{
OpenGrayReleaseRuleItemDTO
item
=
new
OpenGrayReleaseRuleItemDTO
();
item
.
setClientAppId
(
grayReleaseRuleItemDTO
.
getClientAppId
());
item
.
setClientIpList
(
grayReleaseRuleItemDTO
.
getClientIpList
());
ruleItems
.
add
(
item
);
});
openGrayReleaseRuleDTO
.
setRuleItems
(
ruleItems
);
Preconditions
.
checkArgument
(
grayReleaseRuleDTO
!=
null
);
return
openGrayReleaseRuleDTO
;
return
BeanUtils
.
transfrom
(
OpenGrayReleaseRuleDTO
.
class
,
grayReleaseRuleDTO
)
;
}
public
static
GrayReleaseRuleDTO
transformToGrayReleaseRuleDTO
(
OpenGrayReleaseRuleDTO
openGrayReleaseRuleDTO
){
Preconditions
.
checkArgument
(
openGrayReleaseRuleDTO
!=
null
);
String
appId
=
openGrayReleaseRuleDTO
.
getAppId
();
String
branchName
=
openGrayReleaseRuleDTO
.
getBranchName
();
String
clusterName
=
openGrayReleaseRuleDTO
.
getClusterName
();
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceBranchController.java
View file @
39ef9ca6
...
...
@@ -6,8 +6,11 @@ package com.ctrip.framework.apollo.openapi.v1.controller;
import
com.ctrip.framework.apollo.common.dto.GrayReleaseRuleDTO
;
import
com.ctrip.framework.apollo.common.dto.NamespaceDTO
;
import
com.ctrip.framework.apollo.common.exception.BadRequestException
;
import
com.ctrip.framework.apollo.common.utils.BeanUtils
;
import
com.ctrip.framework.apollo.common.utils.RequestPrecondition
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.core.utils.StringUtils
;
import
com.ctrip.framework.apollo.openapi.auth.ConsumerPermissionValidator
;
import
com.ctrip.framework.apollo.openapi.dto.OpenGrayReleaseRuleDTO
;
import
com.ctrip.framework.apollo.openapi.dto.OpenNamespaceDTO
;
...
...
@@ -16,6 +19,7 @@ import com.ctrip.framework.apollo.portal.component.PermissionValidator;
import
com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO
;
import
com.ctrip.framework.apollo.portal.service.NamespaceBranchService
;
import
com.ctrip.framework.apollo.portal.service.ReleaseService
;
import
com.ctrip.framework.apollo.portal.spi.UserService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.access.AccessDeniedException
;
import
org.springframework.security.access.prepost.PreAuthorize
;
...
...
@@ -33,6 +37,8 @@ public class NamespaceBranchController {
private
ReleaseService
releaseService
;
@Autowired
private
NamespaceBranchService
namespaceBranchService
;
@Autowired
private
UserService
userService
;
@RequestMapping
(
value
=
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/branches"
,
method
=
RequestMethod
.
GET
)
public
OpenNamespaceDTO
findBranch
(
@PathVariable
String
appId
,
...
...
@@ -54,6 +60,12 @@ public class NamespaceBranchController {
@PathVariable
String
namespaceName
,
@RequestParam
(
"operator"
)
String
operator
,
HttpServletRequest
request
)
{
RequestPrecondition
.
checkArguments
(!
StringUtils
.
isContainEmpty
(
operator
),
"operator can not be empty"
);
if
(
userService
.
findByUserId
(
operator
)
==
null
)
{
throw
new
BadRequestException
(
"operator "
+
operator
+
" not exists"
);
}
NamespaceDTO
namespaceDTO
=
namespaceBranchService
.
createBranch
(
appId
,
Env
.
valueOf
(
env
.
toUpperCase
()),
clusterName
,
namespaceName
,
operator
);
if
(
namespaceDTO
==
null
)
{
return
null
;
...
...
@@ -70,6 +82,12 @@ public class NamespaceBranchController {
@PathVariable
String
branchName
,
@RequestParam
(
"operator"
)
String
operator
,
HttpServletRequest
request
)
{
RequestPrecondition
.
checkArguments
(!
StringUtils
.
isContainEmpty
(
operator
),
"operator can not be empty"
);
if
(
userService
.
findByUserId
(
operator
)
==
null
)
{
throw
new
BadRequestException
(
"operator "
+
operator
+
" not exists"
);
}
boolean
canDelete
=
consumerPermissionValidator
.
hasReleaseNamespacePermission
(
request
,
appId
,
namespaceName
,
env
)
||
(
consumerPermissionValidator
.
hasModifyNamespacePermission
(
request
,
appId
,
namespaceName
,
env
)
&&
releaseService
.
loadLatestRelease
(
appId
,
Env
.
valueOf
(
env
),
branchName
,
namespaceName
)
==
null
);
...
...
@@ -103,6 +121,17 @@ public class NamespaceBranchController {
@PathVariable
String
branchName
,
@RequestBody
OpenGrayReleaseRuleDTO
rules
,
@RequestParam
(
"operator"
)
String
operator
,
HttpServletRequest
request
)
{
RequestPrecondition
.
checkArguments
(!
StringUtils
.
isContainEmpty
(
operator
),
"operator can not be empty"
);
if
(
userService
.
findByUserId
(
operator
)
==
null
)
{
throw
new
BadRequestException
(
"operator "
+
operator
+
" not exists"
);
}
rules
.
setAppId
(
appId
);
rules
.
setClusterName
(
clusterName
);
rules
.
setNamespaceName
(
namespaceName
);
rules
.
setBranchName
(
branchName
);
GrayReleaseRuleDTO
grayReleaseRuleDTO
=
OpenApiBeanUtils
.
transformToGrayReleaseRuleDTO
(
rules
);
namespaceBranchService
.
updateBranchGrayRules
(
appId
,
Env
.
valueOf
(
env
.
toUpperCase
()),
clusterName
,
namespaceName
,
branchName
,
grayReleaseRuleDTO
,
operator
);
...
...
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