Search in sources :

Example 76 with TransportAddress

use of org.opensearch.common.transport.TransportAddress in project OpenSearch by opensearch-project.

the class Ec2DiscoveryTests method testFilterByTags.

public void testFilterByTags() throws InterruptedException {
    int nodes = randomIntBetween(5, 10);
    Settings nodeSettings = Settings.builder().put(AwsEc2Service.TAG_SETTING.getKey() + "stage", "prod").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"));
            prodInstances++;
        } else {
            tags.add(new Tag("stage", "dev"));
        }
        tagsList.add(tags);
    }
    logger.info("started [{}] instances with [{}] stage=prod tag", nodes, prodInstances);
    List<TransportAddress> dynamicHosts = buildDynamicHosts(nodeSettings, nodes, tagsList);
    assertThat(dynamicHosts, hasSize(prodInstances));
}
Also used : TransportAddress(org.opensearch.common.transport.TransportAddress) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Tag(com.amazonaws.services.ec2.model.Tag) Settings(org.opensearch.common.settings.Settings)

Example 77 with TransportAddress

use of org.opensearch.common.transport.TransportAddress in project OpenSearch by opensearch-project.

the class Ec2DiscoveryTests method testPublicIp.

public void testPublicIp() throws InterruptedException {
    int nodes = randomInt(10);
    for (int i = 0; i < nodes; i++) {
        poorMansDNS.put(PREFIX_PUBLIC_IP + (i + 1), buildNewFakeTransportAddress());
    }
    Settings nodeSettings = Settings.builder().put(AwsEc2Service.HOST_TYPE_SETTING.getKey(), "public_ip").build();
    List<TransportAddress> dynamicHosts = buildDynamicHosts(nodeSettings, nodes);
    assertThat(dynamicHosts, hasSize(nodes));
    // We check that we are using here expected address
    int node = 1;
    for (TransportAddress address : dynamicHosts) {
        TransportAddress expected = poorMansDNS.get(PREFIX_PUBLIC_IP + node++);
        assertEquals(address, expected);
    }
}
Also used : TransportAddress(org.opensearch.common.transport.TransportAddress) Settings(org.opensearch.common.settings.Settings)

Example 78 with TransportAddress

use of org.opensearch.common.transport.TransportAddress in project OpenSearch by opensearch-project.

the class Ec2DiscoveryTests method testFilterByMultipleTags.

public void testFilterByMultipleTags() throws InterruptedException {
    int nodes = randomIntBetween(5, 10);
    Settings nodeSettings = Settings.builder().putList(AwsEc2Service.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<TransportAddress> dynamicHosts = buildDynamicHosts(nodeSettings, nodes, tagsList);
    assertThat(dynamicHosts, hasSize(prodInstances));
}
Also used : TransportAddress(org.opensearch.common.transport.TransportAddress) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Tag(com.amazonaws.services.ec2.model.Tag) Settings(org.opensearch.common.settings.Settings)

Example 79 with TransportAddress

use of org.opensearch.common.transport.TransportAddress in project OpenSearch by opensearch-project.

the class Ec2DiscoveryTests method testPrivateIp.

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

Example 80 with TransportAddress

use of org.opensearch.common.transport.TransportAddress in project OpenSearch by opensearch-project.

the class Ec2DiscoveryTests method testDefaultSettings.

public void testDefaultSettings() throws InterruptedException {
    int nodes = randomInt(10);
    Settings nodeSettings = Settings.builder().build();
    List<TransportAddress> discoveryNodes = buildDynamicHosts(nodeSettings, nodes);
    assertThat(discoveryNodes, hasSize(nodes));
}
Also used : TransportAddress(org.opensearch.common.transport.TransportAddress) Settings(org.opensearch.common.settings.Settings)

Aggregations

TransportAddress (org.opensearch.common.transport.TransportAddress)129 Settings (org.opensearch.common.settings.Settings)51 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)43 BoundTransportAddress (org.opensearch.common.transport.BoundTransportAddress)31 Version (org.opensearch.Version)26 ArrayList (java.util.ArrayList)24 IOException (java.io.IOException)22 List (java.util.List)21 InetAddress (java.net.InetAddress)20 HashSet (java.util.HashSet)20 CountDownLatch (java.util.concurrent.CountDownLatch)20 ClusterSettings (org.opensearch.common.settings.ClusterSettings)20 ThreadPool (org.opensearch.threadpool.ThreadPool)17 Matchers.containsString (org.hamcrest.Matchers.containsString)16 HttpServerTransport (org.opensearch.http.HttpServerTransport)16 Set (java.util.Set)15 TimeUnit (java.util.concurrent.TimeUnit)15 AtomicReference (java.util.concurrent.atomic.AtomicReference)15 OpenSearchTestCase (org.opensearch.test.OpenSearchTestCase)15 MockTransportService (org.opensearch.test.transport.MockTransportService)15