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;
}
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));
}
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());
}
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());
}
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));
}
Aggregations