forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move list tasks under Tasks namespace
Our API spec define the tasks API as e.g. tasks.list, meaning that they belong to their own namespace. This commit moves them from the cluster namespace to their own namespace. Relates to elastic#29546
- Loading branch information
Showing
10 changed files
with
303 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
client/rest-high-level/src/main/java/org/elasticsearch/client/TasksClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.client; | ||
|
||
import org.apache.http.Header; | ||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest; | ||
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse; | ||
|
||
import java.io.IOException; | ||
|
||
import static java.util.Collections.emptySet; | ||
|
||
/** | ||
* A wrapper for the {@link RestHighLevelClient} that provides methods for accessing the Tasks API. | ||
* <p> | ||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/tasks.html">Task Management API on elastic.co</a> | ||
*/ | ||
public class TasksClient { | ||
private final RestHighLevelClient restHighLevelClient; | ||
|
||
TasksClient(RestHighLevelClient restHighLevelClient) { | ||
this.restHighLevelClient = restHighLevelClient; | ||
} | ||
|
||
/** | ||
* Get current tasks using the Task Management API | ||
* <p> | ||
* See | ||
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/tasks.html"> Task Management API on elastic.co</a> | ||
*/ | ||
public ListTasksResponse list(ListTasksRequest request, Header... headers) throws IOException { | ||
return restHighLevelClient.performRequestAndParseEntity(request, RequestConverters::listTasks, ListTasksResponse::fromXContent, | ||
emptySet(), headers); | ||
} | ||
|
||
/** | ||
* Asynchronously get current tasks using the Task Management API | ||
* <p> | ||
* See | ||
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/tasks.html"> Task Management API on elastic.co</a> | ||
*/ | ||
public void listAsync(ListTasksRequest request, ActionListener<ListTasksResponse> listener, Header... headers) { | ||
restHighLevelClient.performRequestAsyncAndParseEntity(request, RequestConverters::listTasks, ListTasksResponse::fromXContent, | ||
listener, emptySet(), headers); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
client/rest-high-level/src/test/java/org/elasticsearch/client/TasksIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.client; | ||
|
||
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest; | ||
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse; | ||
import org.elasticsearch.action.admin.cluster.node.tasks.list.TaskGroup; | ||
import org.elasticsearch.tasks.TaskInfo; | ||
|
||
import java.io.IOException; | ||
|
||
import static java.util.Collections.emptyList; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.greaterThanOrEqualTo; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
|
||
public class TasksIT extends ESRestHighLevelClientTestCase { | ||
|
||
public void testListTasks() throws IOException { | ||
ListTasksRequest request = new ListTasksRequest(); | ||
ListTasksResponse response = execute(request, highLevelClient().tasks()::list, highLevelClient().tasks()::listAsync); | ||
|
||
assertThat(response, notNullValue()); | ||
assertThat(response.getNodeFailures(), equalTo(emptyList())); | ||
assertThat(response.getTaskFailures(), equalTo(emptyList())); | ||
// It's possible that there are other tasks except 'cluster:monitor/tasks/lists[n]' and 'action":"cluster:monitor/tasks/lists' | ||
assertThat(response.getTasks().size(), greaterThanOrEqualTo(2)); | ||
boolean listTasksFound = false; | ||
for (TaskGroup taskGroup : response.getTaskGroups()) { | ||
TaskInfo parent = taskGroup.getTaskInfo(); | ||
if ("cluster:monitor/tasks/lists".equals(parent.getAction())) { | ||
assertThat(taskGroup.getChildTasks().size(), equalTo(1)); | ||
TaskGroup childGroup = taskGroup.getChildTasks().iterator().next(); | ||
assertThat(childGroup.getChildTasks().isEmpty(), equalTo(true)); | ||
TaskInfo child = childGroup.getTaskInfo(); | ||
assertThat(child.getAction(), equalTo("cluster:monitor/tasks/lists[n]")); | ||
assertThat(child.getParentTaskId(), equalTo(parent.getTaskId())); | ||
listTasksFound = true; | ||
} | ||
} | ||
assertTrue("List tasks were not found", listTasksFound); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.