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 2015/06/04 20:11:41 UTC
[1/3] mesos git commit: Update callers of os::getenv() in libprocess.
Repository: mesos
Updated Branches:
refs/heads/master c394e1415 -> 7b99908da
Update callers of os::getenv() in libprocess.
Review: https://reviews.apache.org/r/34318
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/7b99908d
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/7b99908d
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/7b99908d
Branch: refs/heads/master
Commit: 7b99908da118fbc644f26ff204d546c0348b2c1f
Parents: dc21646
Author: Greg Mann <Gr...@gmail.com>
Authored: Thu Jun 4 10:52:56 2015 -0700
Committer: Timothy Chen <tn...@apache.org>
Committed: Thu Jun 4 11:11:30 2015 -0700
----------------------------------------------------------------------
3rdparty/libprocess/src/process.cpp | 26 ++++++++++++--------------
3rdparty/libprocess/src/profiler.cpp | 5 ++++-
2 files changed, 16 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/7b99908d/3rdparty/libprocess/src/process.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/process.cpp b/3rdparty/libprocess/src/process.cpp
index f1d3e5b..d1b4d46 100644
--- a/3rdparty/libprocess/src/process.cpp
+++ b/3rdparty/libprocess/src/process.cpp
@@ -774,25 +774,23 @@ void initialize(const string& delegate)
__address__ = Address::LOCALHOST_ANY();
- char* value;
-
// Check environment for ip.
- value = getenv("LIBPROCESS_IP");
- if (value != NULL) {
- Try<net::IP> ip = net::IP::parse(value, AF_INET);
+ Option<string> value = os::getenv("LIBPROCESS_IP");
+ if (value.isSome()) {
+ Try<net::IP> ip = net::IP::parse(value.get(), AF_INET);
if (ip.isError()) {
- LOG(FATAL) << "Parsing LIBPROCESS_IP=" << value
+ LOG(FATAL) << "Parsing LIBPROCESS_IP=" << value.get()
<< " failed: " << ip.error();
}
__address__.ip = ip.get();
}
// Check environment for port.
- value = getenv("LIBPROCESS_PORT");
- if (value != NULL) {
- int result = atoi(value);
+ value = os::getenv("LIBPROCESS_PORT");
+ if (value.isSome()) {
+ const int result = atoi(value.get().c_str());
if (result < 0 || result > USHRT_MAX) {
- LOG(FATAL) << "LIBPROCESS_PORT=" << value << " is not a valid port";
+ LOG(FATAL) << "LIBPROCESS_PORT=" << value.get() << " is not a valid port";
}
__address__.port = result;
}
@@ -872,11 +870,11 @@ void initialize(const string& delegate)
// Create the global statistics.
// TODO(dhamon): Plumb this through to metrics.
- // value = getenv("LIBPROCESS_STATISTICS_WINDOW");
- // if (value != NULL) {
- // Try<Duration> window = Duration::parse(string(value));
+ // value = os::getenv("LIBPROCESS_STATISTICS_WINDOW");
+ // if (value.isSome()) {
+ // Try<Duration> window = Duration::parse(value.get());
// if (window.isError()) {
- // LOG(FATAL) << "LIBPROCESS_STATISTICS_WINDOW=" << value
+ // LOG(FATAL) << "LIBPROCESS_STATISTICS_WINDOW=" << value.get()
// << " is not a valid duration: " << window.error();
// }
// statistics = new Statistics(window.get());
http://git-wip-us.apache.org/repos/asf/mesos/blob/7b99908d/3rdparty/libprocess/src/profiler.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/profiler.cpp b/3rdparty/libprocess/src/profiler.cpp
index fe00aa5..2159576 100644
--- a/3rdparty/libprocess/src/profiler.cpp
+++ b/3rdparty/libprocess/src/profiler.cpp
@@ -12,6 +12,7 @@
#include "process/profiler.hpp"
#include "stout/format.hpp"
+#include "stout/option.hpp"
#include "stout/os.hpp"
namespace process {
@@ -57,7 +58,9 @@ const std::string Profiler::STOP_HELP()
Future<http::Response> Profiler::start(const http::Request& request)
{
#ifdef HAS_GPERFTOOLS
- if (os::getenv("LIBPROCESS_ENABLE_PROFILER", false) != "1") {
+ const Option<std::string>
+ enableProfiler = os::getenv("LIBPROCESS_ENABLE_PROFILER");
+ if (enableProfiler.isNone() || enableProfiler.get() != "1") {
return http::BadRequest(
"The profiler is not enabled. To enable the profiler, libprocess "
"must be started with LIBPROCESS_ENABLE_PROFILER=1 in the "
[2/3] mesos git commit: Updated callers of os::getenv() and removed
calls to os::hasenv().
Posted by tn...@apache.org.
Updated callers of os::getenv() and removed calls to os::hasenv().
Review: https://reviews.apache.org/r/34317
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/dc216463
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/dc216463
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/dc216463
Branch: refs/heads/master
Commit: dc2164631ba4dd4e104370a1cb1ca3812cba1d99
Parents: 2a74bcb
Author: Greg Mann <Gr...@gmail.com>
Authored: Thu Jun 4 10:52:26 2015 -0700
Committer: Timothy Chen <tn...@apache.org>
Committed: Thu Jun 4 11:11:30 2015 -0700
----------------------------------------------------------------------
src/cli/mesos.cpp | 39 +++++++++-----
src/examples/balloon_framework.cpp | 36 ++++++++-----
src/examples/docker_no_executor_framework.cpp | 22 ++++----
src/examples/load_generator_framework.cpp | 6 ++-
src/examples/long_lived_framework.cpp | 36 ++++++++-----
src/examples/low_level_scheduler_libprocess.cpp | 36 ++++++++-----
src/examples/low_level_scheduler_pthread.cpp | 35 ++++++++-----
src/examples/no_executor_framework.cpp | 25 +++++----
src/examples/test_framework.cpp | 35 ++++++++-----
src/exec/exec.cpp | 55 +++++++++++---------
src/hdfs/hdfs.hpp | 8 +--
src/jvm/jvm.cpp | 7 +--
src/launcher/executor.cpp | 7 ++-
src/launcher/fetcher.cpp | 8 +--
src/slave/containerizer/containerizer.cpp | 5 +-
src/slave/containerizer/docker.cpp | 5 +-
src/tests/anonymous_tests.cpp | 2 +-
src/tests/environment.cpp | 2 +-
18 files changed, 221 insertions(+), 148 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/dc216463/src/cli/mesos.cpp
----------------------------------------------------------------------
diff --git a/src/cli/mesos.cpp b/src/cli/mesos.cpp
index 1121e19..bb92b68 100644
--- a/src/cli/mesos.cpp
+++ b/src/cli/mesos.cpp
@@ -3,6 +3,7 @@
#include <iostream>
#include <list>
+#include <stout/option.hpp>
#include <stout/os.hpp>
#include <stout/path.hpp>
#include <stout/strings.hpp>
@@ -18,19 +19,21 @@ using std::string;
void usage(const char* argv0)
{
// Get a list of available commands.
- const string& PATH = os::getenv("PATH");
+ const Option<string> PATH = os::getenv("PATH");
list<string> commands;
- foreach (const string& path, strings::split(PATH, ":")) {
- Try<list<string> > matches = os::glob(path::join(path, "mesos-*"));
- if (matches.isSome()) {
- foreach (const string& match, matches.get()) {
- Try<bool> access = os::access(match, X_OK);
- if (access.isSome() && access.get()) {
- Try<string> basename = os::basename(match);
- if (basename.isSome()) {
- commands.push_back(basename.get().substr(6));
+ if (PATH.isSome()) {
+ foreach (const string& path, strings::split(PATH.get(), ":")) {
+ Try<list<string> > matches = os::glob(path::join(path, "mesos-*"));
+ if (matches.isSome()) {
+ foreach (const string& match, matches.get()) {
+ Try<bool> access = os::access(match, X_OK);
+ if (access.isSome() && access.get()) {
+ Try<string> basename = os::basename(match);
+ if (basename.isSome()) {
+ commands.push_back(basename.get().substr(6));
+ }
}
}
}
@@ -52,6 +55,8 @@ void usage(const char* argv0)
int main(int argc, char** argv)
{
+ Option<string> value;
+
// Try and add the absolute dirname of argv[0] to PATH so we can
// find commands (since our installation directory might not be on
// the path).
@@ -59,7 +64,12 @@ int main(int argc, char** argv)
if (dirname.isSome()) {
Result<string> realpath = os::realpath(dirname.get());
if (realpath.isSome()) {
- os::setenv("PATH", realpath.get() + ":" + os::getenv("PATH"));
+ value = os::getenv("PATH");
+ if (value.isSome()) {
+ os::setenv("PATH", realpath.get() + ":" + value.get());
+ } else {
+ os::setenv("PATH", realpath.get());
+ }
}
}
@@ -72,7 +82,12 @@ int main(int argc, char** argv)
// TODO(benh): Remove this if/when we install the 'mesos' module via
// PIP and setuptools.
string path = path::join(PKGLIBEXECDIR, "python");
- os::setenv("PYTHONPATH", os::getenv("PYTHONPATH", false) + ":" + path);
+ value = os::getenv("PYTHONPATH");
+ if (value.isSome()) {
+ os::setenv("PYTHONPATH", value.get() + ":" + path);
+ } else {
+ os::setenv("PYTHONPATH", path);
+ }
// Now dispatch to any mesos-'command' on PATH.
if (string(argv[1]) == "help") {
http://git-wip-us.apache.org/repos/asf/mesos/blob/dc216463/src/examples/balloon_framework.cpp
----------------------------------------------------------------------
diff --git a/src/examples/balloon_framework.cpp b/src/examples/balloon_framework.cpp
index c2337ba..1eb5945 100644
--- a/src/examples/balloon_framework.cpp
+++ b/src/examples/balloon_framework.cpp
@@ -29,6 +29,7 @@
#include <mesos/scheduler.hpp>
#include <stout/numify.hpp>
+#include <stout/option.hpp>
#include <stout/os.hpp>
#include <stout/stringify.hpp>
@@ -200,10 +201,12 @@ int main(int argc, char** argv)
}
// Find this executable's directory to locate executor.
- std::string path = os::realpath(::dirname(argv[0])).get();
- std::string uri = path + "/balloon-executor";
- if (getenv("MESOS_BUILD_DIR")) {
- uri = std::string(::getenv("MESOS_BUILD_DIR")) + "/src/balloon-executor";
+ string uri;
+ Option<string> value = os::getenv("MESOS_BUILD_DIR");
+ if (value.isSome()) {
+ uri = path::join(value.get(), "src", "balloon-executor");
+ } else {
+ uri = path::join(os::realpath(dirname(argv[0])).get(), "balloon-executor");
}
ExecutorInfo executor;
@@ -223,28 +226,33 @@ int main(int argc, char** argv)
framework.set_user(""); // Have Mesos fill in the current user.
framework.set_name("Balloon Framework (C++)");
- if (os::hasenv("MESOS_CHECKPOINT")) {
+ value = os::getenv("MESOS_CHECKPOINT");
+ if (value.isSome()) {
framework.set_checkpoint(
- numify<bool>(os::getenv("MESOS_CHECKPOINT")).get());
+ numify<bool>(value.get()).get());
}
MesosSchedulerDriver* driver;
- if (os::hasenv("MESOS_AUTHENTICATE")) {
+ value = os::getenv("MESOS_AUTHENTICATE");
+ if (value.isSome()) {
cout << "Enabling authentication for the framework" << endl;
- if (!os::hasenv("DEFAULT_PRINCIPAL")) {
+ value = os::getenv("DEFAULT_PRINCIPAL");
+ if (value.isNone()) {
EXIT(1) << "Expecting authentication principal in the environment";
}
- if (!os::hasenv("DEFAULT_SECRET")) {
+ Credential credential;
+ credential.set_principal(value.get());
+
+ framework.set_principal(value.get());
+
+ value = os::getenv("DEFAULT_SECRET");
+ if (value.isNone()) {
EXIT(1) << "Expecting authentication secret in the environment";
}
- Credential credential;
- credential.set_principal(getenv("DEFAULT_PRINCIPAL"));
- credential.set_secret(getenv("DEFAULT_SECRET"));
-
- framework.set_principal(getenv("DEFAULT_PRINCIPAL"));
+ credential.set_secret(value.get());
driver = new MesosSchedulerDriver(
&scheduler, framework, argv[1], credential);
http://git-wip-us.apache.org/repos/asf/mesos/blob/dc216463/src/examples/docker_no_executor_framework.cpp
----------------------------------------------------------------------
diff --git a/src/examples/docker_no_executor_framework.cpp b/src/examples/docker_no_executor_framework.cpp
index df8b910..7993fcd 100644
--- a/src/examples/docker_no_executor_framework.cpp
+++ b/src/examples/docker_no_executor_framework.cpp
@@ -26,6 +26,7 @@
#include <mesos/scheduler.hpp>
#include <stout/exit.hpp>
+#include <stout/option.hpp>
#include <stout/os.hpp>
using namespace mesos;
@@ -185,28 +186,31 @@ int main(int argc, char** argv)
// TODO(vinod): Make checkpointing the default when it is default
// on the slave.
- if (os::hasenv("MESOS_CHECKPOINT")) {
+ if (os::getenv("MESOS_CHECKPOINT").isSome()) {
cout << "Enabling checkpoint for the framework" << endl;
framework.set_checkpoint(true);
}
MesosSchedulerDriver* driver;
- if (os::hasenv("MESOS_AUTHENTICATE")) {
+ if (os::getenv("MESOS_AUTHENTICATE").isSome()) {
cout << "Enabling authentication for the framework" << endl;
- if (!os::hasenv("DEFAULT_PRINCIPAL")) {
+ Option<string> value = os::getenv("DEFAULT_PRINCIPAL");
+ if (value.isNone()) {
EXIT(1) << "Expecting authentication principal in the environment";
}
- if (!os::hasenv("DEFAULT_SECRET")) {
+ Credential credential;
+ credential.set_principal(value.get());
+
+ framework.set_principal(value.get());
+
+ value = os::getenv("DEFAULT_SECRET");
+ if (value.isNone()) {
EXIT(1) << "Expecting authentication secret in the environment";
}
- Credential credential;
- credential.set_principal(getenv("DEFAULT_PRINCIPAL"));
- credential.set_secret(getenv("DEFAULT_SECRET"));
-
- framework.set_principal(getenv("DEFAULT_PRINCIPAL"));
+ credential.set_secret(value.get());
driver = new MesosSchedulerDriver(
&scheduler, framework, argv[1], credential);
http://git-wip-us.apache.org/repos/asf/mesos/blob/dc216463/src/examples/load_generator_framework.cpp
----------------------------------------------------------------------
diff --git a/src/examples/load_generator_framework.cpp b/src/examples/load_generator_framework.cpp
index 6e83308..725478f 100644
--- a/src/examples/load_generator_framework.cpp
+++ b/src/examples/load_generator_framework.cpp
@@ -26,6 +26,7 @@
#include <process/timeout.hpp>
#include <stout/numify.hpp>
+#include <stout/option.hpp>
#include <stout/os.hpp>
#include <stout/stopwatch.hpp>
#include <stout/strings.hpp>
@@ -321,9 +322,10 @@ int main(int argc, char** argv)
framework.set_user(""); // Have Mesos fill in the current user.
framework.set_name("Load Generator Framework (C++)");
- if (os::hasenv("MESOS_CHECKPOINT")) {
+ const Option<string> checkpoint = os::getenv("MESOS_CHECKPOINT");
+ if (checkpoint.isSome()) {
framework.set_checkpoint(
- numify<bool>(os::getenv("MESOS_CHECKPOINT")).get());
+ numify<bool>(checkpoint.get()).get());
}
MesosSchedulerDriver* driver;
http://git-wip-us.apache.org/repos/asf/mesos/blob/dc216463/src/examples/long_lived_framework.cpp
----------------------------------------------------------------------
diff --git a/src/examples/long_lived_framework.cpp b/src/examples/long_lived_framework.cpp
index d1d577e..3f2ebe0 100644
--- a/src/examples/long_lived_framework.cpp
+++ b/src/examples/long_lived_framework.cpp
@@ -26,6 +26,7 @@
#include <mesos/scheduler.hpp>
#include <stout/numify.hpp>
+#include <stout/option.hpp>
#include <stout/os.hpp>
#include <stout/stringify.hpp>
@@ -161,10 +162,13 @@ int main(int argc, char** argv)
}
// Find this executable's directory to locate executor.
- string path = os::realpath(dirname(argv[0])).get();
- string uri = path + "/long-lived-executor";
- if (getenv("MESOS_BUILD_DIR")) {
- uri = string(getenv("MESOS_BUILD_DIR")) + "/src/long-lived-executor";
+ string uri;
+ Option<string> value = os::getenv("MESOS_BUILD_DIR");
+ if (value.isSome()) {
+ uri = path::join(value.get(), "src", "long-lived-executor");
+ } else {
+ uri =
+ path::join(os::realpath(dirname(argv[0])).get(), "long-lived-executor");
}
ExecutorInfo executor;
@@ -179,28 +183,32 @@ int main(int argc, char** argv)
framework.set_user(""); // Have Mesos fill in the current user.
framework.set_name("Long Lived Framework (C++)");
- if (os::hasenv("MESOS_CHECKPOINT")) {
+ value = os::getenv("MESOS_CHECKPOINT");
+ if (value.isSome()) {
framework.set_checkpoint(
- numify<bool>(os::getenv("MESOS_CHECKPOINT")).get());
+ numify<bool>(value.get()).get());
}
MesosSchedulerDriver* driver;
- if (os::hasenv("MESOS_AUTHENTICATE")) {
+ if (os::getenv("MESOS_AUTHENTICATE").isSome()) {
cout << "Enabling authentication for the framework" << endl;
- if (!os::hasenv("DEFAULT_PRINCIPAL")) {
+ value = os::getenv("DEFAULT_PRINCIPAL");
+ if (value.isNone()) {
EXIT(1) << "Expecting authentication principal in the environment";
}
- if (!os::hasenv("DEFAULT_SECRET")) {
+ Credential credential;
+ credential.set_principal(value.get());
+
+ framework.set_principal(value.get());
+
+ value = os::getenv("DEFAULT_SECRET");
+ if (value.isNone()) {
EXIT(1) << "Expecting authentication secret in the environment";
}
- Credential credential;
- credential.set_principal(getenv("DEFAULT_PRINCIPAL"));
- credential.set_secret(getenv("DEFAULT_SECRET"));
-
- framework.set_principal(getenv("DEFAULT_PRINCIPAL"));
+ credential.set_secret(value.get());
driver = new MesosSchedulerDriver(
&scheduler, framework, argv[1], credential);
http://git-wip-us.apache.org/repos/asf/mesos/blob/dc216463/src/examples/low_level_scheduler_libprocess.cpp
----------------------------------------------------------------------
diff --git a/src/examples/low_level_scheduler_libprocess.cpp b/src/examples/low_level_scheduler_libprocess.cpp
index df92e8d..fe4eb29 100644
--- a/src/examples/low_level_scheduler_libprocess.cpp
+++ b/src/examples/low_level_scheduler_libprocess.cpp
@@ -42,6 +42,7 @@
#include <stout/numify.hpp>
#include <stout/option.hpp>
#include <stout/os.hpp>
+#include <stout/option.hpp>
#include <stout/stringify.hpp>
#include "common/status_utils.hpp"
@@ -344,10 +345,13 @@ void usage(const char* argv0, const flags::FlagsBase& flags)
int main(int argc, char** argv)
{
// Find this executable's directory to locate executor.
- string uri =
- path::join(os::realpath(dirname(argv[0])).get(), "src", "test-executor");
- if (getenv("MESOS_BUILD_DIR")) {
- uri = path::join(os::getenv("MESOS_BUILD_DIR"), "src", "test-executor");
+ string uri;
+ Option<string> value = os::getenv("MESOS_BUILD_DIR");
+ if (value.isSome()) {
+ uri = path::join(value.get(), "src", "test-executor");
+ } else {
+ uri =
+ path::join(os::realpath(dirname(argv[0])).get(), "src", "test-executor");
}
mesos::internal::logging::Flags flags;
@@ -383,9 +387,10 @@ int main(int argc, char** argv)
framework.set_name("Low-Level Scheduler using libprocess (C++)");
framework.set_role(role);
- if (os::hasenv("MESOS_CHECKPOINT")) {
+ value = os::getenv("MESOS_CHECKPOINT");
+ if (value.isSome()) {
framework.set_checkpoint(
- numify<bool>(os::getenv("MESOS_CHECKPOINT")).get());
+ numify<bool>(value.get()).get());
}
ExecutorInfo executor;
@@ -395,22 +400,25 @@ int main(int argc, char** argv)
executor.set_source("cpp_test");
LowLevelScheduler* scheduler;
- if (os::hasenv("MESOS_AUTHENTICATE")) {
+ if (os::getenv("MESOS_AUTHENTICATE").isSome()) {
cout << "Enabling authentication for the scheduler" << endl;
- if (!os::hasenv("DEFAULT_PRINCIPAL")) {
+ value = os::getenv("DEFAULT_PRINCIPAL");
+ if (value.isNone()) {
EXIT(1) << "Expecting authentication principal in the environment";
}
- if (!os::hasenv("DEFAULT_SECRET")) {
+ Credential credential;
+ credential.set_principal(value.get());
+
+ framework.set_principal(value.get());
+
+ value = os::getenv("DEFAULT_SECRET");
+ if (value.isNone()) {
EXIT(1) << "Expecting authentication secret in the environment";
}
- Credential credential;
- credential.set_principal(getenv("DEFAULT_PRINCIPAL"));
- credential.set_secret(getenv("DEFAULT_SECRET"));
-
- framework.set_principal(getenv("DEFAULT_PRINCIPAL"));
+ credential.set_secret(value.get());
scheduler =
new LowLevelScheduler(framework, executor, master.get(), credential);
http://git-wip-us.apache.org/repos/asf/mesos/blob/dc216463/src/examples/low_level_scheduler_pthread.cpp
----------------------------------------------------------------------
diff --git a/src/examples/low_level_scheduler_pthread.cpp b/src/examples/low_level_scheduler_pthread.cpp
index 175ee4d..1d285d8 100644
--- a/src/examples/low_level_scheduler_pthread.cpp
+++ b/src/examples/low_level_scheduler_pthread.cpp
@@ -402,10 +402,13 @@ void usage(const char* argv0, const flags::FlagsBase& flags)
int main(int argc, char** argv)
{
// Find this executable's directory to locate executor.
- string uri =
- path::join(os::realpath(dirname(argv[0])).get(), "src", "test-executor");
- if (getenv("MESOS_BUILD_DIR")) {
- uri = path::join(os::getenv("MESOS_BUILD_DIR"), "src", "test-executor");
+ string uri;
+ Option<string> value = os::getenv("MESOS_BUILD_DIR");
+ if (value.isSome()) {
+ uri = path::join(value.get(), "src", "test-executor");
+ } else {
+ uri =
+ path::join(os::realpath(dirname(argv[0])).get(), "src", "test-executor");
}
mesos::internal::logging::Flags flags;
@@ -440,9 +443,10 @@ int main(int argc, char** argv)
framework.set_name("Low-Level Scheduler using pthread (C++)");
framework.set_role(role);
- if (os::hasenv("MESOS_CHECKPOINT")) {
+ value = os::getenv("MESOS_CHECKPOINT");
+ if (value.isSome()) {
framework.set_checkpoint(
- numify<bool>(os::getenv("MESOS_CHECKPOINT")).get());
+ numify<bool>(value.get()).get());
}
ExecutorInfo executor;
@@ -452,22 +456,25 @@ int main(int argc, char** argv)
executor.set_source("cpp_test");
LowLevelScheduler* scheduler;
- if (os::hasenv("MESOS_AUTHENTICATE")) {
+ if (os::getenv("MESOS_AUTHENTICATE").isSome()) {
cout << "Enabling authentication for the scheduler" << endl;
- if (!os::hasenv("DEFAULT_PRINCIPAL")) {
+ value = os::getenv("DEFAULT_PRINCIPAL");
+ if (value.isNone()) {
EXIT(1) << "Expecting authentication principal in the environment";
}
- if (!os::hasenv("DEFAULT_SECRET")) {
+ Credential credential;
+ credential.set_principal(value.get());
+
+ framework.set_principal(value.get());
+
+ value = os::getenv("DEFAULT_SECRET");
+ if (value.isNone()) {
EXIT(1) << "Expecting authentication secret in the environment";
}
- Credential credential;
- credential.set_principal(getenv("DEFAULT_PRINCIPAL"));
- credential.set_secret(getenv("DEFAULT_SECRET"));
-
- framework.set_principal(getenv("DEFAULT_PRINCIPAL"));
+ credential.set_secret(value.get());
scheduler =
new LowLevelScheduler(framework, executor, master.get(), credential);
http://git-wip-us.apache.org/repos/asf/mesos/blob/dc216463/src/examples/no_executor_framework.cpp
----------------------------------------------------------------------
diff --git a/src/examples/no_executor_framework.cpp b/src/examples/no_executor_framework.cpp
index 37001c3..1fb853d 100644
--- a/src/examples/no_executor_framework.cpp
+++ b/src/examples/no_executor_framework.cpp
@@ -30,6 +30,7 @@
#include <stout/check.hpp>
#include <stout/exit.hpp>
#include <stout/numify.hpp>
+#include <stout/option.hpp>
#include <stout/os.hpp>
#include <stout/stringify.hpp>
@@ -170,28 +171,32 @@ int main(int argc, char** argv)
framework.set_user(""); // Have Mesos fill in the current user.
framework.set_name("No Executor Framework (C++)");
- if (os::hasenv("MESOS_CHECKPOINT")) {
+ Option<string> value = os::getenv("MESOS_CHECKPOINT");
+ if (value.isSome()) {
framework.set_checkpoint(
- numify<bool>(os::getenv("MESOS_CHECKPOINT")).get());
+ numify<bool>(value.get()).get());
}
MesosSchedulerDriver* driver;
- if (os::hasenv("MESOS_AUTHENTICATE")) {
+ if (os::getenv("MESOS_AUTHENTICATE").isSome()) {
cout << "Enabling authentication for the framework" << endl;
- if (!os::hasenv("DEFAULT_PRINCIPAL")) {
+ value = os::getenv("DEFAULT_PRINCIPAL");
+ if (value.isNone()) {
EXIT(1) << "Expecting authentication principal in the environment";
}
- if (!os::hasenv("DEFAULT_SECRET")) {
+ Credential credential;
+ credential.set_principal(value.get());
+
+ framework.set_principal(value.get());
+
+ value = os::getenv("DEFAULT_SECRET");
+ if (value.isNone()) {
EXIT(1) << "Expecting authentication secret in the environment";
}
- Credential credential;
- credential.set_principal(getenv("DEFAULT_PRINCIPAL"));
- credential.set_secret(getenv("DEFAULT_SECRET"));
-
- framework.set_principal(getenv("DEFAULT_PRINCIPAL"));
+ credential.set_secret(value.get());
driver = new MesosSchedulerDriver(
&scheduler, framework, argv[1], credential);
http://git-wip-us.apache.org/repos/asf/mesos/blob/dc216463/src/examples/test_framework.cpp
----------------------------------------------------------------------
diff --git a/src/examples/test_framework.cpp b/src/examples/test_framework.cpp
index 25f5f8c..99b981d 100644
--- a/src/examples/test_framework.cpp
+++ b/src/examples/test_framework.cpp
@@ -31,6 +31,7 @@
#include <stout/exit.hpp>
#include <stout/flags.hpp>
#include <stout/numify.hpp>
+#include <stout/option.hpp>
#include <stout/os.hpp>
#include <stout/stringify.hpp>
@@ -195,10 +196,12 @@ void usage(const char* argv0, const flags::FlagsBase& flags)
int main(int argc, char** argv)
{
// Find this executable's directory to locate executor.
- string path = os::realpath(dirname(argv[0])).get();
- string uri = path + "/test-executor";
- if (getenv("MESOS_BUILD_DIR")) {
- uri = string(getenv("MESOS_BUILD_DIR")) + "/src/test-executor";
+ string uri;
+ Option<string> value = os::getenv("MESOS_BUILD_DIR");
+ if (value.isSome()) {
+ uri = path::join(value.get(), "src", "test-executor");
+ } else {
+ uri = path::join(os::realpath(dirname(argv[0])).get(), "test-executor");
}
mesos::internal::logging::Flags flags;
@@ -239,13 +242,14 @@ int main(int argc, char** argv)
framework.set_name("Test Framework (C++)");
framework.set_role(role);
- if (os::hasenv("MESOS_CHECKPOINT")) {
+ value = os::getenv("MESOS_CHECKPOINT");
+ if (value.isSome()) {
framework.set_checkpoint(
- numify<bool>(os::getenv("MESOS_CHECKPOINT")).get());
+ numify<bool>(value.get()).get());
}
bool implicitAcknowledgements = true;
- if (os::hasenv("MESOS_EXPLICIT_ACKNOWLEDGEMENTS")) {
+ if (os::getenv("MESOS_EXPLICIT_ACKNOWLEDGEMENTS").isSome()) {
cout << "Enabling explicit acknowledgements for status updates" << endl;
implicitAcknowledgements = false;
@@ -254,20 +258,25 @@ int main(int argc, char** argv)
MesosSchedulerDriver* driver;
TestScheduler scheduler(implicitAcknowledgements, executor, role);
- if (os::hasenv("MESOS_AUTHENTICATE")) {
+ if (os::getenv("MESOS_AUTHENTICATE").isSome()) {
cout << "Enabling authentication for the framework" << endl;
- if (!os::hasenv("DEFAULT_PRINCIPAL")) {
+ value = os::getenv("DEFAULT_PRINCIPAL");
+ if (value.isNone()) {
EXIT(1) << "Expecting authentication principal in the environment";
}
Credential credential;
- credential.set_principal(getenv("DEFAULT_PRINCIPAL"));
- if (os::hasenv("DEFAULT_SECRET")) {
- credential.set_secret(getenv("DEFAULT_SECRET"));
+ credential.set_principal(value.get());
+
+ framework.set_principal(value.get());
+
+ value = os::getenv("DEFAULT_SECRET");
+ if (value.isNone()) {
+ EXIT(1) << "Expecting authentication secret in the environment";
}
- framework.set_principal(getenv("DEFAULT_PRINCIPAL"));
+ credential.set_secret(value.get());
driver = new MesosSchedulerDriver(
&scheduler,
http://git-wip-us.apache.org/repos/asf/mesos/blob/dc216463/src/exec/exec.cpp
----------------------------------------------------------------------
diff --git a/src/exec/exec.cpp b/src/exec/exec.cpp
index a22e8bb..0dfd5a6 100644
--- a/src/exec/exec.cpp
+++ b/src/exec/exec.cpp
@@ -631,59 +631,64 @@ Status MesosExecutorDriver::start()
string workDirectory;
bool checkpoint;
- string value;
+ Option<string> value;
std::istringstream iss;
// Check if this is local (for example, for testing).
- value = os::getenv("MESOS_LOCAL", false);
-
- if (!value.empty()) {
- local = true;
- } else {
- local = false;
- }
+ local = os::getenv("MESOS_LOCAL").isSome();
// Get slave PID from environment.
value = os::getenv("MESOS_SLAVE_PID");
- slave = UPID(value);
- CHECK(slave) << "Cannot parse MESOS_SLAVE_PID '" << value << "'";
+ if (value.isNone()) {
+ EXIT(1) << "Expecting 'MESOS_SLAVE_PID' to be set in the environment.";
+ }
+
+ slave = UPID(value.get());
+ CHECK(slave) << "Cannot parse MESOS_SLAVE_PID '" << value.get() << "'";
// Get slave ID from environment.
value = os::getenv("MESOS_SLAVE_ID");
- slaveId.set_value(value);
+ if (value.isNone()) {
+ EXIT(1) << "Expecting 'MESOS_SLAVE_ID' to be set in the environment.";
+ }
+ slaveId.set_value(value.get());
// Get framework ID from environment.
value = os::getenv("MESOS_FRAMEWORK_ID");
- frameworkId.set_value(value);
+ if (value.isNone()) {
+ EXIT(1) << "Expecting 'MESOS_FRAMEWORK_ID' to be set in the environment.";
+ }
+ frameworkId.set_value(value.get());
// Get executor ID from environment.
value = os::getenv("MESOS_EXECUTOR_ID");
- executorId.set_value(value);
+ if (value.isNone()) {
+ EXIT(1) << "Expecting 'MESOS_EXECUTOR_ID' to be set in the environment.";
+ }
+ executorId.set_value(value.get());
// Get working directory from environment.
value = os::getenv("MESOS_DIRECTORY");
- workDirectory = value;
+ if (value.isNone()) {
+ EXIT(1) << "Expecting 'MESOS_DIRECTORY' to be set in the environment.";
+ }
+ workDirectory = value.get();
// Get checkpointing status from environment.
- value = os::getenv("MESOS_CHECKPOINT", false);
-
- if (!value.empty()) {
- checkpoint = value == "1";
- } else {
- checkpoint = false;
- }
+ value = os::getenv("MESOS_CHECKPOINT");
+ checkpoint = value.isSome() && value.get() == "1";
Duration recoveryTimeout = slave::RECOVERY_TIMEOUT;
// Get the recovery timeout if checkpointing is enabled.
if (checkpoint) {
- value = os::getenv("MESOS_RECOVERY_TIMEOUT", false);
+ value = os::getenv("MESOS_RECOVERY_TIMEOUT");
- if (!value.empty()) {
- Try<Duration> _recoveryTimeout = Duration::parse(value);
+ if (value.isSome()) {
+ Try<Duration> _recoveryTimeout = Duration::parse(value.get());
CHECK_SOME(_recoveryTimeout)
- << "Cannot parse MESOS_RECOVERY_TIMEOUT '" << value << "': "
+ << "Cannot parse MESOS_RECOVERY_TIMEOUT '" << value.get() << "': "
<< _recoveryTimeout.error();
recoveryTimeout = _recoveryTimeout.get();
http://git-wip-us.apache.org/repos/asf/mesos/blob/dc216463/src/hdfs/hdfs.hpp
----------------------------------------------------------------------
diff --git a/src/hdfs/hdfs.hpp b/src/hdfs/hdfs.hpp
index 0b0312c..cba386a 100644
--- a/src/hdfs/hdfs.hpp
+++ b/src/hdfs/hdfs.hpp
@@ -33,14 +33,14 @@ struct HDFS
explicit HDFS(const std::string& _hadoop)
: hadoop(os::exists(_hadoop)
? _hadoop
- : (os::hasenv("HADOOP_HOME")
- ? path::join(os::getenv("HADOOP_HOME"), "bin/hadoop")
+ : (os::getenv("HADOOP_HOME").isSome()
+ ? path::join(os::getenv("HADOOP_HOME").get(), "bin/hadoop")
: "hadoop")) {}
// Look for `hadoop' in HADOOP_HOME or assume it's on the PATH.
HDFS()
- : hadoop(os::hasenv("HADOOP_HOME")
- ? path::join(os::getenv("HADOOP_HOME"), "bin/hadoop")
+ : hadoop(os::getenv("HADOOP_HOME").isSome()
+ ? path::join(os::getenv("HADOOP_HOME").get(), "bin/hadoop")
: "hadoop") {}
// Check if hadoop client is available at the path that was set.
http://git-wip-us.apache.org/repos/asf/mesos/blob/dc216463/src/jvm/jvm.cpp
----------------------------------------------------------------------
diff --git a/src/jvm/jvm.cpp b/src/jvm/jvm.cpp
index 0fda513..3fda5a7 100644
--- a/src/jvm/jvm.cpp
+++ b/src/jvm/jvm.cpp
@@ -29,6 +29,7 @@
#include <stout/dynamiclibrary.hpp>
#include <stout/exit.hpp>
#include <stout/foreach.hpp>
+#include <stout/option.hpp>
#include <stout/os.hpp>
#include "common/build.hpp"
@@ -75,14 +76,14 @@ Try<Jvm*> Jvm::create(
JavaVM* jvm = NULL;
JNIEnv* env = NULL;
- std::string libJvmPath = os::getenv("JAVA_JVM_LIBRARY", false);
+ Option<std::string> libJvmPath = os::getenv("JAVA_JVM_LIBRARY");
- if (libJvmPath.empty()) {
+ if (libJvmPath.isNone()) {
libJvmPath = mesos::internal::build::JAVA_JVM_LIBRARY;
}
static DynamicLibrary* libJvm = new DynamicLibrary();
- Try<Nothing> openResult = libJvm->open(libJvmPath);
+ Try<Nothing> openResult = libJvm->open(libJvmPath.get());
if (openResult.isError()) {
return Error(openResult.error());
http://git-wip-us.apache.org/repos/asf/mesos/blob/dc216463/src/launcher/executor.cpp
----------------------------------------------------------------------
diff --git a/src/launcher/executor.cpp b/src/launcher/executor.cpp
index f79dc60..9a3a1c3 100644
--- a/src/launcher/executor.cpp
+++ b/src/launcher/executor.cpp
@@ -631,10 +631,9 @@ int main(int argc, char** argv)
}
}
- string path = os::getenv("MESOS_LAUNCHER_DIR", false);
- if (path.empty()) {
- path = os::realpath(dirname(argv[0])).get();
- }
+ const Option<string> envPath = os::getenv("MESOS_LAUNCHER_DIR");
+ string path = envPath.isSome() ? envPath.get()
+ : os::realpath(dirname(argv[0])).get();
mesos::internal::CommandExecutor executor(override, path);
mesos::MesosExecutorDriver driver(&executor);
return driver.run() == mesos::DRIVER_STOPPED ? EXIT_SUCCESS : EXIT_FAILURE;
http://git-wip-us.apache.org/repos/asf/mesos/blob/dc216463/src/launcher/fetcher.cpp
----------------------------------------------------------------------
diff --git a/src/launcher/fetcher.cpp b/src/launcher/fetcher.cpp
index c32106f..a3d27dc 100644
--- a/src/launcher/fetcher.cpp
+++ b/src/launcher/fetcher.cpp
@@ -384,13 +384,13 @@ int main(int argc, char* argv[])
logging::initialize(argv[0], flags, true); // Catch signals.
- CHECK(os::hasenv("MESOS_FETCHER_INFO"))
+ const Option<std::string> jsonFetcherInfo = os::getenv("MESOS_FETCHER_INFO");
+ CHECK(jsonFetcherInfo.isSome())
<< "Missing MESOS_FETCHER_INFO environment variable";
- string jsonFetcherInfo = os::getenv("MESOS_FETCHER_INFO");
- LOG(INFO) << "Fetcher Info: " << jsonFetcherInfo;
+ LOG(INFO) << "Fetcher Info: " << jsonFetcherInfo.get();
- Try<JSON::Object> parse = JSON::parse<JSON::Object>(jsonFetcherInfo);
+ Try<JSON::Object> parse = JSON::parse<JSON::Object>(jsonFetcherInfo.get());
CHECK_SOME(parse) << "Failed to parse MESOS_FETCHER_INFO: " << parse.error();
Try<FetcherInfo> fetcherInfo = ::protobuf::parse<FetcherInfo>(parse.get());
http://git-wip-us.apache.org/repos/asf/mesos/blob/dc216463/src/slave/containerizer/containerizer.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/containerizer.cpp b/src/slave/containerizer/containerizer.cpp
index 4d66e76..e995ce6 100644
--- a/src/slave/containerizer/containerizer.cpp
+++ b/src/slave/containerizer/containerizer.cpp
@@ -24,6 +24,7 @@
#include <stout/fs.hpp>
#include <stout/hashmap.hpp>
+#include <stout/os.hpp>
#include <stout/stringify.hpp>
#include <stout/strings.hpp>
#include <stout/uuid.hpp>
@@ -252,7 +253,7 @@ map<string, string> executorEnvironment(
// case the framework wants to override).
// TODO(tillt): Adapt library towards JNI specific name once libmesos
// has been split.
- if (!os::hasenv("MESOS_NATIVE_JAVA_LIBRARY")) {
+ if (os::getenv("MESOS_NATIVE_JAVA_LIBRARY").isNone()) {
string path =
#ifdef __APPLE__
LIBDIR "/libmesos-" VERSION ".dylib";
@@ -267,7 +268,7 @@ map<string, string> executorEnvironment(
// Also add MESOS_NATIVE_LIBRARY if it's not already present.
// This environment variable is kept for offering non JVM-based
// frameworks a more compact and JNI independent library.
- if (!os::hasenv("MESOS_NATIVE_LIBRARY")) {
+ if (os::getenv("MESOS_NATIVE_LIBRARY").isNone()) {
string path =
#ifdef __APPLE__
LIBDIR "/libmesos-" VERSION ".dylib";
http://git-wip-us.apache.org/repos/asf/mesos/blob/dc216463/src/slave/containerizer/docker.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/docker.cpp b/src/slave/containerizer/docker.cpp
index 41e0b98..00db981 100644
--- a/src/slave/containerizer/docker.cpp
+++ b/src/slave/containerizer/docker.cpp
@@ -884,8 +884,9 @@ Future<pid_t> DockerContainerizerProcess::launchExecutorProcess(
}
// Pass GLOG flag to the executor.
- if (os::hasenv("GLOG_v")) {
- environment["GLOG_v"] = os::getenv("GLOG_v");
+ const Option<string> glog = os::getenv("GLOG_v");
+ if (glog.isSome()) {
+ environment["GLOG_v"] = glog.get();
}
vector<string> argv;
http://git-wip-us.apache.org/repos/asf/mesos/blob/dc216463/src/tests/anonymous_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/anonymous_tests.cpp b/src/tests/anonymous_tests.cpp
index 12d4eb4..3ddd79d 100644
--- a/src/tests/anonymous_tests.cpp
+++ b/src/tests/anonymous_tests.cpp
@@ -67,7 +67,7 @@ TEST_F(AnonymousTest, Running)
// Test if the environment variables have been created by the
// anonymous module.
- EXPECT_EQ("42", os::getenv(TEST_ANONYMOUS_ENVIRONMENT_VARIABLE));
+ EXPECT_EQ("42", os::getenv(TEST_ANONYMOUS_ENVIRONMENT_VARIABLE).get());
// Clear test relevant environment.
os::unsetenv(TEST_ANONYMOUS_ENVIRONMENT_VARIABLE);
http://git-wip-us.apache.org/repos/asf/mesos/blob/dc216463/src/tests/environment.cpp
----------------------------------------------------------------------
diff --git a/src/tests/environment.cpp b/src/tests/environment.cpp
index e002363..2b6bc0c 100644
--- a/src/tests/environment.cpp
+++ b/src/tests/environment.cpp
@@ -367,7 +367,7 @@ void Environment::SetUp()
// Set the path to the native JNI library for running JVM tests.
// TODO(tillt): Adapt library towards JNI specific name once libmesos
// has been split.
- if (!os::hasenv("MESOS_NATIVE_JAVA_LIBRARY")) {
+ if (os::getenv("MESOS_NATIVE_JAVA_LIBRARY").isNone()) {
string path = path::join(tests::flags.build_dir, "src", ".libs");
#ifdef __APPLE__
path = path::join(path, "libmesos-" VERSION ".dylib");
[3/3] mesos git commit: Refactored os::getenv() to return an option
and removed os::hasenv().
Posted by tn...@apache.org.
Refactored os::getenv() to return an option and removed os::hasenv().
Review: https://reviews.apache.org/r/34319
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/2a74bcb5
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/2a74bcb5
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/2a74bcb5
Branch: refs/heads/master
Commit: 2a74bcb5267d4dcded403d85df20b310950823a8
Parents: c394e14
Author: Greg Mann <Gr...@gmail.com>
Authored: Thu Jun 4 10:51:27 2015 -0700
Committer: Timothy Chen <tn...@apache.org>
Committed: Thu Jun 4 11:11:30 2015 -0700
----------------------------------------------------------------------
.../3rdparty/stout/include/stout/os.hpp | 28 ++++++--------------
1 file changed, 8 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/2a74bcb5/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
index 8ee02ef..68626b0 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
@@ -153,31 +153,18 @@ inline hashmap<std::string, std::string> environment()
}
-// Checks if the specified key is in the environment variables.
-inline bool hasenv(const std::string& key)
-{
- char* value = ::getenv(key.c_str());
-
- return value != NULL;
-}
-
// Looks in the environment variables for the specified key and
-// returns a string representation of it's value. If 'expected' is
-// true (default) and no environment variable matching key is found,
-// this function will exit the process.
-inline std::string getenv(const std::string& key, bool expected = true)
+// returns a string representation of its value. If no environment
+// variable matching key is found, None() is returned.
+inline Option<std::string> getenv(const std::string& key)
{
char* value = ::getenv(key.c_str());
- if (expected && value == NULL) {
- LOG(FATAL) << "Expecting '" << key << "' in environment variables";
- }
-
- if (value != NULL) {
- return std::string(value);
+ if (value == NULL) {
+ return None();
}
- return std::string();
+ return std::string(value);
}
@@ -1257,7 +1244,8 @@ inline std::string paths()
#else
"DYLD_LIBRARY_PATH";
#endif
- return getenv(environmentVariable, false);
+ const Option<std::string> path = getenv(environmentVariable);
+ return path.isSome() ? path.get() : std::string();
}