Search in sources :

Example 16 with SingularityPendingTaskId

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

the class SingularityDeployChecker method deleteObsoletePendingTasks.

private void deleteObsoletePendingTasks(SingularityPendingDeploy pendingDeploy) {
    List<SingularityPendingTaskId> obsoletePendingTasks = taskManager.getPendingTaskIds().stream().filter(taskId -> taskId.getRequestId().equals(pendingDeploy.getDeployMarker().getRequestId())).filter(taskId -> !taskId.getDeployId().equals(pendingDeploy.getDeployMarker().getDeployId())).collect(Collectors.toList());
    for (SingularityPendingTaskId pendingTaskId : obsoletePendingTasks) {
        LOG.debug("Deleting obsolete pending task {}", pendingTaskId.getId());
        taskManager.deletePendingTask(pendingTaskId);
    }
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) DeployManager(com.hubspot.singularity.data.DeployManager) SingularityLoadBalancerUpdate(com.hubspot.singularity.SingularityLoadBalancerUpdate) Inject(com.google.inject.Inject) RequestManager(com.hubspot.singularity.data.RequestManager) LoggerFactory(org.slf4j.LoggerFactory) SingularityDeployFailureReason(com.hubspot.singularity.SingularityDeployFailureReason) SingularityExpiringScale(com.hubspot.singularity.expiring.SingularityExpiringScale) DeployState(com.hubspot.singularity.DeployState) RequestHistoryType(com.hubspot.singularity.SingularityRequestHistory.RequestHistoryType) SingularityTaskShellCommandRequestId(com.hubspot.singularity.SingularityTaskShellCommandRequestId) Optional(com.google.common.base.Optional) Map(java.util.Map) TaskManager(com.hubspot.singularity.data.TaskManager) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Collection(java.util.Collection) Set(java.util.Set) SingularityUpdatePendingDeployRequest(com.hubspot.singularity.SingularityUpdatePendingDeployRequest) UUID(java.util.UUID) SingularityExpiringPause(com.hubspot.singularity.expiring.SingularityExpiringPause) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) RequestState(com.hubspot.singularity.RequestState) SingularityDeployResult(com.hubspot.singularity.SingularityDeployResult) PendingType(com.hubspot.singularity.SingularityPendingRequest.PendingType) DeployHealth(com.hubspot.singularity.scheduler.SingularityDeployHealthHelper.DeployHealth) List(java.util.List) JavaUtils(com.hubspot.mesos.JavaUtils) LoadBalancerClient(com.hubspot.singularity.hooks.LoadBalancerClient) SingularitySchedulerLock(com.hubspot.singularity.mesos.SingularitySchedulerLock) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) SingularityRequestWithState(com.hubspot.singularity.SingularityRequestWithState) SingularityRequest(com.hubspot.singularity.SingularityRequest) Iterables(com.google.common.collect.Iterables) SingularityPendingRequest(com.hubspot.singularity.SingularityPendingRequest) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) LoadBalancerRequestId(com.hubspot.singularity.LoadBalancerRequestType.LoadBalancerRequestId) SingularityDeployKey(com.hubspot.singularity.SingularityDeployKey) RequestType(com.hubspot.singularity.RequestType) ExecutorService(java.util.concurrent.ExecutorService) SingularityConfiguration(com.hubspot.singularity.config.SingularityConfiguration) SingularityTaskCleanup(com.hubspot.singularity.SingularityTaskCleanup) Logger(org.slf4j.Logger) BaragonRequestState(com.hubspot.baragon.models.BaragonRequestState) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) SingularityDeployFailure(com.hubspot.singularity.SingularityDeployFailure) SingularityPendingDeploy(com.hubspot.singularity.SingularityPendingDeploy) TimeUnit(java.util.concurrent.TimeUnit) SingularityDeployMarker(com.hubspot.singularity.SingularityDeployMarker) SingularityRequestDeployState(com.hubspot.singularity.SingularityRequestDeployState) DurationFormatUtils(org.apache.commons.lang3.time.DurationFormatUtils) TaskCleanupType(com.hubspot.singularity.TaskCleanupType) LoadBalancerRequestType(com.hubspot.singularity.LoadBalancerRequestType) SingularityRunNowRequest(com.hubspot.singularity.api.SingularityRunNowRequest) Collections(java.util.Collections) SingularityPendingRequestBuilder(com.hubspot.singularity.SingularityPendingRequestBuilder) SingularityDeployProgress(com.hubspot.singularity.SingularityDeployProgress) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId)

Example 17 with SingularityPendingTaskId

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

the class SingularityDisasterDetectionPoller method collectDisasterStats.

private SingularityDisasterDataPoint collectDisasterStats() {
    long now = System.currentTimeMillis();
    int numActiveTasks = taskManager.getNumActiveTasks();
    List<SingularityPendingTaskId> pendingTasks = taskManager.getPendingTaskIds();
    int numPendingTasks = pendingTasks.size();
    int numLateTasks = 0;
    long totalTaskLagMillis = 0;
    int numPastDueTasks = 0;
    for (SingularityPendingTaskId pendingTask : pendingTasks) {
        long taskLagMillis = now - pendingTask.getNextRunAt();
        if (taskLagMillis > 0) {
            numPastDueTasks++;
            totalTaskLagMillis += taskLagMillis;
            if (taskLagMillis > configuration.getDeltaAfterWhichTasksAreLateMillis()) {
                numLateTasks++;
            }
        }
    }
    long avgTaskLagMillis = totalTaskLagMillis / Math.max(numPastDueTasks, 1);
    List<SingularitySlave> slaves = slaveManager.getObjects();
    int numRunningSlaves = 0;
    for (SingularitySlave slave : slaves) {
        if (slave.getCurrentState().getState() != MachineState.DEAD && slave.getCurrentState().getState() != MachineState.MISSING_ON_STARTUP) {
            numRunningSlaves++;
        }
    }
    int numLostSlaves = activeSlavesLost.getAndSet(0);
    int numLostTasks = 0;
    for (Reason lostTaskReason : disasterConfiguration.getLostTaskReasons()) {
        numLostTasks += taskLostReasons.count(lostTaskReason);
    }
    taskLostReasons.clear();
    return new SingularityDisasterDataPoint(now, numActiveTasks, numPendingTasks, numLateTasks, avgTaskLagMillis, numLostTasks, numRunningSlaves, numLostSlaves);
}
Also used : SingularitySlave(com.hubspot.singularity.SingularitySlave) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) SingularityDisasterDataPoint(com.hubspot.singularity.SingularityDisasterDataPoint) SingularityDisasterDataPoint(com.hubspot.singularity.SingularityDisasterDataPoint) Reason(org.apache.mesos.v1.Protos.TaskStatus.Reason)

Example 18 with SingularityPendingTaskId

use of com.hubspot.singularity.SingularityPendingTaskId 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 19 with SingularityPendingTaskId

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

the class SingularityStartup method getDeployKeyToPendingTaskId.

private Map<SingularityDeployKey, SingularityPendingTaskId> getDeployKeyToPendingTaskId() {
    final List<SingularityPendingTaskId> pendingTaskIds = taskManager.getPendingTaskIds();
    final Map<SingularityDeployKey, SingularityPendingTaskId> deployKeyToPendingTaskId = Maps.newHashMapWithExpectedSize(pendingTaskIds.size());
    for (SingularityPendingTaskId taskId : pendingTaskIds) {
        SingularityDeployKey deployKey = new SingularityDeployKey(taskId.getRequestId(), taskId.getDeployId());
        deployKeyToPendingTaskId.put(deployKey, taskId);
    }
    return deployKeyToPendingTaskId;
}
Also used : SingularityDeployKey(com.hubspot.singularity.SingularityDeployKey) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId)

Example 20 with SingularityPendingTaskId

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

the class SingularityStartup method checkSchedulerForInconsistentState.

/**
 * We need to run this check for the various situations where the scheduler could get in an inconsistent state due
 * to a crash/network failure during series of state transactions.
 *
 *  1) Unpausing
 *  2) Launching Task
 */
@VisibleForTesting
void checkSchedulerForInconsistentState() {
    final long now = System.currentTimeMillis();
    final Map<SingularityDeployKey, SingularityPendingTaskId> deployKeyToPendingTaskId = getDeployKeyToPendingTaskId();
    for (SingularityRequestWithState requestWithState : requestManager.getRequests()) {
        switch(requestWithState.getState()) {
            case ACTIVE:
            case SYSTEM_COOLDOWN:
            case DEPLOYING_TO_UNPAUSE:
                checkActiveRequest(requestWithState, deployKeyToPendingTaskId, now);
                break;
            case DELETED:
            case PAUSED:
            case FINISHED:
                break;
        }
    }
}
Also used : SingularityDeployKey(com.hubspot.singularity.SingularityDeployKey) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) SingularityRequestWithState(com.hubspot.singularity.SingularityRequestWithState) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)36 SingularityRequest (com.hubspot.singularity.SingularityRequest)16 Test (org.junit.Test)16 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)15 SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)9 SingularityPendingTask (com.hubspot.singularity.SingularityPendingTask)8 SingularityRunNowRequest (com.hubspot.singularity.api.SingularityRunNowRequest)8 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)7 SingularityPendingTaskBuilder (com.hubspot.singularity.SingularityPendingTaskBuilder)7 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)6 SingularityTask (com.hubspot.singularity.SingularityTask)6 SingularityRequestWithState (com.hubspot.singularity.SingularityRequestWithState)5 SingularityDeployKey (com.hubspot.singularity.SingularityDeployKey)4 PendingType (com.hubspot.singularity.SingularityPendingRequest.PendingType)4 SingularityRequestDeployState (com.hubspot.singularity.SingularityRequestDeployState)4 Optional (com.google.common.base.Optional)3 Inject (com.google.inject.Inject)3 RequestType (com.hubspot.singularity.RequestType)3 SingularityDeployBuilder (com.hubspot.singularity.SingularityDeployBuilder)3 ArrayList (java.util.ArrayList)3