Supported `ContainerLogger` with nested containers.
authorGilbert Song <songzihao1990@gmail.com>
Wed, 12 Oct 2016 21:38:43 +0000 (14:38 -0700)
committerJoseph Wu <josephwu@apache.org>
Wed, 12 Oct 2016 21:41:30 +0000 (14:41 -0700)
For nested containers, the sandbox directory still exists.  However,
ExecutorInfo's no longer map directly one-to-one to containers.
That means a nested container does not have an associated ExecutorInfo.

The `ExecutorInfo` parameter provides metadata for the `ContainerLogger`
including the FrameworkID, ExecutorID, environment variables, and
arbitrary Labels.  For nested containers, the top-level parent's
`ExecutorInfo` should be sufficient to provide the same metadata.

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

src/slave/containerizer/mesos/containerizer.cpp

index 7ec6f78..f5a4858 100644 (file)
@@ -1333,8 +1333,27 @@ Future<bool> MesosContainerizerProcess::_launch(
     environment.values[name] = value;
   }
 
+  // Determine the 'ExecutorInfo' for the logger. If launching a
+  // top level executor container, use the 'ExecutorInfo' from
+  // 'ContainerConfig'. If launching a nested container, use the
+  // 'ExecutorInfo' from its top level parent container.
+  ExecutorInfo executorInfo;
+  if (container->config.has_executor_info()) {
+    // The top level executor container case. The 'ExecutorInfo'
+    // will always be set in 'ContainerConfig'.
+    executorInfo = container->config.executor_info();
+  } else {
+    // The nested container case. Use the 'ExecutorInfo' from its root
+    // parent container.
+    CHECK(containerId.has_parent());
+    const ContainerID& rootContainerId = getRootContainerId(containerId);
+    CHECK(containers_.contains(rootContainerId));
+    CHECK(containers_[rootContainerId]->config.has_executor_info());
+    executorInfo = containers_[rootContainerId]->config.executor_info();
+  }
+
   return logger->prepare(
-      container->config.executor_info(),
+      executorInfo,
       container->config.directory())
     .then(defer(
         self(),