Search in sources :

Example 6 with SingularityPendingTask

use of com.hubspot.singularity.SingularityPendingTask in project Singularity by HubSpot.

the class SingularityScheduler method deleteScheduledTasks.

private void deleteScheduledTasks(final Collection<SingularityPendingTask> scheduledTasks, SingularityPendingRequest pendingRequest) {
    List<SingularityPendingTask> tasksForDeploy = scheduledTasks.stream().filter(task -> pendingRequest.getRequestId().equals(task.getPendingTaskId().getRequestId())).filter(task -> pendingRequest.getDeployId().equals(task.getPendingTaskId().getDeployId())).collect(Collectors.toList());
    for (SingularityPendingTask task : tasksForDeploy) {
        LOG.debug("Deleting pending task {} in order to reschedule {}", task.getPendingTaskId().getId(), pendingRequest);
        taskManager.deletePendingTask(task.getPendingTaskId());
    }
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) DeployManager(com.hubspot.singularity.data.DeployManager) ExtendedTaskState(com.hubspot.singularity.ExtendedTaskState) ListMultimap(com.google.common.collect.ListMultimap) Date(java.util.Date) Inject(com.google.inject.Inject) RequestManager(com.hubspot.singularity.data.RequestManager) CronExpression(org.quartz.CronExpression) LoggerFactory(org.slf4j.LoggerFactory) InvalidRecurrenceRuleException(org.dmfs.rfc5545.recur.InvalidRecurrenceRuleException) SingularityDeployStatistics(com.hubspot.singularity.SingularityDeployStatistics) SingularityDeployStatisticsBuilder(com.hubspot.singularity.SingularityDeployStatisticsBuilder) DeployState(com.hubspot.singularity.DeployState) SingularityTaskShellCommandRequestId(com.hubspot.singularity.SingularityTaskShellCommandRequestId) TaskRequestManager(com.hubspot.singularity.data.TaskRequestManager) SingularityExpiringBounce(com.hubspot.singularity.expiring.SingularityExpiringBounce) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMultiset(com.google.common.collect.HashMultiset) Optional(com.google.common.base.Optional) Map(java.util.Map) TaskManager(com.hubspot.singularity.data.TaskManager) ParseException(java.text.ParseException) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) TimeZone(java.util.TimeZone) Collection(java.util.Collection) SingularityKilledTaskIdRecord(com.hubspot.singularity.SingularityKilledTaskIdRecord) Set(java.util.Set) Protos(org.apache.mesos.v1.Protos) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) RequestState(com.hubspot.singularity.RequestState) PendingType(com.hubspot.singularity.SingularityPendingRequest.PendingType) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) JavaUtils(com.hubspot.mesos.JavaUtils) RFC5545Schedule(com.hubspot.singularity.helpers.RFC5545Schedule) SingularityMachineAbstraction(com.hubspot.singularity.SingularityMachineAbstraction) Entry(java.util.Map.Entry) ScheduleType(com.hubspot.singularity.ScheduleType) RackManager(com.hubspot.singularity.data.RackManager) SingularitySchedulerLock(com.hubspot.singularity.mesos.SingularitySchedulerLock) SingularityCreateResult(com.hubspot.singularity.SingularityCreateResult) SingularityRequestWithState(com.hubspot.singularity.SingularityRequestWithState) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityTaskHistoryUpdate(com.hubspot.singularity.SingularityTaskHistoryUpdate) SingularityPendingTask(com.hubspot.singularity.SingularityPendingTask) Multiset(com.google.common.collect.Multiset) SingularityPendingRequest(com.hubspot.singularity.SingularityPendingRequest) Singleton(javax.inject.Singleton) AbstractMachineManager(com.hubspot.singularity.data.AbstractMachineManager) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) SingularitySlave(com.hubspot.singularity.SingularitySlave) SingularityDeployKey(com.hubspot.singularity.SingularityDeployKey) RequestType(com.hubspot.singularity.RequestType) SlaveManager(com.hubspot.singularity.data.SlaveManager) SingularityConfiguration(com.hubspot.singularity.config.SingularityConfiguration) SingularityTaskCleanup(com.hubspot.singularity.SingularityTaskCleanup) Logger(org.slf4j.Logger) Reason(org.apache.mesos.v1.Protos.TaskStatus.Reason) Throwables(com.google.common.base.Throwables) SingularityPendingDeploy(com.hubspot.singularity.SingularityPendingDeploy) SingularityRack(com.hubspot.singularity.SingularityRack) Maps(com.google.common.collect.Maps) TimeUnit(java.util.concurrent.TimeUnit) SingularityDeployMarker(com.hubspot.singularity.SingularityDeployMarker) SingularityTaskRequest(com.hubspot.singularity.SingularityTaskRequest) MachineState(com.hubspot.singularity.MachineState) SingularityMailer(com.hubspot.singularity.smtp.SingularityMailer) SingularityRequestDeployState(com.hubspot.singularity.SingularityRequestDeployState) TaskCleanupType(com.hubspot.singularity.TaskCleanupType) Comparator(java.util.Comparator) Collections(java.util.Collections) SingularityDeployProgress(com.hubspot.singularity.SingularityDeployProgress) SingularityPendingTask(com.hubspot.singularity.SingularityPendingTask)

Example 7 with SingularityPendingTask

use of com.hubspot.singularity.SingularityPendingTask in project Singularity by HubSpot.

the class SingularityScheduler method getDueTasks.

@Timed
public List<SingularityTaskRequest> getDueTasks() {
    final List<SingularityPendingTask> tasks = taskManager.getPendingTasks();
    final long now = System.currentTimeMillis();
    final List<SingularityPendingTask> dueTasks = Lists.newArrayListWithCapacity(tasks.size());
    for (SingularityPendingTask task : tasks) {
        if (task.getPendingTaskId().getNextRunAt() <= now) {
            dueTasks.add(task);
        }
    }
    final List<SingularityTaskRequest> dueTaskRequests = taskRequestManager.getTaskRequests(dueTasks);
    return checkForStaleScheduledTasks(dueTasks, dueTaskRequests);
}
Also used : SingularityPendingTask(com.hubspot.singularity.SingularityPendingTask) SingularityTaskRequest(com.hubspot.singularity.SingularityTaskRequest) Timed(com.codahale.metrics.annotation.Timed)

Example 8 with SingularityPendingTask

use of com.hubspot.singularity.SingularityPendingTask in project Singularity by HubSpot.

the class TaskResource method deleteScheduledTask.

public Optional<SingularityPendingTask> deleteScheduledTask(String taskId, SingularityUser user) {
    Optional<SingularityPendingTask> maybePendingTask = taskManager.getPendingTask(getPendingTaskIdFromStr(taskId));
    if (maybePendingTask.isPresent()) {
        SingularityPendingTaskId pendingTaskId = maybePendingTask.get().getPendingTaskId();
        Optional<SingularityRequestWithState> maybeRequest = requestManager.getRequest(pendingTaskId.getRequestId());
        checkNotFound(maybeRequest.isPresent(), "Couldn't find: " + taskId);
        SingularityRequest request = maybeRequest.get().getRequest();
        authorizationHelper.checkForAuthorizationByRequestId(request.getId(), user, SingularityAuthorizationScope.WRITE);
        checkBadRequest(request.getRequestType() == RequestType.ON_DEMAND, "Only ON_DEMAND tasks may be deleted.");
        taskManager.markPendingTaskForDeletion(pendingTaskId);
    }
    return maybePendingTask;
}
Also used : SingularityPendingTask(com.hubspot.singularity.SingularityPendingTask) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) SingularityRequestWithState(com.hubspot.singularity.SingularityRequestWithState) SingularityRequest(com.hubspot.singularity.SingularityRequest)

Example 9 with SingularityPendingTask

use of com.hubspot.singularity.SingularityPendingTask in project Singularity by HubSpot.

the class TaskTrackerResource method getTaskStateByRunId.

@GET
@Path("/run/{requestId}/{runId}")
@ApiOperation(value = "Get the current state of a task by taskId whether it is pending, active, or inactive")
@ApiResponses({ @ApiResponse(code = 404, message = "Task with this runId does not exist") })
public Optional<SingularityTaskState> getTaskStateByRunId(@Auth SingularityUser user, @PathParam("requestId") String requestId, @PathParam("runId") String runId) {
    authorizationHelper.checkForAuthorizationByRequestId(requestId, user, SingularityAuthorizationScope.READ);
    // Check if it's active or inactive
    Optional<SingularityTaskId> maybeTaskId = taskManager.getTaskByRunId(requestId, runId);
    if (maybeTaskId.isPresent()) {
        Optional<SingularityTaskState> maybeTaskState = getTaskStateFromId(maybeTaskId.get());
        if (maybeTaskState.isPresent()) {
            return maybeTaskState;
        }
    } else {
        Optional<SingularityTaskHistory> maybeTaskHistory = historyManager.getTaskHistoryByRunId(requestId, runId);
        if (maybeTaskHistory.isPresent()) {
            return Optional.of(SingularityTaskState.fromTaskHistory(maybeTaskHistory.get()));
        }
    }
    // Check if it's pending
    for (SingularityPendingTask pendingTask : taskManager.getPendingTasksForRequest(requestId)) {
        if (pendingTask.getRunId().isPresent() && pendingTask.getRunId().get().equals(runId)) {
            return Optional.of(new SingularityTaskState(Optional.absent(), pendingTask.getPendingTaskId(), pendingTask.getRunId(), Optional.absent(), Collections.emptyList(), true));
        }
    }
    for (SingularityPendingRequest pendingRequest : requestManager.getPendingRequests()) {
        if (pendingRequest.getRequestId().equals(requestId) && pendingRequest.getRunId().isPresent() && pendingRequest.getRunId().get().equals(runId)) {
            return Optional.of(new SingularityTaskState(Optional.absent(), Optional.absent(), pendingRequest.getRunId(), Optional.absent(), Collections.emptyList(), true));
        }
    }
    return Optional.absent();
}
Also used : SingularityTaskState(com.hubspot.singularity.SingularityTaskState) SingularityPendingRequest(com.hubspot.singularity.SingularityPendingRequest) SingularityPendingTask(com.hubspot.singularity.SingularityPendingTask) SingularityTaskHistory(com.hubspot.singularity.SingularityTaskHistory) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses)

Example 10 with SingularityPendingTask

use of com.hubspot.singularity.SingularityPendingTask in project Singularity by HubSpot.

the class SingularityScheduler method getScheduledTaskIds.

private List<SingularityPendingTask> getScheduledTaskIds(int numMissingInstances, List<SingularityTaskId> matchingTaskIds, SingularityRequest request, RequestState state, SingularityDeployStatistics deployStatistics, String deployId, SingularityPendingRequest pendingRequest, Optional<SingularityPendingDeploy> maybePendingDeploy) {
    final Optional<Long> nextRunAt = getNextRunAt(request, state, deployStatistics, pendingRequest, maybePendingDeploy);
    if (!nextRunAt.isPresent()) {
        return Collections.emptyList();
    }
    final Set<Integer> inuseInstanceNumbers = Sets.newHashSetWithExpectedSize(matchingTaskIds.size());
    for (SingularityTaskId matchingTaskId : matchingTaskIds) {
        inuseInstanceNumbers.add(matchingTaskId.getInstanceNo());
    }
    final List<SingularityPendingTask> newTasks = Lists.newArrayListWithCapacity(numMissingInstances);
    int nextInstanceNumber = 1;
    for (int i = 0; i < numMissingInstances; i++) {
        while (inuseInstanceNumbers.contains(nextInstanceNumber)) {
            nextInstanceNumber++;
        }
        newTasks.add(new SingularityPendingTask(new SingularityPendingTaskId(request.getId(), deployId, nextRunAt.get(), nextInstanceNumber, pendingRequest.getPendingType(), pendingRequest.getTimestamp()), pendingRequest.getCmdLineArgsList(), pendingRequest.getUser(), pendingRequest.getRunId(), pendingRequest.getSkipHealthchecks(), pendingRequest.getMessage(), pendingRequest.getResources(), pendingRequest.getS3UploaderAdditionalFiles(), pendingRequest.getRunAsUserOverride(), pendingRequest.getEnvOverrides(), pendingRequest.getExtraArtifacts(), pendingRequest.getActionId()));
        nextInstanceNumber++;
    }
    return newTasks;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SingularityPendingTask(com.hubspot.singularity.SingularityPendingTask) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) SingularityTaskId(com.hubspot.singularity.SingularityTaskId)

Aggregations

SingularityPendingTask (com.hubspot.singularity.SingularityPendingTask)22 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)9 Test (org.junit.Test)8 SingularityTask (com.hubspot.singularity.SingularityTask)6 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)6 SingularityTaskRequest (com.hubspot.singularity.SingularityTaskRequest)6 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)4 SingularityPendingTaskBuilder (com.hubspot.singularity.SingularityPendingTaskBuilder)4 SingularityRequest (com.hubspot.singularity.SingularityRequest)4 SingularityRequestWithState (com.hubspot.singularity.SingularityRequestWithState)4 Resources (com.hubspot.mesos.Resources)3 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)3 SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)3 Timed (com.codahale.metrics.annotation.Timed)2 MachineState (com.hubspot.singularity.MachineState)2 SingularityDeployKey (com.hubspot.singularity.SingularityDeployKey)2 SingularityPendingDeploy (com.hubspot.singularity.SingularityPendingDeploy)2 SingularityRunNowRequestBuilder (com.hubspot.singularity.SingularityRunNowRequestBuilder)2 SingularityRunNowRequest (com.hubspot.singularity.api.SingularityRunNowRequest)2 TaskInfo (org.apache.mesos.v1.Protos.TaskInfo)2