You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2016/12/10 02:02:08 UTC

[01/12] mesos git commit: Normalized how temporary directories are determined in tests.

Repository: mesos
Updated Branches:
  refs/heads/master 8a6bdb8e6 -> a6bb33b2c


Normalized how temporary directories are determined in tests.

This changes the Mesos tests to use the updated `os::temp` helper,
which (on POSIX) now checks the `TMPDIR` environment variable.

On Windows, this changes the temporary directory to an appropriate
location (`/tmp` does not exist on Windows by default).

Review: https://reviews.apache.org/r/54490/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/883f5d2e
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/883f5d2e
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/883f5d2e

Branch: refs/heads/master
Commit: 883f5d2e31eb3f73e808e58c020f5b68ca7b2e1d
Parents: ca0a8d5
Author: Alex Clemmer <cl...@gmail.com>
Authored: Thu Dec 8 17:38:41 2016 -0800
Committer: Joseph Wu <jo...@apache.org>
Committed: Fri Dec 9 18:01:31 2016 -0800

----------------------------------------------------------------------
 src/tests/environment.cpp | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/883f5d2e/src/tests/environment.cpp
----------------------------------------------------------------------
diff --git a/src/tests/environment.cpp b/src/tests/environment.cpp
index ba75043..a683d8c 100644
--- a/src/tests/environment.cpp
+++ b/src/tests/environment.cpp
@@ -49,6 +49,7 @@
 #include <stout/os/exists.hpp>
 #include <stout/os/pstree.hpp>
 #include <stout/os/shell.hpp>
+#include <stout/os/temp.hpp>
 
 #ifdef __linux__
 #include "linux/cgroups.hpp"
@@ -901,14 +902,10 @@ Try<string> Environment::TemporaryDirectoryEventListener::mkdtemp()
     testName = strings::remove(testName, "DISABLED_", strings::PREFIX);
   }
 
-  Option<string> tmpdir = os::getenv("TMPDIR");
-
-  if (tmpdir.isNone()) {
-    tmpdir = "/tmp";
-  }
+  const string tmpdir = os::temp();
 
   const string& path =
-    path::join(tmpdir.get(), strings::join("_", testCase, testName, "XXXXXX"));
+    path::join(tmpdir, strings::join("_", testCase, testName, "XXXXXX"));
 
   Try<string> mkdtemp = os::mkdtemp(path);
   if (mkdtemp.isSome()) {


[02/12] mesos git commit: Windows: Qualified string, map, and vector in `subprocess.hpp`.

Posted by jo...@apache.org.
Windows: Qualified string, map, and vector in `subprocess.hpp`.

This fixes compilation errors introduced by:
https://reviews.apache.org/r/54555/

The above review removed `using std::map, std::string, std::vector`
but did not add the `std::` qualification to their uses.

Review: https://reviews.apache.org/r/54610/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/a430a651
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/a430a651
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/a430a651

Branch: refs/heads/master
Commit: a430a65147c337bf4db40a3125a0a59abbe02303
Parents: 8a6bdb8
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Fri Dec 9 15:54:48 2016 -0800
Committer: Joseph Wu <jo...@apache.org>
Committed: Fri Dec 9 18:01:31 2016 -0800

----------------------------------------------------------------------
 .../include/process/windows/subprocess.hpp      | 33 +++++++++++---------
 1 file changed, 19 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/a430a651/3rdparty/libprocess/include/process/windows/subprocess.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/windows/subprocess.hpp b/3rdparty/libprocess/include/process/windows/subprocess.hpp
index ae684ff..3bc7f19 100644
--- a/3rdparty/libprocess/include/process/windows/subprocess.hpp
+++ b/3rdparty/libprocess/include/process/windows/subprocess.hpp
@@ -68,12 +68,12 @@ inline void close(
 
 // Retrieves system environment in a `std::map`, ignoring
 // the current process's environment variables.
-inline Option<map<string, string>> getSystemEnvironment()
+inline Option<std::map<std::string, std::string>> getSystemEnvironment()
 {
   std::wstring_convert<std::codecvt<wchar_t, char, mbstate_t>,
     wchar_t> converter;
 
-  map<string, string> systemEnvironment;
+  std::map<std::string, std::string> systemEnvironment;
   wchar_t* environmentEntry = nullptr;
 
   // Get the system environment.
@@ -129,27 +129,32 @@ inline Option<map<string, string>> getSystemEnvironment()
 // `env` and are generally necessary in order to launch things on Windows.
 //
 // [1] https://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx
-inline Option<string> createProcessEnvironment(
-    const Option<map<string, string>>& env)
+inline Option<std::string> createProcessEnvironment(
+    const Option<std::map<std::string, std::string>>& env)
 {
   if (env.isNone() || (env.isSome() && env.get().size() == 0)) {
     return None();
   }
 
-  Option<map<string, string>> systemEnvironment = getSystemEnvironment();
+  Option<std::map<std::string, std::string>> systemEnvironment =
+    getSystemEnvironment();
 
   // The system environment must be non-empty.
   // No subprocesses will be able to launch if the system environment is blank.
   CHECK(systemEnvironment.isSome() && systemEnvironment.get().size() > 0);
 
-  map<string, string> combinedEnvironment = env.get();
+  std::map<std::string, std::string> combinedEnvironment = env.get();
 
-  foreachpair(const string& key, const string& value, systemEnvironment.get()) {
+  foreachpair (const std::string& key,
+               const std::string& value,
+               systemEnvironment.get()) {
     combinedEnvironment[key] = value;
   }
 
-  string environmentString;
-  foreachpair (const string& key, const string& value, combinedEnvironment) {
+  std::string environmentString;
+  foreachpair (const std::string& key,
+               const std::string& value,
+               combinedEnvironment) {
     environmentString += key + '=' + value + '\0';
   }
 
@@ -158,15 +163,15 @@ inline Option<string> createProcessEnvironment(
 
 
 inline Try<PROCESS_INFORMATION> createChildProcess(
-    const string& path,
-    const vector<string>& argv,
-    const Option<map<string, string>>& environment,
+    const std::string& path,
+    const std::vector<std::string>& argv,
+    const Option<std::map<std::string, std::string>>& environment,
     const InputFileDescriptors stdinfds,
     const OutputFileDescriptors stdoutfds,
     const OutputFileDescriptors stderrfds)
 {
   // Construct the environment that will be passed to `CreateProcess`.
-  Option<string> environmentString = createProcessEnvironment(environment);
+  Option<std::string> environmentString = createProcessEnvironment(environment);
   const char* processEnvironment = environmentString.isNone()
     ? nullptr
     : environmentString.get().c_str();
@@ -196,7 +201,7 @@ inline Try<PROCESS_INFORMATION> createChildProcess(
   // to have been already quoted correctly before we generate `command`.
   // Incorrectly-quoted command arguments will probably lead the child process
   // to terminate with an error. See also NOTE on `process::subprocess`.
-  string command = strings::join(" ", argv);
+  std::string command = strings::join(" ", argv);
 
   // Escape the quotes in `command`.
   //


[09/12] mesos git commit: Windows: Added temporary disabled TEST_P macro.

Posted by jo...@apache.org.
Windows: Added temporary disabled TEST_P macro.

This patch adds an additional temporary test macro
for Windows: TEST_P_TEMP_DISABLED_ON_WINDOWS.

Macros like this exist because the global test filters in
`tests/environment.cpp` are not available for stout and libprocess.
Tests that require this macro are not ported to Windows yet.

Review: https://reviews.apache.org/r/52938/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/b531b010
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/b531b010
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/b531b010

Branch: refs/heads/master
Commit: b531b0105b99c1fd433071d89043bcb06573539f
Parents: ff5bef9
Author: Greg Mann <gr...@mesosphere.io>
Authored: Fri Dec 9 16:37:47 2016 -0800
Committer: Joseph Wu <jo...@apache.org>
Committed: Fri Dec 9 18:01:32 2016 -0800

----------------------------------------------------------------------
 3rdparty/stout/include/stout/gtest.hpp | 12 ++++++++++++
 1 file changed, 12 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/b531b010/3rdparty/stout/include/stout/gtest.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/gtest.hpp b/3rdparty/stout/include/stout/gtest.hpp
index 5b4d677..a004a37 100644
--- a/3rdparty/stout/include/stout/gtest.hpp
+++ b/3rdparty/stout/include/stout/gtest.hpp
@@ -205,6 +205,18 @@ template <typename T1, typename T2>
 #endif // __WINDOWS__
 
 
+// Creates a gtest `TEST_P` that is disabled on Windows.
+// TODO(greggomann): Remove after temporarily-disabled tests are fixed on
+// Windows. See MESOS-6392.
+#ifndef __WINDOWS__
+#define TEST_P_TEMP_DISABLED_ON_WINDOWS(test_case_name, test_name) \
+  TEST_P(test_case_name, test_name)
+#else
+#define TEST_P_TEMP_DISABLED_ON_WINDOWS(test_case_name, test_name) \
+  TEST_P(test_case_name, DISABLED_##test_name)
+#endif // __WINDOWS__
+
+
 // NOTE: On Windows, the closest equivalent to `sleep` is `timeout`.
 // Unfortunately, `timeout` requires an interactive terminal, otherwise
 // it errors out immediately. Instead, we use `ping` against localhost


[10/12] mesos git commit: Made use of SSL flags to determine scheduler/executor scheme.

Posted by jo...@apache.org.
Made use of SSL flags to determine scheduler/executor scheme.

This patch updates the HTTP scheduler and executor
libraries to use process::network::openssl::flags()
to determine whether or not SSL is enabled.

Review: https://reviews.apache.org/r/50969/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/4c0ab5ea
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/4c0ab5ea
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/4c0ab5ea

Branch: refs/heads/master
Commit: 4c0ab5eadc8bd07976626124457c9dcd932372b8
Parents: f61f321
Author: Greg Mann <gr...@mesosphere.io>
Authored: Fri Dec 9 16:44:56 2016 -0800
Committer: Joseph Wu <jo...@apache.org>
Committed: Fri Dec 9 18:01:32 2016 -0800

----------------------------------------------------------------------
 src/executor/executor.cpp   | 12 +++++++++++-
 src/scheduler/scheduler.cpp | 13 ++++---------
 2 files changed, 15 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/4c0ab5ea/src/executor/executor.cpp
----------------------------------------------------------------------
diff --git a/src/executor/executor.cpp b/src/executor/executor.cpp
index 1d47b52..9591cd2 100644
--- a/src/executor/executor.cpp
+++ b/src/executor/executor.cpp
@@ -33,6 +33,8 @@
 #include <process/protobuf.hpp>
 #include <process/timer.hpp>
 
+#include <process/ssl/flags.hpp>
+
 #include <stout/duration.hpp>
 #include <stout/lambda.hpp>
 #include <stout/nothing.hpp>
@@ -205,8 +207,16 @@ public:
     UPID upid(value.get());
     CHECK(upid) << "Failed to parse MESOS_SLAVE_PID '" << value.get() << "'";
 
+    string scheme = "http";
+
+#ifdef USE_SSL_SOCKET
+    if (process::network::openssl::flags().enabled) {
+      scheme = "https";
+    }
+#endif // USE_SSL_SOCKET
+
     agent = ::URL(
-        "http",
+        scheme,
         upid.address.ip,
         upid.address.port,
         upid.id +

http://git-wip-us.apache.org/repos/asf/mesos/blob/4c0ab5ea/src/scheduler/scheduler.cpp
----------------------------------------------------------------------
diff --git a/src/scheduler/scheduler.cpp b/src/scheduler/scheduler.cpp
index 956f487..ce69258 100644
--- a/src/scheduler/scheduler.cpp
+++ b/src/scheduler/scheduler.cpp
@@ -57,6 +57,8 @@
 #include <process/metrics/gauge.hpp>
 #include <process/metrics/metrics.hpp>
 
+#include <process/ssl/flags.hpp>
+
 #include <stout/check.hpp>
 #include <stout/duration.hpp>
 #include <stout/error.hpp>
@@ -453,17 +455,10 @@ protected:
       string scheme = "http";
 
 #ifdef USE_SSL_SOCKET
-      // TODO(gkleiman): Update this once the deprecation cycle is over (see
-      // MESOS-6492).
-      Option<string> value = os::getenv("SSL_ENABLED");
-      if (value.isNone()) {
-        value = os::getenv("LIBPROCESS_SSL_ENABLED");
-      }
-
-      if (value.isSome() && (value.get() == "1" || value.get() == "true")) {
+      if (process::network::openssl::flags().enabled) {
         scheme = "https";
       }
-#endif
+#endif // USE_SSL_SOCKET
 
       master = ::URL(
         scheme,


[03/12] mesos git commit: Stout: Added logic for TMPDIR environment variable in `os::temp`.

Posted by jo...@apache.org.
Stout: Added logic for TMPDIR environment variable in `os::temp`.

`TMPDIR` is a POSIX-standard environment variable which can be used
to specify a temporary directory.  This variable is currently read
in the agent tests, but ignored in other parts of the codebase.
(`os::temp` is commonly used by `os::mkdtemp`.)

This commit is one of two commits that will normalize the location
of the temporary directory.

Review: https://reviews.apache.org/r/54489/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/ca0a8d55
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/ca0a8d55
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/ca0a8d55

Branch: refs/heads/master
Commit: ca0a8d552cd098593c3c3b0f76d5215846de7120
Parents: b9ef614
Author: Alex Clemmer <cl...@gmail.com>
Authored: Thu Dec 8 17:25:06 2016 -0800
Committer: Joseph Wu <jo...@apache.org>
Committed: Fri Dec 9 18:01:31 2016 -0800

----------------------------------------------------------------------
 3rdparty/stout/include/stout/os/posix/temp.hpp   | 10 +++++++++-
 3rdparty/stout/include/stout/os/windows/temp.hpp |  7 +++++--
 2 files changed, 14 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/ca0a8d55/3rdparty/stout/include/stout/os/posix/temp.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/posix/temp.hpp b/3rdparty/stout/include/stout/os/posix/temp.hpp
index 823c97b..cdc4386 100644
--- a/3rdparty/stout/include/stout/os/posix/temp.hpp
+++ b/3rdparty/stout/include/stout/os/posix/temp.hpp
@@ -15,12 +15,20 @@
 
 #include <string>
 
+#include <stout/os/getenv.hpp>
+
 
 namespace os {
 
+// Attempts to resolve the system-designated temporary directory before
+// back on a sensible default. On POSIX platforms, this involves checking
+// the POSIX-standard `TMPDIR` environment variable before falling
+// back to `/tmp`.
 inline std::string temp()
 {
-  return "/tmp";
+  Option<std::string> tmpdir = os::getenv("TMPDIR");
+
+  return tmpdir.getOrElse("/tmp");
 }
 
 } // namespace os {

http://git-wip-us.apache.org/repos/asf/mesos/blob/ca0a8d55/3rdparty/stout/include/stout/os/windows/temp.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/temp.hpp b/3rdparty/stout/include/stout/os/windows/temp.hpp
index d1169df..639f1aa 100644
--- a/3rdparty/stout/include/stout/os/windows/temp.hpp
+++ b/3rdparty/stout/include/stout/os/windows/temp.hpp
@@ -20,12 +20,15 @@
 
 namespace os {
 
+// Attempts to resolve the system-designated temporary directory before
+// falling back to a sensible default. On Windows, this involves checking
+// (in this order) environment variables for `TMP`, `TEMP`, and `USERPROFILE`
+// followed by the Windows directory (`::GetTimePath`).  In the unlikely event
+// where none of these are found, this function returns the current directory.
 inline std::string temp()
 {
-  // Get temp folder for current user.
   char temp_folder[MAX_PATH + 2];
   if (::GetTempPath(MAX_PATH + 2, temp_folder) == 0) {
-    // Failed, try current folder.
     if (::GetCurrentDirectory(MAX_PATH + 2, temp_folder) == 0) {
       // Failed, use relative path.
       return ".";


[12/12] mesos git commit: Modified a scheduler test to run with SSL enabled.

Posted by jo...@apache.org.
Modified a scheduler test to run with SSL enabled.

This patch modifies the test SchedulerTest.Teardown to
be parametrized by both ContentType and SSL configuration,
and renames it to SchedulerSSLTest.RunTaskAndTeardown.
This allows the test to verify the scheduler's behavior with
SSL both enabled and disabled.

Review: https://reviews.apache.org/r/50857/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/a6bb33b2
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/a6bb33b2
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/a6bb33b2

Branch: refs/heads/master
Commit: a6bb33b2cec0cd706abe96bbfbf31897ec324ee1
Parents: 4c0ab5e
Author: Greg Mann <gr...@mesosphere.io>
Authored: Fri Dec 9 16:46:52 2016 -0800
Committer: Joseph Wu <jo...@apache.org>
Committed: Fri Dec 9 18:01:32 2016 -0800

----------------------------------------------------------------------
 src/tests/scheduler_tests.cpp | 311 +++++++++++++++++++++++--------------
 1 file changed, 191 insertions(+), 120 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/a6bb33b2/src/tests/scheduler_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/scheduler_tests.cpp b/src/tests/scheduler_tests.cpp
index c031823..95cad9a 100644
--- a/src/tests/scheduler_tests.cpp
+++ b/src/tests/scheduler_tests.cpp
@@ -86,6 +86,17 @@ using testing::DoAll;
 using testing::Return;
 using testing::WithParamInterface;
 
+namespace process {
+
+// We need to reinitialize libprocess in order to test against different
+// configurations, such as when libprocess is initialized with SSL enabled.
+void reinitialize(
+    const Option<string>& delegate,
+    const Option<string>& readonlyAuthenticationRealm,
+    const Option<string>& readwriteAuthenticationRealm);
+
+} // namespace process {
+
 namespace mesos {
 namespace internal {
 namespace tests {
@@ -1043,126 +1054,6 @@ TEST_P(SchedulerTest, ShutdownExecutor)
 }
 
 
-TEST_P(SchedulerTest, Teardown)
-{
-  Try<Owned<cluster::Master>> master = StartMaster();
-  ASSERT_SOME(master);
-
-  auto scheduler = std::make_shared<v1::MockHTTPScheduler>();
-  auto executor = std::make_shared<v1::MockHTTPExecutor>();
-
-  ExecutorID executorId = DEFAULT_EXECUTOR_ID;
-  TestContainerizer containerizer(executorId, executor);
-
-  Owned<MasterDetector> detector = master.get()->createDetector();
-  Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), &containerizer);
-  ASSERT_SOME(slave);
-
-  Future<Nothing> connected;
-  EXPECT_CALL(*scheduler, connected(_))
-    .WillOnce(FutureSatisfy(&connected))
-    .WillRepeatedly(Return()); // Ignore future invocations.
-
-  ContentType contentType = GetParam();
-
-  v1::scheduler::TestMesos mesos(
-      master.get()->pid,
-      contentType,
-      scheduler);
-
-  AWAIT_READY(connected);
-
-  Future<Event::Subscribed> subscribed;
-  EXPECT_CALL(*scheduler, subscribed(_, _))
-    .WillOnce(FutureArg<1>(&subscribed));
-
-  EXPECT_CALL(*scheduler, heartbeat(_))
-    .WillRepeatedly(Return()); // Ignore heartbeats.
-
-  Future<Event::Offers> offers;
-  EXPECT_CALL(*scheduler, offers(_, _))
-    .WillOnce(FutureArg<1>(&offers));
-
-  {
-    Call call;
-    call.set_type(Call::SUBSCRIBE);
-
-    Call::Subscribe* subscribe = call.mutable_subscribe();
-    subscribe->mutable_framework_info()->CopyFrom(v1::DEFAULT_FRAMEWORK_INFO);
-
-    mesos.send(call);
-  }
-
-  AWAIT_READY(subscribed);
-
-  v1::FrameworkID frameworkId(subscribed->framework_id());
-
-  AWAIT_READY(offers);
-  EXPECT_NE(0, offers->offers().size());
-
-  EXPECT_CALL(*executor, connected(_))
-    .WillOnce(v1::executor::SendSubscribe(frameworkId, evolve(executorId)));
-
-  EXPECT_CALL(*executor, subscribed(_, _));
-
-  EXPECT_CALL(*executor, launch(_, _))
-    .WillOnce(v1::executor::SendUpdateFromTask(
-        frameworkId, evolve(executorId), v1::TASK_RUNNING));
-
-  Future<Nothing> acknowledged;
-  EXPECT_CALL(*executor, acknowledged(_, _))
-    .WillOnce(FutureSatisfy(&acknowledged));
-
-  Future<Event::Update> update;
-  EXPECT_CALL(*scheduler, update(_, _))
-    .WillOnce(FutureArg<1>(&update));
-
-  const v1::Offer& offer = offers->offers(0);
-
-  v1::TaskInfo taskInfo =
-    evolve(createTask(devolve(offer), "", DEFAULT_EXECUTOR_ID));
-
-  {
-    Call call;
-    call.mutable_framework_id()->CopyFrom(frameworkId);
-    call.set_type(Call::ACCEPT);
-
-    Call::Accept* accept = call.mutable_accept();
-    accept->add_offer_ids()->CopyFrom(offer.id());
-
-    v1::Offer::Operation* operation = accept->add_operations();
-    operation->set_type(v1::Offer::Operation::LAUNCH);
-    operation->mutable_launch()->add_task_infos()->CopyFrom(taskInfo);
-
-    mesos.send(call);
-  }
-
-  AWAIT_READY(acknowledged);
-  AWAIT_READY(update);
-
-  EXPECT_EQ(v1::TASK_RUNNING, update->status().state());
-
-  Future<Nothing> shutdown;
-  EXPECT_CALL(*executor, shutdown(_))
-    .WillOnce(FutureSatisfy(&shutdown));
-
-  Future<Nothing> disconnected;
-  EXPECT_CALL(*scheduler, disconnected(_))
-    .WillOnce(FutureSatisfy(&disconnected));
-
-  {
-    Call call;
-    call.mutable_framework_id()->CopyFrom(frameworkId);
-    call.set_type(Call::TEARDOWN);
-
-    mesos.send(call);
-  }
-
-  AWAIT_READY(shutdown);
-  AWAIT_READY(disconnected);
-}
-
-
 TEST_P(SchedulerTest, Decline)
 {
   master::Flags flags = CreateMasterFlags();
@@ -1856,6 +1747,186 @@ TEST_P(SchedulerReconcileTasks_BENCHMARK_Test, SchedulerDriver)
   driver.join();
 }
 
+
+// A fixture class for scheduler tests that can be run with SSL either enabled
+// or disabled.
+class SchedulerSSLTest
+  : public MesosTest,
+    public WithParamInterface<std::tr1::tuple<ContentType, string>>
+{
+// These test setup/teardown methods are only needed when compiled with SSL.
+#ifdef USE_SSL_SOCKET
+protected:
+  virtual void SetUp()
+  {
+    MesosTest::SetUp();
+
+    if (std::tr1::get<1>(GetParam()) == "https") {
+      generate_keys_and_certs();
+      set_environment_variables({
+          {"LIBPROCESS_SSL_ENABLED", "true"},
+          {"LIBPROCESS_SSL_KEY_FILE", key_path()},
+          {"LIBPROCESS_SSL_CERT_FILE", certificate_path()},
+          {"LIBPROCESS_SSL_CA_FILE", certificate_path().string()},
+          {"LIBPROCESS_SSL_REQUIRE_CERT", "true"}});
+      process::reinitialize(
+          None(),
+          READONLY_HTTP_AUTHENTICATION_REALM,
+          READWRITE_HTTP_AUTHENTICATION_REALM);
+    } else {
+      set_environment_variables({});
+      process::reinitialize(
+          None(),
+          READONLY_HTTP_AUTHENTICATION_REALM,
+          READWRITE_HTTP_AUTHENTICATION_REALM);
+    }
+  }
+
+public:
+  static void TearDownTestCase()
+  {
+    // The teardown code of `MesosTest` calls `set_environment_variables({})`,
+    // so we invoke it first.
+    MesosTest::TearDownTestCase();
+
+    process::reinitialize(
+        None(),
+        READONLY_HTTP_AUTHENTICATION_REALM,
+        READWRITE_HTTP_AUTHENTICATION_REALM);
+  }
+#endif // USE_SSL_SOCKET
+};
+
+
+INSTANTIATE_TEST_CASE_P(
+    ContentTypeAndSSLConfig,
+    SchedulerSSLTest,
+    ::testing::Combine(
+        ::testing::Values(ContentType::PROTOBUF, ContentType::JSON),
+        ::testing::Values(
+#ifdef USE_SSL_SOCKET
+            string("https"),
+#endif // USE_SSL_SOCKET
+            string("http"))));
+
+
+// Tests that a scheduler can subscribe, run a task, and then tear itself down.
+TEST_P(SchedulerSSLTest, RunTaskAndTeardown)
+{
+  Try<Owned<cluster::Master>> master = StartMaster();
+  ASSERT_SOME(master);
+
+  auto scheduler = std::make_shared<v1::MockHTTPScheduler>();
+  auto executor = std::make_shared<v1::MockHTTPExecutor>();
+
+  ExecutorID executorId = DEFAULT_EXECUTOR_ID;
+  TestContainerizer containerizer(executorId, executor);
+
+  Owned<MasterDetector> detector = master.get()->createDetector();
+  Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), &containerizer);
+  ASSERT_SOME(slave);
+
+  Future<Nothing> connected;
+  EXPECT_CALL(*scheduler, connected(_))
+    .WillOnce(FutureSatisfy(&connected))
+    .WillRepeatedly(Return()); // Ignore future invocations.
+
+  ContentType contentType = std::tr1::get<0>(GetParam());
+
+  v1::scheduler::TestMesos mesos(master.get()->pid, contentType, scheduler);
+
+  AWAIT_READY(connected);
+
+  Future<Event::Subscribed> subscribed;
+  EXPECT_CALL(*scheduler, subscribed(_, _))
+    .WillOnce(FutureArg<1>(&subscribed));
+
+  EXPECT_CALL(*scheduler, heartbeat(_))
+    .WillRepeatedly(Return()); // Ignore heartbeats.
+
+  Future<Event::Offers> offers;
+  EXPECT_CALL(*scheduler, offers(_, _))
+    .WillOnce(FutureArg<1>(&offers));
+
+  {
+    Call call;
+    call.set_type(Call::SUBSCRIBE);
+
+    Call::Subscribe* subscribe = call.mutable_subscribe();
+    subscribe->mutable_framework_info()->CopyFrom(v1::DEFAULT_FRAMEWORK_INFO);
+
+    mesos.send(call);
+  }
+
+  AWAIT_READY(subscribed);
+
+  v1::FrameworkID frameworkId(subscribed->framework_id());
+
+  AWAIT_READY(offers);
+  EXPECT_NE(0, offers->offers().size());
+
+  EXPECT_CALL(*executor, connected(_))
+    .WillOnce(v1::executor::SendSubscribe(frameworkId, evolve(executorId)));
+
+  EXPECT_CALL(*executor, subscribed(_, _));
+
+  EXPECT_CALL(*executor, launch(_, _))
+    .WillOnce(v1::executor::SendUpdateFromTask(
+        frameworkId, evolve(executorId), v1::TASK_RUNNING));
+
+  Future<Nothing> acknowledged;
+  EXPECT_CALL(*executor, acknowledged(_, _))
+    .WillOnce(FutureSatisfy(&acknowledged));
+
+  Future<Event::Update> update;
+  EXPECT_CALL(*scheduler, update(_, _))
+    .WillOnce(FutureArg<1>(&update));
+
+  const v1::Offer& offer = offers->offers(0);
+
+  v1::TaskInfo taskInfo =
+    evolve(createTask(devolve(offer), "", DEFAULT_EXECUTOR_ID));
+
+  {
+    Call call;
+    call.mutable_framework_id()->CopyFrom(frameworkId);
+    call.set_type(Call::ACCEPT);
+
+    Call::Accept* accept = call.mutable_accept();
+    accept->add_offer_ids()->CopyFrom(offer.id());
+
+    v1::Offer::Operation* operation = accept->add_operations();
+    operation->set_type(v1::Offer::Operation::LAUNCH);
+    operation->mutable_launch()->add_task_infos()->CopyFrom(taskInfo);
+
+    mesos.send(call);
+  }
+
+  AWAIT_READY(acknowledged);
+  AWAIT_READY(update);
+
+  EXPECT_EQ(v1::TASK_RUNNING, update->status().state());
+
+  Future<Nothing> shutdown;
+  EXPECT_CALL(*executor, shutdown(_))
+    .WillOnce(FutureSatisfy(&shutdown));
+
+  Future<Nothing> disconnected;
+  EXPECT_CALL(*scheduler, disconnected(_))
+    .WillOnce(FutureSatisfy(&disconnected));
+
+  {
+    Call call;
+    call.mutable_framework_id()->CopyFrom(frameworkId);
+    call.set_type(Call::TEARDOWN);
+
+    mesos.send(call);
+  }
+
+  AWAIT_READY(shutdown);
+  AWAIT_READY(disconnected);
+}
+
 } // namespace tests {
 } // namespace internal {
 } // namespace mesos {


[11/12] mesos git commit: Changed hostname used for SSL cert creation in tests.

Posted by jo...@apache.org.
Changed hostname used for SSL cert creation in tests.

This changes the SSL helpers in libprocess to generate
certs using a hostname determined using the same address
that is advertised by libprocess. This assures that
validation of the certificates will succeed, even in environments
where the loopback interface does not resolve to a single hostname.

The test `SSLTest.BasicSameProcess` is also updated to accommodate
this change.

Review: https://reviews.apache.org/r/51065/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/ff5bef9e
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/ff5bef9e
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/ff5bef9e

Branch: refs/heads/master
Commit: ff5bef9ea42c981dd4a9420038444e82d0de5495
Parents: ba5317b
Author: Greg Mann <gr...@mesosphere.io>
Authored: Fri Dec 9 16:27:11 2016 -0800
Committer: Joseph Wu <jo...@apache.org>
Committed: Fri Dec 9 18:01:32 2016 -0800

----------------------------------------------------------------------
 .../libprocess/include/process/ssl/gtest.hpp    | 25 +++++++++++++-------
 3rdparty/libprocess/src/tests/ssl_tests.cpp     |  4 ++--
 2 files changed, 18 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/ff5bef9e/3rdparty/libprocess/include/process/ssl/gtest.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/ssl/gtest.hpp b/3rdparty/libprocess/include/process/ssl/gtest.hpp
index 2a19b3b..b368eda 100644
--- a/3rdparty/libprocess/include/process/ssl/gtest.hpp
+++ b/3rdparty/libprocess/include/process/ssl/gtest.hpp
@@ -176,12 +176,12 @@ protected:
       cleanup("Could not generate private key: " + private_key.error());
     }
 
-    // Figure out the hostname that 'INADDR_LOOPBACK' will bind to.
+    // Figure out the hostname that libprocess is advertising.
     // Set the hostname of the certificate to this hostname so that
     // hostname verification of the certificate will pass.
-    Try<std::string> hostname = net::getHostname(net::IP(INADDR_LOOPBACK));
+    Try<std::string> hostname = net::getHostname(process::address().ip);
     if (hostname.isError()) {
-      cleanup("Could not determine hostname of 'INADDR_LOOPBACK': " +
+      cleanup("Could not determine hostname of libprocess: " +
               hostname.error());
     }
 
@@ -193,7 +193,7 @@ protected:
         1,
         365,
         hostname.get(),
-        net::IP(INADDR_LOOPBACK));
+        net::IP(process::address().ip));
 
     if (certificate.isError()) {
       cleanup("Could not generate certificate: " + certificate.error());
@@ -302,10 +302,11 @@ protected:
 
     process::network::inet::Socket server = create.get();
 
-    // We need to explicitly bind to the loopback address so the
+    // We need to explicitly bind to the address advertised by libprocess so the
     // certificate we create in this test fixture can be verified.
     Try<process::network::inet::Address> bind =
-      server.bind(process::network::inet::Address::LOOPBACK_ANY());
+      server.bind(
+          process::network::inet::Address(net::IP(process::address().ip), 0));
 
     if (bind.isError()) {
       return Error(bind.error());
@@ -347,8 +348,8 @@ protected:
     const std::vector<std::string> argv = {
       "ssl-client",
       "--use_ssl=" + stringify(use_ssl_socket),
-      "--server=127.0.0.1",
-      "--port=" + stringify(address.get().port),
+      "--server=" + stringify(address->ip),
+      "--port=" + stringify(address->port),
       "--data=" + data};
 
     Result<std::string> path = os::realpath(BUILD_DIR);
@@ -356,6 +357,12 @@ protected:
       return Error("Could not establish build directory path");
     }
 
+    // Explicitly set `LIBPROCESS_IP` in the subprocess to the same IP that was
+    // used to generate the hostname for SSL certificates. This ensures that
+    // certificate verification can succeed.
+    std::map<std::string, std::string> full_environment(environment);
+    full_environment["LIBPROCESS_IP"] = stringify(process::address().ip);
+
     return process::subprocess(
         path::join(path.get(), "ssl-client"),
         argv,
@@ -363,7 +370,7 @@ protected:
         process::Subprocess::PIPE(),
         process::Subprocess::FD(STDERR_FILENO),
         nullptr,
-        environment);
+        full_environment);
   }
 
   static constexpr size_t BACKLOG = 5;

http://git-wip-us.apache.org/repos/asf/mesos/blob/ff5bef9e/3rdparty/libprocess/src/tests/ssl_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/tests/ssl_tests.cpp b/3rdparty/libprocess/src/tests/ssl_tests.cpp
index 7fa46e4..a32d20e 100644
--- a/3rdparty/libprocess/src/tests/ssl_tests.cpp
+++ b/3rdparty/libprocess/src/tests/ssl_tests.cpp
@@ -141,9 +141,9 @@ TEST_P(SSLTest, BasicSameProcess)
   Try<Socket> client = Socket::create(SocketImpl::Kind::SSL);
   ASSERT_SOME(client);
 
-  // We need to explicitly bind to the loopback address so the
+  // We need to explicitly bind to the address advertised by libprocess so the
   // certificate we create in this test fixture can be verified.
-  ASSERT_SOME(server->bind(Address::LOOPBACK_ANY()));
+  ASSERT_SOME(server->bind(Address(net::IP(process::address().ip), 0)));
   ASSERT_SOME(server->listen(BACKLOG));
 
   Try<Address> address = server->address();


[05/12] mesos git commit: Add Andrew Schwartzmeyer to contributors.

Posted by jo...@apache.org.
Add Andrew Schwartzmeyer to contributors.

Review: https://reviews.apache.org/r/54607/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/b31edd94
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/b31edd94
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/b31edd94

Branch: refs/heads/master
Commit: b31edd94da723d3a524f35c938e4205ec483b0d6
Parents: a430a65
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Fri Dec 9 15:54:50 2016 -0800
Committer: Joseph Wu <jo...@apache.org>
Committed: Fri Dec 9 18:01:31 2016 -0800

----------------------------------------------------------------------
 docs/contributors.yaml | 8 ++++++++
 1 file changed, 8 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/b31edd94/docs/contributors.yaml
----------------------------------------------------------------------
diff --git a/docs/contributors.yaml b/docs/contributors.yaml
index 753bd16..65f81d5 100644
--- a/docs/contributors.yaml
+++ b/docs/contributors.yaml
@@ -75,6 +75,14 @@
   jira_user: anandmazumdar
   reviewboard_user: anandmazumdar
 
+- name: Andrew Schwartzmeyer
+  affiliations:
+    - {organization: Microsoft}
+  emails:
+    - andrew@schwartzmeyer.com
+  jira_user: andschwa
+  reviewboard_user: andschwa
+
 - name: Andrey Dyatlov
   affiliations:
     - {organization: Mesosphere}


[06/12] mesos git commit: Removed the UUID from IO Switchboard tests.

Posted by jo...@apache.org.
Removed the UUID from IO Switchboard tests.

The IO switchboard server creates a UNIX socket at a given path.
Due to OS constraints, this path must be less than 104 characters long.

In the tests, the path is set to a value based on the test directory.
If the test directory is too long, the UNIX socket creation will fail,
as observed in OSX, where the standard temporary directory does not
default to `/tmp` (as is the case on most Linux's).

The test directory was changed to provide platform-specific values
in this review:
https://reviews.apache.org/r/54490/

This commit shortens the UNIX socket address by removing the UUID.
This is safe because we are not running multiple IO switchboards
in the same test, in the same directory.


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/3511b540
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/3511b540
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/3511b540

Branch: refs/heads/master
Commit: 3511b5407710e9a0d0a668ce1663a8d89cc028ca
Parents: 883f5d2
Author: Joseph Wu <jo...@apache.org>
Authored: Fri Dec 9 17:50:38 2016 -0800
Committer: Joseph Wu <jo...@apache.org>
Committed: Fri Dec 9 18:01:32 2016 -0800

----------------------------------------------------------------------
 src/tests/containerizer/io_switchboard_tests.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/3511b540/src/tests/containerizer/io_switchboard_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/io_switchboard_tests.cpp b/src/tests/containerizer/io_switchboard_tests.cpp
index 7a90262..ecadeee 100644
--- a/src/tests/containerizer/io_switchboard_tests.cpp
+++ b/src/tests/containerizer/io_switchboard_tests.cpp
@@ -118,7 +118,7 @@ TEST_F(IOSwitchboardServerTest, RedirectLog)
 
   string socketPath = path::join(
       sandbox.get(),
-      "mesos-io-switchboard-" + UUID::random().toString());
+      "mesos-io-switchboard");
 
   Try<Owned<IOSwitchboardServer>> server = IOSwitchboardServer::create(
       false,
@@ -226,7 +226,7 @@ TEST_F(IOSwitchboardServerTest, AttachOutput)
 
   string socketPath = path::join(
       sandbox.get(),
-      "mesos-io-switchboard-" + UUID::random().toString());
+      "mesos-io-switchboard");
 
   Try<Owned<IOSwitchboardServer>> server = IOSwitchboardServer::create(
       false,
@@ -348,7 +348,7 @@ TEST_F(IOSwitchboardServerTest, AttachInput)
 
   string socketPath = path::join(
       sandbox.get(),
-      "mesos-io-switchboard-" + UUID::random().toString());
+      "mesos-io-switchboard");
 
   Try<Owned<IOSwitchboardServer>> server = IOSwitchboardServer::create(
       false,


[08/12] mesos git commit: Parametrized libprocess HTTPTests by SSL configuration.

Posted by jo...@apache.org.
Parametrized libprocess HTTPTests by SSL configuration.

This patch parametrizes the HTTP tests in libprocess so
that they run with SSL both enabled and disabled when
the library is compiled with SSL support.

Review: https://reviews.apache.org/r/50737/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/f61f321b
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/f61f321b
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/f61f321b

Branch: refs/heads/master
Commit: f61f321b4df8291274a2e84e8cf9df3cb2fe0c2a
Parents: b531b01
Author: Greg Mann <gr...@mesosphere.io>
Authored: Fri Dec 9 16:42:02 2016 -0800
Committer: Joseph Wu <jo...@apache.org>
Committed: Fri Dec 9 18:01:32 2016 -0800

----------------------------------------------------------------------
 3rdparty/libprocess/src/tests/http_tests.cpp | 174 ++++++++++++++++------
 1 file changed, 132 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/f61f321b/3rdparty/libprocess/src/tests/http_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/tests/http_tests.cpp b/3rdparty/libprocess/src/tests/http_tests.cpp
index f4c5dd6..822cdb3 100644
--- a/3rdparty/libprocess/src/tests/http_tests.cpp
+++ b/3rdparty/libprocess/src/tests/http_tests.cpp
@@ -36,11 +36,14 @@
 #include <process/owned.hpp>
 #include <process/socket.hpp>
 
+#include <process/ssl/gtest.hpp>
+
 #include <stout/base64.hpp>
 #include <stout/gtest.hpp>
 #include <stout/hashset.hpp>
 #include <stout/none.hpp>
 #include <stout/nothing.hpp>
+#include <stout/option.hpp>
 #include <stout/os.hpp>
 #include <stout/stringify.hpp>
 
@@ -64,6 +67,8 @@ using process::Owned;
 using process::PID;
 using process::Process;
 using process::Promise;
+using process::READONLY_HTTP_AUTHENTICATION_REALM;
+using process::READWRITE_HTTP_AUTHENTICATION_REALM;
 
 using process::http::URL;
 
@@ -79,6 +84,18 @@ using testing::DoAll;
 using testing::EndsWith;
 using testing::Invoke;
 using testing::Return;
+using testing::WithParamInterface;
+
+namespace process {
+
+// We need to reinitialize libprocess in order to test against different
+// configurations, such as when libprocess is initialized with SSL enabled.
+void reinitialize(
+    const Option<string>& delegate,
+    const Option<string>& readonlyAuthenticationRealm,
+    const Option<string>& readwriteAuthenticationRealm);
+
+} // namespace process {
 
 class HttpProcess : public Process<HttpProcess>
 {
@@ -139,10 +156,64 @@ public:
 };
 
 
+// Parametrize the tests with the scheme to be used for HTTP connections.
+class HTTPTest : public SSLTemporaryDirectoryTest,
+                 public WithParamInterface<string>
+{
+// These are only needed if libprocess is compiled with SSL support.
+#ifdef USE_SSL_SOCKET
+protected:
+  virtual void SetUp()
+  {
+    // We must run the parent's `SetUp` first so that we `chdir` into the test
+    // directory before SSL helpers like `key_path()` are called.
+    SSLTemporaryDirectoryTest::SetUp();
+
+    if (GetParam() == "https") {
+      generate_keys_and_certs();
+      set_environment_variables({
+          {"LIBPROCESS_SSL_ENABLED", "true"},
+          {"LIBPROCESS_SSL_KEY_FILE", key_path()},
+          {"LIBPROCESS_SSL_CERT_FILE", certificate_path()}});
+    } else {
+      set_environment_variables({});
+    }
+
+    process::reinitialize(
+        None(),
+        READWRITE_HTTP_AUTHENTICATION_REALM,
+        READONLY_HTTP_AUTHENTICATION_REALM);
+  }
+
+public:
+  static void TearDownTestCase()
+  {
+    set_environment_variables({});
+    process::reinitialize(
+        None(),
+        READWRITE_HTTP_AUTHENTICATION_REALM,
+        READONLY_HTTP_AUTHENTICATION_REALM);
+
+    SSLTemporaryDirectoryTest::TearDownTestCase();
+  }
+#endif // USE_SSL_SOCKET
+};
+
+
+INSTANTIATE_TEST_CASE_P(
+    Scheme,
+    HTTPTest,
+    ::testing::Values(
+#ifdef USE_SSL_SOCKET
+        string("https"),
+#endif // USE_SSL_SOCKET
+        string("http")));
+
+
 // TODO(vinod): Use AWAIT_EXPECT_RESPONSE_STATUS_EQ in the tests.
 
 
-TEST(HTTPTest, Endpoints)
+TEST_P(HTTPTest, Endpoints)
 {
   Http http;
 
@@ -182,7 +253,8 @@ TEST(HTTPTest, Endpoints)
     .WillOnce(DoAll(FutureSatisfy(&request),
                     Return(ok)));
 
-  Future<http::Response> future = http::get(http.process->self(), "pipe");
+  Future<http::Response> future =
+    http::get(http.process->self(), "pipe", None(), None(), GetParam());
 
   AWAIT_READY(request);
 
@@ -202,7 +274,7 @@ TEST(HTTPTest, Endpoints)
   EXPECT_CALL(*http.process, body(_))
     .WillOnce(Return(Future<http::Response>::failed("failure")));
 
-  future = http::get(http.process->self(), "body");
+  future = http::get(http.process->self(), "body", None(), None(), GetParam());
 
   AWAIT_ASSERT_RESPONSE_STATUS_EQ(http::InternalServerError().status, future);
   EXPECT_EQ("failure", future->body);
@@ -212,7 +284,7 @@ TEST(HTTPTest, Endpoints)
 // TODO(hausdorff): Routing logic is broken on Windows. Fix and enable test. In
 // this case, the '/help/(14)/body' route is missing, but the /help/(14) route
 // exists. See MESOS-5904.
-TEST_TEMP_DISABLED_ON_WINDOWS(HTTPTest, EndpointsHelp)
+TEST_P_TEMP_DISABLED_ON_WINDOWS(HTTPTest, EndpointsHelp)
 {
   Http http;
   PID<HttpProcess> pid = http.process->self();
@@ -225,7 +297,7 @@ TEST_TEMP_DISABLED_ON_WINDOWS(HTTPTest, EndpointsHelp)
 
   // Hit '/help' and wait for a 200 OK response.
   http::URL url = http::URL(
-      "http",
+      GetParam(),
       http.process->self().address.ip,
       http.process->self().address.port,
       "/help");
@@ -238,7 +310,7 @@ TEST_TEMP_DISABLED_ON_WINDOWS(HTTPTest, EndpointsHelp)
 
   // Hit '/help?format=json' and wait for a 200 OK response.
   url = http::URL(
-      "http",
+      GetParam(),
       http.process->self().address.ip,
       http.process->self().address.port,
       "/help",
@@ -255,7 +327,7 @@ TEST_TEMP_DISABLED_ON_WINDOWS(HTTPTest, EndpointsHelp)
 
   // Hit '/help/<id>/body' and wait for a 200 OK response.
   url = http::URL(
-      "http",
+      GetParam(),
       http.process->self().address.ip,
       http.process->self().address.port,
       "/help/" + pid.id + "/body");
@@ -268,7 +340,7 @@ TEST_TEMP_DISABLED_ON_WINDOWS(HTTPTest, EndpointsHelp)
 
   // Hit '/help/<id>/a/b/c' and wait for a 200 OK response.
   url = http::URL(
-      "http",
+      GetParam(),
       http.process->self().address.ip,
       http.process->self().address.port,
       "/help/" + pid.id + "/a/b/c");
@@ -284,7 +356,7 @@ TEST_TEMP_DISABLED_ON_WINDOWS(HTTPTest, EndpointsHelp)
 // TODO(hausdorff): Routing logic is broken on Windows. Fix and enable test. In
 // this case, the '/help/(14)/body' route is missing, but the /help/(14) route
 // exists. See MESOS-5904.
-TEST_TEMP_DISABLED_ON_WINDOWS(HTTPTest, EndpointsHelpRemoval)
+TEST_P_TEMP_DISABLED_ON_WINDOWS(HTTPTest, EndpointsHelpRemoval)
 {
   // Start up a new HttpProcess;
   Owned<Http> http(new Http());
@@ -298,7 +370,7 @@ TEST_TEMP_DISABLED_ON_WINDOWS(HTTPTest, EndpointsHelpRemoval)
 
   // Hit '/help/<id>/body' and wait for a 200 OK response.
   http::URL url = http::URL(
-      "http",
+      GetParam(),
       http->process->self().address.ip,
       http->process->self().address.port,
       "/help/" + pid.id + "/body");
@@ -315,7 +387,7 @@ TEST_TEMP_DISABLED_ON_WINDOWS(HTTPTest, EndpointsHelpRemoval)
 
   // Hit '/help/<id>/bogus' and wait for a 400 BAD REQUEST response.
   url = http::URL(
-      "http",
+      GetParam(),
       process::address().ip,
       process::address().port,
       "/help/" + pid.id + "/bogus");
@@ -328,7 +400,7 @@ TEST_TEMP_DISABLED_ON_WINDOWS(HTTPTest, EndpointsHelpRemoval)
 }
 
 
-TEST(HTTPTest, PipeEOF)
+TEST_P(HTTPTest, PipeEOF)
 {
   http::Pipe pipe;
   http::Pipe::Reader reader = pipe.reader();
@@ -378,7 +450,7 @@ TEST(HTTPTest, PipeEOF)
 }
 
 
-TEST(HTTPTest, PipeFailure)
+TEST_P(HTTPTest, PipeFailure)
 {
   http::Pipe pipe;
   http::Pipe::Reader reader = pipe.reader();
@@ -449,7 +521,7 @@ TEST(HTTPTest, PipeReadAll)
 }
 
 
-TEST(HTTPTest, PipeReaderCloses)
+TEST_P(HTTPTest, PipeReaderCloses)
 {
   http::Pipe pipe;
   http::Pipe::Reader reader = pipe.reader();
@@ -483,7 +555,7 @@ TEST(HTTPTest, PipeReaderCloses)
 }
 
 
-TEST(HTTPTest, Encode)
+TEST_P(HTTPTest, Encode)
 {
   string unencoded = "a$&+,/:;=?@ \"<>#%{}|\\^~[]`\x19\x80\xFF";
   unencoded += string("\x00", 1); // Add a null byte to the end.
@@ -507,7 +579,7 @@ TEST(HTTPTest, Encode)
 }
 
 
-TEST(HTTPTest, PathParse)
+TEST_P(HTTPTest, PathParse)
 {
   const string pattern = "/books/{isbn}/chapters/{chapter}";
 
@@ -580,14 +652,15 @@ http::Response validateGetWithQuery(const http::Request& request)
 }
 
 
-TEST(HTTPTest, Get)
+TEST_P(HTTPTest, Get)
 {
   Http http;
 
   EXPECT_CALL(*http.process, get(_))
     .WillOnce(Invoke(validateGetWithoutQuery));
 
-  Future<http::Response> noQueryFuture = http::get(http.process->self(), "get");
+  Future<http::Response> noQueryFuture =
+    http::get(http.process->self(), "get", None(), None(), GetParam());
 
   AWAIT_READY(noQueryFuture);
   EXPECT_EQ(http::Status::OK, noQueryFuture->code);
@@ -597,7 +670,7 @@ TEST(HTTPTest, Get)
     .WillOnce(Invoke(validateGetWithQuery));
 
   Future<http::Response> queryFuture =
-    http::get(http.process->self(), "get", "foo=bar");
+    http::get(http.process->self(), "get", "foo=bar", None(), GetParam());
 
   AWAIT_READY(queryFuture);
   ASSERT_EQ(http::Status::OK, queryFuture->code);
@@ -608,7 +681,7 @@ TEST(HTTPTest, Get)
 // TODO(hausdorff): Routing logic is broken on Windows. Fix and enable test. In
 // this case, the route '/a/b/c' exists and returns 200 ok, but '/a/b' does
 // not. See MESOS-5904.
-TEST_TEMP_DISABLED_ON_WINDOWS(HTTPTest, NestedGet)
+TEST_P_TEMP_DISABLED_ON_WINDOWS(HTTPTest, NestedGet)
 {
   Http http;
 
@@ -619,7 +692,8 @@ TEST_TEMP_DISABLED_ON_WINDOWS(HTTPTest, NestedGet)
     .WillOnce(Return(http::OK()));
 
   // The handler for "/a/b/c" should return 'http::OK()'.
-  Future<http::Response> response = http::get(http.process->self(), "/a/b/c");
+  Future<http::Response> response =
+    http::get(http.process->self(), "/a/b/c", None(), None(), GetParam());
 
   AWAIT_READY(response);
   ASSERT_EQ(http::Status::OK, response->code);
@@ -627,7 +701,8 @@ TEST_TEMP_DISABLED_ON_WINDOWS(HTTPTest, NestedGet)
 
   // "/a/b" should be handled by "/a" handler and return
   // 'http::Accepted()'.
-  response = http::get(http.process->self(), "/a/b");
+  response =
+    http::get(http.process->self(), "/a/b", None(), None(), GetParam());
 
   AWAIT_READY(response);
   ASSERT_EQ(http::Status::ACCEPTED, response->code);
@@ -635,7 +710,7 @@ TEST_TEMP_DISABLED_ON_WINDOWS(HTTPTest, NestedGet)
 }
 
 
-TEST(HTTPTest, StreamingGetComplete)
+TEST_P(HTTPTest, StreamingGetComplete)
 {
   Http http;
 
@@ -647,8 +722,8 @@ TEST(HTTPTest, StreamingGetComplete)
   EXPECT_CALL(*http.process, pipe(_))
     .WillOnce(Return(ok));
 
-  Future<http::Response> response =
-    http::streaming::get(http.process->self(), "pipe");
+  Future<http::Response> response = http::streaming::get(
+      http.process->self(), "pipe", None(), None(), GetParam());
 
   // The response should be ready since the headers were sent.
   AWAIT_READY(response);
@@ -677,7 +752,7 @@ TEST(HTTPTest, StreamingGetComplete)
 }
 
 
-TEST(HTTPTest, StreamingGetFailure)
+TEST_P(HTTPTest, StreamingGetFailure)
 {
   Http http;
 
@@ -689,8 +764,8 @@ TEST(HTTPTest, StreamingGetFailure)
   EXPECT_CALL(*http.process, pipe(_))
     .WillOnce(Return(ok));
 
-  Future<http::Response> response =
-    http::streaming::get(http.process->self(), "pipe");
+  Future<http::Response> response = http::streaming::get(
+      http.process->self(), "pipe", None(), None(), GetParam());
 
   // The response should be ready since the headers were sent.
   AWAIT_READY(response);
@@ -719,7 +794,7 @@ TEST(HTTPTest, StreamingGetFailure)
 }
 
 
-TEST(HTTPTest, PipeEquality)
+TEST_P(HTTPTest, PipeEquality)
 {
   // Pipes are shared objects, like Futures. Copies are considered
   // equal as they point to the same underlying object.
@@ -751,13 +826,18 @@ http::Response validatePost(const http::Request& request)
 }
 
 
-TEST(HTTPTest, Post)
+TEST_P(HTTPTest, Post)
 {
   Http http;
 
   // Test the case where there is a content type but no body.
-  Future<http::Response> future =
-    http::post(http.process->self(), "post", None(), None(), "text/plain");
+  Future<http::Response> future = http::post(
+      http.process->self(),
+      "post",
+      None(),
+      None(),
+      "text/plain",
+      GetParam());
 
   AWAIT_EXPECT_FAILED(future);
 
@@ -769,7 +849,8 @@ TEST(HTTPTest, Post)
       "post",
       None(),
       "This is the payload.",
-      "text/plain");
+      "text/plain",
+      GetParam());
 
   AWAIT_READY(future);
   ASSERT_EQ(http::Status::OK, future->code);
@@ -782,8 +863,13 @@ TEST(HTTPTest, Post)
   EXPECT_CALL(*http.process, post(_))
     .WillOnce(Invoke(validatePost));
 
-  future =
-    http::post(http.process->self(), "post", headers, "This is the payload.");
+  future = http::post(
+      http.process->self(),
+      "post",
+      headers,
+      "This is the payload.",
+      None(),
+      GetParam());
 
   AWAIT_READY(future);
   ASSERT_EQ(http::Status::OK, future->code);
@@ -802,7 +888,7 @@ http::Response validateDelete(const http::Request& request)
 }
 
 
-TEST(HTTPTest, Delete)
+TEST_P(HTTPTest, Delete)
 {
   Http http;
 
@@ -810,7 +896,11 @@ TEST(HTTPTest, Delete)
     .WillOnce(Invoke(validateDelete));
 
   Future<http::Response> future =
-    http::requestDelete(http.process->self(), "delete", None());
+    http::requestDelete(
+        http.process->self(),
+        "delete",
+        None(),
+        GetParam());
 
   AWAIT_READY(future);
   ASSERT_EQ(http::Status::OK, future->code);
@@ -829,7 +919,7 @@ http::Response validateDeleteHttpRequest(const http::Request& request)
 }
 
 
-TEST(HTTPTest, Request)
+TEST_P(HTTPTest, Request)
 {
   Http http;
 
@@ -838,7 +928,7 @@ TEST(HTTPTest, Request)
 
   Future<http::Response> future =
     http::request(http::createRequest(
-        http.process->self(), "DELETE", false, "request"));
+        http.process->self(), "DELETE", GetParam() == "https", "request"));
 
   AWAIT_READY(future);
   ASSERT_EQ(http::Status::OK, future->code);
@@ -1303,7 +1393,7 @@ TEST(HTTPConnectionTest, RequestStreaming)
 // incorrect) results across platforms. Fix and enable the test on Windows. In
 // particular, the encoding in the 3rd example puts the first variable into the
 // query string before the second, but we expect the reverse. See MESOS-5814.
-TEST_TEMP_DISABLED_ON_WINDOWS(HTTPTest, QueryEncodeDecode)
+TEST_P_TEMP_DISABLED_ON_WINDOWS(HTTPTest, QueryEncodeDecode)
 {
   // If we use Type<a, b> directly inside a macro without surrounding
   // parenthesis the comma will be eaten by the macro rather than the
@@ -1344,7 +1434,7 @@ TEST_TEMP_DISABLED_ON_WINDOWS(HTTPTest, QueryEncodeDecode)
 }
 
 
-TEST(HTTPTest, CaseInsensitiveHeaders)
+TEST_P(HTTPTest, CaseInsensitiveHeaders)
 {
   http::Request request;
   request.headers["Content-Length"] = "20";
@@ -1370,7 +1460,7 @@ TEST(HTTPTest, CaseInsensitiveHeaders)
 }
 
 
-TEST(HTTPTest, Accepts)
+TEST_P(HTTPTest, Accepts)
 {
   // Create requests that do not accept the 'text/*' media type.
   vector<string> headers = {


[04/12] mesos git commit: Stout: Moved `os::getenv` from `os.hpp` to `os/getenv.hpp`.

Posted by jo...@apache.org.
Stout: Moved `os::getenv` from `os.hpp` to `os/getenv.hpp`.

This commit moves `os::getenv` to its own file under the `stout/os/`
directory in preparation for a functional change to `os::temp`;
which should look for the standard environment variable `TMPDIR`
before falling back to `/tmp` on POSIX environments.

In other words, `stout/os/temp.hpp` needs to call `os::getenv`, but
doing so prior to this commit would introduce a circular header
dependency with `stout/os.hpp`.  (`stout/os.hpp` aggregates all header
files in `stout/os/` and therefore, no files in `stout/os/` should be
taking a dependency on it.)

Review: https://reviews.apache.org/r/54519/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/b9ef614c
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/b9ef614c
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/b9ef614c

Branch: refs/heads/master
Commit: b9ef614c53373fdc3aadc0f237e7533b1d2a7209
Parents: b31edd9
Author: Alex Clemmer <cl...@gmail.com>
Authored: Thu Dec 8 17:18:01 2016 -0800
Committer: Joseph Wu <jo...@apache.org>
Committed: Fri Dec 9 18:01:31 2016 -0800

----------------------------------------------------------------------
 3rdparty/stout/include/Makefile.am              |  3 +
 3rdparty/stout/include/stout/os.hpp             |  1 +
 3rdparty/stout/include/stout/os/getenv.hpp      | 23 ++++++++
 .../stout/include/stout/os/posix/getenv.hpp     | 42 ++++++++++++++
 .../stout/include/stout/os/windows/getenv.hpp   | 58 ++++++++++++++++++++
 3rdparty/stout/include/stout/posix/os.hpp       | 15 -----
 3rdparty/stout/include/stout/windows/os.hpp     | 26 ---------
 7 files changed, 127 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/b9ef614c/3rdparty/stout/include/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/Makefile.am b/3rdparty/stout/include/Makefile.am
index fc020bb..56c4491 100644
--- a/3rdparty/stout/include/Makefile.am
+++ b/3rdparty/stout/include/Makefile.am
@@ -67,6 +67,7 @@ nobase_include_HEADERS =			\
   stout/os/environment.hpp			\
   stout/os/exists.hpp				\
   stout/os/fcntl.hpp				\
+  stout/os/getenv.hpp				\
   stout/os/find.hpp				\
   stout/os/fork.hpp				\
   stout/os/freebsd.hpp				\
@@ -115,6 +116,7 @@ nobase_include_HEADERS =			\
   stout/os/posix/fork.hpp			\
   stout/os/posix/fsync.hpp			\
   stout/os/posix/ftruncate.hpp			\
+  stout/os/posix/getenv.hpp			\
   stout/os/posix/kill.hpp			\
   stout/os/posix/killtree.hpp			\
   stout/os/posix/mkdtemp.hpp			\
@@ -142,6 +144,7 @@ nobase_include_HEADERS =			\
   stout/os/windows/fork.hpp			\
   stout/os/windows/fsync.hpp			\
   stout/os/windows/ftruncate.hpp		\
+  stout/os/windows/getenv.hpp			\
   stout/os/windows/kill.hpp			\
   stout/os/windows/killtree.hpp			\
   stout/os/windows/mkdtemp.hpp			\

http://git-wip-us.apache.org/repos/asf/mesos/blob/b9ef614c/3rdparty/stout/include/stout/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os.hpp b/3rdparty/stout/include/stout/os.hpp
index cdcbbf4..63265ee 100644
--- a/3rdparty/stout/include/stout/os.hpp
+++ b/3rdparty/stout/include/stout/os.hpp
@@ -48,6 +48,7 @@
 #include <stout/os/chroot.hpp>
 #include <stout/os/exists.hpp>
 #include <stout/os/fcntl.hpp>
+#include <stout/os/getenv.hpp>
 #include <stout/os/kill.hpp>
 #include <stout/os/ls.hpp>
 #include <stout/os/mkdir.hpp>

http://git-wip-us.apache.org/repos/asf/mesos/blob/b9ef614c/3rdparty/stout/include/stout/os/getenv.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/getenv.hpp b/3rdparty/stout/include/stout/os/getenv.hpp
new file mode 100644
index 0000000..624621b
--- /dev/null
+++ b/3rdparty/stout/include/stout/os/getenv.hpp
@@ -0,0 +1,23 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//  http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __STOUT_OS_GETENV_HPP__
+#define __STOUT_OS_GETENV_HPP__
+
+
+#ifdef __WINDOWS__
+#include <stout/os/windows/getenv.hpp>
+#else
+#include <stout/os/posix/getenv.hpp>
+#endif // __WINDOWS__
+
+#endif // __STOUT_OS_GETENV_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/b9ef614c/3rdparty/stout/include/stout/os/posix/getenv.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/posix/getenv.hpp b/3rdparty/stout/include/stout/os/posix/getenv.hpp
new file mode 100644
index 0000000..bb3cd93
--- /dev/null
+++ b/3rdparty/stout/include/stout/os/posix/getenv.hpp
@@ -0,0 +1,42 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//  http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __STOUT_OS_POSIX_GETENV_HPP__
+#define __STOUT_OS_POSIX_GETENV_HPP__
+
+#include <stdlib.h>
+
+#include <string>
+
+#include <stout/none.hpp>
+#include <stout/option.hpp>
+
+
+namespace os {
+
+// Looks in the environment variables for the specified key and
+// 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 (value == nullptr) {
+    return None();
+  }
+
+  return std::string(value);
+}
+
+} // namespace os {
+
+#endif // __STOUT_OS_POSIX_GETENV_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/b9ef614c/3rdparty/stout/include/stout/os/windows/getenv.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/getenv.hpp b/3rdparty/stout/include/stout/os/windows/getenv.hpp
new file mode 100644
index 0000000..2200f85
--- /dev/null
+++ b/3rdparty/stout/include/stout/os/windows/getenv.hpp
@@ -0,0 +1,58 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//  http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __STOUT_OS_WINDOWS_GETENV_HPP__
+#define __STOUT_OS_WINDOWS_GETENV_HPP__
+
+#include <memory>
+#include <string>
+
+#include <stout/none.hpp>
+#include <stout/option.hpp>
+#include <stout/windows.hpp>
+
+
+namespace os {
+
+// Looks in the environment variables for the specified key and
+// 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)
+{
+  // NOTE: The double-call to `::GetEnvironmentVariable` here uses the first
+  // call to get the size of the variable's value, and then again to retrieve
+  // the value itself. It is possible to have `::GetEnvironmentVariable`
+  // allocate the space for this, but we explicitly do it this way to avoid
+  // that.
+  DWORD buffer_size = ::GetEnvironmentVariable(key.c_str(), nullptr, 0);
+  if (buffer_size == 0) {
+    return None();
+  }
+
+  std::unique_ptr<char[]> environment(new char[buffer_size]);
+
+  DWORD value_size =
+    ::GetEnvironmentVariable(key.c_str(), environment.get(), buffer_size);
+
+  if (value_size == 0) {
+    // If `value_size == 0` here, that probably means the environment variable
+    // was deleted between when we checked and when we allocated the buffer. We
+    // report `None` to indicate the environment variable was not found.
+    return None();
+  }
+
+  return std::string(environment.get());
+}
+
+} // namespace os {
+
+#endif // __STOUT_OS_WINDOWS_GETENV_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/b9ef614c/3rdparty/stout/include/stout/posix/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/posix/os.hpp b/3rdparty/stout/include/stout/posix/os.hpp
index 8443aa0..05d27a0 100644
--- a/3rdparty/stout/include/stout/posix/os.hpp
+++ b/3rdparty/stout/include/stout/posix/os.hpp
@@ -362,21 +362,6 @@ inline Try<std::set<pid_t>> pids(Option<pid_t> group, Option<pid_t> session)
 }
 
 
-// Looks in the environment variables for the specified key and
-// 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 (value == nullptr) {
-    return None();
-  }
-
-  return std::string(value);
-}
-
-
 // Creates a tar 'archive' with gzip compression, of the given 'path'.
 inline Try<Nothing> tar(const std::string& path, const std::string& archive)
 {

http://git-wip-us.apache.org/repos/asf/mesos/blob/b9ef614c/3rdparty/stout/include/stout/windows/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/windows/os.hpp b/3rdparty/stout/include/stout/windows/os.hpp
index 2f20ccc..51c8dcf 100644
--- a/3rdparty/stout/include/stout/windows/os.hpp
+++ b/3rdparty/stout/include/stout/windows/os.hpp
@@ -489,32 +489,6 @@ inline Try<UTSInfo> uname()
 }
 
 
-// Looks in the environment variables for the specified key and
-// 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)
-{
-  DWORD buffer_size = ::GetEnvironmentVariable(key.c_str(), nullptr, 0);
-  if (buffer_size == 0) {
-    return None();
-  }
-
-  std::unique_ptr<char[]> environment(new char[buffer_size]);
-
-  DWORD value_size =
-    ::GetEnvironmentVariable(key.c_str(), environment.get(), buffer_size);
-
-  if (value_size == 0) {
-    // If `value_size == 0` here, that probably means the environment variable
-    // was deleted between when we checked and when we allocated the buffer. We
-    // report `None` to indicate the environment variable was not found.
-    return None();
-  }
-
-  return std::string(environment.get());
-}
-
-
 inline tm* gmtime_r(const time_t* timep, tm* result)
 {
   return ::gmtime_s(result, timep) == ERROR_SUCCESS ? result : nullptr;


[07/12] mesos git commit: Added SSL support to libprocess HTTP request helpers.

Posted by jo...@apache.org.
Added SSL support to libprocess HTTP request helpers.

In order to test libprocess HTTP functionality with SSL
both enabled and disabled, the HTTP helper functions that
libprocess uses in tests must be parametrized by SSL
configuration.

The HTTP/HTTPS scheme appears as the last argument in these helpers
because it is the least commonly changed part of the URL.
Most tests that do not exercise SSL will suffice with a default.

Review: https://reviews.apache.org/r/50736/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/ba5317ba
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/ba5317ba
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/ba5317ba

Branch: refs/heads/master
Commit: ba5317ba4a07d28b256b5faab2aa6c503260c3ec
Parents: 3511b54
Author: Greg Mann <gr...@mesosphere.io>
Authored: Fri Dec 9 16:24:50 2016 -0800
Committer: Joseph Wu <jo...@apache.org>
Committed: Fri Dec 9 18:01:32 2016 -0800

----------------------------------------------------------------------
 3rdparty/libprocess/include/process/http.hpp | 16 +++++---
 3rdparty/libprocess/src/http.cpp             | 47 +++++++++++++++++------
 2 files changed, 47 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/ba5317ba/3rdparty/libprocess/include/process/http.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/http.hpp b/3rdparty/libprocess/include/process/http.hpp
index 7f44292..22fa31d 100644
--- a/3rdparty/libprocess/include/process/http.hpp
+++ b/3rdparty/libprocess/include/process/http.hpp
@@ -981,7 +981,8 @@ Future<Response> get(
     const UPID& upid,
     const Option<std::string>& path = None(),
     const Option<std::string>& query = None(),
-    const Option<Headers>& headers = None());
+    const Option<Headers>& headers = None(),
+    const Option<std::string>& scheme = None());
 
 
 // Asynchronously sends an HTTP POST request to the specified URL
@@ -1002,7 +1003,8 @@ Future<Response> post(
     const Option<std::string>& path = None(),
     const Option<Headers>& headers = None(),
     const Option<std::string>& body = None(),
-    const Option<std::string>& contentType = None());
+    const Option<std::string>& contentType = None(),
+    const Option<std::string>& scheme = None());
 
 
 /**
@@ -1026,12 +1028,14 @@ Future<Response> requestDelete(
  * @param path The optional path to be be deleted. If not send the
      request is send to the process directly.
  * @param headers Optional headers for the request.
+ * @param scheme Optional scheme for the request.
  * @return A future with the HTTP response.
  */
 Future<Response> requestDelete(
     const UPID& upid,
     const Option<std::string>& path = None(),
-    const Option<Headers>& headers = None());
+    const Option<Headers>& headers = None(),
+    const Option<std::string>& scheme = None());
 
 
 namespace streaming {
@@ -1052,7 +1056,8 @@ Future<Response> get(
     const UPID& upid,
     const Option<std::string>& path = None(),
     const Option<std::string>& query = None(),
-    const Option<Headers>& headers = None());
+    const Option<Headers>& headers = None(),
+    const Option<std::string>& scheme = None());
 
 // Asynchronously sends an HTTP POST request to the specified URL
 // and returns the HTTP response of type 'PIPE' once the response
@@ -1073,7 +1078,8 @@ Future<Response> post(
     const Option<std::string>& path = None(),
     const Option<Headers>& headers = None(),
     const Option<std::string>& body = None(),
-    const Option<std::string>& contentType = None());
+    const Option<std::string>& contentType = None(),
+    const Option<std::string>& scheme = None());
 
 } // namespace streaming {
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/ba5317ba/3rdparty/libprocess/src/http.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/http.cpp b/3rdparty/libprocess/src/http.cpp
index fc55bda..c0eaeff 100644
--- a/3rdparty/libprocess/src/http.cpp
+++ b/3rdparty/libprocess/src/http.cpp
@@ -1864,7 +1864,7 @@ Request createRequest(
   const Option<string>& body,
   const Option<string>& contentType)
 {
-  string scheme = enableSSL ? "https" : "http";
+  const string scheme = enableSSL ? "https" : "http";
   URL url(scheme, net::IP(upid.address.ip), upid.address.port, upid.id);
 
   if (path.isSome()) {
@@ -1917,9 +1917,14 @@ Future<Response> get(
     const UPID& upid,
     const Option<string>& path,
     const Option<string>& query,
-    const Option<Headers>& headers)
+    const Option<Headers>& headers,
+    const Option<string>& scheme)
 {
-  URL url("http", net::IP(upid.address.ip), upid.address.port, upid.id);
+  URL url(
+      scheme.getOrElse("http"),
+      net::IP(upid.address.ip),
+      upid.address.port,
+      upid.id);
 
   if (path.isSome()) {
     // TODO(benh): Get 'query' and/or 'fragment' out of 'path'.
@@ -1977,9 +1982,14 @@ Future<Response> post(
     const Option<string>& path,
     const Option<Headers>& headers,
     const Option<string>& body,
-    const Option<string>& contentType)
+    const Option<string>& contentType,
+    const Option<string>& scheme)
 {
-  URL url("http", net::IP(upid.address.ip), upid.address.port, upid.id);
+  URL url(
+      scheme.getOrElse("http"),
+      net::IP(upid.address.ip),
+      upid.address.port,
+      upid.id);
 
   if (path.isSome()) {
     // TODO(benh): Get 'query' and/or 'fragment' out of 'path'.
@@ -2010,9 +2020,14 @@ Future<Response> requestDelete(
 Future<Response> requestDelete(
     const UPID& upid,
     const Option<string>& path,
-    const Option<Headers>& headers)
+    const Option<Headers>& headers,
+    const Option<string>& scheme)
 {
-  URL url("http", net::IP(upid.address.ip), upid.address.port, upid.id);
+  URL url(
+      scheme.getOrElse("http"),
+      net::IP(upid.address.ip),
+      upid.address.port,
+      upid.id);
 
   if (path.isSome()) {
     // TODO(joerg84): Handle 'query' and/or 'fragment' in 'path'.
@@ -2048,9 +2063,14 @@ Future<Response> get(
     const UPID& upid,
     const Option<string>& path,
     const Option<string>& query,
-    const Option<Headers>& headers)
+    const Option<Headers>& headers,
+    const Option<string>& scheme)
 {
-  URL url("http", net::IP(upid.address.ip), upid.address.port, upid.id);
+  URL url(
+      scheme.getOrElse("http"),
+      net::IP(upid.address.ip),
+      upid.address.port,
+      upid.id);
 
   if (path.isSome()) {
     // TODO(benh): Get 'query' and/or 'fragment' out of 'path'.
@@ -2108,9 +2128,14 @@ Future<Response> post(
     const Option<string>& path,
     const Option<Headers>& headers,
     const Option<string>& body,
-    const Option<string>& contentType)
+    const Option<string>& contentType,
+    const Option<string>& scheme)
 {
-  URL url("http", net::IP(upid.address.ip), upid.address.port, upid.id);
+  URL url(
+      scheme.getOrElse("http"),
+      net::IP(upid.address.ip),
+      upid.address.port,
+      upid.id);
 
   if (path.isSome()) {
     // TODO(benh): Get 'query' and/or 'fragment' out of 'path'.