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