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 2017/12/19 03:51:14 UTC

[6/7] mesos git commit: Added flag to pass VolumeProfileAdaptor module to SLRP.

Added flag to pass VolumeProfileAdaptor module to SLRP.

This adds an agent flag to choose the VolumeProfileAdaptor module
to load and passes this information down to the storage resource
providers. A single module can potentially be used by multiple
storage resource providers.

We choose to pass the module along as a global variable because the
module is not needed by many of the components in the injection path.
Specifically, the Storage Local Resource Provider will need the module,
but its parents, the Local Resource Provider and Resource Provider
Daemons will not.

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


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

Branch: refs/heads/master
Commit: f4743f76b34e737d86e5734cdc5f2e70ae2eee3e
Parents: 504d702
Author: Joseph Wu <jo...@apache.org>
Authored: Fri Dec 8 18:13:54 2017 -0800
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Dec 18 19:47:35 2017 -0800

----------------------------------------------------------------------
 .../mesos/resource_provider/volume_profile.hpp  | 12 ++++++++
 src/resource_provider/storage/provider.cpp      | 10 ++++++-
 src/resource_provider/volume_profile.cpp        | 30 ++++++++++++++++++++
 src/slave/flags.cpp                             |  9 ++++++
 src/slave/flags.hpp                             |  1 +
 src/slave/slave.cpp                             | 16 +++++++++++
 src/slave/slave.hpp                             |  4 +++
 7 files changed, 81 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/f4743f76/include/mesos/resource_provider/volume_profile.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/resource_provider/volume_profile.hpp b/include/mesos/resource_provider/volume_profile.hpp
index ea3fcf0..7141a14 100644
--- a/include/mesos/resource_provider/volume_profile.hpp
+++ b/include/mesos/resource_provider/volume_profile.hpp
@@ -17,6 +17,7 @@
 #ifndef __MESOS_RESOURCE_PROVIDER_VOLUME_PROFILE_HPP__
 #define __MESOS_RESOURCE_PROVIDER_VOLUME_PROFILE_HPP__
 
+#include <memory>
 #include <string>
 #include <tuple>
 
@@ -82,6 +83,17 @@ public:
   static Try<VolumeProfileAdaptor*> create(
       const Option<std::string>& name = None());
 
+  /**
+   * Global methods for setting and getting a VolumeProfileAdaptor instance.
+   *
+   * The agent (or test) is expected to create and set the adaptor instance
+   * and manage the pointer (this method will only keep a weak pointer).
+   * Each component that needs to use the VolumeProfileAdaptor, such as the
+   * Storage Local Resource Provider, should call `getAdaptor`.
+   */
+  static void setAdaptor(const std::shared_ptr<VolumeProfileAdaptor>& adaptor);
+  static std::shared_ptr<VolumeProfileAdaptor> getAdaptor();
+
   virtual ~VolumeProfileAdaptor() {}
 
   /**

http://git-wip-us.apache.org/repos/asf/mesos/blob/f4743f76/src/resource_provider/storage/provider.cpp
----------------------------------------------------------------------
diff --git a/src/resource_provider/storage/provider.cpp b/src/resource_provider/storage/provider.cpp
index 158b6b4..b50de33 100644
--- a/src/resource_provider/storage/provider.cpp
+++ b/src/resource_provider/storage/provider.cpp
@@ -18,6 +18,7 @@
 
 #include <algorithm>
 #include <cctype>
+#include <memory>
 #include <numeric>
 
 #include <glog/logging.h>
@@ -36,6 +37,7 @@
 #include <mesos/type_utils.hpp>
 
 #include <mesos/resource_provider/resource_provider.hpp>
+#include <mesos/resource_provider/volume_profile.hpp>
 
 #include <mesos/v1/resource_provider.hpp>
 
@@ -295,7 +297,11 @@ public:
       slaveId(_slaveId),
       authToken(_authToken),
       strict(_strict),
-      resourceVersion(id::UUID::random()) {}
+      resourceVersion(id::UUID::random())
+  {
+    volumeProfileAdaptor = VolumeProfileAdaptor::getAdaptor();
+    CHECK_NOTNULL(volumeProfileAdaptor.get());
+  }
 
   StorageLocalResourceProviderProcess(
       const StorageLocalResourceProviderProcess& other) = delete;
@@ -408,6 +414,8 @@ private:
   const Option<string> authToken;
   const bool strict;
 
+  shared_ptr<VolumeProfileAdaptor> volumeProfileAdaptor;
+
   csi::Version csiVersion;
   csi::VolumeCapability defaultMountCapability;
   csi::VolumeCapability defaultBlockCapability;

http://git-wip-us.apache.org/repos/asf/mesos/blob/f4743f76/src/resource_provider/volume_profile.cpp
----------------------------------------------------------------------
diff --git a/src/resource_provider/volume_profile.cpp b/src/resource_provider/volume_profile.cpp
index 739ebb1..2b83703 100644
--- a/src/resource_provider/volume_profile.cpp
+++ b/src/resource_provider/volume_profile.cpp
@@ -98,4 +98,34 @@ Try<VolumeProfileAdaptor*> VolumeProfileAdaptor::create(
   return result;
 }
 
+
+// NOTE: This is a pointer because we avoid using non-POD types
+// as global variables.
+//
+// NOTE: This is a `weak_ptr` because the ownership of the module should
+// belong to the caller of the `create` method above. This will, for example,
+// allow tests to instantiate an Agent and subsequently destruct the Agent
+// without leaving a module behind in a global variable.
+static std::weak_ptr<VolumeProfileAdaptor>* currentAdaptor = nullptr;
+
+
+void VolumeProfileAdaptor::setAdaptor(
+    const std::shared_ptr<VolumeProfileAdaptor>& adaptor)
+{
+  if (currentAdaptor != nullptr) {
+    delete currentAdaptor;
+  }
+
+  currentAdaptor = new std::weak_ptr<VolumeProfileAdaptor>(adaptor);
+}
+
+
+std::shared_ptr<VolumeProfileAdaptor> VolumeProfileAdaptor::getAdaptor()
+{
+  // This method should never be called before `setAdaptor` has been called.
+  CHECK_NOTNULL(currentAdaptor);
+
+  return currentAdaptor->lock();
+}
+
 } // namespace mesos {

http://git-wip-us.apache.org/repos/asf/mesos/blob/f4743f76/src/slave/flags.cpp
----------------------------------------------------------------------
diff --git a/src/slave/flags.cpp b/src/slave/flags.cpp
index d4b95b7..69f37fe 100644
--- a/src/slave/flags.cpp
+++ b/src/slave/flags.cpp
@@ -111,6 +111,15 @@ mesos::internal::slave::Flags::Flags()
       "  \"name\": \"lvm\"\n"
       "}");
 
+  add(&Flags::volume_profile_adaptor,
+      "volume_profile_adaptor",
+      "The name of the volume profile adaptor module that storage resource\n"
+      "providers should use for translating a 'volume profile' into inputs\n"
+      "consumed by various Container Storage Interface (CSI) plugins.\n"
+      "If this flag is not specified, the default behavior for storage\n"
+      "resource providers is to only expose resources for pre-existing\n"
+      "volumes and not publish RAW volumes.");
+
   add(&Flags::isolation,
       "isolation",
       "Isolation mechanisms to use, e.g., `posix/cpu,posix/mem` (or \n"

http://git-wip-us.apache.org/repos/asf/mesos/blob/f4743f76/src/slave/flags.hpp
----------------------------------------------------------------------
diff --git a/src/slave/flags.hpp b/src/slave/flags.hpp
index 5918484..d5f95fe 100644
--- a/src/slave/flags.hpp
+++ b/src/slave/flags.hpp
@@ -46,6 +46,7 @@ public:
   bool hostname_lookup;
   Option<std::string> resources;
   Option<std::string> resource_provider_config_dir;
+  Option<std::string> volume_profile_adaptor;
   std::string isolation;
   std::string launcher;
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/f4743f76/src/slave/slave.cpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index e69d42a..2dfbdeb 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -419,6 +419,22 @@ void Slave::initialize()
       << mkdir.error();
   }
 
+  // Create the VolumeProfileAdaptor module and set it globally so
+  // any component that needs the module can share this instance.
+  Try<VolumeProfileAdaptor*> _volumeProfileAdaptor =
+    VolumeProfileAdaptor::create(flags.volume_profile_adaptor);
+
+  if (_volumeProfileAdaptor.isError()) {
+    EXIT(EXIT_FAILURE)
+      << "Failed to create volume profile adaptor: "
+      << _volumeProfileAdaptor.error();
+  }
+
+  volumeProfileAdaptor =
+    shared_ptr<VolumeProfileAdaptor>(_volumeProfileAdaptor.get());
+
+  VolumeProfileAdaptor::setAdaptor(volumeProfileAdaptor);
+
   string scheme = "http";
 
 #ifdef USE_SSL_SOCKET

http://git-wip-us.apache.org/repos/asf/mesos/blob/f4743f76/src/slave/slave.hpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.hpp b/src/slave/slave.hpp
index 75cc583..52759b1 100644
--- a/src/slave/slave.hpp
+++ b/src/slave/slave.hpp
@@ -40,6 +40,8 @@
 
 #include <mesos/module/authenticatee.hpp>
 
+#include <mesos/resource_provider/volume_profile.hpp>
+
 #include <mesos/slave/containerizer.hpp>
 #include <mesos/slave/qos_controller.hpp>
 #include <mesos/slave/resource_estimator.hpp>
@@ -724,6 +726,8 @@ private:
 
   mesos::slave::QoSController* qosController;
 
+  std::shared_ptr<VolumeProfileAdaptor> volumeProfileAdaptor;
+
   mesos::SecretGenerator* secretGenerator;
 
   const Option<Authorizer*> authorizer;