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