Apache Mesos
v0_utils.hpp
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef __CSI_V0_UTILS_HPP__
18 #define __CSI_V0_UTILS_HPP__
19 
20 #include <google/protobuf/message.h>
21 
22 #include <mesos/mesos.hpp>
23 
24 #include <mesos/csi/v0.hpp>
25 
26 #include <stout/foreach.hpp>
27 #include <stout/unreachable.hpp>
28 
29 namespace mesos {
30 namespace csi {
31 namespace v0 {
32 
34 
35 
37 {
38  PluginCapabilities() = default;
39 
40  template <typename Iterable>
41  PluginCapabilities(const Iterable& capabilities)
42  {
43  foreach (const auto& capability, capabilities) {
44  if (capability.has_service() &&
45  PluginCapability::Service::Type_IsValid(
46  capability.service().type())) {
47  switch (capability.service().type()) {
49  break;
51  controllerService = true;
52  break;
53 
54  // NOTE: We avoid using a default clause for the following values in
55  // proto3's open enum to enable the compiler to detect missing enum
56  // cases for us. See: https://github.com/google/protobuf/issues/3917
57  case google::protobuf::kint32min:
58  case google::protobuf::kint32max:
59  UNREACHABLE();
60  }
61  }
62  }
63  }
64 
65  bool controllerService = false;
66 };
67 
68 
70 {
71  ControllerCapabilities() = default;
72 
73  template <typename Iterable>
74  ControllerCapabilities(const Iterable& capabilities)
75  {
76  foreach (const auto& capability, capabilities) {
77  if (capability.has_rpc() &&
78  ControllerServiceCapability::RPC::Type_IsValid(
79  capability.rpc().type())) {
80  switch (capability.rpc().type()) {
82  break;
83  case ControllerServiceCapability::RPC::CREATE_DELETE_VOLUME:
84  createDeleteVolume = true;
85  break;
86  case ControllerServiceCapability::RPC::PUBLISH_UNPUBLISH_VOLUME:
87  publishUnpublishVolume = true;
88  break;
89  case ControllerServiceCapability::RPC::LIST_VOLUMES:
90  listVolumes = true;
91  break;
92  case ControllerServiceCapability::RPC::GET_CAPACITY:
93  getCapacity = true;
94  break;
95 
96  // NOTE: We avoid using a default clause for the following values in
97  // proto3's open enum to enable the compiler to detect missing enum
98  // cases for us. See: https://github.com/google/protobuf/issues/3917
99  case google::protobuf::kint32min:
100  case google::protobuf::kint32max:
101  UNREACHABLE();
102  }
103  }
104  }
105  }
106 
107  bool createDeleteVolume = false;
108  bool publishUnpublishVolume = false;
109  bool listVolumes = false;
110  bool getCapacity = false;
111 };
112 
113 
115 {
116  NodeCapabilities() = default;
117 
118  template <typename Iterable>
119  NodeCapabilities(const Iterable& capabilities)
120  {
121  foreach (const auto& capability, capabilities) {
122  if (capability.has_rpc() &&
123  NodeServiceCapability::RPC::Type_IsValid(capability.rpc().type())) {
124  switch (capability.rpc().type()) {
126  break;
127  case NodeServiceCapability::RPC::STAGE_UNSTAGE_VOLUME:
128  stageUnstageVolume = true;
129  break;
130 
131  // NOTE: We avoid using a default clause for the following values in
132  // proto3's open enum to enable the compiler to detect missing enum
133  // cases for us. See: https://github.com/google/protobuf/issues/3917
134  case google::protobuf::kint32min:
135  case google::protobuf::kint32max:
136  UNREACHABLE();
137  }
138  }
139  }
140  }
141 
142  bool stageUnstageVolume = false;
143 };
144 
145 
146 // Helpers to devolve CSI v0 protobufs to their unversioned counterparts.
147 CSIVolume::VolumeCapability devolve(const VolumeCapability& capability);
148 
149 google::protobuf::RepeatedPtrField<CSIVolume::VolumeCapability> devolve(
150  const google::protobuf::RepeatedPtrField<VolumeCapability>& capabilities);
151 
152 
153 // Helpers to evolve unversioned CSI protobufs to their v0 counterparts.
154 VolumeCapability evolve(const CSIVolume::VolumeCapability& capability);
155 
156 google::protobuf::RepeatedPtrField<VolumeCapability> evolve(
157  const google::protobuf::RepeatedPtrField<CSIVolume::VolumeCapability>&
158  capabilities);
159 
160 } // namespace v0 {
161 } // namespace csi {
162 } // namespace mesos {
163 
164 #endif // __CSI_V0_UTILS_HPP__
Definition: v0_utils.hpp:69
Definition: v0.hpp:49
constexpr Service CONTROLLER_SERVICE
Definition: service_manager.hpp:40
Volume::Source::CSIVolume CSIVolume
Definition: v0_utils.hpp:33
Definition: v0_utils.hpp:36
Definition: agent.hpp:25
const int UNKNOWN
Definition: diagnosis.hpp:39
#define UNREACHABLE()
Definition: unreachable.hpp:22
CSIVolume::VolumeCapability devolve(const VolumeCapability &capability)
ControllerCapabilities(const Iterable &capabilities)
Definition: v0_utils.hpp:74
bool controllerService
Definition: v0_utils.hpp:65
Definition: v0_utils.hpp:114
PluginCapabilities(const Iterable &capabilities)
Definition: v0_utils.hpp:41
VolumeCapability evolve(const CSIVolume::VolumeCapability &capability)
NodeCapabilities(const Iterable &capabilities)
Definition: v0_utils.hpp:119