| 733 | |
| 734 | |
| 735 | Future<http::Response> Master::QuotaHandler::_set( |
| 736 | const QuotaRequest& quotaRequest, |
| 737 | const Option<Principal>& principal) const |
| 738 | { |
| 739 | Try<QuotaInfo> create = quota::createQuotaInfo(quotaRequest); |
| 740 | if (create.isError()) { |
| 741 | return BadRequest( |
| 742 | "Failed to create 'QuotaInfo' from set quota request: " + |
| 743 | create.error()); |
| 744 | } |
| 745 | |
| 746 | QuotaInfo quotaInfo = create.get(); |
| 747 | |
| 748 | // Check that each guarantee/resource is valid. |
| 749 | Option<Error> validate = Resources::validate(quotaInfo.guarantee()); |
| 750 | if (validate.isSome()) { |
| 751 | return BadRequest( |
| 752 | "Failed to validate set quota request:" |
| 753 | " QuotaInfo with invalid resource: " + validate->message); |
| 754 | } |
| 755 | |
| 756 | upgradeResources("aInfo); |
| 757 | |
| 758 | // Check that the `QuotaInfo` is a valid quota request. |
| 759 | { |
| 760 | Option<Error> error = quota::validation::quotaInfo(quotaInfo); |
| 761 | if (error.isSome()) { |
| 762 | return BadRequest( |
| 763 | "Failed to validate set quota request: " + error->message); |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | // Check that the role is on the role whitelist, if it exists. |
| 768 | if (!master->isWhitelistedRole(quotaInfo.role())) { |
| 769 | return BadRequest( |
| 770 | "Failed to validate set quota request: Unknown role '" + |
| 771 | quotaInfo.role() + "'"); |
| 772 | } |
| 773 | |
| 774 | // Check that we are not updating an existing quota. |
| 775 | // TODO(joerg84): Update error message once quota update is in place. |
| 776 | if (master->quotas.contains(quotaInfo.role())) { |
| 777 | return BadRequest( |
| 778 | "Failed to validate set quota request: Cannot set quota" |
| 779 | " for role '" + quotaInfo.role() + "' which already has quota"); |
| 780 | } |
| 781 | |
| 782 | // Validate that adding this quota does not violate the hierarchical |
| 783 | // relationship between quotas. |
| 784 | { |
| 785 | // TODO(mzhu): Keep an update-to-date `QuotaTree` in the memory |
| 786 | // to avoid construction from scratch every time. |
| 787 | QuotaTree quotaTree({}); |
| 788 | |
| 789 | foreachpair (const string& role, const Quota& quota, master->quotas) { |
| 790 | quotaTree.update(role, quota); |
| 791 | } |
| 792 |
nothing calls this directly
no test coverage detected