This is an automated email from the ASF dual-hosted git repository.

mmerli pushed a commit to branch branch-2.8
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/branch-2.8 by this push:
     new a8383d9  Fix deleting tenants with active namespaces with 500. (#13020)
a8383d9 is described below

commit a8383d961b3b6d6740c8a1f31054e5f50a768315
Author: Jiwei Guo <techno...@apache.org>
AuthorDate: Tue Nov 30 01:01:42 2021 +0800

    Fix deleting tenants with active namespaces with 500. (#13020)
---
 .../java/org/apache/pulsar/broker/admin/impl/TenantsBase.java     | 6 +++++-
 .../main/java/org/apache/pulsar/broker/web/PulsarWebResource.java | 6 +++---
 .../test/java/org/apache/pulsar/broker/admin/AdminApiTest.java    | 8 ++++++++
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git 
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/TenantsBase.java
 
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/TenantsBase.java
index 879e8b0..f5f3b8e 100644
--- 
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/TenantsBase.java
+++ 
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/TenantsBase.java
@@ -288,7 +288,11 @@ public class TenantsBase extends PulsarWebResource {
                 }
             }).exceptionally(ex -> {
                 log.error("Failed to delete tenant due to active namespace 
{}", tenant, ex.getCause());
-                asyncResponse.resume(new RestException(ex));
+                if (ex.getCause() instanceof IllegalStateException) {
+                    asyncResponse.resume(new RestException(Status.CONFLICT, 
ex.getCause()));
+                } else {
+                    asyncResponse.resume(new RestException(ex));
+                }
                 return null;
             });
         });
diff --git 
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/web/PulsarWebResource.java
 
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/web/PulsarWebResource.java
index f0ee3a1..d44a812 100644
--- 
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/web/PulsarWebResource.java
+++ 
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/web/PulsarWebResource.java
@@ -955,7 +955,7 @@ public abstract class PulsarWebResource {
                             }
                             if (children != null && !children.isEmpty()) {
                                 checkNs.completeExceptionally(
-                                        new 
RestException(Status.PRECONDITION_FAILED, "Tenant has active namespace"));
+                                        new IllegalStateException("The tenant 
still has active namespaces"));
                                 return;
                             }
                             String namespace = NamespaceName.get(tenant, 
clusterOrNamespace).toString();
@@ -965,8 +965,8 @@ public abstract class PulsarWebResource {
                             // add it to the list
                             namespaceResources().getAsync(path(POLICIES, 
namespace)).thenApply(data -> {
                                 if (data.isPresent()) {
-                                    checkNs.completeExceptionally(new 
RestException(Status.PRECONDITION_FAILED,
-                                            "Tenant has active namespace"));
+                                    checkNs.completeExceptionally(
+                                            new IllegalStateException("The 
tenant still has active namespaces"));
                                 } else {
                                     checkNs.complete(null);
                                 }
diff --git 
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest.java 
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest.java
index ce9bfa4..2d9ddc4 100644
--- 
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest.java
+++ 
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest.java
@@ -673,6 +673,14 @@ public class AdminApiTest extends 
MockedPulsarServiceBaseTest {
         admin.tenants().updateTenant("prop-xyz", newTenantAdmin);
 
         assertEquals(admin.tenants().getTenantInfo("prop-xyz"), 
newTenantAdmin);
+        try {
+            admin.tenants().deleteTenant("prop-xyz");
+            fail("should have failed");
+        } catch (PulsarAdminException e) {
+            assertTrue(e instanceof ConflictException);
+            assertEquals(e.getStatusCode(), 409);
+            assertEquals(e.getMessage(), "The tenant still has active 
namespaces");
+        }
 
         admin.namespaces().deleteNamespace("prop-xyz/ns1");
         admin.tenants().deleteTenant("prop-xyz");

Reply via email to