use of org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest in project OpenSearch by opensearch-project.
the class IndicesRequestConverters method clearCache.
static Request clearCache(ClearIndicesCacheRequest clearIndicesCacheRequest) {
String[] indices = clearIndicesCacheRequest.indices() == null ? Strings.EMPTY_ARRAY : clearIndicesCacheRequest.indices();
Request request = new Request(HttpPost.METHOD_NAME, RequestConverters.endpoint(indices, "_cache/clear"));
RequestConverters.Params parameters = new RequestConverters.Params();
parameters.withIndicesOptions(clearIndicesCacheRequest.indicesOptions());
parameters.putParam("query", Boolean.toString(clearIndicesCacheRequest.queryCache()));
parameters.putParam("fielddata", Boolean.toString(clearIndicesCacheRequest.fieldDataCache()));
parameters.putParam("request", Boolean.toString(clearIndicesCacheRequest.requestCache()));
parameters.putParam("fields", String.join(",", clearIndicesCacheRequest.fields()));
request.addParameters(parameters.asMap());
return request;
}
use of org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest in project OpenSearch by opensearch-project.
the class IndicesRequestIT method testClearCache.
public void testClearCache() {
String clearCacheAction = ClearIndicesCacheAction.NAME + "[n]";
interceptTransportActions(clearCacheAction);
ClearIndicesCacheRequest clearIndicesCacheRequest = new ClearIndicesCacheRequest(randomIndicesOrAliases());
internalCluster().coordOnlyNodeClient().admin().indices().clearCache(clearIndicesCacheRequest).actionGet();
clearInterceptedActions();
assertSameIndices(clearIndicesCacheRequest, clearCacheAction);
}
use of org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest in project OpenSearch by opensearch-project.
the class IndicesRequestConvertersTests method testClearCache.
public void testClearCache() {
String[] indices = OpenSearchTestCase.randomBoolean() ? null : RequestConvertersTests.randomIndicesNames(0, 5);
ClearIndicesCacheRequest clearIndicesCacheRequest;
if (OpenSearchTestCase.randomBoolean()) {
clearIndicesCacheRequest = new ClearIndicesCacheRequest(indices);
} else {
clearIndicesCacheRequest = new ClearIndicesCacheRequest();
clearIndicesCacheRequest.indices(indices);
}
Map<String, String> expectedParams = new HashMap<>();
RequestConvertersTests.setRandomIndicesOptions(clearIndicesCacheRequest::indicesOptions, clearIndicesCacheRequest::indicesOptions, expectedParams);
if (OpenSearchTestCase.randomBoolean()) {
clearIndicesCacheRequest.queryCache(OpenSearchTestCase.randomBoolean());
}
expectedParams.put("query", Boolean.toString(clearIndicesCacheRequest.queryCache()));
if (OpenSearchTestCase.randomBoolean()) {
clearIndicesCacheRequest.fieldDataCache(OpenSearchTestCase.randomBoolean());
}
expectedParams.put("fielddata", Boolean.toString(clearIndicesCacheRequest.fieldDataCache()));
if (OpenSearchTestCase.randomBoolean()) {
clearIndicesCacheRequest.requestCache(OpenSearchTestCase.randomBoolean());
}
expectedParams.put("request", Boolean.toString(clearIndicesCacheRequest.requestCache()));
if (OpenSearchTestCase.randomBoolean()) {
clearIndicesCacheRequest.fields(RequestConvertersTests.randomIndicesNames(1, 5));
expectedParams.put("fields", String.join(",", clearIndicesCacheRequest.fields()));
}
Request request = IndicesRequestConverters.clearCache(clearIndicesCacheRequest);
StringJoiner endpoint = new StringJoiner("/", "/", "");
if (indices != null && indices.length > 0) {
endpoint.add(String.join(",", indices));
}
endpoint.add("_cache/clear");
Assert.assertThat(request.getEndpoint(), equalTo(endpoint.toString()));
Assert.assertThat(request.getParameters(), equalTo(expectedParams));
Assert.assertThat(request.getEntity(), nullValue());
Assert.assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME));
}
use of org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest in project OpenSearch by opensearch-project.
the class RestClearIndicesCacheAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
ClearIndicesCacheRequest clearIndicesCacheRequest = new ClearIndicesCacheRequest(Strings.splitStringByCommaToArray(request.param("index")));
clearIndicesCacheRequest.indicesOptions(IndicesOptions.fromRequest(request, clearIndicesCacheRequest.indicesOptions()));
fromRequest(request, clearIndicesCacheRequest);
return channel -> client.admin().indices().clearCache(clearIndicesCacheRequest, new RestToXContentListener<>(channel));
}
use of org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest in project OpenSearch by opensearch-project.
the class RestClearIndicesCacheActionTests method testRequestCacheSet.
public void testRequestCacheSet() throws Exception {
final HashMap<String, String> params = new HashMap<>();
params.put("request", "true");
final RestRequest restRequest = new FakeRestRequest.Builder(xContentRegistry()).withParams(params).build();
ClearIndicesCacheRequest cacheRequest = new ClearIndicesCacheRequest();
cacheRequest = RestClearIndicesCacheAction.fromRequest(restRequest, cacheRequest);
assertThat(cacheRequest.requestCache(), equalTo(true));
}
Aggregations