Search in sources :

Example 1 with SingularityBounceRequest

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

the class RequestHelper method checkReschedule.

private void checkReschedule(SingularityRequest newRequest, Optional<SingularityRequest> maybeOldRequest, Optional<String> user, long timestamp, Optional<Boolean> skipHealthchecks, Optional<String> message, Optional<SingularityBounceRequest> maybeBounceRequest) {
    if (!maybeOldRequest.isPresent()) {
        return;
    }
    if (shouldReschedule(newRequest, maybeOldRequest.get())) {
        Optional<String> maybeDeployId = deployManager.getInUseDeployId(newRequest.getId());
        if (maybeDeployId.isPresent()) {
            if (maybeBounceRequest.isPresent()) {
                Optional<String> actionId = maybeBounceRequest.get().getActionId().or(Optional.of(UUID.randomUUID().toString()));
                Optional<Boolean> removeFromLoadBalancer = Optional.absent();
                SingularityCreateResult createResult = requestManager.createCleanupRequest(new SingularityRequestCleanup(user, maybeBounceRequest.get().getIncremental().or(true) ? RequestCleanupType.INCREMENTAL_BOUNCE : RequestCleanupType.BOUNCE, System.currentTimeMillis(), Optional.<Boolean>absent(), removeFromLoadBalancer, newRequest.getId(), Optional.of(maybeDeployId.get()), skipHealthchecks, message, actionId, maybeBounceRequest.get().getRunShellCommandBeforeKill()));
                if (createResult != SingularityCreateResult.EXISTED) {
                    requestManager.bounce(newRequest, System.currentTimeMillis(), user, Optional.of("Bouncing due to bounce after scale"));
                    final SingularityBounceRequest validatedBounceRequest = validator.checkBounceRequest(maybeBounceRequest.get());
                    requestManager.saveExpiringObject(new SingularityExpiringBounce(newRequest.getId(), maybeDeployId.get(), user, System.currentTimeMillis(), validatedBounceRequest, actionId.get()));
                } else {
                    requestManager.addToPendingQueue(new SingularityPendingRequest(newRequest.getId(), maybeDeployId.get(), timestamp, user, PendingType.UPDATED_REQUEST, skipHealthchecks, message));
                }
            } else {
                requestManager.addToPendingQueue(new SingularityPendingRequest(newRequest.getId(), maybeDeployId.get(), timestamp, user, PendingType.UPDATED_REQUEST, skipHealthchecks, message));
            }
        }
    }
}
Also used : SingularityRequestCleanup(com.hubspot.singularity.SingularityRequestCleanup) SingularityPendingRequest(com.hubspot.singularity.SingularityPendingRequest) SingularityExpiringBounce(com.hubspot.singularity.expiring.SingularityExpiringBounce) SingularityCreateResult(com.hubspot.singularity.SingularityCreateResult) SingularityBounceRequest(com.hubspot.singularity.api.SingularityBounceRequest)

Example 2 with SingularityBounceRequest

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

the class SingularitySchedulerTest method testBounceOnPendingInstancesReleasesLock.

@Test
public void testBounceOnPendingInstancesReleasesLock() {
    initRequest();
    initFirstDeploy();
    SingularityTask task = startTask(firstDeploy, 1);
    statusUpdate(task, TaskState.TASK_FAILED);
    killKilledTasks();
    Assert.assertEquals("Bounce starts when tasks have not yet been launched", 0, taskManager.getActiveTaskIds().size());
    requestResource.bounce(requestId, Optional.of(new SingularityBounceRequest(Optional.absent(), Optional.of(true), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent())), singularityUser);
    // It acquires a lock on the bounce
    Assert.assertTrue("Lock on bounce should be acquired during bounce", requestManager.getExpiringBounce(requestId).isPresent());
    cleaner.drainCleanupQueue();
    scheduler.drainPendingQueue();
    resourceOffers();
    for (SingularityTaskId singularityTaskId : taskManager.getActiveTaskIds()) {
        taskManager.saveTaskHistoryUpdate(new SingularityTaskHistoryUpdate(singularityTaskId, System.currentTimeMillis(), ExtendedTaskState.TASK_RUNNING, Optional.absent(), Optional.absent(), Collections.emptySet()));
    }
    cleaner.drainCleanupQueue();
    killKilledTasks();
    // It finishes with one task running and the bounce released
    Assert.assertEquals("Should end bounce with target number of tasks", 1, taskManager.getActiveTaskIds().size());
    for (SingularityTaskId singularityTaskId : taskManager.getActiveTaskIds()) {
        String statusMessage = taskManager.getTaskHistoryUpdates(singularityTaskId).get(0).getStatusMessage().get();
        Assert.assertTrue("Task was started by bounce", statusMessage.contains("BOUNCE"));
    }
    Assert.assertFalse("Lock on bounce should be released after bounce", requestManager.getExpiringBounce(requestId).isPresent());
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) SingularityTaskHistoryUpdate(com.hubspot.singularity.SingularityTaskHistoryUpdate) SingularityBounceRequest(com.hubspot.singularity.api.SingularityBounceRequest) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Test(org.junit.Test)

Example 3 with SingularityBounceRequest

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

the class SingularitySchedulerTest method testBounceReleasesLockWithAlternateCleanupType.

@Test
public void testBounceReleasesLockWithAlternateCleanupType() {
    initRequest();
    initFirstDeploy();
    startTask(firstDeploy, 1);
    List<SingularityTaskId> activeTaskIds = taskManager.getActiveTaskIds();
    Assert.assertEquals(1, activeTaskIds.size());
    SingularityTaskId firstTaskId = activeTaskIds.get(0);
    requestResource.bounce(requestId, Optional.of(new SingularityBounceRequest(Optional.absent(), Optional.of(true), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent())), singularityUser);
    Assert.assertTrue(requestManager.isBouncing(requestId));
    cleaner.drainCleanupQueue();
    scheduler.drainPendingQueue();
    resourceOffers();
    // Save a new cleanup type over the old one, and make sure the bounce lock still releases
    taskManager.saveTaskCleanup(new SingularityTaskCleanup(Optional.absent(), TaskCleanupType.USER_REQUESTED, System.currentTimeMillis(), firstTaskId, Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent()));
    for (SingularityTaskId singularityTaskId : taskManager.getActiveTaskIds()) {
        taskManager.saveTaskHistoryUpdate(new SingularityTaskHistoryUpdate(singularityTaskId, System.currentTimeMillis(), ExtendedTaskState.TASK_RUNNING, Optional.absent(), Optional.absent(), Collections.emptySet()));
    }
    Assert.assertTrue(requestManager.isBouncing(requestId));
    cleaner.drainCleanupQueue();
    killKilledTasks();
    Assert.assertFalse(requestManager.isBouncing(requestId));
}
Also used : SingularityTaskHistoryUpdate(com.hubspot.singularity.SingularityTaskHistoryUpdate) SingularityTaskCleanup(com.hubspot.singularity.SingularityTaskCleanup) SingularityBounceRequest(com.hubspot.singularity.api.SingularityBounceRequest) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Test(org.junit.Test)

Example 4 with SingularityBounceRequest

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

the class SingularitySchedulerTest method testBounceOnRunningInstancesReleasesLock.

@Test
public void testBounceOnRunningInstancesReleasesLock() {
    initRequest();
    initFirstDeploy();
    startTask(firstDeploy, 1);
    Assert.assertEquals(1, taskManager.getActiveTaskIds().size());
    requestResource.bounce(requestId, Optional.of(new SingularityBounceRequest(Optional.absent(), Optional.of(true), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent())), singularityUser);
    Assert.assertTrue(requestManager.isBouncing(requestId));
    cleaner.drainCleanupQueue();
    // It acquires a lock on the bounce
    Assert.assertTrue("Lock on bounce should be acquired during bounce", requestManager.getExpiringBounce(requestId).isPresent());
    scheduler.drainPendingQueue();
    resourceOffers();
    for (SingularityTaskId singularityTaskId : taskManager.getActiveTaskIds()) {
        taskManager.saveTaskHistoryUpdate(new SingularityTaskHistoryUpdate(singularityTaskId, System.currentTimeMillis(), ExtendedTaskState.TASK_RUNNING, Optional.absent(), Optional.absent(), Collections.emptySet()));
    }
    Assert.assertTrue("Need to start at least 1 instance to begin killing old instances", taskManager.getActiveTaskIds().size() >= 2);
    Assert.assertTrue(requestManager.isBouncing(requestId));
    cleaner.drainCleanupQueue();
    killKilledTasks();
    Assert.assertFalse(requestManager.isBouncing(requestId));
    // It finishes with one task running and the bounce released
    Assert.assertEquals("Should end bounce with target number of tasks", 1, taskManager.getActiveTaskIds().size());
    for (SingularityTaskId singularityTaskId : taskManager.getActiveTaskIds()) {
        String statusMessage = taskManager.getTaskHistoryUpdates(singularityTaskId).get(0).getStatusMessage().get();
        Assert.assertTrue("Task was started by bounce", statusMessage.contains("BOUNCE"));
    }
    Assert.assertFalse("Lock on bounce should be released after bounce", requestManager.getExpiringBounce(requestId).isPresent());
}
Also used : SingularityTaskHistoryUpdate(com.hubspot.singularity.SingularityTaskHistoryUpdate) SingularityBounceRequest(com.hubspot.singularity.api.SingularityBounceRequest) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Test(org.junit.Test)

Example 5 with SingularityBounceRequest

use of com.hubspot.singularity.api.SingularityBounceRequest 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)

Aggregations

SingularityBounceRequest (com.hubspot.singularity.api.SingularityBounceRequest)10 Test (org.junit.Test)7 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)4 SingularityTask (com.hubspot.singularity.SingularityTask)3 SingularityTaskHistoryUpdate (com.hubspot.singularity.SingularityTaskHistoryUpdate)3 SingularityRequestCleanup (com.hubspot.singularity.SingularityRequestCleanup)2 SingularityRequestWithState (com.hubspot.singularity.SingularityRequestWithState)2 SingularityShellCommand (com.hubspot.singularity.SingularityShellCommand)2 SingularityTaskCleanup (com.hubspot.singularity.SingularityTaskCleanup)2 SingularityScaleRequest (com.hubspot.singularity.api.SingularityScaleRequest)2 SingularityExpiringBounce (com.hubspot.singularity.expiring.SingularityExpiringBounce)2 ByteString (com.google.protobuf.ByteString)1 SingularityCreateResult (com.hubspot.singularity.SingularityCreateResult)1 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)1 SingularityRequest (com.hubspot.singularity.SingularityRequest)1 SingularityTaskShellCommandRequestId (com.hubspot.singularity.SingularityTaskShellCommandRequestId)1 SingularityTaskShellCommandUpdate (com.hubspot.singularity.SingularityTaskShellCommandUpdate)1 SingularityExpiringScale (com.hubspot.singularity.expiring.SingularityExpiringScale)1