Search in sources :

Example 11 with Plugin

use of org.elasticsearch.plugins.Plugin in project crate by crate.

the class Node method close.

// During concurrent close() calls we want to make sure that all of them return after the node has completed it's shutdown cycle.
// If not, the hook that is added in Bootstrap#setup() will be useless:
// close() might not be executed, in case another (for example api) call to close() has already set some lifecycles to stopped.
// In this case the process will be terminated even if the first call to close() has not finished yet.
@Override
public synchronized void close() throws IOException {
    synchronized (lifecycle) {
        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(injector.getInstance(PeerRecoverySourceService.class));
    toClose.add(() -> stopWatch.stop().start("routing"));
    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));
    toClose.add(() -> stopWatch.stop().start("gateway_meta_state"));
    toClose.add(injector.getInstance(GatewayMetaState.class));
    toClose.add(() -> stopWatch.stop().start("node_environment"));
    toClose.add(injector.getInstance(NodeEnvironment.class));
    toClose.add(() -> stopWatch.stop().start("decommission_service"));
    toClose.add(injector.getInstance(DecommissioningService.class));
    toClose.add(() -> stopWatch.stop().start("node_disconnect_job_monitor_service"));
    toClose.add(injector.getInstance(NodeDisconnectJobMonitorService.class));
    toClose.add(() -> stopWatch.stop().start("jobs_log_service"));
    toClose.add(injector.getInstance(JobsLogService.class));
    toClose.add(() -> stopWatch.stop().start("postgres_netty"));
    toClose.add(injector.getInstance(PostgresNetty.class));
    toClose.add(() -> stopWatch.stop().start("tasks_service"));
    toClose.add(injector.getInstance(TasksService.class));
    toClose.add(() -> stopWatch.stop().start("schemas"));
    toClose.add(injector.getInstance(Schemas.class));
    toClose.add(() -> stopWatch.stop().start("array_mapper_service"));
    toClose.add(injector.getInstance(ArrayMapperService.class));
    toClose.add(() -> stopWatch.stop().start("dangling_artifacts_service"));
    toClose.add(injector.getInstance(DanglingArtifactsService.class));
    toClose.add(() -> stopWatch.stop().start("ssl_context_provider_service"));
    toClose.add(injector.getInstance(SslContextProviderService.class));
    toClose.add(() -> stopWatch.stop().start("blob_service"));
    toClose.add(injector.getInstance(BlobService.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"));
    toClose.add(() -> injector.getInstance(ThreadPool.class).shutdown());
    // Don't call shutdownNow here, it might break ongoing operations on Lucene indices.
    // See https://issues.apache.org/jira/browse/LUCENE-7248. We call shutdownNow in
    // awaitClose if the node doesn't finish closing within the specified time.
    toClose.add(() -> stopWatch.stop());
    if (logger.isTraceEnabled()) {
        logger.trace("Close times for each service:\n{}", stopWatch.prettyPrint());
    }
    IOUtils.close(toClose);
    logger.info("closed");
}
Also used : SnapshotsService(org.elasticsearch.snapshots.SnapshotsService) SnapshotShardsService(org.elasticsearch.snapshots.SnapshotShardsService) NodeConnectionsService(org.elasticsearch.cluster.NodeConnectionsService) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) Closeable(java.io.Closeable) IndicesStore(org.elasticsearch.indices.store.IndicesStore) SslContextProviderService(io.crate.protocols.ssl.SslContextProviderService) ArrayList(java.util.ArrayList) TasksService(io.crate.execution.jobs.TasksService) HttpServerTransport(org.elasticsearch.http.HttpServerTransport) DecommissioningService(io.crate.cluster.gracefulstop.DecommissioningService) GatewayMetaState(org.elasticsearch.gateway.GatewayMetaState) PostgresNetty(io.crate.protocols.postgres.PostgresNetty) IndicesClusterStateService(org.elasticsearch.indices.cluster.IndicesClusterStateService) LifecycleComponent(org.elasticsearch.common.component.LifecycleComponent) PeerRecoverySourceService(org.elasticsearch.indices.recovery.PeerRecoverySourceService) Client(org.elasticsearch.client.Client) NodeClient(org.elasticsearch.client.node.NodeClient) DanglingArtifactsService(io.crate.metadata.DanglingArtifactsService) JobsLogService(io.crate.execution.engine.collect.stats.JobsLogService) Discovery(org.elasticsearch.discovery.Discovery) IndicesService(org.elasticsearch.indices.IndicesService) Schemas(io.crate.metadata.Schemas) StopWatch(org.elasticsearch.common.StopWatch) GatewayService(org.elasticsearch.gateway.GatewayService) ClusterService(org.elasticsearch.cluster.service.ClusterService) TransportService(org.elasticsearch.transport.TransportService) NodeDisconnectJobMonitorService(io.crate.execution.jobs.transport.NodeDisconnectJobMonitorService) BlobService(io.crate.blob.BlobService) ArrayMapperService(io.crate.lucene.ArrayMapperService) ClusterPlugin(org.elasticsearch.plugins.ClusterPlugin) IndexStorePlugin(org.elasticsearch.plugins.IndexStorePlugin) RepositoryPlugin(org.elasticsearch.plugins.RepositoryPlugin) NetworkPlugin(org.elasticsearch.plugins.NetworkPlugin) Plugin(org.elasticsearch.plugins.Plugin) AnalysisPlugin(org.elasticsearch.plugins.AnalysisPlugin) EnginePlugin(org.elasticsearch.plugins.EnginePlugin) CopyPlugin(io.crate.plugin.CopyPlugin) DiscoveryPlugin(org.elasticsearch.plugins.DiscoveryPlugin) MapperPlugin(org.elasticsearch.plugins.MapperPlugin) ActionPlugin(org.elasticsearch.plugins.ActionPlugin)

Example 12 with Plugin

use of org.elasticsearch.plugins.Plugin in project crate by crate.

the class IndicesServiceCloseTests method startNode.

private Node startNode() throws NodeValidationException {
    final Path tempDir = createTempDir();
    String nodeName = "node_s_0";
    Settings settings = Settings.builder().put(ClusterName.CLUSTER_NAME_SETTING.getKey(), InternalTestCluster.clusterName("single-node-cluster", random().nextLong())).put(Environment.PATH_HOME_SETTING.getKey(), tempDir).put(Environment.PATH_REPO_SETTING.getKey(), tempDir.resolve("repo")).put(Environment.PATH_SHARED_DATA_SETTING.getKey(), createTempDir().getParent()).put(Node.NODE_NAME_SETTING.getKey(), nodeName).put(EsExecutors.PROCESSORS_SETTING.getKey(), // limit the number of threads created
    1).put("transport.type", getTestTransportType()).put(Node.NODE_DATA_SETTING.getKey(), true).put(NodeEnvironment.NODE_ID_SEED_SETTING.getKey(), random().nextLong()).put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK_SETTING.getKey(), "1b").put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK_SETTING.getKey(), "1b").put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_DISK_FLOOD_STAGE_WATERMARK_SETTING.getKey(), "1b").putList(// empty list disables a port scan for other nodes
    DISCOVERY_SEED_HOSTS_SETTING.getKey()).putList(INITIAL_MASTER_NODES_SETTING.getKey(), nodeName).build();
    Collection<Class<? extends Plugin>> plugins = Arrays.asList(MockHttpTransport.TestPlugin.class, Netty4Plugin.class);
    Node node = new MockNode(settings, plugins, true);
    node.start();
    return node;
}
Also used : Path(java.nio.file.Path) MockHttpTransport(org.elasticsearch.test.MockHttpTransport) Node(org.elasticsearch.node.Node) MockNode(org.elasticsearch.node.MockNode) MockNode(org.elasticsearch.node.MockNode) DiskThresholdSettings(org.elasticsearch.cluster.routing.allocation.DiskThresholdSettings) Settings(org.elasticsearch.common.settings.Settings) Plugin(org.elasticsearch.plugins.Plugin) Netty4Plugin(org.elasticsearch.transport.Netty4Plugin)

Example 13 with Plugin

use of org.elasticsearch.plugins.Plugin in project crate by crate.

the class InternalTestCluster method buildNode.

/**
 * builds a new node
 *
 * @param nodeId                    node ordinal
 * @param settings                  the settings to use
 * @param reuseExisting             if a node with the same name is already part of {@link #nodes}, no new node will be built and
 *                                  the method will return the existing one
 * @param onTransportServiceStarted callback to run when transport service is started
 */
private synchronized NodeAndClient buildNode(int nodeId, Settings settings, boolean reuseExisting, Runnable onTransportServiceStarted) {
    assert Thread.holdsLock(this);
    ensureOpen();
    Collection<Class<? extends Plugin>> plugins = getPlugins();
    String name = settings.get("node.name");
    final NodeAndClient nodeAndClient = nodes.get(name);
    if (reuseExisting && nodeAndClient != null) {
        // reusing an existing node implies its transport service already started
        onTransportServiceStarted.run();
        return nodeAndClient;
    }
    assert reuseExisting == true || nodeAndClient == null : "node name [" + name + "] already exists but not allowed to use it";
    MockNode node = new MockNode(settings, plugins, nodeConfigurationSource.nodeConfigPath(nodeId), forbidPrivateIndexSettings);
    node.injector().getInstance(TransportService.class).addLifecycleListener(new LifecycleListener() {

        @Override
        public void afterStart() {
            onTransportServiceStarted.run();
        }
    });
    return new NodeAndClient(name, node, settings, nodeId);
}
Also used : TransportService(org.elasticsearch.transport.TransportService) MockTransportService(org.elasticsearch.test.transport.MockTransportService) MockNode(org.elasticsearch.node.MockNode) LifecycleListener(org.elasticsearch.common.component.LifecycleListener) Plugin(org.elasticsearch.plugins.Plugin)

Aggregations

Plugin (org.elasticsearch.plugins.Plugin)13 Settings (org.elasticsearch.common.settings.Settings)8 MockTcpTransportPlugin (org.elasticsearch.transport.MockTcpTransportPlugin)6 ArrayList (java.util.ArrayList)5 MockNode (org.elasticsearch.node.MockNode)5 Path (java.nio.file.Path)4 TransportService (org.elasticsearch.transport.TransportService)4 Closeable (java.io.Closeable)3 Client (org.elasticsearch.client.Client)3 LifecycleComponent (org.elasticsearch.common.component.LifecycleComponent)3 BigArrays (org.elasticsearch.common.util.BigArrays)3 Node (org.elasticsearch.node.Node)3 ActionPlugin (org.elasticsearch.plugins.ActionPlugin)3 NetworkPlugin (org.elasticsearch.plugins.NetworkPlugin)3 InternalTestCluster (org.elasticsearch.test.InternalTestCluster)3 NodeConfigurationSource (org.elasticsearch.test.NodeConfigurationSource)3 AfterClass (org.junit.AfterClass)3 BeforeClass (org.junit.BeforeClass)3 NodeClient (org.elasticsearch.client.node.NodeClient)2 NodeConnectionsService (org.elasticsearch.cluster.NodeConnectionsService)2