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);
}
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));
}
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()));
}
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);
}
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());
}
Aggregations