use of com.hubspot.singularity.SingularityTaskId in project Singularity by HubSpot.
the class SingularityLeaderCache method getActiveTaskIdsAsStrings.
public List<String> getActiveTaskIdsAsStrings() {
List<SingularityTaskId> localActiveTaskIds = getActiveTaskIds();
List<String> strings = new ArrayList<>(localActiveTaskIds.size());
for (SingularityTaskId taskId : localActiveTaskIds) {
strings.add(taskId.getId());
}
return strings;
}
use of com.hubspot.singularity.SingularityTaskId in project Singularity by HubSpot.
the class SingularityScheduler method getMatchingTaskIds.
private List<SingularityTaskId> getMatchingTaskIds(SingularityRequest request, SingularityDeployKey deployKey) {
List<SingularityTaskId> activeTaskIdsForRequest = leaderCache.getActiveTaskIdsForRequest(deployKey.getRequestId());
if (request.isLongRunning()) {
Set<SingularityTaskId> killedTaskIds = leaderCache.getKilledTasks().stream().map(SingularityKilledTaskIdRecord::getTaskId).collect(Collectors.toSet());
List<SingularityTaskId> matchingTaskIds = new ArrayList<>();
for (SingularityTaskId taskId : activeTaskIdsForRequest) {
if (!taskId.getDeployId().equals(deployKey.getDeployId())) {
continue;
}
if (leaderCache.getCleanupTaskIds().contains(taskId)) {
continue;
}
if (killedTaskIds.contains(taskId)) {
continue;
}
matchingTaskIds.add(taskId);
}
return matchingTaskIds;
} else {
return new ArrayList<>(activeTaskIdsForRequest);
}
}
use of com.hubspot.singularity.SingularityTaskId in project Singularity by HubSpot.
the class TaskResource method getShellCommandHisotry.
@GET
@Path("/task/{taskId}/command")
@ApiOperation(value = "Retrieve a list of shell commands that have run for a task")
public List<SingularityTaskShellCommandHistory> getShellCommandHisotry(@Auth SingularityUser user, @PathParam("taskId") String taskId) {
authorizationHelper.checkForAuthorizationByTaskId(taskId, user, SingularityAuthorizationScope.READ);
SingularityTaskId taskIdObj = getTaskIdFromStr(taskId);
return taskManager.getTaskShellCommandHistory(taskIdObj);
}
use of com.hubspot.singularity.SingularityTaskId in project Singularity by HubSpot.
the class TaskResource method checkActiveTask.
private SingularityTask checkActiveTask(String taskId, SingularityAuthorizationScope scope, SingularityUser user) {
SingularityTaskId taskIdObj = getTaskIdFromStr(taskId);
Optional<SingularityTask> task = taskManager.getTask(taskIdObj);
checkNotFound(task.isPresent() && taskManager.isActiveTask(taskId), "No active task with id %s", taskId);
if (task.isPresent()) {
authorizationHelper.checkForAuthorizationByRequestId(task.get().getTaskId().getRequestId(), user, scope);
}
return task.get();
}
use of com.hubspot.singularity.SingularityTaskId in project Singularity by HubSpot.
the class TaskResource method runShellCommand.
@POST
@Path("/task/{taskId}/command")
@ApiOperation(value = "Run a configured shell command against the given task")
@ApiResponses({ @ApiResponse(code = 400, message = "Given shell command option doesn't exist"), @ApiResponse(code = 403, message = "Given shell command doesn't exist") })
@Consumes({ MediaType.APPLICATION_JSON })
public SingularityTaskShellCommandRequest runShellCommand(@Auth SingularityUser user, @PathParam("taskId") String taskId, final SingularityShellCommand shellCommand) {
SingularityTaskId taskIdObj = getTaskIdFromStr(taskId);
authorizationHelper.checkForAuthorizationByTaskId(taskId, user, SingularityAuthorizationScope.WRITE);
validator.checkActionEnabled(SingularityAction.RUN_SHELL_COMMAND);
if (!taskManager.isActiveTask(taskId)) {
throw WebExceptions.badRequest("%s is not an active task, can't run %s on it", taskId, shellCommand.getName());
}
return startShellCommand(taskIdObj, shellCommand, user);
}
Aggregations