Apache Mesos
mesos.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 __MESOS_V1_HPP__
18 #define __MESOS_V1_HPP__
19 
20 #include <iosfwd>
21 #include <string>
22 #include <vector>
23 
24 #include <boost/functional/hash.hpp>
25 
26 #include <google/protobuf/repeated_field.h>
27 
28 #include <mesos/v1/mesos.pb.h> // ONLY USEFUL AFTER RUNNING PROTOC.
29 
30 #include <stout/strings.hpp>
31 
32 // This file includes definitions for operators on public protobuf
33 // classes (defined in mesos.proto, module.proto, etc.) that don't
34 // have these operators generated by the protobuf compiler. The
35 // corresponding definitions are in src/v1/type_utils.cpp.
36 //
37 // Mesos modules need some of the protobuf classes defined in
38 // mesos.proto, module.proto, etc., and require some of these
39 // operators declared in mesos.hpp. Exposing mesos.hpp
40 // allows us to build modules without having a dependency on mesos
41 // source tree (src/*).
42 
43 namespace mesos {
44 namespace v1 {
45 
46 bool operator==(const CommandInfo& left, const CommandInfo& right);
47 bool operator==(const CommandInfo::URI& left, const CommandInfo::URI& right);
48 bool operator==(const ContainerInfo& left, const ContainerInfo& right);
49 bool operator==(const Credential& left, const Credential& right);
50 bool operator==(const CSIPluginInfo& left, const CSIPluginInfo& right);
51 
52 bool operator==(
53  const CSIPluginContainerInfo& left,
54  const CSIPluginContainerInfo& right);
55 
56 bool operator==(const DiscoveryInfo& left, const DiscoveryInfo& right);
57 bool operator==(const Environment& left, const Environment& right);
58 bool operator==(const ExecutorInfo& left, const ExecutorInfo& right);
59 bool operator==(const FileInfo& left, const FileInfo& right);
60 bool operator==(const Label& left, const Label& right);
61 bool operator==(const Labels& left, const Labels& right);
62 bool operator==(const MasterInfo& left, const MasterInfo& right);
63 
64 bool operator==(
65  const ResourceProviderInfo& left,
66  const ResourceProviderInfo& right);
67 
68 bool operator==(
69  const ResourceStatistics& left,
70  const ResourceStatistics& right);
71 
72 bool operator==(const AgentInfo& left, const AgentInfo& right);
73 bool operator==(const TaskStatus& left, const TaskStatus& right);
74 bool operator==(const URL& left, const URL& right);
75 bool operator==(const Volume& left, const Volume& right);
76 
77 bool operator!=(const Labels& left, const Labels& right);
78 bool operator!=(const TaskStatus& left, const TaskStatus& right);
79 
80 
81 inline bool operator==(const ContainerID& left, const ContainerID& right)
82 {
83  return left.value() == right.value();
84 }
85 
86 
87 inline bool operator==(const ExecutorID& left, const ExecutorID& right)
88 {
89  return left.value() == right.value();
90 }
91 
92 
93 inline bool operator==(const FrameworkID& left, const FrameworkID& right)
94 {
95  return left.value() == right.value();
96 }
97 
98 
99 inline bool operator==(const FrameworkInfo& left, const FrameworkInfo& right)
100 {
101  return (left.name() == right.name()) && (left.user() == right.user());
102 }
103 
104 
105 inline bool operator==(const OfferID& left, const OfferID& right)
106 {
107  return left.value() == right.value();
108 }
109 
110 
111 inline bool operator==(const OperationID& left, const OperationID& right)
112 {
113  return left.value() == right.value();
114 }
115 
116 
117 inline bool operator==(
118  const ResourceProviderID& left,
119  const ResourceProviderID& right)
120 {
121  return left.value() == right.value();
122 }
123 
124 
125 inline bool operator==(const AgentID& left, const AgentID& right)
126 {
127  return left.value() == right.value();
128 }
129 
130 
131 inline bool operator==(const TaskID& left, const TaskID& right)
132 {
133  return left.value() == right.value();
134 }
135 
136 
137 inline bool operator==(const TimeInfo& left, const TimeInfo& right)
138 {
139  return left.nanoseconds() == right.nanoseconds();
140 }
141 
142 
143 inline bool operator==(const DurationInfo& left, const DurationInfo& right)
144 {
145  return left.nanoseconds() == right.nanoseconds();
146 }
147 
148 
149 inline bool operator==(const ContainerID& left, const std::string& right)
150 {
151  return left.value() == right;
152 }
153 
154 
155 inline bool operator==(const ExecutorID& left, const std::string& right)
156 {
157  return left.value() == right;
158 }
159 
160 
161 inline bool operator==(const FrameworkID& left, const std::string& right)
162 {
163  return left.value() == right;
164 }
165 
166 
167 inline bool operator==(const OfferID& left, const std::string& right)
168 {
169  return left.value() == right;
170 }
171 
172 
173 inline bool operator==(const AgentID& left, const std::string& right)
174 {
175  return left.value() == right;
176 }
177 
178 
179 inline bool operator==(const TaskID& left, const std::string& right)
180 {
181  return left.value() == right;
182 }
183 
184 
185 inline bool operator==(
186  const DomainInfo::FaultDomain::RegionInfo& left,
187  const DomainInfo::FaultDomain::RegionInfo& right)
188 {
189  return left.name() == right.name();
190 }
191 
192 
193 inline bool operator==(
194  const DomainInfo::FaultDomain::ZoneInfo& left,
195  const DomainInfo::FaultDomain::ZoneInfo& right)
196 {
197  return left.name() == right.name();
198 }
199 
200 
201 inline bool operator==(
202  const DomainInfo::FaultDomain& left,
203  const DomainInfo::FaultDomain& right)
204 {
205  return left.region() == right.region() && left.zone() == right.zone();
206 }
207 
208 
209 inline bool operator==(const DomainInfo& left, const DomainInfo& right)
210 {
211  return left.fault_domain() == right.fault_domain();
212 }
213 
214 
219 inline bool operator==(const MachineID& left, const MachineID& right)
220 {
221  // NOTE: Both fields default to the empty string if they are not specified,
222  // so the string comparisons are safe.
223  return left.has_hostname() == right.has_hostname() &&
224  strings::lower(left.hostname()) == strings::lower(right.hostname()) &&
225  left.has_ip() == right.has_ip() &&
226  left.ip() == right.ip();
227 }
228 
229 
230 inline bool operator!=(const ContainerID& left, const ContainerID& right)
231 {
232  return left.value() != right.value();
233 }
234 
235 
236 inline bool operator!=(
237  const CSIPluginContainerInfo& left,
238  const CSIPluginContainerInfo& right)
239 {
240  return !(left == right);
241 }
242 
243 
244 inline bool operator!=(const ExecutorID& left, const ExecutorID& right)
245 {
246  return left.value() != right.value();
247 }
248 
249 
250 inline bool operator!=(const FrameworkID& left, const FrameworkID& right)
251 {
252  return left.value() != right.value();
253 }
254 
255 
256 inline bool operator!=(const OperationID& left, const OperationID& right)
257 {
258  return left.value() != right.value();
259 }
260 
261 
262 inline bool operator!=(
263  const ResourceProviderID& left,
264  const ResourceProviderID& right)
265 {
266  return left.value() != right.value();
267 }
268 
269 
270 inline bool operator!=(
271  const ResourceProviderInfo& left,
272  const ResourceProviderInfo& right)
273 {
274  return !(left == right);
275 }
276 
277 
278 inline bool operator!=(const AgentID& left, const AgentID& right)
279 {
280  return left.value() != right.value();
281 }
282 
283 
284 inline bool operator!=(const TimeInfo& left, const TimeInfo& right)
285 {
286  return !(left == right);
287 }
288 
289 
290 inline bool operator!=(const DurationInfo& left, const DurationInfo& right)
291 {
292  return !(left == right);
293 }
294 
295 
296 inline bool operator!=(
297  const DomainInfo::FaultDomain::RegionInfo& left,
298  const DomainInfo::FaultDomain::RegionInfo& right)
299 {
300  return left.name() != right.name();
301 }
302 
303 
304 inline bool operator<(const ContainerID& left, const ContainerID& right)
305 {
306  return left.value() < right.value();
307 }
308 
309 
310 inline bool operator<(const ExecutorID& left, const ExecutorID& right)
311 {
312  return left.value() < right.value();
313 }
314 
315 
316 inline bool operator<(const FrameworkID& left, const FrameworkID& right)
317 {
318  return left.value() < right.value();
319 }
320 
321 
322 inline bool operator<(const OfferID& left, const OfferID& right)
323 {
324  return left.value() < right.value();
325 }
326 
327 
328 inline bool operator<(const AgentID& left, const AgentID& right)
329 {
330  return left.value() < right.value();
331 }
332 
333 
334 inline bool operator<(const TaskID& left, const TaskID& right)
335 {
336  return left.value() < right.value();
337 }
338 
339 
340 std::ostream& operator<<(
341  std::ostream& stream,
342  const CapabilityInfo& capabilityInfo);
343 
344 
345 std::ostream& operator<<(
346  std::ostream& stream,
347  const CheckStatusInfo& checkStatusInfo);
348 
349 
350 std::ostream& operator<<(std::ostream& stream, const ContainerID& containerId);
351 
352 
353 std::ostream& operator<<(
354  std::ostream& stream,
355  const ContainerInfo& containerInfo);
356 
357 
358 std::ostream& operator<<(std::ostream& stream, const DomainInfo& domainInfo);
359 
360 
361 std::ostream& operator<<(std::ostream& stream, const ExecutorID& executorId);
362 
363 
364 std::ostream& operator<<(std::ostream& stream, const ExecutorInfo& executor);
365 
366 
367 std::ostream& operator<<(std::ostream& stream, const FrameworkID& frameworkId);
368 
369 
370 std::ostream& operator<<(std::ostream& stream, const MasterInfo& master);
371 
372 
373 std::ostream& operator<<(std::ostream& stream, const OfferID& offerId);
374 
375 
376 std::ostream& operator<<(std::ostream& stream, const OperationID& operationId);
377 
378 
379 std::ostream& operator<<(std::ostream& stream, const OperationState& state);
380 
381 
382 std::ostream& operator<<(std::ostream& stream, const RateLimits& limits);
383 
384 
385 std::ostream& operator<<(std::ostream& stream, const RLimitInfo& limits);
386 
387 
388 std::ostream& operator<<(
389  std::ostream& stream,
390  const ResourceProviderID& resourceProviderId);
391 
392 
393 std::ostream& operator<<(
394  std::ostream& stream,
395  const ResourceProviderInfo& resourceProviderInfo);
396 
397 
398 std::ostream& operator<<(std::ostream& stream, const AgentID& agentId);
399 
400 
401 std::ostream& operator<<(std::ostream& stream, const AgentInfo& agent);
402 
403 
404 std::ostream& operator<<(std::ostream& stream, const TaskID& taskId);
405 
406 
407 std::ostream& operator<<(std::ostream& stream, const MachineID& machineId);
408 
409 
410 std::ostream& operator<<(std::ostream& stream, const TaskInfo& task);
411 
412 
413 std::ostream& operator<<(
414  std::ostream& stream,
415  const TaskGroupInfo& taskGroupInfo);
416 
417 
418 std::ostream& operator<<(std::ostream& stream, const TaskState& state);
419 
420 
421 std::ostream& operator<<(std::ostream& stream, const CheckInfo::Type& type);
422 
423 
424 std::ostream& operator<<(
425  std::ostream& stream,
426  const CSIPluginContainerInfo::Service& service);
427 
428 
429 std::ostream& operator<<(
430  std::ostream& stream,
431  const FrameworkInfo::Capability& capability);
432 
433 
434 std::ostream& operator<<(std::ostream& stream, const Image::Type& imageType);
435 
436 
437 std::ostream& operator<<(std::ostream& stream, const Secret::Type& secretType);
438 
439 
440 std::ostream& operator<<(
441  std::ostream& stream,
442  const Offer::Operation::Type& operationType);
443 
444 
445 std::ostream& operator<<(
446  std::ostream& stream,
447  const Resource::DiskInfo::Source::Type& sourceType);
448 
449 
450 template <typename T>
451 inline std::ostream& operator<<(
452  std::ostream& stream,
453  const google::protobuf::RepeatedPtrField<T>& messages)
454 {
455  stream << "[ ";
456  for (auto it = messages.begin(); it != messages.end(); ++it) {
457  if (it != messages.begin()) {
458  stream << ", ";
459  }
460  stream << *it;
461  }
462  stream << " ]";
463  return stream;
464 }
465 
466 
467 template <typename T>
468 inline std::ostream& operator<<(
469  std::ostream& stream,
470  const std::vector<T>& messages)
471 {
472  stream << "[ ";
473  for (auto it = messages.begin(); it != messages.end(); ++it) {
474  if (it != messages.begin()) {
475  stream << ", ";
476  }
477  stream << *it;
478  }
479  stream << " ]";
480  return stream;
481 }
482 
483 
484 std::ostream& operator<<(
485  std::ostream& stream,
487 
488 } // namespace v1 {
489 } // namespace mesos {
490 
491 namespace std {
492 
493 template <>
494 struct hash<mesos::v1::CommandInfo::URI>
495 {
496  typedef size_t result_type;
497 
498  typedef mesos::v1::CommandInfo::URI argument_type;
499 
501  {
502  size_t seed = 0;
503 
504  if (uri.extract()) {
505  seed += 11;
506  }
507 
508  if (uri.executable()) {
509  seed += 2003;
510  }
511 
512  boost::hash_combine(seed, uri.value());
513  return seed;
514  }
515 };
516 
517 
518 template <>
519 struct hash<mesos::v1::ContainerID>
520 {
521  typedef size_t result_type;
522 
523  typedef mesos::v1::ContainerID argument_type;
524 
525  result_type operator()(const argument_type& containerId) const
526  {
527  size_t seed = 0;
528  boost::hash_combine(seed, containerId.value());
529  return seed;
530  }
531 };
532 
533 
534 template <>
535 struct hash<mesos::v1::ExecutorID>
536 {
537  typedef size_t result_type;
538 
539  typedef mesos::v1::ExecutorID argument_type;
540 
541  result_type operator()(const argument_type& executorId) const
542  {
543  size_t seed = 0;
544  boost::hash_combine(seed, executorId.value());
545  return seed;
546  }
547 };
548 
549 
550 template <>
551 struct hash<mesos::v1::FrameworkID>
552 {
553  typedef size_t result_type;
554 
555  typedef mesos::v1::FrameworkID argument_type;
556 
557  result_type operator()(const argument_type& frameworkId) const
558  {
559  size_t seed = 0;
560  boost::hash_combine(seed, frameworkId.value());
561  return seed;
562  }
563 };
564 
565 
566 template <>
567 struct hash<mesos::v1::OfferID>
568 {
569  typedef size_t result_type;
570 
571  typedef mesos::v1::OfferID argument_type;
572 
573  result_type operator()(const argument_type& offerId) const
574  {
575  size_t seed = 0;
576  boost::hash_combine(seed, offerId.value());
577  return seed;
578  }
579 };
580 
581 
582 template <>
583 struct hash<mesos::v1::AgentID>
584 {
585  typedef size_t result_type;
586 
587  typedef mesos::v1::AgentID argument_type;
588 
589  result_type operator()(const argument_type& agentId) const
590  {
591  size_t seed = 0;
592  boost::hash_combine(seed, agentId.value());
593  return seed;
594  }
595 };
596 
597 
598 template <>
599 struct hash<mesos::v1::TaskID>
600 {
601  typedef size_t result_type;
602 
603  typedef mesos::v1::TaskID argument_type;
604 
605  result_type operator()(const argument_type& taskId) const
606  {
607  size_t seed = 0;
608  boost::hash_combine(seed, taskId.value());
609  return seed;
610  }
611 };
612 
613 
614 template <>
615 struct hash<mesos::v1::TaskState>
616 {
617  typedef size_t result_type;
618 
619  typedef mesos::v1::TaskState argument_type;
620 
621  result_type operator()(const argument_type& taskState) const
622  {
623  // Use the underlying type of the enum as hash value.
624  return static_cast<size_t>(taskState);
625  }
626 };
627 
628 
629 template <>
630 struct hash<mesos::v1::TaskStatus_Source>
631 {
632  typedef size_t result_type;
633 
634  typedef mesos::v1::TaskStatus_Source argument_type;
635 
636  result_type operator()(const argument_type& source) const
637  {
638  // Use the underlying type of the enum as hash value.
639  return static_cast<size_t>(source);
640  }
641 };
642 
643 
644 template <>
645 struct hash<mesos::v1::TaskStatus_Reason>
646 {
647  typedef size_t result_type;
648 
649  typedef mesos::v1::TaskStatus_Reason argument_type;
650 
651  result_type operator()(const argument_type& reason) const
652  {
653  // Use the underlying type of the enum as hash value.
654  return static_cast<size_t>(reason);
655  }
656 };
657 
658 
659 template <>
660 struct hash<mesos::v1::Image::Type>
661 {
662  typedef size_t result_type;
663 
665 
666  result_type operator()(const argument_type& imageType) const
667  {
668  // Use the underlying type of the enum as hash value.
669  return static_cast<size_t>(imageType);
670  }
671 };
672 
673 
674 template <>
675 struct hash<std::pair<mesos::v1::FrameworkID, mesos::v1::ExecutorID>>
676 {
677  typedef size_t result_type;
678 
679  typedef std::pair<
680  mesos::v1::FrameworkID, mesos::v1::ExecutorID> argument_type;
681 
683  {
684  size_t seed = 0;
685  boost::hash_combine(seed, std::hash<mesos::v1::FrameworkID>()(pair.first));
686  boost::hash_combine(seed, std::hash<mesos::v1::ExecutorID>()(pair.second));
687  return seed;
688  }
689 };
690 
691 
692 template <>
693 struct hash<mesos::v1::MachineID>
694 {
695  typedef size_t result_type;
696 
697  typedef mesos::v1::MachineID argument_type;
698 
699  result_type operator()(const argument_type& machineId) const
700  {
701  size_t seed = 0;
702  boost::hash_combine(seed, strings::lower(machineId.hostname()));
703  boost::hash_combine(seed, machineId.ip());
704  return seed;
705  }
706 };
707 
708 
709 template <>
710 struct hash<mesos::v1::OperationID>
711 {
712  typedef size_t result_type;
713 
714  typedef mesos::v1::OperationID argument_type;
715 
716  result_type operator()(const argument_type& operationId) const
717  {
718  size_t seed = 0;
719  boost::hash_combine(seed, operationId.value());
720  return seed;
721  }
722 };
723 
724 
725 template <>
726 struct hash<mesos::v1::ResourceProviderID>
727 {
728  typedef size_t result_type;
729 
730  typedef mesos::v1::ResourceProviderID argument_type;
731 
732  result_type operator()(const argument_type& resourceProviderId) const
733  {
734  size_t seed = 0;
735  boost::hash_combine(seed, resourceProviderId.value());
736  return seed;
737  }
738 };
739 
740 } // namespace std {
741 
742 #endif // __MESOS_V1_HPP__
mesos::v1::TaskStatus_Source argument_type
Definition: mesos.hpp:634
result_type operator()(const argument_type &source) const
Definition: mesos.hpp:636
size_t result_type
Definition: mesos.hpp:585
mesos::v1::ContainerID argument_type
Definition: mesos.hpp:523
mesos::v1::ResourceProviderID argument_type
Definition: mesos.hpp:730
mesos::v1::ExecutorID argument_type
Definition: mesos.hpp:539
result_type operator()(const argument_type &uri) const
Definition: mesos.hpp:500
size_t result_type
Definition: mesos.hpp:569
Definition: mesos.hpp:535
size_t result_type
Definition: mesos.hpp:553
result_type operator()(const argument_type &resourceProviderId) const
Definition: mesos.hpp:732
mesos::v1::TaskState argument_type
Definition: mesos.hpp:619
result_type operator()(const argument_type &taskState) const
Definition: mesos.hpp:621
size_t result_type
Definition: mesos.hpp:728
Capability
Definition: capabilities.hpp:35
result_type operator()(const argument_type &reason) const
Definition: mesos.hpp:651
std::pair< mesos::v1::FrameworkID, mesos::v1::ExecutorID > argument_type
Definition: mesos.hpp:680
mesos::v1::MachineID argument_type
Definition: mesos.hpp:697
size_t result_type
Definition: mesos.hpp:496
mesos::v1::FrameworkID argument_type
Definition: mesos.hpp:555
Iterable< V > map(F &&f, const Iterable< U, Us...> &input)
Definition: lambda.hpp:45
result_type operator()(const argument_type &executorId) const
Definition: mesos.hpp:541
size_t result_type
Definition: mesos.hpp:632
bool operator==(const CommandInfo &left, const CommandInfo &right)
size_t result_type
Definition: mesos.hpp:695
size_t result_type
Definition: mesos.hpp:712
mesos::v1::AgentID argument_type
Definition: mesos.hpp:587
mesos::v1::TaskStatus_Reason argument_type
Definition: mesos.hpp:649
result_type operator()(const argument_type &frameworkId) const
Definition: mesos.hpp:557
mesos::v1::OperationID argument_type
Definition: mesos.hpp:714
Type
Definition: capabilities.hpp:79
Definition: mesos.hpp:551
result_type operator()(const argument_type &imageType) const
Definition: mesos.hpp:666
mesos::v1::Image::Type argument_type
Definition: mesos.hpp:664
size_t result_type
Definition: mesos.hpp:617
Try< uint32_t > type(const std::string &path)
bool operator<(const ContainerID &left, const ContainerID &right)
Definition: mesos.hpp:304
size_t result_type
Definition: mesos.hpp:647
mesos::v1::TaskID argument_type
Definition: mesos.hpp:603
size_t result_type
Definition: mesos.hpp:537
bool operator!=(const Labels &left, const Labels &right)
result_type operator()(const argument_type &offerId) const
Definition: mesos.hpp:573
size_t result_type
Definition: mesos.hpp:601
result_type operator()(const argument_type &machineId) const
Definition: mesos.hpp:699
result_type operator()(const argument_type &containerId) const
Definition: mesos.hpp:525
mesos::v1::OfferID argument_type
Definition: mesos.hpp:571
result_type operator()(const argument_type &operationId) const
Definition: mesos.hpp:716
mesos::v1::CommandInfo::URI argument_type
Definition: mesos.hpp:498
result_type operator()(const argument_type &taskId) const
Definition: mesos.hpp:605
size_t result_type
Definition: mesos.hpp:662
std::string lower(const std::string &s)
Definition: strings.hpp:412
std::ostream & operator<<(std::ostream &stream, const Attribute &attribute)
result_type operator()(const argument_type &pair) const
Definition: mesos.hpp:682
Option< Error > checkStatusInfo(const CheckStatusInfo &checkStatusInfo)
size_t result_type
Definition: mesos.hpp:521
result_type operator()(const argument_type &agentId) const
Definition: mesos.hpp:589