You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by fj...@apache.org on 2019/01/11 04:53:23 UTC

[incubator-druid] branch master updated: Propagate errors to RemoteTaskActionClient (#6837)

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

fjy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-druid.git


The following commit(s) were added to refs/heads/master by this push:
     new 39780d9  Propagate errors to RemoteTaskActionClient (#6837)
39780d9 is described below

commit 39780d914c8f81d6d0af918d7b721433ae3314ef
Author: Jihoon Son <ji...@apache.org>
AuthorDate: Thu Jan 10 20:53:18 2019 -0800

    Propagate errors to RemoteTaskActionClient (#6837)
    
    * Propagate errors to RemoteTaskActionClient
    
    * style
---
 .../common/actions/RemoteTaskActionClient.java     |  5 +-
 .../indexing/overlord/http/OverlordResource.java   |  5 +-
 .../common/actions/RemoteTaskActionClientTest.java | 54 ++++++++++------------
 3 files changed, 30 insertions(+), 34 deletions(-)

diff --git a/indexing-service/src/main/java/org/apache/druid/indexing/common/actions/RemoteTaskActionClient.java b/indexing-service/src/main/java/org/apache/druid/indexing/common/actions/RemoteTaskActionClient.java
index a1f2ebb..19046ce 100644
--- a/indexing-service/src/main/java/org/apache/druid/indexing/common/actions/RemoteTaskActionClient.java
+++ b/indexing-service/src/main/java/org/apache/druid/indexing/common/actions/RemoteTaskActionClient.java
@@ -90,8 +90,9 @@ public class RemoteTaskActionClient implements TaskActionClient
         } else {
           // Want to retry, so throw an IOException.
           throw new IOE(
-              "Scary HTTP status returned: %s. Check your overlord logs for exceptions.",
-              fullResponseHolder.getStatus()
+              "Error with status[%s] and message[%s]. Check overlord logs for details.",
+              fullResponseHolder.getStatus(),
+              fullResponseHolder.getContent()
           );
         }
       }
diff --git a/indexing-service/src/main/java/org/apache/druid/indexing/overlord/http/OverlordResource.java b/indexing-service/src/main/java/org/apache/druid/indexing/overlord/http/OverlordResource.java
index 0e230db..9b59202 100644
--- a/indexing-service/src/main/java/org/apache/druid/indexing/overlord/http/OverlordResource.java
+++ b/indexing-service/src/main/java/org/apache/druid/indexing/overlord/http/OverlordResource.java
@@ -93,7 +93,6 @@ import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.Status;
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -485,9 +484,9 @@ public class OverlordResource
               retMap = new HashMap<>();
               retMap.put("result", ret);
             }
-            catch (IOException e) {
+            catch (Exception e) {
               log.warn(e, "Failed to perform task action");
-              return Response.serverError().build();
+              return Response.serverError().entity(ImmutableMap.of("error", e.getMessage())).build();
             }
 
             return Response.ok().entity(retMap).build();
diff --git a/indexing-service/src/test/java/org/apache/druid/indexing/common/actions/RemoteTaskActionClientTest.java b/indexing-service/src/test/java/org/apache/druid/indexing/common/actions/RemoteTaskActionClientTest.java
index fe4402d..ec28edf 100644
--- a/indexing-service/src/test/java/org/apache/druid/indexing/common/actions/RemoteTaskActionClientTest.java
+++ b/indexing-service/src/test/java/org/apache/druid/indexing/common/actions/RemoteTaskActionClientTest.java
@@ -37,7 +37,9 @@ import org.jboss.netty.handler.codec.http.HttpResponse;
 import org.jboss.netty.handler.codec.http.HttpResponseStatus;
 import org.junit.Assert;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.ExpectedException;
 
 import java.io.IOException;
 import java.net.URL;
@@ -51,25 +53,16 @@ import static org.easymock.EasyMock.replay;
 
 public class RemoteTaskActionClientTest
 {
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
   private DruidLeaderClient druidLeaderClient;
-  List<TaskLock> result = null;
   private ObjectMapper objectMapper = new DefaultObjectMapper();
 
   @Before
   public void setUp()
   {
     druidLeaderClient = EasyMock.createMock(DruidLeaderClient.class);
-
-    long now = System.currentTimeMillis();
-
-    result = Collections.singletonList(new TaskLock(
-        TaskLockType.SHARED,
-        "groupId",
-        "dataSource",
-        Intervals.utc(now - 30 * 1000, now),
-        "version",
-        0
-    ));
   }
 
   @Test
@@ -81,7 +74,15 @@ public class RemoteTaskActionClientTest
 
     // return status code 200 and a list with size equals 1
     Map<String, Object> responseBody = new HashMap<String, Object>();
-    responseBody.put("result", result);
+    final List<TaskLock> expectedLocks = Collections.singletonList(new TaskLock(
+        TaskLockType.SHARED,
+        "groupId",
+        "dataSource",
+        Intervals.of("2019/2020"),
+        "version",
+        0
+    ));
+    responseBody.put("result", expectedLocks);
     String strResult = objectMapper.writeValueAsString(responseBody);
     FullResponseHolder responseHolder = new FullResponseHolder(
         HttpResponseStatus.OK,
@@ -93,7 +94,6 @@ public class RemoteTaskActionClientTest
     expect(druidLeaderClient.go(request)).andReturn(responseHolder);
     replay(druidLeaderClient);
 
-
     Task task = new NoopTask("id", null, 0, 0, null, null, null);
     RemoteTaskActionClient client = new RemoteTaskActionClient(
         task,
@@ -101,18 +101,13 @@ public class RemoteTaskActionClientTest
         new RetryPolicyFactory(new RetryPolicyConfig()),
         objectMapper
     );
-    try {
-      result = client.submit(new LockListAction());
-    }
-    catch (IOException e) {
-      Assert.fail("unexpected IOException");
-    }
-
-    Assert.assertEquals(1, result.size());
+    final List<TaskLock> locks = client.submit(new LockListAction());
+
+    Assert.assertEquals(expectedLocks, locks);
     EasyMock.verify(druidLeaderClient);
   }
 
-  @Test(expected = IOException.class)
+  @Test
   public void testSubmitWithIllegalStatusCode() throws Exception
   {
     // return status code 400 and a list with size equals 1
@@ -121,20 +116,16 @@ public class RemoteTaskActionClientTest
         .andReturn(request);
 
     // return status code 200 and a list with size equals 1
-    Map<String, Object> responseBody = new HashMap<String, Object>();
-    responseBody.put("result", result);
-    String strResult = objectMapper.writeValueAsString(responseBody);
     FullResponseHolder responseHolder = new FullResponseHolder(
         HttpResponseStatus.BAD_REQUEST,
         EasyMock.createNiceMock(HttpResponse.class),
-        new StringBuilder().append(strResult)
+        new StringBuilder().append("testSubmitWithIllegalStatusCode")
     );
 
     // set up mocks
     expect(druidLeaderClient.go(request)).andReturn(responseHolder);
     replay(druidLeaderClient);
 
-
     Task task = new NoopTask("id", null, 0, 0, null, null, null);
     RemoteTaskActionClient client = new RemoteTaskActionClient(
         task,
@@ -142,6 +133,11 @@ public class RemoteTaskActionClientTest
         new RetryPolicyFactory(objectMapper.readValue("{\"maxRetryCount\":0}", RetryPolicyConfig.class)),
         objectMapper
     );
-    result = client.submit(new LockListAction());
+    expectedException.expect(IOException.class);
+    expectedException.expectMessage(
+        "Error with status[400 Bad Request] and message[testSubmitWithIllegalStatusCode]. "
+        + "Check overlord logs for details."
+    );
+    client.submit(new LockListAction());
   }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org