You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/08/27 05:02:57 UTC

[GitHub] [pulsar] liangyuanpeng opened a new pull request #11811: [ISSUE 11779] Get response from cause when completion exception

liangyuanpeng opened a new pull request #11811:
URL: https://github.com/apache/pulsar/pull/11811


   <!--
   ### Contribution Checklist
     
     - Name the pull request in the form "[Issue XYZ][component] Title of the pull request", where *XYZ* should be replaced by the actual issue number.
       Skip *Issue XYZ* if there is no associated github issue for this pull request.
       Skip *component* if you are unsure about which is the best component. E.g. `[docs] Fix typo in produce method`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   *(If this PR fixes a github issue, please add `Fixes #<xyz>`.)*
   
   Fixes #11779
   
   *(or if this PR is one task of a github issue, please add `Master Issue: #<xyz>` to link to the master issue.)*
   
   
   
   ### Motivation
   
   
   *Explain here the context, and why you're making that change. What is the problem you're trying to solve.*
   
   We will get the exception of CompletionException when we use  `CompletableFuture#completeExceptionally`. 
   
   But the RestException just work for `WebApplicationException`, and we can get the `WebApplicationException` from `Throwable#getCause()`  when we  use  `CompletableFuture#completeExceptionally` for some WebApplicationException`
   
   Now we juse got the status of 500 and not really status.
   ```
   return Response
                   .status(Status.INTERNAL_SERVER_ERROR)
                   .entity(getExceptionData(t))
                   .type(MediaType.TEXT_PLAIN)
                   .build();
   ```
   
   ### Modifications
   
   *Describe the modifications you've done.*
   
   `RestException#getResponse` Add `Throwable#getCause()` work for instanceof WebApplicationException.
   
   ### Verifying this change
   
   - [ ] Make sure that the change passes the CI checks.
   
   *(Please pick either of the following options)*
   
   This change is a trivial rework / code cleanup without any test coverage.
   
   This change added tests and can be verified as follows:
   
   *(example:)*
     - *Added integration tests for end-to-end deployment with large payloads (10MB)*
     - *Extended integration test for recovery after broker failure*
   
   ### Does this pull request potentially affect one of the following parts:
   
   *If `yes` was chosen, please highlight the changes*
   
     - Dependencies (does it add or upgrade a dependency): (yes / no)
     - The public API: (yes)
     - The schema: (yes / no / don't know)
     - The default values of configurations: (yes / no)
     - The wire protocol: (yes / no)
     - The rest endpoints: (yes / no)
     - The admin cli options: (yes / no)
     - Anything that affects deployment: (yes / no / don't know)
   
   ### Documentation
   
   #### For contributor
   
   For this PR, do we need to update docs?
   
   No,
   
   #### For committer
   
   For this PR, do we need to update docs?
   
   no-need-doc
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] merlimat commented on pull request #11811: [ISSUE 11779] Get response from cause when completion exception

Posted by GitBox <gi...@apache.org>.
merlimat commented on pull request #11811:
URL: https://github.com/apache/pulsar/pull/11811#issuecomment-907268276


   @liangyuanpeng There are few checktyle issues reported in CI: 
   
   ```
   [INFO] There are 4 errors reported by Checkstyle 8.37 with ../buildtools/src/main/resources/pulsar/checkstyle.xml ruleset.
   5651
   Error:  src/main/java/org/apache/pulsar/broker/web/RestException.java:[23,8] (imports) UnusedImports: Unused import: java.util.concurrent.CompletableFuture.
   5652
   Error:  src/main/java/org/apache/pulsar/broker/web/RestException.java:[79,10] (whitespace) WhitespaceAround: 'else' is not preceded with whitespace.
   5653
   Error:  src/main/java/org/apache/pulsar/broker/web/RestException.java:[79,15] (whitespace) WhitespaceAround: 'if' is not followed by whitespace.
   5654
   Error:  src/main/java/org/apache/pulsar/broker/web/PulsarWebResource.java:[72,8] (imports) UnusedImports: Unused import: org.apache.pulsar.client.admin.PulsarAdminException.
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] liangyuanpeng closed pull request #11811: [ISSUE 11779] Get response from cause when completion exception

Posted by GitBox <gi...@apache.org>.
liangyuanpeng closed pull request #11811:
URL: https://github.com/apache/pulsar/pull/11811


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] merlimat commented on a change in pull request #11811: [ISSUE 11779] Get response from cause when completion exception

Posted by GitBox <gi...@apache.org>.
merlimat commented on a change in pull request #11811:
URL: https://github.com/apache/pulsar/pull/11811#discussion_r697513733



##########
File path: pulsar-broker/src/main/resources/log4j2.xml
##########
@@ -0,0 +1,102 @@
+<?xml version="1.0" encoding="UTF-8"?>

Review comment:
       This file shouldn't be added to the PR

##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/web/PulsarWebResource.java
##########
@@ -961,7 +962,7 @@ public void validatePoliciesReadOnlyAccess() {
                             }
                             if (children != null && !children.isEmpty()) {
                                 checkNs.completeExceptionally(
-                                        new RestException(Status.PRECONDITION_FAILED, "Tenant has active namespace"));
+                                        new RestException(Status.CONFLICT, "The tenant still has active namespace"));

Review comment:
       I'm not sure we should change the response code here. Client are expecting the PRECONDITION_FAILED in some of the places.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] liangyuanpeng commented on a change in pull request #11811: [ISSUE 11779] Get response from cause when completion exception

Posted by GitBox <gi...@apache.org>.
liangyuanpeng commented on a change in pull request #11811:
URL: https://github.com/apache/pulsar/pull/11811#discussion_r698013751



##########
File path: pulsar-broker/src/main/resources/log4j2.xml
##########
@@ -0,0 +1,102 @@
+<?xml version="1.0" encoding="UTF-8"?>

Review comment:
       Absolutely, sorry about that.

##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/web/PulsarWebResource.java
##########
@@ -961,7 +962,7 @@ public void validatePoliciesReadOnlyAccess() {
                             }
                             if (children != null && !children.isEmpty()) {
                                 checkNs.completeExceptionally(
-                                        new RestException(Status.PRECONDITION_FAILED, "Tenant has active namespace"));
+                                        new RestException(Status.CONFLICT, "The tenant still has active namespace"));

Review comment:
       Thanks for your review,I'm not sure about "Client are expecting the PRECONDITION_FAILED in some of the places.", Seems like this method (internalDeleteTenant) used by API delete tenant only.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] gaoran10 commented on a change in pull request #11811: [ISSUE 11779] Get response from cause when completion exception

Posted by GitBox <gi...@apache.org>.
gaoran10 commented on a change in pull request #11811:
URL: https://github.com/apache/pulsar/pull/11811#discussion_r700151835



##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/web/RestException.java
##########
@@ -75,6 +76,9 @@ private static Response getResponse(Throwable t) {
         if (t instanceof WebApplicationException) {
             WebApplicationException e = (WebApplicationException) t;
             return e.getResponse();
+        }else if(t.getCause() instanceof WebApplicationException){

Review comment:
       Please maintain the code format style.

##########
File path: pulsar-broker/src/main/resources/log4j2.xml
##########
@@ -0,0 +1,102 @@
+<?xml version="1.0" encoding="UTF-8"?>

Review comment:
       Please remove this file.

##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/web/PulsarWebResource.java
##########
@@ -961,7 +962,7 @@ public void validatePoliciesReadOnlyAccess() {
                             }
                             if (children != null && !children.isEmpty()) {
                                 checkNs.completeExceptionally(
-                                        new RestException(Status.PRECONDITION_FAILED, "Tenant has active namespace"));
+                                        new RestException(Status.CONFLICT, "The tenant still has active namespace"));

Review comment:
       It seems that this is a precondition check, maybe the error code `Status.PRECONDITION_FAILED` is more suitable.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org