Search in sources :

Example 26 with DiscoveryNode

use of org.elasticsearch.cluster.node.DiscoveryNode in project elasticsearch by elastic.

the class Ec2DiscoveryTests method testFilterByMultipleTags.

public void testFilterByMultipleTags() throws InterruptedException {
    int nodes = randomIntBetween(5, 10);
    Settings nodeSettings = Settings.builder().putArray(DISCOVERY_EC2.TAG_SETTING.getKey() + "stage", "prod", "preprod").build();
    int prodInstances = 0;
    List<List<Tag>> tagsList = new ArrayList<>();
    for (int node = 0; node < nodes; node++) {
        List<Tag> tags = new ArrayList<>();
        if (randomBoolean()) {
            tags.add(new Tag("stage", "prod"));
            if (randomBoolean()) {
                tags.add(new Tag("stage", "preprod"));
                prodInstances++;
            }
        } else {
            tags.add(new Tag("stage", "dev"));
            if (randomBoolean()) {
                tags.add(new Tag("stage", "preprod"));
            }
        }
        tagsList.add(tags);
    }
    logger.info("started [{}] instances with [{}] stage=prod tag", nodes, prodInstances);
    List<DiscoveryNode> discoveryNodes = buildDynamicNodes(nodeSettings, nodes, tagsList);
    assertThat(discoveryNodes, hasSize(prodInstances));
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Tag(com.amazonaws.services.ec2.model.Tag) Settings(org.elasticsearch.common.settings.Settings)

Example 27 with DiscoveryNode

use of org.elasticsearch.cluster.node.DiscoveryNode in project elasticsearch by elastic.

the class Ec2DiscoveryTests method testPrivateDns.

public void testPrivateDns() throws InterruptedException {
    int nodes = randomInt(10);
    for (int i = 0; i < nodes; i++) {
        String instanceId = "node" + (i + 1);
        poorMansDNS.put(AmazonEC2Mock.PREFIX_PRIVATE_DNS + instanceId + AmazonEC2Mock.SUFFIX_PRIVATE_DNS, buildNewFakeTransportAddress());
    }
    Settings nodeSettings = Settings.builder().put(DISCOVERY_EC2.HOST_TYPE_SETTING.getKey(), "private_dns").build();
    List<DiscoveryNode> discoveryNodes = buildDynamicNodes(nodeSettings, nodes);
    assertThat(discoveryNodes, hasSize(nodes));
    // We check that we are using here expected address
    int node = 1;
    for (DiscoveryNode discoveryNode : discoveryNodes) {
        String instanceId = "node" + node++;
        TransportAddress address = discoveryNode.getAddress();
        TransportAddress expected = poorMansDNS.get(AmazonEC2Mock.PREFIX_PRIVATE_DNS + instanceId + AmazonEC2Mock.SUFFIX_PRIVATE_DNS);
        assertEquals(address, expected);
    }
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) TransportAddress(org.elasticsearch.common.transport.TransportAddress) Matchers.containsString(org.hamcrest.Matchers.containsString) Settings(org.elasticsearch.common.settings.Settings)

Example 28 with DiscoveryNode

use of org.elasticsearch.cluster.node.DiscoveryNode in project elasticsearch by elastic.

the class Ec2DiscoveryTests method buildDynamicNodes.

protected List<DiscoveryNode> buildDynamicNodes(Settings nodeSettings, int nodes, List<List<Tag>> tagsList) {
    AwsEc2Service awsEc2Service = new AwsEc2ServiceMock(nodeSettings, nodes, tagsList);
    AwsEc2UnicastHostsProvider provider = new AwsEc2UnicastHostsProvider(nodeSettings, transportService, awsEc2Service);
    List<DiscoveryNode> discoveryNodes = provider.buildDynamicNodes();
    logger.debug("--> nodes found: {}", discoveryNodes);
    return discoveryNodes;
}
Also used : AwsEc2Service(org.elasticsearch.cloud.aws.AwsEc2Service) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode)

Example 29 with DiscoveryNode

use of org.elasticsearch.cluster.node.DiscoveryNode in project elasticsearch by elastic.

the class Ec2DiscoveryTests method testPrivateIp.

public void testPrivateIp() throws InterruptedException {
    int nodes = randomInt(10);
    for (int i = 0; i < nodes; i++) {
        poorMansDNS.put(AmazonEC2Mock.PREFIX_PRIVATE_IP + (i + 1), buildNewFakeTransportAddress());
    }
    Settings nodeSettings = Settings.builder().put(DISCOVERY_EC2.HOST_TYPE_SETTING.getKey(), "private_ip").build();
    List<DiscoveryNode> discoveryNodes = buildDynamicNodes(nodeSettings, nodes);
    assertThat(discoveryNodes, hasSize(nodes));
    // We check that we are using here expected address
    int node = 1;
    for (DiscoveryNode discoveryNode : discoveryNodes) {
        TransportAddress address = discoveryNode.getAddress();
        TransportAddress expected = poorMansDNS.get(AmazonEC2Mock.PREFIX_PRIVATE_IP + node++);
        assertEquals(address, expected);
    }
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) TransportAddress(org.elasticsearch.common.transport.TransportAddress) Settings(org.elasticsearch.common.settings.Settings)

Example 30 with DiscoveryNode

use of org.elasticsearch.cluster.node.DiscoveryNode in project elasticsearch by elastic.

the class Ec2DiscoveryTests method testDefaultSettings.

public void testDefaultSettings() throws InterruptedException {
    int nodes = randomInt(10);
    Settings nodeSettings = Settings.builder().build();
    List<DiscoveryNode> discoveryNodes = buildDynamicNodes(nodeSettings, nodes);
    assertThat(discoveryNodes, hasSize(nodes));
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Settings(org.elasticsearch.common.settings.Settings)

Aggregations

DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)352 ClusterState (org.elasticsearch.cluster.ClusterState)83 ArrayList (java.util.ArrayList)82 Settings (org.elasticsearch.common.settings.Settings)79 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)74 IOException (java.io.IOException)69 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)52 HashMap (java.util.HashMap)45 ShardId (org.elasticsearch.index.shard.ShardId)45 HashSet (java.util.HashSet)43 List (java.util.List)41 TransportAddress (org.elasticsearch.common.transport.TransportAddress)41 CountDownLatch (java.util.concurrent.CountDownLatch)39 MockTransportService (org.elasticsearch.test.transport.MockTransportService)39 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)37 Map (java.util.Map)35 ExecutionException (java.util.concurrent.ExecutionException)35 Version (org.elasticsearch.Version)35 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)31 ClusterName (org.elasticsearch.cluster.ClusterName)30