Search in sources :

Example 6 with SingularityTask

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

the class BlendedHistoryHelper method getTaskHistoriesFor.

public List<SingularityTaskIdHistory> getTaskHistoriesFor(TaskManager taskManager, Collection<SingularityTaskId> taskIds) {
    Map<SingularityTaskId, SingularityTask> tasks = taskManager.getTasks(taskIds);
    Map<SingularityTaskId, List<SingularityTaskHistoryUpdate>> map = taskManager.getTaskHistoryUpdates(taskIds);
    List<SingularityTaskIdHistory> histories = Lists.newArrayListWithCapacity(taskIds.size());
    for (SingularityTaskId taskId : taskIds) {
        List<SingularityTaskHistoryUpdate> historyUpdates = map.get(taskId);
        SingularityTask task = tasks.get(taskId);
        if (task != null) {
            histories.add(SingularityTaskIdHistory.fromTaskIdAndTaskAndUpdates(taskId, task, historyUpdates));
        }
    }
    Collections.sort(histories);
    return histories;
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) SingularityTaskHistoryUpdate(com.hubspot.singularity.SingularityTaskHistoryUpdate) ArrayList(java.util.ArrayList) List(java.util.List) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) SingularityTaskIdHistory(com.hubspot.singularity.SingularityTaskIdHistory)

Example 7 with SingularityTask

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

the class SingularityWebhookSender method checkTaskUpdates.

private int checkTaskUpdates(SingularityWebhook webhook, List<CompletableFuture<Response>> webhookFutures) {
    final List<SingularityTaskHistoryUpdate> taskUpdates = webhookManager.getQueuedTaskUpdatesForHook(webhook.getId());
    int numTaskUpdates = 0;
    for (SingularityTaskHistoryUpdate taskUpdate : taskUpdates) {
        Optional<SingularityTask> task = taskHistoryHelper.getTask(taskUpdate.getTaskId());
        // TODO compress
        if (!task.isPresent()) {
            LOG.warn("Couldn't find task for taskUpdate {}", taskUpdate);
            webhookManager.deleteTaskUpdate(webhook, taskUpdate);
            continue;
        }
        webhookFutures.add(webhookSemaphore.call(() -> executeWebhookAsync(webhook, new SingularityTaskWebhook(task.get(), taskUpdate), new SingularityTaskWebhookAsyncHandler(webhookManager, webhook, taskUpdate, shouldDeleteUpdateOnFailure(numTaskUpdates, taskUpdate.getTimestamp())))));
    }
    return taskUpdates.size();
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) SingularityTaskHistoryUpdate(com.hubspot.singularity.SingularityTaskHistoryUpdate) SingularityTaskWebhook(com.hubspot.singularity.SingularityTaskWebhook)

Example 8 with SingularityTask

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

the class SingularitySchedulerTest method testScheduledNotification.

@Test
public void testScheduledNotification() {
    // run every hour
    schedule = "0 0 * * * ?";
    initScheduledRequest();
    initFirstDeploy();
    configuration.setWarnIfScheduledJobIsRunningForAtLeastMillis(Long.MAX_VALUE);
    configuration.setWarnIfScheduledJobIsRunningPastNextRunPct(200);
    final long now = System.currentTimeMillis();
    SingularityTask firstTask = launchTask(request, firstDeploy, now - TimeUnit.HOURS.toMillis(3), 1, TaskState.TASK_RUNNING);
    scheduledJobPoller.runActionOnPoll();
    Mockito.verify(mailer, Mockito.times(0)).sendTaskOverdueMail(ArgumentMatchers.<Optional<SingularityTask>>any(), ArgumentMatchers.<SingularityTaskId>any(), ArgumentMatchers.<SingularityRequest>any(), ArgumentMatchers.anyLong(), ArgumentMatchers.anyLong());
    configuration.setWarnIfScheduledJobIsRunningForAtLeastMillis(TimeUnit.HOURS.toMillis(1));
    scheduledJobPoller.runActionOnPoll();
    Mockito.verify(mailer, Mockito.times(1)).sendTaskOverdueMail(ArgumentMatchers.<Optional<SingularityTask>>any(), ArgumentMatchers.<SingularityTaskId>any(), ArgumentMatchers.<SingularityRequest>any(), ArgumentMatchers.anyLong(), ArgumentMatchers.anyLong());
    scheduledJobPoller.runActionOnPoll();
    Mockito.verify(mailer, Mockito.times(1)).sendTaskOverdueMail(ArgumentMatchers.<Optional<SingularityTask>>any(), ArgumentMatchers.<SingularityTaskId>any(), ArgumentMatchers.<SingularityRequest>any(), ArgumentMatchers.anyLong(), ArgumentMatchers.anyLong());
    statusUpdate(firstTask, TaskState.TASK_FINISHED);
    Optional<SingularityDeployStatistics> deployStatistics = deployManager.getDeployStatistics(requestId, firstDeployId);
    long oldAvg = deployStatistics.get().getAverageRuntimeMillis().get();
    Assert.assertTrue(deployStatistics.get().getNumTasks() == 1);
    Assert.assertTrue(deployStatistics.get().getAverageRuntimeMillis().get() > 1 && deployStatistics.get().getAverageRuntimeMillis().get() < TimeUnit.DAYS.toMillis(1));
    configuration.setWarnIfScheduledJobIsRunningForAtLeastMillis(1);
    SingularityTask secondTask = launchTask(request, firstDeploy, now - 500, 1, TaskState.TASK_RUNNING);
    scheduledJobPoller.runActionOnPoll();
    Mockito.verify(mailer, Mockito.times(1)).sendTaskOverdueMail(ArgumentMatchers.<Optional<SingularityTask>>any(), ArgumentMatchers.<SingularityTaskId>any(), ArgumentMatchers.<SingularityRequest>any(), ArgumentMatchers.anyLong(), ArgumentMatchers.anyLong());
    statusUpdate(secondTask, TaskState.TASK_FINISHED);
    deployStatistics = deployManager.getDeployStatistics(requestId, firstDeployId);
    Assert.assertTrue(deployStatistics.get().getNumTasks() == 2);
    Assert.assertTrue(deployStatistics.get().getAverageRuntimeMillis().get() > 1 && deployStatistics.get().getAverageRuntimeMillis().get() < oldAvg);
    saveRequest(request.toBuilder().setScheduledExpectedRuntimeMillis(Optional.of(1L)).build());
    SingularityTask thirdTask = launchTask(request, firstDeploy, now - 502, 1, TaskState.TASK_RUNNING);
    scheduledJobPoller.runActionOnPoll();
    Mockito.verify(mailer, Mockito.times(2)).sendTaskOverdueMail(ArgumentMatchers.<Optional<SingularityTask>>any(), ArgumentMatchers.<SingularityTaskId>any(), ArgumentMatchers.<SingularityRequest>any(), ArgumentMatchers.anyLong(), ArgumentMatchers.anyLong());
    taskManager.deleteTaskHistory(thirdTask.getTaskId());
    scheduledJobPoller.runActionOnPoll();
    Mockito.verify(mailer, Mockito.times(3)).sendTaskOverdueMail(ArgumentMatchers.<Optional<SingularityTask>>any(), ArgumentMatchers.<SingularityTaskId>any(), ArgumentMatchers.<SingularityRequest>any(), ArgumentMatchers.anyLong(), ArgumentMatchers.anyLong());
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) SingularityDeployStatistics(com.hubspot.singularity.SingularityDeployStatistics) Test(org.junit.Test)

Example 9 with SingularityTask

use of com.hubspot.singularity.SingularityTask 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 10 with SingularityTask

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

the class SingularitySchedulerTest method testTaskKill.

@Test
public void testTaskKill() {
    initRequest();
    initFirstDeploy();
    SingularityTask firstTask = startTask(firstDeploy);
    taskResource.killTask(firstTask.getTaskId().getId(), Optional.absent(), singularityUser);
    cleaner.drainCleanupQueue();
    killKilledTasks();
    Assert.assertEquals(0, taskManager.getNumCleanupTasks());
    Assert.assertEquals(0, taskManager.getNumActiveTasks());
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) Test(org.junit.Test)

Aggregations

SingularityTask (com.hubspot.singularity.SingularityTask)94 Test (org.junit.Test)66 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)33 SingularityDeployBuilder (com.hubspot.singularity.SingularityDeployBuilder)15 SingularityRequest (com.hubspot.singularity.SingularityRequest)15 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)12 SingularityTaskHealthcheckResult (com.hubspot.singularity.SingularityTaskHealthcheckResult)11 HealthcheckOptions (com.hubspot.deploy.HealthcheckOptions)9 HealthcheckOptionsBuilder (com.hubspot.deploy.HealthcheckOptionsBuilder)9 Resources (com.hubspot.mesos.Resources)7 ArrayList (java.util.ArrayList)7 SingularityTaskHistoryUpdate (com.hubspot.singularity.SingularityTaskHistoryUpdate)6 List (java.util.List)6 SingularityDeployProgress (com.hubspot.singularity.SingularityDeployProgress)5 SingularityRunNowRequestBuilder (com.hubspot.singularity.SingularityRunNowRequestBuilder)5 SingularityLoadBalancerUpdate (com.hubspot.singularity.SingularityLoadBalancerUpdate)4 SingularityPendingTask (com.hubspot.singularity.SingularityPendingTask)4 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)4 SingularityRunNowRequest (com.hubspot.singularity.api.SingularityRunNowRequest)4 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)3