Repository: mesos Updated Branches: refs/heads/master eb3263af2 -> 2ee98b040
Added allocation role to tasks/executors in v0 /state API. Added allocation role of tasks/executors to the /state v0 API. Unlike v1 API where allocation_info is nested in each one of resources, we add that information at task/executor level for v0 API since the JSON format for resources cannot be extended to support allocation role. Note that resources of one task/executor are guaranteed to have same allocation role. Review: https://reviews.apache.org/r/56938/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/2ee98b04 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/2ee98b04 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/2ee98b04 Branch: refs/heads/master Commit: 2ee98b040927ec80371f1850717fe4add91b8b77 Parents: eb3263a Author: Jay Guo <[email protected]> Authored: Thu Feb 23 13:26:43 2017 -0800 Committer: Benjamin Mahler <[email protected]> Committed: Thu Feb 23 13:55:51 2017 -0800 ---------------------------------------------------------------------- src/common/http.cpp | 14 ++++++++++++++ src/master/http.cpp | 11 +++++++++-- src/slave/http.cpp | 13 +++++++++++++ src/tests/slave_tests.cpp | 16 ++++++++++++++-- 4 files changed, 50 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/2ee98b04/src/common/http.cpp ---------------------------------------------------------------------- diff --git a/src/common/http.cpp b/src/common/http.cpp index abfbf72..5d75ecd 100644 --- a/src/common/http.cpp +++ b/src/common/http.cpp @@ -559,6 +559,15 @@ void json(JSON::ObjectWriter* writer, const ExecutorInfo& executorInfo) writer->field("command", executorInfo.command()); writer->field("resources", Resources(executorInfo.resources())); + // Resources may be empty for command executors. + if (!executorInfo.resources().empty()) { + // Executors are not allowed to mix resources allocated to + // different roles, see MESOS-6636. + writer->field( + "role", + executorInfo.resources().begin()->allocation_info().role()); + } + if (executorInfo.has_labels()) { writer->field("labels", executorInfo.labels()); } @@ -641,6 +650,11 @@ void json(JSON::ObjectWriter* writer, const Task& task) writer->field("slave_id", task.slave_id().value()); writer->field("state", TaskState_Name(task.state())); writer->field("resources", Resources(task.resources())); + + // Tasks are not allowed to mix resources allocated to + // different roles, see MESOS-6636. + writer->field("role", task.resources().begin()->allocation_info().role()); + writer->field("statuses", task.statuses()); if (task.has_user()) { http://git-wip-us.apache.org/repos/asf/mesos/blob/2ee98b04/src/master/http.cpp ---------------------------------------------------------------------- diff --git a/src/master/http.cpp b/src/master/http.cpp index e2fd71c..6e5178e 100644 --- a/src/master/http.cpp +++ b/src/master/http.cpp @@ -266,12 +266,19 @@ struct FullFrameworkWriter { writer->field("framework_id", framework_->id().value()); writer->field( - "executor_id", - taskInfo.executor().executor_id().value()); + "executor_id", + taskInfo.executor().executor_id().value()); writer->field("slave_id", taskInfo.slave_id().value()); writer->field("state", TaskState_Name(TASK_STAGING)); writer->field("resources", Resources(taskInfo.resources())); + + // Tasks are not allowed to mix resources allocated to + // different roles, see MESOS-6636. + writer->field( + "role", + taskInfo.resources().begin()->allocation_info().role()); + writer->field("statuses", std::initializer_list<TaskStatus>{}); if (taskInfo.has_labels()) { http://git-wip-us.apache.org/repos/asf/mesos/blob/2ee98b04/src/slave/http.cpp ---------------------------------------------------------------------- diff --git a/src/slave/http.cpp b/src/slave/http.cpp index 8a9fabf..17b6398 100644 --- a/src/slave/http.cpp +++ b/src/slave/http.cpp @@ -127,6 +127,10 @@ static void json(JSON::ObjectWriter* writer, const TaskInfo& task) writer->field("slave_id", task.slave_id().value()); writer->field("resources", Resources(task.resources())); + // Tasks are not allowed to mix resources allocated to + // different roles, see MESOS-6636. + writer->field("role", task.resources().begin()->allocation_info().role()); + if (task.has_command()) { writer->field("command", task.command()); } @@ -174,6 +178,15 @@ struct ExecutorWriter writer->field("directory", executor_->directory); writer->field("resources", executor_->resources); + // Resources may be empty for command executors. + if (!executor_->info.resources().empty()) { + // Executors are not allowed to mix resources allocated to + // different roles, see MESOS-6636. + writer->field( + "role", + executor_->info.resources().begin()->allocation_info().role()); + } + if (executor_->info.has_labels()) { writer->field("labels", executor_->info.labels()); } http://git-wip-us.apache.org/repos/asf/mesos/blob/2ee98b04/src/tests/slave_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/slave_tests.cpp b/src/tests/slave_tests.cpp index 61767b1..3731c76 100644 --- a/src/tests/slave_tests.cpp +++ b/src/tests/slave_tests.cpp @@ -1581,6 +1581,9 @@ TEST_F(SlaveTest, StateEndpoint) AWAIT_READY(offers); EXPECT_NE(0u, offers.get().size()); + Resources executorResources = Resources::parse("cpus:0.1;mem:32").get(); + executorResources.allocate("*"); + TaskID taskId; taskId.set_value("1"); @@ -1588,8 +1591,11 @@ TEST_F(SlaveTest, StateEndpoint) task.set_name(""); task.mutable_task_id()->MergeFrom(taskId); task.mutable_slave_id()->MergeFrom(offers.get()[0].slave_id()); - task.mutable_resources()->MergeFrom(offers.get()[0].resources()); + task.mutable_resources()->MergeFrom( + Resources(offers.get()[0].resources()) - executorResources); + task.mutable_executor()->MergeFrom(DEFAULT_EXECUTOR_INFO); + task.mutable_executor()->mutable_resources()->CopyFrom(executorResources); EXPECT_CALL(exec, registered(_, _, _, _)); @@ -1638,6 +1644,11 @@ TEST_F(SlaveTest, StateEndpoint) EXPECT_EQ("default", executor.values["id"]); EXPECT_EQ("", executor.values["source"]); + EXPECT_EQ("*", executor.values["role"]); + EXPECT_EQ( + model(Resources(task.resources()) + + Resources(task.executor().resources())), + executor.values["resources"]); Result<JSON::Array> tasks = executor.find<JSON::Array>("tasks"); ASSERT_SOME(tasks); @@ -1648,7 +1659,8 @@ TEST_F(SlaveTest, StateEndpoint) EXPECT_EQ("", taskJSON.values["name"]); EXPECT_EQ(taskId.value(), taskJSON.values["id"]); EXPECT_EQ("TASK_RUNNING", taskJSON.values["state"]); - EXPECT_EQ(model(resources.get()), taskJSON.values["resources"]); + EXPECT_EQ("*", taskJSON.values["role"]); + EXPECT_EQ(model(task.resources()), taskJSON.values["resources"]); EXPECT_CALL(exec, shutdown(_)) .Times(AtMost(1));
