Skip to content

Commit e9459a2

Browse files
committed
allow user to delete private namespace
1 parent 0c4069f commit e9459a2

File tree

4 files changed

+14
-32
lines changed

4 files changed

+14
-32
lines changed

apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,26 +74,22 @@ public NamespaceDTO createNamespace(Env env, NamespaceDTO namespace) {
7474
@Transactional
7575
public void deleteNamespace(String appId, Env env, String clusterName, String namespaceName) {
7676

77-
//1. check private namespace
7877
AppNamespace appNamespace = appNamespaceService.findByAppIdAndName(appId, namespaceName);
79-
if (appNamespace != null && !appNamespace.isPublic()) {
80-
throw new BadRequestException("Private namespace can not be deleted");
81-
}
8278

83-
//2. check parent namespace has not instances
79+
//1. check parent namespace has not instances
8480
if (namespaceHasInstances(appId, env, clusterName, namespaceName)) {
8581
throw new BadRequestException("Can not delete namespace because namespace has active instances");
8682
}
8783

88-
//3. check child namespace has not instances
84+
//2. check child namespace has not instances
8985
NamespaceDTO childNamespace = branchService.findBranchBaseInfo(appId, env, clusterName, namespaceName);
9086
if (childNamespace != null &&
9187
namespaceHasInstances(appId, env, childNamespace.getClusterName(), namespaceName)) {
9288
throw new BadRequestException("Can not delete namespace because namespace's branch has active instances");
9389
}
9490

95-
//4. check public namespace has not associated namespace
96-
if (appNamespace != null && publicAppNamespaceHasAssociatedNamespace(namespaceName, env)) {
91+
//3. check public namespace has not associated namespace
92+
if (appNamespace != null && appNamespace.isPublic() && publicAppNamespaceHasAssociatedNamespace(namespaceName, env)) {
9793
throw new BadRequestException("Can not delete public namespace which has associated namespaces");
9894
}
9995

apollo-portal/src/main/resources/static/config.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,7 @@ <h4 class="text-center" ng-show="viewMode == 2">
288288
apollo-detail="'发现有 <b>' + deleteNamespaceContext.namespace.instancesCount +
289289
'</b> 个实例正在使用Namespace(' + deleteNamespaceContext.namespace.baseInfo.namespaceName +
290290
'),删除Namespace将导致实例获取不到配置。<br>
291-
请到 <ins>“实例列表”</ins> 确认实例信息,如已确认删除Namespace将不会导致实例异常,
292-
请联系Apollo相关负责人删除Namespace'"
291+
请到 <ins>“实例列表”</ins> 确认实例信息,如确认相关实例都已经不再使用该Namespace配置,可以联系Apollo相关负责人删除实例信息(InstanceConfig)或等待实例24小时自动过期后再来删除。'"
293292
apollo-confirm="continueDeleteNamespace">
294293
</apolloconfirmdialog>
295294

@@ -298,8 +297,7 @@ <h4 class="text-center" ng-show="viewMode == 2">
298297
apollo-detail="'发现有 <b>' + deleteNamespaceContext.namespace.branch.latestReleaseInstances.total
299298
+ '</b> 个实例正在使用Namespace(' + deleteNamespaceContext.namespace.baseInfo.namespaceName +
300299
')灰度版本的配置,删除Namespace将导致实例获取不到配置。<br>
301-
请到 <ins>“灰度版本” => “实例列表”</ins> 确认实例信息,如已确认删除Namespace将不会导致实例异常,
302-
请联系Apollo相关负责人删除Namespace'"
300+
请到 <ins>“灰度版本” => “实例列表”</ins> 确认实例信息,如确认相关实例都已经不再使用该Namespace配置,可以联系Apollo相关负责人删除实例信息(InstanceConfig)或等待实例24小时自动过期后再来删除。'"
303301
apollo-confirm="continueDeleteNamespace">
304302
</apolloconfirmdialog>
305303

apollo-portal/src/main/resources/static/scripts/directive/delete-namespace-modal-directive.js

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,20 @@ function deleteNamespaceModalDirective($window, $q, toastr, AppUtil, EventManage
1818
var toDeleteNamespace = context.namespace;
1919
scope.toDeleteNamespace = toDeleteNamespace;
2020

21-
//1. check namespace is not private
22-
if (!checkNotPrivateNamespace(toDeleteNamespace)) {
23-
return;
24-
}
25-
26-
//2. check operator has master permission
21+
//1. check operator has master permission
2722
checkPermission(toDeleteNamespace).then(function () {
2823

29-
//3. check namespace's master branch has not instances
24+
//2. check namespace's master branch has not instances
3025
if (!checkMasterInstance(toDeleteNamespace)) {
3126
return;
3227
}
3328

34-
//4. check namespace's gray branch has not instances
29+
//3. check namespace's gray branch has not instances
3530
if (!checkBranchInstance(toDeleteNamespace)) {
3631
return;
3732
}
3833

39-
if (toDeleteNamespace.isLinkedNamespace) {
34+
if (!toDeleteNamespace.isPublic || toDeleteNamespace.isLinkedNamespace) {
4035
showDeleteNamespaceConfirmDialog();
4136
} else {
4237
//5. check public namespace has not associated namespace
@@ -48,15 +43,6 @@ function deleteNamespaceModalDirective($window, $q, toastr, AppUtil, EventManage
4843

4944
});
5045

51-
function checkNotPrivateNamespace(namespace) {
52-
if (!namespace.isPublic) {
53-
toastr.error("不能删除私有的Namespace", "删除失败");
54-
return false;
55-
}
56-
57-
return true;
58-
}
59-
6046
function checkPermission(namespace) {
6147
var d = $q.defer();
6248

@@ -153,7 +139,6 @@ function deleteNamespaceModalDirective($window, $q, toastr, AppUtil, EventManage
153139

154140
function showDeleteNamespaceConfirmDialog() {
155141
AppUtil.showModal('#deleteNamespaceModal');
156-
157142
}
158143

159144
function doDeleteNamespace() {

apollo-portal/src/main/resources/static/views/component/delete-namespace-modal.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ <h4 class="modal-title">
88
删除Namespace
99
</h4>
1010
</div>
11-
<div class="modal-body form-horizontal">
11+
<div class="modal-body form-horizontal" ng-show="toDeleteNamespace.isPublic">
1212
删除Namespace将导致实例获取不到此Namespace的配置,确定要删除吗?
1313
</div>
14+
<div class="modal-body form-horizontal" ng-show="!toDeleteNamespace.isPublic">
15+
删除私有Namespace将导致实例获取不到此Namespace的配置,而且无法在当前集群重新创建该Namespace(除非使用管理员工具把所有环境的AppNamespace删除后重建),确定要删除吗?
16+
</div>
1417
<div class="modal-footer">
1518
<button type="button" class="btn btn-default" data-dismiss="modal">
1619
取消

0 commit comments

Comments
 (0)