Search in sources :

Example 1 with LocalDataStorageDruidModule

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

the class Initialization method makeInjectorWithModules.

public static Injector makeInjectorWithModules(final Set<NodeRole> nodeRoles, final Injector baseInjector, final Iterable<? extends Module> modules) {
    final ModuleList defaultModules = new ModuleList(baseInjector, nodeRoles);
    defaultModules.addModules(// New modules should be added after Log4jShutterDownerModule
    new Log4jShutterDownerModule(), new DruidAuthModule(), new LifecycleModule(), TLSCertificateCheckerModule.class, EmitterModule.class, HttpClientModule.global(), HttpClientModule.escalatedGlobal(), new HttpClientModule("druid.broker.http", Client.class), new HttpClientModule("druid.broker.http", EscalatedClient.class), new CuratorModule(), new AnnouncerModule(), new MetricsModule(), new SegmentWriteOutMediumModule(), new ServerModule(), new DruidProcessingConfigModule(), new StorageNodeModule(), new JettyServerModule(), new ExpressionModule(), new DiscoveryModule(), new ServerViewModule(), new MetadataConfigModule(), new DerbyMetadataStorageDruidModule(), new JacksonConfigManagerModule(), new IndexingServiceDiscoveryModule(), new CoordinatorDiscoveryModule(), new LocalDataStorageDruidModule(), new FirehoseModule(), new JavaScriptModule(), new AuthenticatorModule(), new AuthenticatorMapperModule(), new EscalatorModule(), new AuthorizerModule(), new AuthorizerMapperModule(), new StartupLoggingModule(), new ExternalStorageAccessSecurityModule());
    ModuleList actualModules = new ModuleList(baseInjector, nodeRoles);
    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, nodeRoles);
    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(org.apache.druid.curator.CuratorModule) IndexingServiceDiscoveryModule(org.apache.druid.guice.IndexingServiceDiscoveryModule) DiscoveryModule(org.apache.druid.curator.discovery.DiscoveryModule) CoordinatorDiscoveryModule(org.apache.druid.guice.CoordinatorDiscoveryModule) ServerViewModule(org.apache.druid.guice.ServerViewModule) EscalatorModule(org.apache.druid.guice.security.EscalatorModule) JettyServerModule(org.apache.druid.server.initialization.jetty.JettyServerModule) JettyServerModule(org.apache.druid.server.initialization.jetty.JettyServerModule) ServerModule(org.apache.druid.guice.ServerModule) AuthenticatorMapperModule(org.apache.druid.server.initialization.AuthenticatorMapperModule) FirehoseModule(org.apache.druid.guice.FirehoseModule) LocalDataStorageDruidModule(org.apache.druid.guice.LocalDataStorageDruidModule) DerbyMetadataStorageDruidModule(org.apache.druid.metadata.storage.derby.DerbyMetadataStorageDruidModule) Client(org.apache.druid.guice.annotations.Client) EscalatedClient(org.apache.druid.guice.annotations.EscalatedClient) ExtensionsConfig(org.apache.druid.guice.ExtensionsConfig) JacksonConfigManagerModule(org.apache.druid.guice.JacksonConfigManagerModule) LifecycleModule(org.apache.druid.guice.LifecycleModule) ExternalStorageAccessSecurityModule(org.apache.druid.server.initialization.ExternalStorageAccessSecurityModule) AuthorizerModule(org.apache.druid.guice.security.AuthorizerModule) IndexingServiceDiscoveryModule(org.apache.druid.guice.IndexingServiceDiscoveryModule) ExpressionModule(org.apache.druid.guice.ExpressionModule) LocalDataStorageDruidModule(org.apache.druid.guice.LocalDataStorageDruidModule) StartupLoggingModule(org.apache.druid.guice.StartupLoggingModule) SegmentWriteOutMediumModule(org.apache.druid.segment.writeout.SegmentWriteOutMediumModule) DerbyMetadataStorageDruidModule(org.apache.druid.metadata.storage.derby.DerbyMetadataStorageDruidModule) DruidProcessingConfigModule(org.apache.druid.guice.DruidProcessingConfigModule) EscalatedClient(org.apache.druid.guice.annotations.EscalatedClient) MetadataConfigModule(org.apache.druid.guice.MetadataConfigModule) CoordinatorDiscoveryModule(org.apache.druid.guice.CoordinatorDiscoveryModule) AuthorizerMapperModule(org.apache.druid.server.initialization.AuthorizerMapperModule) DruidAuthModule(org.apache.druid.guice.security.DruidAuthModule) MetricsModule(org.apache.druid.server.metrics.MetricsModule) AnnouncerModule(org.apache.druid.guice.AnnouncerModule) StorageNodeModule(org.apache.druid.guice.StorageNodeModule) AuthenticatorModule(org.apache.druid.guice.security.AuthenticatorModule) Module(com.google.inject.Module) ExpressionModule(org.apache.druid.guice.ExpressionModule) DruidAuthModule(org.apache.druid.guice.security.DruidAuthModule) LifecycleModule(org.apache.druid.guice.LifecycleModule) StartupLoggingModule(org.apache.druid.guice.StartupLoggingModule) JacksonConfigManagerModule(org.apache.druid.guice.JacksonConfigManagerModule) AuthorizerMapperModule(org.apache.druid.server.initialization.AuthorizerMapperModule) AuthenticatorMapperModule(org.apache.druid.server.initialization.AuthenticatorMapperModule) TLSCertificateCheckerModule(org.apache.druid.server.security.TLSCertificateCheckerModule) IndexingServiceDiscoveryModule(org.apache.druid.guice.IndexingServiceDiscoveryModule) AuthenticatorModule(org.apache.druid.guice.security.AuthenticatorModule) HttpClientModule(org.apache.druid.guice.http.HttpClientModule) LocalDataStorageDruidModule(org.apache.druid.guice.LocalDataStorageDruidModule) DiscoveryModule(org.apache.druid.curator.discovery.DiscoveryModule) JettyServerModule(org.apache.druid.server.initialization.jetty.JettyServerModule) MetricsModule(org.apache.druid.server.metrics.MetricsModule) SegmentWriteOutMediumModule(org.apache.druid.segment.writeout.SegmentWriteOutMediumModule) FirehoseModule(org.apache.druid.guice.FirehoseModule) DerbyMetadataStorageDruidModule(org.apache.druid.metadata.storage.derby.DerbyMetadataStorageDruidModule) StorageNodeModule(org.apache.druid.guice.StorageNodeModule) MetadataConfigModule(org.apache.druid.guice.MetadataConfigModule) JavaScriptModule(org.apache.druid.guice.JavaScriptModule) ServerViewModule(org.apache.druid.guice.ServerViewModule) CoordinatorDiscoveryModule(org.apache.druid.guice.CoordinatorDiscoveryModule) CuratorModule(org.apache.druid.curator.CuratorModule) AnnouncerModule(org.apache.druid.guice.AnnouncerModule) DruidSecondaryModule(org.apache.druid.guice.DruidSecondaryModule) EscalatorModule(org.apache.druid.guice.security.EscalatorModule) ExternalStorageAccessSecurityModule(org.apache.druid.server.initialization.ExternalStorageAccessSecurityModule) DruidProcessingConfigModule(org.apache.druid.guice.DruidProcessingConfigModule) ServerModule(org.apache.druid.guice.ServerModule) EmitterModule(org.apache.druid.server.emitter.EmitterModule) AuthorizerModule(org.apache.druid.guice.security.AuthorizerModule) HttpClientModule(org.apache.druid.guice.http.HttpClientModule) JavaScriptModule(org.apache.druid.guice.JavaScriptModule)

Example 2 with LocalDataStorageDruidModule

use of org.apache.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()) {
        LOG.info("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 IndexingServiceInputSourceModule(), new LocalDataStorageDruidModule())));
    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 ("query".equalsIgnoreCase(type)) {
            jsonMapper.readValue(file, Query.class);
        } else if ("hadoopConfig".equalsIgnoreCase(type)) {
            jsonMapper.readValue(file, HadoopDruidIndexerConfig.class);
        } else if ("task".equalsIgnoreCase(type)) {
            jsonMapper.readValue(file, Task.class);
        } else if ("parse".equalsIgnoreCase(type)) {
            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);
            }
            parser.initializeParser();
            if (resource != null) {
                final CharSource source;
                if (new File(resource).isFile()) {
                    logWriter.write("loading data from file '" + resource + "'");
                    source = Resources.asByteSource(new File(resource).toURI().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) {
        LOG.error(e, "INVALID JSON!");
        Throwables.propagateIfPossible(e);
        throw new RuntimeException(e);
    }
}
Also used : CharSource(com.google.common.io.CharSource) IndexingServiceFirehoseModule(org.apache.druid.guice.IndexingServiceFirehoseModule) IndexingHadoopModule(org.apache.druid.indexer.IndexingHadoopModule) LocalDataStorageDruidModule(org.apache.druid.guice.LocalDataStorageDruidModule) UOE(org.apache.druid.java.util.common.UOE) Logger(org.apache.druid.java.util.common.logger.Logger) HadoopDruidIndexerConfig(org.apache.druid.indexer.HadoopDruidIndexerConfig) NullWriter(org.apache.commons.io.output.NullWriter) IOException(java.io.IOException) FirehoseModule(org.apache.druid.guice.FirehoseModule) IndexingServiceFirehoseModule(org.apache.druid.guice.IndexingServiceFirehoseModule) IndexingServiceInputSourceModule(org.apache.druid.guice.IndexingServiceInputSourceModule) Injector(com.google.inject.Injector) StringInputRowParser(org.apache.druid.data.input.impl.StringInputRowParser) ExtensionsConfig(org.apache.druid.guice.ExtensionsConfig) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ExtensionsConfig (org.apache.druid.guice.ExtensionsConfig)2 FirehoseModule (org.apache.druid.guice.FirehoseModule)2 LocalDataStorageDruidModule (org.apache.druid.guice.LocalDataStorageDruidModule)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 File (java.io.File)1 IOException (java.io.IOException)1 NullWriter (org.apache.commons.io.output.NullWriter)1 CuratorModule (org.apache.druid.curator.CuratorModule)1 DiscoveryModule (org.apache.druid.curator.discovery.DiscoveryModule)1 StringInputRowParser (org.apache.druid.data.input.impl.StringInputRowParser)1 AnnouncerModule (org.apache.druid.guice.AnnouncerModule)1 CoordinatorDiscoveryModule (org.apache.druid.guice.CoordinatorDiscoveryModule)1 DruidProcessingConfigModule (org.apache.druid.guice.DruidProcessingConfigModule)1 DruidSecondaryModule (org.apache.druid.guice.DruidSecondaryModule)1 ExpressionModule (org.apache.druid.guice.ExpressionModule)1 IndexingServiceDiscoveryModule (org.apache.druid.guice.IndexingServiceDiscoveryModule)1 IndexingServiceFirehoseModule (org.apache.druid.guice.IndexingServiceFirehoseModule)1