| 11211 | |
| 11212 | |
| 11213 | Try<Nothing> Executor::updateTaskState(const TaskStatus& status) |
| 11214 | { |
| 11215 | bool terminal = protobuf::isTerminalState(status.state()); |
| 11216 | |
| 11217 | const TaskID& taskId = status.task_id(); |
| 11218 | |
| 11219 | Task* task = nullptr; |
| 11220 | |
| 11221 | if (queuedTasks.contains(taskId)) { |
| 11222 | if (!terminal) { |
| 11223 | return Error("Cannot send non-terminal update for queued task"); |
| 11224 | } |
| 11225 | |
| 11226 | TaskInfo taskInfo = CHECK_NOTNONE(dequeueTask(taskId)); |
| 11227 | |
| 11228 | task = new Task(protobuf::createTask( |
| 11229 | taskInfo, |
| 11230 | status.state(), |
| 11231 | frameworkId)); |
| 11232 | } else if (launchedTasks.contains(taskId)) { |
| 11233 | task = launchedTasks.at(status.task_id()); |
| 11234 | |
| 11235 | if (terminal) { |
| 11236 | if (pendingStatusUpdates.contains(status.task_id())) { |
| 11237 | auto statusUpdates = pendingStatusUpdates[status.task_id()].values(); |
| 11238 | |
| 11239 | auto firstTerminal = std::find_if( |
| 11240 | statusUpdates.begin(), |
| 11241 | statusUpdates.end(), |
| 11242 | [](const TaskStatus& status) { |
| 11243 | return protobuf::isTerminalState(status.state()); |
| 11244 | }); |
| 11245 | |
| 11246 | CHECK(firstTerminal != statusUpdates.end()); |
| 11247 | |
| 11248 | if (firstTerminal->uuid() != status.uuid()) { |
| 11249 | return Error("Unexpected terminal status update after first status" |
| 11250 | " update " + stringify(firstTerminal->state())); |
| 11251 | } |
| 11252 | } |
| 11253 | |
| 11254 | launchedTasks.erase(taskId); |
| 11255 | } |
| 11256 | } else if (terminatedTasks.contains(taskId)) { |
| 11257 | return Error("Task is already terminated with state" |
| 11258 | " " + stringify(terminatedTasks.at(taskId)->state())); |
| 11259 | } else { |
| 11260 | return Error("Task is unknown"); |
| 11261 | } |
| 11262 | |
| 11263 | CHECK_NOTNULL(task); |
| 11264 | |
| 11265 | // TODO(brenden): Consider wiping the `data` and `message` fields? |
| 11266 | if (task->statuses_size() > 0 && |
| 11267 | task->statuses(task->statuses_size() - 1).state() == status.state()) { |
| 11268 | task->mutable_statuses()->RemoveLast(); |
| 11269 | } |
| 11270 |
no test coverage detected