Search in sources :

Example 46 with SingularityTaskId

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;
}
Also used : ArrayList(java.util.ArrayList) SingularityTaskId(com.hubspot.singularity.SingularityTaskId)

Example 47 with SingularityTaskId

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);
    }
}
Also used : ArrayList(java.util.ArrayList) SingularityTaskId(com.hubspot.singularity.SingularityTaskId)

Example 48 with SingularityTaskId

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);
}
Also used : SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(com.wordnik.swagger.annotations.ApiOperation)

Example 49 with SingularityTaskId

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();
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) SingularityTaskId(com.hubspot.singularity.SingularityTaskId)

Example 50 with SingularityTaskId

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);
}
Also used : SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses)

Aggregations

SingularityTaskId (com.hubspot.singularity.SingularityTaskId)106 Test (org.junit.Test)44 SingularityTask (com.hubspot.singularity.SingularityTask)34 SingularityRequest (com.hubspot.singularity.SingularityRequest)26 ArrayList (java.util.ArrayList)26 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)14 SingularityTaskHistoryUpdate (com.hubspot.singularity.SingularityTaskHistoryUpdate)13 MesosTaskMonitorObject (com.hubspot.mesos.json.MesosTaskMonitorObject)12 List (java.util.List)11 SingularityRequestWithState (com.hubspot.singularity.SingularityRequestWithState)10 SingularityDeployProgress (com.hubspot.singularity.SingularityDeployProgress)9 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)9 SingularityRunNowRequest (com.hubspot.singularity.api.SingularityRunNowRequest)9 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)8 SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)7 SingularityTaskCleanup (com.hubspot.singularity.SingularityTaskCleanup)7 SingularityTaskShellCommandRequestId (com.hubspot.singularity.SingularityTaskShellCommandRequestId)7 HashMap (java.util.HashMap)7 SingularityRequestDeployState (com.hubspot.singularity.SingularityRequestDeployState)6 SingularitySlaveUsage (com.hubspot.singularity.SingularitySlaveUsage)6