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/11/30 00:04:20 UTC

[09/13] mesos git commit: Added utility functions and structures for CSI version and capabilities.

Added utility functions and structures for CSI version and capabilities.

This patch adds some helper structures and functions for CSI protobuf.
The comparison and output operators for `csi::Version` are declared in
the `::csi` namespace so they can find it through ADL. Also, it exposes
`::csi` in `mesos::csi` in `spec.hpp` instead of `client.hpp`.

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


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

Branch: refs/heads/master
Commit: 8bca4bedb8e492a3e6c037a3174f2aacb4dcd20a
Parents: bec1cfd
Author: Chun-Hung Hsiao <ch...@mesosphere.io>
Authored: Wed Nov 29 15:31:07 2017 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Wed Nov 29 15:31:07 2017 -0800

----------------------------------------------------------------------
 src/Makefile.am    |  6 ++--
 src/csi/client.hpp |  2 --
 src/csi/spec.hpp   |  8 +++++
 src/csi/utils.cpp  | 42 +++++++++++++++++++++++++
 src/csi/utils.hpp  | 83 +++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 137 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/8bca4bed/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index a82ec7f..9438a7e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1493,11 +1493,13 @@ if ENABLE_GRPC
 noinst_LTLIBRARIES += libcsi.la
 libcsi_la_SOURCES =							\
   csi/client.cpp							\
-  csi/paths.cpp
+  csi/paths.cpp								\
+  csi/utils.cpp
 libcsi_la_SOURCES +=							\
   csi/client.hpp							\
   csi/paths.hpp								\
-  csi/spec.hpp
+  csi/spec.hpp								\
+  csi/utils.hpp
 nodist_libcsi_la_SOURCES = $(CXX_CSI_PROTOS)
 libcsi_la_CPPFLAGS = $(MESOS_CPPFLAGS)
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/8bca4bed/src/csi/client.hpp
----------------------------------------------------------------------
diff --git a/src/csi/client.hpp b/src/csi/client.hpp
index a5571f4..91dda0d 100644
--- a/src/csi/client.hpp
+++ b/src/csi/client.hpp
@@ -26,8 +26,6 @@
 namespace mesos {
 namespace csi {
 
-using namespace ::csi;
-
 class Client
 {
 public:

http://git-wip-us.apache.org/repos/asf/mesos/blob/8bca4bed/src/csi/spec.hpp
----------------------------------------------------------------------
diff --git a/src/csi/spec.hpp b/src/csi/spec.hpp
index 60e40e0..c819be3 100644
--- a/src/csi/spec.hpp
+++ b/src/csi/spec.hpp
@@ -20,4 +20,12 @@
 // ONLY USEFUL AFTER RUNNING PROTOC WITH GRPC CPP PLUGIN.
 #include "csi/csi.grpc.pb.h"
 
+namespace mesos {
+namespace csi {
+
+using namespace ::csi;
+
+} // namespace csi {
+} // namespace mesos {
+
 #endif // __CSI_SPEC_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/8bca4bed/src/csi/utils.cpp
----------------------------------------------------------------------
diff --git a/src/csi/utils.cpp b/src/csi/utils.cpp
new file mode 100644
index 0000000..ef1bf69
--- /dev/null
+++ b/src/csi/utils.cpp
@@ -0,0 +1,42 @@
+// 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 "csi/utils.hpp"
+
+#include <stout/strings.hpp>
+
+using std::ostream;
+
+namespace csi {
+
+bool operator==(const Version& left, const Version& right)
+{
+  return left.major() == right.major() &&
+    left.minor() == right.minor() &&
+    left.patch() == right.patch();
+}
+
+
+ostream& operator<<(ostream& stream, const Version& version)
+{
+  return stream << strings::join(
+      ".",
+      version.major(),
+      version.minor(),
+      version.patch());
+}
+
+} // namespace csi {

http://git-wip-us.apache.org/repos/asf/mesos/blob/8bca4bed/src/csi/utils.hpp
----------------------------------------------------------------------
diff --git a/src/csi/utils.hpp b/src/csi/utils.hpp
new file mode 100644
index 0000000..0a8622c
--- /dev/null
+++ b/src/csi/utils.hpp
@@ -0,0 +1,83 @@
+// 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 __CSI_UTILS_HPP__
+#define __CSI_UTILS_HPP__
+
+#include <ostream>
+
+#include <stout/foreach.hpp>
+#include <stout/unreachable.hpp>
+
+#include "csi/spec.hpp"
+
+namespace csi {
+
+bool operator==(const Version& left, const Version& right);
+
+
+std::ostream& operator<<(std::ostream& stream, const Version& version);
+
+} // namespace csi {
+
+
+namespace mesos {
+namespace csi {
+
+struct ControllerCapabilities
+{
+  ControllerCapabilities() = default;
+
+  template <typename Iterable>
+  ControllerCapabilities(const Iterable& capabilities)
+  {
+    foreach (const auto& capability, capabilities) {
+      if (capability.has_rpc() &&
+          ControllerServiceCapability::RPC::Type_IsValid(
+              capability.rpc().type())) {
+        switch(capability.rpc().type()) {
+          case ControllerServiceCapability::RPC::UNKNOWN:
+            break;
+          case ControllerServiceCapability::RPC::CREATE_DELETE_VOLUME:
+            createDeleteVolume = true;
+            break;
+          case ControllerServiceCapability::RPC::PUBLISH_UNPUBLISH_VOLUME:
+            publishUnpublishVolume = true;
+            break;
+          case ControllerServiceCapability::RPC::LIST_VOLUMES:
+            listVolumes = true;
+            break;
+          case ControllerServiceCapability::RPC::GET_CAPACITY:
+            getCapacity = true;
+            break;
+          case google::protobuf::kint32min:
+          case google::protobuf::kint32max:
+            UNREACHABLE();
+        }
+      }
+    }
+  }
+
+  bool createDeleteVolume = false;
+  bool publishUnpublishVolume = false;
+  bool listVolumes = false;
+  bool getCapacity = false;
+};
+
+} // namespace csi {
+} // namespace mesos {
+
+#endif // __CSI_UTILS_HPP__