Search in sources :

Example 21 with SingularityTaskHistoryUpdate

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);
}
Also used : SingularityTaskHistoryUpdate(com.hubspot.singularity.SingularityTaskHistoryUpdate) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Test(org.junit.Test)

Example 22 with SingularityTaskHistoryUpdate

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);
}
Also used : SingularityTaskHistoryUpdate(com.hubspot.singularity.SingularityTaskHistoryUpdate) Test(org.junit.Test)

Example 23 with SingularityTaskHistoryUpdate

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());
    }
}
Also used : SingularityTaskHistoryUpdate(com.hubspot.singularity.SingularityTaskHistoryUpdate) CuratorTransactionFinal(org.apache.curator.framework.api.transaction.CuratorTransactionFinal) SingularityTaskStatusHolder(com.hubspot.singularity.SingularityTaskStatusHolder) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

SingularityTaskHistoryUpdate (com.hubspot.singularity.SingularityTaskHistoryUpdate)23 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)12 SingularityTask (com.hubspot.singularity.SingularityTask)7 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 SimplifiedTaskState (com.hubspot.singularity.SingularityTaskHistoryUpdate.SimplifiedTaskState)3 SingularityTaskStatusHolder (com.hubspot.singularity.SingularityTaskStatusHolder)3 SingularityBounceRequest (com.hubspot.singularity.api.SingularityBounceRequest)3 List (java.util.List)3 Timed (com.codahale.metrics.annotation.Timed)2 SingularityDeployFailure (com.hubspot.singularity.SingularityDeployFailure)2 SingularityTaskIdHistory (com.hubspot.singularity.SingularityTaskIdHistory)2 SingularityTaskMetadata (com.hubspot.singularity.SingularityTaskMetadata)2 AtomicDouble (com.google.common.util.concurrent.AtomicDouble)1 Resources (com.hubspot.mesos.Resources)1 MesosSlaveMetricsSnapshotObject (com.hubspot.mesos.json.MesosSlaveMetricsSnapshotObject)1 MesosTaskMonitorObject (com.hubspot.mesos.json.MesosTaskMonitorObject)1 MesosTaskStatusObject (com.hubspot.mesos.protos.MesosTaskStatusObject)1 ExtendedTaskState (com.hubspot.singularity.ExtendedTaskState)1 InvalidSingularityTaskIdException (com.hubspot.singularity.InvalidSingularityTaskIdException)1