| 3911 | |
| 3912 | |
| 3913 | void Master::accept( |
| 3914 | Framework* framework, |
| 3915 | scheduler::Call::Accept&& accept) |
| 3916 | { |
| 3917 | CHECK_NOTNULL(framework); |
| 3918 | |
| 3919 | // Bump metrics. |
| 3920 | foreach (const Offer::Operation& operation, accept.operations()) { |
| 3921 | if (operation.type() == Offer::Operation::LAUNCH) { |
| 3922 | if (operation.launch().task_infos().size() > 0) { |
| 3923 | ++metrics->messages_launch_tasks; |
| 3924 | } else { |
| 3925 | ++metrics->messages_decline_offers; |
| 3926 | LOG(WARNING) << "Implicitly declining offers: " << accept.offer_ids() |
| 3927 | << " in ACCEPT call for framework " << framework->id() |
| 3928 | << " as the launch operation specified no tasks"; |
| 3929 | } |
| 3930 | } |
| 3931 | |
| 3932 | // TODO(mpark): Add metrics for LAUNCH_GROUP operation. |
| 3933 | // TODO(jieyu): Add metrics for non launch operations. |
| 3934 | } |
| 3935 | |
| 3936 | Option<Error> error = None(); |
| 3937 | |
| 3938 | if (accept.offer_ids().size() == 0) { |
| 3939 | error = Error("No offers specified"); |
| 3940 | } else { |
| 3941 | // Validate the offers. |
| 3942 | error = validation::offer::validate(accept.offer_ids(), this, framework); |
| 3943 | } |
| 3944 | |
| 3945 | if (error.isSome()) { |
| 3946 | // TODO(jieyu): Consider adding a 'drop' overload for ACCEPT call to |
| 3947 | // consistently handle message dropping. It would be ideal if the |
| 3948 | // 'drop' overload can handle both resource recovery and lost task |
| 3949 | // notifications. |
| 3950 | |
| 3951 | // Discard existing offers. |
| 3952 | foreach (const OfferID& offerId, accept.offer_ids()) { |
| 3953 | Offer* offer = getOffer(offerId); |
| 3954 | if (offer != nullptr) { |
| 3955 | discardOffer(offer); |
| 3956 | } else { |
| 3957 | // If the offer was not in our offer set, then this offer is no |
| 3958 | // longer valid. |
| 3959 | LOG(WARNING) << "Ignoring accept of offer " << offerId |
| 3960 | << " since it is no longer valid"; |
| 3961 | } |
| 3962 | } |
| 3963 | |
| 3964 | LOG(WARNING) << "ACCEPT call used invalid offers '" << accept.offer_ids() |
| 3965 | << "': " << error->message; |
| 3966 | |
| 3967 | const TaskState newTaskState = |
| 3968 | framework->capabilities.partitionAware ? TASK_DROPPED : TASK_LOST; |
| 3969 | |
| 3970 | foreach (const Offer::Operation& operation, accept.operations()) { |