Search in sources :

Example 1 with ClearIndicesCacheRequest

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;
}
Also used : UpdateSettingsRequest(org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest) CreateIndexRequest(org.opensearch.client.indices.CreateIndexRequest) SimulateIndexTemplateRequest(org.opensearch.client.indices.SimulateIndexTemplateRequest) FlushRequest(org.opensearch.action.admin.indices.flush.FlushRequest) RefreshRequest(org.opensearch.action.admin.indices.refresh.RefreshRequest) GetIndexRequest(org.opensearch.client.indices.GetIndexRequest) DeleteAliasRequest(org.opensearch.client.indices.DeleteAliasRequest) OpenIndexRequest(org.opensearch.action.admin.indices.open.OpenIndexRequest) GetFieldMappingsRequest(org.opensearch.client.indices.GetFieldMappingsRequest) ForceMergeRequest(org.opensearch.action.admin.indices.forcemerge.ForceMergeRequest) GetSettingsRequest(org.opensearch.action.admin.indices.settings.get.GetSettingsRequest) GetDataStreamRequest(org.opensearch.client.indices.GetDataStreamRequest) DeleteIndexRequest(org.opensearch.action.admin.indices.delete.DeleteIndexRequest) ComposableIndexTemplateExistRequest(org.opensearch.client.indices.ComposableIndexTemplateExistRequest) AnalyzeRequest(org.opensearch.client.indices.AnalyzeRequest) ResizeRequest(org.opensearch.client.indices.ResizeRequest) GetComposableIndexTemplateRequest(org.opensearch.client.indices.GetComposableIndexTemplateRequest) DataStreamsStatsRequest(org.opensearch.client.indices.DataStreamsStatsRequest) DeleteIndexTemplateRequest(org.opensearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest) CloseIndexRequest(org.opensearch.client.indices.CloseIndexRequest) GetIndexTemplatesRequest(org.opensearch.client.indices.GetIndexTemplatesRequest) GetMappingsRequest(org.opensearch.client.indices.GetMappingsRequest) GetAliasesRequest(org.opensearch.action.admin.indices.alias.get.GetAliasesRequest) PutComposableIndexTemplateRequest(org.opensearch.client.indices.PutComposableIndexTemplateRequest) CreateDataStreamRequest(org.opensearch.client.indices.CreateDataStreamRequest) IndicesAliasesRequest(org.opensearch.action.admin.indices.alias.IndicesAliasesRequest) PutMappingRequest(org.opensearch.client.indices.PutMappingRequest) DeleteComposableIndexTemplateRequest(org.opensearch.client.indices.DeleteComposableIndexTemplateRequest) PutIndexTemplateRequest(org.opensearch.client.indices.PutIndexTemplateRequest) ValidateQueryRequest(org.opensearch.action.admin.indices.validate.query.ValidateQueryRequest) DeleteDataStreamRequest(org.opensearch.client.indices.DeleteDataStreamRequest) ClearIndicesCacheRequest(org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest) IndexTemplatesExistRequest(org.opensearch.client.indices.IndexTemplatesExistRequest) RolloverRequest(org.opensearch.client.indices.rollover.RolloverRequest)

Example 2 with ClearIndicesCacheRequest

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);
}
Also used : ClearIndicesCacheRequest(org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest)

Example 3 with ClearIndicesCacheRequest

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));
}
Also used : HashMap(java.util.HashMap) ClearIndicesCacheRequest(org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest) UpdateSettingsRequest(org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest) RefreshRequest(org.opensearch.action.admin.indices.refresh.RefreshRequest) OpenIndexRequest(org.opensearch.action.admin.indices.open.OpenIndexRequest) ForceMergeRequest(org.opensearch.action.admin.indices.forcemerge.ForceMergeRequest) GetDataStreamRequest(org.opensearch.client.indices.GetDataStreamRequest) AnalyzeRequest(org.opensearch.client.indices.AnalyzeRequest) DeleteIndexTemplateRequest(org.opensearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest) AcknowledgedRequest(org.opensearch.action.support.master.AcknowledgedRequest) PutMappingRequest(org.opensearch.client.indices.PutMappingRequest) PutIndexTemplateRequest(org.opensearch.client.indices.PutIndexTemplateRequest) DeleteDataStreamRequest(org.opensearch.client.indices.DeleteDataStreamRequest) ClearIndicesCacheRequest(org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest) RolloverRequest(org.opensearch.client.indices.rollover.RolloverRequest) CreateIndexRequest(org.opensearch.client.indices.CreateIndexRequest) FlushRequest(org.opensearch.action.admin.indices.flush.FlushRequest) GetIndexRequest(org.opensearch.client.indices.GetIndexRequest) DeleteAliasRequest(org.opensearch.client.indices.DeleteAliasRequest) GetFieldMappingsRequest(org.opensearch.client.indices.GetFieldMappingsRequest) GetSettingsRequest(org.opensearch.action.admin.indices.settings.get.GetSettingsRequest) DeleteIndexRequest(org.opensearch.action.admin.indices.delete.DeleteIndexRequest) ResizeRequest(org.opensearch.client.indices.ResizeRequest) CloseIndexRequest(org.opensearch.client.indices.CloseIndexRequest) GetIndexTemplatesRequest(org.opensearch.client.indices.GetIndexTemplatesRequest) GetMappingsRequest(org.opensearch.client.indices.GetMappingsRequest) GetAliasesRequest(org.opensearch.action.admin.indices.alias.get.GetAliasesRequest) CreateDataStreamRequest(org.opensearch.client.indices.CreateDataStreamRequest) IndicesAliasesRequest(org.opensearch.action.admin.indices.alias.IndicesAliasesRequest) ValidateQueryRequest(org.opensearch.action.admin.indices.validate.query.ValidateQueryRequest) IndexTemplatesExistRequest(org.opensearch.client.indices.IndexTemplatesExistRequest) StringJoiner(java.util.StringJoiner)

Example 4 with ClearIndicesCacheRequest

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));
}
Also used : POST(org.opensearch.rest.RestRequest.Method.POST) List(java.util.List) NodeClient(org.opensearch.client.node.NodeClient) RestToXContentListener(org.opensearch.rest.action.RestToXContentListener) Collections.unmodifiableList(java.util.Collections.unmodifiableList) RestRequest(org.opensearch.rest.RestRequest) Arrays.asList(java.util.Arrays.asList) IOException(java.io.IOException) IndicesOptions(org.opensearch.action.support.IndicesOptions) BaseRestHandler(org.opensearch.rest.BaseRestHandler) ClearIndicesCacheRequest(org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest) Strings(org.opensearch.common.Strings) ClearIndicesCacheRequest(org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest)

Example 5 with ClearIndicesCacheRequest

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));
}
Also used : FakeRestRequest(org.opensearch.test.rest.FakeRestRequest) RestRequest(org.opensearch.rest.RestRequest) HashMap(java.util.HashMap) ClearIndicesCacheRequest(org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest)

Aggregations

ClearIndicesCacheRequest (org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest)5 HashMap (java.util.HashMap)2 IndicesAliasesRequest (org.opensearch.action.admin.indices.alias.IndicesAliasesRequest)2 GetAliasesRequest (org.opensearch.action.admin.indices.alias.get.GetAliasesRequest)2 DeleteIndexRequest (org.opensearch.action.admin.indices.delete.DeleteIndexRequest)2 FlushRequest (org.opensearch.action.admin.indices.flush.FlushRequest)2 ForceMergeRequest (org.opensearch.action.admin.indices.forcemerge.ForceMergeRequest)2 OpenIndexRequest (org.opensearch.action.admin.indices.open.OpenIndexRequest)2 RefreshRequest (org.opensearch.action.admin.indices.refresh.RefreshRequest)2 GetSettingsRequest (org.opensearch.action.admin.indices.settings.get.GetSettingsRequest)2 UpdateSettingsRequest (org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest)2 DeleteIndexTemplateRequest (org.opensearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest)2 ValidateQueryRequest (org.opensearch.action.admin.indices.validate.query.ValidateQueryRequest)2 AnalyzeRequest (org.opensearch.client.indices.AnalyzeRequest)2 CloseIndexRequest (org.opensearch.client.indices.CloseIndexRequest)2 CreateDataStreamRequest (org.opensearch.client.indices.CreateDataStreamRequest)2 CreateIndexRequest (org.opensearch.client.indices.CreateIndexRequest)2 DeleteAliasRequest (org.opensearch.client.indices.DeleteAliasRequest)2 DeleteDataStreamRequest (org.opensearch.client.indices.DeleteDataStreamRequest)2 GetDataStreamRequest (org.opensearch.client.indices.GetDataStreamRequest)2