use of org.elasticsearch.common.transport.InetSocketTransportAddress in project api-core by ca-cwds.
the class ElasticUtils method getValidatedESNodes.
@SuppressWarnings("fb-contrib:CLI_CONSTANT_LIST_INDEX")
private static List<InetSocketTransportAddress> getValidatedESNodes(ElasticsearchConfiguration config) {
final List<InetSocketTransportAddress> addressList = new ArrayList<>();
final List<String> nodesList = new ArrayList<>();
// If provided use Host and Port as a first node. For backward compatibility
if (config.getElasticsearchHost() != null && config.getElasticsearchPort() != null) {
nodesList.add(config.getElasticsearchHost().concat(":").concat(config.getElasticsearchPort()));
}
// Example: host1:port1,host2:port2,...etc.
if (config.getElasticsearchNodes() != null) {
nodesList.addAll(Arrays.asList(config.getElasticsearchNodes().split(",")));
}
// remove duplicates if any.
final Map<String, String[]> nodesMap = new HashMap<>(nodesList.size());
for (String node : nodesList) {
nodesMap.put(node, node.split(":"));
}
for (Map.Entry<String, String[]> entry : nodesMap.entrySet()) {
String[] hostPort = entry.getValue();
if (hostPort.length >= 2) {
LOGGER.info("Adding new ES Node host:[{}] port:[{}] to elasticsearch client", hostPort[0], hostPort[1]);
try {
addressList.add(new InetSocketTransportAddress(InetAddress.getByName(hostPort[0]), Integer.parseInt(hostPort[1])));
} catch (UnknownHostException e) {
LOGGER.error("Error adding Node: {}", e.getMessage(), e);
}
}
}
return addressList;
}
use of org.elasticsearch.common.transport.InetSocketTransportAddress in project fabric8 by jboss-fuse.
the class FabricDiscovery method doStart.
@Override
protected void doStart() throws ElasticsearchException {
logger.debug("Starting FabricDiscovery");
Map<String, String> nodeAttributes = discoveryNodeService.buildAttributes();
// note, we rely on the fact that its a new id each time we start, see FD and "kill -9" handling
String nodeId = UUID.randomUUID().toString();
String host = settings.get("discovery.publish.host");
String port = settings.get("discovery.publish.port");
if (host != null && port != null) {
TransportAddress address = new InetSocketTransportAddress(host, Integer.parseInt(port));
localNode = new DiscoveryNode(settings.get("name"), nodeId, address, nodeAttributes, Version.CURRENT);
} else {
localNode = new DiscoveryNode(settings.get("name"), nodeId, transportService.boundAddress().publishAddress(), nodeAttributes, Version.CURRENT);
}
tracker.open();
logger.debug("FabricDiscovery started");
}
use of org.elasticsearch.common.transport.InetSocketTransportAddress in project incubator-skywalking by apache.
the class ElasticSearchClient method initialize.
@Override
public void initialize() throws ClientException {
Settings settings = Settings.builder().put("cluster.name", clusterName).put("client.transport.sniff", clusterTransportSniffer).build();
client = new PreBuiltTransportClient(settings);
List<AddressPairs> pairsList = parseClusterNodes(clusterNodes);
for (AddressPairs pairs : pairsList) {
try {
((PreBuiltTransportClient) client).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(pairs.host), pairs.port));
} catch (UnknownHostException e) {
throw new ElasticSearchClientException(e.getMessage(), e);
}
}
this.ready = true;
}
use of org.elasticsearch.common.transport.InetSocketTransportAddress in project ff4j by ff4j.
the class ElasticConnection method initTransportClient.
private void initTransportClient() {
TransportClient tClient = new TransportClient();
if (!Util.isEmpty(urlSet)) {
for (URL url : urlSet) {
tClient.addTransportAddress(new InetSocketTransportAddress(url.getHost(), url.getPort()));
}
}
esClient = tClient;
}
use of org.elasticsearch.common.transport.InetSocketTransportAddress in project kylo by Teradata.
the class IndexElasticSearchTest method setUp.
@Before
public void setUp() throws IOException {
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
insertDocument = classloader.getResourceAsStream("elasticsearch/insert.json");
updateDocument = classloader.getResourceAsStream("elasticsearch/update.json");
metadataDocument = classloader.getResourceAsStream("elasticsearch/metadata.json");
Settings settings = Settings.settingsBuilder().put("cluster.name", TEST_CLUSTER).build();
esClient = TransportClient.builder().settings(settings).build().addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(TEST_HOST), 9300));
}
Aggregations