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