org.elasticsearch.common.component.LifecycleComponent Java Examples

The following examples show how to use org.elasticsearch.common.component.LifecycleComponent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SQLPlugin.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public Collection<Class<? extends LifecycleComponent>> getGuiceServiceClasses() {
    ImmutableList.Builder<Class<? extends LifecycleComponent>> builder =
        ImmutableList.<Class<? extends LifecycleComponent>>builder()
        .add(DecommissioningService.class)
        .add(NodeDisconnectJobMonitorService.class)
        .add(JobsLogService.class)
        .add(PostgresNetty.class)
        .add(TasksService.class)
        .add(Schemas.class)
        .add(DefaultTemplateService.class)
        .add(ArrayMapperService.class)
        .add(DanglingArtifactsService.class);
    if (licenseExtension != null) {
        builder.addAll(licenseExtension.getGuiceServiceClasses());
    }
    if (sslExtension != null) {
        builder.addAll(sslExtension.getGuiceServiceClasses());
    }
    return builder.build();
}
 
Example #2
Source File: Node.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private Node stop() {
    if (!lifecycle.moveToStopped()) {
        return this;
    }
    ESLogger logger = Loggers.getLogger(Node.class, settings.get("name"));
    logger.info("stopping ...");

    injector.getInstance(TribeService.class).stop();
    injector.getInstance(ResourceWatcherService.class).stop();
    if (settings.getAsBoolean("http.enabled", true)) {
        injector.getInstance(HttpServer.class).stop();
    }

    injector.getInstance(SnapshotsService.class).stop();
    injector.getInstance(SnapshotShardsService.class).stop();
    // stop any changes happening as a result of cluster state changes
    injector.getInstance(IndicesClusterStateService.class).stop();
    // we close indices first, so operations won't be allowed on it
    injector.getInstance(IndexingMemoryController.class).stop();
    injector.getInstance(IndicesTTLService.class).stop();
    injector.getInstance(RoutingService.class).stop();
    injector.getInstance(ClusterService.class).stop();
    injector.getInstance(DiscoveryService.class).stop();
    injector.getInstance(MonitorService.class).stop();
    injector.getInstance(GatewayService.class).stop();
    injector.getInstance(SearchService.class).stop();
    injector.getInstance(RestController.class).stop();
    injector.getInstance(TransportService.class).stop();

    for (Class<? extends LifecycleComponent> plugin : pluginsService.nodeServices()) {
        injector.getInstance(plugin).stop();
    }
    // we should stop this last since it waits for resources to get released
    // if we had scroll searchers etc or recovery going on we wait for to finish.
    injector.getInstance(IndicesService.class).stop();
    logger.info("stopped");

    return this;
}
 
Example #3
Source File: BundlePlugin.java    From elasticsearch-plugin-bundle with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Collection<Class<? extends LifecycleComponent>> getGuiceServiceClasses() {
    Collection<Class<? extends LifecycleComponent>> extra = new ArrayList<>();
    if (settings.getAsBoolean("plugins.xbib.reference.enabled", true)) {
        extra.add(ReferenceService.class);
    }
    if (settings.getAsBoolean("plugins.xbib.standardnumber.enabled", true)) {
        extra.add(StandardnumberService.class);
    }
    return extra;
}
 
Example #4
Source File: TastePlugin.java    From elasticsearch-taste with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public Collection<Class<? extends LifecycleComponent>> nodeServices() {
    final Collection<Class<? extends LifecycleComponent>> services = Lists
            .newArrayList();
    services.add(TasteService.class);
    return services;
}
 
Example #5
Source File: ReindexingPlugin.java    From elasticsearch-reindexing with Apache License 2.0 5 votes vote down vote up
/**
 * extend node level services
 * @return
 */
@Override
public Collection<Class<? extends LifecycleComponent>> nodeServices() {
    final Collection<Class<? extends LifecycleComponent>> services = new ArrayList<>();
    services.add(ReindexingService.class);
    return services;
}
 
Example #6
Source File: PluginLoader.java    From crate with Apache License 2.0 5 votes vote down vote up
Collection<Class<? extends LifecycleComponent>> getGuiceServiceClasses() {
    List<Class<? extends LifecycleComponent>> services = new ArrayList<>();
    for (Plugin plugin : plugins) {
        services.addAll(plugin.getGuiceServiceClasses());
    }
    return services;
}
 
Example #7
Source File: Node.java    From crate with Apache License 2.0 5 votes vote down vote up
private Node stop() {
    if (!lifecycle.moveToStopped()) {
        return this;
    }
    logger.info("stopping ...");

    injector.getInstance(HttpServerTransport.class).stop();

    injector.getInstance(SnapshotsService.class).stop();
    injector.getInstance(SnapshotShardsService.class).stop();
    // stop any changes happening as a result of cluster state changes
    injector.getInstance(IndicesClusterStateService.class).stop();
    // close discovery early to not react to pings anymore.
    // This can confuse other nodes and delay things - mostly if we're the master and we're running tests.
    injector.getInstance(Discovery.class).stop();
    // we close indices first, so operations won't be allowed on it
    injector.getInstance(RoutingService.class).stop();
    injector.getInstance(ClusterService.class).stop();
    injector.getInstance(NodeConnectionsService.class).stop();
    nodeService.getMonitorService().stop();
    injector.getInstance(GatewayService.class).stop();
    injector.getInstance(TransportService.class).stop();

    pluginLifecycleComponents.forEach(LifecycleComponent::stop);
    // we should stop this last since it waits for resources to get released
    // if we had scroll searchers etc or recovery going on we wait for to finish.
    injector.getInstance(IndicesService.class).stop();
    logger.info("stopped");

    return this;
}
 
Example #8
Source File: PluginsService.java    From crate with Apache License 2.0 5 votes vote down vote up
/** Returns all classes injected into guice by plugins which extend {@link LifecycleComponent}. */
public Collection<Class<? extends LifecycleComponent>> getGuiceServiceClasses() {
    List<Class<? extends LifecycleComponent>> services = new ArrayList<>();
    for (Tuple<PluginInfo, Plugin> plugin : plugins) {
        services.addAll(plugin.v2().getGuiceServiceClasses());
    }
    return services;
}
 
Example #9
Source File: PluginsService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public Collection<Class<? extends LifecycleComponent>> nodeServices() {
    List<Class<? extends LifecycleComponent>> services = new ArrayList<>();
    for (Tuple<PluginInfo, Plugin> plugin : plugins) {
        services.addAll(plugin.v2().nodeServices());
    }
    return services;
}
 
Example #10
Source File: CrateComponentLoader.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public Collection<Class<? extends LifecycleComponent>> nodeServices() {
    List<Class<? extends LifecycleComponent>> services = Lists.newArrayList();
    for (Plugin plugin : plugins) {
        services.addAll(plugin.nodeServices());
    }
    return services;
}
 
Example #11
Source File: CrateCorePlugin.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<Class<? extends LifecycleComponent>> nodeServices() {
    Collection<Class<? extends LifecycleComponent>> services = Lists.newArrayList();
    services.addAll(pluginLoader.nodeServices());
    services.addAll(crateComponentLoader.nodeServices());
    services.add(AuthService.class);
    return services;
}
 
Example #12
Source File: SQLPlugin.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<Class<? extends LifecycleComponent>> nodeServices() {
    return ImmutableList.<Class<? extends LifecycleComponent>>of(
        DecommissioningService.class,
        BulkRetryCoordinatorPool.class,
        NodeDisconnectJobMonitorService.class,
        JobContextService.class);
}
 
Example #13
Source File: PluginLoader.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public Collection<Class<? extends LifecycleComponent>> nodeServices() {
    List<Class<? extends LifecycleComponent>> services = Lists.newArrayList();
    for (Plugin plugin : plugins) {
        services.addAll(plugin.nodeServices());
        services.addAll(plugin.services());
    }
    return services;
}
 
Example #14
Source File: UDCPlugin.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<Class<? extends LifecycleComponent>> getGuiceServiceClasses() {
    if (UDCService.UDC_ENABLED_SETTING.setting().get(settings)) {
        return Collections.singletonList(UDCService.class);
    }
    return super.getGuiceServiceClasses();
}
 
Example #15
Source File: BlobPlugin.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<Class<? extends LifecycleComponent>> nodeServices() {
    // only start the service if we have a data node
    if (!settings.getAsBoolean("node.client", false)) {
        Collection<Class<? extends LifecycleComponent>> services = Lists.newArrayList();
        services.add(BlobService.class);
        return services;
    }
    return super.nodeServices();
}
 
Example #16
Source File: DynamicRankingPlugin.java    From elasticsearch-dynarank with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<Class<? extends LifecycleComponent>> getGuiceServiceClasses() {
    final Collection<Class<? extends LifecycleComponent>> services = new ArrayList<>();
    services.add(DynamicRanker.class);
    return services;
}
 
Example #17
Source File: BlobPlugin.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<Class<? extends LifecycleComponent>> getGuiceServiceClasses() {
    return List.of(BlobService.class);
}
 
Example #18
Source File: Node.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public synchronized void close() throws IOException {
    if (lifecycle.started()) {
        stop();
    }
    if (!lifecycle.moveToClosed()) {
        return;
    }

    logger.info("closing ...");
    List<Closeable> toClose = new ArrayList<>();
    StopWatch stopWatch = new StopWatch("node_close");
    toClose.add(() -> stopWatch.start("node_service"));
    toClose.add(nodeService);
    toClose.add(() -> stopWatch.stop().start("http"));
    toClose.add(injector.getInstance(HttpServerTransport.class));
    toClose.add(() -> stopWatch.stop().start("snapshot_service"));
    toClose.add(injector.getInstance(SnapshotsService.class));
    toClose.add(injector.getInstance(SnapshotShardsService.class));
    toClose.add(() -> stopWatch.stop().start("client"));
    Releasables.close(injector.getInstance(Client.class));
    toClose.add(() -> stopWatch.stop().start("indices_cluster"));
    toClose.add(injector.getInstance(IndicesClusterStateService.class));
    toClose.add(() -> stopWatch.stop().start("indices"));
    toClose.add(injector.getInstance(IndicesService.class));
    // close filter/fielddata caches after indices
    toClose.add(injector.getInstance(IndicesStore.class));
    toClose.add(() -> stopWatch.stop().start("routing"));
    toClose.add(injector.getInstance(RoutingService.class));
    toClose.add(() -> stopWatch.stop().start("cluster"));
    toClose.add(injector.getInstance(ClusterService.class));
    toClose.add(() -> stopWatch.stop().start("node_connections_service"));
    toClose.add(injector.getInstance(NodeConnectionsService.class));
    toClose.add(() -> stopWatch.stop().start("discovery"));
    toClose.add(injector.getInstance(Discovery.class));
    toClose.add(() -> stopWatch.stop().start("monitor"));
    toClose.add(nodeService.getMonitorService());
    toClose.add(() -> stopWatch.stop().start("gateway"));
    toClose.add(injector.getInstance(GatewayService.class));
    toClose.add(() -> stopWatch.stop().start("transport"));
    toClose.add(injector.getInstance(TransportService.class));

    for (LifecycleComponent plugin : pluginLifecycleComponents) {
        toClose.add(() -> stopWatch.stop().start("plugin(" + plugin.getClass().getName() + ")"));
        toClose.add(plugin);
    }
    toClose.addAll(pluginsService.filterPlugins(Plugin.class));

    toClose.add(() -> stopWatch.stop().start("thread_pool"));
    // TODO this should really use ThreadPool.terminate()
    toClose.add(() -> injector.getInstance(ThreadPool.class).shutdown());
    toClose.add(() -> {
        try {
            injector.getInstance(ThreadPool.class).awaitTermination(10, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            // ignore
        }
    });

    toClose.add(() -> stopWatch.stop().start("thread_pool_force_shutdown"));
    toClose.add(() -> injector.getInstance(ThreadPool.class).shutdownNow());
    toClose.add(() -> stopWatch.stop());


    toClose.add(injector.getInstance(NodeEnvironment.class));
    toClose.add(injector.getInstance(PageCacheRecycler.class));

    if (logger.isTraceEnabled()) {
        logger.trace("Close times for each service:\n{}", stopWatch.prettyPrint());
    }
    IOUtils.close(toClose);
    logger.info("closed");
}
 
Example #19
Source File: PluginLoaderPlugin.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<Class<? extends LifecycleComponent>> getGuiceServiceClasses() {
    return Lists2.concat(sqlPlugin.getGuiceServiceClasses(), pluginLoader.getGuiceServiceClasses());
}
 
Example #20
Source File: EnterpriseSslExtension.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<Class<? extends LifecycleComponent>> getGuiceServiceClasses() {
    return Collections.singletonList(SslContextProviderService.class);
}
 
Example #21
Source File: EnterpriseLicenseExtension.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<Class<? extends LifecycleComponent>> getGuiceServiceClasses() {
    return Collections.singletonList(EnterpriseLicenseComponent.class);
}
 
Example #22
Source File: SynonymPlugin.java    From elasticsearch-analysis-synonym with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<Class<? extends LifecycleComponent>> getGuiceServiceClasses() {
    return singletonList(SynonymAnalysisService.class);
}
 
Example #23
Source File: XmlPlugin.java    From elasticsearch-xml with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<Class<? extends LifecycleComponent>> nodeServices() {
    Collection<Class<? extends LifecycleComponent>> services = new ArrayList<>();
    services.add(XmlService.class);
    return services;
}
 
Example #24
Source File: OpenShiftElasticSearchPlugin.java    From openshift-elasticsearch-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<Class<? extends LifecycleComponent>> getGuiceServiceClasses() {
    Collection<Class<? extends LifecycleComponent>> serviceClasses = sgPlugin.getGuiceServiceClasses();
    return serviceClasses;
}
 
Example #25
Source File: DynamicSynonymPlugin.java    From elasticsearch-analysis-dynamic-synonym with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<Class<? extends LifecycleComponent>> getGuiceServiceClasses() {
    List<Class<DynamicSynonymGuiceService>> a = singletonList(DynamicSynonymGuiceService.class);
    Object b = a;
    return (Collection<Class<? extends LifecycleComponent>>) b;
}
 
Example #26
Source File: Plugin.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
/**
 * Node level services that will be automatically started/stopped/closed.
 */
public Collection<Class<? extends LifecycleComponent>> nodeServices() {
    return Collections.emptyList();
}
 
Example #27
Source File: Node.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
/**
 * Start the node. If the node is already started, this method is no-op.
 */
public Node start() {
    if (!lifecycle.moveToStarted()) {
        return this;
    }

    ESLogger logger = Loggers.getLogger(Node.class, settings.get("name"));
    logger.info("starting ...");
    // hack around dependency injection problem (for now...)
    injector.getInstance(Discovery.class).setRoutingService(injector.getInstance(RoutingService.class));
    for (Class<? extends LifecycleComponent> plugin : pluginsService.nodeServices()) {
        injector.getInstance(plugin).start();
    }

    injector.getInstance(MappingUpdatedAction.class).setClient(client);
    injector.getInstance(IndicesService.class).start();
    injector.getInstance(IndexingMemoryController.class).start();
    injector.getInstance(IndicesClusterStateService.class).start();
    injector.getInstance(IndicesTTLService.class).start();
    injector.getInstance(SnapshotsService.class).start();
    injector.getInstance(SnapshotShardsService.class).start();
    injector.getInstance(RoutingService.class).start();
    injector.getInstance(SearchService.class).start();
    injector.getInstance(MonitorService.class).start();
    injector.getInstance(RestController.class).start();

    // TODO hack around circular dependencies problems
    injector.getInstance(GatewayAllocator.class).setReallocation(injector.getInstance(ClusterService.class), injector.getInstance(RoutingService.class));

    injector.getInstance(ResourceWatcherService.class).start();
    injector.getInstance(GatewayService.class).start();
    injector.getInstance(TenantManagementService.class).start();

    // Start the transport service now so the publish address will be added to the local disco node in ClusterService
    TransportService transportService = injector.getInstance(TransportService.class);
    transportService.start();
    injector.getInstance(ClusterService.class).start();

    // start after cluster service so the local disco is known
    DiscoveryService discoService = injector.getInstance(DiscoveryService.class).start();


    transportService.acceptIncomingRequests();
    discoService.joinClusterAndWaitForInitialState();

    if (settings.getAsBoolean("http.enabled", true)) {
        injector.getInstance(HttpServer.class).start();
    }
    injector.getInstance(TribeService.class).start();
    if (settings.getAsBoolean("node.portsfile", false)) {
        if (settings.getAsBoolean("http.enabled", true)) {
            HttpServerTransport http = injector.getInstance(HttpServerTransport.class);
            writePortsFile("http", http.boundAddress());
        }
        TransportService transport = injector.getInstance(TransportService.class);
        writePortsFile("transport", transport.boundAddress());
    }
    logger.info("started");

    return this;
}
 
Example #28
Source File: AbstractPlugin.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<Class<? extends LifecycleComponent>> services() {
    return ImmutableList.of();
}
 
Example #29
Source File: AbstractPlugin.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
/**
 * Defaults to return an empty list.
 */
@Override
public Collection<Class<? extends LifecycleComponent>> nodeServices() {
    return ImmutableList.of();
}
 
Example #30
Source File: Plugin.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Node level services that will be automatically started/stopped/closed.
 */
Collection<Class<? extends LifecycleComponent>> nodeServices();