You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by al...@apache.org on 2017/09/04 13:45:44 UTC
mesos git commit: Improved consistency of cout/cerr and glog usage in
main functions.
Repository: mesos
Updated Branches:
refs/heads/master 7f1598bc1 -> 40aa0d9f7
Improved consistency of cout/cerr and glog usage in main functions.
The main functions now have a common initialization pattern:
1. Load flags.
2. Check if the --help flag has been passed.
3. Check if the flags are correct.
4. Initialize logging.
5. Parse and setup the environment variables.
6. Initialize libprocess.
This change reduces the number of messages "WARNING: Logging before
InitGoogleLogging() is written to STDERR" as we now use glog only after
the fourth step. This forces all glog messages to end up in a logdir.
Review: https://reviews.apache.org/r/61849/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/40aa0d9f
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/40aa0d9f
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/40aa0d9f
Branch: refs/heads/master
Commit: 40aa0d9f77ccd3264ea9e84dc5e3e49d601168b9
Parents: 7f1598b
Author: Armand Grillet <ag...@mesosphere.io>
Authored: Mon Sep 4 15:45:04 2017 +0200
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Mon Sep 4 15:45:04 2017 +0200
----------------------------------------------------------------------
src/docker/executor.cpp | 4 ++--
src/launcher/default_executor.cpp | 6 +++---
src/launcher/executor.cpp | 5 +++--
src/local/main.cpp | 20 ++++++++++----------
src/master/main.cpp | 17 ++++++++---------
src/slave/main.cpp | 17 ++++++++---------
6 files changed, 34 insertions(+), 35 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/40aa0d9f/src/docker/executor.cpp
----------------------------------------------------------------------
diff --git a/src/docker/executor.cpp b/src/docker/executor.cpp
index aff9793..59e594d 100644
--- a/src/docker/executor.cpp
+++ b/src/docker/executor.cpp
@@ -787,8 +787,6 @@ int main(int argc, char** argv)
{
GOOGLE_PROTOBUF_VERIFY_VERSION;
- process::initialize();
-
mesos::internal::docker::Flags flags;
// Load flags from environment and command line.
@@ -903,6 +901,8 @@ int main(int argc, char** argv)
EXIT(EXIT_FAILURE) << flags.usage("Missing required option --launcher_dir");
}
+ process::initialize();
+
// The 2nd argument for docker create is set to false so we skip
// validation when creating a docker abstraction, as the slave
// should have already validated docker.
http://git-wip-us.apache.org/repos/asf/mesos/blob/40aa0d9f/src/launcher/default_executor.cpp
----------------------------------------------------------------------
diff --git a/src/launcher/default_executor.cpp b/src/launcher/default_executor.cpp
index 30bae5c..106b7f2 100644
--- a/src/launcher/default_executor.cpp
+++ b/src/launcher/default_executor.cpp
@@ -1467,14 +1467,12 @@ public:
int main(int argc, char** argv)
{
- process::initialize();
-
- Flags flags;
mesos::FrameworkID frameworkId;
mesos::ExecutorID executorId;
string scheme = "http"; // Default scheme.
::URL agent;
string sandboxDirectory;
+ Flags flags;
// Load flags from command line.
Try<flags::Warnings> load = flags.load(None(), &argc, &argv);
@@ -1529,6 +1527,8 @@ int main(int argc, char** argv)
<< "Expecting 'MESOS_SLAVE_PID' to be set in the environment";
}
+ process::initialize();
+
UPID upid(value.get());
CHECK(upid) << "Failed to parse MESOS_SLAVE_PID '" << value.get() << "'";
http://git-wip-us.apache.org/repos/asf/mesos/blob/40aa0d9f/src/launcher/executor.cpp
----------------------------------------------------------------------
diff --git a/src/launcher/executor.cpp b/src/launcher/executor.cpp
index 65b9a2c..951597b 100644
--- a/src/launcher/executor.cpp
+++ b/src/launcher/executor.cpp
@@ -1209,11 +1209,10 @@ public:
int main(int argc, char** argv)
{
- Flags flags;
mesos::FrameworkID frameworkId;
mesos::ExecutorID executorId;
- process::initialize();
+ Flags flags;
// Load flags from command line.
Try<flags::Warnings> load = flags.load(None(), &argc, &argv);
@@ -1268,6 +1267,8 @@ int main(int argc, char** argv)
shutdownGracePeriod = parse.get();
}
+ process::initialize();
+
Owned<mesos::internal::CommandExecutor> executor(
new mesos::internal::CommandExecutor(
flags.launcher_dir,
http://git-wip-us.apache.org/repos/asf/mesos/blob/40aa0d9f/src/local/main.cpp
----------------------------------------------------------------------
diff --git a/src/local/main.cpp b/src/local/main.cpp
index f0d7e8c..f6145b7 100644
--- a/src/local/main.cpp
+++ b/src/local/main.cpp
@@ -81,14 +81,21 @@ int main(int argc, char **argv)
// flags since we might have some master/slave flags as well.
Try<flags::Warnings> load = flags.load("MESOS_", argc, argv, true);
+ if (flags.help) {
+ cout << flags.usage() << endl;
+ return EXIT_SUCCESS;
+ }
+
if (load.isError()) {
cerr << flags.usage(load.error()) << endl;
return EXIT_FAILURE;
}
- if (flags.help) {
- cout << flags.usage() << endl;
- return EXIT_SUCCESS;
+ logging::initialize(argv[0], flags);
+
+ // Log any flag warnings (after logging is initialized).
+ foreach (const flags::Warning& warning, load->warnings) {
+ LOG(WARNING) << warning.message;
}
// Initialize libprocess.
@@ -100,13 +107,6 @@ int main(int argc, char **argv)
process::initialize("master");
- logging::initialize(argv[0], flags);
-
- // Log any flag warnings (after logging is initialized).
- foreach (const flags::Warning& warning, load->warnings) {
- LOG(WARNING) << warning.message;
- }
-
spawn(new VersionProcess(), true);
process::wait(local::launch(flags));
http://git-wip-us.apache.org/repos/asf/mesos/blob/40aa0d9f/src/master/main.cpp
----------------------------------------------------------------------
diff --git a/src/master/main.cpp b/src/master/main.cpp
index 1a78a55..7e815bf 100644
--- a/src/master/main.cpp
+++ b/src/master/main.cpp
@@ -133,9 +133,9 @@ int main(int argc, char** argv)
{
// The order of initialization of various master components is as follows:
// * Validate flags.
+ // * Logging.
// * Log build information.
// * Libprocess.
- // * Logging.
// * Version process.
// * Firewall rules: should be initialized before initializing HTTP endpoints.
// * Modules: Load module libraries and manifests before they
@@ -176,6 +176,13 @@ int main(int argc, char** argv)
return EXIT_FAILURE;
}
+ logging::initialize(argv[0], flags, true); // Catch signals.
+
+ // Log any flag warnings (after logging is initialized).
+ foreach (const flags::Warning& warning, load->warnings) {
+ LOG(WARNING) << warning.message;
+ }
+
// Check that master's version has the expected format (SemVer).
{
Try<Version> version = Version::parse(MESOS_VERSION);
@@ -252,14 +259,6 @@ int main(int argc, char** argv)
<< "`main()` was not the function's first invocation";
}
- // TODO(alexr): This should happen before we start using glog, see MESOS-7586.
- logging::initialize(argv[0], flags, true); // Catch signals.
-
- // Log any flag warnings (after logging is initialized).
- foreach (const flags::Warning& warning, load->warnings) {
- LOG(WARNING) << warning.message;
- }
-
spawn(new VersionProcess(), true);
// Initialize firewall rules.
http://git-wip-us.apache.org/repos/asf/mesos/blob/40aa0d9f/src/slave/main.cpp
----------------------------------------------------------------------
diff --git a/src/slave/main.cpp b/src/slave/main.cpp
index b8e275c..d53ff50 100644
--- a/src/slave/main.cpp
+++ b/src/slave/main.cpp
@@ -224,9 +224,9 @@ int main(int argc, char** argv)
// The order of initialization is as follows:
// * Windows socket stack.
// * Validate flags.
+ // * Logging
// * Log build information.
// * Libprocess
- // * Logging
// * Version process
// * Firewall rules: should be initialized before initializing HTTP endpoints.
// * Modules: Load module libraries and manifests before they
@@ -268,6 +268,13 @@ int main(int argc, char** argv)
return EXIT_FAILURE;
}
+ logging::initialize(argv[0], flags, true); // Catch signals.
+
+ // Log any flag warnings (after logging is initialized).
+ foreach (const flags::Warning& warning, load->warnings) {
+ LOG(WARNING) << warning.message;
+ }
+
// Check that agent's version has the expected format (SemVer).
{
Try<Version> version = Version::parse(MESOS_VERSION);
@@ -378,14 +385,6 @@ int main(int argc, char** argv)
<< "`main()` was not the function's first invocation";
}
- // TODO(alexr): This should happen before we start using glog, see MESOS-7586.
- logging::initialize(argv[0], flags, true); // Catch signals.
-
- // Log any flag warnings (after logging is initialized).
- foreach (const flags::Warning& warning, load->warnings) {
- LOG(WARNING) << warning.message;
- }
-
spawn(new VersionProcess(), true);
if (flags.firewall_rules.isSome()) {