| 691 | |
| 692 | |
| 693 | pair<Response, Option<Master::ReadOnlyHandler::PostProcessing>> |
| 694 | Master::ReadOnlyHandler::roles( |
| 695 | ContentType outputContentType, |
| 696 | const hashmap<std::string, std::string>& query, |
| 697 | const process::Owned<ObjectApprovers>& approvers) const |
| 698 | { |
| 699 | CHECK_EQ(outputContentType, ContentType::JSON); |
| 700 | |
| 701 | const Master* master = this->master; |
| 702 | |
| 703 | const vector<string> knownRoles = master->knownRoles(); |
| 704 | |
| 705 | auto roles = [&](JSON::ObjectWriter* writer) { |
| 706 | writer->field( |
| 707 | "roles", |
| 708 | [&](JSON::ArrayWriter* writer) { |
| 709 | foreach (const string& name, knownRoles) { |
| 710 | if (!approvers->approved<VIEW_ROLE>(name)) { |
| 711 | continue; |
| 712 | } |
| 713 | |
| 714 | writer->element([&](JSON::ObjectWriter* writer) { |
| 715 | writer->field("name", name); |
| 716 | |
| 717 | writer->field( |
| 718 | "weight", |
| 719 | master->weights.get(name).getOrElse(DEFAULT_WEIGHT)); |
| 720 | |
| 721 | Option<Role*> role = master->roles.get(name); |
| 722 | |
| 723 | RoleResourceBreakdown resourceBreakdown(master, name); |
| 724 | |
| 725 | // Prior to Mesos 1.9, this field is filled based on |
| 726 | // `QuotaInfo` which is now deprecated. For backward |
| 727 | // compatibility reasons, we do not use any formatter |
| 728 | // for the new struct but construct the response by hand. |
| 729 | // Specifically: |
| 730 | // |
| 731 | // - We keep the `role` field which was present in the |
| 732 | // `QuotaInfo`. |
| 733 | // |
| 734 | // - We name the field using singular `guarantee` and `limit` |
| 735 | // which is different from the plural used in `QuotaConfig`. |
| 736 | const Quota quota = master->quotas.get(name).getOrElse(Quota()); |
| 737 | |
| 738 | writer->field("quota", [&](JSON::ObjectWriter* writer) { |
| 739 | writer->field("role", name); |
| 740 | |
| 741 | writer->field("guarantee", quota.guarantees); |
| 742 | writer->field("limit", quota.limits); |
| 743 | writer->field("consumed", resourceBreakdown.consumedQuota()); |
| 744 | }); |
| 745 | |
| 746 | ResourceQuantities allocated = resourceBreakdown.allocated(); |
| 747 | ResourceQuantities offered = resourceBreakdown.offered(); |
| 748 | |
| 749 | // Deprecated by allocated, offered, reserved. |
| 750 | writer->field("resources", allocated + offered); |
no test coverage detected