Search in sources :

Example 1 with LocalDataStorageDruidModule

use of io.druid.guice.LocalDataStorageDruidModule 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);
    }
}
Also used : CharSource(com.google.common.io.CharSource) IndexingServiceFirehoseModule(io.druid.guice.IndexingServiceFirehoseModule) IndexingHadoopModule(io.druid.indexer.IndexingHadoopModule) LocalDataStorageDruidModule(io.druid.guice.LocalDataStorageDruidModule) UOE(io.druid.java.util.common.UOE) Logger(io.druid.java.util.common.logger.Logger) HadoopDruidIndexerConfig(io.druid.indexer.HadoopDruidIndexerConfig) NullWriter(org.apache.commons.io.output.NullWriter) IOException(java.io.IOException) FirehoseModule(io.druid.guice.FirehoseModule) IndexingServiceFirehoseModule(io.druid.guice.IndexingServiceFirehoseModule) Injector(com.google.inject.Injector) StringInputRowParser(io.druid.data.input.impl.StringInputRowParser) ParsersModule(io.druid.guice.ParsersModule) ExtensionsConfig(io.druid.guice.ExtensionsConfig) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with LocalDataStorageDruidModule

use of io.druid.guice.LocalDataStorageDruidModule in project druid by druid-io.

the class Initialization method makeInjectorWithModules.

public static Injector makeInjectorWithModules(final Injector baseInjector, Iterable<? extends Module> modules) {
    final ModuleList defaultModules = new ModuleList(baseInjector);
    defaultModules.addModules(// New modules should be added after Log4jShutterDownerModule
    new Log4jShutterDownerModule(), new DruidAuthModule(), new LifecycleModule(), EmitterModule.class, HttpClientModule.global(), new HttpClientModule("druid.broker.http", Client.class), new CuratorModule(), new AnnouncerModule(), new DruidProcessingModule(), new AWSModule(), new MetricsModule(), new ServerModule(), new StorageNodeModule(), new JettyServerModule(), new QueryableModule(), new QueryRunnerFactoryModule(), new DiscoveryModule(), new ServerViewModule(), new MetadataConfigModule(), new DerbyMetadataStorageDruidModule(), new JacksonConfigManagerModule(), new IndexingServiceDiscoveryModule(), new CoordinatorDiscoveryModule(), new LocalDataStorageDruidModule(), new FirehoseModule(), new ParsersModule(), new JavaScriptModule(), new StartupLoggingModule());
    ModuleList actualModules = new ModuleList(baseInjector);
    actualModules.addModule(DruidSecondaryModule.class);
    for (Object module : modules) {
        actualModules.addModule(module);
    }
    Module intermediateModules = Modules.override(defaultModules.getModules()).with(actualModules.getModules());
    ModuleList extensionModules = new ModuleList(baseInjector);
    final ExtensionsConfig config = baseInjector.getInstance(ExtensionsConfig.class);
    for (DruidModule module : Initialization.getFromExtensions(config, DruidModule.class)) {
        extensionModules.addModule(module);
    }
    return Guice.createInjector(Modules.override(intermediateModules).with(extensionModules.getModules()));
}
Also used : CuratorModule(io.druid.curator.CuratorModule) DiscoveryModule(io.druid.curator.discovery.DiscoveryModule) CoordinatorDiscoveryModule(io.druid.guice.CoordinatorDiscoveryModule) IndexingServiceDiscoveryModule(io.druid.guice.IndexingServiceDiscoveryModule) ServerViewModule(io.druid.guice.ServerViewModule) JettyServerModule(io.druid.server.initialization.jetty.JettyServerModule) JettyServerModule(io.druid.server.initialization.jetty.JettyServerModule) ServerModule(io.druid.guice.ServerModule) FirehoseModule(io.druid.guice.FirehoseModule) AWSModule(io.druid.guice.AWSModule) ParsersModule(io.druid.guice.ParsersModule) LocalDataStorageDruidModule(io.druid.guice.LocalDataStorageDruidModule) DerbyMetadataStorageDruidModule(io.druid.metadata.storage.derby.DerbyMetadataStorageDruidModule) Client(io.druid.guice.annotations.Client) ExtensionsConfig(io.druid.guice.ExtensionsConfig) JacksonConfigManagerModule(io.druid.guice.JacksonConfigManagerModule) LifecycleModule(io.druid.guice.LifecycleModule) IndexingServiceDiscoveryModule(io.druid.guice.IndexingServiceDiscoveryModule) QueryRunnerFactoryModule(io.druid.guice.QueryRunnerFactoryModule) LocalDataStorageDruidModule(io.druid.guice.LocalDataStorageDruidModule) StartupLoggingModule(io.druid.guice.StartupLoggingModule) DerbyMetadataStorageDruidModule(io.druid.metadata.storage.derby.DerbyMetadataStorageDruidModule) QueryableModule(io.druid.guice.QueryableModule) MetadataConfigModule(io.druid.guice.MetadataConfigModule) CoordinatorDiscoveryModule(io.druid.guice.CoordinatorDiscoveryModule) DruidProcessingModule(io.druid.guice.DruidProcessingModule) DruidAuthModule(io.druid.guice.security.DruidAuthModule) MetricsModule(io.druid.server.metrics.MetricsModule) AnnouncerModule(io.druid.guice.AnnouncerModule) StorageNodeModule(io.druid.guice.StorageNodeModule) Module(com.google.inject.Module) ParsersModule(io.druid.guice.ParsersModule) QueryableModule(io.druid.guice.QueryableModule) DiscoveryModule(io.druid.curator.discovery.DiscoveryModule) LocalDataStorageDruidModule(io.druid.guice.LocalDataStorageDruidModule) AnnouncerModule(io.druid.guice.AnnouncerModule) AWSModule(io.druid.guice.AWSModule) CoordinatorDiscoveryModule(io.druid.guice.CoordinatorDiscoveryModule) MetricsModule(io.druid.server.metrics.MetricsModule) FirehoseModule(io.druid.guice.FirehoseModule) DruidAuthModule(io.druid.guice.security.DruidAuthModule) JavaScriptModule(io.druid.guice.JavaScriptModule) EmitterModule(io.druid.server.initialization.EmitterModule) LifecycleModule(io.druid.guice.LifecycleModule) ServerViewModule(io.druid.guice.ServerViewModule) JacksonConfigManagerModule(io.druid.guice.JacksonConfigManagerModule) MetadataConfigModule(io.druid.guice.MetadataConfigModule) CuratorModule(io.druid.curator.CuratorModule) IndexingServiceDiscoveryModule(io.druid.guice.IndexingServiceDiscoveryModule) StartupLoggingModule(io.druid.guice.StartupLoggingModule) DerbyMetadataStorageDruidModule(io.druid.metadata.storage.derby.DerbyMetadataStorageDruidModule) JettyServerModule(io.druid.server.initialization.jetty.JettyServerModule) StorageNodeModule(io.druid.guice.StorageNodeModule) ServerModule(io.druid.guice.ServerModule) HttpClientModule(io.druid.guice.http.HttpClientModule) DruidProcessingModule(io.druid.guice.DruidProcessingModule) QueryRunnerFactoryModule(io.druid.guice.QueryRunnerFactoryModule) DruidSecondaryModule(io.druid.guice.DruidSecondaryModule) HttpClientModule(io.druid.guice.http.HttpClientModule) JavaScriptModule(io.druid.guice.JavaScriptModule)

Aggregations

ExtensionsConfig (io.druid.guice.ExtensionsConfig)2 FirehoseModule (io.druid.guice.FirehoseModule)2 LocalDataStorageDruidModule (io.druid.guice.LocalDataStorageDruidModule)2 ParsersModule (io.druid.guice.ParsersModule)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 CharSource (com.google.common.io.CharSource)1 Injector (com.google.inject.Injector)1 Module (com.google.inject.Module)1 CuratorModule (io.druid.curator.CuratorModule)1 DiscoveryModule (io.druid.curator.discovery.DiscoveryModule)1 StringInputRowParser (io.druid.data.input.impl.StringInputRowParser)1 AWSModule (io.druid.guice.AWSModule)1 AnnouncerModule (io.druid.guice.AnnouncerModule)1 CoordinatorDiscoveryModule (io.druid.guice.CoordinatorDiscoveryModule)1 DruidProcessingModule (io.druid.guice.DruidProcessingModule)1 DruidSecondaryModule (io.druid.guice.DruidSecondaryModule)1 IndexingServiceDiscoveryModule (io.druid.guice.IndexingServiceDiscoveryModule)1 IndexingServiceFirehoseModule (io.druid.guice.IndexingServiceFirehoseModule)1 JacksonConfigManagerModule (io.druid.guice.JacksonConfigManagerModule)1 JavaScriptModule (io.druid.guice.JavaScriptModule)1