Search in sources :

Example 1 with MesosTaskStatusObject

use of com.hubspot.mesos.protos.MesosTaskStatusObject in project Singularity by HubSpot.

the class LastTaskStatusMigration method applyMigration.

@Override
public void applyMigration() {
    final long start = System.currentTimeMillis();
    final List<SingularityTaskId> taskIds = taskManager.getActiveTaskIds();
    for (SingularityTaskId taskId : taskIds) {
        List<SingularityTaskHistoryUpdate> updates = Lists.reverse(taskManager.getTaskHistoryUpdates(taskId));
        Optional<MesosTaskStatusObject> taskStatus = Optional.absent();
        for (SingularityTaskHistoryUpdate update : updates) {
            if (update.getTaskState().toTaskState().isPresent()) {
                Optional<SingularityTask> task = taskManager.getTask(taskId);
                taskStatus = Optional.of(mesosProtosUtils.taskStatusFromProtos(TaskStatus.newBuilder().setTaskId(TaskID.newBuilder().setValue(taskId.getId())).setAgentId(MesosProtosUtils.toAgentId(task.get().getAgentId())).setState(MesosProtosUtils.toTaskState(update.getTaskState())).build()));
                break;
            }
        }
        SingularityTaskStatusHolder taskStatusHolder = new SingularityTaskStatusHolder(taskId, taskStatus, start, serverId, Optional.absent());
        taskManager.saveLastActiveTaskStatus(taskStatusHolder);
    }
}
Also used : MesosTaskStatusObject(com.hubspot.mesos.protos.MesosTaskStatusObject) SingularityTask(com.hubspot.singularity.SingularityTask) SingularityTaskHistoryUpdate(com.hubspot.singularity.SingularityTaskHistoryUpdate) SingularityTaskStatusHolder(com.hubspot.singularity.SingularityTaskStatusHolder) SingularityTaskId(com.hubspot.singularity.SingularityTaskId)

Example 2 with MesosTaskStatusObject

use of com.hubspot.mesos.protos.MesosTaskStatusObject in project Singularity by HubSpot.

the class SingularityTaskReconciliation method checkReconciliation.

private void checkReconciliation(final long reconciliationStart, final Collection<SingularityTaskId> remainingTaskIds, final int numTimes, final Histogram histogram) {
    final List<SingularityTaskStatusHolder> taskStatusHolders = taskManager.getLastActiveTaskStatusesFor(remainingTaskIds);
    final List<MesosTaskStatusObject> taskStatuses = Lists.newArrayListWithCapacity(taskStatusHolders.size());
    for (SingularityTaskStatusHolder taskStatusHolder : taskStatusHolders) {
        if (taskStatusHolder.getServerId().equals(serverId) && taskStatusHolder.getServerTimestamp() > reconciliationStart) {
            histogram.update(taskStatusHolder.getServerTimestamp() - reconciliationStart);
            continue;
        }
        if (taskStatusHolder.getTaskStatus().isPresent()) {
            LOG.debug("Re-requesting task status for {}", taskStatusHolder.getTaskId());
            taskStatuses.add(taskStatusHolder.getTaskStatus().get());
        } else {
            TaskStatus.Builder fakeTaskStatusBuilder = TaskStatus.newBuilder().setTaskId(TaskID.newBuilder().setValue(taskStatusHolder.getTaskId().getId())).setState(TaskState.TASK_STARTING);
            if (taskStatusHolder.getSlaveId().isPresent()) {
                fakeTaskStatusBuilder.setAgentId(AgentID.newBuilder().setValue(taskStatusHolder.getSlaveId().get()));
            }
            LOG.info("Task {} didn't have a TaskStatus yet, submitting fake status", taskStatusHolder.getTaskId());
            taskStatuses.add(mesosProtosUtils.taskStatusFromProtos(fakeTaskStatusBuilder.build()));
        }
    }
    if (taskStatuses.isEmpty()) {
        LOG.info("Task reconciliation ended after {} checks and {}", numTimes, JavaUtils.duration(reconciliationStart));
        final Snapshot snapshot = histogram.getSnapshot();
        stateManager.saveTaskReconciliationStatistics(new SingularityTaskReconciliationStatistics(reconciliationStart, System.currentTimeMillis() - reconciliationStart, numTimes, histogram.getCount(), snapshot.getMax(), snapshot.getMean(), snapshot.getMin(), snapshot.getMedian(), snapshot.get75thPercentile(), snapshot.get95thPercentile(), snapshot.get98thPercentile(), snapshot.get99thPercentile(), snapshot.get999thPercentile(), snapshot.getStdDev()));
        isRunningReconciliation.set(false);
        return;
    }
    LOG.info("Requesting reconciliation of {} taskStatuses, task reconciliation has been running for {}", taskStatuses.size(), JavaUtils.duration(reconciliationStart));
    schedulerClient.reconcile(taskStatuses.stream().map((t) -> Task.newBuilder().setTaskId(MesosProtosUtils.toTaskId(t.getTaskId())).setAgentId(MesosProtosUtils.toAgentId(t.getAgentId())).build()).collect(Collectors.toList()));
    scheduleReconciliationCheck(reconciliationStart, remainingTaskIds, numTimes, histogram);
}
Also used : MesosTaskStatusObject(com.hubspot.mesos.protos.MesosTaskStatusObject) Snapshot(com.codahale.metrics.Snapshot) SingularityTaskStatusHolder(com.hubspot.singularity.SingularityTaskStatusHolder) TaskStatus(org.apache.mesos.v1.Protos.TaskStatus) SingularityTaskReconciliationStatistics(com.hubspot.singularity.SingularityTaskReconciliationStatistics)

Aggregations

MesosTaskStatusObject (com.hubspot.mesos.protos.MesosTaskStatusObject)2 SingularityTaskStatusHolder (com.hubspot.singularity.SingularityTaskStatusHolder)2 Snapshot (com.codahale.metrics.Snapshot)1 SingularityTask (com.hubspot.singularity.SingularityTask)1 SingularityTaskHistoryUpdate (com.hubspot.singularity.SingularityTaskHistoryUpdate)1 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)1 SingularityTaskReconciliationStatistics (com.hubspot.singularity.SingularityTaskReconciliationStatistics)1 TaskStatus (org.apache.mesos.v1.Protos.TaskStatus)1