Search in sources :

Example 1 with SingularityTaskHealthcheckResult

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

the class SingularityDeployHealthHelper method getTaskFailures.

public List<SingularityDeployFailure> getTaskFailures(final Optional<SingularityDeploy> deploy, final Collection<SingularityTaskId> activeTasks) {
    List<SingularityDeployFailure> failures = new ArrayList<>();
    Map<SingularityTaskId, List<SingularityTaskHistoryUpdate>> taskUpdates = taskManager.getTaskHistoryUpdates(activeTasks);
    Map<SingularityTaskId, SingularityTaskHealthcheckResult> healthcheckResults = taskManager.getLastHealthcheck(activeTasks);
    for (SingularityTaskId taskId : activeTasks) {
        Optional<SingularityDeployFailure> maybeFailure = getTaskFailure(deploy.get(), taskUpdates, healthcheckResults, taskId);
        if (maybeFailure.isPresent()) {
            failures.add(maybeFailure.get());
        }
    }
    return failures;
}
Also used : SingularityDeployFailure(com.hubspot.singularity.SingularityDeployFailure) SingularityTaskHealthcheckResult(com.hubspot.singularity.SingularityTaskHealthcheckResult) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SingularityTaskId(com.hubspot.singularity.SingularityTaskId)

Example 2 with SingularityTaskHealthcheckResult

use of com.hubspot.singularity.SingularityTaskHealthcheckResult 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.empty();
    }
    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));
}
Also used : SingularityLoadBalancerUpdate(com.hubspot.singularity.SingularityLoadBalancerUpdate) SingularityTaskShellCommandHistory(com.hubspot.singularity.SingularityTaskShellCommandHistory) SingularityTaskHealthcheckResult(com.hubspot.singularity.SingularityTaskHealthcheckResult) SingularityTask(com.hubspot.singularity.SingularityTask) SingularityTaskMetadata(com.hubspot.singularity.SingularityTaskMetadata) SingularityTaskHistoryUpdate(com.hubspot.singularity.SingularityTaskHistoryUpdate) SingularityTaskHistory(com.hubspot.singularity.SingularityTaskHistory)

Example 3 with SingularityTaskHealthcheckResult

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

the class TaskManager method getLastHealthcheck.

public Map<SingularityTaskId, SingularityTaskHealthcheckResult> getLastHealthcheck(Collection<SingularityTaskId> taskIds) {
    List<String> paths = Lists.newArrayListWithCapacity(taskIds.size());
    for (SingularityTaskId taskId : taskIds) {
        paths.add(getLastHealthcheckPath(taskId));
    }
    List<SingularityTaskHealthcheckResult> healthcheckResults = getAsync("getLastHealthcheck", paths, healthcheckResultTranscoder);
    return Maps.uniqueIndex(healthcheckResults, SingularityTaskIdHolder.getTaskIdFunction());
}
Also used : SingularityTaskHealthcheckResult(com.hubspot.singularity.SingularityTaskHealthcheckResult) SingularityTaskId(com.hubspot.singularity.SingularityTaskId)

Example 4 with SingularityTaskHealthcheckResult

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

the class SingularitySchedulerTest method testIncrementalBounce.

@Test
public void testIncrementalBounce() {
    initRequest();
    // set up agents so scale validate will pass
    resourceOffers(2);
    SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
    requestResource.postRequest(request.toBuilder().setAgentPlacement(Optional.of(AgentPlacement.SEPARATE_BY_REQUEST)).setInstances(Optional.of(2)).build(), singularityUser);
    initHCDeploy();
    SingularityTask taskOne = startSeparatePlacementTask(firstDeploy, 1);
    SingularityTask taskTwo = startSeparatePlacementTask(firstDeploy, 2);
    requestManager.createCleanupRequest(new SingularityRequestCleanup(user, RequestCleanupType.INCREMENTAL_BOUNCE, System.currentTimeMillis(), Optional.<Boolean>empty(), Optional.empty(), requestId, Optional.of(firstDeployId), Optional.<Boolean>empty(), Optional.<String>empty(), Optional.<String>empty(), Optional.<SingularityShellCommand>empty()));
    Assertions.assertTrue(requestManager.cleanupRequestExists(requestId));
    cleaner.drainCleanupQueue();
    Assertions.assertTrue(!requestManager.cleanupRequestExists(requestId));
    Assertions.assertEquals(2, taskManager.getCleanupTaskIds().size());
    scheduler.drainPendingQueue();
    resourceOffers(3);
    SingularityTask taskThree = null;
    for (SingularityTask task : taskManager.getActiveTasks()) {
        if (!task.getTaskId().equals(taskOne.getTaskId()) && !task.getTaskId().equals(taskTwo.getTaskId())) {
            taskThree = task;
        }
    }
    statusUpdate(taskThree, TaskState.TASK_RUNNING, Optional.of(1L));
    Assertions.assertEquals(3, taskManager.getActiveTaskIds().size());
    cleaner.drainCleanupQueue();
    // No old tasks should be killed before new ones pass healthchecks
    Assertions.assertEquals(2, taskManager.getCleanupTaskIds().size());
    taskManager.saveHealthcheckResult(new SingularityTaskHealthcheckResult(Optional.of(200), Optional.of(1000L), System.currentTimeMillis(), Optional.<String>empty(), Optional.<String>empty(), taskThree.getTaskId(), Optional.<Boolean>empty()));
    cleaner.drainCleanupQueue();
    Assertions.assertEquals(1, taskManager.getCleanupTaskIds().size());
    statusUpdate(taskOne, TaskState.TASK_KILLED);
    resourceOffers(3);
    SingularityTask taskFour = null;
    for (SingularityTask task : taskManager.getActiveTasks()) {
        if (!task.getTaskId().equals(taskOne.getTaskId()) && !task.getTaskId().equals(taskTwo.getTaskId()) && !task.getTaskId().equals(taskThree.getTaskId())) {
            taskFour = task;
        }
    }
    statusUpdate(taskFour, TaskState.TASK_RUNNING, Optional.of(1L));
    taskManager.saveHealthcheckResult(new SingularityTaskHealthcheckResult(Optional.of(200), Optional.of(1000L), System.currentTimeMillis(), Optional.<String>empty(), Optional.<String>empty(), taskFour.getTaskId(), Optional.<Boolean>empty()));
    cleaner.drainCleanupQueue();
    Assertions.assertTrue(taskManager.getCleanupTaskIds().isEmpty());
}
Also used : SingularityRequestCleanup(com.hubspot.singularity.SingularityRequestCleanup) SingularityTaskHealthcheckResult(com.hubspot.singularity.SingularityTaskHealthcheckResult) SingularityTask(com.hubspot.singularity.SingularityTask) SingularityShellCommand(com.hubspot.singularity.SingularityShellCommand) SingularityRequest(com.hubspot.singularity.SingularityRequest) Test(org.junit.jupiter.api.Test)

Example 5 with SingularityTaskHealthcheckResult

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

the class SingularitySchedulerTest method testCleanerFindsTasksWithSkippedHealthchecks.

@Test
public void testCleanerFindsTasksWithSkippedHealthchecks() {
    initRequest();
    // set up agents so scale validate will pass
    resourceOffers(2);
    SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
    long now = System.currentTimeMillis();
    requestManager.saveHistory(new SingularityRequestHistory(now, Optional.<String>empty(), RequestHistoryType.UPDATED, request.toBuilder().setSkipHealthchecks(Optional.of(true)).setInstances(Optional.of(2)).build(), Optional.<String>empty()));
    firstDeploy = initDeploy(new SingularityDeployBuilder(request.getId(), firstDeployId).setCommand(Optional.of("sleep 100")).setHealthcheckUri(Optional.of("http://uri")), System.currentTimeMillis());
    SingularityTask taskOne = launchTask(request, firstDeploy, now + 1000, now + 2000, 1, TaskState.TASK_RUNNING);
    finishDeploy(new SingularityDeployMarker(requestId, firstDeployId, now + 2000, Optional.<String>empty(), Optional.<String>empty()), firstDeploy);
    SingularityRequest updatedRequest = request.toBuilder().setSkipHealthchecks(Optional.<Boolean>empty()).setInstances(Optional.of(2)).build();
    requestManager.saveHistory(new SingularityRequestHistory(now + 3000, Optional.<String>empty(), RequestHistoryType.UPDATED, updatedRequest, Optional.<String>empty()));
    SingularityTask newTaskTwoWithCheck = prepTask(updatedRequest, firstDeploy, now + 4000, 2);
    taskManager.createTaskAndDeletePendingTask(newTaskTwoWithCheck);
    statusUpdate(newTaskTwoWithCheck, TaskState.TASK_RUNNING, Optional.of(now + 5000));
    taskManager.saveHealthcheckResult(new SingularityTaskHealthcheckResult(Optional.of(200), Optional.of(1000L), now + 6000, Optional.<String>empty(), Optional.<String>empty(), newTaskTwoWithCheck.getTaskId(), Optional.<Boolean>empty()));
    SingularityTask unhealthyTaskThree = prepTask(updatedRequest, firstDeploy, now + 4000, 3);
    taskManager.createTaskAndDeletePendingTask(unhealthyTaskThree);
    statusUpdate(unhealthyTaskThree, TaskState.TASK_RUNNING, Optional.of(now + 5000));
    List<SingularityTaskId> activeTaskIds = taskManager.getActiveTaskIdsForRequest(requestId);
    List<SingularityTaskId> healthyTaskIds = deployHealthHelper.getHealthyTasks(updatedRequest, firstDeploy, activeTaskIds, false);
    Assertions.assertTrue(!healthyTaskIds.contains(unhealthyTaskThree.getTaskId()));
    // Healthchecked and skip-healthchecked tasks should both be here
    Assertions.assertEquals(2, healthyTaskIds.size());
    Assertions.assertEquals(DeployHealth.WAITING, deployHealthHelper.getDeployHealth(updatedRequest, firstDeploy, activeTaskIds, false));
    taskManager.saveHealthcheckResult(new SingularityTaskHealthcheckResult(Optional.of(200), Optional.of(1000L), now + 6000, Optional.<String>empty(), Optional.<String>empty(), unhealthyTaskThree.getTaskId(), Optional.<Boolean>empty()));
    Assertions.assertEquals(DeployHealth.HEALTHY, deployHealthHelper.getDeployHealth(updatedRequest, firstDeploy, activeTaskIds, false));
}
Also used : SingularityRequestHistory(com.hubspot.singularity.SingularityRequestHistory) SingularityTaskHealthcheckResult(com.hubspot.singularity.SingularityTaskHealthcheckResult) SingularityTask(com.hubspot.singularity.SingularityTask) SingularityDeployMarker(com.hubspot.singularity.SingularityDeployMarker) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Test(org.junit.jupiter.api.Test)

Aggregations

SingularityTaskHealthcheckResult (com.hubspot.singularity.SingularityTaskHealthcheckResult)20 SingularityTask (com.hubspot.singularity.SingularityTask)11 Test (org.junit.jupiter.api.Test)10 SingularityDeployBuilder (com.hubspot.singularity.SingularityDeployBuilder)8 HealthcheckOptions (com.hubspot.deploy.HealthcheckOptions)7 HealthcheckOptionsBuilder (com.hubspot.deploy.HealthcheckOptionsBuilder)7 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)7 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)7 SingularityDeployFailure (com.hubspot.singularity.SingularityDeployFailure)3 SingularityRequest (com.hubspot.singularity.SingularityRequest)3 SingularityRequestHistory (com.hubspot.singularity.SingularityRequestHistory)3 ArrayList (java.util.ArrayList)3 SingularityLoadBalancerUpdate (com.hubspot.singularity.SingularityLoadBalancerUpdate)2 List (java.util.List)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 LoadBalancerRequestId (com.hubspot.singularity.LoadBalancerRequestType.LoadBalancerRequestId)1 RequestState (com.hubspot.singularity.RequestState)1 SingularityDeployMarker (com.hubspot.singularity.SingularityDeployMarker)1 SingularityPendingDeploy (com.hubspot.singularity.SingularityPendingDeploy)1 SingularityRequestCleanup (com.hubspot.singularity.SingularityRequestCleanup)1