use of com.hubspot.singularity.SingularityTask in project Singularity by HubSpot.
the class SingularitySchedulerTest method itSetsRequestStateToDeletedIfTaskCleanupFails.
@Test
public void itSetsRequestStateToDeletedIfTaskCleanupFails() {
initRequest();
SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
requestResource.postRequest(request.toBuilder().setInstances(Optional.of(2)).build(), singularityUser);
initFirstDeploy();
SingularityTask firstTask = launchTask(request, firstDeploy, 1, TaskState.TASK_RUNNING);
launchTask(request, firstDeploy, 2, TaskState.TASK_RUNNING);
Assert.assertEquals(requestId, requestManager.getActiveRequests().iterator().next().getRequest().getId());
Assert.assertEquals(2, taskManager.getActiveTaskIds().size());
requestManager.startDeletingRequest(request, Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent());
Assert.assertEquals(requestId, requestManager.getCleanupRequests().get(0).getRequestId());
Assert.assertEquals(RequestState.DELETING, requestManager.getRequest(requestId).get().getState());
statusUpdate(firstTask, TaskState.TASK_FAILED);
Assert.assertEquals(1, taskManager.getActiveTaskIds().size());
cleaner.drainCleanupQueue();
Assert.assertEquals(0, taskManager.getCleanupTaskIds().size());
killKilledTasks();
cleaner.drainCleanupQueue();
Assert.assertFalse(requestManager.getRequest(requestId).isPresent());
}
use of com.hubspot.singularity.SingularityTask in project Singularity by HubSpot.
the class SingularitySchedulerTest method testCooldownAfterSequentialFailures.
@Test
public void testCooldownAfterSequentialFailures() {
initRequest();
initFirstDeploy();
Assert.assertTrue(requestManager.getRequest(requestId).get().getState() == RequestState.ACTIVE);
configuration.setCooldownAfterFailures(2);
SingularityTask firstTask = startTask(firstDeploy);
SingularityTask secondTask = startTask(firstDeploy);
statusUpdate(firstTask, TaskState.TASK_FAILED);
Assert.assertTrue(requestManager.getRequest(requestId).get().getState() == RequestState.ACTIVE);
statusUpdate(secondTask, TaskState.TASK_FAILED);
Assert.assertTrue(requestManager.getRequest(requestId).get().getState() == RequestState.SYSTEM_COOLDOWN);
cooldownChecker.checkCooldowns();
Assert.assertTrue(requestManager.getRequest(requestId).get().getState() == RequestState.SYSTEM_COOLDOWN);
SingularityTask thirdTask = startTask(firstDeploy);
statusUpdate(thirdTask, TaskState.TASK_FINISHED);
Assert.assertTrue(requestManager.getRequest(requestId).get().getState() == RequestState.ACTIVE);
}
use of com.hubspot.singularity.SingularityTask in project Singularity by HubSpot.
the class SingularitySchedulerTest method testIncrementalBounce.
@Test
public void testIncrementalBounce() {
initRequest();
// set up slaves so scale validate will pass
resourceOffers(2);
SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
requestResource.postRequest(request.toBuilder().setSlavePlacement(Optional.of(SlavePlacement.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>absent(), Optional.absent(), requestId, Optional.of(firstDeployId), Optional.<Boolean>absent(), Optional.<String>absent(), Optional.<String>absent(), Optional.<SingularityShellCommand>absent()));
Assert.assertTrue(requestManager.cleanupRequestExists(requestId));
cleaner.drainCleanupQueue();
Assert.assertTrue(!requestManager.cleanupRequestExists(requestId));
Assert.assertEquals(2, taskManager.getCleanupTaskIds().size());
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));
Assert.assertEquals(3, taskManager.getActiveTaskIds().size());
cleaner.drainCleanupQueue();
// No old tasks should be killed before new ones pass healthchecks
Assert.assertEquals(2, taskManager.getCleanupTaskIds().size());
taskManager.saveHealthcheckResult(new SingularityTaskHealthcheckResult(Optional.of(200), Optional.of(1000L), System.currentTimeMillis(), Optional.<String>absent(), Optional.<String>absent(), taskThree.getTaskId(), Optional.<Boolean>absent()));
cleaner.drainCleanupQueue();
Assert.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>absent(), Optional.<String>absent(), taskFour.getTaskId(), Optional.<Boolean>absent()));
cleaner.drainCleanupQueue();
Assert.assertTrue(taskManager.getCleanupTaskIds().isEmpty());
}
use of com.hubspot.singularity.SingularityTask in project Singularity by HubSpot.
the class SingularitySchedulerTest method testCleanerLeavesPausedRequestTasksByDemand.
@Test
public void testCleanerLeavesPausedRequestTasksByDemand() {
initScheduledRequest();
initFirstDeploy();
SingularityTask firstTask = launchTask(request, firstDeploy, 1, TaskState.TASK_RUNNING);
createAndSchedulePendingTask(firstDeployId);
requestResource.pause(requestId, Optional.of(new SingularityPauseRequest(Optional.of(false), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent())), singularityUser);
cleaner.drainCleanupQueue();
Assert.assertTrue(taskManager.getKilledTaskIdRecords().isEmpty());
Assert.assertTrue(taskManager.getPendingTaskIds().isEmpty());
Assert.assertTrue(requestManager.getCleanupRequests().isEmpty());
statusUpdate(firstTask, TaskState.TASK_FINISHED);
// make sure something new isn't scheduled!
Assert.assertTrue(taskManager.getPendingTaskIds().isEmpty());
}
use of com.hubspot.singularity.SingularityTask in project Singularity by HubSpot.
the class SingularitySchedulerTest method testCustomResourcesWithRunNowRequest.
@Test
public void testCustomResourcesWithRunNowRequest() {
SingularityRequestBuilder bldr = new SingularityRequestBuilder(requestId, RequestType.ON_DEMAND);
requestResource.postRequest(bldr.build(), singularityUser);
deploy("d2");
SingularityRunNowRequest runNowRequest = new SingularityRunNowRequestBuilder().setResources(new Resources(2, 2, 0)).build();
requestResource.scheduleImmediately(singularityUser, requestId, runNowRequest);
scheduler.drainPendingQueue();
SingularityPendingTask pendingTaskWithResourcs = taskManager.getPendingTasks().get(0);
Assert.assertTrue(pendingTaskWithResourcs.getResources().isPresent());
Assert.assertEquals(pendingTaskWithResourcs.getResources().get().getCpus(), 2, 0.0);
sms.resourceOffers(Arrays.asList(createOffer(5, 5, 5, "slave1", "host1", Optional.of("rack1"))));
SingularityTask task = taskManager.getActiveTasks().get(0);
Assert.assertEquals(MesosUtils.getNumCpus(mesosProtosUtils.toResourceList(task.getMesosTask().getResources()), Optional.<String>absent()), 2.0, 0.0);
}
Aggregations