You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by mp...@apache.org on 2016/04/10 01:18:44 UTC

[1/8] mesos git commit: CMake: Placed master files that moved into the correct directories.

Repository: mesos
Updated Branches:
  refs/heads/master d7e6a1413 -> 8c6a55d10


CMake: Placed master files that moved into the correct directories.

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


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

Branch: refs/heads/master
Commit: b93653f96ca4f00e71b02989cf759ac53668c9fa
Parents: d7e6a14
Author: Alex Clemmer <cl...@gmail.com>
Authored: Sat Apr 9 15:55:24 2016 -0700
Committer: Michael Park <mp...@apache.org>
Committed: Sat Apr 9 15:55:24 2016 -0700

----------------------------------------------------------------------
 src/CMakeLists.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/b93653f9/src/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 9a4cffa..ca59a18 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -199,8 +199,8 @@ set(LOGGING_SRC
   )
 
 set(MASTER_SRC
-  master/contender.cpp
-  master/detector.cpp
+  master/contender/contender.cpp
+  master/detector/detector.cpp
   master/flags.cpp
   master/http.cpp
   master/maintenance.cpp


[5/8] mesos git commit: Windows: Fixed `fs::list` to be more compliant with POSIX version.

Posted by mp...@apache.org.
Windows: Fixed `fs::list` to be more compliant with POSIX version.

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


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

Branch: refs/heads/master
Commit: 47bef6f96da51beae03afed5093236493c7ed3b5
Parents: e5af13d
Author: Alex Clemmer <cl...@gmail.com>
Authored: Sat Apr 9 15:56:17 2016 -0700
Committer: Michael Park <mp...@apache.org>
Committed: Sat Apr 9 15:58:35 2016 -0700

----------------------------------------------------------------------
 .../3rdparty/stout/include/stout/windows/fs.hpp       | 11 +++++++++--
 .../3rdparty/stout/tests/os/filesystem_tests.cpp      | 14 +++++++++++---
 2 files changed, 20 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/47bef6f9/3rdparty/libprocess/3rdparty/stout/include/stout/windows/fs.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/windows/fs.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/windows/fs.hpp
index 7dace7d..99887b1 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/windows/fs.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/windows/fs.hpp
@@ -88,16 +88,23 @@ inline Try<Nothing> symlink(
 // `/root/dir/subdir/*.txt` or `/root/dir/subdir/file?.txt`.
 inline Try<std::list<std::string>> list(const std::string& pattern)
 {
+  std::list<std::string> found_files;
   WIN32_FIND_DATA find_data;
   const HANDLE search_handle = ::FindFirstFile(pattern.c_str(), &find_data);
+
   if (search_handle == INVALID_HANDLE_VALUE) {
+    // For compliance with the POSIX implementation (which uses `::glob`),
+    // return an empty list instead of an error when the path does not exist.
+    int error = ::GetLastError();
+    if (error == ERROR_FILE_NOT_FOUND || error == ERROR_PATH_NOT_FOUND) {
+      return found_files;
+    }
+
     return WindowsError(
         "'fs::list' failed when searching for files with pattern '" +
         pattern + "'");
   }
 
-  std::list<std::string> found_files;
-
   do {
     const std::string current_file(find_data.cFileName);
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/47bef6f9/3rdparty/libprocess/3rdparty/stout/tests/os/filesystem_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/os/filesystem_tests.cpp b/3rdparty/libprocess/3rdparty/stout/tests/os/filesystem_tests.cpp
index 1336972..013b467 100644
--- a/3rdparty/libprocess/3rdparty/stout/tests/os/filesystem_tests.cpp
+++ b/3rdparty/libprocess/3rdparty/stout/tests/os/filesystem_tests.cpp
@@ -177,13 +177,21 @@ TEST_F(FsTest, List)
 
   // Search all files in folder
   Try<list<string>> allFiles = fs::list(path::join(testdir, "*"));
+  ASSERT_SOME(allFiles);
   EXPECT_EQ(3u, allFiles.get().size());
 
   // Search .jpg files in folder
   Try<list<string>> jpgFiles = fs::list(path::join(testdir, "*.jpg"));
+  ASSERT_SOME(jpgFiles);
   EXPECT_EQ(1u, jpgFiles.get().size());
 
-  // Search .txt files in folder
-  Try<list<string>> txtFiles = fs::list(path::join(testdir, "*.txt"));
-  EXPECT_EQ(2u, txtFiles.get().size());
+  // Search test*.txt files in folder
+  Try<list<string>> testTxtFiles = fs::list(path::join(testdir, "*.txt"));
+  ASSERT_SOME(testTxtFiles);
+  EXPECT_EQ(2u, testTxtFiles.get().size());
+
+  // Verify that we return empty list when we provide an invalid path.
+  Try<list<string>> noFiles = fs::list("this_path_does_not_exist");
+  ASSERT_SOME(noFiles);
+  EXPECT_EQ(0u, noFiles.get().size());
 }


[6/8] mesos git commit: Stout: Moved `os::libraries::` namespace back to `stout/os.hpp`.

Posted by mp...@apache.org.
Stout: Moved `os::libraries::` namespace back to `stout/os.hpp`.

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


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

Branch: refs/heads/master
Commit: 1ffa4838846591036a343b444d659127269ecfb1
Parents: d80f9ce
Author: Alex Clemmer <cl...@gmail.com>
Authored: Sat Apr 9 15:55:57 2016 -0700
Committer: Michael Park <mp...@apache.org>
Committed: Sat Apr 9 15:58:35 2016 -0700

----------------------------------------------------------------------
 .../3rdparty/stout/include/stout/os.hpp         | 79 ++++++++++++++++++++
 .../3rdparty/stout/include/stout/posix/os.hpp   | 60 ---------------
 2 files changed, 79 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/1ffa4838/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 79e30ca..06bf04e 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
@@ -67,4 +67,83 @@
 #include <stout/posix/os.hpp>
 #endif // __WINDOWS__
 
+
+namespace os {
+namespace libraries {
+namespace Library {
+
+// Library prefix; e.g., the `lib` in `libprocess`. NOTE: there is no prefix
+// on Windows; `libprocess.a` would be `process.lib`.
+constexpr const char* prefix =
+#ifdef __WINDOWS__
+    "";
+#else
+    "lib";
+#endif // __WINDOWS__
+
+
+// The suffix for a shared library; e.g., `.so` on Linux.
+constexpr const char* extension =
+#ifdef __APPLE__
+    ".dylib";
+#elif defined(__WINDOWS__)
+    ".dll";
+#else
+    ".so";
+#endif // __APPLE__
+
+
+// The name of the environment variable that contains paths on which the
+// linker should search for libraries. NOTE: Windows does not have an
+// environment variable that controls the paths the linker searches through.
+constexpr const char* ldPathEnvironmentVariable =
+#ifdef __APPLE__
+    "DYLD_LIBRARY_PATH";
+#elif defined(__WINDOWS__)
+    "";
+#else
+    "LD_LIBRARY_PATH";
+#endif
+
+} // namespace Library {
+
+// Returns the full library name by adding prefix and extension to
+// library name.
+inline std::string expandName(const std::string& libraryName)
+{
+  return Library::prefix + libraryName + Library::extension;
+}
+
+
+// Returns the current value of LD_LIBRARY_PATH environment variable.
+inline std::string paths()
+{
+  const Option<std::string> path = getenv(Library::ldPathEnvironmentVariable);
+  return path.isSome() ? path.get() : std::string();
+}
+
+
+// Updates the value of LD_LIBRARY_PATH environment variable.
+// Note that setPaths has an effect only for child processes
+// launched after calling it.
+inline void setPaths(const std::string& newPaths)
+{
+  os::setenv(Library::ldPathEnvironmentVariable, newPaths);
+}
+
+
+// Append newPath to the current value of LD_LIBRARY_PATH environment
+// variable.
+inline void appendPaths(const std::string& newPaths)
+{
+  if (paths().empty()) {
+    setPaths(newPaths);
+  } else {
+    setPaths(paths() + ":" + newPaths);
+  }
+}
+
+} // namespace libraries {
+} // namespace os {
+
 #endif // __STOUT_OS_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/1ffa4838/3rdparty/libprocess/3rdparty/stout/include/stout/posix/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/posix/os.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/posix/os.hpp
index edaa76a..e25d43b 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/posix/os.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/posix/os.hpp
@@ -470,66 +470,6 @@ inline int pagesize()
   return sysconf(_SC_PAGESIZE);
 }
 
-namespace libraries {
-
-// Returns the full library name by adding prefix and extension to
-// library name.
-inline std::string expandName(const std::string& libraryName)
-{
-  const char* prefix = "lib";
-  const char* extension =
-#ifdef __APPLE__
-    ".dylib";
-#else
-    ".so";
-#endif
-
-  return prefix + libraryName + extension;
-}
-
-
-// Returns the current value of LD_LIBRARY_PATH environment variable.
-inline std::string paths()
-{
-  const char* environmentVariable =
-#ifdef __APPLE__
-    "DYLD_LIBRARY_PATH";
-#else
-    "LD_LIBRARY_PATH";
-#endif
-  const Option<std::string> path = getenv(environmentVariable);
-  return path.isSome() ? path.get() : std::string();
-}
-
-
-// Updates the value of LD_LIBRARY_PATH environment variable.
-// Note that setPaths has an effect only for child processes
-// launched after calling it.
-inline void setPaths(const std::string& newPaths)
-{
-  const char* environmentVariable =
-#ifdef __APPLE__
-    "DYLD_LIBRARY_PATH";
-#else
-    "LD_LIBRARY_PATH";
-#endif
-  setenv(environmentVariable, newPaths);
-}
-
-
-// Append newPath to the current value of LD_LIBRARY_PATH environment
-// variable.
-inline void appendPaths(const std::string& newPaths)
-{
-  if (paths().empty()) {
-    setPaths(newPaths);
-  } else {
-    setPaths(paths() + ":" + newPaths);
-  }
-}
-
-} // namespace libraries {
-
 /* /TODO */
 
 } // namespace os {


[7/8] mesos git commit: Agent: Fixed transitive #include problem in `load.cpp`.

Posted by mp...@apache.org.
Agent: Fixed transitive #include problem in `load.cpp`.

`qos_controllers/load.cpp` currently includes `stout/posix/os.hpp`
directly, which includes `killtree`, which includes `os.hpp`. When we
move `os::libraries` back to `os.hpp`, this will cause a problem,
because it will mean that `os::setenv` (which is defined further down in
`stout/posix/os.hpp` is not defined before
`os::libraries::Library::setPaths`, which uses it.

In general, this problem is usually caused by including something like
`stout/posix/os.hpp` instead of `os.hpp`. The choice to include such a
header is somewhat fraught, because many files in `os.hpp` (particularly
those that are included into `os.hpp` via a derivative, like
`posix/os.hpp`) have implicit dependencies on functions they `#include`
being defined before their code is defined. This issue will probably get
worse in the future. Furthermore, it is worth noting that the plan is
to, at some point, remove `os.hpp` altogether. Depending on the specific
implementation, this could make the "transitive #include problem" either
dramatically worse, or much better. This is a discussion the community
needs to have more braodly.

This commit will resovle the compile problem by removing `load.cpp`'s
explicit dependency on `os/os.hpp` and `posix/os.hpp`, and replacing
them with plain-old `stout/os.hpp`. As noted, however, this is really an
immediate solution to a larger problem, which we don't attempt to fully
address here.

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


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

Branch: refs/heads/master
Commit: d80f9ce36bb87b355f72a45163cb253c5d557222
Parents: fa72f74
Author: Alex Clemmer <cl...@gmail.com>
Authored: Sat Apr 9 15:55:45 2016 -0700
Committer: Michael Park <mp...@apache.org>
Committed: Sat Apr 9 15:58:35 2016 -0700

----------------------------------------------------------------------
 src/slave/qos_controllers/load.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/d80f9ce3/src/slave/qos_controllers/load.cpp
----------------------------------------------------------------------
diff --git a/src/slave/qos_controllers/load.cpp b/src/slave/qos_controllers/load.cpp
index dd44f92..31f6079 100644
--- a/src/slave/qos_controllers/load.cpp
+++ b/src/slave/qos_controllers/load.cpp
@@ -28,8 +28,7 @@
 #include <stout/lambda.hpp>
 #include <stout/numify.hpp>
 #include <stout/option.hpp>
-#include <stout/os/os.hpp>
-#include <stout/posix/os.hpp>
+#include <stout/os.hpp>
 #include <stout/result.hpp>
 
 #include "slave/qos_controllers/load.hpp"


[4/8] mesos git commit: Stout: Implemented `os::setenv` on Windows.

Posted by mp...@apache.org.
Stout: Implemented `os::setenv` on Windows.

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


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

Branch: refs/heads/master
Commit: fa72f74298a183c39cb53ddbfa65f038e27c6853
Parents: d5922af
Author: Alex Clemmer <cl...@gmail.com>
Authored: Sat Apr 9 15:55:40 2016 -0700
Committer: Michael Park <mp...@apache.org>
Committed: Sat Apr 9 15:58:35 2016 -0700

----------------------------------------------------------------------
 .../3rdparty/stout/include/stout/windows/os.hpp | 25 ++++++++++++++++----
 1 file changed, 20 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/fa72f742/3rdparty/libprocess/3rdparty/stout/include/stout/windows/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/windows/os.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/windows/os.hpp
index c48106e..e1a4557 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/windows/os.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/windows/os.hpp
@@ -45,17 +45,32 @@ inline int pagesize()
   return si.dwPageSize;
 }
 
-/*
+
 // Sets the value associated with the specified key in the set of
 // environment variables.
-inline void setenv(const std::string& key,
-                   const std::string& value,
-                   bool overwrite = true)
+inline void setenv(
+    const std::string& key,
+    const std::string& value,
+    bool overwrite = true)
 {
-  UNIMPLEMENTED;
+  // Do not set the variable if already set and `overwrite` was not specified.
+  //
+  // Per MSDN[1], `GetEnvironmentVariable` returns 0 on error and sets the
+  // error code to `ERROR_ENVVAR_NOT_FOUND` if the variable was not found.
+  //
+  // [1] https://msdn.microsoft.com/en-us/library/windows/desktop/ms683188(v=vs.85).aspx
+  if (!overwrite &&
+      ::GetEnvironmentVariable(key.c_str(), NULL, 0) != 0 &&
+      ::GetLastError() == ERROR_ENVVAR_NOT_FOUND) {
+    return;
+  }
+
+  // `SetEnvironmentVariable` returns an error code, but we can't act on it.
+  ::SetEnvironmentVariable(key.c_str(), value.c_str());
 }
 
 
+/*
 // Unsets the value associated with the specified key in the set of
 // environment variables.
 inline void unsetenv(const std::string& key)


[8/8] mesos git commit: Windows: Forked `os::rename()`.

Posted by mp...@apache.org.
Windows: Forked `os::rename()`.

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


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

Branch: refs/heads/master
Commit: 8c6a55d10a2dc30ba2ffe078105266f1ffa4727f
Parents: 47bef6f
Author: Alex Clemmer <cl...@gmail.com>
Authored: Sat Apr 9 15:56:24 2016 -0700
Committer: Michael Park <mp...@apache.org>
Committed: Sat Apr 9 15:58:36 2016 -0700

----------------------------------------------------------------------
 .../3rdparty/stout/include/Makefile.am          |  2 +
 .../3rdparty/stout/include/stout/os.hpp         |  2 +
 .../stout/include/stout/os/posix/rename.hpp     | 38 +++++++++++++
 .../3rdparty/stout/include/stout/os/rename.hpp  | 25 ++------
 .../stout/include/stout/os/windows/rename.hpp   | 54 ++++++++++++++++++
 .../stout/tests/os/filesystem_tests.cpp         | 60 ++++++++++++++++++++
 6 files changed, 161 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/8c6a55d1/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/Makefile.am b/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
index 6606e60..03f46d9 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
+++ b/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
@@ -111,6 +111,7 @@ nobase_include_HEADERS =			\
   stout/os/posix/mkdtemp.hpp			\
   stout/os/posix/pstree.hpp			\
   stout/os/posix/read.hpp			\
+  stout/os/posix/rename.hpp			\
   stout/os/posix/rmdir.hpp			\
   stout/os/posix/sendfile.hpp			\
   stout/os/posix/shell.hpp			\
@@ -131,6 +132,7 @@ nobase_include_HEADERS =			\
   stout/os/windows/mkdtemp.hpp			\
   stout/os/windows/pstree.hpp			\
   stout/os/windows/read.hpp			\
+  stout/os/windows/rename.hpp			\
   stout/os/windows/rmdir.hpp			\
   stout/os/windows/sendfile.hpp			\
   stout/os/windows/shell.hpp			\

http://git-wip-us.apache.org/repos/asf/mesos/blob/8c6a55d1/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 06bf04e..e7accaa 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
@@ -31,6 +31,7 @@
 #include <stout/bytes.hpp>
 #include <stout/duration.hpp>
 #include <stout/error.hpp>
+#include <stout/exit.hpp>
 #include <stout/foreach.hpp>
 #include <stout/none.hpp>
 #include <stout/nothing.hpp>
@@ -51,6 +52,7 @@
 #include <stout/os/mkdtemp.hpp>
 #include <stout/os/mktemp.hpp>
 #include <stout/os/process.hpp>
+#include <stout/os/rename.hpp>
 #include <stout/os/rm.hpp>
 #include <stout/os/rmdir.hpp>
 #include <stout/os/shell.hpp>

http://git-wip-us.apache.org/repos/asf/mesos/blob/8c6a55d1/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/rename.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/rename.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/rename.hpp
new file mode 100644
index 0000000..9cff6db
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/rename.hpp
@@ -0,0 +1,38 @@
+// 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_RENAME_HPP__
+#define __STOUT_OS_POSIX_RENAME_HPP__
+
+#include <stdio.h>
+
+#include <string>
+
+#include <stout/error.hpp>
+#include <stout/nothing.hpp>
+#include <stout/try.hpp>
+
+
+namespace os {
+
+inline Try<Nothing> rename(const std::string& from, const std::string& to)
+{
+  if (::rename(from.c_str(), to.c_str()) != 0) {
+    return ErrnoError();
+  }
+
+  return Nothing();
+}
+
+} // namespace os {
+
+#endif // __STOUT_OS_POSIX_RENAME_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/8c6a55d1/3rdparty/libprocess/3rdparty/stout/include/stout/os/rename.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/rename.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/rename.hpp
index 7b22152..8a4e084 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/rename.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/rename.hpp
@@ -13,25 +13,10 @@
 #ifndef __STOUT_OS_RENAME_HPP__
 #define __STOUT_OS_RENAME_HPP__
 
-#include <stdio.h>
-
-#include <string>
-
-#include <stout/error.hpp>
-#include <stout/nothing.hpp>
-#include <stout/try.hpp>
-
-namespace os {
-
-inline Try<Nothing> rename(const std::string& from, const std::string& to)
-{
-  if (::rename(from.c_str(), to.c_str()) != 0) {
-    return ErrnoError();
-  }
-
-  return Nothing();
-}
-
-} // namespace os {
+#ifdef __WINDOWS__
+#include <stout/os/windows/rename.hpp>
+#else
+#include <stout/os/posix/rename.hpp>
+#endif // __WINDOWS__
 
 #endif // __STOUT_OS_RENAME_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/8c6a55d1/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/rename.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/rename.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/rename.hpp
new file mode 100644
index 0000000..544ff90
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/rename.hpp
@@ -0,0 +1,54 @@
+// 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_RENAME_HPP__
+#define __STOUT_OS_WINDOWS_RENAME_HPP__
+
+#include <string>
+
+#include <stout/error.hpp>
+#include <stout/nothing.hpp>
+#include <stout/try.hpp>
+#include <stout/windows.hpp>
+
+
+namespace os {
+
+inline Try<Nothing> rename(const std::string& from, const std::string& to)
+{
+  // Use `MoveFile` to perform the file move. The MSVCRT implementation of
+  // `::rename` fails if the `to` file already exists[1], while some UNIX
+  // implementations allow that[2].
+  //
+  // Use `MOVEFILE_COPY_ALLOWED` to allow moving the file to another volume and
+  // `MOVEFILE_REPLACE_EXISTING` to comply with the UNIX implementation and
+  // replace an existing file[3].
+  //
+  // [1] https://msdn.microsoft.com/en-us/library/zw5t957f.aspx
+  // [2] http://man7.org/linux/man-pages/man2/rename.2.html
+  // [3] https://msdn.microsoft.com/en-us/library/windows/desktop/aa365240(v=vs.85).aspx
+  const BOOL result = ::MoveFileEx(
+      from.c_str(),
+      to.c_str(),
+      MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING);
+
+  if (!result) {
+    return WindowsError(
+        "`os::rename` failed to move file '" + from + "' to '" + to + "'");
+  }
+
+  return Nothing();
+}
+
+} // namespace os {
+
+#endif // __STOUT_OS_WINDOWS_RENAME_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/8c6a55d1/3rdparty/libprocess/3rdparty/stout/tests/os/filesystem_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/os/filesystem_tests.cpp b/3rdparty/libprocess/3rdparty/stout/tests/os/filesystem_tests.cpp
index 013b467..ab6f595 100644
--- a/3rdparty/libprocess/3rdparty/stout/tests/os/filesystem_tests.cpp
+++ b/3rdparty/libprocess/3rdparty/stout/tests/os/filesystem_tests.cpp
@@ -27,6 +27,7 @@
 #include <stout/os/ls.hpp>
 #include <stout/os/mkdir.hpp>
 #include <stout/os/read.hpp>
+#include <stout/os/rename.hpp>
 #include <stout/os/touch.hpp>
 #include <stout/os/write.hpp>
 
@@ -195,3 +196,62 @@ TEST_F(FsTest, List)
   ASSERT_SOME(noFiles);
   EXPECT_EQ(0u, noFiles.get().size());
 }
+
+
+TEST_F(FsTest, Rename)
+{
+  const string testdir = path::join(os::getcwd(), UUID::random().toString());
+  ASSERT_SOME(os::mkdir(testdir)); // Create the directories.
+
+  // Now write some files.
+  const string file1 = testdir + "/file1.txt";
+  const string file2 = testdir + "/file2.txt";
+  const string file3 = testdir + "/file3.jpg";
+
+  ASSERT_SOME(os::touch(file1));
+  ASSERT_SOME(os::touch(file2));
+
+  // Write something to `file1`.
+  const string message = "hello world!";
+  ASSERT_SOME(os::write(file1, message));
+
+  // Search all files in folder
+  Try<list<string>> allFiles = fs::list(path::join(testdir, "*"));
+  ASSERT_SOME(allFiles);
+  EXPECT_EQ(2u, allFiles.get().size());
+
+  // Rename a `file1` to `file3`, which does not exist yet. Verify `file3`
+  // contains the text that was in `file1`, and make sure the count of files in
+  // the directory has stayed the same.
+  EXPECT_SOME(os::rename(file1, file3));
+
+  Try<string> file3Contents = os::read(file3);
+  ASSERT_SOME(file3Contents);
+  EXPECT_EQ(message, file3Contents.get());
+
+  allFiles = fs::list(path::join(testdir, "*"));
+  ASSERT_SOME(allFiles);
+  EXPECT_EQ(2u, allFiles.get().size());
+
+  // Rename `file3` -> `file2`. `file2` exists, so this will replace it. Verify
+  // text in the file, and that the count of files in the directory have gone
+  // down.
+  EXPECT_SOME(os::rename(file3, file2));
+  Try<string> file2Contents = os::read(file2);
+  ASSERT_SOME(file2Contents);
+  EXPECT_EQ(message, file2Contents.get());
+
+  allFiles = fs::list(path::join(testdir, "*"));
+  ASSERT_SOME(allFiles);
+  EXPECT_EQ(1u, allFiles.get().size());
+
+  // Rename a fake file, verify failure.
+  const string fakeFile = testdir + "does_not_exist";
+  EXPECT_ERROR(os::rename(fakeFile, file1));
+
+  EXPECT_FALSE(os::exists(file1));
+
+  allFiles = fs::list(path::join(testdir, "*"));
+  ASSERT_SOME(allFiles);
+  EXPECT_EQ(1u, allFiles.get().size());
+}


[2/8] mesos git commit: Stout: Uncommented functions and marked them as `= delete` instead.

Posted by mp...@apache.org.
Stout: Uncommented functions and marked them as `= delete` instead.

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


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

Branch: refs/heads/master
Commit: e5af13dc6369a23133b388c9964671e2ead18735
Parents: 1ffa483
Author: Alex Clemmer <cl...@gmail.com>
Authored: Sat Apr 9 15:56:05 2016 -0700
Committer: Michael Park <mp...@apache.org>
Committed: Sat Apr 9 15:58:35 2016 -0700

----------------------------------------------------------------------
 .../3rdparty/stout/include/stout/windows/os.hpp | 75 +++++---------------
 1 file changed, 17 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/e5af13dc/3rdparty/libprocess/3rdparty/stout/include/stout/windows/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/windows/os.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/windows/os.hpp
index e1a4557..c3f4faa 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/windows/os.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/windows/os.hpp
@@ -70,13 +70,9 @@ inline void setenv(
 }
 
 
-/*
 // Unsets the value associated with the specified key in the set of
 // environment variables.
-inline void unsetenv(const std::string& key)
-{
-  UNIMPLEMENTED;
-}
+inline void unsetenv(const std::string& key) = delete;
 
 
 // Executes a command by calling "/bin/sh -c <command>", and returns
@@ -84,10 +80,7 @@ inline void unsetenv(const std::string& key)
 // return -1 on error (e.g., fork/exec/waitpid failed). This function
 // is async signal safe. We return int instead of returning a Try
 // because Try involves 'new', which is not async signal safe.
-inline int system(const std::string& command)
-{
-  UNIMPLEMENTED;
-}
+inline int system(const std::string& command) = delete;
 
 
 // This function is a portable version of execvpe ('p' means searching
@@ -97,96 +90,62 @@ inline int system(const std::string& command)
 // NOTE: This function is not thread safe. It is supposed to be used
 // only after fork (when there is only one thread). This function is
 // async signal safe.
-inline int execvpe(const char* file, char** argv, char** envp)
-{
-  UNIMPLEMENTED;
-}
+inline int execvpe(const char* file, char** argv, char** envp) = delete;
 
 
 inline Try<Nothing> chown(
     uid_t uid,
     gid_t gid,
     const std::string& path,
-    bool recursive)
-{
-  UNIMPLEMENTED;
-}
+    bool recursive) = delete;
 
 
-inline Try<Nothing> chmod(const std::string& path, int mode)
-{
-  UNIMPLEMENTED;
-}
+inline Try<Nothing> chmod(const std::string& path, int mode) = delete;
 
 
 inline Try<Nothing> mknod(
     const std::string& path,
     mode_t mode,
-    dev_t dev)
-{
-  UNIMPLEMENTED;
-}
+    dev_t dev) = delete;
 
 
 // Suspends execution for the given duration.
-inline Try<Nothing> sleep(const Duration& duration)
-{
-  UNIMPLEMENTED;
-}
+inline Try<Nothing> sleep(const Duration& duration) = delete;
 
 
 // Returns the list of files that match the given (shell) pattern.
-inline Try<std::list<std::string>> glob(const std::string& pattern)
-{
-  UNIMPLEMENTED;
-}
+inline Try<std::list<std::string>> glob(const std::string& pattern) = delete;
 
 
 // Returns the total number of cpus (cores).
-inline Try<long> cpus()
-{
-  UNIMPLEMENTED;
-}
+inline Try<long> cpus() = delete;
 
 
 // Returns load struct with average system loads for the last
 // 1, 5 and 15 minutes respectively.
 // Load values should be interpreted as usual average loads from
 // uptime(1).
-inline Try<Load> loadavg()
-{
-  UNIMPLEMENTED;
-}
+inline Try<Load> loadavg() = delete;
 
 
 // Returns the total size of main and free memory.
-inline Try<Memory> memory()
-{
-  UNIMPLEMENTED;
-}
+inline Try<Memory> memory() = delete;
 
 
 // Return the system information.
-inline Try<UTSInfo> uname()
-{
-  UNIMPLEMENTED;
-}
+inline Try<UTSInfo> uname() = delete;
 
 
-inline Try<std::list<Process>> processes()
-{
-  UNIMPLEMENTED;
-}
+inline Try<std::list<Process>> processes() = delete;
 
 
 // Overload of os::pids for filtering by groups and sessions.
 // A group / session id of 0 will fitler on the group / session ID
 // of the calling process.
-inline Try<std::set<pid_t>> pids(Option<pid_t> group, Option<pid_t> session)
-{
-  UNIMPLEMENTED;
-}
-*/
+inline Try<std::set<pid_t>> pids(
+    Option<pid_t> group,
+    Option<pid_t> session) = delete;
+
 
 inline tm* gmtime_r(const time_t* timep, tm* result)
 {


[3/8] mesos git commit: Windows: Changed the calling parameters for Windows API.

Posted by mp...@apache.org.
Windows: Changed the calling parameters for Windows API.

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


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

Branch: refs/heads/master
Commit: d5922af36c3a29f0c9c207f5dc58a2c10505127b
Parents: b93653f
Author: Daniel Pravat <dp...@outlook.com>
Authored: Sat Apr 9 15:55:33 2016 -0700
Committer: Michael Park <mp...@apache.org>
Committed: Sat Apr 9 15:58:35 2016 -0700

----------------------------------------------------------------------
 3rdparty/libprocess/src/libevent.cpp    |  2 ++
 3rdparty/libprocess/src/poll_socket.cpp | 35 ++++++++++++++++++++++++----
 2 files changed, 33 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/d5922af3/3rdparty/libprocess/src/libevent.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/libevent.cpp b/3rdparty/libprocess/src/libevent.cpp
index c4a8da8..f5b8675 100644
--- a/3rdparty/libprocess/src/libevent.cpp
+++ b/3rdparty/libprocess/src/libevent.cpp
@@ -10,7 +10,9 @@
 // See the License for the specific language governing permissions and
 // limitations under the License
 
+#ifndef __WINDOWS__
 #include <unistd.h>
+#endif // __WINDOWS__
 
 #include <mutex>
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/d5922af3/3rdparty/libprocess/src/poll_socket.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/poll_socket.cpp b/3rdparty/libprocess/src/poll_socket.cpp
index cb28785..42ab965 100644
--- a/3rdparty/libprocess/src/poll_socket.cpp
+++ b/3rdparty/libprocess/src/poll_socket.cpp
@@ -10,7 +10,12 @@
 // See the License for the specific language governing permissions and
 // limitations under the License
 
+
+#ifdef __WINDOWS__
+#include <stout/windows.hpp>
+#else
 #include <netinet/tcp.h>
+#endif // __WINDOWS__
 
 #include <process/io.hpp>
 #include <process/network.hpp>
@@ -18,6 +23,7 @@
 
 #include <stout/os/sendfile.hpp>
 #include <stout/os/strerror.hpp>
+#include <stout/os.hpp>
 
 #include "config.hpp"
 #include "poll_socket.hpp"
@@ -69,8 +75,15 @@ Future<Socket> accept(int fd)
   }
 
   // Turn off Nagle (TCP_NODELAY) so pipelined requests don't wait.
+  // NOTE: We cast to `char*` here because the function prototypes on Windows
+  // use `char*` instead of `void*`.
   int on = 1;
-  if (setsockopt(s, SOL_TCP, TCP_NODELAY, &on, sizeof(on)) < 0) {
+  if (::setsockopt(
+          s,
+          SOL_TCP,
+          TCP_NODELAY,
+          reinterpret_cast<const char*>(&on),
+          sizeof(on)) < 0) {
     const string error = os::strerror(errno);
     VLOG(1) << "Failed to turn off the Nagle algorithm: " << error;
     os::close(s);
@@ -105,7 +118,15 @@ Future<Nothing> connect(const Socket& socket)
   socklen_t optlen = sizeof(opt);
   int s = socket.get();
 
-  if (getsockopt(s, SOL_SOCKET, SO_ERROR, &opt, &optlen) < 0 || opt != 0) {
+  // NOTE: We cast to `char*` here because the function prototypes on Windows
+  // use `char*` instead of `void*`.
+  if (::getsockopt(
+          s,
+          SOL_SOCKET,
+          SO_ERROR,
+          reinterpret_cast<char*>(&opt),
+          &optlen) < 0 ||
+      opt != 0) {
     // Connect failure.
     VLOG(1) << "Socket error while connecting";
     return Failure("Socket error while connecting");
@@ -148,10 +169,16 @@ Future<size_t> socket_send_data(int s, const char* data, size_t size)
   while (true) {
     ssize_t length = send(s, data, size, MSG_NOSIGNAL);
 
-    if (length < 0 && (errno == EINTR)) {
+#ifdef __WINDOWS__
+    int error = WSAGetLastError();
+#else
+    int error = errno;
+#endif // __WINDOWS__
+
+    if (length < 0 && net::is_restartable_error(error)) {
       // Interrupted, try again now.
       continue;
-    } else if (length < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
+    } else if (length < 0 && net::is_retryable_error(error)) {
       // Might block, try again later.
       return io::poll(s, io::WRITE)
         .then(lambda::bind(&internal::socket_send_data, s, data, size));