use of com.hubspot.singularity.SingularityTaskHistory in project Singularity by HubSpot.
the class TaskManager method getTaskHistory.
public Optional<SingularityTaskHistory> getTaskHistory(SingularityTaskId taskId) {
final Optional<SingularityTask> task = getTaskCheckCache(taskId, true);
if (!task.isPresent()) {
return Optional.absent();
}
List<SingularityTaskHistoryUpdate> taskUpdates = getTaskHistoryUpdates(taskId);
Optional<String> directory = getDirectory(taskId);
Optional<String> containerId = getContainerId(taskId);
List<SingularityTaskHealthcheckResult> healthchecks = getHealthcheckResults(taskId);
List<SingularityLoadBalancerUpdate> loadBalancerUpdates = Lists.newArrayListWithCapacity(2);
checkLoadBalancerHistory(loadBalancerUpdates, taskId, LoadBalancerRequestType.ADD);
checkLoadBalancerHistory(loadBalancerUpdates, taskId, LoadBalancerRequestType.REMOVE);
List<SingularityTaskShellCommandHistory> shellCommandHistory = getTaskShellCommandHistory(taskId);
List<SingularityTaskMetadata> taskMetadata = getTaskMetadata(taskId);
return Optional.of(new SingularityTaskHistory(taskUpdates, directory, containerId, healthchecks, task.get(), loadBalancerUpdates, shellCommandHistory, taskMetadata));
}
use of com.hubspot.singularity.SingularityTaskHistory in project Singularity by HubSpot.
the class SingularityMailPoller method checkToSendTaskFinishedMail.
private void checkToSendTaskFinishedMail(SingularityTaskId taskId) {
Optional<SingularityRequestWithState> requestWithState = requestManager.getRequest(taskId.getRequestId());
Optional<SingularityTaskHistory> taskHistory = taskManager.getTaskHistory(taskId);
ShouldSendMailState shouldSendState = shouldSendTaskFinishedMail(taskId, requestWithState, taskHistory);
if (shouldSendState == ShouldSendMailState.WAIT) {
return;
}
try {
mailer.sendTaskCompletedMail(taskHistory.get(), requestWithState.get().getRequest());
} catch (Throwable t) {
LOG.error("While trying to send task completed mail for {}", taskId, t);
} finally {
SingularityDeleteResult result = taskManager.deleteFinishedTaskMailQueue(taskId);
LOG.debug("Task {} mail sent with status {} (delete result {})", taskId, shouldSendState, result);
}
}
use of com.hubspot.singularity.SingularityTaskHistory in project Singularity by HubSpot.
the class S3LogResource method getS3PrefixesForTask.
// Generation of prefixes
private Collection<String> getS3PrefixesForTask(S3Configuration s3Configuration, SingularityTaskId taskId, Optional<Long> startArg, Optional<Long> endArg, String group, SingularityUser user) {
Optional<SingularityTaskHistory> history = getTaskHistory(taskId, user);
long start = taskId.getStartedAt();
if (startArg.isPresent()) {
start = Math.max(startArg.get(), start);
}
long end = start + s3Configuration.getMissingTaskDefaultS3SearchPeriodMillis();
if (history.isPresent()) {
SimplifiedTaskState taskState = SingularityTaskHistoryUpdate.getCurrentState(history.get().getTaskUpdates());
if (taskState == SimplifiedTaskState.DONE) {
end = Iterables.getLast(history.get().getTaskUpdates()).getTimestamp();
} else {
end = System.currentTimeMillis();
}
}
if (endArg.isPresent()) {
end = Math.min(endArg.get(), end);
}
Optional<String> tag = Optional.absent();
if (history.isPresent() && history.get().getTask().getTaskRequest().getDeploy().getExecutorData().isPresent()) {
tag = history.get().getTask().getTaskRequest().getDeploy().getExecutorData().get().getLoggingTag();
}
Collection<String> prefixes = SingularityS3FormatHelper.getS3KeyPrefixes(s3Configuration.getS3KeyFormat(), taskId, tag, start, end, group);
for (SingularityS3UploaderFile additionalFile : s3Configuration.getS3UploaderAdditionalFiles()) {
if (additionalFile.getS3UploaderKeyPattern().isPresent() && !additionalFile.getS3UploaderKeyPattern().get().equals(s3Configuration.getS3KeyFormat())) {
prefixes.addAll(SingularityS3FormatHelper.getS3KeyPrefixes(additionalFile.getS3UploaderKeyPattern().get(), taskId, tag, start, end, group));
}
}
LOG.trace("Task {} got S3 prefixes {} for start {}, end {}, tag {}", taskId, prefixes, start, end, tag);
return prefixes;
}
use of com.hubspot.singularity.SingularityTaskHistory in project Singularity by HubSpot.
the class S3LogResource method getRequestGroupForTask.
// Finding request group
private Optional<String> getRequestGroupForTask(final SingularityTaskId taskId, SingularityUser user) {
Optional<SingularityTaskHistory> maybeTaskHistory = getTaskHistory(taskId, user);
if (maybeTaskHistory.isPresent()) {
SingularityRequest request = maybeTaskHistory.get().getTask().getTaskRequest().getRequest();
authorizationHelper.checkForAuthorization(request, user, SingularityAuthorizationScope.READ);
return request.getGroup();
} else {
return getRequestGroup(taskId.getRequestId(), user);
}
}
use of com.hubspot.singularity.SingularityTaskHistory in project Singularity by HubSpot.
the class SandboxResource method read.
@GET
@Path("/{taskId}/read")
@ApiOperation("Retrieve part of the contents of a file in a specific task's sandbox.")
public MesosFileChunkObject read(@Auth SingularityUser user, @ApiParam("The task ID of the sandbox to read from") @PathParam("taskId") String taskId, @ApiParam("The path to the file to be read") @QueryParam("path") String path, @ApiParam("Optional string to grep for") @QueryParam("grep") Optional<String> grep, @ApiParam("Byte offset to start reading from") @QueryParam("offset") Optional<Long> offset, @ApiParam("Maximum number of bytes to read") @QueryParam("length") Optional<Long> length) {
authorizationHelper.checkForAuthorizationByTaskId(taskId, user, SingularityAuthorizationScope.READ);
final SingularityTaskHistory history = checkHistory(taskId, user);
checkBadRequest(!Strings.isNullOrEmpty(path), "Must specify 'path'");
final String slaveHostname = history.getTask().getHostname();
final String fullPath = new File(history.getDirectory().get(), path).toString();
try {
final Optional<MesosFileChunkObject> maybeChunk = sandboxManager.read(slaveHostname, fullPath, offset, length);
checkNotFound(maybeChunk.isPresent(), "File %s does not exist for task ID %s", fullPath, taskId);
if (grep.isPresent() && !Strings.isNullOrEmpty(grep.get())) {
final Pattern grepPattern = Pattern.compile(grep.get());
final StringBuilder strBuilder = new StringBuilder(maybeChunk.get().getData().length());
for (String line : Splitter.on("\n").split(maybeChunk.get().getData())) {
if (grepPattern.matcher(line).find()) {
strBuilder.append(line);
strBuilder.append("\n");
}
}
return new MesosFileChunkObject(strBuilder.toString(), maybeChunk.get().getOffset(), Optional.of(maybeChunk.get().getOffset() + maybeChunk.get().getData().length()));
}
return maybeChunk.get();
} catch (SlaveNotFoundException snfe) {
throw notFound("Slave @ %s was not found, it is probably offline", slaveHostname);
}
}
Aggregations