Added the `RPC` enum and `RPCTraits` helper. To make it easy to enumerate all types of CSI RPC calls, the `RPC` enum is introduced. The `RPCTraits` helper class can be used to determine the request and response type of a particular RPC.
Review: https://reviews.apache.org/r/67375 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/cae7d7a3 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/cae7d7a3 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/cae7d7a3 Branch: refs/heads/master Commit: cae7d7a385e9edf0db81d524c6a208f6ad8540fd Parents: 4314334 Author: Chun-Hung Hsiao <chhs...@mesosphere.io> Authored: Tue May 29 19:29:16 2018 -0700 Committer: Chun-Hung Hsiao <chhs...@mesosphere.io> Committed: Thu May 31 18:29:56 2018 -0700 ---------------------------------------------------------------------- src/CMakeLists.txt | 3 +- src/Makefile.am | 4 +- src/csi/rpc.cpp | 105 +++++++++++++++++++++++++ src/csi/rpc.hpp | 201 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 311 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/cae7d7a3/src/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f86884d..02798ed 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -242,7 +242,8 @@ set(CSI_SRC if (ENABLE_GRPC) list(APPEND CSI_SRC - csi/client.cpp) + csi/client.cpp + csi/rpc.cpp) endif () set(DOCKER_SRC http://git-wip-us.apache.org/repos/asf/mesos/blob/cae7d7a3/src/Makefile.am ---------------------------------------------------------------------- diff --git a/src/Makefile.am b/src/Makefile.am index b7184ce..874305a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1548,7 +1548,9 @@ libcsi_la_SOURCES += \ if ENABLE_GRPC libcsi_la_SOURCES += \ csi/client.cpp \ - csi/client.hpp + csi/client.hpp \ + csi/rpc.cpp \ + csi/rpc.hpp endif nodist_libcsi_la_SOURCES = $(CXX_CSI_PROTOS) http://git-wip-us.apache.org/repos/asf/mesos/blob/cae7d7a3/src/csi/rpc.cpp ---------------------------------------------------------------------- diff --git a/src/csi/rpc.cpp b/src/csi/rpc.cpp new file mode 100644 index 0000000..e8a2770 --- /dev/null +++ b/src/csi/rpc.cpp @@ -0,0 +1,105 @@ +// 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/rpc.hpp" + +#include <stout/unreachable.hpp> + +using std::ostream; + +namespace mesos { +namespace csi { +namespace v0 { + +ostream& operator<<(ostream& stream, const RPC& rpc) +{ + switch (rpc) { + case GET_PLUGIN_INFO: + return stream + << Identity::service_full_name() + << ".GetPluginInfo"; + case GET_PLUGIN_CAPABILITIES: + return stream + << Identity::service_full_name() + << ".GetPluginCapabilities"; + case PROBE: + return stream + << Identity::service_full_name() + << ".Probe"; + case CREATE_VOLUME: + return stream + << Controller::service_full_name() + << ".CreateVolume"; + case DELETE_VOLUME: + return stream + << Controller::service_full_name() + << ".DeleteVolume"; + case CONTROLLER_PUBLISH_VOLUME: + return stream + << Controller::service_full_name() + << ".ControllerPublishVolume"; + case CONTROLLER_UNPUBLISH_VOLUME: + return stream + << Controller::service_full_name() + << ".ControllerUnpublishVolume"; + case VALIDATE_VOLUME_CAPABILITIES: + return stream + << Controller::service_full_name() + << ".ValidateVolumeCapabilities"; + case LIST_VOLUMES: + return stream + << Controller::service_full_name() + << ".ListVolumes"; + case GET_CAPACITY: + return stream + << Controller::service_full_name() + << ".GetCapacity"; + case CONTROLLER_GET_CAPABILITIES: + return stream + << Controller::service_full_name() + << ".ControllerGetCapabilities"; + case NODE_STAGE_VOLUME: + return stream + << Node::service_full_name() + << ".NodeStageVolume"; + case NODE_UNSTAGE_VOLUME: + return stream + << Node::service_full_name() + << ".NodeUnstageVolume"; + case NODE_PUBLISH_VOLUME: + return stream + << Node::service_full_name() + << ".NodePublishVolume"; + case NODE_UNPUBLISH_VOLUME: + return stream + << Node::service_full_name() + << ".NodeUnpublishVolume"; + case NODE_GET_ID: + return stream + << Node::service_full_name() + << ".NodeGetId"; + case NODE_GET_CAPABILITIES: + return stream + << Node::service_full_name() + << ".NodeGetCapabilities"; + } + + UNREACHABLE(); +} + +} // namespace v0 { +} // namespace csi { +} // namespace mesos { http://git-wip-us.apache.org/repos/asf/mesos/blob/cae7d7a3/src/csi/rpc.hpp ---------------------------------------------------------------------- diff --git a/src/csi/rpc.hpp b/src/csi/rpc.hpp new file mode 100644 index 0000000..c30a509 --- /dev/null +++ b/src/csi/rpc.hpp @@ -0,0 +1,201 @@ +// 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_RPC_HPP__ +#define __CSI_RPC_HPP__ + +#include <ostream> + +#include <csi/spec.hpp> + +namespace mesos { +namespace csi { +namespace v0 { + +enum RPC +{ + // RPCs for the Identity service. + GET_PLUGIN_INFO, + GET_PLUGIN_CAPABILITIES, + PROBE, + + // RPCs for the Controller service. + CREATE_VOLUME, + DELETE_VOLUME, + CONTROLLER_PUBLISH_VOLUME, + CONTROLLER_UNPUBLISH_VOLUME, + VALIDATE_VOLUME_CAPABILITIES, + LIST_VOLUMES, + GET_CAPACITY, + CONTROLLER_GET_CAPABILITIES, + + // RPCs for the Node service. + NODE_STAGE_VOLUME, + NODE_UNSTAGE_VOLUME, + NODE_PUBLISH_VOLUME, + NODE_UNPUBLISH_VOLUME, + NODE_GET_ID, + NODE_GET_CAPABILITIES +}; + + +template <RPC> +struct RPCTraits; + + +template <> +struct RPCTraits<GET_PLUGIN_INFO> +{ + typedef GetPluginInfoRequest request_type; + typedef GetPluginInfoResponse response_type; +}; + + +template <> +struct RPCTraits<GET_PLUGIN_CAPABILITIES> +{ + typedef GetPluginCapabilitiesRequest request_type; + typedef GetPluginCapabilitiesResponse response_type; +}; + + +template <> +struct RPCTraits<PROBE> +{ + typedef ProbeRequest request_type; + typedef ProbeResponse response_type; +}; + + +template <> +struct RPCTraits<CREATE_VOLUME> +{ + typedef CreateVolumeRequest request_type; + typedef CreateVolumeResponse response_type; +}; + + +template <> +struct RPCTraits<DELETE_VOLUME> +{ + typedef DeleteVolumeRequest request_type; + typedef DeleteVolumeResponse response_type; +}; + + +template <> +struct RPCTraits<CONTROLLER_PUBLISH_VOLUME> +{ + typedef ControllerPublishVolumeRequest request_type; + typedef ControllerPublishVolumeResponse response_type; +}; + + +template <> +struct RPCTraits<CONTROLLER_UNPUBLISH_VOLUME> +{ + typedef ControllerUnpublishVolumeRequest request_type; + typedef ControllerUnpublishVolumeResponse response_type; +}; + + +template <> +struct RPCTraits<VALIDATE_VOLUME_CAPABILITIES> +{ + typedef ValidateVolumeCapabilitiesRequest request_type; + typedef ValidateVolumeCapabilitiesResponse response_type; +}; + + +template <> +struct RPCTraits<LIST_VOLUMES> +{ + typedef ListVolumesRequest request_type; + typedef ListVolumesResponse response_type; +}; + + +template <> +struct RPCTraits<GET_CAPACITY> +{ + typedef GetCapacityRequest request_type; + typedef GetCapacityResponse response_type; +}; + + +template <> +struct RPCTraits<CONTROLLER_GET_CAPABILITIES> +{ + typedef ControllerGetCapabilitiesRequest request_type; + typedef ControllerGetCapabilitiesResponse response_type; +}; + + +template <> +struct RPCTraits<NODE_STAGE_VOLUME> +{ + typedef NodeStageVolumeRequest request_type; + typedef NodeStageVolumeResponse response_type; +}; + + +template <> +struct RPCTraits<NODE_UNSTAGE_VOLUME> +{ + typedef NodeUnstageVolumeRequest request_type; + typedef NodeUnstageVolumeResponse response_type; +}; + + +template <> +struct RPCTraits<NODE_PUBLISH_VOLUME> +{ + typedef NodePublishVolumeRequest request_type; + typedef NodePublishVolumeResponse response_type; +}; + + +template <> +struct RPCTraits<NODE_UNPUBLISH_VOLUME> +{ + typedef NodeUnpublishVolumeRequest request_type; + typedef NodeUnpublishVolumeResponse response_type; +}; + + +template <> +struct RPCTraits<NODE_GET_ID> +{ + typedef NodeGetIdRequest request_type; + typedef NodeGetIdResponse response_type; +}; + + +template <> +struct RPCTraits<NODE_GET_CAPABILITIES> +{ + typedef NodeGetCapabilitiesRequest request_type; + typedef NodeGetCapabilitiesResponse response_type; +}; + + +std::ostream& operator<<(std::ostream& stream, const RPC& rpc); + +} // namespace v0 { +} // namespace csi { +} // namespace mesos { + +#endif // __CSI_RPC_HPP__