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 6ef64a3a6ff34975d58abbb0b78e2b402d39873c Author: Chun-Hung Hsiao <[email protected]> AuthorDate: Thu Mar 28 22:14:32 2019 -0700 Added spec inclusion header and type helpers for CSI v1. Review: https://reviews.apache.org/r/70361 --- include/mesos/csi/v1.hpp | 103 +++++++++++++++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 1 + src/Makefile.am | 4 +- src/csi/v1.cpp | 32 +++++++++++++++ 4 files changed, 139 insertions(+), 1 deletion(-) diff --git a/include/mesos/csi/v1.hpp b/include/mesos/csi/v1.hpp new file mode 100644 index 0000000..d4ebe42 --- /dev/null +++ b/include/mesos/csi/v1.hpp @@ -0,0 +1,103 @@ +// 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 __MESOS_CSI_V1_HPP__ +#define __MESOS_CSI_V1_HPP__ + +#include <ostream> +#include <type_traits> + +// ONLY USEFUL AFTER RUNNING PROTOC. +#include <csi/v1/csi.pb.h> + +// ONLY USEFUL AFTER RUNNING PROTOC WITH GRPC CPP PLUGIN. +#include <csi/v1/csi.grpc.pb.h> + +#include <google/protobuf/message.h> + +#include <google/protobuf/util/json_util.h> +#include <google/protobuf/util/message_differencer.h> + +#include <stout/check.hpp> + +namespace mesos { +namespace csi { +namespace v1 { + +using namespace ::csi::v1; + +} // namespace v1 { +} // namespace csi { +} // namespace mesos { + + +namespace csi { +namespace v1 { + +// Default implementation for comparing protobuf messages in namespace +// `csi::v1`. Note that any non-template overloading of the equality operator +// would take precedence over this function template. +template < + typename Message, + typename std::enable_if<std::is_convertible< + Message*, google::protobuf::Message*>::value, int>::type = 0> +bool operator==(const Message& left, const Message& right) +{ + // NOTE: `MessageDifferencer::Equivalent` would ignore unknown fields and load + // default values for unset fields (which are indistinguishable in proto3). + return google::protobuf::util::MessageDifferencer::Equivalent(left, right); +} + + +template < + typename Message, + typename std::enable_if<std::is_convertible< + Message*, google::protobuf::Message*>::value, int>::type = 0> +bool operator!=(const Message& left, const Message& right) +{ + return !(left == right); +} + + +std::ostream& operator<<( + std::ostream& stream, + const ControllerServiceCapability::RPC::Type& type); + + +// Default implementation for output protobuf messages in namespace `csi::v1`. +// Note that any non-template overloading of the output operator would take +// precedence over this function template. +template < + typename Message, + typename std::enable_if<std::is_convertible< + Message*, google::protobuf::Message*>::value, int>::type = 0> +std::ostream& operator<<(std::ostream& stream, const Message& message) +{ + // NOTE: We use Google's JSON utility functions for proto3. + std::string output; + google::protobuf::util::Status status = + google::protobuf::util::MessageToJsonString(message, &output); + + CHECK(status.ok()) + << "Could not convert messages to string: " << status.error_message(); + + return stream << output; +} + +} // namespace v1 { +} // namespace csi { + +#endif // __MESOS_CSI_V1_HPP__ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5ffeccd..0512044 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -241,6 +241,7 @@ set(CSI_SRC csi/v0_client.cpp csi/v0_utils.cpp csi/v0_volume_manager.cpp + csi/v1.cpp csi/volume_manager.cpp) set(DOCKER_SRC diff --git a/src/Makefile.am b/src/Makefile.am index 6782e4b..2f25a84 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -710,7 +710,8 @@ csidir = $(pkgincludedir)/csi csi_HEADERS = \ $(top_srcdir)/include/mesos/csi/types.hpp \ $(top_srcdir)/include/mesos/csi/types.proto \ - $(top_srcdir)/include/mesos/csi/v0.hpp + $(top_srcdir)/include/mesos/csi/v0.hpp \ + $(top_srcdir)/include/mesos/csi/v1.hpp nodist_csi_HEADERS = \ ../include/mesos/csi/types.pb.h @@ -1594,6 +1595,7 @@ libcsi_la_SOURCES = \ csi/v0_volume_manager.cpp \ csi/v0_volume_manager.hpp \ csi/v0_volume_manager_process.hpp \ + csi/v1.cpp \ csi/volume_manager.cpp \ csi/volume_manager.hpp diff --git a/src/csi/v1.cpp b/src/csi/v1.cpp new file mode 100644 index 0000000..a07d1fa --- /dev/null +++ b/src/csi/v1.cpp @@ -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. + +#include <mesos/csi/v1.hpp> + +using std::ostream; + +namespace csi { +namespace v1 { + +ostream& operator<<( + ostream& stream, + const ControllerServiceCapability::RPC::Type& type) +{ + return stream << ControllerServiceCapability::RPC::Type_Name(type); +} + +} // namespace v1 { +} // namespace csi {
