Search in sources :

Example 1 with JestClientFactory

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();
}
Also used : Builder(io.searchbox.client.config.HttpClientConfig.Builder) JestClientFactory(io.searchbox.client.JestClientFactory) JestHttpClient(io.searchbox.client.http.JestHttpClient)

Example 2 with JestClientFactory

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();
        }
    }
}
Also used : HttpClientConfig(io.searchbox.client.config.HttpClientConfig) Search(io.searchbox.core.Search) SearchResult(io.searchbox.core.SearchResult) JestClient(io.searchbox.client.JestClient) JestClientFactory(io.searchbox.client.JestClientFactory) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder)

Example 3 with JestClientFactory

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;
    });
}
Also used : HttpClientConfig(io.searchbox.client.config.HttpClientConfig) Search(io.searchbox.core.Search) SearchResult(io.searchbox.core.SearchResult) JestClient(io.searchbox.client.JestClient) JestClientFactory(io.searchbox.client.JestClientFactory) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder)

Example 4 with JestClientFactory

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());
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) NodeBuilder(org.elasticsearch.node.NodeBuilder) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) JestClientFactory(io.searchbox.client.JestClientFactory) Property(org.ff4j.property.Property) IndicesExists(io.searchbox.indices.IndicesExists)

Example 5 with JestClientFactory

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();
}
Also used : HttpClientConfig(io.searchbox.client.config.HttpClientConfig) JestClientFactory(io.searchbox.client.JestClientFactory)

Aggregations

JestClientFactory (io.searchbox.client.JestClientFactory)14 HttpClientConfig (io.searchbox.client.config.HttpClientConfig)9 JestClient (io.searchbox.client.JestClient)3 Search (io.searchbox.core.Search)3 SearchResult (io.searchbox.core.SearchResult)3 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)3 GsonBuilder (com.google.gson.GsonBuilder)2 Builder (io.searchbox.client.config.HttpClientConfig.Builder)2 Gson (com.google.gson.Gson)1 JestHttpClient (io.searchbox.client.http.JestHttpClient)1 Bulk (io.searchbox.core.Bulk)1 IndicesExists (io.searchbox.indices.IndicesExists)1 URL (java.net.URL)1 KeyManagementException (java.security.KeyManagementException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 CertificateException (java.security.cert.CertificateException)1 X509Certificate (java.security.cert.X509Certificate)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1