use of org.elasticsearch.client.transport.TransportClient in project zipkin by openzipkin.
the class ElasticsearchDependenciesTest method writeDependencyLinks.
protected void writeDependencyLinks(List<DependencyLink> links, long timestampMillis) {
long midnight = Util.midnightUTC(timestampMillis);
TransportClient client = ((NativeClient) storage().client()).client;
BulkRequestBuilder request = client.prepareBulk();
for (DependencyLink link : links) {
request.add(client.prepareIndex(storage().indexNameFormatter.indexNameForTimestamp(midnight), ElasticsearchConstants.DEPENDENCY_LINK).setId(// Unique constraint
link.parent + "|" + link.child).setSource("parent", link.parent, "child", link.child, "callCount", link.callCount));
}
request.execute().actionGet();
client.admin().indices().flush(new FlushRequest()).actionGet();
}
use of org.elasticsearch.client.transport.TransportClient in project sonarqube by SonarSource.
the class EsClientProviderTest method connection_to_local_es_when_cluster_mode_is_disabled.
@Test
public void connection_to_local_es_when_cluster_mode_is_disabled() throws Exception {
settings.setProperty(ProcessProperties.CLUSTER_ENABLED, false);
settings.setProperty(ProcessProperties.SEARCH_HOST, localhost);
settings.setProperty(ProcessProperties.SEARCH_PORT, 8080);
EsClient client = underTest.provide(settings);
TransportClient transportClient = (TransportClient) client.nativeClient();
assertThat(transportClient.transportAddresses()).hasSize(1);
TransportAddress address = transportClient.transportAddresses().get(0);
assertThat(address.getAddress()).isEqualTo(localhost);
assertThat(address.getPort()).isEqualTo(8080);
assertThat(logTester.logs(LoggerLevel.INFO)).has(new Condition<>(s -> s.contains("Connected to local Elasticsearch: [" + localhost + ":8080]"), ""));
// keep in cache
assertThat(underTest.provide(settings)).isSameAs(client);
}
use of org.elasticsearch.client.transport.TransportClient in project sonarqube by SonarSource.
the class EsClientProviderTest method connection_to_remote_es_nodes_when_cluster_mode_is_enabled_and_local_es_is_disabled.
@Test
public void connection_to_remote_es_nodes_when_cluster_mode_is_enabled_and_local_es_is_disabled() throws Exception {
settings.setProperty(ProcessProperties.CLUSTER_ENABLED, true);
settings.setProperty(ProcessProperties.CLUSTER_SEARCH_DISABLED, true);
settings.setProperty(ProcessProperties.CLUSTER_SEARCH_HOSTS, format("%s:8080,%s:8081", localhost, localhost));
EsClient client = underTest.provide(settings);
TransportClient transportClient = (TransportClient) client.nativeClient();
assertThat(transportClient.transportAddresses()).hasSize(2);
TransportAddress address = transportClient.transportAddresses().get(0);
assertThat(address.getAddress()).isEqualTo(localhost);
assertThat(address.getPort()).isEqualTo(8080);
address = transportClient.transportAddresses().get(1);
assertThat(address.getAddress()).isEqualTo(localhost);
assertThat(address.getPort()).isEqualTo(8081);
assertThat(logTester.logs(LoggerLevel.INFO)).has(new Condition<>(s -> s.contains("Connected to remote Elasticsearch: [" + localhost + ":8080, " + localhost + ":8081]"), ""));
// keep in cache
assertThat(underTest.provide(settings)).isSameAs(client);
}
use of org.elasticsearch.client.transport.TransportClient in project MSEC by Tencent.
the class ESHelper method ClusterStatus.
public void ClusterStatus(ArrayList<String> ips, String cluster_name, QueryESClusterDetailResponse response) {
Logger logger = Logger.getLogger(ESHelper.class);
TransportClient client = null;
HashSet<String> total_ips = new HashSet<>(ips);
try {
Settings settings = Settings.builder().put("cluster.name", cluster_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));
}
ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setTimeout(TimeValue.timeValueSeconds(5)).execute().actionGet();
if (healthResponse != null && !healthResponse.isTimedOut()) {
response.setActive_shards(healthResponse.getActiveShards());
response.setTotal_shards(healthResponse.getActiveShards() + healthResponse.getUnassignedShards());
response.setHealth_status(healthResponse.getStatus().toString().toLowerCase());
response.setServer_port(default_port);
logger.info(healthResponse);
if (healthResponse.getNumberOfNodes() > 0) {
NodesStatsResponse nodeStats = client.admin().cluster().prepareNodesStats().all().get();
if (nodeStats != null) {
for (NodeStats stats : nodeStats.getNodes()) {
QueryESClusterDetailResponse.RTInfo info = new QueryESClusterDetailResponse().new RTInfo();
info.setOK(true);
info.setAvail_disk_size(stats.getFs().getTotal().getAvailable().getBytes());
info.setDoc_count(stats.getIndices().getDocs().getCount());
info.setDoc_disk_size(stats.getIndices().getStore().getSizeInBytes());
response.getInfo_map().put(stats.getNode().getAddress().getHost(), info);
total_ips.add(stats.getNode().getAddress().getHost());
}
}
}
}
//update Zen settings
client.admin().cluster().prepareUpdateSettings().setPersistentSettings(Settings.builder().put("discovery.zen.minimum_master_nodes", total_ips.size() / 2 + 1)).setTransientSettings(Settings.builder().put("discovery.zen.minimum_master_nodes", total_ips.size() / 2 + 1)).get();
//update template settings
PutIndexTemplateResponse tpl_resp = client.admin().indices().preparePutTemplate("template_msec").setTemplate("msec_*").setSettings(Settings.builder().put("number_of_replicas", 1).put("refresh_interval", "30s")).addMapping("logs", MAPPING).execute().get();
logger.info("Create mapping: " + tpl_resp.isAcknowledged());
} catch (UnknownHostException e) {
logger.error(e);
} catch (Exception e) {
logger.error(e);
} finally {
if (client != null)
client.close();
}
}
use of org.elasticsearch.client.transport.TransportClient in project elasticsearch-jetty by sonian.
the class AbstractJettyHttpServerTests method closeAllNodes.
public void closeAllNodes() {
for (TransportClient client : transportClients) {
client.close();
}
transportClients.clear();
for (Client client : clients.values()) {
client.close();
}
clients.clear();
for (Node node : nodes.values()) {
node.close();
}
nodes.clear();
}
Aggregations