Search in sources :

Example 36 with RE

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);
    }
}
Also used : RE(org.apache.druid.java.util.common.RE) InputRow(org.apache.druid.data.input.InputRow) ParseException(org.apache.druid.java.util.common.parsers.ParseException)

Example 37 with RE

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);
        }
    }
}
Also used : RE(org.apache.druid.java.util.common.RE) Request(org.apache.druid.java.util.http.client.Request) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) URL(java.net.URL) TimeoutException(java.util.concurrent.TimeoutException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 38 with RE

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);
    }
}
Also used : RE(org.apache.druid.java.util.common.RE) Request(org.apache.druid.java.util.http.client.Request) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) ExecutionException(java.util.concurrent.ExecutionException) URL(java.net.URL) TimeoutException(io.netty.handler.timeout.TimeoutException)

Example 39 with RE

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());
    }
}
Also used : SqlQuery(org.apache.druid.sql.http.SqlQuery) RE(org.apache.druid.java.util.common.RE) HttpResponseStatus(org.jboss.netty.handler.codec.http.HttpResponseStatus) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) ISE(org.apache.druid.java.util.common.ISE) Test(org.testng.annotations.Test)

Example 40 with RE

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());
}
Also used : RE(org.apache.druid.java.util.common.RE) Request(org.apache.druid.java.util.http.client.Request) URL(java.net.URL) Test(org.junit.Test)

Aggregations

RE (org.apache.druid.java.util.common.RE)46 IOException (java.io.IOException)11 Request (org.apache.druid.java.util.http.client.Request)10 URL (java.net.URL)8 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 InputStream (java.io.InputStream)5 ExecutionException (java.util.concurrent.ExecutionException)5 ISE (org.apache.druid.java.util.common.ISE)5 Map (java.util.Map)4 StatusResponseHolder (org.apache.druid.java.util.http.client.response.StatusResponseHolder)4 JavaType (com.fasterxml.jackson.databind.JavaType)3 HashMap (java.util.HashMap)3 DataSegment (org.apache.druid.timeline.DataSegment)3 OSSException (com.aliyun.oss.OSSException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ApiException (io.kubernetes.client.openapi.ApiException)2 File (java.io.File)2