You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by tn...@apache.org on 2016/04/01 01:48:18 UTC
[3/3] mesos git commit: Cleaned up the health check launcher code in
docker executor.
Cleaned up the health check launcher code in docker executor.
This change cleans up the code a bit making it easier to read:
- Bail out early wherever possible to reduce nestedness of code
making it easier to read.
- Minor cleanups around merging conditions together wherever
possible.
Review: https://reviews.apache.org/r/45557/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/4dcc8635
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/4dcc8635
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/4dcc8635
Branch: refs/heads/master
Commit: 4dcc8635e612e9a1033170dfbc1e3b562c55927a
Parents: 3b42c0b
Author: Anand Mazumdar <ma...@gmail.com>
Authored: Thu Mar 31 16:35:52 2016 -0700
Committer: Timothy Chen <tn...@apache.org>
Committed: Thu Mar 31 16:35:52 2016 -0700
----------------------------------------------------------------------
src/docker/executor.cpp | 152 +++++++++++++++++++++----------------------
1 file changed, 74 insertions(+), 78 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/4dcc8635/src/docker/executor.cpp
----------------------------------------------------------------------
diff --git a/src/docker/executor.cpp b/src/docker/executor.cpp
index a9ed8c2..26cc88d 100644
--- a/src/docker/executor.cpp
+++ b/src/docker/executor.cpp
@@ -373,100 +373,96 @@ private:
void launchHealthCheck(const string& containerName, const TaskInfo& task)
{
- if (!killed && task.has_health_check()) {
- HealthCheck healthCheck = task.health_check();
-
- // Wrap the original health check command in "docker exec".
- if (healthCheck.has_command()) {
- CommandInfo command = healthCheck.command();
-
- // "docker exec" require docker version greater than 1.3.0.
- Try<Nothing> validateVersion =
- docker->validateVersion(Version(1, 3, 0));
-
- if (validateVersion.isError()) {
- cerr << "Unable to launch health process: "
- << validateVersion.error() << endl;
- return;
- }
+ // Bail out early if we have been already killed or if the task has no
+ // associated health checks.
+ if (killed || !task.has_health_check()) {
+ return;
+ }
- vector<string> argv;
- argv.push_back(docker->getPath());
- argv.push_back("exec");
- argv.push_back(containerName);
+ HealthCheck healthCheck = task.health_check();
+ if (!healthCheck.has_command()) {
+ cerr << "Unable to launch health process: "
+ << "Only command health check is supported now" << endl;
+ return;
+ }
- if (command.shell()) {
- if (!command.has_value()) {
- cerr << "Unable to launch health process: "
- << "Shell command is not specified" << endl;
- return;
- }
+ // "docker exec" require docker version greater than 1.3.0.
+ Try<Nothing> validateVersion =
+ docker->validateVersion(Version(1, 3, 0));
- argv.push_back("sh");
- argv.push_back("-c");
- argv.push_back("\"");
- argv.push_back(command.value());
- argv.push_back("\"");
- } else {
- if (!command.has_value()) {
- cerr << "Unable to launch health process: "
- << "Executable path is not specified" << endl;
- return;
- }
+ if (validateVersion.isError()) {
+ cerr << "Unable to launch health process: "
+ << validateVersion.error() << endl;
+ return;
+ }
- argv.push_back(command.value());
+ // Wrap the original health check command in "docker exec".
+ const CommandInfo& command = healthCheck.command();
+ if (!command.has_value()) {
+ cerr << "Unable to launch health process: "
+ << (command.shell() ? "Shell command" : "Executable path")
+ << " is not specified" << endl;
+ return;
+ }
- foreach (const string& argument, command.arguments()) {
- argv.push_back(argument);
- }
- }
+ vector<string> argv;
+ argv.push_back(docker->getPath());
+ argv.push_back("exec");
+ argv.push_back(containerName);
+
+ if (command.shell()) {
+ argv.push_back("sh");
+ argv.push_back("-c");
+ argv.push_back("\"");
+ argv.push_back(command.value());
+ argv.push_back("\"");
+ } else {
+ argv.push_back(command.value());
- command.set_shell(true);
- command.clear_arguments();
- command.set_value(strings::join(" ", argv));
- healthCheck.mutable_command()->CopyFrom(command);
- } else {
- cerr << "Unable to launch health process: "
- << "Only command health check is supported now" << endl;
- return;
+ foreach (const string& argument, command.arguments()) {
+ argv.push_back(argument);
}
+ }
- JSON::Object json = JSON::protobuf(healthCheck);
+ healthCheck.mutable_command()->set_shell(true);
+ healthCheck.mutable_command()->clear_arguments();
+ healthCheck.mutable_command()->set_value(strings::join(" ", argv));
- const string path = path::join(healthCheckDir, "mesos-health-check");
+ JSON::Object json = JSON::protobuf(healthCheck);
- // Launch the subprocess using 'exec' style so that quotes can
- // be properly handled.
- vector<string> argv;
- argv.push_back(path);
- argv.push_back("--executor=" + stringify(self()));
- argv.push_back("--health_check_json=" + stringify(json));
- argv.push_back("--task_id=" + task.task_id().value());
+ const string path = path::join(healthCheckDir, "mesos-health-check");
- const string cmd = strings::join(" ", argv);
+ // Launch the subprocess using 'exec' style so that quotes can
+ // be properly handled.
+ argv.push_back(path);
+ argv.push_back("--executor=" + stringify(self()));
+ argv.push_back("--health_check_json=" + stringify(json));
+ argv.push_back("--task_id=" + task.task_id().value());
- cout << "Launching health check process: " << cmd << endl;
+ const string cmd = strings::join(" ", argv);
- Try<Subprocess> healthProcess =
- process::subprocess(
- path,
- argv,
- // Intentionally not sending STDIN to avoid health check
- // commands that expect STDIN input to block.
- Subprocess::PATH("/dev/null"),
- Subprocess::FD(STDOUT_FILENO),
- Subprocess::FD(STDERR_FILENO));
+ cout << "Launching health check process: " << cmd << endl;
- if (healthProcess.isError()) {
- cerr << "Unable to launch health process: "
- << healthProcess.error() << endl;
- } else {
- healthPid = healthProcess.get().pid();
+ Try<Subprocess> healthProcess =
+ process::subprocess(
+ path,
+ argv,
+ // Intentionally not sending STDIN to avoid health check
+ // commands that expect STDIN input to block.
+ Subprocess::PATH("/dev/null"),
+ Subprocess::FD(STDOUT_FILENO),
+ Subprocess::FD(STDERR_FILENO));
- cout << "Health check process launched at pid: "
- << stringify(healthPid) << endl;
- }
+ if (healthProcess.isError()) {
+ cerr << "Unable to launch health process: "
+ << healthProcess.error() << endl;
+ return;
}
+
+ healthPid = healthProcess.get().pid();
+
+ cout << "Health check process launched at pid: "
+ << stringify(healthPid) << endl;
}
bool killed;