Search in sources :

Example 46 with TransportAddress

use of org.elasticsearch.common.transport.TransportAddress in project pentaho-kettle by pentaho.

the class ElasticSearchBulkDialog method test.

private void test(TestType testType) {
    try {
        ElasticSearchBulkMeta tempMeta = new ElasticSearchBulkMeta();
        toModel(tempMeta);
        // if ( !tempMeta.getServers().isEmpty() ) {
        Settings.Builder settingsBuilder = Settings.builder();
        settingsBuilder.put(Settings.Builder.EMPTY_SETTINGS);
        tempMeta.getSettingsMap().entrySet().stream().forEach((s) -> settingsBuilder.put(s.getKey(), transMeta.environmentSubstitute(s.getValue())));
        try (PreBuiltTransportClient client = new PreBuiltTransportClient(settingsBuilder.build())) {
            for (Server server : tempMeta.getServers()) {
                client.addTransportAddress(new TransportAddress(InetAddress.getByName(transMeta.environmentSubstitute(server.getAddress())), server.getPort()));
            }
            AdminClient admin = client.admin();
            switch(testType) {
                case INDEX:
                    if (StringUtils.isBlank(tempMeta.getIndex())) {
                        showError(BaseMessages.getString(PKG, "ElasticSearchBulk.Error.NoIndex"));
                        break;
                    }
                    // First check to see if the index exists
                    IndicesExistsRequestBuilder indicesExistBld = admin.indices().prepareExists(tempMeta.getIndex());
                    IndicesExistsResponse indicesExistResponse = indicesExistBld.execute().get();
                    if (!indicesExistResponse.isExists()) {
                        showError(BaseMessages.getString(PKG, "ElasticSearchBulkDialog.Error.NoIndex"));
                        return;
                    }
                    RecoveryRequestBuilder indicesBld = admin.indices().prepareRecoveries(tempMeta.getIndex());
                    ActionFuture<RecoveryResponse> lafInd = indicesBld.execute();
                    String shards = "" + lafInd.get().getSuccessfulShards() + "/" + lafInd.get().getTotalShards();
                    showMessage(BaseMessages.getString(PKG, "ElasticSearchBulkDialog.TestIndex.TestOK", shards));
                    break;
                case CLUSTER:
                    ClusterStateRequestBuilder clusterBld = admin.cluster().prepareState();
                    ActionFuture<ClusterStateResponse> lafClu = clusterBld.execute();
                    ClusterStateResponse cluResp = lafClu.actionGet();
                    String name = cluResp.getClusterName().value();
                    ClusterState cluState = cluResp.getState();
                    int numNodes = cluState.getNodes().getSize();
                    showMessage(BaseMessages.getString(PKG, "ElasticSearchBulkDialog.TestCluster.TestOK", name, numNodes));
                    break;
                default:
                    break;
            }
        }
    } catch (NoNodeAvailableException | MasterNotDiscoveredException e) {
        showError(BaseMessages.getString(PKG, "ElasticSearchBulkDialog.Error.NoNodesFound"));
    } catch (Exception e) {
        showError(e.getLocalizedMessage());
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) Server(org.pentaho.di.trans.steps.elasticsearchbulk.ElasticSearchBulkMeta.Server) TransportAddress(org.elasticsearch.common.transport.TransportAddress) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) ClusterStateRequestBuilder(org.elasticsearch.action.admin.cluster.state.ClusterStateRequestBuilder) NoNodeAvailableException(org.elasticsearch.client.transport.NoNodeAvailableException) MasterNotDiscoveredException(org.elasticsearch.discovery.MasterNotDiscoveredException) MasterNotDiscoveredException(org.elasticsearch.discovery.MasterNotDiscoveredException) NoNodeAvailableException(org.elasticsearch.client.transport.NoNodeAvailableException) KettleException(org.pentaho.di.core.exception.KettleException) RecoveryResponse(org.elasticsearch.action.admin.indices.recovery.RecoveryResponse) PreBuiltTransportClient(org.elasticsearch.transport.client.PreBuiltTransportClient) IndicesExistsRequestBuilder(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequestBuilder) IndicesExistsResponse(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse) RecoveryRequestBuilder(org.elasticsearch.action.admin.indices.recovery.RecoveryRequestBuilder) ElasticSearchBulkMeta(org.pentaho.di.trans.steps.elasticsearchbulk.ElasticSearchBulkMeta) Settings(org.elasticsearch.common.settings.Settings) AdminClient(org.elasticsearch.client.AdminClient)

Example 47 with TransportAddress

use of org.elasticsearch.common.transport.TransportAddress in project ff4j by ff4j.

the class ESConfigurationTest method client.

@Bean
public Client client() {
    TransportClient client = new TransportClient();
    for (int i = 0; i < ports.size(); i++) {
        TransportAddress address = new InetSocketTransportAddress(hostname, ports.get(i));
        client.addTransportAddress(address);
    }
    return client;
}
Also used : TransportClient(org.elasticsearch.client.transport.TransportClient) TransportAddress(org.elasticsearch.common.transport.TransportAddress) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) Bean(org.springframework.context.annotation.Bean)

Example 48 with TransportAddress

use of org.elasticsearch.common.transport.TransportAddress in project calcite by apache.

the class Elasticsearch2Schema method open.

private void open(List<InetSocketAddress> transportAddresses, Map<String, String> userConfig) {
    final List<TransportAddress> transportNodes = new ArrayList<>(transportAddresses.size());
    for (InetSocketAddress address : transportAddresses) {
        transportNodes.add(new InetSocketTransportAddress(address));
    }
    Settings settings = Settings.settingsBuilder().put(userConfig).build();
    final TransportClient transportClient = TransportClient.builder().settings(settings).build();
    for (TransportAddress transport : transportNodes) {
        transportClient.addTransportAddress(transport);
    }
    final List<DiscoveryNode> nodes = ImmutableList.copyOf(transportClient.connectedNodes());
    if (nodes.isEmpty()) {
        throw new RuntimeException("Cannot connect to any elasticsearch nodes");
    }
    client = transportClient;
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) TransportClient(org.elasticsearch.client.transport.TransportClient) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) TransportAddress(org.elasticsearch.common.transport.TransportAddress) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) Settings(org.elasticsearch.common.settings.Settings)

Example 49 with TransportAddress

use of org.elasticsearch.common.transport.TransportAddress in project flink by apache.

the class ElasticsearchSinkITCase method getClient.

@Override
@SuppressWarnings("deprecation")
protected final Client getClient() {
    TransportAddress transportAddress = new TransportAddress(elasticsearchContainer.getTcpHost());
    String expectedClusterName = getClusterName();
    Settings settings = Settings.builder().put("cluster.name", expectedClusterName).build();
    return new PreBuiltTransportClient(settings).addTransportAddress(transportAddress);
}
Also used : PreBuiltTransportClient(org.elasticsearch.transport.client.PreBuiltTransportClient) TransportAddress(org.elasticsearch.common.transport.TransportAddress) Settings(org.elasticsearch.common.settings.Settings)

Example 50 with TransportAddress

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

the class PostgresNetty method resolveBindAddress.

private BoundTransportAddress resolveBindAddress() {
    // Bind and start to accept incoming connections.
    try {
        InetAddress[] hostAddresses = networkService.resolveBindHostAddresses(bindHosts);
        for (InetAddress address : hostAddresses) {
            if (address instanceof Inet4Address || address instanceof Inet6Address) {
                boundAddresses.add(bindAddress(address));
            }
        }
    } catch (IOException e) {
        throw new BindPostgresException("Failed to resolve binding network host", e);
    }
    final InetAddress publishInetAddress;
    try {
        publishInetAddress = networkService.resolvePublishHostAddresses(publishHosts);
    } catch (Exception e) {
        throw new BindTransportException("Failed to resolve publish address", e);
    }
    final int publishPort = resolvePublishPort(boundAddresses, publishInetAddress);
    final InetSocketAddress publishAddress = new InetSocketAddress(publishInetAddress, publishPort);
    return new BoundTransportAddress(boundAddresses.toArray(new TransportAddress[0]), new TransportAddress(publishAddress));
}
Also used : Inet4Address(java.net.Inet4Address) InetSocketAddress(java.net.InetSocketAddress) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) TransportAddress(org.elasticsearch.common.transport.TransportAddress) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) BindTransportException(org.elasticsearch.transport.BindTransportException) Inet6Address(java.net.Inet6Address) IOException(java.io.IOException) InetAddress(java.net.InetAddress) BindTransportException(org.elasticsearch.transport.BindTransportException) BindHttpException(org.elasticsearch.http.BindHttpException) IOException(java.io.IOException)

Aggregations

TransportAddress (org.elasticsearch.common.transport.TransportAddress)129 Settings (org.elasticsearch.common.settings.Settings)46 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)45 BoundTransportAddress (org.elasticsearch.common.transport.BoundTransportAddress)33 ArrayList (java.util.ArrayList)31 IOException (java.io.IOException)30 InetSocketAddress (java.net.InetSocketAddress)28 InetAddress (java.net.InetAddress)22 PreBuiltTransportClient (org.elasticsearch.transport.client.PreBuiltTransportClient)20 HashSet (java.util.HashSet)16 UnknownHostException (java.net.UnknownHostException)15 TransportClient (org.elasticsearch.client.transport.TransportClient)15 TransportService (org.elasticsearch.transport.TransportService)14 NamedWriteableRegistry (org.elasticsearch.common.io.stream.NamedWriteableRegistry)13 AtomicReference (java.util.concurrent.atomic.AtomicReference)12 ClusterState (org.elasticsearch.cluster.ClusterState)12 NetworkService (org.elasticsearch.common.network.NetworkService)12 ThreadPool (org.elasticsearch.threadpool.ThreadPool)12 HashMap (java.util.HashMap)11 List (java.util.List)11