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  return seed;
533  }
534 };
535 
536 
537 template <>
538 struct hash<mesos::v1::ContainerID>
539 {
540  typedef size_t result_type;
541 
542  typedef mesos::v1::ContainerID argument_type;
543 
544  result_type operator()(const argument_type& containerId) const
545  {
546  size_t seed = 0;
547  boost::hash_combine(seed, containerId.value());
548  return seed;
549  }
550 };
551 
552 
553 template <>
554 struct hash<mesos::v1::ExecutorID>
555 {
556  typedef size_t result_type;
557 
558  typedef mesos::v1::ExecutorID argument_type;
559 
560  result_type operator()(const argument_type& executorId) const
561  {
562  size_t seed = 0;
563  boost::hash_combine(seed, executorId.value());
564  return seed;
565  }
566 };
567 
568 
569 template <>
570 struct hash<mesos::v1::FrameworkID>
571 {
572  typedef size_t result_type;
573 
574  typedef mesos::v1::FrameworkID argument_type;
575 
576  result_type operator()(const argument_type& frameworkId) const
577  {
578  size_t seed = 0;
579  boost::hash_combine(seed, frameworkId.value());
580  return seed;
581  }
582 };
583 
584 
585 template <>
586 struct hash<mesos::v1::OfferID>
587 {
588  typedef size_t result_type;
589 
590  typedef mesos::v1::OfferID argument_type;
591 
592  result_type operator()(const argument_type& offerId) const
593  {
594  size_t seed = 0;
595  boost::hash_combine(seed, offerId.value());
596  return seed;
597  }
598 };
599 
600 
601 template <>
602 struct hash<mesos::v1::AgentID>
603 {
604  typedef size_t result_type;
605 
606  typedef mesos::v1::AgentID argument_type;
607 
608  result_type operator()(const argument_type& agentId) const
609  {
610  size_t seed = 0;
611  boost::hash_combine(seed, agentId.value());
612  return seed;
613  }
614 };
615 
616 
617 template <>
618 struct hash<mesos::v1::TaskID>
619 {
620  typedef size_t result_type;
621 
622  typedef mesos::v1::TaskID argument_type;
623 
624  result_type operator()(const argument_type& taskId) const
625  {
626  size_t seed = 0;
627  boost::hash_combine(seed, taskId.value());
628  return seed;
629  }
630 };
631 
632 
633 template <>
634 struct hash<mesos::v1::TaskState>
635 {
636  typedef size_t result_type;
637 
638  typedef mesos::v1::TaskState argument_type;
639 
640  result_type operator()(const argument_type& taskState) const
641  {
642  // Use the underlying type of the enum as hash value.
643  return static_cast<size_t>(taskState);
644  }
645 };
646 
647 
648 template <>
649 struct hash<mesos::v1::TaskStatus_Source>
650 {
651  typedef size_t result_type;
652 
653  typedef mesos::v1::TaskStatus_Source argument_type;
654 
655  result_type operator()(const argument_type& source) const
656  {
657  // Use the underlying type of the enum as hash value.
658  return static_cast<size_t>(source);
659  }
660 };
661 
662 
663 template <>
664 struct hash<mesos::v1::TaskStatus_Reason>
665 {
666  typedef size_t result_type;
667 
668  typedef mesos::v1::TaskStatus_Reason argument_type;
669 
670  result_type operator()(const argument_type& reason) const
671  {
672  // Use the underlying type of the enum as hash value.
673  return static_cast<size_t>(reason);
674  }
675 };
676 
677 
678 template <>
679 struct hash<mesos::v1::Image::Type>
680 {
681  typedef size_t result_type;
682 
684 
685  result_type operator()(const argument_type& imageType) const
686  {
687  // Use the underlying type of the enum as hash value.
688  return static_cast<size_t>(imageType);
689  }
690 };
691 
692 
693 template <>
694 struct hash<std::pair<mesos::v1::FrameworkID, mesos::v1::ExecutorID>>
695 {
696  typedef size_t result_type;
697 
698  typedef std::pair<
699  mesos::v1::FrameworkID, mesos::v1::ExecutorID> argument_type;
700 
701  result_type operator()(const argument_type& pair) const
702  {
703  size_t seed = 0;
704  boost::hash_combine(seed, std::hash<mesos::v1::FrameworkID>()(pair.first));
705  boost::hash_combine(seed, std::hash<mesos::v1::ExecutorID>()(pair.second));
706  return seed;
707  }
708 };
709 
710 
711 template <>
712 struct hash<mesos::v1::MachineID>
713 {
714  typedef size_t result_type;
715 
716  typedef mesos::v1::MachineID argument_type;
717 
718  result_type operator()(const argument_type& machineId) const
719  {
720  size_t seed = 0;
721  boost::hash_combine(seed, strings::lower(machineId.hostname()));
722  boost::hash_combine(seed, machineId.ip());
723  return seed;
724  }
725 };
726 
727 
728 template <>
729 struct hash<mesos::v1::OperationID>
730 {
731  typedef size_t result_type;
732 
733  typedef mesos::v1::OperationID argument_type;
734 
735  result_type operator()(const argument_type& operationId) const
736  {
737  size_t seed = 0;
738  boost::hash_combine(seed, operationId.value());
739  return seed;
740  }
741 };
742 
743 
744 template <>
745 struct hash<mesos::v1::ResourceProviderID>
746 {
747  typedef size_t result_type;
748 
749  typedef mesos::v1::ResourceProviderID argument_type;
750 
751  result_type operator()(const argument_type& resourceProviderId) const
752  {
753  size_t seed = 0;
754  boost::hash_combine(seed, resourceProviderId.value());
755  return seed;
756  }
757 };
758 
759 } // namespace std {
760 
761 #endif // __MESOS_V1_HPP__
mesos::v1::TaskStatus_Source argument_type
Definition: mesos.hpp:653
result_type operator()(const argument_type &source) const
Definition: mesos.hpp:655
size_t result_type
Definition: mesos.hpp:604
mesos::v1::ContainerID argument_type
Definition: mesos.hpp:542
Definition: master.hpp:27
mesos::v1::ResourceProviderID argument_type
Definition: mesos.hpp:749
mesos::v1::ExecutorID argument_type
Definition: mesos.hpp:558
result_type operator()(const argument_type &uri) const
Definition: mesos.hpp:519
size_t result_type
Definition: mesos.hpp:588
Result< ProcessStatus > status(pid_t pid)
Definition: proc.hpp:166
Definition: mesos.hpp:554
size_t result_type
Definition: mesos.hpp:572
result_type operator()(const argument_type &resourceProviderId) const
Definition: mesos.hpp:751
Definition: type_utils.hpp:510
mesos::v1::TaskState argument_type
Definition: mesos.hpp:638
result_type operator()(const argument_type &taskState) const
Definition: mesos.hpp:640
size_t result_type
Definition: mesos.hpp:747
Capability
Definition: capabilities.hpp:35
Operation
Definition: cgroups.hpp:441
result_type operator()(const argument_type &reason) const
Definition: mesos.hpp:670
std::pair< mesos::v1::FrameworkID, mesos::v1::ExecutorID > argument_type
Definition: mesos.hpp:699
mesos::v1::MachineID argument_type
Definition: mesos.hpp:716
size_t result_type
Definition: mesos.hpp:515
mesos::v1::FrameworkID argument_type
Definition: mesos.hpp:574
Definition: agent.hpp:27
Definition: spec.hpp:30
result_type operator()(const argument_type &executorId) const
Definition: mesos.hpp:560
size_t result_type
Definition: mesos.hpp:651
bool operator==(const CommandInfo &left, const CommandInfo &right)
size_t result_type
Definition: mesos.hpp:714
size_t result_type
Definition: mesos.hpp:731
mesos::v1::AgentID argument_type
Definition: mesos.hpp:606
Iterable< V > map(F &&f, const Iterable< U, Us... > &input)
Definition: lambda.hpp:46
mesos::v1::TaskStatus_Reason argument_type
Definition: mesos.hpp:668
result_type operator()(const argument_type &frameworkId) const
Definition: mesos.hpp:576
mesos::v1::OperationID argument_type
Definition: mesos.hpp:733
Type
Definition: capabilities.hpp:79
Definition: mesos.hpp:570
result_type operator()(const argument_type &imageType) const
Definition: mesos.hpp:685
mesos::v1::Image::Type argument_type
Definition: mesos.hpp:683
size_t result_type
Definition: mesos.hpp:636
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:666
mesos::v1::TaskID argument_type
Definition: mesos.hpp:622
size_t result_type
Definition: mesos.hpp:556
Definition: uri.hpp:21
bool operator!=(const Labels &left, const Labels &right)
result_type operator()(const argument_type &offerId) const
Definition: mesos.hpp:592
size_t result_type
Definition: mesos.hpp:620
result_type operator()(const argument_type &machineId) const
Definition: mesos.hpp:718
result_type operator()(const argument_type &containerId) const
Definition: mesos.hpp:544
mesos::v1::OfferID argument_type
Definition: mesos.hpp:590
result_type operator()(const argument_type &operationId) const
Definition: mesos.hpp:735
mesos::v1::CommandInfo::URI argument_type
Definition: mesos.hpp:517
result_type operator()(const argument_type &taskId) const
Definition: mesos.hpp:624
size_t result_type
Definition: mesos.hpp:681
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:701
size_t result_type
Definition: mesos.hpp:540
result_type operator()(const argument_type &agentId) const
Definition: mesos.hpp:608