Search in sources :

Example 1 with Plugin

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

the class InternalTestCluster method buildNode.

/**
     * builds a new node
     *
     * @param nodeId                the node internal id (see {@link NodeAndClient#nodeAndClientId()}
     * @param seed                  the node's random seed
     * @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 defaultMinMasterNodes min_master_nodes value to use if min_master_nodes is auto managed
     */
private NodeAndClient buildNode(int nodeId, long seed, Settings settings, boolean reuseExisting, int defaultMinMasterNodes) {
    assert Thread.holdsLock(this);
    ensureOpen();
    settings = getSettings(nodeId, seed, settings);
    Collection<Class<? extends Plugin>> plugins = getPlugins();
    String name = buildNodeName(nodeId, settings);
    if (reuseExisting && nodes.containsKey(name)) {
        return nodes.get(name);
    } else {
        assert reuseExisting == true || nodes.containsKey(name) == false : "node name [" + name + "] already exists but not allowed to use it";
    }
    Settings.Builder finalSettings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), // allow overriding path.home
    baseDir).put(settings).put("node.name", name).put(NodeEnvironment.NODE_ID_SEED_SETTING.getKey(), seed);
    if (autoManageMinMasterNodes) {
        assert finalSettings.get(DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.getKey()) == null : "min master nodes may not be set when auto managed";
        finalSettings.put(ZenDiscovery.MASTER_ELECTION_WAIT_FOR_JOINS_TIMEOUT_SETTING.getKey(), "5s").put(DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.getKey(), defaultMinMasterNodes);
    } else if (finalSettings.get(DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.getKey()) == null) {
        throw new IllegalArgumentException(DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.getKey() + " must be configured");
    }
    MockNode node = new MockNode(finalSettings.build(), plugins);
    return new NodeAndClient(name, node, nodeId);
}
Also used : Builder(org.elasticsearch.common.settings.Settings.Builder) MockNode(org.elasticsearch.node.MockNode) RecoverySettings(org.elasticsearch.indices.recovery.RecoverySettings) TransportSettings(org.elasticsearch.transport.TransportSettings) DiskThresholdSettings(org.elasticsearch.cluster.routing.allocation.DiskThresholdSettings) Settings(org.elasticsearch.common.settings.Settings) Plugin(org.elasticsearch.plugins.Plugin)

Example 2 with Plugin

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

the class ESSingleNodeTestCase method newNode.

private Node newNode() {
    final Path tempDir = createTempDir();
    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.name", "node_s_0").put("script.inline", "true").put("script.stored", "true").put(ScriptService.SCRIPT_MAX_COMPILATIONS_PER_MINUTE.getKey(), 1000).put(EsExecutors.PROCESSORS_SETTING.getKey(), // limit the number of threads created
    1).put(NetworkModule.HTTP_ENABLED.getKey(), false).put("transport.type", MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME).put(Node.NODE_DATA_SETTING.getKey(), true).put(NodeEnvironment.NODE_ID_SEED_SETTING.getKey(), random().nextLong()).put(// allow test cases to provide their own settings or override these
    nodeSettings()).build();
    Collection<Class<? extends Plugin>> plugins = getPlugins();
    if (plugins.contains(MockTcpTransportPlugin.class) == false) {
        plugins = new ArrayList<>(plugins);
        plugins.add(MockTcpTransportPlugin.class);
    }
    if (plugins.contains(TestZenDiscovery.TestPlugin.class) == false) {
        plugins = new ArrayList<>(plugins);
        plugins.add(TestZenDiscovery.TestPlugin.class);
    }
    Node build = new MockNode(settings, plugins);
    try {
        build.start();
    } catch (NodeValidationException e) {
        throw new RuntimeException(e);
    }
    return build;
}
Also used : Path(java.nio.file.Path) MockTcpTransportPlugin(org.elasticsearch.transport.MockTcpTransportPlugin) Node(org.elasticsearch.node.Node) MockNode(org.elasticsearch.node.MockNode) MockNode(org.elasticsearch.node.MockNode) NodeValidationException(org.elasticsearch.node.NodeValidationException) BeforeClass(org.junit.BeforeClass) AfterClass(org.junit.AfterClass) TestZenDiscovery(org.elasticsearch.test.discovery.TestZenDiscovery) Settings(org.elasticsearch.common.settings.Settings) MockTcpTransportPlugin(org.elasticsearch.transport.MockTcpTransportPlugin) Plugin(org.elasticsearch.plugins.Plugin)

Example 3 with Plugin

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

the class TribeUnitTests method createTribes.

@BeforeClass
public static void createTribes() throws NodeValidationException {
    Settings baseSettings = Settings.builder().put(NetworkModule.HTTP_ENABLED.getKey(), false).put("transport.type", MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).put(NodeEnvironment.MAX_LOCAL_STORAGE_NODES_SETTING.getKey(), 2).build();
    final List<Class<? extends Plugin>> mockPlugins = Arrays.asList(MockTcpTransportPlugin.class, TestZenDiscovery.TestPlugin.class);
    tribe1 = new MockNode(Settings.builder().put(baseSettings).put("cluster.name", "tribe1").put("node.name", "tribe1_node").put(NodeEnvironment.NODE_ID_SEED_SETTING.getKey(), random().nextLong()).build(), mockPlugins).start();
    tribe2 = new MockNode(Settings.builder().put(baseSettings).put("cluster.name", "tribe2").put("node.name", "tribe2_node").put(NodeEnvironment.NODE_ID_SEED_SETTING.getKey(), random().nextLong()).build(), mockPlugins).start();
}
Also used : BeforeClass(org.junit.BeforeClass) AfterClass(org.junit.AfterClass) MockNode(org.elasticsearch.node.MockNode) TestZenDiscovery(org.elasticsearch.test.discovery.TestZenDiscovery) Settings(org.elasticsearch.common.settings.Settings) MockTcpTransportPlugin(org.elasticsearch.transport.MockTcpTransportPlugin) Plugin(org.elasticsearch.plugins.Plugin) BeforeClass(org.junit.BeforeClass)

Example 4 with Plugin

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

the class ESSmokeClientTestCase method startClient.

private static Client startClient(Path tempDir, TransportAddress... transportAddresses) {
    Settings.Builder builder = Settings.builder().put("node.name", "qa_smoke_client_" + counter.getAndIncrement()).put("client.transport.ignore_cluster_name", true).put(Environment.PATH_HOME_SETTING.getKey(), tempDir);
    final Collection<Class<? extends Plugin>> plugins;
    if (random().nextBoolean()) {
        builder.put(NetworkModule.TRANSPORT_TYPE_KEY, MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME);
        plugins = Collections.singleton(MockTcpTransportPlugin.class);
    } else {
        plugins = Collections.emptyList();
    }
    TransportClient client = new PreBuiltTransportClient(builder.build(), plugins).addTransportAddresses(transportAddresses);
    logger.info("--> Elasticsearch Java TransportClient started");
    Exception clientException = null;
    try {
        ClusterHealthResponse health = client.admin().cluster().prepareHealth().get();
        logger.info("--> connected to [{}] cluster which is running [{}] node(s).", health.getClusterName(), health.getNumberOfNodes());
    } catch (Exception e) {
        clientException = e;
    }
    assumeNoException("Sounds like your cluster is not running at " + clusterAddresses, clientException);
    return client;
}
Also used : MockTcpTransportPlugin(org.elasticsearch.transport.MockTcpTransportPlugin) TransportClient(org.elasticsearch.client.transport.TransportClient) PreBuiltTransportClient(org.elasticsearch.transport.client.PreBuiltTransportClient) PreBuiltTransportClient(org.elasticsearch.transport.client.PreBuiltTransportClient) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) BeforeClass(org.junit.BeforeClass) AfterClass(org.junit.AfterClass) Settings(org.elasticsearch.common.settings.Settings) IOException(java.io.IOException) MockTcpTransportPlugin(org.elasticsearch.transport.MockTcpTransportPlugin) Plugin(org.elasticsearch.plugins.Plugin)

Example 5 with Plugin

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

the class InternalTestClusterTests method testTwoNodeCluster.

public void testTwoNodeCluster() throws Exception {
    String transportClient = getTestTransportType();
    NodeConfigurationSource nodeConfigurationSource = new NodeConfigurationSource() {

        @Override
        public Settings nodeSettings(int nodeOrdinal) {
            return Settings.builder().put(NetworkModule.TRANSPORT_TYPE_KEY, getTestTransportType()).putList(DISCOVERY_SEED_PROVIDERS_SETTING.getKey(), "file").putList(SettingsBasedSeedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING.getKey()).build();
        }

        @Override
        public Path nodeConfigPath(int nodeOrdinal) {
            return null;
        }

        @Override
        public Settings transportClientSettings() {
            return Settings.builder().put(NetworkModule.TRANSPORT_TYPE_KEY, transportClient).build();
        }
    };
    String nodePrefix = "test";
    Path baseDir = createTempDir();
    List<Class<? extends Plugin>> plugins = new ArrayList<>(mockPlugins());
    plugins.add(NodeAttrCheckPlugin.class);
    InternalTestCluster cluster = new InternalTestCluster(randomLong(), baseDir, false, true, 2, 2, "test", nodeConfigurationSource, 0, nodePrefix, plugins);
    try {
        cluster.beforeTest(random());
        switch(randomInt(2)) {
            case 0:
                cluster.stopRandomDataNode();
                cluster.startNode();
                break;
            case 1:
                cluster.rollingRestart(InternalTestCluster.EMPTY_CALLBACK);
                break;
            case 2:
                cluster.fullRestart();
                break;
        }
    } finally {
        cluster.close();
    }
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) InternalTestCluster(org.elasticsearch.test.InternalTestCluster) NodeConfigurationSource(org.elasticsearch.test.NodeConfigurationSource) 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