Search in sources :

Example 1 with RethrottleRequestBuilder

use of org.opensearch.index.reindex.RethrottleRequestBuilder in project OpenSearch by opensearch-project.

the class ReindexDocumentationIT method testTasks.

public void testTasks() throws Exception {
    final Client client = client();
    final ReindexRequestBuilder builder = reindexAndPartiallyBlock();
    {
        // tag::update-by-query-list-tasks
        ListTasksResponse tasksList = client.admin().cluster().prepareListTasks().setActions(UpdateByQueryAction.NAME).setDetailed(true).get();
        for (TaskInfo info : tasksList.getTasks()) {
            TaskId taskId = info.getTaskId();
            BulkByScrollTask.Status status = (BulkByScrollTask.Status) info.getStatus();
        // do stuff
        }
    // end::update-by-query-list-tasks
    }
    TaskInfo mainTask = CancelTests.findTaskToCancel(ReindexAction.NAME, builder.request().getSlices());
    BulkByScrollTask.Status status = (BulkByScrollTask.Status) mainTask.getStatus();
    assertNull(status.getReasonCancelled());
    TaskId taskId = mainTask.getTaskId();
    {
        // tag::update-by-query-get-task
        GetTaskResponse get = client.admin().cluster().prepareGetTask(taskId).get();
    // end::update-by-query-get-task
    }
    {
        // tag::update-by-query-cancel-task
        // Cancel all update-by-query requests
        client.admin().cluster().prepareCancelTasks().setActions(UpdateByQueryAction.NAME).get().getTasks();
        // Cancel a specific update-by-query request
        client.admin().cluster().prepareCancelTasks().setTaskId(taskId).get().getTasks();
    // end::update-by-query-cancel-task
    }
    {
        // tag::update-by-query-rethrottle
        new RethrottleRequestBuilder(client, RethrottleAction.INSTANCE).setTaskId(taskId).setRequestsPerSecond(2.0f).get();
    // end::update-by-query-rethrottle
    }
    // unblocking the blocked update
    ALLOWED_OPERATIONS.release(builder.request().getSlices());
}
Also used : TaskInfo(org.opensearch.tasks.TaskInfo) TaskId(org.opensearch.tasks.TaskId) ReindexRequestBuilder(org.opensearch.index.reindex.ReindexRequestBuilder) GetTaskResponse(org.opensearch.action.admin.cluster.node.tasks.get.GetTaskResponse) BulkByScrollTask(org.opensearch.index.reindex.BulkByScrollTask) Client(org.opensearch.client.Client) ListTasksResponse(org.opensearch.action.admin.cluster.node.tasks.list.ListTasksResponse) RethrottleRequestBuilder(org.opensearch.index.reindex.RethrottleRequestBuilder)

Aggregations

GetTaskResponse (org.opensearch.action.admin.cluster.node.tasks.get.GetTaskResponse)1 ListTasksResponse (org.opensearch.action.admin.cluster.node.tasks.list.ListTasksResponse)1 Client (org.opensearch.client.Client)1 BulkByScrollTask (org.opensearch.index.reindex.BulkByScrollTask)1 ReindexRequestBuilder (org.opensearch.index.reindex.ReindexRequestBuilder)1 RethrottleRequestBuilder (org.opensearch.index.reindex.RethrottleRequestBuilder)1 TaskId (org.opensearch.tasks.TaskId)1 TaskInfo (org.opensearch.tasks.TaskInfo)1