mirror of https://github.com/apache/druid.git
Fix bug Unrecognized token 'No': was expecting (JSON String,...) when… (#11934)
* Fix bug Unrecognized token 'No': was expecting (JSON String,...) when calling the API /druid/indexer/v1/task/taskId/reports and the report is not found * Also log other non-OK statuses
This commit is contained in:
parent
a04f99a950
commit
a4353aa1f4
|
@ -32,6 +32,7 @@ import org.apache.druid.java.util.common.DateTimes;
|
|||
import org.apache.druid.java.util.common.ISE;
|
||||
import org.apache.druid.java.util.common.StringUtils;
|
||||
import org.apache.druid.java.util.common.jackson.JacksonUtils;
|
||||
import org.apache.druid.java.util.common.logger.Logger;
|
||||
import org.apache.druid.java.util.http.client.response.StringFullResponseHolder;
|
||||
import org.apache.druid.timeline.DataSegment;
|
||||
import org.jboss.netty.handler.codec.http.HttpMethod;
|
||||
|
@ -53,6 +54,7 @@ import java.util.Set;
|
|||
|
||||
public class HttpIndexingServiceClient implements IndexingServiceClient
|
||||
{
|
||||
private static final Logger log = new Logger(HttpIndexingServiceClient.class);
|
||||
private final DruidLeaderClient druidLeaderClient;
|
||||
private final ObjectMapper jsonMapper;
|
||||
|
||||
|
@ -350,7 +352,13 @@ public class HttpIndexingServiceClient implements IndexingServiceClient
|
|||
)
|
||||
);
|
||||
|
||||
if (responseHolder.getContent().length() == 0) {
|
||||
if (responseHolder.getContent().length() == 0 || responseHolder.getStatus() != HttpResponseStatus.OK) {
|
||||
if (responseHolder.getStatus() == HttpResponseStatus.NOT_FOUND) {
|
||||
log.info("Report not found for taskId [%s] because [%s]", taskId, responseHolder.getContent());
|
||||
} else {
|
||||
// also log other non-ok statuses:
|
||||
log.info("Non OK response for taskId [%s] because [%s]", taskId, responseHolder.getContent());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,8 @@ import org.apache.druid.java.util.http.client.Request;
|
|||
import org.apache.druid.java.util.http.client.response.StringFullResponseHolder;
|
||||
import org.easymock.EasyMock;
|
||||
import org.jboss.netty.buffer.BigEndianHeapChannelBuffer;
|
||||
import org.jboss.netty.buffer.ChannelBuffer;
|
||||
import org.jboss.netty.buffer.ChannelBuffers;
|
||||
import org.jboss.netty.handler.codec.http.HttpMethod;
|
||||
import org.jboss.netty.handler.codec.http.HttpResponse;
|
||||
import org.jboss.netty.handler.codec.http.HttpResponseStatus;
|
||||
|
@ -197,6 +199,43 @@ public class HttpIndexingServiceClientTest
|
|||
EasyMock.verify(druidLeaderClient, response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTaskReportStatusNotFound() throws Exception
|
||||
{
|
||||
String taskId = "testTaskId";
|
||||
HttpResponse response = EasyMock.createMock(HttpResponse.class);
|
||||
String errorMsg = "No task reports were found for this task. "
|
||||
+ "The task may not exist, or it may not have completed yet.";
|
||||
ChannelBuffer buf = ChannelBuffers.buffer(errorMsg.length());
|
||||
buf.writeBytes(errorMsg.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
EasyMock.expect(response.getContent()).andReturn(buf);
|
||||
EasyMock.replay(response);
|
||||
|
||||
StringFullResponseHolder responseHolder = new StringFullResponseHolder(
|
||||
HttpResponseStatus.NOT_FOUND,
|
||||
response,
|
||||
StandardCharsets.UTF_8
|
||||
).addChunk("");
|
||||
|
||||
EasyMock.expect(druidLeaderClient.go(EasyMock.anyObject(Request.class)))
|
||||
.andReturn(responseHolder)
|
||||
.anyTimes();
|
||||
|
||||
EasyMock.expect(druidLeaderClient.makeRequest(HttpMethod.GET, "/druid/indexer/v1/task/testTaskId/reports"))
|
||||
.andReturn(new Request(
|
||||
HttpMethod.GET,
|
||||
new URL("http://localhost:8090/druid/indexer/v1/task/testTaskId/reports")
|
||||
))
|
||||
.anyTimes();
|
||||
EasyMock.replay(druidLeaderClient);
|
||||
|
||||
final Map<String, Object> actualResponse = httpIndexingServiceClient.getTaskReport(taskId);
|
||||
Assert.assertNull(actualResponse);
|
||||
|
||||
EasyMock.verify(druidLeaderClient, response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTaskReportEmpty() throws Exception
|
||||
{
|
||||
|
@ -228,4 +267,6 @@ public class HttpIndexingServiceClientTest
|
|||
|
||||
EasyMock.verify(druidLeaderClient, response);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue