use of org.apache.druid.java.util.common.RE in project druid by druid-io.
the class HadoopDruidIndexerMapper method map.
@Override
protected void map(Object key, Object value, Context context) throws IOException, InterruptedException {
try {
final List<InputRow> inputRows = parseInputRow(value, parser);
for (InputRow inputRow : inputRows) {
try {
if (inputRow == null) {
// Throw away null rows from the parser.
log.debug("Throwing away row [%s]", value);
context.getCounter(HadoopDruidIndexerConfig.IndexJobCounters.ROWS_THROWN_AWAY_COUNTER).increment(1);
continue;
}
if (!Intervals.ETERNITY.contains(inputRow.getTimestamp())) {
final String errorMsg = StringUtils.format("Encountered row with timestamp that cannot be represented as a long: [%s]", inputRow);
throw new ParseException(null, errorMsg);
}
if (granularitySpec.inputIntervals().isEmpty() || granularitySpec.bucketInterval(DateTimes.utc(inputRow.getTimestampFromEpoch())).isPresent()) {
innerMap(inputRow, context);
} else {
context.getCounter(HadoopDruidIndexerConfig.IndexJobCounters.ROWS_THROWN_AWAY_COUNTER).increment(1);
}
} catch (ParseException pe) {
handleParseException(pe, context);
}
}
} catch (ParseException pe) {
handleParseException(pe, context);
} catch (RuntimeException e) {
throw new RE(e, "Failure on row[%s]", value);
}
}
use of org.apache.druid.java.util.common.RE in project druid by druid-io.
the class RemoteTaskRunner method shutdown.
/**
* Finds the worker running the task and forwards the shutdown signal to the worker.
*
* @param taskId - task id to shutdown
*/
@Override
public void shutdown(final String taskId, String reason) {
log.info("Shutdown [%s] because: [%s]", taskId, reason);
if (!lifecycleLock.awaitStarted(1, TimeUnit.SECONDS)) {
log.info("This TaskRunner is stopped or not yet started. Ignoring shutdown command for task: %s", taskId);
} else if (pendingTasks.remove(taskId) != null) {
pendingTaskPayloads.remove(taskId);
log.info("Removed task from pending queue: %s", taskId);
} else if (completeTasks.containsKey(taskId)) {
cleanup(taskId);
} else {
final ZkWorker zkWorker = findWorkerRunningTask(taskId);
if (zkWorker == null) {
log.info("Can't shutdown! No worker running task %s", taskId);
return;
}
URL url = null;
try {
url = TaskRunnerUtils.makeWorkerURL(zkWorker.getWorker(), "/druid/worker/v1/task/%s/shutdown", taskId);
final StatusResponseHolder response = httpClient.go(new Request(HttpMethod.POST, url), StatusResponseHandler.getInstance(), shutdownTimeout).get();
log.info("Sent shutdown message to worker: %s, status %s, response: %s", zkWorker.getWorker().getHost(), response.getStatus(), response.getContent());
if (!HttpResponseStatus.OK.equals(response.getStatus())) {
log.error("Shutdown failed for %s! Are you sure the task was running?", taskId);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RE(e, "Interrupted posting shutdown to [%s] for task [%s]", url, taskId);
} catch (Exception e) {
throw new RE(e, "Error in handling post to [%s] for task [%s]", zkWorker.getWorker().getHost(), taskId);
}
}
}
use of org.apache.druid.java.util.common.RE in project druid by druid-io.
the class WorkerTaskRunnerQueryAdapter method sendRequestToWorker.
private void sendRequestToWorker(String workerHost, WorkerTaskRunner.ActionType action) {
WorkerTaskRunner workerTaskRunner = getWorkerTaskRunner();
if (workerTaskRunner == null) {
throw new RE("Task Runner does not support enable/disable worker actions");
}
Optional<ImmutableWorkerInfo> workerInfo = Iterables.tryFind(workerTaskRunner.getWorkers(), entry -> entry.getWorker().getHost().equals(workerHost));
if (!workerInfo.isPresent()) {
throw new RE("Worker on host %s does not exists", workerHost);
}
String actionName = WorkerTaskRunner.ActionType.ENABLE.equals(action) ? "enable" : "disable";
final URL workerUrl = TaskRunnerUtils.makeWorkerURL(workerInfo.get().getWorker(), "/druid/worker/v1/%s", actionName);
try {
final StatusResponseHolder response = httpClient.go(new Request(HttpMethod.POST, workerUrl), StatusResponseHandler.getInstance()).get();
log.info("Sent %s action request to worker: %s, status: %s, response: %s", action, workerHost, response.getStatus(), response.getContent());
if (!HttpResponseStatus.OK.equals(response.getStatus())) {
throw new RE("Action [%s] failed for worker [%s] with status %s(%s)", action, workerHost, response.getStatus().getCode(), response.getStatus().getReasonPhrase());
}
} catch (ExecutionException | InterruptedException | TimeoutException e) {
Throwables.propagate(e);
}
}
use of org.apache.druid.java.util.common.RE in project druid by druid-io.
the class ITSqlCancelTest method testCancelInvalidQuery.
@Test
public void testCancelInvalidQuery() throws Exception {
final Future<StatusResponseHolder> queryResponseFuture = sqlClient.queryAsync(sqlHelper.getQueryURL(config.getRouterUrl()), new SqlQuery(QUERY, null, false, false, false, ImmutableMap.of(BaseQuery.SQL_QUERY_ID, "validId"), null));
// Wait until the sqlLifecycle is authorized and registered
Thread.sleep(1000);
final HttpResponseStatus responseStatus = sqlClient.cancelQuery(sqlHelper.getCancelUrl(config.getRouterUrl(), "invalidId"), 1000);
if (!responseStatus.equals(HttpResponseStatus.NOT_FOUND)) {
throw new RE("Expected http response [%s], actual response [%s]", HttpResponseStatus.NOT_FOUND, responseStatus);
}
final StatusResponseHolder queryResponse = queryResponseFuture.get(30, TimeUnit.SECONDS);
if (!queryResponse.getStatus().equals(HttpResponseStatus.OK)) {
throw new ISE("Cancel request failed with status[%s] and content[%s]", queryResponse.getStatus(), queryResponse.getContent());
}
}
use of org.apache.druid.java.util.common.RE in project druid by druid-io.
the class WorkerTaskRunnerQueryAdpaterTest method testDisableWorkerWhenWorkerRaisesError.
@Test
public void testDisableWorkerWhenWorkerRaisesError() throws Exception {
final URL workerUrl = new URL("http://worker-host1/druid/worker/v1/disable");
Capture<Request> capturedRequest = getHttpClientRequestCapture(HttpResponseStatus.INTERNAL_SERVER_ERROR, "");
EasyMock.replay(workerTaskRunner, taskMaster, httpClient);
try {
workerTaskRunnerQueryAdapter.disableWorker("worker-host1");
Assert.fail("Should raise RE exception!");
} catch (RE re) {
}
Assert.assertEquals(HttpMethod.POST, capturedRequest.getValue().getMethod());
Assert.assertEquals(workerUrl, capturedRequest.getValue().getUrl());
}
Aggregations