pulsar-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] yush1ga closed pull request #910: Fix status code when partitioned-topic unsubscribe fails
Date Thu, 01 Jan 1970 00:00:00 GMT
yush1ga closed pull request #910: Fix status code when partitioned-topic unsubscribe fails
URL: https://github.com/apache/incubator-pulsar/pull/910
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/PersistentTopics.java
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/PersistentTopics.java
index a0ca6a106..a29fbb6eb 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/PersistentTopics.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/PersistentTopics.java
@@ -741,7 +741,14 @@ public void deleteSubscription(@PathParam("property") String property,
@PathPara
                             subName);
                 }
             } catch (Exception e) {
-                throw new RestException(e);
+                if (e instanceof NotFoundException) {
+                    throw new RestException(Status.NOT_FOUND, "Subscription not found");
+                } else if (e instanceof PreconditionFailedException) {
+                    throw new RestException(Status.PRECONDITION_FAILED, "Subscription has
active connected consumers");
+                } else {
+                    log.error("[{}] Failed to delete subscription {} {}", clientAppId(),
dn, subName, e);
+                    throw new RestException(e);
+                }
             }
         } else {
             validateAdminOperationOnDestination(dn, authoritative);
@@ -753,12 +760,12 @@ public void deleteSubscription(@PathParam("property") String property,
@PathPara
                 log.info("[{}][{}] Deleted subscription {}", clientAppId(), dn, subName);
             } catch (Exception e) {
                 Throwable t = e.getCause();
-                log.error("[{}] Failed to delete subscription {} {}", clientAppId(), dn,
subName, e);
                 if (e instanceof NullPointerException) {
                     throw new RestException(Status.NOT_FOUND, "Subscription not found");
                 } else if (t instanceof SubscriptionBusyException) {
                     throw new RestException(Status.PRECONDITION_FAILED, "Subscription has
active connected consumers");
                 } else {
+                    log.error("[{}] Failed to delete subscription {} {}", clientAppId(),
dn, subName, e);
                     throw new RestException(t);
                 }
             }
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 d379daaaf..0ef5d9c90 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
@@ -756,6 +756,15 @@ public void partitionedTopics(String topicName) throws Exception {
 
         assertEquals(admin.persistentTopics().getSubscriptions(partitionedTopicName), Lists.newArrayList("my-sub"));
 
+        try {
+            admin.persistentTopics().deleteSubscription(partitionedTopicName, "my-sub");
+            fail("should have failed");
+        } catch (PulsarAdminException.PreconditionFailedException e) {
+            // ok
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+
         Consumer consumer1 = client.subscribe(partitionedTopicName, "my-sub-1", conf);
 
         assertEquals(Sets.newHashSet(admin.persistentTopics().getSubscriptions(partitionedTopicName)),


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message