Minor refactor for MesosContainerizer. This change moves two different pieces of code, that each iterate over list of ContainerPrepareInfos, close together for readability. It becomes even more relevant when looking at https://reviews.apache.org/r/38365/ that iterates over yet another member from ContainerPrepareInfo.
Review: https://reviews.apache.org/r/38364 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/fc541a9a Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/fc541a9a Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/fc541a9a Branch: refs/heads/master Commit: fc541a9a97eb1d86c27452019ff217eed11ed5a3 Parents: e047f7d Author: Kapil Arya <[email protected]> Authored: Wed Sep 16 17:00:55 2015 -0700 Committer: Niklas Q. Nielsen <[email protected]> Committed: Wed Sep 16 17:00:55 2015 -0700 ---------------------------------------------------------------------- src/slave/containerizer/mesos/containerizer.cpp | 38 ++++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/fc541a9a/src/slave/containerizer/mesos/containerizer.cpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/mesos/containerizer.cpp b/src/slave/containerizer/mesos/containerizer.cpp index 71f16cc..3f0d8fb 100644 --- a/src/slave/containerizer/mesos/containerizer.cpp +++ b/src/slave/containerizer/mesos/containerizer.cpp @@ -786,17 +786,31 @@ Future<bool> MesosContainerizerProcess::_launch( environment[variable.name()] = variable.value(); } - // Include any environment variables returned from - // Isolator::prepare(). + JSON::Array commandArray; foreach (const Option<ContainerPrepareInfo>& prepareInfo, prepareInfos) { - if (prepareInfo.isSome() && prepareInfo.get().has_environment()) { + if (!prepareInfo.isSome()) { + continue; + } + + // Populate the list of additional commands to be run inside the container + // context. + foreach (const CommandInfo& command, prepareInfo.get().commands()) { + commandArray.values.push_back(JSON::Protobuf(command)); + } + + // Process additional environment variables returned by isolators. + if (prepareInfo.get().has_environment()) { foreach (const Environment::Variable& variable, - prepareInfo.get().environment().variables()) { + prepareInfo.get().environment().variables()) { environment[variable.name()] = variable.value(); } } } + // TODO(jieyu): Use JSON::Array once we have generic parse support. + JSON::Object commands; + commands.values["commands"] = commandArray; + // Use a pipe to block the child until it's been isolated. int pipes[2]; @@ -814,21 +828,7 @@ Future<bool> MesosContainerizerProcess::_launch( launchFlags.user = user; launchFlags.pipe_read = pipes[0]; launchFlags.pipe_write = pipes[1]; - - // Prepare the additional prepareInfo commands. - // TODO(jieyu): Use JSON::Array once we have generic parse support. - JSON::Object object; - JSON::Array array; - foreach (const Option<ContainerPrepareInfo>& prepareInfo, prepareInfos) { - if (prepareInfo.isSome()) { - foreach (const CommandInfo& command, prepareInfo.get().commands()) { - array.values.push_back(JSON::Protobuf(command)); - } - } - } - object.values["commands"] = array; - - launchFlags.commands = object; + launchFlags.commands = commands; // TODO(karya): Create ContainerPrepareInfo.namespaces and use that instead of // Isolator::namespaces().
