Skip to content
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

Get task info by runId #813

Merged
merged 7 commits into from Dec 29, 2015
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -29,6 +29,9 @@ public interface HistoryJDBI {
@SqlQuery("SELECT bytes FROM taskHistory WHERE taskId = :taskId")
byte[] getTaskHistoryForTask(@Bind("taskId") String taskId);

@SqlQuery("SELECT bytes FROM taskHistory WHERE requestId = :requestId AND runId = :runId")
byte[] getTaskHistoryForTaskByRunId(@Bind("requestId") String requestId, @Bind("runId") String runId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we index on runId?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not currently, we would probably need to for this case

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, we should add an index. let me know if you need a hand with this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an index in b63cf47 , can someone with more mysql chops double check that please?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syncing up w/ monty about this

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which query/queries will benefit from the added index in b63cf47?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The one on the line for this comment thread:
SELECT bytes FROM taskHistory WHERE requestId = :requestId AND runId = :runId


@SqlQuery("SELECT bytes FROM deployHistory WHERE requestId = :requestId AND deployId = :deployId")
byte[] getDeployHistoryForDeploy(@Bind("requestId") String requestId, @Bind("deployId") String deployId);

Expand Down
Expand Up @@ -32,6 +32,8 @@ public enum OrderDirection {

Optional<SingularityTaskHistory> getTaskHistory(String taskId);

Optional<SingularityTaskHistory> getTaskHistoryByRunId(String requestId, String runId);

List<SingularityRequestHistory> getRequestHistory(String requestId, Optional<OrderDirection> orderDirection, Integer limitStart, Integer limitCount);

List<String> getRequestHistoryLike(String requestIdLike, Integer limitStart, Integer limitCount);
Expand Down
Expand Up @@ -120,6 +120,17 @@ public Optional<SingularityTaskHistory> getTaskHistory(String taskId) {
return Optional.of(taskHistoryTranscoder.fromBytes(historyBytes));
}

@Override
public Optional<SingularityTaskHistory> getTaskHistoryByRunId(String requestId, String runId) {
byte[] historyBytes = history.getTaskHistoryForTaskByRunId(requestId, runId);

if (historyBytes == null || historyBytes.length == 0) {
return Optional.absent();
}

return Optional.of(taskHistoryTranscoder.fromBytes(historyBytes));
}

@Override
public List<SingularityRequestIdCount> getRequestIdCounts(Date before) {
return history.getRequestIdCounts(before);
Expand Down
Expand Up @@ -59,6 +59,11 @@ public Optional<SingularityTaskHistory> getTaskHistory(String taskId) {
return Optional.absent();
}

@Override
public Optional<SingularityTaskHistory> getTaskHistoryByRunId(String requestId, String runId) {
return Optional.absent();
}

@Override
public List<SingularityRequestHistory> getRequestHistory(String requestId, Optional<OrderDirection> orderDirection, Integer limitStart, Integer limitCount) {
return Collections.emptyList();
Expand Down
Expand Up @@ -50,4 +50,20 @@ public Optional<SingularityTask> getTask(SingularityTaskId taskId) {
return Optional.absent();
}

public Optional<SingularityTaskIdHistory> getByRunId(String requestId, String runId) {
for (SingularityTaskIdHistory history : getFromZk(requestId)) {
if (history.getRunId().isPresent() && history.getRunId().get().equals(runId)) {
return Optional.of(history);
}
}

Optional<SingularityTaskHistory> history = historyManager.getTaskHistoryByRunId(requestId, runId);

if (history.isPresent()) {
return Optional.of(SingularityTaskIdHistory.fromTaskIdAndTaskAndUpdates(history.get().getTask().getTaskId(), history.get().getTask(), history.get().getTaskUpdates()));
}

return Optional.absent();
}

}
Expand Up @@ -152,6 +152,18 @@ public List<SingularityTaskIdHistory> getTaskHistoryForRequest(
return taskHistoryHelper.getBlendedHistory(requestId, limitStart, limitCount);
}

@GET
@Path("/request/{requestId}/run/{runId}")
@ApiOperation("Retrieve the history for a task by runId")
public Optional<SingularityTaskIdHistory> getTaskHistoryForRequest(
@ApiParam("Request ID to look up") @PathParam("requestId") String requestId,
@ApiParam("runId to look up") @PathParam("runId") String runId) {

authorizationHelper.checkForAuthorizationByRequestId(requestId, user, SingularityAuthorizationScope.READ);

return taskHistoryHelper.getByRunId(requestId, runId);
}

@GET
@Path("/request/{requestId}/deploys")
@ApiOperation("")
Expand Down