Search in sources :

Example 41 with Lifecycle

use of org.apache.druid.java.util.common.lifecycle.Lifecycle in project druid by druid-io.

the class CliCoordinator method getModules.

@Override
protected List<? extends Module> getModules() {
    List<Module> modules = new ArrayList<>();
    modules.add(JettyHttpClientModule.global());
    modules.add(new Module() {

        @Override
        public void configure(Binder binder) {
            binder.bindConstant().annotatedWith(Names.named("serviceName")).to(TieredBrokerConfig.DEFAULT_COORDINATOR_SERVICE_NAME);
            binder.bindConstant().annotatedWith(Names.named("servicePort")).to(8081);
            binder.bindConstant().annotatedWith(Names.named("tlsServicePort")).to(8281);
            ConfigProvider.bind(binder, DruidCoordinatorConfig.class);
            binder.bind(MetadataStorage.class).toProvider(MetadataStorageProvider.class);
            JsonConfigProvider.bind(binder, "druid.manager.segments", SegmentsMetadataManagerConfig.class);
            JsonConfigProvider.bind(binder, "druid.manager.rules", MetadataRuleManagerConfig.class);
            JsonConfigProvider.bind(binder, "druid.manager.lookups", LookupCoordinatorManagerConfig.class);
            JsonConfigProvider.bind(binder, "druid.coordinator.balancer", BalancerStrategyFactory.class);
            JsonConfigProvider.bind(binder, "druid.coordinator.segment", CoordinatorSegmentWatcherConfig.class);
            JsonConfigProvider.bind(binder, "druid.coordinator.balancer.cachingCost", CachingCostBalancerStrategyConfig.class);
            binder.bind(RedirectFilter.class).in(LazySingleton.class);
            if (beOverlord) {
                binder.bind(RedirectInfo.class).to(CoordinatorOverlordRedirectInfo.class).in(LazySingleton.class);
            } else {
                binder.bind(RedirectInfo.class).to(CoordinatorRedirectInfo.class).in(LazySingleton.class);
            }
            binder.bind(SegmentsMetadataManager.class).toProvider(SegmentsMetadataManagerProvider.class).in(ManageLifecycle.class);
            binder.bind(MetadataRuleManager.class).toProvider(MetadataRuleManagerProvider.class).in(ManageLifecycle.class);
            binder.bind(AuditManager.class).toProvider(AuditManagerProvider.class).in(ManageLifecycle.class);
            binder.bind(IndexingServiceClient.class).to(HttpIndexingServiceClient.class).in(LazySingleton.class);
            binder.bind(LookupCoordinatorManager.class).in(LazySingleton.class);
            binder.bind(CoordinatorServerView.class);
            binder.bind(DruidCoordinator.class);
            LifecycleModule.register(binder, CoordinatorServerView.class);
            LifecycleModule.register(binder, MetadataStorage.class);
            LifecycleModule.register(binder, DruidCoordinator.class);
            binder.bind(JettyServerInitializer.class).to(CoordinatorJettyServerInitializer.class);
            Jerseys.addResource(binder, CoordinatorResource.class);
            Jerseys.addResource(binder, CompactionResource.class);
            Jerseys.addResource(binder, CoordinatorDynamicConfigsResource.class);
            Jerseys.addResource(binder, CoordinatorCompactionConfigsResource.class);
            Jerseys.addResource(binder, TiersResource.class);
            Jerseys.addResource(binder, RulesResource.class);
            Jerseys.addResource(binder, ServersResource.class);
            Jerseys.addResource(binder, DataSourcesResource.class);
            Jerseys.addResource(binder, MetadataResource.class);
            Jerseys.addResource(binder, IntervalsResource.class);
            Jerseys.addResource(binder, LookupCoordinatorResource.class);
            Jerseys.addResource(binder, ClusterResource.class);
            Jerseys.addResource(binder, HttpServerInventoryViewResource.class);
            LifecycleModule.register(binder, Server.class);
            LifecycleModule.register(binder, DataSourcesResource.class);
            // Binding for Set of indexing service coordinator Duty
            final ConditionalMultibind<CoordinatorDuty> conditionalIndexingServiceDutyMultibind = ConditionalMultibind.create(properties, binder, CoordinatorDuty.class, CoordinatorIndexingServiceDuty.class);
            if (conditionalIndexingServiceDutyMultibind.matchCondition("druid.coordinator.merge.on", Predicates.equalTo("true"))) {
                throw new UnsupportedOperationException("'druid.coordinator.merge.on' is not supported anymore. " + "Please consider using Coordinator's automatic compaction instead. " + "See https://druid.apache.org/docs/latest/operations/segment-optimization.html and " + "https://druid.apache.org/docs/latest/operations/api-reference.html#compaction-configuration " + "for more details about compaction.");
            }
            conditionalIndexingServiceDutyMultibind.addConditionBinding("druid.coordinator.kill.on", "true", Predicates.equalTo("true"), KillUnusedSegments.class);
            conditionalIndexingServiceDutyMultibind.addConditionBinding("druid.coordinator.kill.pendingSegments.on", "true", Predicates.equalTo("true"), KillStalePendingSegments.class);
            // Binding for Set of metadata store management coordinator Ddty
            final ConditionalMultibind<CoordinatorDuty> conditionalMetadataStoreManagementDutyMultibind = ConditionalMultibind.create(properties, binder, CoordinatorDuty.class, CoordinatorMetadataStoreManagementDuty.class);
            conditionalMetadataStoreManagementDutyMultibind.addConditionBinding("druid.coordinator.kill.supervisor.on", "true", Predicates.equalTo("true"), KillSupervisors.class);
            conditionalMetadataStoreManagementDutyMultibind.addConditionBinding("druid.coordinator.kill.audit.on", "true", Predicates.equalTo("true"), KillAuditLog.class);
            conditionalMetadataStoreManagementDutyMultibind.addConditionBinding("druid.coordinator.kill.rule.on", "true", Predicates.equalTo("true"), KillRules.class);
            conditionalMetadataStoreManagementDutyMultibind.addConditionBinding("druid.coordinator.kill.datasource.on", "true", Predicates.equalTo("true"), KillDatasourceMetadata.class);
            conditionalMetadataStoreManagementDutyMultibind.addConditionBinding("druid.coordinator.kill.compaction.on", Predicates.equalTo("true"), KillCompactionConfig.class);
            bindAnnouncer(binder, Coordinator.class, DiscoverySideEffectsProvider.create());
            Jerseys.addResource(binder, SelfDiscoveryResource.class);
            LifecycleModule.registerKey(binder, Key.get(SelfDiscoveryResource.class));
            if (!beOverlord) {
                // These are needed to deserialize SupervisorSpec for Supervisor Auto Cleanup
                binder.bind(TaskStorage.class).toProvider(Providers.of(null));
                binder.bind(TaskMaster.class).toProvider(Providers.of(null));
                binder.bind(RowIngestionMetersFactory.class).toProvider(Providers.of(null));
            }
            binder.bind(CoordinatorCustomDutyGroups.class).toProvider(new CoordinatorCustomDutyGroupsProvider()).in(LazySingleton.class);
        }

        @Provides
        @LazySingleton
        public LoadQueueTaskMaster getLoadQueueTaskMaster(Provider<CuratorFramework> curatorFrameworkProvider, ObjectMapper jsonMapper, ScheduledExecutorFactory factory, DruidCoordinatorConfig config, @EscalatedGlobal HttpClient httpClient, ZkPathsConfig zkPaths, Lifecycle lifecycle) {
            boolean useHttpLoadQueuePeon = "http".equalsIgnoreCase(config.getLoadQueuePeonType());
            ExecutorService callBackExec;
            if (useHttpLoadQueuePeon) {
                callBackExec = Execs.singleThreaded("LoadQueuePeon-callbackexec--%d");
            } else {
                callBackExec = Execs.multiThreaded(config.getNumCuratorCallBackThreads(), "LoadQueuePeon-callbackexec--%d");
            }
            ExecutorServices.manageLifecycle(lifecycle, callBackExec);
            return new LoadQueueTaskMaster(curatorFrameworkProvider, jsonMapper, factory.create(1, "Master-PeonExec--%d"), callBackExec, config, httpClient, zkPaths);
        }
    });
    if (beOverlord) {
        modules.addAll(new CliOverlord().getModules(false));
    } else {
        // Only add LookupSerdeModule if !beOverlord, since CliOverlord includes it, and having two copies causes
        // the injector to get confused due to having multiple bindings for the same classes.
        modules.add(new LookupSerdeModule());
    }
    return modules;
}
Also used : LookupSerdeModule(org.apache.druid.query.lookup.LookupSerdeModule) Server(org.eclipse.jetty.server.Server) ArrayList(java.util.ArrayList) LookupCoordinatorResource(org.apache.druid.server.http.LookupCoordinatorResource) CoordinatorResource(org.apache.druid.server.http.CoordinatorResource) ServersResource(org.apache.druid.server.http.ServersResource) LazySingleton(org.apache.druid.guice.LazySingleton) SegmentsMetadataManagerConfig(org.apache.druid.metadata.SegmentsMetadataManagerConfig) CuratorFramework(org.apache.curator.framework.CuratorFramework) CachingCostBalancerStrategyConfig(org.apache.druid.server.coordinator.CachingCostBalancerStrategyConfig) ZkPathsConfig(org.apache.druid.server.initialization.ZkPathsConfig) KillRules(org.apache.druid.server.coordinator.duty.KillRules) AuditManager(org.apache.druid.audit.AuditManager) DruidCoordinator(org.apache.druid.server.coordinator.DruidCoordinator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MetadataStorageProvider(org.apache.druid.metadata.MetadataStorageProvider) MetadataResource(org.apache.druid.server.http.MetadataResource) CoordinatorMetadataStoreManagementDuty(org.apache.druid.guice.annotations.CoordinatorMetadataStoreManagementDuty) IndexingServiceClient(org.apache.druid.client.indexing.IndexingServiceClient) HttpIndexingServiceClient(org.apache.druid.client.indexing.HttpIndexingServiceClient) KillCompactionConfig(org.apache.druid.server.coordinator.duty.KillCompactionConfig) ManageLifecycle(org.apache.druid.guice.ManageLifecycle) Lifecycle(org.apache.druid.java.util.common.lifecycle.Lifecycle) CoordinatorSegmentWatcherConfig(org.apache.druid.client.CoordinatorSegmentWatcherConfig) LookupCoordinatorResource(org.apache.druid.server.http.LookupCoordinatorResource) HttpServerInventoryViewResource(org.apache.druid.client.HttpServerInventoryViewResource) ScheduledExecutorFactory(org.apache.druid.java.util.common.concurrent.ScheduledExecutorFactory) MetadataStorage(org.apache.druid.metadata.MetadataStorage) RedirectInfo(org.apache.druid.server.http.RedirectInfo) CoordinatorRedirectInfo(org.apache.druid.server.http.CoordinatorRedirectInfo) LifecycleModule(org.apache.druid.guice.LifecycleModule) JettyHttpClientModule(org.apache.druid.guice.http.JettyHttpClientModule) Module(com.google.inject.Module) LookupSerdeModule(org.apache.druid.query.lookup.LookupSerdeModule) KillAuditLog(org.apache.druid.server.coordinator.duty.KillAuditLog) LoadQueueTaskMaster(org.apache.druid.server.coordinator.LoadQueueTaskMaster) SegmentsMetadataManager(org.apache.druid.metadata.SegmentsMetadataManager) MetadataRuleManager(org.apache.druid.metadata.MetadataRuleManager) KillStalePendingSegments(org.apache.druid.server.coordinator.KillStalePendingSegments) ClusterResource(org.apache.druid.server.http.ClusterResource) Binder(com.google.inject.Binder) TiersResource(org.apache.druid.server.http.TiersResource) CoordinatorDuty(org.apache.druid.server.coordinator.duty.CoordinatorDuty) KillUnusedSegments(org.apache.druid.server.coordinator.duty.KillUnusedSegments) DruidCoordinatorConfig(org.apache.druid.server.coordinator.DruidCoordinatorConfig) CoordinatorCompactionConfigsResource(org.apache.druid.server.http.CoordinatorCompactionConfigsResource) LookupCoordinatorManagerConfig(org.apache.druid.server.lookup.cache.LookupCoordinatorManagerConfig) CoordinatorCustomDutyGroups(org.apache.druid.server.coordinator.duty.CoordinatorCustomDutyGroups) KillDatasourceMetadata(org.apache.druid.server.coordinator.duty.KillDatasourceMetadata) RulesResource(org.apache.druid.server.http.RulesResource) CompactionResource(org.apache.druid.server.http.CompactionResource) CoordinatorIndexingServiceDuty(org.apache.druid.guice.annotations.CoordinatorIndexingServiceDuty) BalancerStrategyFactory(org.apache.druid.server.coordinator.BalancerStrategyFactory) SelfDiscoveryResource(org.apache.druid.server.http.SelfDiscoveryResource) ManageLifecycle(org.apache.druid.guice.ManageLifecycle) DruidCoordinator(org.apache.druid.server.coordinator.DruidCoordinator) Coordinator(org.apache.druid.client.coordinator.Coordinator) Provides(com.google.inject.Provides) CoordinatorDynamicConfigsResource(org.apache.druid.server.http.CoordinatorDynamicConfigsResource) IntervalsResource(org.apache.druid.server.http.IntervalsResource) MetadataRuleManagerConfig(org.apache.druid.metadata.MetadataRuleManagerConfig) HttpClient(org.apache.druid.java.util.http.client.HttpClient) ExecutorService(java.util.concurrent.ExecutorService) KillSupervisors(org.apache.druid.server.coordinator.duty.KillSupervisors) DataSourcesResource(org.apache.druid.server.http.DataSourcesResource) CoordinatorServerView(org.apache.druid.client.CoordinatorServerView) ConditionalMultibind(org.apache.druid.guice.ConditionalMultibind)

Example 42 with Lifecycle

use of org.apache.druid.java.util.common.lifecycle.Lifecycle 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.getPlaintextPort();
    tlsPort = node.getTlsPort();
    lifecycle = injector.getInstance(Lifecycle.class);
    lifecycle.start();
    ClientHolder holder = injector.getInstance(ClientHolder.class);
    server = injector.getInstance(Server.class);
    client = holder.getClient();
}
Also used : Server(org.eclipse.jetty.server.Server) Injector(com.google.inject.Injector) Lifecycle(org.apache.druid.java.util.common.lifecycle.Lifecycle) DruidNode(org.apache.druid.server.DruidNode) Self(org.apache.druid.guice.annotations.Self) Before(org.junit.Before)

Example 43 with Lifecycle

use of org.apache.druid.java.util.common.lifecycle.Lifecycle in project druid by druid-io.

the class CliPeon method run.

@SuppressForbidden(reason = "System#out, System#err")
@Override
public void run() {
    try {
        Injector injector = makeInjector();
        try {
            final Lifecycle lifecycle = initLifecycle(injector);
            final Thread hook = new Thread(() -> {
                log.info("Running shutdown hook");
                lifecycle.stop();
            });
            Runtime.getRuntime().addShutdownHook(hook);
            injector.getInstance(ExecutorLifecycle.class).join();
            // Sanity check to help debug unexpected non-daemon threads
            final Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
            for (Thread thread : threadSet) {
                if (!thread.isDaemon() && thread != Thread.currentThread()) {
                    log.info("Thread [%s] is non daemon.", thread);
                }
            }
            // Explicitly call lifecycle stop, dont rely on shutdown hook.
            lifecycle.stop();
            try {
                Runtime.getRuntime().removeShutdownHook(hook);
            } catch (IllegalStateException e) {
                System.err.println("Cannot remove shutdown hook, already shutting down!");
            }
        } catch (Throwable t) {
            System.err.println("Error!");
            System.err.println(Throwables.getStackTraceAsString(t));
            System.exit(1);
        }
        System.out.println("Finished peon task");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Injector(com.google.inject.Injector) ExecutorLifecycle(org.apache.druid.indexing.worker.executor.ExecutorLifecycle) ManageLifecycle(org.apache.druid.guice.ManageLifecycle) Lifecycle(org.apache.druid.java.util.common.lifecycle.Lifecycle) ExecutorLifecycle(org.apache.druid.indexing.worker.executor.ExecutorLifecycle) IOException(java.io.IOException) SuppressForbidden(io.netty.util.SuppressForbidden)

Example 44 with Lifecycle

use of org.apache.druid.java.util.common.lifecycle.Lifecycle in project druid by druid-io.

the class AsyncQueryForwardingServletTest method setup.

@Override
@Before
public void setup() throws Exception {
    setProperties();
    Injector injector = setupInjector();
    final DruidNode node = injector.getInstance(Key.get(DruidNode.class, Self.class));
    port = node.getPlaintextPort();
    port1 = SocketUtil.findOpenPortFrom(port + 1);
    port2 = SocketUtil.findOpenPortFrom(port1 + 1);
    lifecycle = injector.getInstance(Lifecycle.class);
    lifecycle.start();
    ClientHolder holder = injector.getInstance(ClientHolder.class);
    client = holder.getClient();
}
Also used : Injector(com.google.inject.Injector) Lifecycle(org.apache.druid.java.util.common.lifecycle.Lifecycle) Self(org.apache.druid.guice.annotations.Self) Before(org.junit.Before)

Example 45 with Lifecycle

use of org.apache.druid.java.util.common.lifecycle.Lifecycle in project druid by druid-io.

the class GuiceRunnable method initLifecycle.

public Lifecycle initLifecycle(Injector injector) {
    try {
        final Lifecycle lifecycle = injector.getInstance(Lifecycle.class);
        final StartupLoggingConfig startupLoggingConfig = injector.getInstance(StartupLoggingConfig.class);
        Long directSizeBytes = null;
        try {
            directSizeBytes = JvmUtils.getRuntimeInfo().getDirectMemorySizeBytes();
        } catch (UnsupportedOperationException ignore) {
        // querying direct memory is not supported
        }
        log.info("Starting up with processors[%,d], memory[%,d], maxMemory[%,d]%s. Properties follow.", JvmUtils.getRuntimeInfo().getAvailableProcessors(), JvmUtils.getRuntimeInfo().getTotalHeapSizeBytes(), JvmUtils.getRuntimeInfo().getMaxHeapSizeBytes(), directSizeBytes != null ? StringUtils.format(", directMemory[%,d]", directSizeBytes) : "");
        if (startupLoggingConfig.isLogProperties()) {
            final Set<String> maskProperties = Sets.newHashSet(startupLoggingConfig.getMaskProperties());
            final Properties props = injector.getInstance(Properties.class);
            for (String propertyName : Ordering.natural().sortedCopy(props.stringPropertyNames())) {
                String property = props.getProperty(propertyName);
                for (String masked : maskProperties) {
                    if (propertyName.contains(masked)) {
                        property = "<masked>";
                        break;
                    }
                }
                log.info("* %s: %s", propertyName, property);
            }
        }
        try {
            lifecycle.start();
        } catch (Throwable t) {
            log.error(t, "Error when starting up.  Failing.");
            System.exit(1);
        }
        return lifecycle;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : StartupLoggingConfig(org.apache.druid.server.log.StartupLoggingConfig) Lifecycle(org.apache.druid.java.util.common.lifecycle.Lifecycle) Properties(java.util.Properties)

Aggregations

Lifecycle (org.apache.druid.java.util.common.lifecycle.Lifecycle)46 Test (org.junit.Test)21 Injector (com.google.inject.Injector)12 URL (java.net.URL)12 ExecutionException (java.util.concurrent.ExecutionException)12 StatusResponseHolder (org.apache.druid.java.util.http.client.response.StatusResponseHolder)10 Before (org.junit.Before)10 ExecutorService (java.util.concurrent.ExecutorService)6 Binder (com.google.inject.Binder)5 Module (com.google.inject.Module)5 OutputStream (java.io.OutputStream)5 Properties (java.util.Properties)5 ManageLifecycle (org.apache.druid.guice.ManageLifecycle)5 NoopServiceEmitter (org.apache.druid.server.metrics.NoopServiceEmitter)5 ChannelException (org.jboss.netty.channel.ChannelException)5 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)4 IOException (java.io.IOException)4 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Provides (com.google.inject.Provides)3