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