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());
}
}
});
}
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();
}
}
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();
}
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());
}
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;
}
Aggregations