Search in sources :

Example 56 with SingularityTask

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

the class SingularityDeployChecker method enqueueAndProcessLbRequest.

private SingularityDeployResult enqueueAndProcessLbRequest(SingularityRequest request, Optional<SingularityDeploy> deploy, SingularityPendingDeploy pendingDeploy, Optional<SingularityUpdatePendingDeployRequest> updatePendingDeployRequest, Collection<SingularityTaskId> deployActiveTasks, Collection<SingularityTaskId> otherActiveTasks) {
    Collection<SingularityTaskId> toShutDown = tasksToShutDown(pendingDeploy.getDeployProgress().get(), otherActiveTasks, request);
    final Map<SingularityTaskId, SingularityTask> tasks = taskManager.getTasks(Iterables.concat(deployActiveTasks, toShutDown));
    final LoadBalancerRequestId lbRequestId = getLoadBalancerRequestId(pendingDeploy);
    List<SingularityTaskId> toRemoveFromLb = new ArrayList<>();
    for (SingularityTaskId taskId : toShutDown) {
        Optional<SingularityLoadBalancerUpdate> maybeAddUpdate = taskManager.getLoadBalancerState(taskId, LoadBalancerRequestType.ADD);
        if (maybeAddUpdate.isPresent() && maybeAddUpdate.get().getLoadBalancerState() == BaragonRequestState.SUCCESS) {
            toRemoveFromLb.add(taskId);
        }
    }
    updateLoadBalancerStateForTasks(deployActiveTasks, LoadBalancerRequestType.ADD, SingularityLoadBalancerUpdate.preEnqueue(lbRequestId));
    updateLoadBalancerStateForTasks(toRemoveFromLb, LoadBalancerRequestType.REMOVE, SingularityLoadBalancerUpdate.preEnqueue(lbRequestId));
    SingularityLoadBalancerUpdate enqueueResult = lbClient.enqueue(lbRequestId, request, deploy.get(), getTasks(deployActiveTasks, tasks), getTasks(toShutDown, tasks));
    return processLbState(request, deploy, pendingDeploy, updatePendingDeployRequest, deployActiveTasks, otherActiveTasks, toShutDown, enqueueResult);
}
Also used : SingularityLoadBalancerUpdate(com.hubspot.singularity.SingularityLoadBalancerUpdate) SingularityTask(com.hubspot.singularity.SingularityTask) LoadBalancerRequestId(com.hubspot.singularity.LoadBalancerRequestType.LoadBalancerRequestId) ArrayList(java.util.ArrayList) SingularityTaskId(com.hubspot.singularity.SingularityTaskId)

Example 57 with SingularityTask

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

the class SingularityTaskShellCommandDispatchPoller method runActionOnPoll.

@Override
public void runActionOnPoll() {
    final long start = System.currentTimeMillis();
    final List<SingularityTaskShellCommandRequest> shellRequests = taskManager.getAllQueuedTaskShellCommandRequests();
    if (!schedulerClient.isRunning()) {
        LOG.warn("Unable to process shell requests because scheduler driver isn't present ({} tasks waiting)", shellRequests.size());
        return;
    }
    if (shellRequests.isEmpty()) {
        LOG.trace("No shell requests to send.");
        return;
    }
    for (SingularityTaskShellCommandRequest shellRequest : shellRequests) {
        Optional<SingularityTask> task = taskManager.getTask(shellRequest.getTaskId());
        if (!task.isPresent() || !taskManager.isActiveTask(shellRequest.getTaskId().getId())) {
            LOG.info("Skipping shell request {} because {} didn't exist or isn't active", shellRequest, shellRequest.getTaskId());
            continue;
        }
        final ExecutorID executorId = MesosProtosUtils.toExecutorId(task.get().getMesosTask().getExecutor().getExecutorId());
        final AgentID slaveId = MesosProtosUtils.toAgentId(task.get().getMesosTask().getAgentId());
        final byte[] bytes = transcoder.toBytes(shellRequest);
        schedulerClient.frameworkMessage(executorId, slaveId, bytes);
        LOG.info("Sent {} ({} bytes) to {} on {}", shellRequest, bytes.length, executorId, slaveId);
        taskManager.saveTaskShellCommandRequestToTask(shellRequest);
        taskManager.deleteTaskShellCommandRequestFromQueue(shellRequest);
    }
    LOG.info("Sent {} shell requests to executors in {}", shellRequests.size(), JavaUtils.duration(start));
}
Also used : ExecutorID(org.apache.mesos.v1.Protos.ExecutorID) SingularityTask(com.hubspot.singularity.SingularityTask) SingularityTaskShellCommandRequest(com.hubspot.singularity.SingularityTaskShellCommandRequest) AgentID(org.apache.mesos.v1.Protos.AgentID)

Example 58 with SingularityTask

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

the class SingularitySchedulerTest method testLbCleanupDoesNotRemoveBeforeAdd.

@Test
public void testLbCleanupDoesNotRemoveBeforeAdd() {
    initLoadBalancedRequest();
    initFirstDeploy();
    SingularityTask taskOne = launchTask(request, firstDeploy, 1, TaskState.TASK_RUNNING);
    initSecondDeploy();
    SingularityTask taskTwo = launchTask(request, secondDeploy, 1, TaskState.TASK_RUNNING);
    testingLbClient.setNextBaragonRequestState(BaragonRequestState.WAITING);
    deployChecker.checkDeploys();
    // First task from old deploy is still starting, never got added to LB so it should not have a removal request
    Assert.assertFalse(taskManager.getLoadBalancerState(taskOne.getTaskId(), LoadBalancerRequestType.ADD).isPresent());
    Assert.assertFalse(taskManager.getLoadBalancerState(taskOne.getTaskId(), LoadBalancerRequestType.REMOVE).isPresent());
    // Second task should have an add request
    Assert.assertTrue(taskManager.getLoadBalancerState(taskTwo.getTaskId(), LoadBalancerRequestType.ADD).isPresent());
    testingLbClient.setNextBaragonRequestState(BaragonRequestState.SUCCESS);
    deployChecker.checkDeploys();
    // First task from old deploy should still have no LB updates, but should have a cleanup
    Assert.assertFalse(taskManager.getLoadBalancerState(taskOne.getTaskId(), LoadBalancerRequestType.ADD).isPresent());
    Assert.assertFalse(taskManager.getLoadBalancerState(taskOne.getTaskId(), LoadBalancerRequestType.REMOVE).isPresent());
    Assert.assertTrue(taskManager.getCleanupTaskIds().contains(taskOne.getTaskId()));
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) Test(org.junit.Test)

Example 59 with SingularityTask

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

the class SingularitySchedulerTest method testCooldownScalesToInstances.

@Test
public void testCooldownScalesToInstances() {
    initRequest();
    initFirstDeploy();
    configuration.setCooldownAfterFailures(2);
    configuration.setCooldownAfterPctOfInstancesFail(.51);
    requestManager.activate(request.toBuilder().setInstances(Optional.of(4)).build(), RequestHistoryType.CREATED, System.currentTimeMillis(), Optional.<String>absent(), Optional.<String>absent());
    SingularityTask task1 = startTask(firstDeploy, 1);
    SingularityTask task2 = startTask(firstDeploy, 2);
    SingularityTask task3 = startTask(firstDeploy, 3);
    SingularityTask task4 = startTask(firstDeploy, 4);
    statusUpdate(task1, TaskState.TASK_FAILED);
    statusUpdate(task2, TaskState.TASK_FAILED);
    statusUpdate(task3, TaskState.TASK_FAILED);
    Assert.assertTrue(requestManager.getRequest(requestId).get().getState() == RequestState.ACTIVE);
    task1 = startTask(firstDeploy, 1);
    task2 = startTask(firstDeploy, 2);
    task3 = startTask(firstDeploy, 3);
    statusUpdate(task1, TaskState.TASK_FAILED);
    statusUpdate(task2, TaskState.TASK_FAILED);
    Assert.assertTrue(requestManager.getRequest(requestId).get().getState() == RequestState.ACTIVE);
    statusUpdate(task3, TaskState.TASK_FAILED);
    Assert.assertTrue(requestManager.getRequest(requestId).get().getState() == RequestState.SYSTEM_COOLDOWN);
    statusUpdate(task4, TaskState.TASK_FINISHED);
    Assert.assertTrue(requestManager.getRequest(requestId).get().getState() == RequestState.ACTIVE);
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) Test(org.junit.Test)

Example 60 with SingularityTask

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

the class SingularitySchedulerTest method testRunNowScheduledJobDoesNotRetry.

@Test
public void testRunNowScheduledJobDoesNotRetry() {
    initScheduledRequest();
    SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
    SingularityRequest newRequest = request.toBuilder().setNumRetriesOnFailure(Optional.of(2)).build();
    requestResource.postRequest(newRequest, singularityUser);
    initFirstDeploy();
    requestResource.scheduleImmediately(singularityUser, requestId, new SingularityRunNowRequestBuilder().build());
    resourceOffers();
    SingularityTask task = taskManager.getActiveTasks().get(0);
    statusUpdate(task, TaskState.TASK_FAILED);
    scheduler.drainPendingQueue();
    SingularityDeployStatistics deployStatistics = deployManager.getDeployStatistics(task.getTaskId().getRequestId(), task.getTaskId().getDeployId()).get();
    Assert.assertEquals(MesosTaskState.TASK_FAILED, deployStatistics.getLastTaskState().get().toTaskState().get());
    Assert.assertEquals(PendingType.TASK_DONE, taskManager.getPendingTaskIds().get(0).getPendingType());
    Assert.assertEquals(1, deployStatistics.getNumFailures());
    Assert.assertEquals(0, deployStatistics.getNumSequentialRetries());
    Assert.assertEquals(Optional.<Long>absent(), deployStatistics.getAverageRuntimeMillis());
}
Also used : SingularityRunNowRequestBuilder(com.hubspot.singularity.SingularityRunNowRequestBuilder) SingularityTask(com.hubspot.singularity.SingularityTask) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityDeployStatistics(com.hubspot.singularity.SingularityDeployStatistics) 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