use of org.elasticsearch.common.transport.InetSocketTransportAddress in project vertexium by visallo.
the class Elasticsearch5SearchIndex method createTransportClient.
private static TransportClient createTransportClient(ElasticsearchSearchIndexConfiguration config) {
Settings settings = tryReadSettingsFromFile(config);
if (settings == null) {
Settings.Builder settingsBuilder = Settings.builder();
if (config.getClusterName() != null) {
settingsBuilder.put("cluster.name", config.getClusterName());
}
for (Map.Entry<String, String> esSetting : config.getEsSettings().entrySet()) {
settingsBuilder.put(esSetting.getKey(), esSetting.getValue());
}
settings = settingsBuilder.build();
}
TransportClient transportClient = new PreBuiltTransportClient(settings);
for (String esLocation : config.getEsLocations()) {
String[] locationSocket = esLocation.split(":");
String hostname;
int port;
if (locationSocket.length == 2) {
hostname = locationSocket[0];
port = Integer.parseInt(locationSocket[1]);
} else if (locationSocket.length == 1) {
hostname = locationSocket[0];
port = config.getPort();
} else {
throw new VertexiumException("Invalid elastic search location: " + esLocation);
}
InetAddress host;
try {
host = InetAddress.getByName(hostname);
} catch (UnknownHostException ex) {
throw new VertexiumException("Could not resolve host: " + hostname, ex);
}
transportClient.addTransportAddress(new InetSocketTransportAddress(host, port));
}
return transportClient;
}
use of org.elasticsearch.common.transport.InetSocketTransportAddress in project vertexium by visallo.
the class ElasticsearchResource method getLocation.
private String getLocation() {
ClusterStateResponse responsee = runner.node().client().admin().cluster().prepareState().execute().actionGet();
InetSocketTransportAddress address = (InetSocketTransportAddress) responsee.getState().getNodes().getNodes().values().iterator().next().value.getAddress();
return "localhost:" + address.address().getPort();
}
use of org.elasticsearch.common.transport.InetSocketTransportAddress in project calcite by apache.
the class Elasticsearch5Schema 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.builder().put(userConfig).build();
final TransportClient transportClient = new PreBuiltTransportClient(settings);
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;
}
use of org.elasticsearch.common.transport.InetSocketTransportAddress 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();
}
}
Aggregations