use of org.elasticsearch.common.transport.TransportAddress in project pentaho-kettle by pentaho.
the class ElasticSearchBulkDialog method test.
private void test(TestType testType) {
try {
ElasticSearchBulkMeta tempMeta = new ElasticSearchBulkMeta();
toModel(tempMeta);
// if ( !tempMeta.getServers().isEmpty() ) {
Settings.Builder settingsBuilder = Settings.builder();
settingsBuilder.put(Settings.Builder.EMPTY_SETTINGS);
tempMeta.getSettingsMap().entrySet().stream().forEach((s) -> settingsBuilder.put(s.getKey(), transMeta.environmentSubstitute(s.getValue())));
try (PreBuiltTransportClient client = new PreBuiltTransportClient(settingsBuilder.build())) {
for (Server server : tempMeta.getServers()) {
client.addTransportAddress(new TransportAddress(InetAddress.getByName(transMeta.environmentSubstitute(server.getAddress())), server.getPort()));
}
AdminClient admin = client.admin();
switch(testType) {
case INDEX:
if (StringUtils.isBlank(tempMeta.getIndex())) {
showError(BaseMessages.getString(PKG, "ElasticSearchBulk.Error.NoIndex"));
break;
}
// First check to see if the index exists
IndicesExistsRequestBuilder indicesExistBld = admin.indices().prepareExists(tempMeta.getIndex());
IndicesExistsResponse indicesExistResponse = indicesExistBld.execute().get();
if (!indicesExistResponse.isExists()) {
showError(BaseMessages.getString(PKG, "ElasticSearchBulkDialog.Error.NoIndex"));
return;
}
RecoveryRequestBuilder indicesBld = admin.indices().prepareRecoveries(tempMeta.getIndex());
ActionFuture<RecoveryResponse> lafInd = indicesBld.execute();
String shards = "" + lafInd.get().getSuccessfulShards() + "/" + lafInd.get().getTotalShards();
showMessage(BaseMessages.getString(PKG, "ElasticSearchBulkDialog.TestIndex.TestOK", shards));
break;
case CLUSTER:
ClusterStateRequestBuilder clusterBld = admin.cluster().prepareState();
ActionFuture<ClusterStateResponse> lafClu = clusterBld.execute();
ClusterStateResponse cluResp = lafClu.actionGet();
String name = cluResp.getClusterName().value();
ClusterState cluState = cluResp.getState();
int numNodes = cluState.getNodes().getSize();
showMessage(BaseMessages.getString(PKG, "ElasticSearchBulkDialog.TestCluster.TestOK", name, numNodes));
break;
default:
break;
}
}
} catch (NoNodeAvailableException | MasterNotDiscoveredException e) {
showError(BaseMessages.getString(PKG, "ElasticSearchBulkDialog.Error.NoNodesFound"));
} catch (Exception e) {
showError(e.getLocalizedMessage());
}
}
use of org.elasticsearch.common.transport.TransportAddress in project ff4j by ff4j.
the class ESConfigurationTest method client.
@Bean
public Client client() {
TransportClient client = new TransportClient();
for (int i = 0; i < ports.size(); i++) {
TransportAddress address = new InetSocketTransportAddress(hostname, ports.get(i));
client.addTransportAddress(address);
}
return client;
}
use of org.elasticsearch.common.transport.TransportAddress in project calcite by apache.
the class Elasticsearch2Schema 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.settingsBuilder().put(userConfig).build();
final TransportClient transportClient = TransportClient.builder().settings(settings).build();
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.TransportAddress in project flink by apache.
the class ElasticsearchSinkITCase method getClient.
@Override
@SuppressWarnings("deprecation")
protected final Client getClient() {
TransportAddress transportAddress = new TransportAddress(elasticsearchContainer.getTcpHost());
String expectedClusterName = getClusterName();
Settings settings = Settings.builder().put("cluster.name", expectedClusterName).build();
return new PreBuiltTransportClient(settings).addTransportAddress(transportAddress);
}
use of org.elasticsearch.common.transport.TransportAddress in project crate by crate.
the class PostgresNetty method resolveBindAddress.
private BoundTransportAddress resolveBindAddress() {
// Bind and start to accept incoming connections.
try {
InetAddress[] hostAddresses = networkService.resolveBindHostAddresses(bindHosts);
for (InetAddress address : hostAddresses) {
if (address instanceof Inet4Address || address instanceof Inet6Address) {
boundAddresses.add(bindAddress(address));
}
}
} catch (IOException e) {
throw new BindPostgresException("Failed to resolve binding network host", e);
}
final InetAddress publishInetAddress;
try {
publishInetAddress = networkService.resolvePublishHostAddresses(publishHosts);
} catch (Exception e) {
throw new BindTransportException("Failed to resolve publish address", e);
}
final int publishPort = resolvePublishPort(boundAddresses, publishInetAddress);
final InetSocketAddress publishAddress = new InetSocketAddress(publishInetAddress, publishPort);
return new BoundTransportAddress(boundAddresses.toArray(new TransportAddress[0]), new TransportAddress(publishAddress));
}
Aggregations