| 878 | } |
| 879 | |
| 880 | void resourceOffers( |
| 881 | const UPID& from, |
| 882 | const vector<Offer>& offers, |
| 883 | const vector<string>& pids) |
| 884 | { |
| 885 | if (!running.load()) { |
| 886 | VLOG(1) << "Ignoring resource offers message because " |
| 887 | << "the driver is not running!"; |
| 888 | return; |
| 889 | } |
| 890 | |
| 891 | if (!connected) { |
| 892 | VLOG(1) << "Ignoring resource offers message because the driver is " |
| 893 | << "disconnected!"; |
| 894 | return; |
| 895 | } |
| 896 | |
| 897 | CHECK_SOME(master); |
| 898 | |
| 899 | if (from != master->pid()) { |
| 900 | VLOG(1) << "Ignoring resource offers message because it was sent " |
| 901 | << "from '" << from << "' instead of the leading master '" |
| 902 | << master->pid() << "'"; |
| 903 | return; |
| 904 | } |
| 905 | |
| 906 | // We exit early if `offers` is empty since we don't implement inverse |
| 907 | // offers in the old scheduler API. It could be empty when there are only |
| 908 | // inverse offers as part of the `ResourceOffersMessage`. |
| 909 | if (offers.empty()) { |
| 910 | return; |
| 911 | } |
| 912 | |
| 913 | VLOG(2) << "Received " << offers.size() << " offers"; |
| 914 | |
| 915 | CHECK_EQ(offers.size(), pids.size()); |
| 916 | |
| 917 | // Save the pid associated with each slave (one per offer) so |
| 918 | // later we can send framework messages directly. |
| 919 | for (size_t i = 0; i < offers.size(); i++) { |
| 920 | UPID pid(pids[i]); |
| 921 | // Check if parse failed (e.g., due to DNS). |
| 922 | if (pid != UPID()) { |
| 923 | VLOG(3) << "Saving PID '" << pids[i] << "'"; |
| 924 | savedOffers[offers[i].id()][offers[i].slave_id()] = pid; |
| 925 | } else { |
| 926 | VLOG(1) << "Failed to parse PID '" << pids[i] << "'"; |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | Stopwatch stopwatch; |
| 931 | if (FLAGS_v >= 1) { |
| 932 | stopwatch.start(); |
| 933 | } |
| 934 | |
| 935 | scheduler->resourceOffers(driver, offers); |
| 936 | |
| 937 | VLOG(1) << "Scheduler::resourceOffers took " << stopwatch.elapsed(); |