Added ContainerID to ContainerStatus. Review: https://reviews.apache.org/r/53464
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/2c0ddbaa Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/2c0ddbaa Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/2c0ddbaa Branch: refs/heads/master Commit: 2c0ddbaa8bb631f6ecf96cc3f046b4dd63df6e00 Parents: 78f8466 Author: Jie Yu <yujie....@gmail.com> Authored: Thu Nov 3 16:59:26 2016 -0700 Committer: Jie Yu <yujie....@gmail.com> Committed: Mon Nov 7 16:28:11 2016 -0800 ---------------------------------------------------------------------- include/mesos/mesos.proto | 2 + include/mesos/v1/mesos.proto | 2 + src/slave/containerizer/mesos/containerizer.cpp | 1 + .../containerizer/mesos_containerizer_tests.cpp | 56 ++++++++++++++++++++ 4 files changed, 61 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/2c0ddbaa/include/mesos/mesos.proto ---------------------------------------------------------------------- diff --git a/include/mesos/mesos.proto b/include/mesos/mesos.proto index 2e781ff..3805759 100644 --- a/include/mesos/mesos.proto +++ b/include/mesos/mesos.proto @@ -2207,6 +2207,8 @@ message ContainerInfo { * TaskStatus message. */ message ContainerStatus { + optional ContainerID container_id = 4; + // This field can be reliably used to identify the container IP address. repeated NetworkInfo network_infos = 1; http://git-wip-us.apache.org/repos/asf/mesos/blob/2c0ddbaa/include/mesos/v1/mesos.proto ---------------------------------------------------------------------- diff --git a/include/mesos/v1/mesos.proto b/include/mesos/v1/mesos.proto index 6eea669..5b542ff 100644 --- a/include/mesos/v1/mesos.proto +++ b/include/mesos/v1/mesos.proto @@ -2206,6 +2206,8 @@ message ContainerInfo { * TaskStatus message. */ message ContainerStatus { + optional ContainerID container_id = 4; + // This field can be reliably used to identify the container IP address. repeated NetworkInfo network_infos = 1; http://git-wip-us.apache.org/repos/asf/mesos/blob/2c0ddbaa/src/slave/containerizer/mesos/containerizer.cpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/mesos/containerizer.cpp b/src/slave/containerizer/mesos/containerizer.cpp index c9ec92f..32fba76 100644 --- a/src/slave/containerizer/mesos/containerizer.cpp +++ b/src/slave/containerizer/mesos/containerizer.cpp @@ -1906,6 +1906,7 @@ Future<ContainerStatus> MesosContainerizerProcess::status( return await(futures) .then([containerId](const list<Future<ContainerStatus>>& statuses) { ContainerStatus result; + result.mutable_container_id()->CopyFrom(containerId); foreach (const Future<ContainerStatus>& status, statuses) { if (status.isReady()) { http://git-wip-us.apache.org/repos/asf/mesos/blob/2c0ddbaa/src/tests/containerizer/mesos_containerizer_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/containerizer/mesos_containerizer_tests.cpp b/src/tests/containerizer/mesos_containerizer_tests.cpp index a003111..8cb7d4e 100644 --- a/src/tests/containerizer/mesos_containerizer_tests.cpp +++ b/src/tests/containerizer/mesos_containerizer_tests.cpp @@ -199,6 +199,62 @@ TEST_F(MesosContainerizerTest, Destroy) } +// This test verifies that ContainerID is properly set in the +// ContainerStatus returned from 'status()' method. +TEST_F(MesosContainerizerTest, StatusWithContainerID) +{ + slave::Flags flags = CreateSlaveFlags(); + + Fetcher fetcher; + + Try<MesosContainerizer*> create = MesosContainerizer::create( + flags, + true, + &fetcher); + + ASSERT_SOME(create); + + Owned<MesosContainerizer> containerizer(create.get()); + + SlaveState state; + state.id = SlaveID(); + + AWAIT_READY(containerizer->recover(state)); + + ContainerID containerId; + containerId.set_value(UUID::random().toString()); + + Try<string> directory = environment->mkdtemp(); + ASSERT_SOME(directory); + + Future<bool> launch = containerizer->launch( + containerId, + None(), + createExecutorInfo("executor", "sleep 1000", "cpus:1"), + directory.get(), + None(), + SlaveID(), + map<string, string>(), + true); // TODO(benh): Ever want to test not checkpointing? + + AWAIT_ASSERT_TRUE(launch); + + Future<ContainerStatus> status = containerizer->status(containerId); + AWAIT_READY(status); + + EXPECT_EQ(containerId, status->container_id()); + + Future<Option<ContainerTermination>> wait = containerizer->wait(containerId); + + containerizer->destroy(containerId); + + AWAIT_READY(wait); + ASSERT_SOME(wait.get()); + ASSERT_TRUE(wait.get()->has_status()); + EXPECT_WTERMSIG_EQ(SIGKILL, wait.get()->status()); +} + + class MesosContainerizerIsolatorPreparationTest : public MesosTest { public: