You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2016/07/29 20:43:24 UTC
mesos git commit: Updated -=/+= to subtract/add for resource object.
Repository: mesos
Updated Branches:
refs/heads/master 044bd9833 -> 3f488e8d3
Updated -=/+= to subtract/add for resource object.
This is a follow up action for MESOS-5919. Based on the patch of
https://reviews.apache.org/r/50553/ and
https://reviews.apache.org/r/50557/, we should update -=/+= to
subtract/add if the resource object is from a Resources object,
since it is already validated.
Review: https://reviews.apache.org/r/50568/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/3f488e8d
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/3f488e8d
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/3f488e8d
Branch: refs/heads/master
Commit: 3f488e8d3b4bc84ecdcf28bf89ee1ca952beeae7
Parents: 044bd98
Author: Guangya Liu <gy...@gmail.com>
Authored: Fri Jul 29 13:42:49 2016 -0700
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Fri Jul 29 13:42:49 2016 -0700
----------------------------------------------------------------------
include/mesos/resources.hpp | 10 +++++-----
include/mesos/v1/resources.hpp | 10 +++++-----
src/common/resources.cpp | 22 +++++++++++-----------
src/v1/resources.cpp | 22 +++++++++++-----------
4 files changed, 32 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/3f488e8d/include/mesos/resources.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/resources.hpp b/include/mesos/resources.hpp
index 88a9fea..6638c8f 100644
--- a/include/mesos/resources.hpp
+++ b/include/mesos/resources.hpp
@@ -381,6 +381,11 @@ public:
Resources& operator-=(const Resource& that);
Resources& operator-=(const Resources& that);
+ // Validation-free versions of += and -= `Resource` operators.
+ // These can be used when `r` is already validated.
+ void add(const Resource& r);
+ void subtract(const Resource& r);
+
private:
// Similar to 'contains(const Resource&)' but skips the validity
// check. This can be used to avoid the performance overhead of
@@ -396,11 +401,6 @@ private:
// returns Resources.
Option<Resources> find(const Resource& target) const;
- // Validation-free versions of += and -= `Resource` operators.
- // These can be used when `r` is already validated.
- void add(const Resource& r);
- void subtract(const Resource& r);
-
google::protobuf::RepeatedPtrField<Resource> resources;
};
http://git-wip-us.apache.org/repos/asf/mesos/blob/3f488e8d/include/mesos/v1/resources.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/v1/resources.hpp b/include/mesos/v1/resources.hpp
index 054ed00..fdbabf5 100644
--- a/include/mesos/v1/resources.hpp
+++ b/include/mesos/v1/resources.hpp
@@ -381,6 +381,11 @@ public:
Resources& operator-=(const Resource& that);
Resources& operator-=(const Resources& that);
+ // Validation-free versions of += and -= `Resource` operators.
+ // These can be used when `r` is already validated.
+ void add(const Resource& r);
+ void subtract(const Resource& r);
+
private:
// Similar to 'contains(const Resource&)' but skips the validity
// check. This can be used to avoid the performance overhead of
@@ -396,11 +401,6 @@ private:
// returns Resources.
Option<Resources> find(const Resource& target) const;
- // Validation-free versions of += and -= `Resource` operators.
- // These can be used when `r` is already validated.
- void add(const Resource& r);
- void subtract(const Resource& r);
-
google::protobuf::RepeatedPtrField<Resource> resources;
};
http://git-wip-us.apache.org/repos/asf/mesos/blob/3f488e8d/src/common/resources.cpp
----------------------------------------------------------------------
diff --git a/src/common/resources.cpp b/src/common/resources.cpp
index 69166de..468581d 100644
--- a/src/common/resources.cpp
+++ b/src/common/resources.cpp
@@ -455,7 +455,7 @@ static Try<Resources> convertJSON(
return Error("Some JSON resources were empty: " + stringify(resource));
}
- result += resource;
+ result.add(resource);
}
return result;
@@ -862,7 +862,7 @@ hashmap<string, Resources> Resources::reservations() const
foreach (const Resource& resource, resources) {
if (isReserved(resource)) {
- result[resource.role()] += resource;
+ result[resource.role()].add(resource);
}
}
@@ -930,7 +930,7 @@ Resources Resources::createStrippedScalarQuantity() const
Resource scalar = resource;
scalar.clear_reservation();
scalar.clear_disk();
- stripped += scalar;
+ stripped.add(scalar);
}
}
@@ -987,7 +987,7 @@ Try<Resources> Resources::apply(const Offer::Operation& operation) const
}
result -= unreserved;
- result += reserved;
+ result.add(reserved);
}
break;
}
@@ -1012,7 +1012,7 @@ Try<Resources> Resources::apply(const Offer::Operation& operation) const
Resources unreserved = Resources(reserved).flatten();
- result -= reserved;
+ result.subtract(reserved);
result += unreserved;
}
break;
@@ -1050,8 +1050,8 @@ Try<Resources> Resources::apply(const Offer::Operation& operation) const
return Error("Invalid CREATE Operation: Insufficient disk resources");
}
- result -= stripped;
- result += volume;
+ result.subtract(stripped);
+ result.add(volume);
}
break;
}
@@ -1085,8 +1085,8 @@ Try<Resources> Resources::apply(const Offer::Operation& operation) const
stripped.clear_disk();
}
- result -= volume;
- result += stripped;
+ result.subtract(volume);
+ result.add(stripped);
}
break;
}
@@ -1323,8 +1323,8 @@ Option<Resources> Resources::find(const Resource& target) const
remaining.flatten(resource.role(), resource.reservation());
}
} else if (remaining.contains(flattened)) {
- found += resource;
- total -= resource;
+ found.add(resource);
+ total.subtract(resource);
remaining -= flattened;
break;
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/3f488e8d/src/v1/resources.cpp
----------------------------------------------------------------------
diff --git a/src/v1/resources.cpp b/src/v1/resources.cpp
index 90897e3..230d55b 100644
--- a/src/v1/resources.cpp
+++ b/src/v1/resources.cpp
@@ -457,7 +457,7 @@ static Try<Resources> convertJSON(
return Error("Some JSON resources were empty: " + stringify(resource));
}
- result += resource;
+ result.add(resource);
}
return result;
@@ -865,7 +865,7 @@ hashmap<string, Resources> Resources::reservations() const
foreach (const Resource& resource, resources) {
if (isReserved(resource)) {
- result[resource.role()] += resource;
+ result[resource.role()].add(resource);
}
}
@@ -933,7 +933,7 @@ Resources Resources::createStrippedScalarQuantity() const
Resource scalar = resource;
scalar.clear_reservation();
scalar.clear_disk();
- stripped += scalar;
+ stripped.add(scalar);
}
}
@@ -990,7 +990,7 @@ Try<Resources> Resources::apply(const Offer::Operation& operation) const
}
result -= unreserved;
- result += reserved;
+ result.add(reserved);
}
break;
}
@@ -1015,7 +1015,7 @@ Try<Resources> Resources::apply(const Offer::Operation& operation) const
Resources unreserved = Resources(reserved).flatten();
- result -= reserved;
+ result.subtract(reserved);
result += unreserved;
}
break;
@@ -1053,8 +1053,8 @@ Try<Resources> Resources::apply(const Offer::Operation& operation) const
return Error("Invalid CREATE Operation: Insufficient disk resources");
}
- result -= stripped;
- result += volume;
+ result.subtract(stripped);
+ result.add(volume);
}
break;
}
@@ -1088,8 +1088,8 @@ Try<Resources> Resources::apply(const Offer::Operation& operation) const
stripped.clear_disk();
}
- result -= volume;
- result += stripped;
+ result.subtract(volume);
+ result.add(stripped);
}
break;
}
@@ -1326,8 +1326,8 @@ Option<Resources> Resources::find(const Resource& target) const
remaining.flatten(resource.role(), resource.reservation());
}
} else if (remaining.contains(flattened)) {
- found += resource;
- total -= resource;
+ found.add(resource);
+ total.subtract(resource);
remaining -= flattened;
break;
}