use of com.hubspot.singularity.SingularityTask in project Singularity by HubSpot.
the class SingularityHealthchecksTest method testFailingStatusCodes.
@Test
public void testFailingStatusCodes() {
initRequest();
final String deployId = "retry_test";
List<Integer> failureCodes = ImmutableList.of(404);
HealthcheckOptions options = new HealthcheckOptionsBuilder("http://uri").setMaxRetries(Optional.of(3)).setFailureStatusCodes(Optional.of(failureCodes)).build();
SingularityDeployBuilder db = new SingularityDeployBuilder(requestId, deployId).setHealthcheck(Optional.of(options));
SingularityDeploy deploy = initDeploy(db, System.currentTimeMillis());
deployChecker.checkDeploys();
Assert.assertTrue(!deployManager.getDeployResult(requestId, deployId).isPresent());
SingularityTask task = launchTask(request, deploy, System.currentTimeMillis(), 1, TaskState.TASK_RUNNING);
deployChecker.checkDeploys();
Assert.assertTrue(!deployManager.getDeployResult(requestId, deployId).isPresent());
taskManager.saveHealthcheckResult(new SingularityTaskHealthcheckResult(Optional.of(503), Optional.of(1000L), System.currentTimeMillis(), Optional.<String>absent(), Optional.<String>absent(), task.getTaskId(), Optional.<Boolean>absent()));
deployChecker.checkDeploys();
Assert.assertTrue(!deployManager.getDeployResult(requestId, deployId).isPresent());
taskManager.saveHealthcheckResult(new SingularityTaskHealthcheckResult(Optional.of(404), Optional.of(1000L), System.currentTimeMillis() + 1, Optional.<String>absent(), Optional.<String>absent(), task.getTaskId(), Optional.<Boolean>absent()));
deployChecker.checkDeploys();
// Bad status code should cause instant failure even though retries remain
Assert.assertEquals(DeployState.FAILED, deployManager.getDeployResult(requestId, deployId).get().getDeployState());
}
use of com.hubspot.singularity.SingularityTask in project Singularity by HubSpot.
the class SingularityHealthchecksTest method testPortNumber.
@Test
public void testPortNumber() {
try {
setConfigurationForNoDelay();
initRequest();
HealthcheckOptions options = new HealthcheckOptionsBuilder("http://uri").setPortNumber(Optional.of(81L)).setStartupDelaySeconds(Optional.of(0)).build();
firstDeploy = initAndFinishDeploy(request, new SingularityDeployBuilder(request.getId(), firstDeployId).setCommand(Optional.of("sleep 100")).setResources(Optional.of(new Resources(1, 64, 3, 0))).setHealthcheck(Optional.of(options)), Optional.absent());
requestResource.postRequest(request.toBuilder().setInstances(Optional.of(2)).build(), singularityUser);
scheduler.drainPendingQueue();
String[] portRange = { "80:82" };
sms.resourceOffers(Arrays.asList(createOffer(20, 20000, 50000, "slave1", "host1", Optional.<String>absent(), Collections.<String, String>emptyMap(), portRange)));
SingularityTaskId firstTaskId = taskManager.getActiveTaskIdsForRequest(requestId).get(0);
SingularityTask firstTask = taskManager.getTask(firstTaskId).get();
statusUpdate(firstTask, TaskState.TASK_RUNNING);
newTaskChecker.enqueueNewTaskCheck(firstTask, requestManager.getRequest(requestId), healthchecker);
Awaitility.await("healthcheck present").atMost(5, TimeUnit.SECONDS).until(() -> taskManager.getLastHealthcheck(firstTask.getTaskId()).isPresent());
Assert.assertTrue(taskManager.getLastHealthcheck(firstTask.getTaskId()).get().toString().contains("host1:81"));
} finally {
unsetConfigurationForNoDelay();
}
}
use of com.hubspot.singularity.SingularityTask in project Singularity by HubSpot.
the class SingularityHealthchecksTest method testSkipHealthchecksDuringBounce.
@Test
public void testSkipHealthchecksDuringBounce() {
try {
initRequest();
initHCDeploy();
SingularityTask firstTask = startTask(firstDeploy, 1);
requestResource.bounce(requestId, Optional.of(new SingularityBounceRequest(Optional.absent(), Optional.of(true), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent())), singularityUser);
setConfigurationForNoDelay();
cleaner.drainCleanupQueue();
resourceOffers();
List<SingularityTaskId> taskIds = taskManager.getAllTaskIds();
taskIds.remove(firstTask.getTaskId());
SingularityTaskId secondTaskId = taskIds.get(0);
SingularityTask secondTask = taskManager.getTask(secondTaskId).get();
statusUpdate(secondTask, TaskState.TASK_RUNNING);
Assert.assertTrue(healthchecker.cancelHealthcheck(firstTask.getTaskId().getId()));
newTaskChecker.cancelNewTaskCheck(firstTask.getTaskId().getId());
finishHealthchecks();
finishNewTaskChecks();
Assert.assertTrue(!taskManager.getLastHealthcheck(secondTask.getTaskId()).isPresent());
cleaner.drainCleanupQueue();
killKilledTasks();
Assert.assertEquals(0, taskManager.getNumCleanupTasks());
Assert.assertEquals(1, taskManager.getNumActiveTasks());
} finally {
unsetConfigurationForNoDelay();
}
}
use of com.hubspot.singularity.SingularityTask in project Singularity by HubSpot.
the class StateManagerTest method itDoesntCountCleaningTasks.
@Test
public void itDoesntCountCleaningTasks() {
initRequest();
initFirstDeploy();
SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
saveAndSchedule(request.toBuilder().setInstances(Optional.of(3)));
resourceOffers();
Assert.assertEquals(3, taskManager.getActiveTaskIds().size());
Assert.assertEquals(0, stateManager.getState(true, false).getOverProvisionedRequests());
Assert.assertEquals(0, stateManager.getState(true, false).getUnderProvisionedRequests());
SingularityTask task = taskManager.getActiveTasks().get(0);
statusUpdate(task, TaskState.TASK_KILLED);
scheduler.drainPendingQueue();
taskManager.createTaskCleanup(new SingularityTaskCleanup(Optional.absent(), TaskCleanupType.BOUNCING, 1L, task.getTaskId(), Optional.absent(), Optional.absent(), Optional.absent()));
Assert.assertEquals(2, taskManager.getActiveTaskIds().size());
Assert.assertEquals(0, stateManager.getState(true, false).getOverProvisionedRequests());
Assert.assertEquals(1, stateManager.getState(true, false).getUnderProvisionedRequests());
launchTask(request, firstDeploy, 4, TaskState.TASK_RUNNING);
launchTask(request, firstDeploy, 5, TaskState.TASK_RUNNING);
Assert.assertEquals(4, taskManager.getActiveTaskIds().size());
Assert.assertEquals(0, stateManager.getState(true, false).getUnderProvisionedRequests());
Assert.assertEquals(1, stateManager.getState(true, false).getOverProvisionedRequests());
}
use of com.hubspot.singularity.SingularityTask in project Singularity by HubSpot.
the class SingularityMesosSchedulerImpl method killAndRecord.
public void killAndRecord(SingularityTaskId taskId, Optional<RequestCleanupType> requestCleanupType, Optional<TaskCleanupType> taskCleanupType, Optional<Long> originalTimestamp, Optional<Integer> retries, Optional<String> user) {
Preconditions.checkState(isRunning());
Optional<TaskCleanupType> maybeCleanupFromRequestAndTask = getTaskCleanupType(requestCleanupType, taskCleanupType);
if (maybeCleanupFromRequestAndTask.isPresent() && (maybeCleanupFromRequestAndTask.get() == TaskCleanupType.USER_REQUESTED_DESTROY || maybeCleanupFromRequestAndTask.get() == TaskCleanupType.REQUEST_DELETING)) {
Optional<SingularityTask> task = taskManager.getTask(taskId);
if (task.isPresent()) {
if (task.get().getTaskRequest().getDeploy().getCustomExecutorCmd().isPresent()) {
byte[] messageBytes = transcoder.toBytes(new SingularityTaskDestroyFrameworkMessage(taskId, user));
mesosSchedulerClient.frameworkMessage(MesosProtosUtils.toExecutorId(task.get().getMesosTask().getExecutor().getExecutorId()), MesosProtosUtils.toAgentId(task.get().getMesosTask().getAgentId()), messageBytes);
} else {
LOG.warn("Not using custom executor, will not send framework message to destroy task");
}
} else {
String message = String.format("No task data available to build kill task framework message for task %s", taskId);
exceptionNotifier.notify(message);
LOG.error(message);
}
}
mesosSchedulerClient.kill(TaskID.newBuilder().setValue(taskId.toString()).build());
taskManager.saveKilledRecord(new SingularityKilledTaskIdRecord(taskId, System.currentTimeMillis(), originalTimestamp.or(System.currentTimeMillis()), requestCleanupType, taskCleanupType, retries.or(-1) + 1));
}
Aggregations