use of com.hubspot.singularity.SingularityTaskHistoryUpdate in project Singularity by HubSpot.
the class MesosUtilsTest method testTaskOrdering.
@Test
public void testTaskOrdering() {
final SingularityTaskId taskId = new SingularityTaskId("r", "d", System.currentTimeMillis(), 1, "h", "r");
final Optional<String> msg = Optional.absent();
SingularityTaskHistoryUpdate update1 = new SingularityTaskHistoryUpdate(taskId, 1L, ExtendedTaskState.TASK_LAUNCHED, msg, Optional.<String>absent());
SingularityTaskHistoryUpdate update2 = new SingularityTaskHistoryUpdate(taskId, 2L, ExtendedTaskState.TASK_RUNNING, msg, Optional.<String>absent());
SingularityTaskHistoryUpdate update3 = new SingularityTaskHistoryUpdate(taskId, 2L, ExtendedTaskState.TASK_FAILED, msg, Optional.<String>absent());
List<SingularityTaskHistoryUpdate> list = Arrays.asList(update2, update1, update3);
Collections.sort(list);
Assert.assertTrue(list.get(0).getTaskState() == ExtendedTaskState.TASK_LAUNCHED);
Assert.assertTrue(list.get(1).getTaskState() == ExtendedTaskState.TASK_RUNNING);
Assert.assertTrue(list.get(2).getTaskState() == ExtendedTaskState.TASK_FAILED);
}
use of com.hubspot.singularity.SingularityTaskHistoryUpdate in project Singularity by HubSpot.
the class SingularitySlavePlacementTest method testSlavePlacementSeparate.
@Test
public void testSlavePlacementSeparate() {
initRequest();
initFirstDeploy();
saveAndSchedule(request.toBuilder().setInstances(Optional.of(2)).setSlavePlacement(Optional.of(SlavePlacement.SEPARATE)));
sms.resourceOffers(Arrays.asList(createOffer(20, 20000, 50000, "slave1", "host1"), createOffer(20, 20000, 50000, "slave1", "host1")));
Assert.assertTrue(taskManager.getPendingTaskIds().size() == 1);
Assert.assertTrue(taskManager.getActiveTaskIds().size() == 1);
sms.resourceOffers(Arrays.asList(createOffer(20, 20000, 50000, "slave1", "host1")));
Assert.assertTrue(taskManager.getPendingTaskIds().size() == 1);
Assert.assertTrue(taskManager.getActiveTaskIds().size() == 1);
eventListener.taskHistoryUpdateEvent(new SingularityTaskHistoryUpdate(taskManager.getActiveTaskIds().get(0), System.currentTimeMillis(), ExtendedTaskState.TASK_CLEANING, Optional.<String>absent(), Optional.<String>absent()));
sms.resourceOffers(Arrays.asList(createOffer(20, 20000, 50000, "slave1", "host1")));
Assert.assertTrue(taskManager.getPendingTaskIds().size() == 1);
Assert.assertTrue(taskManager.getActiveTaskIds().size() == 1);
sms.resourceOffers(Arrays.asList(createOffer(20, 20000, 50000, "slave2", "host2")));
Assert.assertTrue(taskManager.getPendingTaskIds().isEmpty());
Assert.assertTrue(taskManager.getActiveTaskIds().size() == 2);
}
use of com.hubspot.singularity.SingularityTaskHistoryUpdate in project Singularity by HubSpot.
the class TaskManager method createTaskAndDeletePendingTaskPrivate.
private void createTaskAndDeletePendingTaskPrivate(SingularityTask task) throws Exception {
// TODO: Should more of the below be done within a transaction?
deletePendingTask(task.getTaskRequest().getPendingTask().getPendingTaskId());
final long now = System.currentTimeMillis();
String msg = String.format("Task launched because of %s", task.getTaskRequest().getPendingTask().getPendingTaskId().getPendingType().name());
if (task.getTaskRequest().getPendingTask().getUser().isPresent()) {
msg = String.format("%s by %s", msg, task.getTaskRequest().getPendingTask().getUser().get());
}
if (task.getTaskRequest().getPendingTask().getMessage().isPresent()) {
msg = String.format("%s (%s)", msg, task.getTaskRequest().getPendingTask().getMessage().get());
}
saveTaskHistoryUpdate(new SingularityTaskHistoryUpdate(task.getTaskId(), now, ExtendedTaskState.TASK_LAUNCHED, Optional.of(msg), Optional.<String>absent()));
saveLastActiveTaskStatus(new SingularityTaskStatusHolder(task.getTaskId(), Optional.absent(), now, serverId, Optional.of(task.getAgentId().getValue())));
try {
final String path = getTaskPath(task.getTaskId());
CuratorTransactionFinal transaction = curator.inTransaction().create().forPath(path, taskTranscoder.toBytes(task)).and();
transaction.create().forPath(getActivePath(task.getTaskId().getId())).and().commit();
leaderCache.putActiveTask(task);
taskCache.set(path, task);
} catch (KeeperException.NodeExistsException nee) {
LOG.error("Task or active path already existed for {}", task.getTaskId());
}
}
Aggregations