Agent: Added basic Windows isolator support.

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


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

Branch: refs/heads/master
Commit: 5495ce0ec18939f4bdee0f5dca8000db050eabf6
Parents: db26fda
Author: Alex Clemmer <[email protected]>
Authored: Mon May 30 21:19:31 2016 -0700
Committer: Joris Van Remoortere <[email protected]>
Committed: Mon May 30 21:23:21 2016 -0700

----------------------------------------------------------------------
 src/CMakeLists.txt                              | 11 +++
 src/Makefile.am                                 |  2 +
 .../mesos/isolators/filesystem/posix.cpp        |  7 +-
 .../mesos/isolators/filesystem/posix.hpp        |  2 +-
 .../mesos/isolators/filesystem/windows.cpp      | 43 ++++++++++
 .../mesos/isolators/filesystem/windows.hpp      | 49 +++++++++++
 .../containerizer/mesos/isolators/posix.hpp     |  5 +-
 .../containerizer/mesos/isolators/windows.hpp   | 88 ++++++++++++++++++++
 .../mesos/provisioner/provisioner.cpp           |  6 ++
 src/usage/main.cpp                              |  2 +
 src/usage/usage.cpp                             |  4 +
 src/usage/usage.hpp                             |  2 +
 12 files changed, 216 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/5495ce0e/src/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 1a0c447..2c59a42 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -163,6 +163,12 @@ set(LINUX_SRC
   slave/containerizer/mesos/provisioner/backends/overlay.cpp
   )
 
+set(WIN32_SRC
+  ${WIN32_SRC}
+  slave/containerizer/mesos/isolators/filesystem/posix.cpp
+  slave/containerizer/mesos/isolators/filesystem/windows.cpp
+  )
+
 set(DOCKER_SRC
   docker/docker.hpp
   docker/docker.cpp
@@ -392,6 +398,11 @@ if (LINUX)
   set(MESOS_SRC ${MESOS_SRC} ${LINUX_SRC})
 endif (LINUX)
 
+# Include source for Windows build.
+if (WIN32)
+  set(MESOS_SRC ${MESOS_SRC} ${WIN32_SRC})
+endif (WIN32)
+
 add_definitions(-DUSE_STATIC_LIB -DBUILD_DATE=0 -DBUILD_TIME=0 
-DBUILD_USER="frank" -DBUILD_FLAGS="" -DBUILD_JAVA_JVM_LIBRARY="")
 
 # INCLUDE DIRECTIVES FOR MESOS LIBRARY (generates, e.g., -I/path/to/thing

http://git-wip-us.apache.org/repos/asf/mesos/blob/5495ce0e/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index f083cd7..c0be66a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -924,6 +924,7 @@ libmesos_no_3rdparty_la_SOURCES +=                          
        \
   slave/containerizer/mesos/mount.hpp                                  \
   slave/containerizer/mesos/isolators/posix.hpp                                
\
   slave/containerizer/mesos/isolators/filesystem/posix.hpp             \
+  slave/containerizer/mesos/isolators/filesystem/windows.hpp           \
   slave/containerizer/mesos/isolators/posix/disk.hpp                   \
   slave/containerizer/mesos/isolators/docker/volume/driver.hpp         \
   slave/containerizer/mesos/isolators/docker/volume/paths.hpp          \
@@ -931,6 +932,7 @@ libmesos_no_3rdparty_la_SOURCES +=                          
        \
   slave/containerizer/mesos/isolators/network/cni/paths.hpp            \
   slave/containerizer/mesos/isolators/network/cni/spec.hpp             \
   slave/containerizer/mesos/isolators/network/cni/spec.hpp             \
+  slave/containerizer/mesos/isolators/windows.hpp                      \
   slave/containerizer/mesos/provisioner/backend.hpp                    \
   slave/containerizer/mesos/provisioner/paths.hpp                      \
   slave/containerizer/mesos/provisioner/provisioner.hpp                        
\

http://git-wip-us.apache.org/repos/asf/mesos/blob/5495ce0e/src/slave/containerizer/mesos/isolators/filesystem/posix.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/filesystem/posix.cpp 
b/src/slave/containerizer/mesos/isolators/filesystem/posix.cpp
index cb42d83..d45166f 100644
--- a/src/slave/containerizer/mesos/isolators/filesystem/posix.cpp
+++ b/src/slave/containerizer/mesos/isolators/filesystem/posix.cpp
@@ -186,6 +186,11 @@ Future<Nothing> PosixFilesystemIsolatorProcess::update(
                      os::strerror(errno));
     }
 
+    // TODO(hausdorff): (MESOS-5461) Persistent volumes maintain the invariant
+    // that they are used by one task at a time. This is currently enforced by
+    // `os::chown`. Windows does not support `os::chown`, we will need to
+    // revisit this later.
+#ifndef __WINDOWS__
     LOG(INFO) << "Changing the ownership of the persistent volume at '"
               << original << "' with uid " << s.st_uid
               << " and gid " << s.st_gid;
@@ -197,7 +202,7 @@ Future<Nothing> PosixFilesystemIsolatorProcess::update(
           original + "' with uid " + stringify(s.st_uid) +
           " and gid " + stringify(s.st_gid) + ": " + chown.error());
     }
-
+#endif
     string link = path::join(info->directory, containerPath);
 
     if (os::exists(link)) {

http://git-wip-us.apache.org/repos/asf/mesos/blob/5495ce0e/src/slave/containerizer/mesos/isolators/filesystem/posix.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/filesystem/posix.hpp 
b/src/slave/containerizer/mesos/isolators/filesystem/posix.hpp
index 01ab179..794b6e5 100644
--- a/src/slave/containerizer/mesos/isolators/filesystem/posix.hpp
+++ b/src/slave/containerizer/mesos/isolators/filesystem/posix.hpp
@@ -49,7 +49,7 @@ public:
   virtual process::Future<Nothing> cleanup(
       const ContainerID& containerId);
 
-private:
+protected:
   PosixFilesystemIsolatorProcess(const Flags& flags);
 
   const Flags flags;

http://git-wip-us.apache.org/repos/asf/mesos/blob/5495ce0e/src/slave/containerizer/mesos/isolators/filesystem/windows.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/filesystem/windows.cpp 
b/src/slave/containerizer/mesos/isolators/filesystem/windows.cpp
new file mode 100644
index 0000000..0bee68b
--- /dev/null
+++ b/src/slave/containerizer/mesos/isolators/filesystem/windows.cpp
@@ -0,0 +1,43 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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.
+
+#include "slave/paths.hpp"
+
+#include "slave/containerizer/mesos/isolators/filesystem/windows.hpp"
+
+using namespace process;
+
+using mesos::slave::Isolator;
+
+namespace mesos {
+namespace internal {
+namespace slave {
+
+WindowsFilesystemIsolatorProcess::WindowsFilesystemIsolatorProcess(
+    const Flags& _flags)
+  : PosixFilesystemIsolatorProcess(_flags) {}
+
+Try<Isolator*> WindowsFilesystemIsolatorProcess::create(const Flags& flags)
+{
+  process::Owned<MesosIsolatorProcess> process(
+      new WindowsFilesystemIsolatorProcess(flags));
+
+  return new MesosIsolator(process);
+}
+
+} // namespace slave {
+} // namespace internal {
+} // namespace mesos {

http://git-wip-us.apache.org/repos/asf/mesos/blob/5495ce0e/src/slave/containerizer/mesos/isolators/filesystem/windows.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/filesystem/windows.hpp 
b/src/slave/containerizer/mesos/isolators/filesystem/windows.hpp
new file mode 100644
index 0000000..2bf011d
--- /dev/null
+++ b/src/slave/containerizer/mesos/isolators/filesystem/windows.hpp
@@ -0,0 +1,49 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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 __WINDOWS_FILESYSTEM_ISOLATOR_HPP__
+#define __WINDOWS_FILESYSTEM_ISOLATOR_HPP__
+
+#include <mesos/resources.hpp>
+
+#include "slave/flags.hpp"
+
+#include "slave/containerizer/mesos/isolator.hpp"
+#include "slave/containerizer/mesos/isolators/filesystem/posix.hpp"
+
+namespace mesos {
+namespace internal {
+namespace slave {
+
+// TODO(hausdorff): (MESOS-5462) For now the Windows isolators are essentially
+// direct copies of their POSIX counterparts. In the future, we expect to
+// refactor the POSIX classes into platform-independent base class, with
+// Windows and POSIX implementations. For now, we leave the Windows
+// implementations as inheriting from the POSIX implementations.
+class WindowsFilesystemIsolatorProcess : public PosixFilesystemIsolatorProcess
+{
+public:
+  static Try<mesos::slave::Isolator*> create(const Flags& flags);
+
+private:
+  WindowsFilesystemIsolatorProcess(const Flags& flags);
+};
+
+} // namespace slave {
+} // namespace internal {
+} // namespace mesos {
+
+#endif // __WINDOWS_FILESYSTEM_ISOLATOR_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/5495ce0e/src/slave/containerizer/mesos/isolators/posix.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/posix.hpp 
b/src/slave/containerizer/mesos/isolators/posix.hpp
index 227505a..e5cee9c 100644
--- a/src/slave/containerizer/mesos/isolators/posix.hpp
+++ b/src/slave/containerizer/mesos/isolators/posix.hpp
@@ -164,11 +164,10 @@ public:
     return usage.get();
   }
 
-private:
+protected:
   PosixCpuIsolatorProcess() {}
 };
 
-
 class PosixMemIsolatorProcess : public PosixIsolatorProcess
 {
 public:
@@ -198,7 +197,7 @@ public:
     return usage.get();
   }
 
-private:
+protected:
   PosixMemIsolatorProcess() {}
 };
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/5495ce0e/src/slave/containerizer/mesos/isolators/windows.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/windows.hpp 
b/src/slave/containerizer/mesos/isolators/windows.hpp
new file mode 100644
index 0000000..aec3316
--- /dev/null
+++ b/src/slave/containerizer/mesos/isolators/windows.hpp
@@ -0,0 +1,88 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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 __WINDOWS_ISOLATOR_HPP__
+#define __WINDOWS_ISOLATOR_HPP__
+
+#include <process/future.hpp>
+
+#include "slave/flags.hpp"
+
+#include "slave/containerizer/mesos/isolator.hpp"
+#include "slave/containerizer/mesos/isolators/posix.hpp"
+
+namespace mesos {
+namespace internal {
+namespace slave {
+
+// A basic MesosIsolatorProcess that keeps track of the pid but
+// doesn't do any resource isolation. Subclasses must implement
+// usage() for their appropriate resource(s).
+//
+// TODO(hausdorff): (MESOS-5462) For now the Windows isolators are essentially
+// direct copies of their POSIX counterparts. In the future, we expect to
+// refactor the POSIX classes into platform-independent base class, with
+// Windows and POSIX implementations. For now, we leave the Windows
+// implementations as inheriting from the POSIX implementations.
+class WindowsIsolatorProcess : public PosixIsolatorProcess {};
+
+
+// TODO(hausdorff): (MESOS-5462) For now the Windows isolators are essentially
+// direct copies of their POSIX counterparts. In the future, we expect to
+// refactor the POSIX classes into platform-independent base class, with
+// Windows and POSIX implementations. For now, we leave the Windows
+// implementations as inheriting from the POSIX implementations.
+class WindowsCpuIsolatorProcess : public PosixCpuIsolatorProcess
+{
+public:
+  static Try<mesos::slave::Isolator*> create(const Flags& flags)
+  {
+    process::Owned<MesosIsolatorProcess> process(
+        new WindowsCpuIsolatorProcess());
+
+    return new MesosIsolator(process);
+  }
+
+private:
+  WindowsCpuIsolatorProcess() {}
+};
+
+
+// TODO(hausdorff): (MESOS-5462) For now the Windows isolators are essentially
+// direct copies of their POSIX counterparts. In the future, we expect to
+// refactor the POSIX classes into platform-independent base class, with
+// Windows and POSIX implementations. For now, we leave the Windows
+// implementations as inheriting from the POSIX implementations.
+class WindowsMemIsolatorProcess : public PosixMemIsolatorProcess
+{
+public:
+  static Try<mesos::slave::Isolator*> create(const Flags& flags)
+  {
+    process::Owned<MesosIsolatorProcess> process(
+        new WindowsMemIsolatorProcess());
+
+    return new MesosIsolator(process);
+  }
+
+private:
+  WindowsMemIsolatorProcess() {}
+};
+
+} // namespace slave {
+} // namespace internal {
+} // namespace mesos {
+
+#endif // __WINDOWS_ISOLATOR_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/5495ce0e/src/slave/containerizer/mesos/provisioner/provisioner.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/provisioner/provisioner.cpp 
b/src/slave/containerizer/mesos/provisioner/provisioner.cpp
index 9e803f6..7540be6 100644
--- a/src/slave/containerizer/mesos/provisioner/provisioner.cpp
+++ b/src/slave/containerizer/mesos/provisioner/provisioner.cpp
@@ -14,7 +14,9 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+#ifndef __WINDOWS__
 #include <fts.h>
+#endif // __WINDOWS__
 
 #include <mesos/type_utils.hpp>
 
@@ -333,6 +335,7 @@ Future<ProvisionInfo> ProvisionerProcess::__provision(
     return ProvisionInfo{rootfs, imageInfo.dockerManifest};
   }
 
+#ifndef __WINDOWS__
   char* _rootfs[] = {const_cast<char*>(rootfs.c_str()), nullptr};
 
   FTS* tree = ::fts_open(_rootfs, FTS_NOCHDIR | FTS_PHYSICAL, nullptr);
@@ -391,6 +394,9 @@ Future<ProvisionInfo> ProvisionerProcess::__provision(
   }
 
   return ProvisionInfo{rootfs, imageInfo.dockerManifest};
+#else
+  return ProvisionInfo{ rootfs, imageInfo.dockerManifest };
+#endif // __WINDOWS__
 }
 
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/5495ce0e/src/usage/main.cpp
----------------------------------------------------------------------
diff --git a/src/usage/main.cpp b/src/usage/main.cpp
index ab3bb23..5ad4a3b 100644
--- a/src/usage/main.cpp
+++ b/src/usage/main.cpp
@@ -14,7 +14,9 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+#ifndef __WINDOWS__
 #include <unistd.h> // For pid_t and STDOUT_FILENO.
+#endif // __WINDOWS__
 
 #include <iostream>
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/5495ce0e/src/usage/usage.cpp
----------------------------------------------------------------------
diff --git a/src/usage/usage.cpp b/src/usage/usage.cpp
index 3b19682..01c29f0 100644
--- a/src/usage/usage.cpp
+++ b/src/usage/usage.cpp
@@ -14,7 +14,9 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+#ifndef __WINDOWS__
 #include <unistd.h> // For pid_t.
+#endif // __WINDOWS__
 
 #include <deque>
 
@@ -23,6 +25,8 @@
 #include <stout/foreach.hpp>
 #include <stout/os.hpp>
 
+#include <stout/os/pstree.hpp>
+
 #include "usage/usage.hpp"
 
 namespace mesos {

http://git-wip-us.apache.org/repos/asf/mesos/blob/5495ce0e/src/usage/usage.hpp
----------------------------------------------------------------------
diff --git a/src/usage/usage.hpp b/src/usage/usage.hpp
index 2e1996a..6576b90 100644
--- a/src/usage/usage.hpp
+++ b/src/usage/usage.hpp
@@ -17,7 +17,9 @@
 #ifndef __USAGE_HPP__
 #define __USAGE_HPP__
 
+#ifndef __WINDOWS__
 #include <unistd.h> // For pid_t.
+#endif // __WINDOWS__
 
 #include "mesos/mesos.hpp"
 

Reply via email to