Search in sources :

Example 1 with SingularityScaleRequest

use of com.hubspot.singularity.api.SingularityScaleRequest in project Singularity by HubSpot.

the class SingularitySchedulerTest method testBounce.

@Test
public void testBounce() {
    initRequest();
    requestResource.scale(requestId, new SingularityScaleRequest(Optional.of(3), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent()), singularityUser);
    initFirstDeploy();
    SingularityTask taskOne = startTask(firstDeploy, 1);
    SingularityTask taskTwo = startTask(firstDeploy, 2);
    SingularityTask taskThree = startTask(firstDeploy, 3);
    requestResource.bounce(requestId, Optional.absent(), singularityUser);
    Assert.assertTrue(requestManager.cleanupRequestExists(requestId));
    cleaner.drainCleanupQueue();
    Assert.assertTrue(!requestManager.cleanupRequestExists(requestId));
    Assert.assertTrue(taskManager.getCleanupTaskIds().size() == 3);
    cleaner.drainCleanupQueue();
    Assert.assertTrue(!requestManager.cleanupRequestExists(requestId));
    Assert.assertTrue(taskManager.getCleanupTaskIds().size() == 3);
    resourceOffers();
    Assert.assertTrue(taskManager.getActiveTaskIds().size() == 6);
    cleaner.drainCleanupQueue();
    Assert.assertTrue(taskManager.getCleanupTaskIds().size() == 3);
    for (SingularityTask task : taskManager.getActiveTasks()) {
        if (!task.getTaskId().equals(taskOne.getTaskId()) && !task.getTaskId().equals(taskTwo.getTaskId()) && !task.getTaskId().equals(taskThree.getTaskId())) {
            statusUpdate(task, TaskState.TASK_RUNNING, Optional.of(1L));
        }
    }
    cleaner.drainCleanupQueue();
    Assert.assertTrue(taskManager.getCleanupTaskIds().isEmpty());
    Assert.assertTrue(taskManager.getKilledTaskIdRecords().size() == 3);
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) SingularityScaleRequest(com.hubspot.singularity.api.SingularityScaleRequest) Test(org.junit.Test)

Example 2 with SingularityScaleRequest

use of com.hubspot.singularity.api.SingularityScaleRequest in project Singularity by HubSpot.

the class SingularitySchedulerTest method testScaleDownTakesHighestInstancesWithPendingTask.

@Test
public void testScaleDownTakesHighestInstancesWithPendingTask() {
    initRequest();
    initFirstDeploy();
    saveAndSchedule(request.toBuilder().setInstances(Optional.of(5)));
    resourceOffers();
    Assert.assertEquals(5, taskManager.getActiveTaskIds().size());
    SingularityTaskId instance2 = null;
    for (SingularityTaskId taskId : taskManager.getActiveTaskIds()) {
        if (taskId.getInstanceNo() == 2) {
            instance2 = taskId;
        }
    }
    statusUpdate(taskManager.getTask(instance2).get(), TaskState.TASK_KILLED);
    killKilledTasks();
    scheduler.drainPendingQueue();
    requestResource.scale(requestId, new SingularityScaleRequest(Optional.of(3), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent()), singularityUser);
    scheduler.drainPendingQueue();
    cleaner.drainCleanupQueue();
    // instances 4 and 5 should get killed
    Assert.assertEquals(2, taskManager.getKilledTaskIdRecords().size());
    killKilledTasks();
    resourceOffers();
    // instances 1,2,3 should be active
    Assert.assertEquals(3, taskManager.getActiveTaskIds().size());
    for (SingularityTaskId taskId : taskManager.getActiveTaskIds()) {
        Assert.assertTrue(taskId.getInstanceNo() < 4);
    }
}
Also used : SingularityScaleRequest(com.hubspot.singularity.api.SingularityScaleRequest) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Test(org.junit.Test)

Example 3 with SingularityScaleRequest

use of com.hubspot.singularity.api.SingularityScaleRequest in project Singularity by HubSpot.

the class SingularitySchedulerTest method testIncrementalBounceShutsDownOldTasksPerNewHealthyTask.

@Test
public void testIncrementalBounceShutsDownOldTasksPerNewHealthyTask() {
    initRequest();
    requestResource.scale(requestId, new SingularityScaleRequest(Optional.of(3), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent()), singularityUser);
    initFirstDeploy();
    startTask(firstDeploy, 1);
    startTask(firstDeploy, 2);
    startTask(firstDeploy, 3);
    requestResource.bounce(requestId, Optional.of(new SingularityBounceRequest(Optional.of(true), Optional.absent(), Optional.of(1L), Optional.absent(), Optional.of("msg"), Optional.absent())), singularityUser);
    Assert.assertTrue(requestManager.cleanupRequestExists(requestId));
    cleaner.drainCleanupQueue();
    Assert.assertTrue(!requestManager.cleanupRequestExists(requestId));
    Assert.assertEquals(3, taskManager.getCleanupTaskIds().size());
    SingularityTask newTask = launchTask(request, firstDeploy, 5, TaskState.TASK_STARTING);
    cleaner.drainCleanupQueue();
    Assert.assertEquals(0, taskManager.getKilledTaskIdRecords().size());
    Assert.assertEquals(4, taskManager.getActiveTaskIds().size());
    statusUpdate(newTask, TaskState.TASK_RUNNING);
    cleaner.drainCleanupQueue();
    Assert.assertEquals(1, taskManager.getKilledTaskIdRecords().size());
    Assert.assertEquals(4, taskManager.getActiveTaskIds().size());
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) SingularityBounceRequest(com.hubspot.singularity.api.SingularityBounceRequest) SingularityScaleRequest(com.hubspot.singularity.api.SingularityScaleRequest) Test(org.junit.Test)

Example 4 with SingularityScaleRequest

use of com.hubspot.singularity.api.SingularityScaleRequest in project Singularity by HubSpot.

the class SingularitySchedulerTestBase method initWithTasks.

protected void initWithTasks(int num) {
    initRequest();
    requestResource.scale(requestId, new SingularityScaleRequest(Optional.of(num), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent()), singularityUser);
    initFirstDeploy();
    startTasks(num);
}
Also used : SingularityScaleRequest(com.hubspot.singularity.api.SingularityScaleRequest)

Example 5 with SingularityScaleRequest

use of com.hubspot.singularity.api.SingularityScaleRequest in project Singularity by HubSpot.

the class SingularityExpiringActionsTest method testExpiringIncrementalBounce.

@Test
public void testExpiringIncrementalBounce() {
    initRequest();
    requestResource.scale(requestId, new SingularityScaleRequest(Optional.of(3), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent()), singularityUser);
    initFirstDeploy();
    startTask(firstDeploy, 1);
    startTask(firstDeploy, 2);
    startTask(firstDeploy, 3);
    requestResource.bounce(requestId, Optional.of(new SingularityBounceRequest(Optional.of(true), Optional.absent(), Optional.of(1L), Optional.absent(), Optional.of("msg"), Optional.absent())), singularityUser);
    Assert.assertTrue(requestManager.cleanupRequestExists(requestId));
    Assert.assertEquals("msg", requestManager.getCleanupRequests().get(0).getMessage().get());
    Assert.assertTrue(requestManager.getCleanupRequests().get(0).getActionId().isPresent());
    String actionId = requestManager.getCleanupRequests().get(0).getActionId().get();
    cleaner.drainCleanupQueue();
    Assert.assertTrue(!requestManager.cleanupRequestExists(requestId));
    Assert.assertTrue(taskManager.getCleanupTaskIds().size() == 3);
    Assert.assertEquals("msg", taskManager.getCleanupTasks().get(0).getMessage().get());
    Assert.assertEquals(actionId, taskManager.getCleanupTasks().get(0).getActionId().get());
    startTask(firstDeploy, 4);
    // launchTask(request, firstDeploy, 5, TaskState.TASK_STARTING);
    cleaner.drainCleanupQueue();
    Assert.assertEquals(1, taskManager.getKilledTaskIdRecords().size());
    Assert.assertEquals(4, taskManager.getActiveTaskIds().size());
    try {
        Thread.sleep(2);
    } catch (InterruptedException ie) {
    }
    expiringUserActionPoller.runActionOnPoll();
    cleaner.drainCleanupQueue();
    resourceOffers();
    killKilledTasks();
    Assert.assertTrue(!requestManager.getExpiringBounce(requestId).isPresent());
    Assert.assertTrue(requestManager.getPendingRequests().isEmpty());
    Assert.assertTrue(taskManager.getPendingTaskIds().isEmpty());
    Assert.assertTrue(taskManager.getActiveTaskIds().size() == 3);
    Assert.assertTrue(!requestManager.cleanupRequestExists(requestId));
    Assert.assertTrue(taskManager.getCleanupTasks().isEmpty());
}
Also used : SingularityBounceRequest(com.hubspot.singularity.api.SingularityBounceRequest) SingularityScaleRequest(com.hubspot.singularity.api.SingularityScaleRequest) Test(org.junit.Test)

Aggregations

SingularityScaleRequest (com.hubspot.singularity.api.SingularityScaleRequest)12 Test (org.junit.Test)11 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)3 MesosTaskMonitorObject (com.hubspot.mesos.json.MesosTaskMonitorObject)2 SingularitySlaveUsage (com.hubspot.singularity.SingularitySlaveUsage)2 ResourceUsageType (com.hubspot.singularity.SingularitySlaveUsage.ResourceUsageType)2 SingularityTask (com.hubspot.singularity.SingularityTask)2 SingularityBounceRequest (com.hubspot.singularity.api.SingularityBounceRequest)2 HashMap (java.util.HashMap)2 Offer (org.apache.mesos.v1.Protos.Offer)2 SingularityKilledTaskIdRecord (com.hubspot.singularity.SingularityKilledTaskIdRecord)1 SingularityDeleteRequestRequest (com.hubspot.singularity.api.SingularityDeleteRequestRequest)1