Search in sources :

Example 26 with BoundTransportAddress

use of org.elasticsearch.common.transport.BoundTransportAddress in project elasticsearch by elastic.

the class MockTransportService method extractTransportAddresses.

public static TransportAddress[] extractTransportAddresses(TransportService transportService) {
    HashSet<TransportAddress> transportAddresses = new HashSet<>();
    BoundTransportAddress boundTransportAddress = transportService.boundAddress();
    transportAddresses.addAll(Arrays.asList(boundTransportAddress.boundAddresses()));
    transportAddresses.add(boundTransportAddress.publishAddress());
    return transportAddresses.toArray(new TransportAddress[transportAddresses.size()]);
}
Also used : TransportAddress(org.elasticsearch.common.transport.TransportAddress) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) HashSet(java.util.HashSet)

Example 27 with BoundTransportAddress

use of org.elasticsearch.common.transport.BoundTransportAddress in project crate by crate.

the class Netty4HttpServerTransport method createBoundHttpAddress.

private BoundTransportAddress createBoundHttpAddress() {
    // Bind and start to accept incoming connections.
    InetAddress[] hostAddresses;
    try {
        hostAddresses = networkService.resolveBindHostAddresses(bindHosts);
    } catch (IOException e) {
        throw new BindHttpException("Failed to resolve host [" + Arrays.toString(bindHosts) + "]", e);
    }
    List<TransportAddress> boundAddresses = new ArrayList<>(hostAddresses.length);
    for (InetAddress address : hostAddresses) {
        boundAddresses.add(bindAddress(address));
    }
    final InetAddress publishInetAddress;
    try {
        publishInetAddress = networkService.resolvePublishHostAddresses(publishHosts);
    } catch (Exception e) {
        throw new BindTransportException("Failed to resolve publish address", e);
    }
    final int publishPort = resolvePublishPort(settings, boundAddresses, publishInetAddress);
    final InetSocketAddress publishAddress = new InetSocketAddress(publishInetAddress, publishPort);
    return new BoundTransportAddress(boundAddresses.toArray(new TransportAddress[0]), new TransportAddress(publishAddress));
}
Also used : BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) TransportAddress(org.elasticsearch.common.transport.TransportAddress) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) BindTransportException(org.elasticsearch.transport.BindTransportException) IOException(java.io.IOException) BindHttpException(org.elasticsearch.http.BindHttpException) InetAddress(java.net.InetAddress) BindHttpException(org.elasticsearch.http.BindHttpException) SettingsException(org.elasticsearch.common.settings.SettingsException) IOException(java.io.IOException) PatternSyntaxException(java.util.regex.PatternSyntaxException) BindTransportException(org.elasticsearch.transport.BindTransportException)

Example 28 with BoundTransportAddress

use of org.elasticsearch.common.transport.BoundTransportAddress in project crate by crate.

the class TcpTransport method bindServer.

protected void bindServer(ProfileSettings profileSettings) {
    // Bind and start to accept incoming connections.
    InetAddress[] hostAddresses;
    List<String> profileBindHosts = profileSettings.bindHosts;
    try {
        hostAddresses = networkService.resolveBindHostAddresses(profileBindHosts.toArray(Strings.EMPTY_ARRAY));
    } catch (IOException e) {
        throw new BindTransportException("Failed to resolve host " + profileBindHosts, e);
    }
    if (logger.isDebugEnabled()) {
        String[] addresses = new String[hostAddresses.length];
        for (int i = 0; i < hostAddresses.length; i++) {
            addresses[i] = NetworkAddress.format(hostAddresses[i]);
        }
        logger.debug("binding server bootstrap to: {}", (Object) addresses);
    }
    assert hostAddresses.length > 0;
    List<InetSocketAddress> boundAddresses = new ArrayList<>();
    for (InetAddress hostAddress : hostAddresses) {
        boundAddresses.add(bindToPort(profileSettings.profileName, hostAddress, profileSettings.portOrRange));
    }
    final BoundTransportAddress boundTransportAddress = createBoundTransportAddress(profileSettings, boundAddresses);
    if (profileSettings.isDefaultProfile) {
        this.boundAddress = boundTransportAddress;
    } else {
        profileBoundAddresses.put(profileSettings.profileName, boundTransportAddress);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) IOException(java.io.IOException) InetAddress(java.net.InetAddress)

Example 29 with BoundTransportAddress

use of org.elasticsearch.common.transport.BoundTransportAddress in project crate by crate.

the class GatewayIndexStateIT method testIndexDeletionWhenNodeRejoins.

/**
 * This test ensures that when an index deletion takes place while a node is offline, when that
 * node rejoins the cluster, it deletes the index locally instead of importing it as a dangling index.
 */
@Test
public void testIndexDeletionWhenNodeRejoins() throws Exception {
    final int numNodes = 2;
    final List<String> nodes;
    logger.info("--> starting a cluster with " + numNodes + " nodes");
    nodes = internalCluster().startNodes(numNodes, Settings.builder().put(IndexGraveyard.SETTING_MAX_TOMBSTONES.getKey(), randomIntBetween(10, 100)).build());
    logger.info("--> create an index");
    // createIndex(indexName);
    execute("create table my_schema.test (id int) with (number_of_replicas = 0)");
    var tableName = "my_schema.test";
    logger.info("--> waiting for green status");
    ensureGreen();
    final String indexUUID = resolveIndex(tableName).getUUID();
    logger.info("--> restart a random date node, deleting the index in between stopping and restarting");
    internalCluster().restartRandomDataNode(new RestartCallback() {

        @Override
        public Settings onNodeStopped(final String nodeName) throws Exception {
            nodes.remove(nodeName);
            logger.info("--> stopped node[{}], remaining nodes {}", nodeName, nodes);
            assert nodes.size() > 0;
            final String otherNode = nodes.get(0);
            logger.info("--> delete index and verify it is deleted");
            var clientProvider = new SQLTransportExecutor.ClientProvider() {

                @Override
                public Client client() {
                    return ESIntegTestCase.client(otherNode);
                }

                @Override
                public String pgUrl() {
                    PostgresNetty postgresNetty = internalCluster().getInstance(PostgresNetty.class, otherNode);
                    BoundTransportAddress boundTransportAddress = postgresNetty.boundAddress();
                    if (boundTransportAddress != null) {
                        InetSocketAddress address = boundTransportAddress.publishAddress().address();
                        return String.format(Locale.ENGLISH, "jdbc:postgresql://%s:%d/?ssl=%s&sslmode=%s", address.getHostName(), address.getPort(), false, "disable");
                    }
                    return null;
                }

                @Override
                public SQLOperations sqlOperations() {
                    return internalCluster().getInstance(SQLOperations.class, otherNode);
                }
            };
            var sqlExecutor = new SQLTransportExecutor(clientProvider);
            // client.admin().indices().prepareDelete(indexName).execute().actionGet();
            sqlExecutor.exec("drop table my_schema.test");
            assertThat(response.rowCount(), is(1L));
            // assertFalse(indexExists(indexName, client));
            try {
                sqlExecutor.exec("select * from my_schema.test");
                fail("expecting index to be deleted");
            } catch (Exception e) {
            // pass
            }
            logger.info("--> index deleted");
            return super.onNodeStopped(nodeName);
        }
    });
    logger.info("--> wait until all nodes are back online");
    client().admin().cluster().health(Requests.clusterHealthRequest().waitForEvents(Priority.LANGUID).waitForNodes(Integer.toString(numNodes))).actionGet(REQUEST_TIMEOUT);
    logger.info("--> waiting for green status");
    ensureGreen();
    logger.info("--> verify that the deleted index is removed from the cluster and not reimported as dangling by the restarted node");
    // assertFalse(indexExists(indexName));
    try {
        execute("select * from my_schema.test");
        fail("expecting index to be deleted");
    } catch (Exception e) {
    // pass
    }
    assertBusy(() -> {
        final NodeEnvironment nodeEnv = internalCluster().getInstance(NodeEnvironment.class);
        try {
            assertFalse("index folder " + indexUUID + " should be deleted", nodeEnv.availableIndexFolders().contains(indexUUID));
        } catch (IOException e) {
            logger.error("Unable to retrieve available index folders from the node", e);
            fail("Unable to retrieve available index folders from the node");
        }
    });
}
Also used : NodeEnvironment(org.elasticsearch.env.NodeEnvironment) InetSocketAddress(java.net.InetSocketAddress) SQLTransportExecutor(io.crate.testing.SQLTransportExecutor) IOException(java.io.IOException) RestartCallback(org.elasticsearch.test.InternalTestCluster.RestartCallback) IOException(java.io.IOException) PostgresNetty(io.crate.protocols.postgres.PostgresNetty) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) Client(org.elasticsearch.client.Client) SQLOperations(io.crate.action.sql.SQLOperations) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test)

Aggregations

BoundTransportAddress (org.elasticsearch.common.transport.BoundTransportAddress)29 TransportAddress (org.elasticsearch.common.transport.TransportAddress)20 IOException (java.io.IOException)14 InetSocketAddress (java.net.InetSocketAddress)12 InetAddress (java.net.InetAddress)11 ArrayList (java.util.ArrayList)10 Settings (org.elasticsearch.common.settings.Settings)8 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)7 UnknownHostException (java.net.UnknownHostException)6 Logger (org.apache.logging.log4j.Logger)6 NamedWriteableRegistry (org.elasticsearch.common.io.stream.NamedWriteableRegistry)6 NetworkService (org.elasticsearch.common.network.NetworkService)6 NoneCircuitBreakerService (org.elasticsearch.indices.breaker.NoneCircuitBreakerService)6 MockTransportService (org.elasticsearch.test.transport.MockTransportService)6 MockTcpTransport (org.elasticsearch.transport.MockTcpTransport)6 ElasticsearchException (org.elasticsearch.ElasticsearchException)5 Transport (org.elasticsearch.transport.Transport)5 TransportService (org.elasticsearch.transport.TransportService)5 HashSet (java.util.HashSet)4 HashMap (java.util.HashMap)3