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;
}
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();
}
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();
}
}
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();
}
}
}
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));
}
Aggregations