Search in sources :

Example 1 with NamedConfigParametersModule

use of com.github.joschi.jadconfig.guice.NamedConfigParametersModule in project graylog2-server by Graylog2.

the class CmdLineTool method setupInjector.

protected Injector setupInjector(NamedConfigParametersModule configModule, Module... otherModules) {
    try {
        final ImmutableList.Builder<Module> modules = ImmutableList.builder();
        modules.add(configModule);
        modules.addAll(getSharedBindingsModules());
        modules.addAll(getCommandBindings());
        modules.addAll(Arrays.asList(otherModules));
        modules.add(new Module() {

            @Override
            public void configure(Binder binder) {
                binder.bind(String.class).annotatedWith(Names.named("BootstrapCommand")).toInstance(commandName);
            }
        });
        return GuiceInjectorHolder.createInjector(modules.build());
    } catch (CreationException e) {
        annotateInjectorCreationException(e);
        return null;
    } catch (Exception e) {
        LOG.error("Injector creation failed!", e);
        return null;
    }
}
Also used : Binder(com.google.inject.Binder) ImmutableList(com.google.common.collect.ImmutableList) CreationException(com.google.inject.CreationException) Module(com.google.inject.Module) PluginModule(org.graylog2.plugin.PluginModule) NamedConfigParametersModule(com.github.joschi.jadconfig.guice.NamedConfigParametersModule) ParameterException(com.github.joschi.jadconfig.ParameterException) NodeIdPersistenceException(org.graylog2.plugin.system.NodeIdPersistenceException) RepositoryException(com.github.joschi.jadconfig.RepositoryException) ValidationException(com.github.joschi.jadconfig.ValidationException) AccessDeniedException(java.nio.file.AccessDeniedException) CreationException(com.google.inject.CreationException)

Example 2 with NamedConfigParametersModule

use of com.github.joschi.jadconfig.guice.NamedConfigParametersModule in project graylog2-server by Graylog2.

the class CmdLineTool method setupCoreConfigInjector.

/**
 * Set up a separate injector, containing only the core configuration bindings. It can be used to look up
 * configuration values in modules at binding time.
 */
protected Injector setupCoreConfigInjector() {
    final NamedConfigParametersModule configModule = new NamedConfigParametersModule(jadConfig.getConfigurationBeans());
    Injector coreConfigInjector = null;
    try {
        coreConfigInjector = Guice.createInjector(Stage.PRODUCTION, ImmutableList.of(configModule, (Module) Binder::requireExplicitBindings, this::featureFlagsBinding));
    } catch (CreationException e) {
        annotateInjectorCreationException(e);
    } catch (Exception e) {
        LOG.error("Injector creation failed!", e);
    }
    if (coreConfigInjector == null) {
        LOG.error("Injector for core configuration could not be created, exiting! (Please include the previous " + "error messages in bug reports.)");
        System.exit(1);
    }
    return coreConfigInjector;
}
Also used : NamedConfigParametersModule(com.github.joschi.jadconfig.guice.NamedConfigParametersModule) Injector(com.google.inject.Injector) CreationException(com.google.inject.CreationException) ParameterException(com.github.joschi.jadconfig.ParameterException) NodeIdPersistenceException(org.graylog2.plugin.system.NodeIdPersistenceException) RepositoryException(com.github.joschi.jadconfig.RepositoryException) UnsupportedSearchException(org.graylog2.storage.UnsupportedSearchException) ValidationException(com.github.joschi.jadconfig.ValidationException) ElasticsearchProbeException(org.graylog2.storage.versionprobe.ElasticsearchProbeException) AccessDeniedException(java.nio.file.AccessDeniedException) CreationException(com.google.inject.CreationException)

Example 3 with NamedConfigParametersModule

use of com.github.joschi.jadconfig.guice.NamedConfigParametersModule in project graylog2-server by Graylog2.

the class CmdLineTool method run.

@Override
public void run() {
    final Level logLevel = setupLogger();
    if (isDumpDefaultConfig()) {
        dumpDefaultConfigAndExit();
    }
    // This is holding all our metrics.
    MetricRegistry metricRegistry = MetricRegistryFactory.create();
    featureFlags = getFeatureFlags(metricRegistry);
    installConfigRepositories();
    installCommandConfig();
    beforeStart();
    beforeStart(parseAndGetTLSConfiguration(), parseAndGetPathConfiguration(configFile));
    processConfiguration(jadConfig);
    coreConfigInjector = setupCoreConfigInjector();
    final Set<Plugin> plugins = loadPlugins(getPluginPath(configFile), chainingClassLoader);
    installPluginConfig(plugins);
    processConfiguration(jadConfig);
    if (isDumpConfig()) {
        dumpCurrentConfigAndExit();
    }
    if (!validateConfiguration()) {
        LOG.error("Validating configuration file failed - exiting.");
        System.exit(1);
    }
    final List<String> arguments = ManagementFactory.getRuntimeMXBean().getInputArguments();
    LOG.info("Running with JVM arguments: {}", Joiner.on(' ').join(arguments));
    beforeInjectorCreation(plugins);
    injector = setupInjector(new NamedConfigParametersModule(jadConfig.getConfigurationBeans()), new PluginBindings(plugins), binder -> binder.bind(MetricRegistry.class).toInstance(metricRegistry));
    if (injector == null) {
        LOG.error("Injector could not be created, exiting! (Please include the previous error messages in bug " + "reports.)");
        System.exit(1);
    }
    addInstrumentedAppender(metricRegistry, logLevel);
    // Report metrics via JMX.
    final JmxReporter reporter = JmxReporter.forRegistry(metricRegistry).build();
    reporter.start();
    startCommand();
}
Also used : NamedConfigParametersModule(com.github.joschi.jadconfig.guice.NamedConfigParametersModule) Option(com.github.rvesse.airline.annotations.Option) Module(com.google.inject.Module) Plugin(org.graylog2.plugin.Plugin) Arrays(java.util.Arrays) ParameterException(com.github.joschi.jadconfig.ParameterException) NodeIdPersistenceException(org.graylog2.plugin.system.NodeIdPersistenceException) FeatureFlagsFactory(org.graylog2.featureflag.FeatureFlagsFactory) GuiceInjectorHolder(org.graylog2.shared.bindings.GuiceInjectorHolder) RepositoryException(com.github.joschi.jadconfig.RepositoryException) LoggerContext(org.apache.logging.log4j.core.LoggerContext) Tools(org.graylog2.plugin.Tools) LoggerFactory(org.slf4j.LoggerFactory) Level(org.apache.logging.log4j.Level) Security(java.security.Security) InstrumentedAppender(com.codahale.metrics.log4j2.InstrumentedAppender) Message(com.google.inject.spi.Message) PluginLoaderConfig(org.graylog2.plugin.PluginLoaderConfig) Map(java.util.Map) UnsupportedSearchException(org.graylog2.storage.UnsupportedSearchException) Version(org.graylog2.plugin.Version) PropertiesRepository(com.github.joschi.jadconfig.repositories.PropertiesRepository) Command(com.github.rvesse.airline.annotations.Command) ChainingClassLoader(org.graylog2.shared.plugins.ChainingClassLoader) Path(java.nio.file.Path) TLSProtocolsConfiguration(org.graylog2.configuration.TLSProtocolsConfiguration) ExceptionUtils(org.graylog2.shared.utilities.ExceptionUtils) Slf4JLoggerFactory(io.netty.util.internal.logging.Slf4JLoggerFactory) ImmutableSet(com.google.common.collect.ImmutableSet) JodaTimeConverterFactory(com.github.joschi.jadconfig.jodatime.JodaTimeConverterFactory) Collection(java.util.Collection) Set(java.util.Set) ServerStatus(org.graylog2.plugin.ServerStatus) SearchVersion(org.graylog2.storage.SearchVersion) ValidationException(com.github.joschi.jadconfig.ValidationException) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Stage(com.google.inject.Stage) List(java.util.List) Stream(java.util.stream.Stream) Configuration(org.graylog2.Configuration) DocsHelper(org.graylog2.plugin.DocsHelper) PluginBindings(org.graylog2.shared.bindings.PluginBindings) PathConfiguration(org.graylog2.configuration.PathConfiguration) PluginMetaData(org.graylog2.plugin.PluginMetaData) ElasticsearchProbeException(org.graylog2.storage.versionprobe.ElasticsearchProbeException) UI(org.graylog2.shared.UI) AccessDeniedException(java.nio.file.AccessDeniedException) GuavaConverterFactory(com.github.joschi.jadconfig.guava.GuavaConverterFactory) Joiner(com.google.common.base.Joiner) EnvironmentRepository(com.github.joschi.jadconfig.repositories.EnvironmentRepository) Strings.nullToEmpty(com.google.common.base.Strings.nullToEmpty) Strings(joptsimple.internal.Strings) HashSet(java.util.HashSet) JmxReporter(com.codahale.metrics.jmx.JmxReporter) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Binder(com.google.inject.Binder) SystemPropertiesRepository(com.github.joschi.jadconfig.repositories.SystemPropertiesRepository) JadConfig(com.github.joschi.jadconfig.JadConfig) ManagementFactory(java.lang.management.ManagementFactory) NamedConfigParametersModule(com.github.joschi.jadconfig.guice.NamedConfigParametersModule) MigrateCmd(org.graylog2.bootstrap.commands.MigrateCmd) FeatureFlags(org.graylog2.featureflag.FeatureFlags) MetricRegistry(com.codahale.metrics.MetricRegistry) Logger(org.slf4j.Logger) Names(com.google.inject.name.Names) PluginLoader(org.graylog2.shared.plugins.PluginLoader) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider) Injector(com.google.inject.Injector) CreationException(com.google.inject.CreationException) Repository(com.github.joschi.jadconfig.Repository) Guice(com.google.inject.Guice) MetricRegistryFactory(org.graylog2.shared.metrics.MetricRegistryFactory) InternalLoggerFactory(io.netty.util.internal.logging.InternalLoggerFactory) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) PluginBindings(org.graylog2.shared.bindings.PluginBindings) MetricRegistry(com.codahale.metrics.MetricRegistry) Level(org.apache.logging.log4j.Level) JmxReporter(com.codahale.metrics.jmx.JmxReporter) Plugin(org.graylog2.plugin.Plugin)

Aggregations

ParameterException (com.github.joschi.jadconfig.ParameterException)3 RepositoryException (com.github.joschi.jadconfig.RepositoryException)3 ValidationException (com.github.joschi.jadconfig.ValidationException)3 NamedConfigParametersModule (com.github.joschi.jadconfig.guice.NamedConfigParametersModule)3 CreationException (com.google.inject.CreationException)3 AccessDeniedException (java.nio.file.AccessDeniedException)3 ImmutableList (com.google.common.collect.ImmutableList)2 Binder (com.google.inject.Binder)2 Injector (com.google.inject.Injector)2 Module (com.google.inject.Module)2 NodeIdPersistenceException (org.graylog2.plugin.system.NodeIdPersistenceException)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 JmxReporter (com.codahale.metrics.jmx.JmxReporter)1 InstrumentedAppender (com.codahale.metrics.log4j2.InstrumentedAppender)1 JadConfig (com.github.joschi.jadconfig.JadConfig)1 Repository (com.github.joschi.jadconfig.Repository)1 GuavaConverterFactory (com.github.joschi.jadconfig.guava.GuavaConverterFactory)1 JodaTimeConverterFactory (com.github.joschi.jadconfig.jodatime.JodaTimeConverterFactory)1 EnvironmentRepository (com.github.joschi.jadconfig.repositories.EnvironmentRepository)1 PropertiesRepository (com.github.joschi.jadconfig.repositories.PropertiesRepository)1