use of com.google.inject.Injector in project druid by druid-io.
the class ValidateSegments method run.
@Override
public void run() {
if (directories.size() != 2) {
throw new IAE("Please provide two segment directories to compare");
}
final Injector injector = makeInjector();
final IndexIO indexIO = injector.getInstance(IndexIO.class);
try {
String dir1 = directories.get(0);
String dir2 = directories.get(1);
indexIO.validateTwoSegments(new File(dir1), new File(dir2));
log.info("Segments [%s] and [%s] are identical", dir1, dir2);
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
use of com.google.inject.Injector in project druid by druid-io.
the class DruidJsonValidator method run.
@Override
public void run() {
File file = new File(jsonFile);
if (!file.exists()) {
System.out.printf("File[%s] does not exist.%n", file);
}
final Injector injector = makeInjector();
final ObjectMapper jsonMapper = injector.getInstance(ObjectMapper.class);
registerModules(jsonMapper, Iterables.concat(Initialization.getFromExtensions(injector.getInstance(ExtensionsConfig.class), DruidModule.class), Arrays.asList(new FirehoseModule(), new IndexingHadoopModule(), new IndexingServiceFirehoseModule(), new LocalDataStorageDruidModule(), new ParsersModule())));
final ClassLoader loader;
if (Thread.currentThread().getContextClassLoader() != null) {
loader = Thread.currentThread().getContextClassLoader();
} else {
loader = DruidJsonValidator.class.getClassLoader();
}
if (toLogger) {
logWriter = new NullWriter() {
private final Logger logger = new Logger(DruidJsonValidator.class);
@Override
public void write(char[] cbuf, int off, int len) {
logger.info(new String(cbuf, off, len));
}
};
}
try {
if (type.equalsIgnoreCase("query")) {
jsonMapper.readValue(file, Query.class);
} else if (type.equalsIgnoreCase("hadoopConfig")) {
jsonMapper.readValue(file, HadoopDruidIndexerConfig.class);
} else if (type.equalsIgnoreCase("task")) {
jsonMapper.readValue(file, Task.class);
} else if (type.equalsIgnoreCase("parse")) {
final StringInputRowParser parser;
if (file.isFile()) {
logWriter.write("loading parse spec from file '" + file + "'");
parser = jsonMapper.readValue(file, StringInputRowParser.class);
} else if (loader.getResource(jsonFile) != null) {
logWriter.write("loading parse spec from resource '" + jsonFile + "'");
parser = jsonMapper.readValue(loader.getResource(jsonFile), StringInputRowParser.class);
} else {
logWriter.write("cannot find proper spec from 'file'.. regarding it as a json spec");
parser = jsonMapper.readValue(jsonFile, StringInputRowParser.class);
}
if (resource != null) {
final CharSource source;
if (new File(resource).isFile()) {
logWriter.write("loading data from file '" + resource + "'");
source = Resources.asByteSource(new File(resource).toURL()).asCharSource(Charset.forName(parser.getEncoding()));
} else if (loader.getResource(resource) != null) {
logWriter.write("loading data from resource '" + resource + "'");
source = Resources.asByteSource(loader.getResource(resource)).asCharSource(Charset.forName(parser.getEncoding()));
} else {
logWriter.write("cannot find proper data from 'resource'.. regarding it as data string");
source = CharSource.wrap(resource);
}
readData(parser, source);
}
} else {
throw new UOE("Unknown type[%s]", type);
}
} catch (Exception e) {
System.out.println("INVALID JSON!");
throw Throwables.propagate(e);
}
}
use of com.google.inject.Injector in project druid by druid-io.
the class BaseJettyTest method setup.
@Before
public void setup() throws Exception {
setProperties();
Injector injector = setupInjector();
final DruidNode node = injector.getInstance(Key.get(DruidNode.class, Self.class));
port = node.getPort();
lifecycle = injector.getInstance(Lifecycle.class);
lifecycle.start();
ClientHolder holder = injector.getInstance(ClientHolder.class);
server = injector.getInstance(Server.class);
client = holder.getClient();
}
use of com.google.inject.Injector in project druid by druid-io.
the class MetricsModuleTest method testSimpleInjectionWithValues.
@Test
public void testSimpleInjectionWithValues() {
final String dataSource = "some datasource";
final String taskId = "some task";
final Injector injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.of(new Module() {
@Override
public void configure(Binder binder) {
JsonConfigProvider.bindInstance(binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, null));
binder.bind(Key.get(String.class, Names.named(DataSourceTaskIdHolder.DATA_SOURCE_BINDING))).toInstance(dataSource);
binder.bind(Key.get(String.class, Names.named(DataSourceTaskIdHolder.TASK_ID_BINDING))).toInstance(taskId);
}
}));
final DataSourceTaskIdHolder dimensionIdHolder = new DataSourceTaskIdHolder();
injector.injectMembers(dimensionIdHolder);
Assert.assertEquals(dataSource, dimensionIdHolder.getDataSource());
Assert.assertEquals(taskId, dimensionIdHolder.getTaskId());
}
use of com.google.inject.Injector in project druid by druid-io.
the class CalciteTests method createOperatorTable.
public static DruidOperatorTable createOperatorTable() {
try {
final Injector injector = Guice.createInjector(new Module() {
@Override
public void configure(final Binder binder) {
// This Module is just to get a LookupReferencesManager with a usable "lookyloo" lookup.
final LookupReferencesManager mock = EasyMock.createMock(LookupReferencesManager.class);
EasyMock.expect(mock.get(EasyMock.eq("lookyloo"))).andReturn(new LookupExtractorFactory() {
@Override
public boolean start() {
throw new UnsupportedOperationException();
}
@Override
public boolean close() {
throw new UnsupportedOperationException();
}
@Override
public boolean replaces(@Nullable final LookupExtractorFactory other) {
throw new UnsupportedOperationException();
}
@Nullable
@Override
public LookupIntrospectHandler getIntrospectHandler() {
throw new UnsupportedOperationException();
}
@Override
public LookupExtractor get() {
return new MapLookupExtractor(ImmutableMap.of("a", "xa", "abc", "xabc"), false);
}
}).anyTimes();
EasyMock.replay(mock);
binder.bind(LookupReferencesManager.class).toInstance(mock);
}
});
final Set<SqlAggregator> aggregators = new HashSet<>();
final Set<SqlExtractionOperator> extractionOperators = new HashSet<>();
for (Class<? extends SqlAggregator> clazz : SqlModule.DEFAULT_AGGREGATOR_CLASSES) {
aggregators.add(injector.getInstance(clazz));
}
for (Class<? extends SqlExtractionOperator> clazz : SqlModule.DEFAULT_EXTRACTION_OPERATOR_CLASSES) {
extractionOperators.add(injector.getInstance(clazz));
}
return new DruidOperatorTable(aggregators, extractionOperators);
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
Aggregations