io.searchbox.cluster.Health Java Examples

The following examples show how to use io.searchbox.cluster.Health. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractClientFactory.java    From apiman with Apache License 2.0 7 votes vote down vote up
/**
 * Called to initialize the storage.
 * @param client the jest client
 * @param indexName the name of the ES index to initialize
 * @param defaultIndexName the default ES index - used to determine which -settings.json file to use
 */
protected void initializeClient(JestClient client, String indexName, String defaultIndexName) {
    try {
        client.execute(new Health.Builder().build());
        Action<JestResult> action = new IndicesExists.Builder(indexName).build();
        // There was occasions where a race occurred here when multiple threads try to
        // create the index simultaneously. This caused a non-fatal, but annoying, exception.
        synchronized(AbstractClientFactory.class) {
            JestResult result = client.execute(action);
            if (!result.isSucceeded()) {
                createIndex(client, indexName, defaultIndexName + "-settings.json"); //$NON-NLS-1$
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #2
Source File: IndexerManagerBeanTest.java    From eplmp with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void pingTest() throws IOException {
    Health health = new Health.Builder().build();
    JestResult result = new JestResult(new Gson());
    Mockito.when(esClient.execute(health))
            .thenReturn(result);

    result.setSucceeded(false);
    Assert.assertFalse(indexerManagerBean.ping());

    result.setSucceeded(true);
    Assert.assertTrue(indexerManagerBean.ping());

    Mockito.when(esClient.execute(health)).thenThrow(new IOException());
    Assert.assertFalse(indexerManagerBean.ping());
}
 
Example #3
Source File: IndexerManagerBean.java    From eplmp with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Check for indexer availability
 *
 * @return ping result
 */
@Override
public boolean ping() {
    try {
        JestResult result = esClient.execute(new Health.Builder().build());
        return result.isSucceeded();
    } catch (IOException e) {
        return false;
    }
}