You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2016/07/04 17:01:35 UTC
[14/15] mesos git commit: Simplified a flag in the launch helper
binary.
Simplified a flag in the launch helper binary.
Using JSON::Object is not necessary. Also, the current name is quite
confusing as we have another flag called '--command'. This patch
simplified this flag.
Review: https://reviews.apache.org/r/49568
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/772cf400
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/772cf400
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/772cf400
Branch: refs/heads/master
Commit: 772cf4007745680a39c4a7bbf820397b194995d2
Parents: 9062dbc
Author: Jie Yu <yu...@gmail.com>
Authored: Sat Jul 2 21:49:22 2016 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Mon Jul 4 10:01:13 2016 -0700
----------------------------------------------------------------------
src/slave/containerizer/mesos/containerizer.cpp | 10 +++-------
src/slave/containerizer/mesos/launch.cpp | 19 ++++---------------
src/slave/containerizer/mesos/launch.hpp | 2 +-
src/tests/containerizer/port_mapping_tests.cpp | 8 +++-----
4 files changed, 11 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/772cf400/src/slave/containerizer/mesos/containerizer.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/containerizer.cpp b/src/slave/containerizer/mesos/containerizer.cpp
index 4fa10a9..856dd82 100644
--- a/src/slave/containerizer/mesos/containerizer.cpp
+++ b/src/slave/containerizer/mesos/containerizer.cpp
@@ -1163,7 +1163,7 @@ Future<bool> MesosContainerizerProcess::__launch(
environment[variable.name()] = variable.value();
}
- JSON::Array commandArray;
+ JSON::Array preExecCommands;
// TODO(jieyu): We should use Option here. If no namespace is
// required, we should pass None() to 'launcher->fork'.
@@ -1177,7 +1177,7 @@ Future<bool> MesosContainerizerProcess::__launch(
// Populate the list of additional commands to be run inside the container
// context.
foreach (const CommandInfo& command, launchInfo->commands()) {
- commandArray.values.emplace_back(JSON::protobuf(command));
+ preExecCommands.values.emplace_back(JSON::protobuf(command));
}
// Process additional environment variables returned by isolators.
@@ -1193,10 +1193,6 @@ Future<bool> MesosContainerizerProcess::__launch(
}
}
- // TODO(jieyu): Use JSON::Array once we have generic parse support.
- JSON::Object commands;
- commands.values["commands"] = commandArray;
-
if (executorLaunchCommand.isNone()) {
executorLaunchCommand = executorInfo.command();
}
@@ -1269,7 +1265,7 @@ Future<bool> MesosContainerizerProcess::__launch(
launchFlags.pipe_read = os::fd_to_handle(pipes[0]);
launchFlags.pipe_write = os::fd_to_handle(pipes[1]);
#endif // __WINDOWS
- launchFlags.commands = commands;
+ launchFlags.pre_exec_commands = preExecCommands;
VLOG(1) << "Launching '" << MESOS_CONTAINERIZER << "' with flags '"
<< launchFlags << "'";
http://git-wip-us.apache.org/repos/asf/mesos/blob/772cf400/src/slave/containerizer/mesos/launch.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/launch.cpp b/src/slave/containerizer/mesos/launch.cpp
index 4e52807..80234aa 100644
--- a/src/slave/containerizer/mesos/launch.cpp
+++ b/src/slave/containerizer/mesos/launch.cpp
@@ -83,8 +83,8 @@ MesosContainerizerLaunch::Flags::Flags()
"properly in the subprocess. It's used to synchronize with the \n"
"parent process. If not specified, no synchronization will happen.");
- add(&commands,
- "commands",
+ add(&pre_exec_commands,
+ "pre_exec_commands",
"The additional preparation commands to execute before\n"
"executing the command.");
}
@@ -171,20 +171,9 @@ int MesosContainerizerLaunch::execute()
// Run additional preparation commands. These are run as the same
// user and with the environment as the agent.
- if (flags.commands.isSome()) {
+ if (flags.pre_exec_commands.isSome()) {
// TODO(jieyu): Use JSON::Array if we have generic parse support.
- JSON::Object object = flags.commands.get();
- if (object.values.count("commands") == 0) {
- cerr << "Invalid JSON format for flag --commands" << endl;
- return 1;
- }
-
- if (!object.values["commands"].is<JSON::Array>()) {
- cerr << "Invalid JSON format for flag --commands" << endl;
- return 1;
- }
-
- JSON::Array array = object.values["commands"].as<JSON::Array>();
+ JSON::Array array = flags.pre_exec_commands.get();
foreach (const JSON::Value& value, array.values) {
if (!value.is<JSON::Object>()) {
cerr << "Invalid JSON format for flag --commands" << endl;
http://git-wip-us.apache.org/repos/asf/mesos/blob/772cf400/src/slave/containerizer/mesos/launch.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/launch.hpp b/src/slave/containerizer/mesos/launch.hpp
index 72b99ad..c6bba37 100644
--- a/src/slave/containerizer/mesos/launch.hpp
+++ b/src/slave/containerizer/mesos/launch.hpp
@@ -42,7 +42,7 @@ public:
#endif // __WINDOWS__
Option<int> pipe_read;
Option<int> pipe_write;
- Option<JSON::Object> commands; // Additional preparation commands.
+ Option<JSON::Array> pre_exec_commands;
};
MesosContainerizerLaunch() : Subcommand(NAME) {}
http://git-wip-us.apache.org/repos/asf/mesos/blob/772cf400/src/tests/containerizer/port_mapping_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/port_mapping_tests.cpp b/src/tests/containerizer/port_mapping_tests.cpp
index b34d5b0..eeb8938 100644
--- a/src/tests/containerizer/port_mapping_tests.cpp
+++ b/src/tests/containerizer/port_mapping_tests.cpp
@@ -327,12 +327,10 @@ protected:
return Error("No valid commands inside ContainerLaunchInfo.");
}
- JSON::Object commands;
- JSON::Array array;
- array.values.push_back(JSON::protobuf(launchInfo->commands(0)));
- commands.values["commands"] = array;
+ JSON::Array preExecCommands;
+ preExecCommands.values.push_back(JSON::protobuf(launchInfo->commands(0)));
- launchFlags.commands = commands;
+ launchFlags.pre_exec_commands = preExecCommands;
vector<string> argv(2);
argv[0] = MESOS_CONTAINERIZER;