Search in sources :

Example 6 with InetSocketTransportAddress

use of org.elasticsearch.common.transport.InetSocketTransportAddress in project qi4j-sdk by Qi4j.

the class ESClusterSupport method activateElasticSearch.

@Override
protected void activateElasticSearch() throws Exception {
    configuration.refresh();
    ElasticSearchClusterConfiguration config = configuration.get();
    String clusterName = config.clusterName().get() == null ? DEFAULT_CLUSTER_NAME : config.clusterName().get();
    index = config.index().get() == null ? DEFAULT_INDEX_NAME : config.index().get();
    indexNonAggregatedAssociations = config.indexNonAggregatedAssociations().get();
    String[] nodes = config.nodes().get() == null ? new String[] { "localhost:9300" } : config.nodes().get().split(",");
    boolean clusterSniff = config.clusterSniff().get();
    boolean ignoreClusterName = config.ignoreClusterName().get();
    String pingTimeout = config.pingTimeout().get() == null ? "5s" : config.pingTimeout().get();
    String samplerInterval = config.samplerInterval().get() == null ? "5s" : config.samplerInterval().get();
    Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", clusterName).put("client.transport.sniff", clusterSniff).put("client.transport.ignore_cluster_name", ignoreClusterName).put("client.transport.ping_timeout", pingTimeout).put("client.transport.nodes_sampler_interval", samplerInterval).build();
    TransportClient transportClient = new TransportClient(settings);
    for (String node : nodes) {
        String[] split = node.split(":");
        String host = split[0];
        int port = Integer.valueOf(split[1]);
        transportClient.addTransportAddress(new InetSocketTransportAddress(host, port));
    }
    client = transportClient;
}
Also used : TransportClient(org.elasticsearch.client.transport.TransportClient) ElasticSearchClusterConfiguration(org.qi4j.index.elasticsearch.ElasticSearchClusterConfiguration) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) Settings(org.elasticsearch.common.settings.Settings) ImmutableSettings(org.elasticsearch.common.settings.ImmutableSettings)

Example 7 with InetSocketTransportAddress

use of org.elasticsearch.common.transport.InetSocketTransportAddress in project sonarqube by SonarSource.

the class EsServerHolder method reset.

private void reset() {
    TransportClient client = TransportClient.builder().settings(Settings.builder().put("network.bind_host", "localhost").put("cluster.name", clusterName).build()).build();
    client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getLoopbackAddress(), port));
    // wait for node to be ready
    client.admin().cluster().prepareHealth().setWaitForGreenStatus().get();
    // delete the indices created by previous tests
    DeleteIndexResponse response = client.admin().indices().prepareDelete("_all").get();
    if (!response.isAcknowledged()) {
        throw new IllegalStateException("Fail to delete all indices");
    }
    client.close();
}
Also used : DeleteIndexResponse(org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse) TransportClient(org.elasticsearch.client.transport.TransportClient) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress)

Example 8 with InetSocketTransportAddress

use of org.elasticsearch.common.transport.InetSocketTransportAddress in project MSEC by Tencent.

the class ESHelper method ClusterAdd.

public void ClusterAdd(ArrayList<String> ips) {
    Logger logger = Logger.getLogger(ESHelper.class);
    TransportClient client = null;
    try {
        Settings settings = Settings.builder().put("cluster.name", cluster_info.getCluster_name()).put("client.transport.sniff", true).build();
        for (String ip : ips) {
            if (client == null) {
                client = new PreBuiltTransportClient(settings).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(ip), default_client_port));
            } else
                client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(ip), default_client_port));
        }
        updateStatus(waitforcluster_message);
        waitForClusterReady(client, ips, ClusterHealthStatus.YELLOW);
    } catch (UnknownHostException e) {
        logger.error(e);
        updateStatus("[ERROR] Connect failed.");
    } catch (IOException e) {
        logger.error(e);
        updateStatus_waitforcluster("[ERROR] Joining cluster failed.");
    } finally {
        if (client != null)
            client.close();
    }
}
Also used : TransportClient(org.elasticsearch.client.transport.TransportClient) PreBuiltTransportClient(org.elasticsearch.transport.client.PreBuiltTransportClient) PreBuiltTransportClient(org.elasticsearch.transport.client.PreBuiltTransportClient) UnknownHostException(java.net.UnknownHostException) IOException(java.io.IOException) Logger(org.apache.log4j.Logger) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) Settings(org.elasticsearch.common.settings.Settings)

Example 9 with InetSocketTransportAddress

use of org.elasticsearch.common.transport.InetSocketTransportAddress in project MSEC by Tencent.

the class ESSink method initESThreadPool.

private void initESThreadPool() {
    serverAddresses = new InetSocketTransportAddress[serverAddressStrings.length];
    workingQueue = new ArrayBlockingQueue<ESClientThread.ESThreadRequest>(serverAddressStrings.length * 2);
    for (int i = 0; i < serverAddressStrings.length; i++) {
        String[] hostPort = serverAddressStrings[i].trim().split(":");
        String host = hostPort[0].trim();
        int port = hostPort.length == 2 ? Integer.parseInt(hostPort[1].trim()) : DEFAULT_PORT;
        try {
            serverAddresses[i] = new InetSocketTransportAddress(InetAddress.getByName(host), port);
            threadPool.submit(new ESClientThread(workingQueue, clusterName, serverAddresses[i]));
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) String(java.lang.String) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress)

Example 10 with InetSocketTransportAddress

use of org.elasticsearch.common.transport.InetSocketTransportAddress in project wonderdog by infochimps-labs.

the class ElasticSearchStreamingRecordReader method buildTransportClient.

/**
       Build a transport client that will connect to some
       Elasticsearch node.
       
     */
private Client buildTransportClient() {
    LOG.info("Connecting transport client to " + transportHost + ":" + Integer.toString(transportPort));
    Settings settings = ImmutableSettings.settingsBuilder().put("client.transport.ignore_cluster_name", "true").build();
    return new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress(transportHost, transportPort));
}
Also used : TransportClient(org.elasticsearch.client.transport.TransportClient) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) ImmutableSettings(org.elasticsearch.common.settings.ImmutableSettings) Settings(org.elasticsearch.common.settings.Settings)

Aggregations

InetSocketTransportAddress (org.elasticsearch.common.transport.InetSocketTransportAddress)35 TransportClient (org.elasticsearch.client.transport.TransportClient)15 Settings (org.elasticsearch.common.settings.Settings)14 ImmutableSettings (org.elasticsearch.common.settings.ImmutableSettings)7 TransportAddress (org.elasticsearch.common.transport.TransportAddress)7 PreBuiltTransportClient (org.elasticsearch.transport.client.PreBuiltTransportClient)7 InetSocketAddress (java.net.InetSocketAddress)5 UnknownHostException (java.net.UnknownHostException)5 IOException (java.io.IOException)4 InetAddress (java.net.InetAddress)3 ArrayList (java.util.ArrayList)3 NodesInfoResponse (org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse)3 BoundTransportAddress (org.elasticsearch.common.transport.BoundTransportAddress)3 File (java.io.File)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Properties (java.util.Properties)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Logger (org.apache.log4j.Logger)2 ElasticsearchClusterRunner (org.codelibs.elasticsearch.runner.ElasticsearchClusterRunner)2