Search in sources :

Example 6 with TransportClient

use of org.elasticsearch.client.transport.TransportClient 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 7 with TransportClient

use of org.elasticsearch.client.transport.TransportClient 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 8 with TransportClient

use of org.elasticsearch.client.transport.TransportClient 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)

Example 9 with TransportClient

use of org.elasticsearch.client.transport.TransportClient in project storm-elastic-search by hmsonline.

the class ElasticSearchBolt method prepare.

@Override
@SuppressWarnings("rawtypes")
public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
    this.collector = collector;
    String elasticSearchHost = (String) stormConf.get(StormElasticSearchConstants.ES_HOST);
    Integer elasticSearchPort = ((Long) stormConf.get(StormElasticSearchConstants.ES_PORT)).intValue();
    String elasticSearchCluster = (String) stormConf.get(StormElasticSearchConstants.ES_CLUSTER_NAME);
    Boolean localMode = (Boolean) stormConf.get(ELASTIC_LOCAL_MODE);
    if (localMode != null && localMode) {
        client = nodeBuilder().local(true).node().client();
    } else {
        Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", elasticSearchCluster).build();
        client = new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress(elasticSearchHost, elasticSearchPort));
    }
}
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)

Example 10 with TransportClient

use of org.elasticsearch.client.transport.TransportClient in project storm-elastic-search by hmsonline.

the class ElasticSearchFunction method prepare.

@SuppressWarnings("rawtypes")
@Override
public void prepare(Map conf, TridentOperationContext context) {
    super.prepare(conf, context);
    String clusterName = (String) conf.get(StormElasticSearchConstants.ES_CLUSTER_NAME);
    String host = (String) conf.get(StormElasticSearchConstants.ES_HOST);
    Integer port = (Integer) conf.get(StormElasticSearchConstants.ES_PORT);
    Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", clusterName).build();
    client = new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress(host, port));
}
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

TransportClient (org.elasticsearch.client.transport.TransportClient)31 Settings (org.elasticsearch.common.settings.Settings)17 InetSocketTransportAddress (org.elasticsearch.common.transport.InetSocketTransportAddress)15 TransportAddress (org.elasticsearch.common.transport.TransportAddress)8 ImmutableSettings (org.elasticsearch.common.settings.ImmutableSettings)7 PreBuiltTransportClient (org.elasticsearch.transport.client.PreBuiltTransportClient)7 Client (org.elasticsearch.client.Client)5 IOException (java.io.IOException)3 UnknownHostException (java.net.UnknownHostException)3 Test (org.junit.Test)3 Settings (org.sonar.api.config.Settings)3 File (java.io.File)2 String.format (java.lang.String.format)2 InetAddress (java.net.InetAddress)2 Logger (org.apache.log4j.Logger)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Condition (org.assertj.core.api.Condition)2 ClusterHealthResponse (org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse)2 BulkRequestBuilder (org.elasticsearch.action.bulk.BulkRequestBuilder)2 Node (org.elasticsearch.node.Node)2