Search in sources :

Example 1 with LoggingContextAccessor

use of io.cdap.cdap.common.logging.LoggingContextAccessor in project cdap by caskdata.

the class AbstractServiceMain method init.

@Override
public final void init(String[] args) throws Exception {
    LOG.info("Initializing master service class {}", getClass().getName());
    // System wide setup
    Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler());
    // Intercept JUL loggers
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();
    TypeToken<?> type = TypeToken.of(getClass()).resolveType(AbstractServiceMain.class.getTypeParameters()[0]);
    T options = (T) type.getRawType().newInstance();
    OptionsParser.init(options, args, getClass().getSimpleName(), ProjectInfo.getVersion().toString(), System.out);
    CConfiguration cConf = CConfiguration.create();
    SecurityUtil.loginForMasterService(cConf);
    SConfiguration sConf = SConfiguration.create();
    if (options.getExtraConfPath() != null) {
        cConf.addResource(new File(options.getExtraConfPath(), "cdap-site.xml").toURI().toURL());
        sConf.addResource(new File(options.getExtraConfPath(), "cdap-security.xml").toURI().toURL());
    }
    cConf = updateCConf(cConf);
    Configuration hConf = new Configuration();
    masterEnv = MasterEnvironments.setMasterEnvironment(MasterEnvironments.create(cConf, options.getEnvProvider()));
    MasterEnvironmentContext masterEnvContext = MasterEnvironments.createContext(cConf, hConf, masterEnv.getName());
    masterEnv.initialize(masterEnvContext);
    List<Module> modules = new ArrayList<>();
    modules.add(new ConfigModule(cConf, hConf, sConf));
    modules.add(RemoteAuthenticatorModules.getDefaultModule());
    modules.add(new PreviewConfigModule(cConf, hConf, sConf));
    modules.add(new IOModule());
    modules.add(new MetricsClientRuntimeModule().getDistributedModules());
    modules.add(new AbstractModule() {

        @Override
        protected void configure() {
            bind(DiscoveryService.class).toProvider(new SupplierProviderBridge<>(masterEnv.getDiscoveryServiceSupplier()));
            bind(DiscoveryServiceClient.class).toProvider(new SupplierProviderBridge<>(masterEnv.getDiscoveryServiceClientSupplier()));
        }
    });
    modules.add(getLogAppenderModule());
    CoreSecurityModule coreSecurityModule = CoreSecurityRuntimeModule.getDistributedModule(cConf);
    modules.add(coreSecurityModule);
    if (coreSecurityModule.requiresZKClient()) {
        modules.add(new ZKClientModule());
    }
    modules.add(new AuthenticationContextModules().getMasterModule());
    modules.addAll(getServiceModules(masterEnv, options, cConf));
    injector = Guice.createInjector(modules);
    // Initialize logging context
    LogAppenderInitializer logAppenderInitializer = injector.getInstance(LogAppenderInitializer.class);
    closeableResources.add(logAppenderInitializer);
    logAppenderInitializer.initialize();
    Optional.ofNullable(getLoggingContext(options)).ifPresent(LoggingContextAccessor::setLoggingContext);
    // Add Services
    services.add(injector.getInstance(MetricsCollectionService.class));
    addServices(injector, services, closeableResources, masterEnv, masterEnvContext, options);
    // Optionally get the storage provider. It is for destroy() method to close it on shutdown.
    Binding<StorageProvider> storageBinding = injector.getExistingBinding(Key.get(StorageProvider.class));
    if (storageBinding != null) {
        storageProvider = storageBinding.getProvider().get();
    }
    LOG.info("Service {} initialized", getClass().getName());
}
Also used : IOModule(io.cdap.cdap.common.guice.IOModule) Configuration(org.apache.hadoop.conf.Configuration) SConfiguration(io.cdap.cdap.common.conf.SConfiguration) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) PreviewConfigModule(io.cdap.cdap.app.preview.PreviewConfigModule) ArrayList(java.util.ArrayList) MetricsClientRuntimeModule(io.cdap.cdap.metrics.guice.MetricsClientRuntimeModule) ZKClientModule(io.cdap.cdap.common.guice.ZKClientModule) LogAppenderInitializer(io.cdap.cdap.logging.appender.LogAppenderInitializer) PreviewConfigModule(io.cdap.cdap.app.preview.PreviewConfigModule) CoreSecurityModule(io.cdap.cdap.security.guice.CoreSecurityModule) SConfiguration(io.cdap.cdap.common.conf.SConfiguration) SupplierProviderBridge(io.cdap.cdap.common.guice.SupplierProviderBridge) UncaughtExceptionHandler(io.cdap.cdap.common.logging.common.UncaughtExceptionHandler) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) AuthenticationContextModules(io.cdap.cdap.security.auth.context.AuthenticationContextModules) StorageProvider(io.cdap.cdap.spi.data.StorageProvider) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) AbstractModule(com.google.inject.AbstractModule) MasterEnvironmentContext(io.cdap.cdap.master.spi.environment.MasterEnvironmentContext) Module(com.google.inject.Module) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) PreviewConfigModule(io.cdap.cdap.app.preview.PreviewConfigModule) CoreSecurityModule(io.cdap.cdap.security.guice.CoreSecurityModule) TransactionExecutorModule(io.cdap.cdap.data.runtime.TransactionExecutorModule) RemoteLogAppenderModule(io.cdap.cdap.logging.guice.RemoteLogAppenderModule) CoreSecurityRuntimeModule(io.cdap.cdap.security.guice.CoreSecurityRuntimeModule) ZKClientModule(io.cdap.cdap.common.guice.ZKClientModule) StorageModule(io.cdap.cdap.data.runtime.StorageModule) IOModule(io.cdap.cdap.common.guice.IOModule) MetricsClientRuntimeModule(io.cdap.cdap.metrics.guice.MetricsClientRuntimeModule) AbstractModule(com.google.inject.AbstractModule) LoggingContextAccessor(io.cdap.cdap.common.logging.LoggingContextAccessor) File(java.io.File)

Aggregations

AbstractModule (com.google.inject.AbstractModule)1 Module (com.google.inject.Module)1 MetricsCollectionService (io.cdap.cdap.api.metrics.MetricsCollectionService)1 PreviewConfigModule (io.cdap.cdap.app.preview.PreviewConfigModule)1 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)1 SConfiguration (io.cdap.cdap.common.conf.SConfiguration)1 ConfigModule (io.cdap.cdap.common.guice.ConfigModule)1 IOModule (io.cdap.cdap.common.guice.IOModule)1 SupplierProviderBridge (io.cdap.cdap.common.guice.SupplierProviderBridge)1 ZKClientModule (io.cdap.cdap.common.guice.ZKClientModule)1 LoggingContextAccessor (io.cdap.cdap.common.logging.LoggingContextAccessor)1 UncaughtExceptionHandler (io.cdap.cdap.common.logging.common.UncaughtExceptionHandler)1 StorageModule (io.cdap.cdap.data.runtime.StorageModule)1 TransactionExecutorModule (io.cdap.cdap.data.runtime.TransactionExecutorModule)1 LogAppenderInitializer (io.cdap.cdap.logging.appender.LogAppenderInitializer)1 RemoteLogAppenderModule (io.cdap.cdap.logging.guice.RemoteLogAppenderModule)1 MasterEnvironmentContext (io.cdap.cdap.master.spi.environment.MasterEnvironmentContext)1 MetricsClientRuntimeModule (io.cdap.cdap.metrics.guice.MetricsClientRuntimeModule)1 AuthenticationContextModules (io.cdap.cdap.security.auth.context.AuthenticationContextModules)1 CoreSecurityModule (io.cdap.cdap.security.guice.CoreSecurityModule)1