MCPcopy Create free account
hub / github.com/apache/mesos / _set

Method _set

src/master/quota_handler.cpp:735–826  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

733
734
735Future<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(&quotaInfo);
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

Callers

nothing calls this directly

Calls 15

createQuotaInfoFunction · 0.85
BadRequestClass · 0.85
upgradeResourcesFunction · 0.85
quotaInfoFunction · 0.85
deferFunction · 0.85
ForbiddenClass · 0.85
isWhitelistedRoleMethod · 0.80
validateFunction · 0.70
errorMethod · 0.65
containsFunction · 0.50
isErrorMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected