Search in sources :

Example 36 with ISE

use of io.druid.java.util.common.ISE in project druid by druid-io.

the class KafkaIndexTaskTest method runTask.

private ListenableFuture<TaskStatus> runTask(final Task task) {
    try {
        taskStorage.insert(task, TaskStatus.running(task.getId()));
    } catch (EntryExistsException e) {
    // suppress
    }
    taskLockbox.syncFromStorage();
    final TaskToolbox toolbox = toolboxFactory.build(task);
    synchronized (runningTasks) {
        runningTasks.add(task);
    }
    return taskExec.submit(new Callable<TaskStatus>() {

        @Override
        public TaskStatus call() throws Exception {
            try {
                if (task.isReady(toolbox.getTaskActionClient())) {
                    return task.run(toolbox);
                } else {
                    throw new ISE("Task is not ready");
                }
            } catch (Exception e) {
                log.warn(e, "Task failed");
                return TaskStatus.failure(task.getId());
            }
        }
    });
}
Also used : TaskToolbox(io.druid.indexing.common.TaskToolbox) EntryExistsException(io.druid.metadata.EntryExistsException) ISE(io.druid.java.util.common.ISE) TaskStatus(io.druid.indexing.common.TaskStatus) EntryExistsException(io.druid.metadata.EntryExistsException) IOException(java.io.IOException) TimeoutException(java.util.concurrent.TimeoutException)

Example 37 with ISE

use of io.druid.java.util.common.ISE in project druid by druid-io.

the class NamespaceLookupExtractorFactory method get.

// Grab the latest snapshot from the CacheScheduler's entry
@Override
public LookupExtractor get() {
    final Lock readLock = startStopSync.readLock();
    try {
        readLock.lockInterruptibly();
    } catch (InterruptedException e) {
        throw Throwables.propagate(e);
    }
    try {
        if (entry == null) {
            throw new ISE("Factory [%s] not started", extractorID);
        }
        final CacheScheduler.CacheState cacheState = entry.getCacheState();
        if (cacheState instanceof CacheScheduler.NoCache) {
            final String noCacheReason = ((CacheScheduler.NoCache) cacheState).name();
            throw new ISE("%s: %s, extractorID = %s", entry, noCacheReason, extractorID);
        }
        CacheScheduler.VersionedCache versionedCache = (CacheScheduler.VersionedCache) cacheState;
        Map<String, String> map = versionedCache.getCache();
        final byte[] v = StringUtils.toUtf8(versionedCache.getVersion());
        final byte[] id = StringUtils.toUtf8(extractorID);
        return new MapLookupExtractor(map, isInjective()) {

            @Override
            public byte[] getCacheKey() {
                return ByteBuffer.allocate(CLASS_CACHE_KEY.length + id.length + 1 + v.length + 1 + 1).put(CLASS_CACHE_KEY).put(id).put((byte) 0xFF).put(v).put((byte) 0xFF).put(isOneToOne() ? (byte) 1 : (byte) 0).array();
            }
        };
    } finally {
        readLock.unlock();
    }
}
Also used : ISE(io.druid.java.util.common.ISE) MapLookupExtractor(io.druid.query.extraction.MapLookupExtractor) CacheScheduler(io.druid.server.lookup.namespace.cache.CacheScheduler) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock)

Example 38 with ISE

use of io.druid.java.util.common.ISE in project druid by druid-io.

the class NamespaceLookupExtractorFactoryTest method testSimpleStartRacyGetDuringDelete.

@Test
public void testSimpleStartRacyGetDuringDelete() {
    final ExtractionNamespace extractionNamespace = new ExtractionNamespace() {

        @Override
        public long getPollMs() {
            return 0;
        }
    };
    expectScheduleAndWaitOnce(extractionNamespace);
    expectEntryGetCacheStateOnce(CacheScheduler.NoCache.ENTRY_CLOSED);
    mockReplay();
    final NamespaceLookupExtractorFactory namespaceLookupExtractorFactory = new NamespaceLookupExtractorFactory(extractionNamespace, scheduler);
    Assert.assertTrue(namespaceLookupExtractorFactory.start());
    try {
        namespaceLookupExtractorFactory.get();
        Assert.fail("Should have thrown ISE");
    } catch (ISE ise) {
    // NOOP
    }
    mockVerify();
}
Also used : ExtractionNamespace(io.druid.query.lookup.namespace.ExtractionNamespace) URIExtractionNamespace(io.druid.query.lookup.namespace.URIExtractionNamespace) ISE(io.druid.java.util.common.ISE) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 39 with ISE

use of io.druid.java.util.common.ISE in project druid by druid-io.

the class NamespaceLookupExtractorFactoryTest method validateNotFound.

private void validateNotFound(String method, LookupIntrospectHandler handler, Class<? extends LookupIntrospectHandler> clazz) throws Exception {
    mockVerify();
    mockReset();
    expectEntryGetCacheStateOnce(versionedCache);
    expectEmptyCache();
    EasyMock.expect(versionedCache.getVersion()).andThrow(new ISE("some exception")).once();
    mockReplay();
    final Response response = (Response) clazz.getMethod(method).invoke(handler);
    Assert.assertEquals(404, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) ISE(io.druid.java.util.common.ISE)

Example 40 with ISE

use of io.druid.java.util.common.ISE in project druid by druid-io.

the class QuotableWhiteSpaceSplitter method restore.

@Override
public List<Pair<Task, ListenableFuture<TaskStatus>>> restore() {
    final File restoreFile = getRestoreFile();
    final TaskRestoreInfo taskRestoreInfo;
    if (restoreFile.exists()) {
        try {
            taskRestoreInfo = jsonMapper.readValue(restoreFile, TaskRestoreInfo.class);
        } catch (Exception e) {
            log.error(e, "Failed to read restorable tasks from file[%s]. Skipping restore.", restoreFile);
            return ImmutableList.of();
        }
    } else {
        return ImmutableList.of();
    }
    final List<Pair<Task, ListenableFuture<TaskStatus>>> retVal = Lists.newArrayList();
    for (final String taskId : taskRestoreInfo.getRunningTasks()) {
        try {
            final File taskFile = new File(taskConfig.getTaskDir(taskId), "task.json");
            final Task task = jsonMapper.readValue(taskFile, Task.class);
            if (!task.getId().equals(taskId)) {
                throw new ISE("WTF?! Task[%s] restore file had wrong id[%s].", taskId, task.getId());
            }
            if (taskConfig.isRestoreTasksOnRestart() && task.canRestore()) {
                log.info("Restoring task[%s].", task.getId());
                retVal.add(Pair.of(task, run(task)));
            }
        } catch (Exception e) {
            log.warn(e, "Failed to restore task[%s]. Trying to restore other tasks.", taskId);
        }
    }
    log.info("Restored %,d tasks.", retVal.size());
    return retVal;
}
Also used : Task(io.druid.indexing.common.task.Task) ISE(io.druid.java.util.common.ISE) TaskStatus(io.druid.indexing.common.TaskStatus) File(java.io.File) IOException(java.io.IOException) Pair(io.druid.java.util.common.Pair)

Aggregations

ISE (io.druid.java.util.common.ISE)158 IOException (java.io.IOException)37 Map (java.util.Map)23 Test (org.junit.Test)21 File (java.io.File)20 List (java.util.List)19 DateTime (org.joda.time.DateTime)18 ArrayList (java.util.ArrayList)17 DataSegment (io.druid.timeline.DataSegment)15 Interval (org.joda.time.Interval)15 Function (com.google.common.base.Function)14 TimeoutException (java.util.concurrent.TimeoutException)12 IAE (io.druid.java.util.common.IAE)10 HashMap (java.util.HashMap)10 ExecutionException (java.util.concurrent.ExecutionException)10 Stopwatch (com.google.common.base.Stopwatch)9 DimensionSpec (io.druid.query.dimension.DimensionSpec)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)8 AggregatorFactory (io.druid.query.aggregation.AggregatorFactory)8