| 567 | } |
| 568 | |
| 569 | void launch(const TaskInfo& task) |
| 570 | { |
| 571 | CHECK_EQ(SUBSCRIBED, state); |
| 572 | |
| 573 | if (launched) { |
| 574 | TaskStatus status = createTaskStatus( |
| 575 | task.task_id(), |
| 576 | TASK_FAILED, |
| 577 | None(), |
| 578 | "Attempted to run multiple tasks using a \"command\" executor"); |
| 579 | |
| 580 | forward(status); |
| 581 | return; |
| 582 | } |
| 583 | |
| 584 | // Capture `TaskInfo` and `TaskID` of the task. |
| 585 | CHECK(taskData.isNone()); |
| 586 | taskData = TaskData(task); |
| 587 | taskId = task.task_id(); |
| 588 | |
| 589 | // Send initial TASK_STARTING update. |
| 590 | TaskStatus starting = createTaskStatus(taskId.get(), TASK_STARTING); |
| 591 | forward(starting); |
| 592 | |
| 593 | // Capture the kill policy. |
| 594 | if (task.has_kill_policy()) { |
| 595 | killPolicy = task.kill_policy(); |
| 596 | } |
| 597 | |
| 598 | // Determine the command to launch the task. |
| 599 | CommandInfo command; |
| 600 | |
| 601 | if (taskCommand.isSome()) { |
| 602 | // Get CommandInfo from a JSON string. |
| 603 | Try<JSON::Object> object = JSON::parse<JSON::Object>(taskCommand.get()); |
| 604 | if (object.isError()) { |
| 605 | ABORT("Failed to parse JSON: " + object.error()); |
| 606 | } |
| 607 | |
| 608 | Try<CommandInfo> parse = ::protobuf::parse<CommandInfo>(object.get()); |
| 609 | if (parse.isError()) { |
| 610 | ABORT("Failed to parse protobuf: " + parse.error()); |
| 611 | } |
| 612 | |
| 613 | command = parse.get(); |
| 614 | } else if (task.has_command()) { |
| 615 | command = task.command(); |
| 616 | } else { |
| 617 | LOG(FATAL) << "Expecting task '" << taskId.get() << "' to have a command"; |
| 618 | } |
| 619 | |
| 620 | // TODO(jieyu): For now, we just fail the executor if the task's |
| 621 | // CommandInfo is not valid. The framework will receive |
| 622 | // TASK_FAILED for the task, and will most likely find out the |
| 623 | // cause with some debugging. This is a temporary solution. A more |
| 624 | // correct solution is to perform this validation at master side. |
| 625 | if (command.shell()) { |
| 626 | CHECK(command.has_value()) |
no test coverage detected