@Override public int hashCode() { return getCode(); }
protected boolean isSuccess(FullResponseHolder responseHolder) { return responseHolder.getStatus().getCode() / 100 == 2; }
@Override public ClientResponse<InputStream> handleResponse(HttpResponse response, TrafficCop trafficCop) { returnCode.set(response.getStatus().getCode()); reasonString.set(response.getStatus().getReasonPhrase()); return super.handleResponse(response, trafficCop); } };
private static void sendHttpResponse(ChannelHandlerContext ctx, HttpRequest req, HttpResponse res) { ChannelFuture f = ctx.getChannel().write(res); if (!isKeepAlive(req) || res.getStatus().getCode() != 200) { f.addListener(ChannelFutureListener.CLOSE); } }
public String findCurrentLeader() { Preconditions.checkState(lifecycleLock.awaitStarted(1, TimeUnit.MILLISECONDS)); final FullResponseHolder responseHolder; try { responseHolder = go(makeRequest(HttpMethod.GET, leaderRequestPath)); } catch (Exception ex) { throw new ISE(ex, "Couldn't find leader."); } if (responseHolder.getStatus().getCode() == 200) { String leaderUrl = responseHolder.getContent(); //verify this is valid url try { URL validatedUrl = new URL(leaderUrl); currentKnownLeader.set(leaderUrl); // validatedUrl.toString() is returned instead of leaderUrl or else teamcity build fails because of breaking // the rule of ignoring new URL(leaderUrl) object. return validatedUrl.toString(); } catch (MalformedURLException ex) { log.error(ex, "Received malformed leader url[%s].", leaderUrl); } } throw new ISE( "Couldn't find leader, failed response status is [%s] and content [%s].", responseHolder.getStatus().getCode(), responseHolder.getContent() ); }
public static class TaskNotRunnableException extends RuntimeException { public TaskNotRunnableException(String message) { super(message); } }
private void resetKafkaIngestion(String overlordAddress, String dataSourceName) { try { FullResponseHolder response = RetryUtils.retry(() -> DruidStorageHandlerUtils.getResponseFromCurrentLeader(getHttpClient(), new Request(HttpMethod.POST, new URL(String.format("http://%s/druid/indexer/v1/supervisor/%s/reset", overlordAddress, dataSourceName))), new FullResponseHandler(Charset.forName("UTF-8"))), input -> input instanceof IOException, getMaxRetryCount()); if (response.getStatus().equals(HttpResponseStatus.OK)) { CONSOLE.printInfo("Druid Kafka Ingestion Reset successful."); } else { throw new IOException(String.format("Unable to reset Kafka Ingestion Druid status [%d] full response [%s]", response.getStatus().getCode(), response.getContent())); } } catch (Exception e) { throw new RuntimeException(e); } }
@Override public ClientResponse<AppendableByteArrayInputStream> handleResponse(HttpResponse response, TrafficCop trafficCop) { status = response.getStatus().getCode(); description = response.getStatus().getReasonPhrase(); return ClientResponse.unfinished(super.handleResponse(response, trafficCop).getObj()); }
private void stopKafkaIngestion(String overlordAddress, String dataSourceName) { try { FullResponseHolder response = RetryUtils.retry(() -> DruidStorageHandlerUtils.getResponseFromCurrentLeader(getHttpClient(), new Request(HttpMethod.POST, new URL(String.format("http://%s/druid/indexer/v1/supervisor/%s/shutdown", overlordAddress, dataSourceName))), new FullResponseHandler(Charset.forName("UTF-8"))), input -> input instanceof IOException, getMaxRetryCount()); if (response.getStatus().equals(HttpResponseStatus.OK)) { CONSOLE.printInfo("Druid Kafka Ingestion shutdown successful."); } else { throw new IOException(String.format("Unable to stop Kafka Ingestion Druid status [%d] full response [%s]", response.getStatus().getCode(), response.getContent())); } } catch (Exception e) { throw new RuntimeException(e); } }
private void resetState() { if (!isDecodingRequest()) { HttpResponse res = (HttpResponse) message; if (res != null && res.getStatus().getCode() == 101) { checkpoint(State.UPGRADED); return; } } checkpoint(State.SKIP_CONTROL_CHARS); }
public void report(String supervisorTaskId, List<DataSegment> pushedSegments) { try { final FullResponseHolder response = submitSmileRequest( supervisorTaskId, HttpMethod.POST, "report", null, serialize(new PushedSegmentsReport(subtaskId, pushedSegments)), true ); if (!isSuccess(response)) { throw new ISE( "Failed to send taskReports to task[%s] with the HTTP code [%d]", supervisorTaskId, response.getStatus().getCode() ); } } catch (IOException e) { throw new RuntimeException(e); } } }
@Override protected void encodeInitialLine(ChannelBuffer buf, HttpMessage message) throws Exception { HttpResponse response = (HttpResponse) message; buf.writeBytes(response.getProtocolVersion().toString().getBytes("ASCII")); buf.writeByte((byte) ' '); buf.writeBytes(String.valueOf(response.getStatus().getCode()).getBytes("ASCII")); buf.writeByte((byte) ' '); buf.writeBytes(String.valueOf(response.getStatus().getReasonPhrase()).getBytes("ASCII")); buf.writeByte((byte) '\r'); buf.writeByte((byte) '\n'); } }
@Override protected void encodeInitialLine(ChannelBuffer buf, HttpMessage message) throws Exception { HttpResponse response = (HttpResponse) message; encodeAscii(response.getProtocolVersion().toString(), buf); buf.writeByte(SP); encodeAscii(String.valueOf(response.getStatus().getCode()), buf); buf.writeByte(SP); encodeAscii(String.valueOf(response.getStatus().getReasonPhrase()), buf); buf.writeByte(CR); buf.writeByte(LF); } }
public SegmentIdWithShardSpec allocateSegment(String supervisorTaskId, DateTime timestamp) throws IOException { final FullResponseHolder response = submitSmileRequest( supervisorTaskId, HttpMethod.POST, "segment/allocate", null, serialize(timestamp), true ); if (!isSuccess(response)) { throw new ISE( "task[%s] failed to allocate a new segment identifier with the HTTP code[%d] and content[%s]", supervisorTaskId, response.getStatus().getCode(), response.getContent() ); } else { return deserialize( response.getContent(), new TypeReference<SegmentIdWithShardSpec>() { } ); } }
).get(); if (response.getStatus().getCode() == 200) { log.info( "Sent shutdown message to worker: %s, status %s, response: %s",
).get(); Assert.assertEquals(200, response.getStatus().getCode()); Assert.assertEquals("hello!", response.getContent());