You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2017/06/30 18:41:45 UTC

[11/13] mesos git commit: Added stubs for local resource provider daemon.

Added stubs for local resource provider daemon.

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


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

Branch: refs/heads/master
Commit: 027dc1ba9d3685a04e89d93112a5980ebc8df0cf
Parents: f5e083c
Author: Jie Yu <yu...@gmail.com>
Authored: Sun Jun 25 21:16:49 2017 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Fri Jun 30 11:09:44 2017 -0700

----------------------------------------------------------------------
 src/CMakeLists.txt                         |  1 +
 src/Makefile.am                            |  3 +
 src/resource_provider/daemon.cpp           | 87 +++++++++++++++++++++++++
 src/resource_provider/daemon.hpp           | 64 ++++++++++++++++++
 src/resource_provider/local.hpp            | 32 +++++++++
 src/resource_provider/storage/provider.cpp |  4 +-
 src/resource_provider/storage/provider.hpp |  8 ++-
 src/slave/slave.cpp                        | 12 ++++
 src/slave/slave.hpp                        |  2 +
 9 files changed, 208 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/027dc1ba/src/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index a1cc956..ea90916 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -399,6 +399,7 @@ set(POSIX_SRC
   )
 
 set(RESOURCE_PROVIDER_SRC
+  resource_provider/daemon.cpp
   resource_provider/driver.cpp
   resource_provider/manager.cpp
   resource_provider/storage/provider.cpp

http://git-wip-us.apache.org/repos/asf/mesos/blob/027dc1ba/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index 9121191..b4c2107 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -944,6 +944,7 @@ libmesos_no_3rdparty_la_SOURCES +=					\
   module/manager.cpp							\
   oci/spec.cpp								\
   posix/rlimits.cpp							\
+  resource_provider/daemon.cpp						\
   resource_provider/driver.cpp						\
   resource_provider/manager.cpp						\
   resource_provider/storage/provider.cpp				\
@@ -1080,6 +1081,8 @@ libmesos_no_3rdparty_la_SOURCES +=					\
   messages/messages.hpp							\
   module/manager.hpp							\
   posix/rlimits.hpp							\
+  resource_provider/daemon.hpp						\
+  resource_provider/local.hpp						\
   resource_provider/manager.hpp						\
   resource_provider/storage/provider.hpp				\
   sched/constants.hpp							\

http://git-wip-us.apache.org/repos/asf/mesos/blob/027dc1ba/src/resource_provider/daemon.cpp
----------------------------------------------------------------------
diff --git a/src/resource_provider/daemon.cpp b/src/resource_provider/daemon.cpp
new file mode 100644
index 0000000..400cfce
--- /dev/null
+++ b/src/resource_provider/daemon.cpp
@@ -0,0 +1,87 @@
+// 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 "resource_provider/daemon.hpp"
+
+#include <process/id.hpp>
+#include <process/process.hpp>
+
+#include "resource_provider/local.hpp"
+
+using std::string;
+
+using process::Owned;
+using process::Process;
+using process::ProcessBase;
+
+using process::spawn;
+using process::terminate;
+using process::wait;
+
+namespace mesos {
+namespace internal {
+
+class LocalResourceProviderDaemonProcess
+  : public Process<LocalResourceProviderDaemonProcess>
+{
+public:
+  LocalResourceProviderDaemonProcess(
+      const string& _workDir,
+      const Option<string>& _configDir)
+    : ProcessBase(process::ID::generate("local-resource-provider-daemon")),
+      workDir(_workDir),
+      configDir(_configDir) {}
+
+protected:
+  void initialize() override;
+
+private:
+  const string workDir;
+  const Option<string> configDir;
+};
+
+
+void LocalResourceProviderDaemonProcess::initialize()
+{
+}
+
+
+Try<Owned<LocalResourceProviderDaemon>> LocalResourceProviderDaemon::create(
+    const slave::Flags& flags)
+{
+  return new LocalResourceProviderDaemon(
+      flags.work_dir,
+      flags.resource_provider_config_dir);
+}
+
+
+LocalResourceProviderDaemon::LocalResourceProviderDaemon(
+    const string& workDir,
+    const Option<string>& configDir)
+  : process(new LocalResourceProviderDaemonProcess(workDir, configDir))
+{
+  spawn(CHECK_NOTNULL(process.get()));
+}
+
+
+LocalResourceProviderDaemon::~LocalResourceProviderDaemon()
+{
+  terminate(process.get());
+  wait(process.get());
+}
+
+} // namespace internal {
+} // namespace mesos {

http://git-wip-us.apache.org/repos/asf/mesos/blob/027dc1ba/src/resource_provider/daemon.hpp
----------------------------------------------------------------------
diff --git a/src/resource_provider/daemon.hpp b/src/resource_provider/daemon.hpp
new file mode 100644
index 0000000..467a5d3
--- /dev/null
+++ b/src/resource_provider/daemon.hpp
@@ -0,0 +1,64 @@
+// 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 __RESOURCE_PROVIDER_DAEMON_HPP__
+#define __RESOURCE_PROVIDER_DAEMON_HPP__
+
+#include <string>
+
+#include <process/owned.hpp>
+
+#include <stout/option.hpp>
+#include <stout/try.hpp>
+
+#include "slave/flags.hpp"
+
+namespace mesos {
+namespace internal {
+
+// Forward declarations.
+class LocalResourceProviderDaemonProcess;
+
+
+// A daemon in the agent monitoring in-process local resource providers.
+// It monitors the config files in the config dir. Based on that, it
+// starts or stops local resource providers.
+class LocalResourceProviderDaemon
+{
+public:
+  static Try<process::Owned<LocalResourceProviderDaemon>> create(
+      const slave::Flags& flags);
+
+  ~LocalResourceProviderDaemon();
+
+  LocalResourceProviderDaemon(
+      const LocalResourceProviderDaemon& other) = delete;
+
+  LocalResourceProviderDaemon& operator=(
+      const LocalResourceProviderDaemon& other) = delete;
+
+private:
+  LocalResourceProviderDaemon(
+      const std::string& workDir,
+      const Option<std::string>& configDir);
+
+  process::Owned<LocalResourceProviderDaemonProcess> process;
+};
+
+} // namespace internal {
+} // namespace mesos {
+
+#endif // __RESOURCE_PROVIDER_DAEMON_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/027dc1ba/src/resource_provider/local.hpp
----------------------------------------------------------------------
diff --git a/src/resource_provider/local.hpp b/src/resource_provider/local.hpp
new file mode 100644
index 0000000..ced2173
--- /dev/null
+++ b/src/resource_provider/local.hpp
@@ -0,0 +1,32 @@
+// 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 __RESOURCE_PROVIDER_LOCAL_HPP__
+#define __RESOURCE_PROVIDER_LOCAL_HPP__
+
+namespace mesos {
+namespace internal {
+
+class LocalResourceProvider
+{
+public:
+  virtual ~LocalResourceProvider() = default;
+};
+
+} // namespace internal {
+} // namespace mesos {
+
+#endif // __RESOURCE_PROVIDER_LOCAL_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/027dc1ba/src/resource_provider/storage/provider.cpp
----------------------------------------------------------------------
diff --git a/src/resource_provider/storage/provider.cpp b/src/resource_provider/storage/provider.cpp
index 512e190..4c39312 100644
--- a/src/resource_provider/storage/provider.cpp
+++ b/src/resource_provider/storage/provider.cpp
@@ -123,10 +123,10 @@ void StorageLocalResourceProviderProcess::initialize()
 }
 
 
-Try<Owned<StorageLocalResourceProvider>> StorageLocalResourceProvider::create(
+Try<Owned<LocalResourceProvider>> StorageLocalResourceProvider::create(
     const ResourceProviderInfo& info)
 {
-  return Owned<StorageLocalResourceProvider>(
+  return Owned<LocalResourceProvider>(
       new StorageLocalResourceProvider(info));
 }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/027dc1ba/src/resource_provider/storage/provider.hpp
----------------------------------------------------------------------
diff --git a/src/resource_provider/storage/provider.hpp b/src/resource_provider/storage/provider.hpp
index 8fb51c8..c6ea440 100644
--- a/src/resource_provider/storage/provider.hpp
+++ b/src/resource_provider/storage/provider.hpp
@@ -23,6 +23,8 @@
 
 #include <mesos/mesos.hpp>
 
+#include "resource_provider/local.hpp"
+
 namespace mesos {
 namespace internal {
 
@@ -30,13 +32,13 @@ namespace internal {
 class StorageLocalResourceProviderProcess;
 
 
-class StorageLocalResourceProvider
+class StorageLocalResourceProvider : public LocalResourceProvider
 {
 public:
-  static Try<process::Owned<StorageLocalResourceProvider>> create(
+  static Try<process::Owned<LocalResourceProvider>> create(
       const mesos::ResourceProviderInfo& info);
 
-  ~StorageLocalResourceProvider();
+  ~StorageLocalResourceProvider() override;
 
   StorageLocalResourceProvider(
       const StorageLocalResourceProvider& other) = delete;

http://git-wip-us.apache.org/repos/asf/mesos/blob/027dc1ba/src/slave/slave.cpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index d2b4772..0e24b8c 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -27,6 +27,7 @@
 #include <set>
 #include <sstream>
 #include <string>
+#include <utility>
 #include <vector>
 
 #include <mesos/type_utils.hpp>
@@ -412,6 +413,17 @@ void Slave::initialize()
       << mkdir.error();
   }
 
+  Try<Owned<LocalResourceProviderDaemon>> _localResourceProviderDaemon =
+    LocalResourceProviderDaemon::create(flags);
+
+  if (_localResourceProviderDaemon.isError()) {
+    EXIT(EXIT_FAILURE)
+      << "Failed to create local resource provider daemon: "
+      << _localResourceProviderDaemon.error();
+  }
+
+  localResourceProviderDaemon = std::move(_localResourceProviderDaemon.get());
+
   Try<Resources> resources = Containerizer::resources(flags);
   if (resources.isError()) {
     EXIT(EXIT_FAILURE)

http://git-wip-us.apache.org/repos/asf/mesos/blob/027dc1ba/src/slave/slave.hpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.hpp b/src/slave/slave.hpp
index d1baaef..5ede32d 100644
--- a/src/slave/slave.hpp
+++ b/src/slave/slave.hpp
@@ -75,6 +75,7 @@
 
 #include "messages/messages.hpp"
 
+#include "resource_provider/daemon.hpp"
 #include "resource_provider/manager.hpp"
 
 #include "slave/constants.hpp"
@@ -644,6 +645,7 @@ private:
   Option<Resources> oversubscribedResources;
 
   ResourceProviderManager resourceProviderManager;
+  process::Owned<LocalResourceProviderDaemon> localResourceProviderDaemon;
 
 protected:
   // Made protected for testing purposes.