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/csi/types.hpp>
23 #include <mesos/csi/v0.hpp>
24 
25 #include <stout/foreach.hpp>
26 #include <stout/unreachable.hpp>
27 
28 namespace mesos {
29 namespace csi {
30 namespace v0 {
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 
50  // NOTE: We avoid using a default clause for the following values in
51  // proto3's open enum to enable the compiler to detect missing enum
52  // cases for us. See: https://github.com/google/protobuf/issues/3917
53  case google::protobuf::kint32min:
54  case google::protobuf::kint32max:
55  UNREACHABLE();
56  }
57  }
58  }
59  }
60 
61  bool controllerService = false;
62 };
63 
64 
66 {
67  ControllerCapabilities() = default;
68 
69  template <typename Iterable>
70  ControllerCapabilities(const Iterable& capabilities)
71  {
72  foreach (const auto& capability, capabilities) {
73  if (capability.has_rpc() &&
74  ControllerServiceCapability::RPC::Type_IsValid(
75  capability.rpc().type())) {
76  switch (capability.rpc().type()) {
78  break;
79  case ControllerServiceCapability::RPC::CREATE_DELETE_VOLUME:
80  createDeleteVolume = true;
81  break;
82  case ControllerServiceCapability::RPC::PUBLISH_UNPUBLISH_VOLUME:
83  publishUnpublishVolume = true;
84  break;
85  case ControllerServiceCapability::RPC::LIST_VOLUMES:
86  listVolumes = true;
87  break;
88  case ControllerServiceCapability::RPC::GET_CAPACITY:
89  getCapacity = true;
90  break;
91 
92  // NOTE: We avoid using a default clause for the following values in
93  // proto3's open enum to enable the compiler to detect missing enum
94  // cases for us. See: https://github.com/google/protobuf/issues/3917
95  case google::protobuf::kint32min:
96  case google::protobuf::kint32max:
97  UNREACHABLE();
98  }
99  }
100  }
101  }
102 
103  bool createDeleteVolume = false;
104  bool publishUnpublishVolume = false;
105  bool listVolumes = false;
106  bool getCapacity = false;
107 };
108 
109 
111 {
112  NodeCapabilities() = default;
113 
114  template <typename Iterable>
115  NodeCapabilities(const Iterable& capabilities)
116  {
117  foreach (const auto& capability, capabilities) {
118  if (capability.has_rpc() &&
119  NodeServiceCapability::RPC::Type_IsValid(capability.rpc().type())) {
120  switch (capability.rpc().type()) {
122  break;
123  case NodeServiceCapability::RPC::STAGE_UNSTAGE_VOLUME:
124  stageUnstageVolume = true;
125  break;
126 
127  // NOTE: We avoid using a default clause for the following values in
128  // proto3's open enum to enable the compiler to detect missing enum
129  // cases for us. See: https://github.com/google/protobuf/issues/3917
130  case google::protobuf::kint32min:
131  case google::protobuf::kint32max:
132  UNREACHABLE();
133  }
134  }
135  }
136  }
137 
138  bool stageUnstageVolume = false;
139 };
140 
141 
142 // Helpers to devolve CSI v0 protobufs to their unversioned counterparts.
143 types::VolumeCapability devolve(const VolumeCapability& capability);
144 
145 google::protobuf::RepeatedPtrField<types::VolumeCapability> devolve(
146  const google::protobuf::RepeatedPtrField<VolumeCapability>& capabilities);
147 
148 
149 // Helpers to evolve unversioned CSI protobufs to their v0 counterparts.
150 VolumeCapability evolve(const types::VolumeCapability& capability);
151 
152 google::protobuf::RepeatedPtrField<VolumeCapability> evolve(
153  const google::protobuf::RepeatedPtrField<types::VolumeCapability>&
154  capabilities);
155 
156 } // namespace v0 {
157 } // namespace csi {
158 } // namespace mesos {
159 
160 #endif // __CSI_V0_UTILS_HPP__
types::VolumeCapability devolve(const VolumeCapability &capability)
Definition: v0_utils.hpp:65
Definition: v0.hpp:49
constexpr Service CONTROLLER_SERVICE
Definition: service_manager.hpp:40
Definition: v0_utils.hpp:32
Definition: agent.hpp:25
const int UNKNOWN
Definition: diagnosis.hpp:39
#define UNREACHABLE()
Definition: unreachable.hpp:22
ControllerCapabilities(const Iterable &capabilities)
Definition: v0_utils.hpp:70
VolumeCapability evolve(const types::VolumeCapability &capability)
bool controllerService
Definition: v0_utils.hpp:61
Definition: v0_utils.hpp:110
PluginCapabilities(const Iterable &capabilities)
Definition: v0_utils.hpp:37
NodeCapabilities(const Iterable &capabilities)
Definition: v0_utils.hpp:115