Use this helper to create a status update from scratch, i.e., without previously attached extra information like `data` or `check_status`.
| 1438 | // Use this helper to create a status update from scratch, i.e., without |
| 1439 | // previously attached extra information like `data` or `check_status`. |
| 1440 | TaskStatus createTaskStatus( |
| 1441 | const TaskID& taskId, |
| 1442 | const TaskState& state, |
| 1443 | const Option<TaskStatus::Reason>& reason = None(), |
| 1444 | const Option<string>& message = None(), |
| 1445 | const Option<TaskResourceLimitation>& limitation = None()) |
| 1446 | { |
| 1447 | TaskStatus status = protobuf::createTaskStatus( |
| 1448 | taskId, |
| 1449 | state, |
| 1450 | id::UUID::random(), |
| 1451 | Clock::now().secs()); |
| 1452 | |
| 1453 | status.mutable_executor_id()->CopyFrom(executorId); |
| 1454 | status.set_source(TaskStatus::SOURCE_EXECUTOR); |
| 1455 | |
| 1456 | if (reason.isSome()) { |
| 1457 | status.set_reason(reason.get()); |
| 1458 | } |
| 1459 | |
| 1460 | if (message.isSome()) { |
| 1461 | status.set_message(message.get()); |
| 1462 | } |
| 1463 | |
| 1464 | if (limitation.isSome()) { |
| 1465 | status.mutable_limitation()->CopyFrom(limitation.get()); |
| 1466 | } |
| 1467 | |
| 1468 | CHECK(containers.contains(taskId)); |
| 1469 | const Container* container = containers.at(taskId).get(); |
| 1470 | |
| 1471 | // TODO(alexr): Augment health information in a way similar to |
| 1472 | // `CheckStatusInfo`. See MESOS-6417 for more details. |
| 1473 | |
| 1474 | // If a check for the task has been defined, `check_status` field in each |
| 1475 | // task status must be set to a valid `CheckStatusInfo` message even if |
| 1476 | // there is no check status available yet. |
| 1477 | if (container->taskInfo.has_check()) { |
| 1478 | CheckStatusInfo checkStatusInfo; |
| 1479 | checkStatusInfo.set_type(container->taskInfo.check().type()); |
| 1480 | switch (container->taskInfo.check().type()) { |
| 1481 | case CheckInfo::COMMAND: { |
| 1482 | checkStatusInfo.mutable_command(); |
| 1483 | break; |
| 1484 | } |
| 1485 | case CheckInfo::HTTP: { |
| 1486 | checkStatusInfo.mutable_http(); |
| 1487 | break; |
| 1488 | } |
| 1489 | case CheckInfo::TCP: { |
| 1490 | checkStatusInfo.mutable_tcp(); |
| 1491 | break; |
| 1492 | } |
| 1493 | case CheckInfo::UNKNOWN: { |
| 1494 | LOG(FATAL) << "UNKNOWN check type is invalid"; |
| 1495 | break; |
| 1496 | } |
| 1497 | } |