mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ne...@apache.org
Subject [1/2] mesos git commit: Synchronize "v1" and unversioned copies of several files.
Date Fri, 17 Mar 2017 21:15:16 GMT
Repository: mesos
Updated Branches:
  refs/heads/master 62161ac44 -> 5381b36e0


Synchronize "v1" and unversioned copies of several files.


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

Branch: refs/heads/master
Commit: af5f259d4edddaad465611b88774240555f4ecb0
Parents: 62161ac
Author: Neil Conway <neil.conway@gmail.com>
Authored: Fri Mar 17 11:30:06 2017 -0700
Committer: Neil Conway <neil.conway@gmail.com>
Committed: Fri Mar 17 14:13:10 2017 -0700

----------------------------------------------------------------------
 include/mesos/attributes.hpp   |  2 ++
 include/mesos/resources.hpp    | 16 ++++++++--------
 include/mesos/v1/resources.hpp | 16 ++++++++++++++++
 src/v1/attributes.cpp          |  1 +
 src/v1/resources.cpp           | 19 ++++++++++++++++---
 src/v1/values.cpp              | 10 +++++-----
 6 files changed, 48 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/af5f259d/include/mesos/attributes.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/attributes.hpp b/include/mesos/attributes.hpp
index 445d15e..641febb 100644
--- a/include/mesos/attributes.hpp
+++ b/include/mesos/attributes.hpp
@@ -28,6 +28,7 @@ namespace mesos {
 
 std::ostream& operator<<(std::ostream& stream, const Attribute& attribute);
 
+
 class Attributes
 {
 public:
@@ -39,6 +40,7 @@ public:
     attributes.MergeFrom(_attributes);
   }
 
+  /*implicit*/
   Attributes(const Attributes& that)
   {
     attributes.MergeFrom(that.attributes);

http://git-wip-us.apache.org/repos/asf/mesos/blob/af5f259d/include/mesos/resources.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/resources.hpp b/include/mesos/resources.hpp
index 73e44be..74583e3 100644
--- a/include/mesos/resources.hpp
+++ b/include/mesos/resources.hpp
@@ -345,14 +345,6 @@ public:
 
   size_t size() const { return resources.size(); }
 
-  // Allocates the resources to the given role (by setting the
-  // `AllocationInfo.role`). Any existing allocation will be
-  // over-written.
-  void allocate(const std::string& role);
-
-  // Unallocates the resources.
-  void unallocate();
-
   // Checks if this Resources is a superset of the given Resources.
   bool contains(const Resources& that) const;
 
@@ -368,6 +360,14 @@ public:
   // - If the resource is not in the Resources object, the count is 0.
   size_t count(const Resource& that) const;
 
+  // Allocates the resources to the given role (by setting the
+  // `AllocationInfo.role`). Any existing allocation will be
+  // over-written.
+  void allocate(const std::string& role);
+
+  // Unallocates the resources.
+  void unallocate();
+
   // Filter resources based on the given predicate.
   Resources filter(
       const lambda::function<bool(const Resource&)>& predicate) const;

http://git-wip-us.apache.org/repos/asf/mesos/blob/af5f259d/include/mesos/v1/resources.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/v1/resources.hpp b/include/mesos/v1/resources.hpp
index 1913229..132ef3e 100644
--- a/include/mesos/v1/resources.hpp
+++ b/include/mesos/v1/resources.hpp
@@ -214,6 +214,22 @@ public:
       const std::string& defaultRole = "*");
 
   /**
+   * Parse an input string into a vector of Resource objects.
+   *
+   * Parses into a vector of Resource objects from either JSON or plain
+   * text. If the string is well-formed JSON it is assumed to be JSON,
+   * otherwise plain text. Any resource that doesn't specify a role is
+   * assigned to the provided default role.
+   *
+   * NOTE: The `Resource` objects in the result vector may not be valid
+   * semantically (i.e., they may not pass `Resources::validate()`). This
+   * is to allow additional handling of the parsing results in some cases.
+   */
+  static Try<std::vector<Resource>> fromString(
+      const std::string& text,
+      const std::string& defaultRole = "*");
+
+  /**
    * Validates a Resource object.
    *
    * Validates the given Resource object. Returns Error if it is not valid. A

http://git-wip-us.apache.org/repos/asf/mesos/blob/af5f259d/src/v1/attributes.cpp
----------------------------------------------------------------------
diff --git a/src/v1/attributes.cpp b/src/v1/attributes.cpp
index fb2fb60..409d664 100644
--- a/src/v1/attributes.cpp
+++ b/src/v1/attributes.cpp
@@ -29,6 +29,7 @@ using std::ostream;
 using std::string;
 using std::vector;
 
+
 namespace mesos {
 namespace v1 {
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/af5f259d/src/v1/resources.cpp
----------------------------------------------------------------------
diff --git a/src/v1/resources.cpp b/src/v1/resources.cpp
index 6fd8687..96faca4 100644
--- a/src/v1/resources.cpp
+++ b/src/v1/resources.cpp
@@ -584,9 +584,7 @@ Try<Resources> Resources::parse(
   // Try to parse as a JSON Array. Otherwise, parse as a text string.
   Try<JSON::Array> json = JSON::parse<JSON::Array>(text);
 
-  Try<vector<Resource>> resources = json.isSome() ?
-    Resources::fromJSON(json.get(), defaultRole) :
-    Resources::fromSimpleString(text, defaultRole);
+  Try<vector<Resource>> resources = Resources::fromString(text, defaultRole);
 
   if (resources.isError()) {
     return Error(resources.error());
@@ -653,6 +651,8 @@ Try<vector<Resource>> Resources::fromSimpleString(
   vector<Resource> resources;
 
   foreach (const string& token, strings::tokenize(text, ";")) {
+    // TODO(anindya_sinha): Allow text based representation of resources
+    // to specify PATH or MOUNT type disks along with its root.
     vector<string> pair = strings::tokenize(token, ":");
     if (pair.size() != 2) {
       return Error(
@@ -692,6 +692,19 @@ Try<vector<Resource>> Resources::fromSimpleString(
 }
 
 
+Try<vector<Resource>> Resources::fromString(
+    const string& text,
+    const string& defaultRole)
+{
+  // Try to parse as a JSON Array. Otherwise, parse as a text string.
+  Try<JSON::Array> json = JSON::parse<JSON::Array>(text);
+
+  return json.isSome() ?
+    Resources::fromJSON(json.get(), defaultRole) :
+    Resources::fromSimpleString(text, defaultRole);
+}
+
+
 Option<Error> Resources::validate(const Resource& resource)
 {
   if (resource.name().empty()) {

http://git-wip-us.apache.org/repos/asf/mesos/blob/af5f259d/src/v1/values.cpp
----------------------------------------------------------------------
diff --git a/src/v1/values.cpp b/src/v1/values.cpp
index 0f16c1e..d2c31f6 100644
--- a/src/v1/values.cpp
+++ b/src/v1/values.cpp
@@ -74,7 +74,8 @@ ostream& operator<<(ostream& stream, const Value::Scalar&
scalar)
 {
   // Output the scalar's full significant digits and save the old
   // precision.
-  long precision = stream.precision(std::numeric_limits<double>::digits10);
+  std::streamsize precision =
+    stream.precision(std::numeric_limits<double>::digits10);
 
   // We discard any additional precision (of the fractional part)
   // from scalar resources before writing them to an ostream. This
@@ -610,12 +611,11 @@ Try<Value> parse(const string& text)
       for (size_t i = 0; i < tokens.size(); i += 2) {
         Value::Range* range = ranges->add_range();
 
-        int j = i;
-        Try<uint64_t> begin = numify<uint64_t>(tokens[j++]);
-        Try<uint64_t> end = numify<uint64_t>(tokens[j++]);
+        Try<uint64_t> begin = numify<uint64_t>(tokens[i]);
+        Try<uint64_t> end = numify<uint64_t>(tokens[i + 1]);
         if (begin.isError() || end.isError()) {
           return Error(
-              "Expecting non-negative integers in '" + tokens[j - 1] + "'");
+              "Expecting non-negative integers in '" + tokens[i] + "'");
         }
 
         range->set_begin(begin.get());


Mime
View raw message