Search in sources :

Example 1 with SingularityTaskDestroyFrameworkMessage

use of com.hubspot.singularity.SingularityTaskDestroyFrameworkMessage in project Singularity by HubSpot.

the class SingularityMesosSchedulerImpl method killAndRecord.

public void killAndRecord(SingularityTaskId taskId, Optional<RequestCleanupType> requestCleanupType, Optional<TaskCleanupType> taskCleanupType, Optional<Long> originalTimestamp, Optional<Integer> retries, Optional<String> user) {
    Preconditions.checkState(isRunning());
    Optional<TaskCleanupType> maybeCleanupFromRequestAndTask = getTaskCleanupType(requestCleanupType, taskCleanupType);
    if (maybeCleanupFromRequestAndTask.isPresent() && (maybeCleanupFromRequestAndTask.get() == TaskCleanupType.USER_REQUESTED_DESTROY || maybeCleanupFromRequestAndTask.get() == TaskCleanupType.REQUEST_DELETING)) {
        Optional<SingularityTask> task = taskManager.getTask(taskId);
        if (task.isPresent()) {
            if (task.get().getTaskRequest().getDeploy().getCustomExecutorCmd().isPresent()) {
                byte[] messageBytes = transcoder.toBytes(new SingularityTaskDestroyFrameworkMessage(taskId, user));
                mesosSchedulerClient.frameworkMessage(MesosProtosUtils.toExecutorId(task.get().getMesosTask().getExecutor().getExecutorId()), MesosProtosUtils.toAgentId(task.get().getMesosTask().getAgentId()), messageBytes);
            } else {
                LOG.warn("Not using custom executor, will not send framework message to destroy task");
            }
        } else {
            String message = String.format("No task data available to build kill task framework message for task %s", taskId);
            exceptionNotifier.notify(message);
            LOG.error(message);
        }
    }
    mesosSchedulerClient.kill(TaskID.newBuilder().setValue(taskId.toString()).build());
    taskManager.saveKilledRecord(new SingularityKilledTaskIdRecord(taskId, System.currentTimeMillis(), originalTimestamp.or(System.currentTimeMillis()), requestCleanupType, taskCleanupType, retries.or(-1) + 1));
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) SingularityKilledTaskIdRecord(com.hubspot.singularity.SingularityKilledTaskIdRecord) TaskCleanupType(com.hubspot.singularity.TaskCleanupType) SingularityTaskDestroyFrameworkMessage(com.hubspot.singularity.SingularityTaskDestroyFrameworkMessage)

Aggregations

SingularityKilledTaskIdRecord (com.hubspot.singularity.SingularityKilledTaskIdRecord)1 SingularityTask (com.hubspot.singularity.SingularityTask)1 SingularityTaskDestroyFrameworkMessage (com.hubspot.singularity.SingularityTaskDestroyFrameworkMessage)1 TaskCleanupType (com.hubspot.singularity.TaskCleanupType)1