[mesos] 02/06: Added capabilities and evolve/devolve helpers for CSI v1.

2019-04-09 Thread chhsiao
This is an automated email from the ASF dual-hosted git repository.

chhsiao pushed a commit to branch 1.8.x
in repository https://gitbox.apache.org/repos/asf/mesos.git

commit e22d60212d3859b69b64b8b7c4d063856df29665
Author: Chun-Hung Hsiao 
AuthorDate: Thu Apr 4 16:27:48 2019 -0700

Added capabilities and evolve/devolve helpers for CSI v1.

This patch adds capability helper structures for CSI v1 services, and
evolve/devolve helpers to convert between CSI v1 protobufs and their
unversioned counterparts.

Review: https://reviews.apache.org/r/70400
---
 src/CMakeLists.txt|   1 +
 src/Makefile.am   |   2 +
 src/csi/v1_utils.cpp  | 242 ++
 src/csi/v1_utils.hpp  | 218 +
 src/tests/csi_utils_tests.cpp |  50 +++--
 5 files changed, 507 insertions(+), 6 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 51c7a04..d36d0be 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -243,6 +243,7 @@ set(CSI_SRC
   csi/v0_volume_manager.cpp
   csi/v1.cpp
   csi/v1_client.cpp
+  csi/v1_utils.cpp
   csi/volume_manager.cpp)
 
 set(DOCKER_SRC
diff --git a/src/Makefile.am b/src/Makefile.am
index 9c0180f..64898df 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1598,6 +1598,8 @@ libcsi_la_SOURCES =   
\
   csi/v1.cpp   \
   csi/v1_client.cpp\
   csi/v1_client.hpp\
+  csi/v1_utils.cpp \
+  csi/v1_utils.hpp \
   csi/volume_manager.cpp   \
   csi/volume_manager.hpp
 
diff --git a/src/csi/v1_utils.cpp b/src/csi/v1_utils.cpp
new file mode 100644
index 000..e74138b
--- /dev/null
+++ b/src/csi/v1_utils.cpp
@@ -0,0 +1,242 @@
+// 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/v1_utils.hpp"
+
+using google::protobuf::RepeatedPtrField;
+
+namespace mesos {
+namespace csi {
+namespace v1 {
+
+// Helper for repeated field devolving to `T1` from `T2`.
+template 
+RepeatedPtrField devolve(RepeatedPtrField from)
+{
+  RepeatedPtrField to;
+  foreach (const T2& value, from) {
+*to.Add() = devolve(value);
+  }
+
+  return to;
+}
+
+
+types::VolumeCapability::BlockVolume devolve(
+const VolumeCapability::BlockVolume& block)
+{
+  return types::VolumeCapability::BlockVolume();
+}
+
+
+types::VolumeCapability::MountVolume devolve(
+const VolumeCapability::MountVolume& mount)
+{
+  types::VolumeCapability::MountVolume result;
+  result.set_fs_type(mount.fs_type());
+  *result.mutable_mount_flags() = mount.mount_flags();
+  return result;
+}
+
+
+types::VolumeCapability::AccessMode devolve(
+const VolumeCapability::AccessMode& accessMode)
+{
+  types::VolumeCapability::AccessMode result;
+
+  switch (accessMode.mode()) {
+case VolumeCapability::AccessMode::UNKNOWN: {
+  result.set_mode(types::VolumeCapability::AccessMode::UNKNOWN);
+  break;
+}
+case VolumeCapability::AccessMode::SINGLE_NODE_WRITER: {
+  result.set_mode(types::VolumeCapability::AccessMode::SINGLE_NODE_WRITER);
+  break;
+}
+case VolumeCapability::AccessMode::SINGLE_NODE_READER_ONLY: {
+  result.set_mode(
+  types::VolumeCapability::AccessMode::SINGLE_NODE_READER_ONLY);
+  break;
+}
+case VolumeCapability::AccessMode::MULTI_NODE_READER_ONLY: {
+  result.set_mode(
+  types::VolumeCapability::AccessMode::MULTI_NODE_READER_ONLY);
+  break;
+}
+case VolumeCapability::AccessMode::MULTI_NODE_SINGLE_WRITER: {
+  result.set_mode(
+  types::VolumeCapability::AccessMode::MULTI_NODE_SINGLE_WRITER);
+  break;
+}
+case VolumeCapability::AccessMode::MULTI_NODE_MULTI_WRITER: {
+  result.set_mode(
+  types::VolumeCapability::AccessMode::MULTI_NODE_MULTI_WRITER);
+  break;
+}
+// NOTE: We avoid using a default clause for the following values in
+// 

[mesos] 02/06: Added capabilities and evolve/devolve helpers for CSI v1.

2019-04-09 Thread chhsiao
This is an automated email from the ASF dual-hosted git repository.

chhsiao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git

commit 645c6ed89852404b0ee483f12f1ced354ced13fc
Author: Chun-Hung Hsiao 
AuthorDate: Thu Apr 4 16:27:48 2019 -0700

Added capabilities and evolve/devolve helpers for CSI v1.

This patch adds capability helper structures for CSI v1 services, and
evolve/devolve helpers to convert between CSI v1 protobufs and their
unversioned counterparts.

Review: https://reviews.apache.org/r/70400
---
 src/CMakeLists.txt|   1 +
 src/Makefile.am   |   2 +
 src/csi/v1_utils.cpp  | 242 ++
 src/csi/v1_utils.hpp  | 218 +
 src/tests/csi_utils_tests.cpp |  50 +++--
 5 files changed, 507 insertions(+), 6 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 51c7a04..d36d0be 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -243,6 +243,7 @@ set(CSI_SRC
   csi/v0_volume_manager.cpp
   csi/v1.cpp
   csi/v1_client.cpp
+  csi/v1_utils.cpp
   csi/volume_manager.cpp)
 
 set(DOCKER_SRC
diff --git a/src/Makefile.am b/src/Makefile.am
index 9c0180f..64898df 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1598,6 +1598,8 @@ libcsi_la_SOURCES =   
\
   csi/v1.cpp   \
   csi/v1_client.cpp\
   csi/v1_client.hpp\
+  csi/v1_utils.cpp \
+  csi/v1_utils.hpp \
   csi/volume_manager.cpp   \
   csi/volume_manager.hpp
 
diff --git a/src/csi/v1_utils.cpp b/src/csi/v1_utils.cpp
new file mode 100644
index 000..e74138b
--- /dev/null
+++ b/src/csi/v1_utils.cpp
@@ -0,0 +1,242 @@
+// 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/v1_utils.hpp"
+
+using google::protobuf::RepeatedPtrField;
+
+namespace mesos {
+namespace csi {
+namespace v1 {
+
+// Helper for repeated field devolving to `T1` from `T2`.
+template 
+RepeatedPtrField devolve(RepeatedPtrField from)
+{
+  RepeatedPtrField to;
+  foreach (const T2& value, from) {
+*to.Add() = devolve(value);
+  }
+
+  return to;
+}
+
+
+types::VolumeCapability::BlockVolume devolve(
+const VolumeCapability::BlockVolume& block)
+{
+  return types::VolumeCapability::BlockVolume();
+}
+
+
+types::VolumeCapability::MountVolume devolve(
+const VolumeCapability::MountVolume& mount)
+{
+  types::VolumeCapability::MountVolume result;
+  result.set_fs_type(mount.fs_type());
+  *result.mutable_mount_flags() = mount.mount_flags();
+  return result;
+}
+
+
+types::VolumeCapability::AccessMode devolve(
+const VolumeCapability::AccessMode& accessMode)
+{
+  types::VolumeCapability::AccessMode result;
+
+  switch (accessMode.mode()) {
+case VolumeCapability::AccessMode::UNKNOWN: {
+  result.set_mode(types::VolumeCapability::AccessMode::UNKNOWN);
+  break;
+}
+case VolumeCapability::AccessMode::SINGLE_NODE_WRITER: {
+  result.set_mode(types::VolumeCapability::AccessMode::SINGLE_NODE_WRITER);
+  break;
+}
+case VolumeCapability::AccessMode::SINGLE_NODE_READER_ONLY: {
+  result.set_mode(
+  types::VolumeCapability::AccessMode::SINGLE_NODE_READER_ONLY);
+  break;
+}
+case VolumeCapability::AccessMode::MULTI_NODE_READER_ONLY: {
+  result.set_mode(
+  types::VolumeCapability::AccessMode::MULTI_NODE_READER_ONLY);
+  break;
+}
+case VolumeCapability::AccessMode::MULTI_NODE_SINGLE_WRITER: {
+  result.set_mode(
+  types::VolumeCapability::AccessMode::MULTI_NODE_SINGLE_WRITER);
+  break;
+}
+case VolumeCapability::AccessMode::MULTI_NODE_MULTI_WRITER: {
+  result.set_mode(
+  types::VolumeCapability::AccessMode::MULTI_NODE_MULTI_WRITER);
+  break;
+}
+// NOTE: We avoid using a default clause for the following values in
+//