private void clearLookupCache(String viewUuid) { try { esClient.prepareClearCache() .setQueryCache(true) .get(); } catch (Exception e) { throw new IllegalStateException(String.format("Unable to clear lookup cache of view '%s'", viewUuid), e); } }
@Override public String toString() { StringBuilder message = new StringBuilder(); message.append("ES clear cache request"); if (request.indices().length > 0) { message.append(String.format(" on indices '%s'", StringUtils.join(request.indices(), ","))); } String[] fields = request.fields(); if (fields != null && fields.length > 0) { message.append(String.format(" on fields '%s'", StringUtils.join(fields, ","))); } if (request.queryCache()) { message.append(" with filter cache"); } if (request.fieldDataCache()) { message.append(" with field data cache"); } if (request.requestCache()) { message.append(" with request cache"); } return message.toString(); } }
@Override public ClearIndicesCacheResponse get() { Profiler profiler = Profiler.createIfTrace(EsClient.LOGGER).start(); try { return super.execute().actionGet(); } catch (Exception e) { throw new IllegalStateException(String.format("Fail to execute %s", toString()), e); } finally { if (profiler.isTraceEnabled()) { profiler.stopTrace(toString()); } } }
@Override protected ClearIndicesCacheRequest readRequestFrom(StreamInput in) throws IOException { final ClearIndicesCacheRequest request = new ClearIndicesCacheRequest(); request.readFrom(in); return request; }
public ClearIndicesCacheRequestBuilder setFields(String... fields) { request.fields(fields); return this; }
public ClearIndicesCacheRequestBuilder setFieldDataCache(boolean fieldDataCache) { request.fieldDataCache(fieldDataCache); return this; }
@Test public void clear_cache() { ClearIndicesCacheRequestBuilder requestBuilder = es.client().prepareClearCache(); requestBuilder.get(); }
public ClearIndicesCacheRequestBuilder setRequestCache(boolean requestCache) { request.requestCache(requestCache); return this; }
public ClearIndicesCacheRequestBuilder setQueryCache(boolean queryCache) { request.queryCache(queryCache); return this; }
@Override public ClearIndicesCacheRequestBuilder prepareClearCache(String... indices) { return new ClearIndicesCacheRequestBuilder(this, ClearIndicesCacheAction.INSTANCE).setIndices(indices); }
/** * Creates a clean indices cache request. * * @param indices The indices to clean their caches. Use {@code null} or {@code _all} to execute against all indices * @return The request */ public static ClearIndicesCacheRequest clearIndicesCacheRequest(String... indices) { return new ClearIndicesCacheRequest(indices); }
@Override public ClearIndicesCacheRequestBuilder newRequestBuilder(ElasticsearchClient client) { return new ClearIndicesCacheRequestBuilder(client, this); } }
@Override protected ClearIndicesCacheResponse newResponse(ClearIndicesCacheRequest request, int totalShards, int successfulShards, int failedShards, List<EmptyResult> responses, List<DefaultShardOperationFailedException> shardFailures, ClusterState clusterState) { return new ClearIndicesCacheResponse(totalShards, successfulShards, failedShards, shardFailures); }
@Test public void to_string() { assertThat(es.client().prepareClearCache().toString()).isEqualTo("ES clear cache request"); assertThat(es.client().prepareClearCache("rules").toString()).isEqualTo("ES clear cache request on indices 'rules'"); assertThat(es.client().prepareClearCache().setFields("key").toString()).isEqualTo("ES clear cache request on fields 'key'"); assertThat(es.client().prepareClearCache().setFieldDataCache(true).toString()).isEqualTo("ES clear cache request with field data cache"); assertThat(es.client().prepareClearCache().setRequestCache(true).toString()).isEqualTo("ES clear cache request with request cache"); }
@Test public void get_with_string_timeout_is_not_yet_implemented() { try { es.client().prepareClearCache().get("1"); fail(); } catch (Exception e) { assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented"); } }
@Test public void execute_should_throw_an_unsupported_operation_exception() { try { es.client().prepareClearCache().execute(); fail(); } catch (Exception e) { assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous"); } }
@Test public void get_with_time_value_timeout_is_not_yet_implemented() { try { es.client().prepareClearCache().get(TimeValue.timeValueMinutes(1)); fail(); } catch (Exception e) { assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented"); } }
@Test public void no_trace_logs() { logTester.setLevel(LoggerLevel.DEBUG); ClearIndicesCacheRequestBuilder requestBuilder = es.client().prepareClearCache(); requestBuilder.get(); assertThat(logTester.logs()).isEmpty(); }
@Test public void trace_logs() { logTester.setLevel(LoggerLevel.TRACE); ClearIndicesCacheRequestBuilder requestBuilder = es.client().prepareClearCache(); requestBuilder.get(); assertThat(logTester.logs()).hasSize(1); }
public void clearIndexes() { Loggers.get(getClass()).info("Truncate Elasticsearch indices"); try { esClient.prepareClearCache().get(); for (String index : esClient.prepareState().get().getState().getMetaData().getConcreteAllIndices()) { clearIndex(new IndexType(index, index)); } } catch (Exception e) { throw new IllegalStateException("Unable to clear indexes", e); } }