Search in sources :

Example 16 with SingularityTaskCleanup

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

the class SingularitySlavePlacementTest method testRackPlacementOnScaleDown.

@Test
public void testRackPlacementOnScaleDown() {
    try {
        configuration.setRebalanceRacksOnScaleDown(true);
        // Set up 3 active racks
        sms.resourceOffers(Arrays.asList(createOffer(1, 128, 1024, "slave1", "host1", Optional.of("rack1"))));
        sms.resourceOffers(Arrays.asList(createOffer(1, 128, 1024, "slave2", "host2", Optional.of("rack2"))));
        sms.resourceOffers(Arrays.asList(createOffer(1, 128, 1024, "slave3", "host3", Optional.of("rack3"))));
        initRequest();
        initFirstDeploy();
        saveAndSchedule(request.toBuilder().setInstances(Optional.of(7)).setRackSensitive(Optional.of(true)));
        sms.resourceOffers(Arrays.asList(createOffer(2, 256, 2048, "slave1", "host1", Optional.of("rack1"))));
        sms.resourceOffers(Arrays.asList(createOffer(2, 256, 2048, "slave2", "host2", Optional.of("rack2"))));
        sms.resourceOffers(Arrays.asList(createOffer(3, 384, 3072, "slave3", "host3", Optional.of("rack3"))));
        Assert.assertEquals(7, taskManager.getActiveTaskIds().size());
        requestResource.postRequest(request.toBuilder().setInstances(Optional.of(4)).setRackSensitive(Optional.of(true)).build(), singularityUser);
        scheduler.drainPendingQueue();
        Assert.assertEquals(4, taskManager.getNumCleanupTasks());
        int rebalanceRackCleanups = 0;
        for (SingularityTaskCleanup cleanup : taskManager.getCleanupTasks()) {
            if (cleanup.getCleanupType() == TaskCleanupType.REBALANCE_RACKS) {
                rebalanceRackCleanups++;
            }
        }
        Assert.assertEquals(1, rebalanceRackCleanups);
        Assert.assertEquals(1, taskManager.getPendingTaskIds().size());
    } finally {
        configuration.setRebalanceRacksOnScaleDown(false);
    }
}
Also used : SingularityTaskCleanup(com.hubspot.singularity.SingularityTaskCleanup) Test(org.junit.Test)

Aggregations

SingularityTaskCleanup (com.hubspot.singularity.SingularityTaskCleanup)16 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)9 SingularityTaskShellCommandRequestId (com.hubspot.singularity.SingularityTaskShellCommandRequestId)9 SingularityTask (com.hubspot.singularity.SingularityTask)5 SingularityTaskShellCommandRequest (com.hubspot.singularity.SingularityTaskShellCommandRequest)5 Test (org.junit.Test)5 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)4 TaskCleanupType (com.hubspot.singularity.TaskCleanupType)4 ArrayList (java.util.ArrayList)3 Optional (com.google.common.base.Optional)2 Inject (com.google.inject.Inject)2 SingularityDeleteResult (com.hubspot.singularity.SingularityDeleteResult)2 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)2 SingularityDeployKey (com.hubspot.singularity.SingularityDeployKey)2 PendingType (com.hubspot.singularity.SingularityPendingRequest.PendingType)2 SingularityRequest (com.hubspot.singularity.SingularityRequest)2 SingularityRequestDeployState (com.hubspot.singularity.SingularityRequestDeployState)2 SingularityRequestWithState (com.hubspot.singularity.SingularityRequestWithState)2 SingularityTaskShellCommandUpdate (com.hubspot.singularity.SingularityTaskShellCommandUpdate)2 SingularityBounceRequest (com.hubspot.singularity.api.SingularityBounceRequest)2