Apache Mesos
v1_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_V1_UTILS_HPP__
18 #define __CSI_V1_UTILS_HPP__
19 
20 #include <google/protobuf/message.h>
21 
22 #include <mesos/mesos.hpp>
23 
24 #include <mesos/csi/v1.hpp>
25 
26 #include <stout/foreach.hpp>
27 #include <stout/unreachable.hpp>
28 
29 namespace mesos {
30 namespace csi {
31 namespace v1 {
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  case PluginCapability::Service::VOLUME_ACCESSIBILITY_CONSTRAINTS:
55  break;
56 
57  // NOTE: We avoid using a default clause for the following values in
58  // proto3's open enum to enable the compiler to detect missing enum
59  // cases for us. See: https://github.com/google/protobuf/issues/3917
60  case google::protobuf::kint32min:
61  case google::protobuf::kint32max:
62  UNREACHABLE();
63  }
64  }
65 
66  if (capability.has_volume_expansion() &&
67  PluginCapability::VolumeExpansion::Type_IsValid(
68  capability.volume_expansion().type())) {
69  switch (capability.volume_expansion().type()) {
71  break;
72  case PluginCapability::VolumeExpansion::ONLINE:
73  volumeExpansionOnline = true;
74  volumeExpansionOffline = false;
75  break;
76  case PluginCapability::VolumeExpansion::OFFLINE:
77  volumeExpansionOnline = false;
79  break;
80 
81  // NOTE: We avoid using a default clause for the following values in
82  // proto3's open enum to enable the compiler to detect missing enum
83  // cases for us. See: https://github.com/google/protobuf/issues/3917
84  case google::protobuf::kint32min:
85  case google::protobuf::kint32max:
86  UNREACHABLE();
87  }
88  }
89  }
90  }
91 
92  bool controllerService = false;
94  bool volumeExpansionOnline = false;
95  bool volumeExpansionOffline = false;
96 };
97 
98 
100 {
101  ControllerCapabilities() = default;
102 
103  template <typename Iterable>
104  ControllerCapabilities(const Iterable& capabilities)
105  {
106  foreach (const auto& capability, capabilities) {
107  if (capability.has_rpc() &&
108  ControllerServiceCapability::RPC::Type_IsValid(
109  capability.rpc().type())) {
110  switch (capability.rpc().type()) {
112  break;
113  case ControllerServiceCapability::RPC::CREATE_DELETE_VOLUME:
114  createDeleteVolume = true;
115  break;
116  case ControllerServiceCapability::RPC::PUBLISH_UNPUBLISH_VOLUME:
117  publishUnpublishVolume = true;
118  break;
119  case ControllerServiceCapability::RPC::LIST_VOLUMES:
120  listVolumes = true;
121  break;
122  case ControllerServiceCapability::RPC::GET_CAPACITY:
123  getCapacity = true;
124  break;
125  case ControllerServiceCapability::RPC::CREATE_DELETE_SNAPSHOT:
126  createDeleteSnapshot = true;
127  break;
128  case ControllerServiceCapability::RPC::LIST_SNAPSHOTS:
129  listSnapshots = true;
130  break;
131  case ControllerServiceCapability::RPC::CLONE_VOLUME:
132  cloneVolume = true;
133  break;
134  case ControllerServiceCapability::RPC::PUBLISH_READONLY:
135  publishReadonly = true;
136  break;
137  case ControllerServiceCapability::RPC::EXPAND_VOLUME:
138  expandVolume = true;
139  break;
140 
141  // NOTE: We avoid using a default clause for the following values in
142  // proto3's open enum to enable the compiler to detect missing enum
143  // cases for us. See: https://github.com/google/protobuf/issues/3917
144  case google::protobuf::kint32min:
145  case google::protobuf::kint32max:
146  UNREACHABLE();
147  }
148  }
149  }
150  }
151 
152  bool createDeleteVolume = false;
153  bool publishUnpublishVolume = false;
154  bool listVolumes = false;
155  bool getCapacity = false;
156  bool createDeleteSnapshot = false;
157  bool listSnapshots = false;
158  bool cloneVolume = false;
159  bool publishReadonly = false;
160  bool expandVolume = false;
161 };
162 
163 
165 {
166  NodeCapabilities() = default;
167 
168  template <typename Iterable>
169  NodeCapabilities(const Iterable& capabilities)
170  {
171  foreach (const auto& capability, capabilities) {
172  if (capability.has_rpc() &&
173  NodeServiceCapability::RPC::Type_IsValid(capability.rpc().type())) {
174  switch (capability.rpc().type()) {
176  break;
177  case NodeServiceCapability::RPC::STAGE_UNSTAGE_VOLUME:
178  stageUnstageVolume = true;
179  break;
180  case NodeServiceCapability::RPC::GET_VOLUME_STATS:
181  getVolumeStats = true;
182  break;
183  case NodeServiceCapability::RPC::EXPAND_VOLUME:
184  expandVolume = true;
185  break;
186 
187  // NOTE: We avoid using a default clause for the following values in
188  // proto3's open enum to enable the compiler to detect missing enum
189  // cases for us. See: https://github.com/google/protobuf/issues/3917
190  case google::protobuf::kint32min:
191  case google::protobuf::kint32max:
192  UNREACHABLE();
193  }
194  }
195  }
196  }
197 
198  bool stageUnstageVolume = false;
199  bool getVolumeStats = false;
200  bool expandVolume = false;
201 };
202 
203 
204 // Helpers to devolve CSI v1 protobufs to their unversioned counterparts.
205 CSIVolume::VolumeCapability devolve(const VolumeCapability& capability);
206 
207 google::protobuf::RepeatedPtrField<CSIVolume::VolumeCapability> devolve(
208  const google::protobuf::RepeatedPtrField<VolumeCapability>& capabilities);
209 
210 
211 // Helpers to evolve unversioned CSI protobufs to their v1 counterparts.
212 VolumeCapability evolve(const CSIVolume::VolumeCapability& capability);
213 
214 google::protobuf::RepeatedPtrField<VolumeCapability> evolve(
215  const google::protobuf::RepeatedPtrField<CSIVolume::VolumeCapability>&
216  capabilities);
217 
218 } // namespace v1 {
219 } // namespace csi {
220 } // namespace mesos {
221 
222 #endif // __CSI_V1_UTILS_HPP__
Volume::Source::CSIVolume CSIVolume
Definition: v1_utils.hpp:33
Definition: v1_utils.hpp:99
PluginCapabilities(const Iterable &capabilities)
Definition: v1_utils.hpp:41
Definition: v0.hpp:49
constexpr Service CONTROLLER_SERVICE
Definition: service_manager.hpp:40
bool volumeAccessibilityConstraints
Definition: v1_utils.hpp:93
Definition: agent.hpp:25
bool volumeExpansionOnline
Definition: v1_utils.hpp:94
bool controllerService
Definition: v1_utils.hpp:92
const int UNKNOWN
Definition: diagnosis.hpp:39
CSIVolume::VolumeCapability devolve(const VolumeCapability &capability)
#define UNREACHABLE()
Definition: unreachable.hpp:22
ControllerCapabilities(const Iterable &capabilities)
Definition: v1_utils.hpp:104
Definition: v1_utils.hpp:164
VolumeCapability evolve(const CSIVolume::VolumeCapability &capability)
bool volumeExpansionOffline
Definition: v1_utils.hpp:95
NodeCapabilities(const Iterable &capabilities)
Definition: v1_utils.hpp:169
Definition: v1_utils.hpp:36