use of io.searchbox.client.JestClientFactory in project gerrit by GerritCodeReview.
the class JestClientBuilder method build.
JestHttpClient build() {
JestClientFactory factory = new JestClientFactory();
Builder builder = new HttpClientConfig.Builder(cfg.urls).multiThreaded(true).discoveryEnabled(false).connTimeout((int) cfg.connectionTimeout).maxConnectionIdleTime(cfg.maxConnectionIdleTime, cfg.maxConnectionIdleUnit).maxTotalConnection(cfg.maxTotalConnection).readTimeout(cfg.readTimeout).requestCompressionEnabled(cfg.requestCompression).discoveryFrequency(1L, TimeUnit.MINUTES);
if (cfg.username != null && cfg.password != null) {
builder.defaultCredentials(cfg.username, cfg.password);
}
factory.setHttpClientConfig(builder.build());
return (JestHttpClient) factory.getObject();
}
use of io.searchbox.client.JestClientFactory in project opennms by OpenNMS.
the class AlarmElasticsearch5IT method getNumberOfAlarmsInEsWithUei.
private static int getNumberOfAlarmsInEsWithUei(InetSocketAddress esHttpAddr, String uei) throws IOException {
JestClient client = null;
try {
JestClientFactory factory = new JestClientFactory();
factory.setHttpClientConfig(new HttpClientConfig.Builder(String.format("http://%s:%d", esHttpAddr.getHostString(), esHttpAddr.getPort())).multiThreaded(true).build());
client = factory.getObject();
SearchResult response = client.execute(new Search.Builder(new SearchSourceBuilder().query(QueryBuilders.matchQuery("eventuei", EventConstants.IMPORT_FAILED_UEI)).toString()).addIndex("opennms-alarms*").build());
LOG.debug("SEARCH RESPONSE: {}", response.toString());
return response.getTotal();
} finally {
if (client != null) {
client.shutdownClient();
}
}
}
use of io.searchbox.client.JestClientFactory in project opennms by OpenNMS.
the class AbstractSyslogTestCase method pollForElasticsearchEventsUsingJest.
protected static void pollForElasticsearchEventsUsingJest(Supplier<InetSocketAddress> esTransportAddr, int numMessages) {
with().pollInterval(15, SECONDS).await().atMost(5, MINUTES).until(() -> {
JestClient client = null;
try {
JestClientFactory factory = new JestClientFactory();
factory.setHttpClientConfig(new HttpClientConfig.Builder(String.format("http://%s:%d", esTransportAddr.get().getHostString(), esTransportAddr.get().getPort())).multiThreaded(true).build());
client = factory.getObject();
SearchResult response = client.execute(new Search.Builder(new SearchSourceBuilder().query(QueryBuilders.matchQuery("eventuei", "uei.opennms.org/vendor/cisco/syslog/SEC-6-IPACCESSLOGP/aclDeniedIPTraffic")).toString()).addIndex("opennms*").build());
LOG.debug("SEARCH RESPONSE: {}", response.toString());
// Sometimes, the first warm-up message is successful so treat both message counts as valid
assertTrue("ES search hits was not equal to " + numMessages + ": " + response.getTotal(), (numMessages == response.getTotal()));
// assertEquals("Event UEI did not match", "uei.opennms.org/vendor/cisco/syslog/SEC-6-IPACCESSLOGP/aclDeniedIPTraffic", response.getHits().getAt(0).getSource().get("eventuei"));
// assertEquals("Event IP address did not match", "4.2.2.2", response.getHits().getAt(0).getSource().get("ipaddr"));
} catch (Throwable e) {
LOG.warn(e.getMessage(), e);
return false;
} finally {
if (client != null) {
client.shutdownClient();
}
}
return true;
});
}
use of io.searchbox.client.JestClientFactory in project ff4j by ff4j.
the class ElasticConnection method initJestClient.
private void initJestClient() throws IOException {
JestClientFactory factory = new JestClientFactory();
// Custom feature converter is required
Gson gson = //
new GsonBuilder().registerTypeAdapter(Feature.class, //
new FeatureConverter()).registerTypeAdapter(Property.class, //
new PropertyConverter()).create();
factory.setHttpClientConfig(//
new HttpClientConfig.Builder(mapUrl()).multiThreaded(//
true).gson(//
gson).build());
jestClient = factory.getObject();
boolean indexExists = jestClient.execute(new IndicesExists.Builder(indexName).build()).isSucceeded();
if (indexExists) {
jestClient.execute(new DeleteIndex.Builder(indexName).build());
}
jestClient.execute(new CreateIndex.Builder(indexName).build());
}
use of io.searchbox.client.JestClientFactory in project vind by RBMHTechnology.
the class ElasticSearchClientBuilder method build.
public static JestClient build(String host, String port) {
final String conn = String.format("http://%s:%s", host, port);
log.info("Creating ElasticSearch REST Client over {}..,", conn);
final JestClientFactory factory = new JestClientFactory();
factory.setHttpClientConfig(new HttpClientConfig.Builder(conn).multiThreaded(true).build());
return factory.getObject();
}
Aggregations