Return-Path: X-Original-To: apmail-aurora-commits-archive@minotaur.apache.org Delivered-To: apmail-aurora-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6B51717F7B for ; Tue, 6 Jan 2015 23:26:48 +0000 (UTC) Received: (qmail 36866 invoked by uid 500); 6 Jan 2015 23:26:49 -0000 Delivered-To: apmail-aurora-commits-archive@aurora.apache.org Received: (qmail 36839 invoked by uid 500); 6 Jan 2015 23:26:49 -0000 Mailing-List: contact commits-help@aurora.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@aurora.incubator.apache.org Delivered-To: mailing list commits@aurora.incubator.apache.org Received: (qmail 36830 invoked by uid 99); 6 Jan 2015 23:26:49 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 06 Jan 2015 23:26:49 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Tue, 06 Jan 2015 23:26:48 +0000 Received: (qmail 35222 invoked by uid 99); 6 Jan 2015 23:26:28 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 06 Jan 2015 23:26:28 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 69F3A9D1F7E; Tue, 6 Jan 2015 23:26:27 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: maxim@apache.org To: commits@aurora.incubator.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: incubator-aurora git commit: Improving quota check message in the client. Date: Tue, 6 Jan 2015 23:26:27 +0000 (UTC) X-Virus-Checked: Checked by ClamAV on apache.org Repository: incubator-aurora Updated Branches: refs/heads/master 9f6ec4bd9 -> 8c49029b6 Improving quota check message in the client. Bugs closed: AURORA-469 Reviewed at https://reviews.apache.org/r/28872/ Project: http://git-wip-us.apache.org/repos/asf/incubator-aurora/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-aurora/commit/8c49029b Tree: http://git-wip-us.apache.org/repos/asf/incubator-aurora/tree/8c49029b Diff: http://git-wip-us.apache.org/repos/asf/incubator-aurora/diff/8c49029b Branch: refs/heads/master Commit: 8c49029b640211f7cccf79d79e2b5ca52ac37e2f Parents: 9f6ec4b Author: Maxim Khutornenko Authored: Tue Jan 6 15:26:07 2015 -0800 Committer: -l Committed: Tue Jan 6 15:26:07 2015 -0800 ---------------------------------------------------------------------- .../apache/aurora/client/api/quota_check.py | 13 ++++++++++++ .../aurora/client/api/test_quota_check.py | 21 ++++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/8c49029b/src/main/python/apache/aurora/client/api/quota_check.py ---------------------------------------------------------------------- diff --git a/src/main/python/apache/aurora/client/api/quota_check.py b/src/main/python/apache/aurora/client/api/quota_check.py index c994050..75406ac 100644 --- a/src/main/python/apache/aurora/client/api/quota_check.py +++ b/src/main/python/apache/aurora/client/api/quota_check.py @@ -12,6 +12,7 @@ # limitations under the License. # +import math import operator from copy import deepcopy @@ -56,6 +57,16 @@ class CapacityRequest(object): def valid(self): return self._quota.numCpus >= 0.0 and self._quota.ramMb >= 0 and self._quota.diskMb >= 0 + def invert_or_reset(self): + """Inverts negative resource and resets positive resource as zero.""" + def invert_or_reset(val): + return math.fabs(val) if val < 0 else 0 + + return CapacityRequest(ResourceAggregate( + numCpus=invert_or_reset(self._quota.numCpus), + ramMb=invert_or_reset(self._quota.ramMb), + diskMb=invert_or_reset(self._quota.diskMb))) + def quota(self): return deepcopy(self._quota) @@ -99,6 +110,8 @@ class QuotaCheck(object): print_quota(allocated.quota(), 'Total allocated quota', job_key.role) print_quota(consumed.quota(), 'Consumed quota', job_key.role) print_quota(requested.quota(), 'Requested', job_key.name) + print_quota(effective.invert_or_reset().quota(), 'Additional quota required', job_key.role) + # TODO(wfarner): Avoid synthesizing scheduler responses. return Response( responseCode=ResponseCode.INVALID_REQUEST, http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/8c49029b/src/test/python/apache/aurora/client/api/test_quota_check.py ---------------------------------------------------------------------- diff --git a/src/test/python/apache/aurora/client/api/test_quota_check.py b/src/test/python/apache/aurora/client/api/test_quota_check.py index 2fc76d2..2c9bef1 100644 --- a/src/test/python/apache/aurora/client/api/test_quota_check.py +++ b/src/test/python/apache/aurora/client/api/test_quota_check.py @@ -15,9 +15,9 @@ import unittest from copy import deepcopy -from mock import create_autospec +from mock import call, create_autospec, patch -from apache.aurora.client.api.quota_check import CapacityRequest, QuotaCheck +from apache.aurora.client.api.quota_check import CapacityRequest, print_quota, QuotaCheck from .api_util import SchedulerThriftApiSpec @@ -110,3 +110,20 @@ class QuotaCheckTest(unittest.TestCase): self.mock_get_quota(allocated, consumed, response_code=ResponseCode.INVALID_REQUEST) self.assert_result(True, released, acquired, ResponseCode.INVALID_REQUEST) + + @patch('apache.aurora.client.api.quota_check.print_quota', spec=print_quota) + def test_additional_quota_out(self, mock_print_quota): + allocated = ResourceAggregate(numCpus=50.0, ramMb=1000, diskMb=3000) + consumed = ResourceAggregate(numCpus=45.0, ramMb=900, diskMb=2900) + released = CapacityRequest(ResourceAggregate(numCpus=5.0, ramMb=100, diskMb=100)) + acquired = CapacityRequest(ResourceAggregate(numCpus=11.0, ramMb=220, diskMb=200)) + additional = ResourceAggregate(numCpus=1.0, ramMb=20, diskMb=0) + + self.mock_get_quota(allocated, consumed) + self.assert_result(True, released, acquired, ResponseCode.INVALID_REQUEST) + assert mock_print_quota.mock_calls[:4] == [ + call(allocated, 'Total allocated quota', self._role), + call(consumed, 'Consumed quota', self._role), + call((acquired - released).quota(), 'Requested', self._name), + call(additional, 'Additional quota required', self._role) + ]