Updated CSI helpers for v0.2.

This patch adds new helper classes for CSI plugin and node capabilities,
removed helpers for the removed csi.Version proto message, and makes
the VolumeState proto message uses csi::v0::VolumeCapability.

NOTE: This is not future-proof if there is a breaking change in
VolumeCapability, we might need to change VolumeState to support
multiple CSI versions in the future.

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


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

Branch: refs/heads/master
Commit: ea5d10873667815a026ec76af5ae94968f206084
Parents: 33eb3eb
Author: Chun-Hung Hsiao <[email protected]>
Authored: Thu Apr 12 12:07:14 2018 -0700
Committer: Chun-Hung Hsiao <[email protected]>
Committed: Thu Apr 12 14:01:52 2018 -0700

----------------------------------------------------------------------
 src/csi/state.hpp   | 15 +++++++++++
 src/csi/state.proto |  8 +++---
 src/csi/utils.cpp   | 40 ++-------------------------
 src/csi/utils.hpp   | 70 +++++++++++++++++++++++++++++++++++++++---------
 4 files changed, 78 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/ea5d1087/src/csi/state.hpp
----------------------------------------------------------------------
diff --git a/src/csi/state.hpp b/src/csi/state.hpp
index dcbc7ab..87ff13d 100644
--- a/src/csi/state.hpp
+++ b/src/csi/state.hpp
@@ -21,4 +21,19 @@
 // ONLY USEFUL AFTER RUNNING PROTOC.
 #include "csi/state.pb.h"
 
+namespace mesos {
+namespace csi {
+namespace state {
+
+inline std::ostream& operator<<(
+    std::ostream& stream,
+    const VolumeState::State& state)
+{
+  return stream << VolumeState::State_Name(state);
+}
+
+} // namespace state {
+} // namespace csi {
+} // namespace mesos {
+
 #endif // __CSI_STATE_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/ea5d1087/src/csi/state.proto
----------------------------------------------------------------------
diff --git a/src/csi/state.proto b/src/csi/state.proto
index 0373c8a..a252cb2 100644
--- a/src/csi/state.proto
+++ b/src/csi/state.proto
@@ -39,18 +39,18 @@ message VolumeState {
 
   // The capability used to publish the volume. This is a
   // REQUIRED field.
-  .csi.VolumeCapability volume_capability = 2;
+  .csi.v0.VolumeCapability volume_capability = 2;
 
   // Attributes of the volume to be used on the node. This field MUST
-  // match the attributes of the `VolumeInfo` returned by
-  // `CreateVolume`. This is an OPTIONAL field.
+  // match the attributes of the `Volume` returned by `CreateVolume`.
+  // This is an OPTIONAL field.
   map<string, string> volume_attributes = 3;
 
   // If the plugin has the `PUBLISH_UNPUBLISH_VOLUME` controller
   // capability, this field MUST be set to the value returned by
   // `ControllerPublishVolume`. Otherwise, this field MUST remain unset.
   // This is an OPTIONAL field.
-  map<string, string> publish_volume_info = 4;
+  map<string, string> publish_info = 4;
 
   // This field is used to check if the node has been rebooted since the
   // last time the volume is mounted. If yes, `NodePublishVolume` needs

http://git-wip-us.apache.org/repos/asf/mesos/blob/ea5d1087/src/csi/utils.cpp
----------------------------------------------------------------------
diff --git a/src/csi/utils.cpp b/src/csi/utils.cpp
index 9e04357..fd6f95d 100644
--- a/src/csi/utils.cpp
+++ b/src/csi/utils.cpp
@@ -26,6 +26,7 @@ using std::string;
 using google::protobuf::util::MessageToJsonString;
 
 namespace csi {
+namespace v0 {
 
 bool operator==(
     const ControllerServiceCapability::RPC& left,
@@ -44,14 +45,6 @@ bool operator==(
 }
 
 
-bool operator==(const Version& left, const Version& right)
-{
-  return left.major() == right.major() &&
-    left.minor() == right.minor() &&
-    left.patch() == right.patch();
-}
-
-
 bool operator==(const VolumeCapability& left, const VolumeCapability& right) {
   // NOTE: This enumeration is set when `block` or `mount` are set and
   // covers the case where neither are set.
@@ -93,12 +86,6 @@ bool operator==(const VolumeCapability& left, const 
VolumeCapability& right) {
 }
 
 
-bool operator!=(const Version& left, const Version& right)
-{
-  return !(left == right);
-}
-
-
 ostream& operator<<(
     ostream& stream,
     const ControllerServiceCapability::RPC::Type& type)
@@ -106,28 +93,5 @@ ostream& operator<<(
   return stream << ControllerServiceCapability::RPC::Type_Name(type);
 }
 
-
-ostream& operator<<(ostream& stream, const Version& version)
-{
-  return stream << strings::join(
-      ".",
-      version.major(),
-      version.minor(),
-      version.patch());
-}
-
-} // namespace csi {
-
-
-namespace mesos {
-namespace csi {
-namespace state {
-
-ostream& operator<<(ostream& stream, const VolumeState::State& state)
-{
-  return stream << VolumeState::State_Name(state);
-}
-
-} // namespace state {
+} // namespace v0 {
 } // namespace csi {
-} // namespace mesos {

http://git-wip-us.apache.org/repos/asf/mesos/blob/ea5d1087/src/csi/utils.hpp
----------------------------------------------------------------------
diff --git a/src/csi/utils.hpp b/src/csi/utils.hpp
index 58b071d..5ce318e 100644
--- a/src/csi/utils.hpp
+++ b/src/csi/utils.hpp
@@ -35,29 +35,21 @@
 #include "csi/state.hpp"
 
 namespace csi {
+namespace v0 {
 
 bool operator==(
     const ControllerServiceCapability& left,
     const ControllerServiceCapability& right);
 
 
-bool operator==(const Version& left, const Version& right);
-
-
 bool operator==(const VolumeCapability& left, const VolumeCapability& right);
 
 
-bool operator!=(const Version& left, const Version& right);
-
-
 std::ostream& operator<<(
     std::ostream& stream,
     const ControllerServiceCapability::RPC::Type& type);
 
 
-std::ostream& operator<<(std::ostream& stream, const Version& version);
-
-
 // Default imprementation for output protobuf messages in namespace
 // `csi`. Note that any non-template overloading of the output operator
 // would take precedence over this function template.
@@ -73,11 +65,41 @@ std::ostream& operator<<(std::ostream& stream, const 
Message& message)
   return stream << output;
 }
 
+} // namespace v0 {
 } // namespace csi {
 
 
 namespace mesos {
 namespace csi {
+namespace v0 {
+
+struct PluginCapabilities
+{
+  PluginCapabilities() = default;
+
+  template <typename Iterable> PluginCapabilities(const Iterable& capabilities)
+  {
+    foreach (const auto& capability, capabilities) {
+      if (capability.has_service() &&
+          PluginCapability::Service::Type_IsValid(
+              capability.service().type())) {
+        switch (capability.service().type()) {
+          case PluginCapability::Service::UNKNOWN:
+            break;
+          case PluginCapability::Service::CONTROLLER_SERVICE:
+            controllerService = true;
+            break;
+          case google::protobuf::kint32min:
+          case google::protobuf::kint32max:
+            UNREACHABLE();
+        }
+      }
+    }
+  }
+
+  bool controllerService = false;
+};
+
 
 struct ControllerCapabilities
 {
@@ -90,7 +112,7 @@ struct ControllerCapabilities
       if (capability.has_rpc() &&
           ControllerServiceCapability::RPC::Type_IsValid(
               capability.rpc().type())) {
-        switch(capability.rpc().type()) {
+        switch (capability.rpc().type()) {
           case ControllerServiceCapability::RPC::UNKNOWN:
             break;
           case ControllerServiceCapability::RPC::CREATE_DELETE_VOLUME:
@@ -120,11 +142,33 @@ struct ControllerCapabilities
 };
 
 
-namespace state {
+struct NodeCapabilities
+{
+  NodeCapabilities() = default;
 
-std::ostream& operator<<(std::ostream& stream, const VolumeState::State& 
state);
+  template <typename Iterable> NodeCapabilities(const Iterable& capabilities)
+  {
+    foreach (const auto& capability, capabilities) {
+      if (capability.has_rpc() &&
+          NodeServiceCapability::RPC::Type_IsValid(capability.rpc().type())) {
+        switch (capability.rpc().type()) {
+          case NodeServiceCapability::RPC::UNKNOWN:
+            break;
+          case NodeServiceCapability::RPC::STAGE_UNSTAGE_VOLUME:
+            stageUnstageVolume = true;
+            break;
+          case google::protobuf::kint32min:
+          case google::protobuf::kint32max:
+            UNREACHABLE();
+        }
+      }
+    }
+  }
+
+  bool stageUnstageVolume = false;
+};
 
-} // namespace state {
+} // namespace v0 {
 } // namespace csi {
 } // namespace mesos {
 

Reply via email to