-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Implemented a new endpoint to get running tasks by datasource #5260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -55,6 +55,7 @@ | |
| import io.druid.indexing.overlord.setup.WorkerBehaviorConfig; | ||
| import io.druid.java.util.common.DateTimes; | ||
| import io.druid.java.util.common.Intervals; | ||
| import io.druid.java.util.common.Pair; | ||
| import io.druid.java.util.common.StringUtils; | ||
| import io.druid.java.util.common.logger.Logger; | ||
| import io.druid.metadata.EntryExistsException; | ||
|
|
@@ -70,6 +71,7 @@ | |
| import io.druid.server.security.ResourceType; | ||
| import io.druid.tasklogs.TaskLogStreamer; | ||
| import io.druid.timeline.DataSegment; | ||
| import org.joda.time.DateTime; | ||
| import org.joda.time.Interval; | ||
|
|
||
| import javax.servlet.http.HttpServletRequest; | ||
|
|
@@ -460,7 +462,8 @@ public String apply(final TaskRunnerWorkItem workItem) | |
| new WaitingTask( | ||
| task.getId(), | ||
| task.getType(), | ||
| SettableFuture.create() | ||
| SettableFuture.create(), | ||
| task.getDataSource() | ||
| ) | ||
| { | ||
| @Override | ||
|
|
@@ -481,15 +484,18 @@ public TaskLocation getLocation() | |
| private static class WaitingTask extends TaskRunnerWorkItem | ||
| { | ||
| private final String taskType; | ||
| private final String dataSource; | ||
|
|
||
| WaitingTask( | ||
| String taskId, | ||
| String taskType, | ||
| ListenableFuture<TaskStatus> result | ||
| ListenableFuture<TaskStatus> result, | ||
| String dataSource | ||
| ) | ||
| { | ||
| super(taskId, result, DateTimes.EPOCH, DateTimes.EPOCH); | ||
| this.taskType = taskType; | ||
| this.dataSource = dataSource; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -503,6 +509,12 @@ public String getTaskType() | |
| { | ||
| return taskType; | ||
| } | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. formatting
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| @Override | ||
| public String getDataSource() | ||
| { | ||
| return dataSource; | ||
| } | ||
| } | ||
|
|
||
| @GET | ||
|
|
@@ -595,20 +607,22 @@ public Response getCompleteTasks( | |
| ) | ||
| ); | ||
|
|
||
| final List<TaskStatusPlus> completeTasks = recentlyFinishedTasks | ||
| .stream() | ||
| .map(status -> new TaskStatusPlus( | ||
| status.getId(), | ||
| taskFunction.apply(status.getId()).getType(), | ||
| taskStorageQueryAdapter.getCreatedTime(status.getId()), | ||
| // Would be nice to include the real queue insertion time, but the TaskStorage API doesn't yet allow it. | ||
| DateTimes.EPOCH, | ||
| status.getStatusCode(), | ||
| status.getDuration(), | ||
| TaskLocation.unknown() | ||
| ) | ||
| ) | ||
| .collect(Collectors.toList()); | ||
| final List<TaskStatusPlus> completeTasks = Lists.newArrayList(Iterables.transform( | ||
| recentlyFinishedTasks, | ||
| status -> { | ||
| final Pair<DateTime, String> pair = taskStorageQueryAdapter.getCreatedDateAndDataSource(status.getId()); | ||
| return new TaskStatusPlus( | ||
| status.getId(), | ||
| taskFunction.apply(status.getId()).getType(), | ||
| pair.lhs, | ||
| // Would be nice to include the real queue insertion time, but the | ||
| // TaskStorage API doesn't yet allow it. | ||
| DateTimes.EPOCH, | ||
| status.getStatusCode(), | ||
| status.getDuration(), | ||
| TaskLocation.unknown(), | ||
| pair.rhs); | ||
| })); | ||
|
|
||
| return Response.ok(completeTasks).build(); | ||
| } | ||
|
|
@@ -718,6 +732,26 @@ public Response doGetLog( | |
| } | ||
| } | ||
|
|
||
| @GET | ||
| @Path("/dataSources/{dataSource}") | ||
| @Produces(MediaType.APPLICATION_JSON) | ||
| public Response getRunningTasksByDataSource(@PathParam("dataSource") String dataSource, | ||
| @Context HttpServletRequest request) | ||
| { | ||
| Optional<TaskRunner> ts = taskMaster.getTaskRunner(); | ||
| if (!ts.isPresent()) { | ||
| return Response.status(Response.Status.NOT_FOUND).entity("No tasks are running").build(); | ||
| } | ||
| Collection<? extends TaskRunnerWorkItem> runningTasks = ts.get().getRunningTasks(); | ||
| if (runningTasks == null || runningTasks.isEmpty()) { | ||
| return Response.status(Response.Status.NOT_FOUND) | ||
| .entity("No running tasks found for the datasource : " + dataSource).build(); | ||
| } | ||
| List<TaskRunnerWorkItem> taskRunnerWorkItemList = runningTasks.stream() | ||
| .filter(task -> dataSource.equals(task.getDataSource())).collect(Collectors.toList()); | ||
| return Response.ok(taskRunnerWorkItemList).build(); | ||
| } | ||
|
|
||
| private Response workItemsResponse(final Function<TaskRunner, Collection<? extends TaskRunnerWorkItem>> fn) | ||
| { | ||
| return asLeaderWith( | ||
|
|
@@ -742,7 +776,8 @@ public TaskStatusPlus apply(TaskRunnerWorkItem workItem) | |
| workItem.getQueueInsertionTime(), | ||
| null, | ||
| null, | ||
| workItem.getLocation() | ||
| workItem.getLocation(), | ||
| workItem.getDataSource() | ||
| ); | ||
| } | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done