Search in sources :

Example 1 with MockNode

use of org.elasticsearch.node.MockNode in project elasticsearch by elastic.

the class AzureRepositoryF method main.

public static void main(String[] args) throws Throwable {
    Settings.Builder settings = Settings.builder();
    settings.put("http.cors.enabled", "true");
    settings.put("http.cors.allow-origin", "*");
    settings.put("cluster.name", AzureRepositoryF.class.getSimpleName());
    // Example for azure repo settings
    // settings.put("cloud.azure.storage.my_account1.account", "account_name");
    // settings.put("cloud.azure.storage.my_account1.key", "account_key");
    // settings.put("cloud.azure.storage.my_account1.default", true);
    // settings.put("cloud.azure.storage.my_account2.account", "account_name");
    // settings.put("cloud.azure.storage.my_account2.key", "account_key_secondary");
    final CountDownLatch latch = new CountDownLatch(1);
    final Node node = new MockNode(settings.build(), Collections.singletonList(AzureRepositoryPlugin.class));
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            try {
                IOUtils.close(node);
            } catch (IOException e) {
                throw new ElasticsearchException(e);
            } finally {
                latch.countDown();
            }
        }
    });
    node.start();
    latch.await();
}
Also used : MockNode(org.elasticsearch.node.MockNode) Node(org.elasticsearch.node.Node) AzureRepositoryPlugin(org.elasticsearch.plugin.repository.azure.AzureRepositoryPlugin) MockNode(org.elasticsearch.node.MockNode) IOException(java.io.IOException) ElasticsearchException(org.elasticsearch.ElasticsearchException) CountDownLatch(java.util.concurrent.CountDownLatch) Settings(org.elasticsearch.common.settings.Settings)

Example 2 with MockNode

use of org.elasticsearch.node.MockNode 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 3 with MockNode

use of org.elasticsearch.node.MockNode 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 4 with MockNode

use of org.elasticsearch.node.MockNode 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 5 with MockNode

use of org.elasticsearch.node.MockNode in project elasticsearch by elastic.

the class TransportClientIT method testNodeVersionIsUpdated.

public void testNodeVersionIsUpdated() throws IOException, NodeValidationException {
    TransportClient client = (TransportClient) internalCluster().client();
    try (Node node = new MockNode(Settings.builder().put(internalCluster().getDefaultSettings()).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).put("node.name", "testNodeVersionIsUpdated").put("transport.type", MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME).put(NetworkModule.HTTP_ENABLED.getKey(), false).put(Node.NODE_DATA_SETTING.getKey(), false).put("cluster.name", "foobar").build(), Arrays.asList(MockTcpTransportPlugin.class, TestZenDiscovery.TestPlugin.class)).start()) {
        TransportAddress transportAddress = node.injector().getInstance(TransportService.class).boundAddress().publishAddress();
        client.addTransportAddress(transportAddress);
        // since we force transport clients there has to be one node started that we connect to.
        assertThat(client.connectedNodes().size(), greaterThanOrEqualTo(1));
        // connected nodes have updated version
        for (DiscoveryNode discoveryNode : client.connectedNodes()) {
            assertThat(discoveryNode.getVersion(), equalTo(Version.CURRENT));
        }
        for (DiscoveryNode discoveryNode : client.listedNodes()) {
            assertThat(discoveryNode.getId(), startsWith("#transport#-"));
            assertThat(discoveryNode.getVersion(), equalTo(Version.CURRENT.minimumCompatibilityVersion()));
        }
        assertThat(client.filteredNodes().size(), equalTo(1));
        for (DiscoveryNode discoveryNode : client.filteredNodes()) {
            assertThat(discoveryNode.getVersion(), equalTo(Version.CURRENT.minimumCompatibilityVersion()));
        }
    }
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) MockTransportClient(org.elasticsearch.transport.MockTransportClient) TransportAddress(org.elasticsearch.common.transport.TransportAddress) MockNode(org.elasticsearch.node.MockNode) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Node(org.elasticsearch.node.Node) MockNode(org.elasticsearch.node.MockNode) TestZenDiscovery(org.elasticsearch.test.discovery.TestZenDiscovery)

Aggregations

MockNode (org.elasticsearch.node.MockNode)7 Settings (org.elasticsearch.common.settings.Settings)6 Node (org.elasticsearch.node.Node)5 TestZenDiscovery (org.elasticsearch.test.discovery.TestZenDiscovery)4 Plugin (org.elasticsearch.plugins.Plugin)3 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)2 MockTcpTransportPlugin (org.elasticsearch.transport.MockTcpTransportPlugin)2 AfterClass (org.junit.AfterClass)2 BeforeClass (org.junit.BeforeClass)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 Client (org.elasticsearch.client.Client)1 AbstractClient (org.elasticsearch.client.support.AbstractClient)1 ClusterState (org.elasticsearch.cluster.ClusterState)1 DiskThresholdSettings (org.elasticsearch.cluster.routing.allocation.DiskThresholdSettings)1 Builder (org.elasticsearch.common.settings.Settings.Builder)1 TransportAddress (org.elasticsearch.common.transport.TransportAddress)1 RecoverySettings (org.elasticsearch.indices.recovery.RecoverySettings)1