You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by me...@apache.org on 2015/07/30 10:48:41 UTC

mesos git commit: Allow slave attributes flag take a value with ':'.

Repository: mesos
Updated Branches:
  refs/heads/master 18e1351b3 -> 032ee8e0b


Allow slave attributes flag take a value with ':'.

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


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

Branch: refs/heads/master
Commit: 032ee8e0bb6bfe73b47173afd369e3343719fed6
Parents: 18e1351
Author: haosdent huang <ha...@gmail.com>
Authored: Thu Jul 30 00:45:08 2015 -0700
Committer: Adam B <ad...@mesosphere.io>
Committed: Thu Jul 30 00:46:13 2015 -0700

----------------------------------------------------------------------
 src/common/attributes.cpp      | 8 ++++----
 src/tests/attributes_tests.cpp | 8 ++++++++
 2 files changed, 12 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/032ee8e0/src/common/attributes.cpp
----------------------------------------------------------------------
diff --git a/src/common/attributes.cpp b/src/common/attributes.cpp
index aab114e..a8a621e 100644
--- a/src/common/attributes.cpp
+++ b/src/common/attributes.cpp
@@ -115,7 +115,7 @@ Attribute Attributes::parse(const std::string& name, const std::string& text)
     LOG(FATAL) << "Failed to parse attribute " << name
                << " text " << text
                << " error " << result.error();
-  } else{
+  } else {
     Value value = result.get();
     attribute.set_name(name);
 
@@ -147,9 +147,9 @@ Attributes Attributes::parse(const string& s)
   vector<string> tokens = strings::tokenize(s, ";\n");
 
   for (size_t i = 0; i < tokens.size(); i++) {
-    const vector<string>& pairs = strings::tokenize(tokens[i], ":");
-    if (pairs.size() != 2) {
-      LOG(FATAL) << "Bad value for attributes, missing ':' within " << pairs[0];
+    const vector<string>& pairs = strings::split(tokens[i], ":", 2);
+    if (pairs.size() != 2 || pairs[0].empty() || pairs[1].empty()) {
+      LOG(FATAL) << "Invalid attribute key:value pair '" << tokens[i] << "'";
     }
 
     attributes.add(parse(pairs[0], pairs[1]));

http://git-wip-us.apache.org/repos/asf/mesos/blob/032ee8e0/src/tests/attributes_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/attributes_tests.cpp b/src/tests/attributes_tests.cpp
index 2e10eaf..ded6120 100644
--- a/src/tests/attributes_tests.cpp
+++ b/src/tests/attributes_tests.cpp
@@ -51,6 +51,14 @@ TEST(AttributesTest, Parsing)
   ASSERT_EQ(Value::TEXT, a.get(2).type());
   ASSERT_EQ("rack", a.get(2).name());
   ASSERT_EQ("rack1,rack2", a.get(2).text().value());
+
+  Attributes b = Attributes::parse("attr1:foo:bar;attr2:baz:qux:");
+  ASSERT_EQ(Value::TEXT, b.get(0).type());
+  ASSERT_EQ("attr1", b.get(0).name());
+  ASSERT_EQ("foo:bar", b.get(0).text().value());
+  ASSERT_EQ(Value::TEXT, b.get(1).type());
+  ASSERT_EQ("attr2", b.get(1).name());
+  ASSERT_EQ("baz:qux:", b.get(1).text().value());
 }