Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public class SingularityClient {
private static final String HISTORY_FORMAT = "http://%s/%s/history";
private static final String TASK_HISTORY_FORMAT = HISTORY_FORMAT + "/task/%s";
private static final String REQUEST_HISTORY_FORMAT = HISTORY_FORMAT + "/request/%s/requests";
private static final String TASK_HISTORY_BY_RUN_ID_FORMAT = HISTORY_FORMAT + "/request/%s/run/%s";
private static final String REQUEST_ACTIVE_TASKS_HISTORY_FORMAT = HISTORY_FORMAT + "/request/%s/tasks/active";
private static final String REQUEST_INACTIVE_TASKS_HISTORY_FORMAT = HISTORY_FORMAT + "/request/%s/tasks";
private static final String REQUEST_DEPLOY_HISTORY_FORMAT = HISTORY_FORMAT + "/request/%s/deploy/%s";
Expand Down Expand Up @@ -795,6 +796,12 @@ public Optional<SingularityDeployHistory> getHistoryForRequestDeploy(String requ
return getSingle(requestUri, "deploy history", new SingularityDeployKey(requestId, deployId).getId(), SingularityDeployHistory.class);
}

public Optional<SingularityTaskIdHistory> getHistoryForTask(String requestId, String runId) {
final String requestUri = String.format(TASK_HISTORY_BY_RUN_ID_FORMAT, getHost(), contextPath, requestId, runId);

return getSingle(requestUri, "task history", requestId, SingularityTaskIdHistory.class);
}

//
// WEBHOOKS
//
Expand Down
Original file line number Diff line number Diff line change
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
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
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

Copy link
Copy Markdown

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
Copy Markdown
Contributor 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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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();
}

}
Original file line number Diff line number Diff line change
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
3 changes: 3 additions & 0 deletions mysql/migrations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,6 @@ ALTER TABLE `taskHistory`
ADD COLUMN deployId VARCHAR(100) NULL,
ADD KEY `deployId` (`deployId`, `requestId`, `updatedAt`);
UPDATE `taskHistory` SET `deployId` = SUBSTRING_INDEX(SUBSTRING_INDEX(`taskId`, '-', -5), '-', 1) WHERE `deployId` IS NULL;

--changeset ssalinas:8 dbms:mysql
ALTER TABLE `taskHistory` ADD KEY `runId` (`runId`, `requestId`);