Search in sources :

Example 41 with SingularityTask

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

the class SingularityHealthchecksTest method testFailingStatusCodes.

@Test
public void testFailingStatusCodes() {
    initRequest();
    final String deployId = "retry_test";
    List<Integer> failureCodes = ImmutableList.of(404);
    HealthcheckOptions options = new HealthcheckOptionsBuilder("http://uri").setMaxRetries(Optional.of(3)).setFailureStatusCodes(Optional.of(failureCodes)).build();
    SingularityDeployBuilder db = new SingularityDeployBuilder(requestId, deployId).setHealthcheck(Optional.of(options));
    SingularityDeploy deploy = initDeploy(db, System.currentTimeMillis());
    deployChecker.checkDeploys();
    Assert.assertTrue(!deployManager.getDeployResult(requestId, deployId).isPresent());
    SingularityTask task = launchTask(request, deploy, System.currentTimeMillis(), 1, TaskState.TASK_RUNNING);
    deployChecker.checkDeploys();
    Assert.assertTrue(!deployManager.getDeployResult(requestId, deployId).isPresent());
    taskManager.saveHealthcheckResult(new SingularityTaskHealthcheckResult(Optional.of(503), Optional.of(1000L), System.currentTimeMillis(), Optional.<String>absent(), Optional.<String>absent(), task.getTaskId(), Optional.<Boolean>absent()));
    deployChecker.checkDeploys();
    Assert.assertTrue(!deployManager.getDeployResult(requestId, deployId).isPresent());
    taskManager.saveHealthcheckResult(new SingularityTaskHealthcheckResult(Optional.of(404), Optional.of(1000L), System.currentTimeMillis() + 1, Optional.<String>absent(), Optional.<String>absent(), task.getTaskId(), Optional.<Boolean>absent()));
    deployChecker.checkDeploys();
    // Bad status code should cause instant failure even though retries remain
    Assert.assertEquals(DeployState.FAILED, deployManager.getDeployResult(requestId, deployId).get().getDeployState());
}
Also used : SingularityTaskHealthcheckResult(com.hubspot.singularity.SingularityTaskHealthcheckResult) SingularityTask(com.hubspot.singularity.SingularityTask) HealthcheckOptions(com.hubspot.deploy.HealthcheckOptions) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) HealthcheckOptionsBuilder(com.hubspot.deploy.HealthcheckOptionsBuilder) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) Test(org.junit.Test)

Example 42 with SingularityTask

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

the class SingularityHealthchecksTest method testPortNumber.

@Test
public void testPortNumber() {
    try {
        setConfigurationForNoDelay();
        initRequest();
        HealthcheckOptions options = new HealthcheckOptionsBuilder("http://uri").setPortNumber(Optional.of(81L)).setStartupDelaySeconds(Optional.of(0)).build();
        firstDeploy = initAndFinishDeploy(request, new SingularityDeployBuilder(request.getId(), firstDeployId).setCommand(Optional.of("sleep 100")).setResources(Optional.of(new Resources(1, 64, 3, 0))).setHealthcheck(Optional.of(options)), Optional.absent());
        requestResource.postRequest(request.toBuilder().setInstances(Optional.of(2)).build(), singularityUser);
        scheduler.drainPendingQueue();
        String[] portRange = { "80:82" };
        sms.resourceOffers(Arrays.asList(createOffer(20, 20000, 50000, "slave1", "host1", Optional.<String>absent(), Collections.<String, String>emptyMap(), portRange)));
        SingularityTaskId firstTaskId = taskManager.getActiveTaskIdsForRequest(requestId).get(0);
        SingularityTask firstTask = taskManager.getTask(firstTaskId).get();
        statusUpdate(firstTask, TaskState.TASK_RUNNING);
        newTaskChecker.enqueueNewTaskCheck(firstTask, requestManager.getRequest(requestId), healthchecker);
        Awaitility.await("healthcheck present").atMost(5, TimeUnit.SECONDS).until(() -> taskManager.getLastHealthcheck(firstTask.getTaskId()).isPresent());
        Assert.assertTrue(taskManager.getLastHealthcheck(firstTask.getTaskId()).get().toString().contains("host1:81"));
    } finally {
        unsetConfigurationForNoDelay();
    }
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) HealthcheckOptions(com.hubspot.deploy.HealthcheckOptions) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) Resources(com.hubspot.mesos.Resources) HealthcheckOptionsBuilder(com.hubspot.deploy.HealthcheckOptionsBuilder) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Test(org.junit.Test)

Example 43 with SingularityTask

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

the class SingularityHealthchecksTest method testSkipHealthchecksDuringBounce.

@Test
public void testSkipHealthchecksDuringBounce() {
    try {
        initRequest();
        initHCDeploy();
        SingularityTask firstTask = startTask(firstDeploy, 1);
        requestResource.bounce(requestId, Optional.of(new SingularityBounceRequest(Optional.absent(), Optional.of(true), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent())), singularityUser);
        setConfigurationForNoDelay();
        cleaner.drainCleanupQueue();
        resourceOffers();
        List<SingularityTaskId> taskIds = taskManager.getAllTaskIds();
        taskIds.remove(firstTask.getTaskId());
        SingularityTaskId secondTaskId = taskIds.get(0);
        SingularityTask secondTask = taskManager.getTask(secondTaskId).get();
        statusUpdate(secondTask, TaskState.TASK_RUNNING);
        Assert.assertTrue(healthchecker.cancelHealthcheck(firstTask.getTaskId().getId()));
        newTaskChecker.cancelNewTaskCheck(firstTask.getTaskId().getId());
        finishHealthchecks();
        finishNewTaskChecks();
        Assert.assertTrue(!taskManager.getLastHealthcheck(secondTask.getTaskId()).isPresent());
        cleaner.drainCleanupQueue();
        killKilledTasks();
        Assert.assertEquals(0, taskManager.getNumCleanupTasks());
        Assert.assertEquals(1, taskManager.getNumActiveTasks());
    } finally {
        unsetConfigurationForNoDelay();
    }
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) SingularityBounceRequest(com.hubspot.singularity.api.SingularityBounceRequest) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Test(org.junit.Test)

Example 44 with SingularityTask

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

the class StateManagerTest method itDoesntCountCleaningTasks.

@Test
public void itDoesntCountCleaningTasks() {
    initRequest();
    initFirstDeploy();
    SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
    saveAndSchedule(request.toBuilder().setInstances(Optional.of(3)));
    resourceOffers();
    Assert.assertEquals(3, taskManager.getActiveTaskIds().size());
    Assert.assertEquals(0, stateManager.getState(true, false).getOverProvisionedRequests());
    Assert.assertEquals(0, stateManager.getState(true, false).getUnderProvisionedRequests());
    SingularityTask task = taskManager.getActiveTasks().get(0);
    statusUpdate(task, TaskState.TASK_KILLED);
    scheduler.drainPendingQueue();
    taskManager.createTaskCleanup(new SingularityTaskCleanup(Optional.absent(), TaskCleanupType.BOUNCING, 1L, task.getTaskId(), Optional.absent(), Optional.absent(), Optional.absent()));
    Assert.assertEquals(2, taskManager.getActiveTaskIds().size());
    Assert.assertEquals(0, stateManager.getState(true, false).getOverProvisionedRequests());
    Assert.assertEquals(1, stateManager.getState(true, false).getUnderProvisionedRequests());
    launchTask(request, firstDeploy, 4, TaskState.TASK_RUNNING);
    launchTask(request, firstDeploy, 5, TaskState.TASK_RUNNING);
    Assert.assertEquals(4, taskManager.getActiveTaskIds().size());
    Assert.assertEquals(0, stateManager.getState(true, false).getUnderProvisionedRequests());
    Assert.assertEquals(1, stateManager.getState(true, false).getOverProvisionedRequests());
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityTaskCleanup(com.hubspot.singularity.SingularityTaskCleanup) Test(org.junit.Test)

Example 45 with SingularityTask

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

the class SingularityMesosSchedulerImpl method killAndRecord.

public void killAndRecord(SingularityTaskId taskId, Optional<RequestCleanupType> requestCleanupType, Optional<TaskCleanupType> taskCleanupType, Optional<Long> originalTimestamp, Optional<Integer> retries, Optional<String> user) {
    Preconditions.checkState(isRunning());
    Optional<TaskCleanupType> maybeCleanupFromRequestAndTask = getTaskCleanupType(requestCleanupType, taskCleanupType);
    if (maybeCleanupFromRequestAndTask.isPresent() && (maybeCleanupFromRequestAndTask.get() == TaskCleanupType.USER_REQUESTED_DESTROY || maybeCleanupFromRequestAndTask.get() == TaskCleanupType.REQUEST_DELETING)) {
        Optional<SingularityTask> task = taskManager.getTask(taskId);
        if (task.isPresent()) {
            if (task.get().getTaskRequest().getDeploy().getCustomExecutorCmd().isPresent()) {
                byte[] messageBytes = transcoder.toBytes(new SingularityTaskDestroyFrameworkMessage(taskId, user));
                mesosSchedulerClient.frameworkMessage(MesosProtosUtils.toExecutorId(task.get().getMesosTask().getExecutor().getExecutorId()), MesosProtosUtils.toAgentId(task.get().getMesosTask().getAgentId()), messageBytes);
            } else {
                LOG.warn("Not using custom executor, will not send framework message to destroy task");
            }
        } else {
            String message = String.format("No task data available to build kill task framework message for task %s", taskId);
            exceptionNotifier.notify(message);
            LOG.error(message);
        }
    }
    mesosSchedulerClient.kill(TaskID.newBuilder().setValue(taskId.toString()).build());
    taskManager.saveKilledRecord(new SingularityKilledTaskIdRecord(taskId, System.currentTimeMillis(), originalTimestamp.or(System.currentTimeMillis()), requestCleanupType, taskCleanupType, retries.or(-1) + 1));
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) SingularityKilledTaskIdRecord(com.hubspot.singularity.SingularityKilledTaskIdRecord) TaskCleanupType(com.hubspot.singularity.TaskCleanupType) SingularityTaskDestroyFrameworkMessage(com.hubspot.singularity.SingularityTaskDestroyFrameworkMessage)

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