use of org.elasticsearch.common.transport.InetSocketTransportAddress in project kylo by Teradata.
the class ElasticSearchService method buildTransportClient.
private void buildTransportClient() {
if (this.client == null) {
try {
Settings settings = Settings.settingsBuilder().put("cluster.name", clientConfig.getClusterName()).build();
client = TransportClient.builder().settings(settings).build().addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(clientConfig.getHost()), clientConfig.getTransportPort()));
} catch (UnknownHostException e) {
throw new RuntimeException("Error encountered during search.");
}
}
}
use of org.elasticsearch.common.transport.InetSocketTransportAddress in project incubator-gobblin by apache.
the class ElasticsearchRestWriter method buildRestClient.
// TODO: Support pass through of configuration (e.g. timeouts etc) of rest client from above
private static RestClient buildRestClient(List<InetSocketTransportAddress> hosts, int threadCount, boolean sslEnabled, String keyStoreType, String keyStoreFilePassword, String identityFilepath, String trustStoreType, String trustStoreFilePassword, String cacertsFilepath) throws Exception {
HttpHost[] httpHosts = new HttpHost[hosts.size()];
String scheme = sslEnabled ? "https" : "http";
for (int h = 0; h < httpHosts.length; h++) {
InetSocketTransportAddress host = hosts.get(h);
httpHosts[h] = new HttpHost(host.getAddress(), host.getPort(), scheme);
}
RestClientBuilder builder = RestClient.builder(httpHosts);
if (sslEnabled) {
log.info("ssl configuration: trustStoreType = {}, cacertsFilePath = {}", trustStoreType, cacertsFilepath);
KeyStore truststore = KeyStore.getInstance(trustStoreType);
FileInputStream trustInputStream = new FileInputStream(cacertsFilepath);
try {
truststore.load(trustInputStream, trustStoreFilePassword.toCharArray());
} finally {
trustInputStream.close();
}
SSLContextBuilder sslBuilder = SSLContexts.custom().loadTrustMaterial(truststore, null);
log.info("ssl key configuration: keyStoreType = {}, keyFilePath = {}", keyStoreType, identityFilepath);
KeyStore keystore = KeyStore.getInstance(keyStoreType);
FileInputStream keyInputStream = new FileInputStream(identityFilepath);
try {
keystore.load(keyInputStream, keyStoreFilePassword.toCharArray());
} finally {
keyInputStream.close();
}
sslBuilder.loadKeyMaterial(keystore, keyStoreFilePassword.toCharArray());
final SSLContext sslContext = sslBuilder.build();
builder = builder.setHttpClientConfigCallback(httpAsyncClientBuilder -> httpAsyncClientBuilder.setSSLContext(sslContext).setSSLHostnameVerifier(new NoopHostnameVerifier()).setDefaultIOReactorConfig(IOReactorConfig.custom().setIoThreadCount(threadCount).build()));
} else {
builder = builder.setHttpClientConfigCallback(httpAsyncClientBuilder -> httpAsyncClientBuilder.setDefaultIOReactorConfig(IOReactorConfig.custom().setIoThreadCount(threadCount).build()));
}
// Configure timeouts
builder.setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder.setConnectionRequestTimeout(// Important, otherwise the client has spurious timeouts
0));
return builder.build();
}
use of org.elasticsearch.common.transport.InetSocketTransportAddress in project flink by apache.
the class ElasticsearchUtils method convertInetSocketAddresses.
/**
* Utility method to convert a {@link List} of {@link InetSocketAddress} to Elasticsearch {@link TransportAddress}.
*
* @param inetSocketAddresses The list of {@link InetSocketAddress} to convert.
*/
public static List<TransportAddress> convertInetSocketAddresses(List<InetSocketAddress> inetSocketAddresses) {
if (inetSocketAddresses == null) {
return null;
} else {
List<TransportAddress> converted;
converted = new ArrayList<>(inetSocketAddresses.size());
for (InetSocketAddress address : inetSocketAddresses) {
converted.add(new InetSocketTransportAddress(address));
}
return converted;
}
}
use of org.elasticsearch.common.transport.InetSocketTransportAddress in project titan by thinkaurelius.
the class ElasticSearchIndex method legacyConfiguration.
/**
* Configure ElasticSearchIndex's ES client according to 0.4.x - 0.5.0 semantics.
* This checks local-mode first. If local-mode is true, then it creates a Node that
* uses JVM local transport and can't talk over the network. If local-mode is
* false, then it creates a TransportClient that can talk over the network and
* uses {@link com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration#INDEX_HOSTS}
* as the server addresses. Note that this configuration method
* does not allow creating a Node that talks over the network.
* <p>
* This is activated by <b>not</b> setting an explicit value for {@link #INTERFACE} in the
* Titan configuration.
*
* @see #interfaceConfiguration(com.thinkaurelius.titan.diskstorage.configuration.Configuration)
* @param config a config passed to ElasticSearchIndex's constructor
* @return a node and client object open and ready for use
*/
private ElasticSearchSetup.Connection legacyConfiguration(Configuration config) {
Node node;
Client client;
if (config.get(LOCAL_MODE)) {
log.debug("Configuring ES for JVM local transport");
boolean clientOnly = config.get(CLIENT_ONLY);
boolean local = config.get(LOCAL_MODE);
NodeBuilder builder = NodeBuilder.nodeBuilder();
Preconditions.checkArgument(config.has(INDEX_CONF_FILE) || config.has(INDEX_DIRECTORY), "Must either configure configuration file or base directory");
if (config.has(INDEX_CONF_FILE)) {
String configFile = config.get(INDEX_CONF_FILE);
ImmutableSettings.Builder sb = ImmutableSettings.settingsBuilder();
log.debug("Configuring ES from YML file [{}]", configFile);
FileInputStream fis = null;
try {
fis = new FileInputStream(configFile);
sb.loadFromStream(configFile, fis);
builder.settings(sb.build());
} catch (FileNotFoundException e) {
throw new TitanException(e);
} finally {
IOUtils.closeQuietly(fis);
}
} else {
String dataDirectory = config.get(INDEX_DIRECTORY);
log.debug("Configuring ES with data directory [{}]", dataDirectory);
File f = new File(dataDirectory);
if (!f.exists())
f.mkdirs();
ImmutableSettings.Builder b = ImmutableSettings.settingsBuilder();
for (String sub : DATA_SUBDIRS) {
String subdir = dataDirectory + File.separator + sub;
f = new File(subdir);
if (!f.exists())
f.mkdirs();
b.put("path." + sub, subdir);
}
b.put("script.disable_dynamic", false);
b.put("indices.ttl.interval", "5s");
builder.settings(b.build());
String clustername = config.get(CLUSTER_NAME);
Preconditions.checkArgument(StringUtils.isNotBlank(clustername), "Invalid cluster name: %s", clustername);
builder.clusterName(clustername);
}
node = builder.client(clientOnly).data(!clientOnly).local(local).node();
client = node.client();
} else {
log.debug("Configuring ES for network transport");
ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder();
if (config.has(CLUSTER_NAME)) {
String clustername = config.get(CLUSTER_NAME);
Preconditions.checkArgument(StringUtils.isNotBlank(clustername), "Invalid cluster name: %s", clustername);
settings.put("cluster.name", clustername);
} else {
settings.put("client.transport.ignore_cluster_name", true);
}
log.debug("Transport sniffing enabled: {}", config.get(CLIENT_SNIFF));
settings.put("client.transport.sniff", config.get(CLIENT_SNIFF));
settings.put("script.disable_dynamic", false);
TransportClient tc = new TransportClient(settings.build());
int defaultPort = config.has(INDEX_PORT) ? config.get(INDEX_PORT) : HOST_PORT_DEFAULT;
for (String host : config.get(INDEX_HOSTS)) {
String[] hostparts = host.split(":");
String hostname = hostparts[0];
int hostport = defaultPort;
if (hostparts.length == 2)
hostport = Integer.parseInt(hostparts[1]);
log.info("Configured remote host: {} : {}", hostname, hostport);
tc.addTransportAddress(new InetSocketTransportAddress(hostname, hostport));
}
client = tc;
node = null;
}
return new ElasticSearchSetup.Connection(node, client);
}
use of org.elasticsearch.common.transport.InetSocketTransportAddress in project sonarqube by SonarSource.
the class SearchServerTest method start_stop_server.
@Test
public void start_stop_server() throws Exception {
Props props = new Props(new Properties());
// the following properties have always default values (see ProcessProperties)
InetAddress host = InetAddress.getLoopbackAddress();
props.set(ProcessProperties.SEARCH_HOST, host.getHostAddress());
props.set(ProcessProperties.SEARCH_PORT, String.valueOf(port));
props.set(ProcessProperties.CLUSTER_NAME, A_CLUSTER_NAME);
props.set(EsSettings.CLUSTER_SEARCH_NODE_NAME, A_NODE_NAME);
props.set(ProcessProperties.PATH_HOME, temp.newFolder().getAbsolutePath());
props.set(ProcessEntryPoint.PROPERTY_SHARED_PATH, temp.newFolder().getAbsolutePath());
underTest = new SearchServer(props);
underTest.start();
assertThat(underTest.getStatus()).isEqualTo(Monitored.Status.OPERATIONAL);
Settings settings = Settings.builder().put("cluster.name", A_CLUSTER_NAME).build();
client = TransportClient.builder().settings(settings).build().addTransportAddress(new InetSocketTransportAddress(host, port));
assertThat(client.admin().cluster().prepareClusterStats().get().getStatus()).isEqualTo(ClusterHealthStatus.GREEN);
underTest.stop();
underTest.awaitStop();
underTest = null;
try {
client.admin().cluster().prepareClusterStats().get();
fail();
} catch (NoNodeAvailableException exception) {
// ok
}
}
Aggregations