Search in sources :

Example 11 with SingularityTaskId

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

the class SingularityExecutorLogging method buildTaskLogger.

public Logger buildTaskLogger(String taskId, String executorId, String executorPid, String taskLogFile) {
    LOG.info("Building a task logger for {} pointing to {}", taskId, taskLogFile);
    LoggerContext context = new LoggerContext();
    context.setName(executorPid);
    baseLogging.prepareRootLogger(context);
    String loggerId = taskId;
    try {
        SingularityTaskId singularityTaskId = SingularityTaskId.valueOf(taskId);
        loggerId = String.format("%s.%s.%s.%s.%s", singularityTaskId.getRequestId(), singularityTaskId.getDeployId(), singularityTaskId.getStartedAt(), singularityTaskId.getInstanceNo(), executorId);
    } catch (InvalidSingularityTaskIdException e) {
        LOG.info("Handling non-SingularityTaskId %s", taskId);
    }
    Logger taskLogger = context.getLogger(loggerId);
    taskLogger.detachAndStopAllAppenders();
    if (baseLogging.getRootLogPath().isPresent()) {
        taskLogger.addAppender(baseLogging.buildFileAppender(context, baseLogging.getRootLogPath().get()));
    }
    taskLogger.addAppender(baseLogging.buildFileAppender(context, taskLogFile));
    context.start();
    return taskLogger;
}
Also used : InvalidSingularityTaskIdException(com.hubspot.singularity.InvalidSingularityTaskIdException) Logger(ch.qos.logback.classic.Logger) LoggerContext(ch.qos.logback.classic.LoggerContext) SingularityTaskId(com.hubspot.singularity.SingularityTaskId)

Example 12 with SingularityTaskId

use of com.hubspot.singularity.SingularityTaskId 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 13 with SingularityTaskId

use of com.hubspot.singularity.SingularityTaskId 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 14 with SingularityTaskId

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

the class SingularitySchedulerTest method testBounceWithLoadBalancer.

@Test
public void testBounceWithLoadBalancer() {
    initLoadBalancedRequest();
    initFirstDeploy();
    configuration.setNewTaskCheckerBaseDelaySeconds(1000000);
    SingularityTask taskOne = launchTask(request, firstDeploy, 1, TaskState.TASK_RUNNING);
    saveLoadBalancerState(BaragonRequestState.SUCCESS, taskOne.getTaskId(), LoadBalancerRequestType.ADD);
    requestResource.bounce(requestId, Optional.absent(), singularityUser);
    cleaner.drainCleanupQueue();
    resourceOffers();
    Assert.assertEquals(2, taskManager.getNumActiveTasks());
    List<SingularityTaskId> tasks = taskManager.getActiveTaskIds();
    tasks.remove(taskOne.getTaskId());
    SingularityTaskId taskTwo = tasks.get(0);
    cleaner.drainCleanupQueue();
    runLaunchedTasks();
    cleaner.drainCleanupQueue();
    Assert.assertEquals(0, taskManager.getKilledTaskIdRecords().size());
    Assert.assertEquals(2, taskManager.getNumActiveTasks());
    // add to LB:
    saveLoadBalancerState(BaragonRequestState.SUCCESS, taskTwo, LoadBalancerRequestType.ADD);
    cleaner.drainCleanupQueue();
    Assert.assertEquals(0, taskManager.getKilledTaskIdRecords().size());
    Assert.assertEquals(2, taskManager.getNumActiveTasks());
    saveLoadBalancerState(BaragonRequestState.SUCCESS, taskOne.getTaskId(), LoadBalancerRequestType.REMOVE);
    cleaner.drainCleanupQueue();
    Assert.assertEquals(1, taskManager.getKilledTaskIdRecords().size());
    killKilledTasks();
    Assert.assertEquals(1, taskManager.getNumActiveTasks());
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Test(org.junit.Test)

Example 15 with SingularityTaskId

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

the class SingularitySchedulerTest method testCleanerFindsTasksWithSkippedHealthchecks.

@Test
public void testCleanerFindsTasksWithSkippedHealthchecks() {
    initRequest();
    // set up slaves so scale validate will pass
    resourceOffers(2);
    SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
    long now = System.currentTimeMillis();
    requestManager.saveHistory(new SingularityRequestHistory(now, Optional.<String>absent(), RequestHistoryType.UPDATED, request.toBuilder().setSkipHealthchecks(Optional.of(true)).setInstances(Optional.of(2)).build(), Optional.<String>absent()));
    firstDeploy = initDeploy(new SingularityDeployBuilder(request.getId(), firstDeployId).setCommand(Optional.of("sleep 100")).setHealthcheckUri(Optional.of("http://uri")), System.currentTimeMillis());
    SingularityTask taskOne = launchTask(request, firstDeploy, now + 1000, now + 2000, 1, TaskState.TASK_RUNNING);
    finishDeploy(new SingularityDeployMarker(requestId, firstDeployId, now + 2000, Optional.<String>absent(), Optional.<String>absent()), firstDeploy);
    SingularityRequest updatedRequest = request.toBuilder().setSkipHealthchecks(Optional.<Boolean>absent()).setInstances(Optional.of(2)).build();
    requestManager.saveHistory(new SingularityRequestHistory(now + 3000, Optional.<String>absent(), RequestHistoryType.UPDATED, updatedRequest, Optional.<String>absent()));
    SingularityTask newTaskTwoWithCheck = prepTask(updatedRequest, firstDeploy, now + 4000, 2);
    taskManager.createTaskAndDeletePendingTask(newTaskTwoWithCheck);
    statusUpdate(newTaskTwoWithCheck, TaskState.TASK_RUNNING, Optional.of(now + 5000));
    taskManager.saveHealthcheckResult(new SingularityTaskHealthcheckResult(Optional.of(200), Optional.of(1000L), now + 6000, Optional.<String>absent(), Optional.<String>absent(), newTaskTwoWithCheck.getTaskId(), Optional.<Boolean>absent()));
    SingularityTask unhealthyTaskThree = prepTask(updatedRequest, firstDeploy, now + 4000, 3);
    taskManager.createTaskAndDeletePendingTask(unhealthyTaskThree);
    statusUpdate(unhealthyTaskThree, TaskState.TASK_RUNNING, Optional.of(now + 5000));
    List<SingularityTaskId> activeTaskIds = taskManager.getActiveTaskIdsForRequest(requestId);
    List<SingularityTaskId> healthyTaskIds = deployHealthHelper.getHealthyTasks(updatedRequest, Optional.of(firstDeploy), activeTaskIds, false);
    Assert.assertTrue(!healthyTaskIds.contains(unhealthyTaskThree.getTaskId()));
    // Healthchecked and skip-healthchecked tasks should both be here
    Assert.assertEquals(2, healthyTaskIds.size());
    Assert.assertEquals(DeployHealth.WAITING, deployHealthHelper.getDeployHealth(updatedRequest, Optional.of(firstDeploy), activeTaskIds, false));
    taskManager.saveHealthcheckResult(new SingularityTaskHealthcheckResult(Optional.of(200), Optional.of(1000L), now + 6000, Optional.<String>absent(), Optional.<String>absent(), unhealthyTaskThree.getTaskId(), Optional.<Boolean>absent()));
    Assert.assertEquals(DeployHealth.HEALTHY, deployHealthHelper.getDeployHealth(updatedRequest, Optional.of(firstDeploy), activeTaskIds, false));
}
Also used : SingularityRequestHistory(com.hubspot.singularity.SingularityRequestHistory) SingularityTaskHealthcheckResult(com.hubspot.singularity.SingularityTaskHealthcheckResult) SingularityTask(com.hubspot.singularity.SingularityTask) SingularityDeployMarker(com.hubspot.singularity.SingularityDeployMarker) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Test(org.junit.Test)

Aggregations

SingularityTaskId (com.hubspot.singularity.SingularityTaskId)106 Test (org.junit.Test)44 SingularityTask (com.hubspot.singularity.SingularityTask)34 SingularityRequest (com.hubspot.singularity.SingularityRequest)26 ArrayList (java.util.ArrayList)26 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)14 SingularityTaskHistoryUpdate (com.hubspot.singularity.SingularityTaskHistoryUpdate)13 MesosTaskMonitorObject (com.hubspot.mesos.json.MesosTaskMonitorObject)12 List (java.util.List)11 SingularityRequestWithState (com.hubspot.singularity.SingularityRequestWithState)10 SingularityDeployProgress (com.hubspot.singularity.SingularityDeployProgress)9 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)9 SingularityRunNowRequest (com.hubspot.singularity.api.SingularityRunNowRequest)9 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)8 SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)7 SingularityTaskCleanup (com.hubspot.singularity.SingularityTaskCleanup)7 SingularityTaskShellCommandRequestId (com.hubspot.singularity.SingularityTaskShellCommandRequestId)7 HashMap (java.util.HashMap)7 SingularityRequestDeployState (com.hubspot.singularity.SingularityRequestDeployState)6 SingularitySlaveUsage (com.hubspot.singularity.SingularitySlaveUsage)6