You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by nn...@apache.org on 2015/09/17 03:21:46 UTC
[4/7] mesos git commit: Added helper to model Labels message for
state.json.
Added helper to model Labels message for state.json.
Also updated Task modelling to show labels only if Task.has_labels() is
true. This way, the "labels" field won't shown if there are no labels.
This makes it consistent with the modelling of rest of the "optional"
fields.
Review: https://reviews.apache.org/r/38366
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/fd0a431c
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/fd0a431c
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/fd0a431c
Branch: refs/heads/master
Commit: fd0a431c340d66f96f71715ace0d10d9c1b17b49
Parents: 6923bb3
Author: Kapil Arya <ka...@mesosphere.io>
Authored: Wed Sep 16 17:01:54 2015 -0700
Committer: Niklas Q. Nielsen <ni...@qni.dk>
Committed: Wed Sep 16 17:01:55 2015 -0700
----------------------------------------------------------------------
src/common/http.cpp | 42 ++++++++++++++----------------------
src/common/http.hpp | 1 +
src/common/protobuf_utils.cpp | 4 +++-
src/master/master.cpp | 4 +++-
src/tests/common/http_tests.cpp | 1 -
5 files changed, 23 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/fd0a431c/src/common/http.cpp
----------------------------------------------------------------------
diff --git a/src/common/http.cpp b/src/common/http.cpp
index 9c0d31e..85fb932 100644
--- a/src/common/http.cpp
+++ b/src/common/http.cpp
@@ -139,6 +139,17 @@ JSON::Object model(const Attributes& attributes)
}
+JSON::Array model(const Labels& labels)
+{
+ JSON::Array array;
+ array.values.reserve(labels.labels().size()); // MESOS-2353.
+ foreach (const Label& label, labels.labels()) {
+ array.values.push_back(JSON::Protobuf(label));
+ }
+ return array;
+}
+
+
// Returns a JSON object modeled on a TaskStatus.
JSON::Object model(const TaskStatus& status)
{
@@ -147,13 +158,8 @@ JSON::Object model(const TaskStatus& status)
object.values["timestamp"] = status.timestamp();
if (status.has_labels()) {
- JSON::Array array;
- array.values.reserve(status.labels().labels().size()); // MESOS-2353.
+ object.values["labels"] = std::move(model(status.labels()));
- foreach (const Label& label, status.labels().labels()) {
- array.values.push_back(JSON::Protobuf(label));
- }
- object.values["labels"] = std::move(array);
}
return object;
@@ -188,16 +194,8 @@ JSON::Object model(const Task& task)
object.values["statuses"] = std::move(array);
}
- {
- JSON::Array array;
- if (task.has_labels()) {
- array.values.reserve(task.labels().labels().size()); // MESOS-2353.
-
- foreach (const Label& label, task.labels().labels()) {
- array.values.push_back(JSON::Protobuf(label));
- }
- }
- object.values["labels"] = std::move(array);
+ if (task.has_labels()) {
+ object.values["labels"] = std::move(model(task.labels()));
}
if (task.has_discovery()) {
@@ -299,16 +297,8 @@ JSON::Object model(
object.values["statuses"] = std::move(array);
}
- {
- JSON::Array array;
- if (task.has_labels()) {
- array.values.reserve(task.labels().labels().size()); // MESOS-2353.
-
- foreach (const Label& label, task.labels().labels()) {
- array.values.push_back(JSON::Protobuf(label));
- }
- }
- object.values["labels"] = std::move(array);
+ if (task.has_labels()) {
+ object.values["labels"] = std::move(model(task.labels()));
}
if (task.has_discovery()) {
http://git-wip-us.apache.org/repos/asf/mesos/blob/fd0a431c/src/common/http.hpp
----------------------------------------------------------------------
diff --git a/src/common/http.hpp b/src/common/http.hpp
index 61ad531..1e61888 100644
--- a/src/common/http.hpp
+++ b/src/common/http.hpp
@@ -79,6 +79,7 @@ JSON::Object model(const hashmap<std::string, Resources>& roleResources);
JSON::Object model(const Attributes& attributes);
JSON::Object model(const CommandInfo& command);
JSON::Object model(const ExecutorInfo& executorInfo);
+JSON::Array model(const Labels& labels);
// These are the two identical ways to model a task, depending on
// whether you have a 'Task' or a 'TaskInfo' available.
http://git-wip-us.apache.org/repos/asf/mesos/blob/fd0a431c/src/common/protobuf_utils.cpp
----------------------------------------------------------------------
diff --git a/src/common/protobuf_utils.cpp b/src/common/protobuf_utils.cpp
index 0861270..c8e6211 100644
--- a/src/common/protobuf_utils.cpp
+++ b/src/common/protobuf_utils.cpp
@@ -137,7 +137,9 @@ Task createTask(
t.mutable_executor_id()->CopyFrom(task.executor().executor_id());
}
- t.mutable_labels()->MergeFrom(task.labels());
+ if (task.has_labels()) {
+ t.mutable_labels()->CopyFrom(task.labels());
+ }
if (task.has_discovery()) {
t.mutable_discovery()->MergeFrom(task.discovery());
http://git-wip-us.apache.org/repos/asf/mesos/blob/fd0a431c/src/master/master.cpp
----------------------------------------------------------------------
diff --git a/src/master/master.cpp b/src/master/master.cpp
index f26271c..1c4e7af 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -2743,7 +2743,9 @@ Resources Master::addTask(
t->mutable_executor_id()->MergeFrom(executorId.get());
}
- t->mutable_labels()->MergeFrom(task.labels());
+ if (task.has_labels()) {
+ t->mutable_labels()->MergeFrom(task.labels());
+ }
if (task.has_discovery()) {
t->mutable_discovery()->MergeFrom(task.discovery());
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/fd0a431c/src/tests/common/http_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/common/http_tests.cpp b/src/tests/common/http_tests.cpp
index bf8712b..8a01ffc 100644
--- a/src/tests/common/http_tests.cpp
+++ b/src/tests/common/http_tests.cpp
@@ -88,7 +88,6 @@ TEST(HTTPTest, ModelTask)
" \"executor_id\":\"\","
" \"framework_id\":\"f\","
" \"id\":\"t\","
- " \"labels\": [],"
" \"name\":\"task\","
" \"resources\":"
" {"