This "fetcher program" is invoked by the slave's fetcher actor (Fetcher, FetcherProcess) to "fetch" URIs into the sandbox directory of a given task. Its parameters are provided in the form of the env var MESOS_FETCHER_INFO which contains a FetcherInfo (see fetcher.proto) object formatted in JSON. These are set by the actor to indicate what set of URIs to process and how to proceed with each one. A
| 531 | // have multiple instances of this fetcher program running at any |
| 532 | // given time. Exit code: 0 if entirely successful, otherwise 1. |
| 533 | int main(int argc, char* argv[]) |
| 534 | { |
| 535 | GOOGLE_PROTOBUF_VERIFY_VERSION; |
| 536 | |
| 537 | mesos::internal::logging::Flags flags; |
| 538 | |
| 539 | Try<flags::Warnings> load = flags.load("MESOS_", argc, argv); |
| 540 | |
| 541 | if (flags.help) { |
| 542 | std::cout << flags.usage() << std::endl; |
| 543 | return EXIT_SUCCESS; |
| 544 | } |
| 545 | |
| 546 | if (load.isError()) { |
| 547 | std::cerr << flags.usage(load.error()) << std::endl; |
| 548 | return EXIT_FAILURE; |
| 549 | } |
| 550 | |
| 551 | logging::initialize(argv[0], true, flags); // Catch signals. |
| 552 | |
| 553 | // Log any flag warnings (after logging is initialized). |
| 554 | foreach (const flags::Warning& warning, load->warnings) { |
| 555 | LOG(WARNING) << warning.message; |
| 556 | } |
| 557 | |
| 558 | const Option<string> jsonFetcherInfo = os::getenv("MESOS_FETCHER_INFO"); |
| 559 | CHECK_SOME(jsonFetcherInfo) |
| 560 | << "Missing MESOS_FETCHER_INFO environment variable"; |
| 561 | |
| 562 | LOG(INFO) << "Fetcher Info: " << jsonFetcherInfo.get(); |
| 563 | |
| 564 | Try<JSON::Object> parse = JSON::parse<JSON::Object>(jsonFetcherInfo.get()); |
| 565 | CHECK_SOME(parse) << "Failed to parse MESOS_FETCHER_INFO: " << parse.error(); |
| 566 | |
| 567 | Try<FetcherInfo> fetcherInfo = ::protobuf::parse<FetcherInfo>(parse.get()); |
| 568 | CHECK_SOME(fetcherInfo) |
| 569 | << "Failed to parse FetcherInfo: " << fetcherInfo.error(); |
| 570 | |
| 571 | CHECK(!fetcherInfo->sandbox_directory().empty()) |
| 572 | << "Missing sandbox directory"; |
| 573 | |
| 574 | const string sandboxDirectory = fetcherInfo->sandbox_directory(); |
| 575 | |
| 576 | Try<Nothing> result = createCacheDirectory(fetcherInfo.get()); |
| 577 | if (result.isError()) { |
| 578 | EXIT(EXIT_FAILURE) |
| 579 | << "Could not create the fetcher cache directory: " << result.error(); |
| 580 | } |
| 581 | |
| 582 | // If the `FetcherInfo` specifies a user, use `os::su()` to fetch files as the |
| 583 | // task's user to ensure that filesystem permissions are enforced. |
| 584 | if (fetcherInfo->has_user()) { |
| 585 | // TODO(coffler): No support for os::su on Windows, see MESOS-8063 |
| 586 | #ifndef __WINDOWS__ |
| 587 | result = os::su(fetcherInfo->user()); |
| 588 | if (result.isError()) { |
| 589 | EXIT(EXIT_FAILURE) << "Fetcher could not execute `os::su()` for user '" |
| 590 | << fetcherInfo->user() << "'"; |
nothing calls this directly
no test coverage detected