Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wrr-cat
apollo
提交
d23e60e1
apollo
项目概览
wrr-cat
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
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,发现更多精彩内容 >>
未验证
提交
d23e60e1
编写于
7月 22, 2018
作者:
J
Jason Song
提交者:
GitHub
7月 22, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1276 from nobodyiam/delete-app-api
add delete app api
上级
6860f0a2
2d9ece83
变更
27
展开全部
隐藏空白更改
内联
并排
Showing
27 changed file
with
403 addition
and
140 deletion
+403
-140
apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/AppController.java
...amework/apollo/adminservice/controller/AppController.java
+1
-2
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AppNamespaceRepository.java
...amework/apollo/biz/repository/AppNamespaceRepository.java
+5
-0
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AppRepository.java
.../ctrip/framework/apollo/biz/repository/AppRepository.java
+0
-1
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/GrayReleaseRuleRepository.java
...work/apollo/biz/repository/GrayReleaseRuleRepository.java
+5
-0
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AdminService.java
.../com/ctrip/framework/apollo/biz/service/AdminService.java
+29
-0
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AppNamespaceService.java
...rip/framework/apollo/biz/service/AppNamespaceService.java
+5
-0
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ClusterService.java
...om/ctrip/framework/apollo/biz/service/ClusterService.java
+3
-0
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/GrayReleaseRuleService.java
.../framework/apollo/biz/service/GrayReleaseRuleService.java
+18
-0
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/NamespaceService.java
.../ctrip/framework/apollo/biz/service/NamespaceService.java
+13
-12
apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/AdminServiceTest.java
.../ctrip/framework/apollo/biz/service/AdminServiceTest.java
+39
-5
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/repository/ConsumerRoleRepository.java
...ork/apollo/openapi/repository/ConsumerRoleRepository.java
+6
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/AdminServiceAPI.java
...om/ctrip/framework/apollo/portal/api/AdminServiceAPI.java
+85
-84
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/AppController.java
...rip/framework/apollo/portal/controller/AppController.java
+33
-23
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/listener/AppDeletionEvent.java
...ip/framework/apollo/portal/listener/AppDeletionEvent.java
+17
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/listener/AppInfoChangedListener.java
...mework/apollo/portal/listener/AppInfoChangedListener.java
+17
-2
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/AppNamespaceRepository.java
...work/apollo/portal/repository/AppNamespaceRepository.java
+6
-3
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/AppRepository.java
...rip/framework/apollo/portal/repository/AppRepository.java
+5
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/FavoriteRepository.java
...ramework/apollo/portal/repository/FavoriteRepository.java
+6
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/PermissionRepository.java
...mework/apollo/portal/repository/PermissionRepository.java
+10
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/RolePermissionRepository.java
...rk/apollo/portal/repository/RolePermissionRepository.java
+5
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/RoleRepository.java
...ip/framework/apollo/portal/repository/RoleRepository.java
+14
-1
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/UserRoleRepository.java
...ramework/apollo/portal/repository/UserRoleRepository.java
+6
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppNamespaceService.java
.../framework/apollo/portal/service/AppNamespaceService.java
+3
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppService.java
...com/ctrip/framework/apollo/portal/service/AppService.java
+29
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/FavoriteService.java
...trip/framework/apollo/portal/service/FavoriteService.java
+7
-6
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/RolePermissionService.java
...ramework/apollo/portal/service/RolePermissionService.java
+4
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultRolePermissionService.java
.../portal/spi/defaultimpl/DefaultRolePermissionService.java
+32
-1
未找到文件。
apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/AppController.java
浏览文件 @
d23e60e1
...
...
@@ -54,7 +54,7 @@ public class AppController {
if
(
entity
==
null
)
{
throw
new
NotFoundException
(
"app not found for appId "
+
appId
);
}
a
ppService
.
delete
(
entity
.
getId
()
,
operator
);
a
dminService
.
deleteApp
(
entity
,
operator
);
}
@RequestMapping
(
value
=
"/apps/{appId:.+}"
,
method
=
RequestMethod
.
PUT
)
...
...
@@ -91,5 +91,4 @@ public class AppController {
public
boolean
isAppIdUnique
(
@PathVariable
(
"appId"
)
String
appId
)
{
return
appService
.
isAppIdUnique
(
appId
);
}
}
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AppNamespaceRepository.java
浏览文件 @
d23e60e1
...
...
@@ -2,6 +2,8 @@ package com.ctrip.framework.apollo.biz.repository;
import
com.ctrip.framework.apollo.common.entity.AppNamespace
;
import
org.springframework.data.jpa.repository.Modifying
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
java.util.List
;
...
...
@@ -24,4 +26,7 @@ public interface AppNamespaceRepository extends PagingAndSortingRepository<AppNa
List
<
AppNamespace
>
findFirst500ByIdGreaterThanOrderByIdAsc
(
long
id
);
@Modifying
@Query
(
"UPDATE AppNamespace SET IsDeleted=1,DataChange_LastModifiedBy = ?2 WHERE AppId=?1"
)
int
batchDeleteByAppId
(
String
appId
,
String
operator
);
}
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AppRepository.java
浏览文件 @
d23e60e1
...
...
@@ -14,5 +14,4 @@ public interface AppRepository extends PagingAndSortingRepository<App, Long> {
List
<
App
>
findByName
(
@Param
(
"name"
)
String
name
);
App
findByAppId
(
String
appId
);
}
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/GrayReleaseRuleRepository.java
浏览文件 @
d23e60e1
...
...
@@ -2,6 +2,8 @@ package com.ctrip.framework.apollo.biz.repository;
import
com.ctrip.framework.apollo.biz.entity.GrayReleaseRule
;
import
org.springframework.data.jpa.repository.Modifying
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
java.util.List
;
...
...
@@ -17,4 +19,7 @@ public interface GrayReleaseRuleRepository extends PagingAndSortingRepository<Gr
List
<
GrayReleaseRule
>
findFirst500ByIdGreaterThanOrderByIdAsc
(
Long
id
);
@Modifying
@Query
(
"UPDATE GrayReleaseRule SET IsDeleted=1, DataChange_LastModifiedBy = ?4 where appId=?1 and clusterName=?2 and namespaceName = ?3"
)
int
batchDelete
(
String
appId
,
String
clusterName
,
String
namespaceName
,
String
operator
);
}
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AdminService.java
浏览文件 @
d23e60e1
package
com.ctrip.framework.apollo.biz.service
;
import
com.ctrip.framework.apollo.biz.entity.Cluster
;
import
com.ctrip.framework.apollo.common.entity.App
;
import
com.ctrip.framework.apollo.common.exception.NotFoundException
;
import
com.ctrip.framework.apollo.core.ConfigConsts
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.List
;
import
java.util.Objects
;
@Service
public
class
AdminService
{
...
...
@@ -19,6 +26,8 @@ public class AdminService {
@Autowired
private
NamespaceService
namespaceService
;
private
final
static
Logger
logger
=
LoggerFactory
.
getLogger
(
AdminService
.
class
);
@Transactional
public
App
createNewApp
(
App
app
)
{
String
createBy
=
app
.
getDataChangeCreatedBy
();
...
...
@@ -35,5 +44,25 @@ public class AdminService {
return
app
;
}
@Transactional
public
void
deleteApp
(
App
app
,
String
operator
)
{
String
appId
=
app
.
getAppId
();
logger
.
info
(
"{} is deleting App:{}"
,
operator
,
appId
);
List
<
Cluster
>
managedClusters
=
clusterService
.
findClusters
(
appId
);
// 1. delete clusters
if
(
Objects
.
nonNull
(
managedClusters
))
{
for
(
Cluster
cluster
:
managedClusters
)
{
clusterService
.
delete
(
cluster
.
getId
(),
operator
);
}
}
// 2. delete appNamespace
appNamespaceService
.
batchDelete
(
appId
,
operator
);
// 3. delete app
appService
.
delete
(
app
.
getId
(),
operator
);
}
}
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AppNamespaceService.java
浏览文件 @
d23e60e1
...
...
@@ -137,4 +137,9 @@ public class AppNamespaceService {
namespaceService
.
save
(
namespace
);
}
}
@Transactional
public
void
batchDelete
(
String
appId
,
String
operator
)
{
appNamespaceRepository
.
batchDeleteByAppId
(
appId
,
operator
);
}
}
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ClusterService.java
浏览文件 @
d23e60e1
...
...
@@ -137,4 +137,7 @@ public class ClusterService {
return
clusterRepository
.
findByParentClusterId
(
parentCluster
.
getId
());
}
public
List
<
Cluster
>
findClusters
(
String
appId
)
{
return
clusterRepository
.
findByAppId
(
appId
);
}
}
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/GrayReleaseRuleService.java
0 → 100644
浏览文件 @
d23e60e1
package
com.ctrip.framework.apollo.biz.service
;
import
com.ctrip.framework.apollo.biz.repository.GrayReleaseRuleRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
@Service
public
class
GrayReleaseRuleService
{
@Autowired
private
GrayReleaseRuleRepository
grayReleaseRuleRepository
;
@Transactional
public
void
batchDelete
(
String
appId
,
String
clusterName
,
String
namespaceName
,
String
operator
)
{
grayReleaseRuleRepository
.
batchDelete
(
appId
,
clusterName
,
namespaceName
,
operator
);
}
}
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/NamespaceService.java
浏览文件 @
d23e60e1
...
...
@@ -59,6 +59,8 @@ public class NamespaceService {
@Autowired
private
ReleaseHistoryService
releaseHistoryService
;
@Autowired
private
GrayReleaseRuleService
grayReleaseRuleService
;
@Autowired
private
NamespaceLockService
namespaceLockService
;
@Autowired
private
InstanceService
instanceService
;
...
...
@@ -263,17 +265,18 @@ public class NamespaceService {
itemService
.
batchDelete
(
namespace
.
getId
(),
operator
);
commitService
.
batchDelete
(
appId
,
clusterName
,
namespace
.
getNamespaceName
(),
operator
);
if
(!
isChildNamespace
(
namespace
))
{
releaseService
.
batchDelete
(
appId
,
clusterName
,
namespace
.
getNamespaceName
(),
operator
);
}
releaseService
.
batchDelete
(
appId
,
clusterName
,
namespace
.
getNamespaceName
(),
operator
);
grayReleaseRuleService
.
batchDelete
(
appId
,
clusterName
,
namespace
.
getNamespaceName
(),
operator
);
//delete child namespace
Namespace
childNamespace
=
findChildNamespace
(
namespace
);
if
(
childNamespace
!=
null
)
{
namespaceBranchService
.
deleteBranch
(
appId
,
clusterName
,
namespaceName
,
childNamespace
.
getClusterName
(),
NamespaceBranchStatus
.
DELETED
,
operator
);
//delete child namespace's releases. Notice: delete child namespace will not delete child namespace's releases
releaseService
.
batchDelete
(
appId
,
childNamespace
.
getClusterName
(),
namespaceName
,
operator
);
if
(!
isChildNamespace
(
namespace
))
{
//delete child namespace
Namespace
childNamespace
=
findChildNamespace
(
namespace
);
if
(
childNamespace
!=
null
)
{
namespaceBranchService
.
deleteBranch
(
appId
,
clusterName
,
namespaceName
,
childNamespace
.
getClusterName
(),
NamespaceBranchStatus
.
DELETED
,
operator
);
//delete child namespace's releases. Notice: delete child namespace will not delete child namespace's releases
releaseService
.
batchDelete
(
appId
,
childNamespace
.
getClusterName
(),
namespaceName
,
operator
);
}
}
releaseHistoryService
.
batchDelete
(
appId
,
clusterName
,
namespaceName
,
operator
);
...
...
@@ -394,6 +397,4 @@ public class NamespaceService {
return
false
;
}
}
apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/AdminServiceTest.java
浏览文件 @
d23e60e1
...
...
@@ -8,15 +8,13 @@ import com.ctrip.framework.apollo.biz.repository.AppRepository;
import
com.ctrip.framework.apollo.common.entity.App
;
import
com.ctrip.framework.apollo.common.exception.ServiceException
;
import
com.ctrip.framework.apollo.core.ConfigConsts
;
import
java.util.Date
;
import
java.util.List
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
java.util.Date
;
import
java.util.List
;
public
class
AdminServiceTest
extends
AbstractIntegrationTest
{
public
class
AdminServiceTest
extends
AbstractIntegrationTest
{
@Autowired
private
AdminService
adminService
;
...
...
@@ -33,6 +31,9 @@ public class AdminServiceTest extends AbstractIntegrationTest{
@Autowired
private
NamespaceService
namespaceService
;
@Autowired
private
AppNamespaceService
appNamespaceService
;
@Test
public
void
testCreateNewApp
()
{
String
appId
=
"someAppId"
;
...
...
@@ -79,4 +80,37 @@ public class AdminServiceTest extends AbstractIntegrationTest{
adminService
.
createNewApp
(
app
);
}
@Test
public
void
testDeleteApp
()
{
String
appId
=
"someAppId"
;
App
app
=
new
App
();
app
.
setAppId
(
appId
);
app
.
setName
(
"someAppName"
);
String
owner
=
"someOwnerName"
;
app
.
setOwnerName
(
owner
);
app
.
setOwnerEmail
(
"someOwnerName@ctrip.com"
);
app
.
setDataChangeCreatedBy
(
owner
);
app
.
setDataChangeLastModifiedBy
(
owner
);
app
.
setDataChangeCreatedTime
(
new
Date
());
app
=
adminService
.
createNewApp
(
app
);
Assert
.
assertEquals
(
appId
,
app
.
getAppId
());
Assert
.
assertEquals
(
1
,
appNamespaceService
.
findByAppId
(
appId
).
size
());
Assert
.
assertEquals
(
1
,
clusterService
.
findClusters
(
appId
).
size
());
Assert
.
assertEquals
(
1
,
namespaceService
.
findNamespaces
(
appId
,
ConfigConsts
.
CLUSTER_NAME_DEFAULT
).
size
());
adminService
.
deleteApp
(
app
,
owner
);
Assert
.
assertEquals
(
0
,
appNamespaceService
.
findByAppId
(
appId
).
size
());
Assert
.
assertEquals
(
0
,
clusterService
.
findClusters
(
appId
).
size
());
Assert
.
assertEquals
(
0
,
namespaceService
.
findByAppIdAndNamespaceName
(
appId
,
ConfigConsts
.
CLUSTER_NAME_DEFAULT
).
size
());
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/repository/ConsumerRoleRepository.java
浏览文件 @
d23e60e1
...
...
@@ -2,6 +2,8 @@ package com.ctrip.framework.apollo.openapi.repository;
import
com.ctrip.framework.apollo.openapi.entity.ConsumerRole
;
import
org.springframework.data.jpa.repository.Modifying
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
java.util.List
;
...
...
@@ -23,4 +25,8 @@ public interface ConsumerRoleRepository extends PagingAndSortingRepository<Consu
List
<
ConsumerRole
>
findByRoleId
(
long
roleId
);
ConsumerRole
findByConsumerIdAndRoleId
(
long
consumerId
,
long
roleId
);
@Modifying
@Query
(
"UPDATE ConsumerRole SET IsDeleted=1, DataChange_LastModifiedBy = ?2 WHERE RoleId in ?1"
)
Integer
batchDeleteByRoleIds
(
List
<
Long
>
roleIds
,
String
operator
);
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/AdminServiceAPI.java
浏览文件 @
d23e60e1
此差异已折叠。
点击以展开。
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/AppController.java
浏览文件 @
d23e60e1
package
com.ctrip.framework.apollo.portal.controller
;
import
com.google.common.collect.Sets
;
import
com.ctrip.framework.apollo.common.entity.App
;
import
com.ctrip.framework.apollo.common.exception.BadRequestException
;
import
com.ctrip.framework.apollo.common.http.MultiResponseEntity
;
...
...
@@ -14,12 +12,16 @@ import com.ctrip.framework.apollo.portal.component.PortalSettings;
import
com.ctrip.framework.apollo.portal.entity.model.AppModel
;
import
com.ctrip.framework.apollo.portal.entity.vo.EnvClusterInfo
;
import
com.ctrip.framework.apollo.portal.listener.AppCreationEvent
;
import
com.ctrip.framework.apollo.portal.listener.AppDeletionEvent
;
import
com.ctrip.framework.apollo.portal.listener.AppInfoChangedEvent
;
import
com.ctrip.framework.apollo.portal.service.AppService
;
import
com.ctrip.framework.apollo.portal.service.RolePermissionService
;
import
com.ctrip.framework.apollo.portal.spi.UserInfoHolder
;
import
com.ctrip.framework.apollo.portal.util.RoleUtils
;
import
com.google.common.collect.Sets
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.Set
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ApplicationEventPublisher
;
import
org.springframework.data.domain.Pageable
;
...
...
@@ -36,10 +38,6 @@ import org.springframework.web.bind.annotation.RequestParam;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.client.HttpClientErrorException
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.Set
;
@RestController
@RequestMapping
(
"/apps"
)
...
...
@@ -82,8 +80,9 @@ public class AppController {
Set
<
String
>
admins
=
appModel
.
getAdmins
();
if
(!
CollectionUtils
.
isEmpty
(
admins
))
{
rolePermissionService
.
assignRoleToUsers
(
RoleUtils
.
buildAppMasterRoleName
(
createdApp
.
getAppId
()),
admins
,
userInfoHolder
.
getUser
().
getUserId
());
rolePermissionService
.
assignRoleToUsers
(
RoleUtils
.
buildAppMasterRoleName
(
createdApp
.
getAppId
()),
admins
,
userInfoHolder
.
getUser
().
getUserId
());
}
return
createdApp
;
...
...
@@ -113,8 +112,8 @@ public class AppController {
response
.
addResponseEntity
(
RichResponseEntity
.
ok
(
appService
.
createEnvNavNode
(
env
,
appId
)));
}
catch
(
Exception
e
)
{
response
.
addResponseEntity
(
RichResponseEntity
.
error
(
HttpStatus
.
INTERNAL_SERVER_ERROR
,
"load env:"
+
env
.
name
()
+
" cluster error."
+
e
.
getMessage
()));
"load env:"
+
env
.
name
()
+
" cluster error."
+
e
.
getMessage
()));
}
}
return
response
;
...
...
@@ -124,8 +123,9 @@ public class AppController {
"application/json"
})
public
ResponseEntity
<
Void
>
create
(
@PathVariable
String
env
,
@RequestBody
App
app
)
{
RequestPrecondition
.
checkArgumentsNotEmpty
(
app
.
getName
(),
app
.
getAppId
(),
app
.
getOwnerEmail
(),
app
.
getOwnerName
(),
app
.
getOrgId
(),
app
.
getOrgName
());
RequestPrecondition
.
checkArgumentsNotEmpty
(
app
.
getName
(),
app
.
getAppId
(),
app
.
getOwnerEmail
(),
app
.
getOwnerName
(),
app
.
getOrgId
(),
app
.
getOrgName
());
if
(!
InputValidator
.
isValidClusterNamespace
(
app
.
getAppId
()))
{
throw
new
BadRequestException
(
InputValidator
.
INVALID_CLUSTER_NAMESPACE_MESSAGE
);
}
...
...
@@ -141,6 +141,15 @@ public class AppController {
return
appService
.
load
(
appId
);
}
@PreAuthorize
(
value
=
"@permissionValidator.isSuperAdmin()"
)
@RequestMapping
(
value
=
"/{appId:.+}"
,
method
=
RequestMethod
.
DELETE
)
public
void
deleteApp
(
@PathVariable
String
appId
)
{
App
app
=
appService
.
deleteAppInLocal
(
appId
);
publisher
.
publishEvent
(
new
AppDeletionEvent
(
app
));
}
@RequestMapping
(
value
=
"/{appId}/miss_envs"
,
method
=
RequestMethod
.
GET
)
public
MultiResponseEntity
<
Env
>
findMissEnvs
(
@PathVariable
String
appId
)
{
...
...
@@ -154,9 +163,9 @@ public class AppController {
response
.
addResponseEntity
(
RichResponseEntity
.
ok
(
env
));
}
else
{
response
.
addResponseEntity
(
RichResponseEntity
.
error
(
HttpStatus
.
INTERNAL_SERVER_ERROR
,
String
.
format
(
"load appId:%s from env %s error."
,
appId
,
env
)
+
e
.
getMessage
()));
String
.
format
(
"load appId:%s from env %s error."
,
appId
,
env
)
+
e
.
getMessage
()));
}
}
}
...
...
@@ -175,16 +184,17 @@ public class AppController {
RequestPrecondition
.
checkArgumentsNotEmpty
(
appId
,
appName
,
ownerName
,
orgId
,
orgName
);
if
(!
InputValidator
.
isValidClusterNamespace
(
appModel
.
getAppId
()))
{
throw
new
BadRequestException
(
String
.
format
(
"AppId格式错误: %s"
,
InputValidator
.
INVALID_CLUSTER_NAMESPACE_MESSAGE
));
throw
new
BadRequestException
(
String
.
format
(
"AppId格式错误: %s"
,
InputValidator
.
INVALID_CLUSTER_NAMESPACE_MESSAGE
));
}
return
App
.
builder
()
.
appId
(
appId
)
.
name
(
appName
)
.
ownerName
(
ownerName
)
.
orgId
(
orgId
)
.
orgName
(
orgName
)
.
build
();
.
appId
(
appId
)
.
name
(
appName
)
.
ownerName
(
ownerName
)
.
orgId
(
orgId
)
.
orgName
(
orgName
)
.
build
();
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/listener/AppDeletionEvent.java
0 → 100644
浏览文件 @
d23e60e1
package
com.ctrip.framework.apollo.portal.listener
;
import
com.ctrip.framework.apollo.common.entity.App
;
import
com.google.common.base.Preconditions
;
import
org.springframework.context.ApplicationEvent
;
public
class
AppDeletionEvent
extends
ApplicationEvent
{
public
AppDeletionEvent
(
Object
source
)
{
super
(
source
);
}
public
App
getApp
()
{
Preconditions
.
checkState
(
source
!=
null
);
return
(
App
)
this
.
source
;
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/listener/AppInfoChangedListener.java
浏览文件 @
d23e60e1
...
...
@@ -5,6 +5,7 @@ import com.ctrip.framework.apollo.common.utils.BeanUtils;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.framework.apollo.portal.component.PortalSettings
;
import
com.ctrip.framework.apollo.portal.spi.UserInfoHolder
;
import
com.ctrip.framework.apollo.tracer.Tracer
;
import
org.slf4j.Logger
;
...
...
@@ -24,7 +25,6 @@ public class AppInfoChangedListener {
@Autowired
private
PortalSettings
portalSettings
;
@EventListener
public
void
onAppInfoChange
(
AppInfoChangedEvent
event
)
{
AppDTO
appDTO
=
BeanUtils
.
transfrom
(
AppDTO
.
class
,
event
.
getApp
());
...
...
@@ -39,7 +39,22 @@ public class AppInfoChangedListener {
Tracer
.
logError
(
String
.
format
(
"Update app's info failed. Env = %s, AppId = %s"
,
env
,
appId
),
e
);
}
}
}
@EventListener
public
void
onAppDelete
(
AppDeletionEvent
event
)
{
AppDTO
appDTO
=
BeanUtils
.
transfrom
(
AppDTO
.
class
,
event
.
getApp
());
String
appId
=
appDTO
.
getAppId
();
String
operator
=
appDTO
.
getDataChangeLastModifiedBy
();
List
<
Env
>
envs
=
portalSettings
.
getActiveEnvs
();
for
(
Env
env
:
envs
)
{
try
{
appAPI
.
deleteApp
(
env
,
appId
,
operator
);
}
catch
(
Throwable
e
)
{
logger
.
error
(
"Delete app failed. Env = {}, AppId = {}"
,
env
,
appId
,
e
);
Tracer
.
logError
(
String
.
format
(
"Delete app failed. Env = %s, AppId = %s"
,
env
,
appId
),
e
);
}
}
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/AppNamespaceRepository.java
浏览文件 @
d23e60e1
package
com.ctrip.framework.apollo.portal.repository
;
import
com.ctrip.framework.apollo.common.entity.AppNamespace
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
java.util.List
;
import
org.springframework.data.jpa.repository.Modifying
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
public
interface
AppNamespaceRepository
extends
PagingAndSortingRepository
<
AppNamespace
,
Long
>
{
...
...
@@ -16,4 +16,7 @@ public interface AppNamespaceRepository extends PagingAndSortingRepository<AppNa
List
<
AppNamespace
>
findByIsPublicTrue
();
@Modifying
@Query
(
"UPDATE AppNamespace SET IsDeleted=1,DataChange_LastModifiedBy=?2 WHERE AppId=?1"
)
int
batchDeleteByAppId
(
String
appId
,
String
operator
);
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/AppRepository.java
浏览文件 @
d23e60e1
...
...
@@ -3,6 +3,8 @@ package com.ctrip.framework.apollo.portal.repository;
import
com.ctrip.framework.apollo.common.entity.App
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.jpa.repository.Modifying
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
java.util.List
;
...
...
@@ -17,4 +19,7 @@ public interface AppRepository extends PagingAndSortingRepository<App, Long> {
List
<
App
>
findByAppIdIn
(
Set
<
String
>
appIds
);
@Modifying
@Query
(
"UPDATE App SET IsDeleted=1,DataChange_LastModifiedBy = ?2 WHERE AppId=?1"
)
int
deleteApp
(
String
appId
,
String
operator
);
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/FavoriteRepository.java
浏览文件 @
d23e60e1
...
...
@@ -3,6 +3,8 @@ package com.ctrip.framework.apollo.portal.repository;
import
com.ctrip.framework.apollo.portal.entity.po.Favorite
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.jpa.repository.Modifying
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
java.util.List
;
...
...
@@ -16,4 +18,8 @@ public interface FavoriteRepository extends PagingAndSortingRepository<Favorite,
Favorite
findFirstByUserIdOrderByPositionAscDataChangeCreatedTimeAsc
(
String
userId
);
Favorite
findByUserIdAndAppId
(
String
userId
,
String
appId
);
@Modifying
@Query
(
"UPDATE Favorite SET IsDeleted=1,DataChange_LastModifiedBy = ?2 WHERE AppId=?1"
)
int
batchDeleteByAppId
(
String
appId
,
String
operator
);
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/PermissionRepository.java
浏览文件 @
d23e60e1
...
...
@@ -2,10 +2,13 @@ package com.ctrip.framework.apollo.portal.repository;
import
com.ctrip.framework.apollo.portal.entity.po.Permission
;
import
org.springframework.data.jpa.repository.Modifying
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
java.util.Collection
;
import
java.util.List
;
import
org.springframework.data.repository.query.Param
;
/**
* @author Jason Song(song_s@ctrip.com)
...
...
@@ -21,4 +24,11 @@ public interface PermissionRepository extends PagingAndSortingRepository<Permiss
*/
List
<
Permission
>
findByPermissionTypeInAndTargetId
(
Collection
<
String
>
permissionTypes
,
String
targetId
);
@Query
(
"SELECT p.id from Permission p where p.targetId = ?1 or p.targetId like CONCAT(?1, '+%'))"
)
List
<
Long
>
findPermissionIdsByAppId
(
String
appId
);
@Modifying
@Query
(
"UPDATE Permission SET IsDeleted=1, DataChange_LastModifiedBy = ?2 WHERE Id in ?1"
)
Integer
batchDelete
(
List
<
Long
>
permissionIds
,
String
operator
);
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/RolePermissionRepository.java
浏览文件 @
d23e60e1
...
...
@@ -2,6 +2,8 @@ package com.ctrip.framework.apollo.portal.repository;
import
com.ctrip.framework.apollo.portal.entity.po.RolePermission
;
import
org.springframework.data.jpa.repository.Modifying
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
java.util.Collection
;
...
...
@@ -17,4 +19,7 @@ public interface RolePermissionRepository extends PagingAndSortingRepository<Rol
*/
List
<
RolePermission
>
findByRoleIdIn
(
Collection
<
Long
>
roleId
);
@Modifying
@Query
(
"UPDATE RolePermission SET IsDeleted=1, DataChange_LastModifiedBy = ?2 WHERE PermissionId in ?1"
)
Integer
batchDeleteByPermissionIds
(
List
<
Long
>
permissionIds
,
String
operator
);
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/RoleRepository.java
浏览文件 @
d23e60e1
package
com.ctrip.framework.apollo.portal.repository
;
import
com.ctrip.framework.apollo.portal.entity.po.Role
;
import
java.util.List
;
import
org.springframework.data.jpa.repository.Modifying
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
org.springframework.data.repository.query.Param
;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public
interface
RoleRepository
extends
PagingAndSortingRepository
<
Role
,
Long
>
{
/**
* find role by role name
*/
Role
findTopByRoleName
(
String
roleName
);
@Query
(
"SELECT r.id from Role r where (r.roleName = CONCAT('Master+', ?1) "
+
"OR r.roleName like CONCAT('ModifyNamespace+', ?1, '+%') "
+
"OR r.roleName like CONCAT('ReleaseNamespace+', ?1, '+%'))"
)
List
<
Long
>
findRoleIdsByAppId
(
String
appId
);
@Modifying
@Query
(
"UPDATE Role SET IsDeleted=1, DataChange_LastModifiedBy = ?2 WHERE Id in ?1"
)
Integer
batchDelete
(
List
<
Long
>
roleIds
,
String
operator
);
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/UserRoleRepository.java
浏览文件 @
d23e60e1
...
...
@@ -2,6 +2,8 @@ package com.ctrip.framework.apollo.portal.repository;
import
com.ctrip.framework.apollo.portal.entity.po.UserRole
;
import
org.springframework.data.jpa.repository.Modifying
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
java.util.Collection
;
...
...
@@ -26,4 +28,8 @@ public interface UserRoleRepository extends PagingAndSortingRepository<UserRole,
*/
List
<
UserRole
>
findByUserIdInAndRoleId
(
Collection
<
String
>
userId
,
long
roleId
);
@Modifying
@Query
(
"UPDATE UserRole SET IsDeleted=1, DataChange_LastModifiedBy = ?2 WHERE RoleId in ?1"
)
Integer
batchDeleteByRoleIds
(
List
<
Long
>
roleIds
,
String
operator
);
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppNamespaceService.java
浏览文件 @
d23e60e1
...
...
@@ -118,4 +118,7 @@ public class AppNamespaceService {
return
createdAppNamespace
;
}
public
void
batchDeleteByAppId
(
String
appId
,
String
operator
)
{
appNamespaceRepository
.
batchDeleteByAppId
(
appId
,
operator
);
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppService.java
浏览文件 @
d23e60e1
...
...
@@ -41,6 +41,10 @@ public class AppService {
@Autowired
private
RoleInitializationService
roleInitializationService
;
@Autowired
private
RolePermissionService
rolePermissionService
;
@Autowired
private
FavoriteService
favoriteService
;
@Autowired
private
UserService
userService
;
...
...
@@ -139,4 +143,29 @@ public class AppService {
return
node
;
}
@Transactional
public
App
deleteAppInLocal
(
String
appId
)
{
App
managedApp
=
appRepository
.
findByAppId
(
appId
);
if
(
managedApp
==
null
)
{
throw
new
BadRequestException
(
String
.
format
(
"App not exists. AppId = %s"
,
appId
));
}
String
operator
=
userInfoHolder
.
getUser
().
getUserId
();
//this operator is passed to com.ctrip.framework.apollo.portal.listener.AppInfoChangedListener.onAppDelete
managedApp
.
setDataChangeLastModifiedBy
(
operator
);
//删除portal数据库中的app
appRepository
.
deleteApp
(
appId
,
operator
);
//删除portal数据库中的appNamespace
appNamespaceService
.
batchDeleteByAppId
(
appId
,
operator
);
//删除portal数据库中的收藏表
favoriteService
.
batchDeleteByAppId
(
appId
,
operator
);
//删除portal数据库中Permission、Role相关数据
rolePermissionService
.
deleteRolePermissionsByAppId
(
appId
,
operator
);
return
managedApp
;
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/FavoriteService.java
浏览文件 @
d23e60e1
package
com.ctrip.framework.apollo.portal.service
;
import
com.ctrip.framework.apollo.common.exception.BadRequestException
;
import
com.ctrip.framework.apollo.portal.entity.po.Favorite
;
import
com.ctrip.framework.apollo.portal.entity.bo.UserInfo
;
import
com.ctrip.framework.apollo.portal.entity.po.Favorite
;
import
com.ctrip.framework.apollo.portal.repository.FavoriteRepository
;
import
com.ctrip.framework.apollo.portal.spi.UserInfoHolder
;
import
com.ctrip.framework.apollo.portal.spi.UserService
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Objects
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.StringUtils
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Objects
;
@Service
public
class
FavoriteService
{
...
...
@@ -110,4 +108,7 @@ public class FavoriteService {
}
}
public
void
batchDeleteByAppId
(
String
appId
,
String
operator
)
{
favoriteRepository
.
batchDeleteByAppId
(
appId
,
operator
);
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/RolePermissionService.java
浏览文件 @
d23e60e1
...
...
@@ -56,4 +56,8 @@ public interface RolePermissionService {
*/
public
Set
<
Permission
>
createPermissions
(
Set
<
Permission
>
permissions
);
/**
* delete permissions when delete app.
*/
public
void
deleteRolePermissionsByAppId
(
String
appId
,
String
operator
);
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultRolePermissionService.java
浏览文件 @
d23e60e1
package
com.ctrip.framework.apollo.portal.spi.defaultimpl
;
import
com.ctrip.framework.apollo.common.entity.BaseEntity
;
import
com.ctrip.framework.apollo.openapi.repository.ConsumerRoleRepository
;
import
com.ctrip.framework.apollo.portal.component.config.PortalConfig
;
import
com.ctrip.framework.apollo.portal.entity.bo.UserInfo
;
import
com.ctrip.framework.apollo.portal.entity.po.Permission
;
...
...
@@ -16,6 +18,8 @@ import com.google.common.collect.FluentIterable;
import
com.google.common.collect.HashMultimap
;
import
com.google.common.collect.Multimap
;
import
com.google.common.collect.Sets
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.CollectionUtils
;
...
...
@@ -36,7 +40,8 @@ public class DefaultRolePermissionService implements RolePermissionService {
private
PermissionRepository
permissionRepository
;
@Autowired
private
PortalConfig
portalConfig
;
@Autowired
private
ConsumerRoleRepository
consumerRoleRepository
;
/**
* Create role with permissions, note that role name should be unique
...
...
@@ -220,4 +225,30 @@ public class DefaultRolePermissionService implements RolePermissionService {
return
FluentIterable
.
from
(
results
).
toSet
();
}
@Transactional
@Override
public
void
deleteRolePermissionsByAppId
(
String
appId
,
String
operator
)
{
List
<
Long
>
permissionIds
=
permissionRepository
.
findPermissionIdsByAppId
(
appId
);
if
(!
permissionIds
.
isEmpty
())
{
// 1. delete Permission
permissionRepository
.
batchDelete
(
permissionIds
,
operator
);
// 2. delete Role Permission
rolePermissionRepository
.
batchDeleteByPermissionIds
(
permissionIds
,
operator
);
}
List
<
Long
>
roleIds
=
roleRepository
.
findRoleIdsByAppId
(
appId
);
if
(!
roleIds
.
isEmpty
())
{
// 3. delete Role
roleRepository
.
batchDelete
(
roleIds
,
operator
);
// 4. delete User Role
userRoleRepository
.
batchDeleteByRoleIds
(
roleIds
,
operator
);
// 5. delete Consumer Role
consumerRoleRepository
.
batchDeleteByRoleIds
(
roleIds
,
operator
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录