Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 768C6200CBC for ; Tue, 20 Jun 2017 11:46:42 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 753F1160BD3; Tue, 20 Jun 2017 09:46:42 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id ECE7A160C01 for ; Tue, 20 Jun 2017 11:46:40 +0200 (CEST) Received: (qmail 10259 invoked by uid 500); 20 Jun 2017 09:46:40 -0000 Mailing-List: contact commits-help@mesos.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@mesos.apache.org Delivered-To: mailing list commits@mesos.apache.org Received: (qmail 10094 invoked by uid 99); 20 Jun 2017 09:46:39 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Jun 2017 09:46:39 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 5D794E1151; Tue, 20 Jun 2017 09:46:37 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: mpark@apache.org To: commits@mesos.apache.org Date: Tue, 20 Jun 2017 09:46:41 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [05/21] mesos git commit: Resources: Adjusted the utilities to the new resource format [5/20]. archived-at: Tue, 20 Jun 2017 09:46:42 -0000 Resources: Adjusted the utilities to the new resource format [5/20]. Review: https://reviews.apache.org/r/60017 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/0bae2670 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/0bae2670 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/0bae2670 Branch: refs/heads/master Commit: 0bae26707645f515317b3860b22df822dd85e718 Parents: 9ac264b Author: Michael Park Authored: Sun Jun 18 22:04:29 2017 -0700 Committer: Michael Park Committed: Tue Jun 20 02:30:25 2017 -0700 ---------------------------------------------------------------------- src/common/resources.cpp | 25 ++++++++++++++++++++----- src/common/resources_utils.cpp | 10 ++++++++-- src/v1/resources.cpp | 25 ++++++++++++++++++++----- 3 files changed, 48 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/0bae2670/src/common/resources.cpp ---------------------------------------------------------------------- diff --git a/src/common/resources.cpp b/src/common/resources.cpp index 22bc24e..c088ee2 100644 --- a/src/common/resources.cpp +++ b/src/common/resources.cpp @@ -1510,7 +1510,18 @@ Resources Resources::createStrippedScalarQuantity() const Resource scalar = resource; scalar.clear_provider_id(); scalar.clear_allocation_info(); - scalar.clear_reservation(); + + // We collapse the stack of reservations here to a single `STATIC` + // reservation in order to maintain existing behavior of ignoring + // the reservation type, and keeping the reservation role. + if (Resources::isReserved(scalar)) { + Resource::ReservationInfo collapsedReservation; + collapsedReservation.set_type(Resource::ReservationInfo::STATIC); + collapsedReservation.set_role(Resources::reservationRole(scalar)); + scalar.clear_reservations(); + scalar.add_reservations()->CopyFrom(collapsedReservation); + } + scalar.clear_disk(); scalar.clear_shared(); stripped.add(scalar); @@ -1562,8 +1573,10 @@ Try Resources::apply(const Offer::Operation& operation) const foreach (const Resource& reserved, operation.reserve().resources()) { if (!Resources::isReserved(reserved)) { return Error("Invalid RESERVE Operation: Resource must be reserved"); - } else if (!reserved.has_reservation()) { - return Error("Invalid RESERVE Operation: Missing 'reservation'"); + } else if (!Resources::isDynamicallyReserved(reserved)) { + return Error( + "Invalid RESERVE Operation: Resource must be" + " dynamically reserved"); } Resources unreserved = Resources(reserved).flatten(); @@ -1588,8 +1601,10 @@ Try Resources::apply(const Offer::Operation& operation) const foreach (const Resource& reserved, operation.unreserve().resources()) { if (!Resources::isReserved(reserved)) { return Error("Invalid UNRESERVE Operation: Resource is not reserved"); - } else if (!reserved.has_reservation()) { - return Error("Invalid UNRESERVE Operation: Missing 'reservation'"); + } else if (!Resources::isDynamicallyReserved(reserved)) { + return Error( + "Invalid UNRESERVE Operation: Resource is not" + " dynamically reserved"); } if (!result.contains(reserved)) { http://git-wip-us.apache.org/repos/asf/mesos/blob/0bae2670/src/common/resources_utils.cpp ---------------------------------------------------------------------- diff --git a/src/common/resources_utils.cpp b/src/common/resources_utils.cpp index 19c89bf..4671477 100644 --- a/src/common/resources_utils.cpp +++ b/src/common/resources_utils.cpp @@ -52,9 +52,15 @@ Try applyCheckpointedResources( Resource stripped = resource; + // Since only unreserved and statically reserved resources can be specified + // on the agent, we strip away all of the dynamic reservations here to + // deduce the agent resources on which to apply the checkpointed resources. if (Resources::isDynamicallyReserved(resource)) { - stripped.set_role("*"); - stripped.clear_reservation(); + Resource::ReservationInfo reservation = stripped.reservations(0); + stripped.clear_reservations(); + if (reservation.type() == Resource::ReservationInfo::STATIC) { + stripped.add_reservations()->CopyFrom(reservation); + } } // Strip persistence and volume from the disk info so that we can http://git-wip-us.apache.org/repos/asf/mesos/blob/0bae2670/src/v1/resources.cpp ---------------------------------------------------------------------- diff --git a/src/v1/resources.cpp b/src/v1/resources.cpp index d03577f..0fd8eac 100644 --- a/src/v1/resources.cpp +++ b/src/v1/resources.cpp @@ -1512,7 +1512,18 @@ Resources Resources::createStrippedScalarQuantity() const Resource scalar = resource; scalar.clear_provider_id(); scalar.clear_allocation_info(); - scalar.clear_reservation(); + + // We collapse the stack of reservations here to a single `STATIC` + // reservation in order to maintain existing behavior of ignoring + // the reservation type, and keeping the reservation role. + if (Resources::isReserved(scalar)) { + Resource::ReservationInfo collapsedReservation; + collapsedReservation.set_type(Resource::ReservationInfo::STATIC); + collapsedReservation.set_role(Resources::reservationRole(scalar)); + scalar.clear_reservations(); + scalar.add_reservations()->CopyFrom(collapsedReservation); + } + scalar.clear_disk(); scalar.clear_shared(); stripped.add(scalar); @@ -1564,8 +1575,10 @@ Try Resources::apply(const Offer::Operation& operation) const foreach (const Resource& reserved, operation.reserve().resources()) { if (!Resources::isReserved(reserved)) { return Error("Invalid RESERVE Operation: Resource must be reserved"); - } else if (!reserved.has_reservation()) { - return Error("Invalid RESERVE Operation: Missing 'reservation'"); + } else if (!Resources::isDynamicallyReserved(reserved)) { + return Error( + "Invalid RESERVE Operation: Resource must be" + " dynamically reserved"); } Resources unreserved = Resources(reserved).flatten(); @@ -1590,8 +1603,10 @@ Try Resources::apply(const Offer::Operation& operation) const foreach (const Resource& reserved, operation.unreserve().resources()) { if (!Resources::isReserved(reserved)) { return Error("Invalid UNRESERVE Operation: Resource is not reserved"); - } else if (!reserved.has_reservation()) { - return Error("Invalid UNRESERVE Operation: Missing 'reservation'"); + } else if (!Resources::isDynamicallyReserved(reserved)) { + return Error( + "Invalid UNRESERVE Operation: Resource is not" + " dynamically reserved"); } if (!result.contains(reserved)) {