You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ya...@apache.org on 2016/08/24 22:46:36 UTC

mesos git commit: Made Resources::add()/subtract() private.

Repository: mesos
Updated Branches:
  refs/heads/master 0fb5faf66 -> b5dd33397


Made Resources::add()/subtract() private.

We do not want external code to call them directly so we should make
them private.

Review: https://reviews.apache.org/r/50836/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/b5dd3339
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/b5dd3339
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/b5dd3339

Branch: refs/heads/master
Commit: b5dd33397e9201fb268e25a9a05a3710f1086040
Parents: 0fb5faf
Author: Guangya Liu <gy...@gmail.com>
Authored: Wed Aug 24 15:42:54 2016 -0700
Committer: Jiang Yan Xu <xu...@apple.com>
Committed: Wed Aug 24 15:42:54 2016 -0700

----------------------------------------------------------------------
 include/mesos/resources.hpp    | 25 ++++++++++++++++++++-----
 include/mesos/v1/resources.hpp | 25 ++++++++++++++++++++-----
 src/common/resources.cpp       |  2 +-
 src/v1/resources.cpp           |  2 +-
 4 files changed, 42 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/b5dd3339/include/mesos/resources.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/resources.hpp b/include/mesos/resources.hpp
index bdbe8ea..b132933 100644
--- a/include/mesos/resources.hpp
+++ b/include/mesos/resources.hpp
@@ -34,6 +34,7 @@
 #include <stout/error.hpp>
 #include <stout/foreach.hpp>
 #include <stout/hashmap.hpp>
+#include <stout/json.hpp>
 #include <stout/lambda.hpp>
 #include <stout/option.hpp>
 #include <stout/try.hpp>
@@ -52,6 +53,16 @@
 
 namespace mesos {
 
+// Forward declarations required for making
+// `convertJSON` a friend of `Resources`.
+class Resources;
+
+namespace internal {
+  Try<Resources> convertJSON(
+      const JSON::Array& resourcesJSON,
+      const std::string& defaultRole);
+}
+
 // NOTE: Resource objects stored in the class are always valid and
 // kept combined if possible. It is the caller's responsibility to
 // validate any Resource object or repeated Resource protobufs before
@@ -458,14 +469,13 @@ 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);
-
   friend std::ostream& operator<<(
       std::ostream& stream, const Resource_& resource_);
 
+  friend Try<Resources> internal::convertJSON(
+      const JSON::Array& resourcesJSON,
+      const std::string& defaultRole);
+
 private:
   // Similar to 'contains(const Resource&)' but skips the validity
   // check. This can be used to avoid the performance overhead of
@@ -481,6 +491,11 @@ 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);
+
   // The add and subtract methods and operators on Resource_ are only
   // allowed from within Resources class so we hide them.
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/b5dd3339/include/mesos/v1/resources.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/v1/resources.hpp b/include/mesos/v1/resources.hpp
index c05cb63..e7f5329 100644
--- a/include/mesos/v1/resources.hpp
+++ b/include/mesos/v1/resources.hpp
@@ -33,6 +33,7 @@
 #include <stout/error.hpp>
 #include <stout/foreach.hpp>
 #include <stout/hashmap.hpp>
+#include <stout/json.hpp>
 #include <stout/lambda.hpp>
 #include <stout/option.hpp>
 #include <stout/try.hpp>
@@ -52,6 +53,16 @@
 namespace mesos {
 namespace v1 {
 
+// Forward declarations required for making
+// `convertJSON` a friend of `Resources`.
+class Resources;
+
+namespace internal {
+  Try<Resources> convertJSON(
+      const JSON::Array& resourcesJSON,
+      const std::string& defaultRole);
+}
+
 // NOTE: Resource objects stored in the class are always valid and
 // kept combined if possible. It is the caller's responsibility to
 // validate any Resource object or repeated Resource protobufs before
@@ -458,14 +469,13 @@ 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);
-
   friend std::ostream& operator<<(
       std::ostream& stream, const Resource_& resource_);
 
+  friend Try<Resources> internal::convertJSON(
+      const JSON::Array& resourcesJSON,
+      const std::string& defaultRole);
+
 private:
   // Similar to 'contains(const Resource&)' but skips the validity
   // check. This can be used to avoid the performance overhead of
@@ -481,6 +491,11 @@ 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);
+
   // The add and subtract methods and operators on Resource_ are only
   // allowed from within Resources class so we hide them.
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/b5dd3339/src/common/resources.cpp
----------------------------------------------------------------------
diff --git a/src/common/resources.cpp b/src/common/resources.cpp
index 96b4c39..a5f5902 100644
--- a/src/common/resources.cpp
+++ b/src/common/resources.cpp
@@ -446,7 +446,7 @@ static Option<Error> validateCommandLineResources(const Resources& resources)
  * @return A `Try` containing a Resources object if conversion was successful,
  *     or an Error otherwise.
  */
-static Try<Resources> convertJSON(
+inline Try<Resources> convertJSON(
     const JSON::Array& resourcesJSON,
     const string& defaultRole)
 {

http://git-wip-us.apache.org/repos/asf/mesos/blob/b5dd3339/src/v1/resources.cpp
----------------------------------------------------------------------
diff --git a/src/v1/resources.cpp b/src/v1/resources.cpp
index 3cc7580..1722175 100644
--- a/src/v1/resources.cpp
+++ b/src/v1/resources.cpp
@@ -448,7 +448,7 @@ static Option<Error> validateCommandLineResources(const Resources& resources)
  * @return A `Try` containing a Resources object if conversion was successful,
  *     or an Error otherwise.
  */
-static Try<Resources> convertJSON(
+inline Try<Resources> convertJSON(
     const JSON::Array& resourcesJSON,
     const string& defaultRole)
 {