Apache Mesos
resources.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_RESOURCES_HPP__
18 #define __MESOS_V1_RESOURCES_HPP__
19 
20 #include <map>
21 #include <iosfwd>
22 #include <set>
23 #include <string>
24 #include <vector>
25 
26 #include <boost/iterator/indirect_iterator.hpp>
27 
28 #include <google/protobuf/repeated_field.h>
29 
30 #include <mesos/v1/mesos.hpp>
31 #include <mesos/v1/values.hpp>
32 
33 #include <stout/bytes.hpp>
34 #include <stout/check.hpp>
35 #include <stout/error.hpp>
36 #include <stout/foreach.hpp>
37 #include <stout/hashmap.hpp>
38 #include <stout/json.hpp>
39 #include <stout/lambda.hpp>
40 #include <stout/nothing.hpp>
41 #include <stout/option.hpp>
42 #include <stout/try.hpp>
43 
44 
45 // Resources come in three types: scalar, ranges, and sets. These are
46 // represented using protocol buffers. To make manipulation of
47 // resources easier within the Mesos core and for scheduler writers,
48 // we provide generic overloaded operators (see below) as well as a
49 // general Resources class that encapsulates a collection of protocol
50 // buffer Resource objects. The Resources class also provides a few
51 // static routines to allow parsing resources (e.g., from the command
52 // line), as well as determining whether or not a Resource object is
53 // valid. Note that many of these operations have not been optimized
54 // but instead just written for correct semantics.
55 
56 namespace mesos {
57 
58 namespace internal { class ResourceQuantities; }
59 
60 namespace v1 {
61 
62 // Forward declaration.
63 class ResourceConversion;
64 
65 
66 // Helper functions.
67 bool operator==(
68  const Resource::ReservationInfo& left,
69  const Resource::ReservationInfo& right);
70 
71 
72 bool operator!=(
73  const Resource::ReservationInfo& left,
74  const Resource::ReservationInfo& right);
75 
76 
77 // NOTE: Resource objects stored in the class are always valid, are in
78 // the "post-reservation-refinement" format, and kept combined if possible.
79 // It is the caller's responsibility to validate any Resource object or
80 // repeated Resource protobufs before constructing a Resources object.
81 // Otherwise, invalid Resource objects will be silently stripped.
82 // Invalid Resource objects will also be silently ignored when used in
83 // arithmetic operations (e.g., +=, -=, etc.).
84 class Resources
85 {
86 private:
87  // An internal abstraction to facilitate managing shared resources.
88  // It allows 'Resources' to group identical shared resource objects
89  // together into a single 'Resource_' object and tracked by its internal
90  // counter. Non-shared resource objects are not grouped.
91  //
92  // The rest of the private section is below the public section. We
93  // need to define Resource_ first because the public typedefs below
94  // depend on it.
95  class Resource_
96  {
97  public:
98  /*implicit*/ Resource_(const Resource& _resource)
99  : resource(_resource),
100  sharedCount(None())
101  {
102  // Setting the counter to 1 to denote "one copy" of the shared resource.
103  if (resource.has_shared()) {
104  sharedCount = 1;
105  }
106  }
107 
108  /*implicit*/ Resource_(Resource&& _resource)
109  : resource(std::move(_resource)), sharedCount(None())
110  {
111  // Setting the counter to 1 to denote "one copy" of the shared resource.
112  if (resource.has_shared()) {
113  sharedCount = 1;
114  }
115  }
116 
117  Resource_(const Resource_& resource_) = default;
118  Resource_(Resource_&& resource_) = default;
119 
120  Resource_& operator=(const Resource_&) = default;
121  Resource_& operator=(Resource_&&) = default;
122 
123  // By implicitly converting to Resource we are able to keep Resource_
124  // logic internal and expose only the protobuf object.
125  operator const Resource&() const { return resource; }
126 
127  // Check whether this Resource_ object corresponds to a shared resource.
128  bool isShared() const { return sharedCount.isSome(); }
129 
130  // Validates this Resource_ object.
131  Option<Error> validate() const;
132 
133  // Check whether this Resource_ object is empty.
134  bool isEmpty() const;
135 
136  // The `Resource_` arithmetic, comparison operators and `contains()`
137  // method require the wrapped `resource` protobuf to have the same
138  // sharedness.
139  //
140  // For shared resources, the `resource` protobuf needs to be equal,
141  // and only the shared counters are adjusted or compared.
142  // For non-shared resources, the shared counters are none and the
143  // semantics of the Resource_ object's operators/contains() method
144  // are the same as those of the Resource objects.
145 
146  // Checks if this Resource_ is a superset of the given Resource_.
147  bool contains(const Resource_& that) const;
148 
149  // The arithmetic operators, viz. += and -= assume that the corresponding
150  // Resource objects are addable or subtractable already.
151  Resource_& operator+=(const Resource_& that);
152  Resource_& operator-=(const Resource_& that);
153 
154  bool operator==(const Resource_& that) const;
155  bool operator!=(const Resource_& that) const;
156 
157  // Friend classes and functions for access to private members.
158  friend class Resources;
159  friend std::ostream& operator<<(
160  std::ostream& stream, const Resource_& resource_);
161 
162  private:
163  // The protobuf Resource that is being managed.
164  Resource resource;
165 
166  // The counter for grouping shared 'resource' objects, None if the
167  // 'resource' is non-shared. This is an int so as to support arithmetic
168  // operations involving subtraction.
169  Option<int> sharedCount;
170  };
171 
172 public:
173  // We rename the type here to alert people about the fact that with
174  // `shared_ptr`, no mutation should be made without obtaining exclusive
175  // ownership. See `resourcesNoMutationWithoutExclusiveOwnership`.
176  using Resource_Unsafe = std::shared_ptr<Resource_>;
177 
190  static Try<Resource> parse(
191  const std::string& name,
192  const std::string& value,
193  const std::string& role);
194 
209  static Try<Resources> parse(
210  const std::string& text,
211  const std::string& defaultRole = "*");
212 
232  static Try<std::vector<Resource>> fromJSON(
233  const JSON::Array& resourcesJSON,
234  const std::string& defaultRole = "*");
235 
253  static Try<std::vector<Resource>> fromSimpleString(
254  const std::string& text,
255  const std::string& defaultRole = "*");
256 
269  static Try<std::vector<Resource>> fromString(
270  const std::string& text,
271  const std::string& defaultRole = "*");
272 
285  static Option<Error> validate(const Resource& resource);
286 
304  static Option<Error> validate(
305  const google::protobuf::RepeatedPtrField<Resource>& resources);
306 
307  // NOTE: The following predicate functions assume that the given resource is
308  // validated, and is in the "post-reservation-refinement" format. That is,
309  // the reservation state is represented by `Resource.reservations` field,
310  // and `Resource.role` and `Resource.reservation` fields are not set.
311  //
312  // See 'Resource Format' section in `mesos.proto` for more details.
313 
314  // Tests if the given Resource object is empty.
315  static bool isEmpty(const Resource& resource);
316 
317  // Tests if the given Resource object is a persistent volume.
318  static bool isPersistentVolume(const Resource& resource);
319 
320  // Tests if the given Resource object is a disk of the specified type.
321  static bool isDisk(
322  const Resource& resource,
324 
325  // Tests if the given Resource object is reserved. If the role is
326  // specified, tests that it's reserved for the given role.
327  static bool isReserved(
328  const Resource& resource,
329  const Option<std::string>& role = None());
330 
331  // Tests if the given Resource object is allocatable to the given role.
332  // A resource object is allocatable to 'role' if:
333  // * it is reserved to an ancestor of that role in the hierarchy, OR
334  // * it is reserved to 'role' itself, OR
335  // * it is unreserved.
336  static bool isAllocatableTo(
337  const Resource& resource,
338  const std::string& role);
339 
340  // Tests if the given Resource object is unreserved.
341  static bool isUnreserved(const Resource& resource);
342 
343  // Tests if the given Resource object is dynamically reserved.
344  static bool isDynamicallyReserved(const Resource& resource);
345 
346  // Tests if the given Resource object is revocable.
347  static bool isRevocable(const Resource& resource);
348 
349  // Tests if the given Resource object is shared.
350  static bool isShared(const Resource& resource);
351 
352  // Tests if the given Resources object is a "pure" scalar quantity which
353  // only consists of resource object with ONLY name, type (set to "Scalar")
354  // and scalar fields set.
355  static bool isScalarQuantity(const Resources& resources);
356 
357  // Tests if the given Resource object has refined reservations.
358  static bool hasRefinedReservations(const Resource& resource);
359 
360  // Tests if the given Resource object is provided by a resource provider.
361  static bool hasResourceProvider(const Resource& resource);
362 
363  // Returns the role to which the given Resource object is reserved for.
364  // This must be called only when the resource is reserved!
365  static const std::string& reservationRole(const Resource& resource);
366 
367  // Shrinks a scalar type `resource` to the target size.
368  // Returns true if the resource was shrunk to the target size,
369  // or the resource is already within the target size.
370  // Returns false otherwise (i.e. the resource is indivisible.
371  // E.g. MOUNT volume).
372  static bool shrink(Resource* resource, const Value::Scalar& target);
373 
374  // Returns the summed up Resources given a hashmap<Key, Resources>.
375  //
376  // NOTE: While scalar resources such as "cpus" sum correctly,
377  // non-scalar resources such as "ports" do not.
378  // e.g. "cpus:2" + "cpus:1" = "cpus:3"
379  // "ports:[0-100]" + "ports:[0-100]" = "ports:[0-100]"
380  //
381  // TODO(mpark): Deprecate this function once we introduce the
382  // concept of "cluster-wide" resources which provides correct
383  // semantics for summation over all types of resources. (e.g.
384  // non-scalar)
385  template <typename Key>
386  static Resources sum(const hashmap<Key, Resources>& _resources)
387  {
388  Resources result;
389 
390  foreachvalue (const Resources& resources, _resources) {
391  result += resources;
392  }
393 
394  return result;
395  }
396 
398 
399  // TODO(jieyu): Consider using C++11 initializer list.
400  /*implicit*/ Resources(const Resource& resource);
401  /*implicit*/ Resources(Resource&& resource);
402 
403  /*implicit*/
404  Resources(const std::vector<Resource>& _resources);
405  Resources(std::vector<Resource>&& _resources);
406 
407  /*implicit*/
408  Resources(const google::protobuf::RepeatedPtrField<Resource>& _resources);
409  Resources(google::protobuf::RepeatedPtrField<Resource>&& _resources);
410 
411  Resources(const Resources& that) = default;
412  Resources(Resources&& that) = default;
413 
415  {
416  if (this != &that) {
417  resourcesNoMutationWithoutExclusiveOwnership =
418  that.resourcesNoMutationWithoutExclusiveOwnership;
419  }
420  return *this;
421  }
422 
424  {
425  if (this != &that) {
426  resourcesNoMutationWithoutExclusiveOwnership =
427  std::move(that.resourcesNoMutationWithoutExclusiveOwnership);
428  }
429  return *this;
430  }
431 
432  bool empty() const
433  {
434  return resourcesNoMutationWithoutExclusiveOwnership.size() == 0;
435  }
436 
437  size_t size() const
438  {
439  return resourcesNoMutationWithoutExclusiveOwnership.size();
440  }
441 
442  // Checks if this Resources is a superset of the given Resources.
443  bool contains(const Resources& that) const;
444 
445  // Checks if this Resources contains the given Resource.
446  bool contains(const Resource& that) const;
447 
448  // Checks if the quantities of this `Resources` is a superset of the
449  // given `ResourceQuantities`. If a `Resource` object is `SCALAR` type,
450  // its quantity is its scalar value. For `RANGES` and `SET` type, their
451  // quantities are the number of different instances in the range or set.
452  // For example, "range:[1-5]" has a quantity of 5 and "set:{a,b}" has a
453  // quantity of 2.
454  bool contains(
455  const mesos::internal::ResourceQuantities& quantities) const;
456  // Count the Resource objects that match the specified value.
457  //
458  // NOTE:
459  // - For a non-shared resource the count can be at most 1 because all
460  // non-shared Resource objects in Resources are unique.
461  // - For a shared resource the count can be greater than 1.
462  // - If the resource is not in the Resources object, the count is 0.
463  size_t count(const Resource& that) const;
464 
465  // Allocates the resources to the given role (by setting the
466  // `AllocationInfo.role`). Any existing allocation will be
467  // over-written.
468  void allocate(const std::string& role);
469 
470  // Unallocates the resources.
471  void unallocate();
472 
473  // Filter resources based on the given predicate.
475  const lambda::function<bool(const Resource&)>& predicate) const;
476 
477  // Returns the reserved resources, by role.
478  hashmap<std::string, Resources> reservations() const;
479 
480  // Returns the reserved resources for the role, if specified.
481  // Note that the "*" role represents unreserved resources,
482  // and will be ignored.
483  Resources reserved(const Option<std::string>& role = None()) const;
484 
485  // Returns resources allocatable to role. See `isAllocatableTo` for the
486  // definition of 'allocatableTo'.
487  Resources allocatableTo(const std::string& role) const;
488 
489  // Returns the unreserved resources.
490  Resources unreserved() const;
491 
492  // Returns the persistent volumes.
493  Resources persistentVolumes() const;
494 
495  // Returns the revocable resources.
496  Resources revocable() const;
497 
498  // Returns the non-revocable resources, effectively !revocable().
499  Resources nonRevocable() const;
500 
501  // Returns the shared resources.
502  Resources shared() const;
503 
504  // Returns the non-shared resources.
505  Resources nonShared() const;
506 
507  // Returns the per-role allocations within these resource objects.
508  // This must be called only when the resources are allocated!
509  hashmap<std::string, Resources> allocations() const;
510 
511  // Returns a `Resources` object with the new reservation added to the back.
512  // The new reservation must be a valid refinement of the current reservation.
513  Resources pushReservation(const Resource::ReservationInfo& reservation) const;
514 
515  // Returns a `Resources` object with the last reservation removed.
516  // Every resource in `Resources` must have `resource.reservations_size() > 0`.
517  Resources popReservation() const;
518 
519  // Returns a `Resources` object with all of the reservations removed.
520  Resources toUnreserved() const;
521 
522  // Returns a Resources object that contains all the scalar resources
523  // but with all the meta-data fields, such as AllocationInfo,
524  // ReservationInfo and etc. cleared. Only scalar resources' name,
525  // type (SCALAR) and value are preserved.
526  //
527  // This is intended for code that would like to aggregate together
528  // Resource values without regard for metadata like whether the
529  // resource is reserved or the particular volume ID in use. For
530  // example, when calculating the total resources in a cluster,
531  // preserving such information has a major performance cost.
532  Resources createStrippedScalarQuantity() const;
533 
534  // Finds a Resources object with the same amount of each resource
535  // type as "targets" from these Resources. The roles specified in
536  // "targets" set the preference order. For each resource type,
537  // resources are first taken from the specified role, then from '*',
538  // then from any other role.
539  // TODO(jieyu): 'find' contains some allocation logic for scalars and
540  // fixed set / range elements. However, this is not sufficient for
541  // schedulers that want, say, any N available ports. We should
542  // consider moving this to an internal "allocation" library for our
543  // example frameworks to leverage.
544  Option<Resources> find(const Resources& targets) const;
545 
546  // Applies a resource conversion by taking out the `consumed`
547  // resources and adding back the `converted` resources. Returns an
548  // Error if the conversion cannot be applied.
549  Try<Resources> apply(const ResourceConversion& conversion) const;
550 
551  // Obtains the conversion from the given operation and applies the
552  // conversion. This method serves a syntax sugar for applying a
553  // resource conversion.
554  // TODO(jieyu): Consider remove this method once we updated all the
555  // call sites.
556  Try<Resources> apply(const Offer::Operation& operation) const;
557 
558  template <typename Iterable>
559  Try<Resources> apply(const Iterable& iterable) const
560  {
561  Resources result = *this;
562 
563  foreach (const auto& t, iterable) {
564  Try<Resources> converted = result.apply(t);
565  if (converted.isError()) {
566  return Error(converted.error());
567  }
568 
569  result = converted.get();
570  }
571 
572  return result;
573  }
574 
575  // Helpers to get resource values. We consider all roles here.
576  template <typename T>
577  Option<T> get(const std::string& name) const;
578 
579  // Get resources of the given name.
580  Resources get(const std::string& name) const;
581 
582  // Get all the resources that are scalars.
583  Resources scalars() const;
584 
585  // Get the set of unique resource names.
586  std::set<std::string> names() const;
587 
588  // Get the types of resources associated with each resource name.
589  // NOTE: Resources of the same name must have the same type, as
590  // enforced by Resources::parse().
591  std::map<std::string, Value_Type> types() const;
592 
593  // Helpers to get known resource types.
594  // TODO(vinod): Fix this when we make these types as first class
595  // protobufs.
596  Option<double> cpus() const;
597  Option<double> gpus() const;
598  Option<Bytes> mem() const;
599  Option<Bytes> disk() const;
600 
601  // TODO(vinod): Provide a Ranges abstraction.
602  Option<Value::Ranges> ports() const;
603 
604  // TODO(jieyu): Consider returning an EphemeralPorts abstraction
605  // which holds the ephemeral ports allocation logic.
606  Option<Value::Ranges> ephemeral_ports() const;
607 
608  // We use `boost::indirect_iterator` to expose `Resource` (implicitly
609  // converted from `Resource_`) iteration, while actually storing
610  // `Resource_Unsafe`.
611  //
612  // NOTE: Non-const `begin()` and `end()` intentionally return const
613  // iterators to prevent mutable access to the `Resource` objects.
614 
615  typedef boost::indirect_iterator<
616  std::vector<Resource_Unsafe>::const_iterator>
618 
620  {
621  return static_cast<const std::vector<Resource_Unsafe>&>(
622  resourcesNoMutationWithoutExclusiveOwnership)
623  .begin();
624  }
625 
627  {
628  return static_cast<const std::vector<Resource_Unsafe>&>(
629  resourcesNoMutationWithoutExclusiveOwnership)
630  .end();
631  }
632 
634  {
635  return resourcesNoMutationWithoutExclusiveOwnership.begin();
636  }
637 
639  {
640  return resourcesNoMutationWithoutExclusiveOwnership.end();
641  }
642 
643  // Using this operator makes it easy to copy a resources object into
644  // a protocol buffer field.
645  // Note that the google::protobuf::RepeatedPtrField<Resource> is
646  // generated at runtime.
647  operator google::protobuf::RepeatedPtrField<Resource>() const;
648 
649  bool operator==(const Resources& that) const;
650  bool operator!=(const Resources& that) const;
651 
652  // NOTE: If any error occurs (e.g., input Resource is not valid or
653  // the first operand is not a superset of the second operand while
654  // doing subtraction), the semantics is as though the second operand
655  // was actually just an empty resource (as though you didn't do the
656  // operation at all).
657  Resources operator+(const Resource& that) const &;
658  Resources operator+(const Resource& that) &&;
659 
660  Resources operator+(Resource&& that) const &;
661  Resources operator+(Resource&& that) &&;
662 
663  Resources& operator+=(const Resource& that);
664  Resources& operator+=(Resource&& that);
665 
666  Resources operator+(const Resources& that) const &;
667  Resources operator+(const Resources& that) &&;
668 
669  Resources operator+(Resources&& that) const &;
670  Resources operator+(Resources&& that) &&;
671 
672  Resources& operator+=(const Resources& that);
673  Resources& operator+=(Resources&& that);
674 
675  Resources operator-(const Resource& that) const;
676  Resources operator-(const Resources& that) const;
677  Resources& operator-=(const Resource& that);
678  Resources& operator-=(const Resources& that);
679 
680  friend std::ostream& operator<<(
681  std::ostream& stream, const Resource_& resource_);
682 
683 private:
684  // Similar to 'contains(const Resource&)' but skips the validity
685  // check. This can be used to avoid the performance overhead of
686  // calling 'contains(const Resource&)' when the resource can be
687  // assumed valid (e.g. it's inside a Resources).
688  //
689  // TODO(jieyu): Measure performance overhead of validity check to
690  // ensure this is warranted.
691  bool _contains(const Resource_& that) const;
692 
693  // Similar to the public 'find', but only for a single Resource
694  // object. The target resource may span multiple roles, so this
695  // returns Resources.
696  Option<Resources> find(const Resource& target) const;
697 
698  // Validation-free versions of += and -= `Resource_` operators.
699  // These can be used when `r` is already validated.
700  //
701  // NOTE: `Resource` objects are implicitly converted to `Resource_`
702  // objects, so here the API can also accept a `Resource` object.
703  void add(const Resource_& r);
704  void add(Resource_&& r);
705 
706  // TODO(mzhu): Add move support.
707  void add(const Resource_Unsafe& that);
708 
709  void subtract(const Resource_& r);
710 
711  Resources& operator+=(const Resource_& that);
712  Resources& operator+=(Resource_&& that);
713 
714  Resources& operator-=(const Resource_& that);
715 
716  // Resources are stored using copy-on-write:
717  //
718  // (1) Copies are done by copying the `shared_ptr`. This
719  // makes read-only filtering (e.g. `unreserved()`)
720  // inexpensive as we do not have to perform copies
721  // of the resource objects.
722  //
723  // (2) When a write occurs:
724  // (a) If there's a single reference to the resource
725  // object, we mutate directly.
726  // (b) If there's more than a single reference to the
727  // resource object, we copy first, then mutate the copy.
728  //
729  // We name the `vector` field `resourcesNoMutationWithoutExclusiveOwnership`
730  // and typedef its item type to `Resource_Unsafe` to alert people
731  // regarding (2).
732  //
733  // TODO(mzhu): While naming the vector and its item type may help, this is
734  // still brittle and certainly not ideal. Explore more robust designs such as
735  // introducing a customized copy-on-write abstraction that hides direct
736  // setters and only allow mutations in a controlled fashion.
737  //
738  // TODO(mzhu): Consider using `boost::intrusive_ptr` for
739  // possibly better performance.
740  std::vector<Resource_Unsafe> resourcesNoMutationWithoutExclusiveOwnership;
741 };
742 
743 
744 std::ostream& operator<<(
745  std::ostream& stream,
746  const Resources::Resource_& resource);
747 
748 
749 std::ostream& operator<<(std::ostream& stream, const Resource& resource);
750 
751 
752 std::ostream& operator<<(std::ostream& stream, const Resources& resources);
753 
754 
755 std::ostream& operator<<(
756  std::ostream& stream,
757  const google::protobuf::RepeatedPtrField<Resource>& resources);
758 
759 
761  const google::protobuf::RepeatedPtrField<Resource>& left,
762  const Resources& right)
763 {
764  return Resources(left) + right;
765 }
766 
767 
769  const google::protobuf::RepeatedPtrField<Resource>& left,
770  const Resources& right)
771 {
772  return Resources(left) - right;
773 }
774 
775 
776 inline bool operator==(
777  const google::protobuf::RepeatedPtrField<Resource>& left,
778  const Resources& right)
779 {
780  return Resources(left) == right;
781 }
782 
783 
784 template <typename Key>
787  const hashmap<Key, Resources>& right)
788 {
789  foreachpair (const Key& key, const Resources& resources, right) {
790  left[key] += resources;
791  }
792  return left;
793 }
794 
795 
796 template <typename Key>
798  const hashmap<Key, Resources>& left,
799  const hashmap<Key, Resources>& right)
800 {
801  hashmap<Key, Resources> result = left;
802  result += right;
803  return result;
804 }
805 
806 
812 {
813 public:
814  typedef lambda::function<Try<Nothing>(const Resources&)> PostValidation;
815 
817  const Resources& _consumed,
818  const Resources& _converted,
819  const Option<PostValidation>& _postValidation = None())
820  : consumed(_consumed),
821  converted(_converted),
822  postValidation(_postValidation) {}
823 
824  Try<Resources> apply(const Resources& resources) const;
825 
829 };
830 
831 } // namespace v1 {
832 } // namespace mesos {
833 
834 #endif // __MESOS_V1_RESOURCES_HPP__
Resources & operator=(const Resources &that)
Definition: resources.hpp:414
Option< Error > validate(const std::string &imageDir)
Definition: errorbase.hpp:36
T & get()&
Definition: try.hpp:73
const_iterator end()
Definition: resources.hpp:626
Definition: check.hpp:33
Try< Resources > apply(const Iterable &iterable) const
Definition: resources.hpp:559
bool empty() const
Definition: resources.hpp:432
std::ostream & operator<<(std::ostream &stream, const ImageGcConfig &imageGcConfig)
Definition: flags.hpp:92
Definition: json.hpp:198
Operation
Definition: cgroups.hpp:458
Future< Nothing > add(const T &metric)
Definition: metrics.hpp:95
Resources operator-(const google::protobuf::RepeatedPtrField< Resource > &left, const Resources &right)
Definition: resources.hpp:774
std::map< std::string, std::string > types
Definition: hashmap.hpp:38
Represents a resource conversion, usually as a result of an offer operation.
Definition: resources.hpp:811
bool contains(const std::string &s, const std::string &substr)
Definition: strings.hpp:423
const_iterator begin() const
Definition: resources.hpp:633
size_t size() const
Definition: resources.hpp:437
Try< long > cpus()
Definition: os.hpp:286
Resources consumed
Definition: resources.hpp:826
ResourceConversion(const Resources &_consumed, const Resources &_converted, const Option< PostValidation > &_postValidation=None())
Definition: resources.hpp:816
Definition: spec.hpp:26
Try< ImageManifest > parse(const std::string &value)
Definition: parse.hpp:36
const_iterator end() const
Definition: resources.hpp:638
Definition: resources.hpp:84
#define foreachpair(KEY, VALUE, ELEMS)
Definition: foreach.hpp:51
#define foreachvalue(VALUE, ELEMS)
Definition: foreach.hpp:77
Value::Scalar & operator-=(Value::Scalar &left, const Value::Scalar &right)
Resources()
Definition: resources.hpp:397
static Try error(const E &e)
Definition: try.hpp:42
Resources & operator=(Resources &&that)
Definition: resources.hpp:423
bool operator==(const ResourceVersionUUID &left, const ResourceVersionUUID &right)
lambda::function< Try< Nothing >const Resources &)> PostValidation
Definition: resources.hpp:814
Resources operator+(const google::protobuf::RepeatedPtrField< Resource > &left, const Resources &right)
Definition: resources.hpp:766
const_iterator begin()
Definition: resources.hpp:619
Definition: resource_quantities.hpp:69
Definition: none.hpp:27
Definition: attributes.hpp:24
bool isError() const
Definition: try.hpp:71
Type
Definition: capabilities.hpp:79
Resources converted
Definition: resources.hpp:827
Try< uint32_t > type(const std::string &path)
Try< Resources > apply(const ResourceConversion &conversion) const
bool operator!=(const ResourceVersionUUID &left, const ResourceVersionUUID &right)
std::shared_ptr< Resource_ > Resource_Unsafe
Definition: resources.hpp:176
boost::indirect_iterator< std::vector< Resource_Unsafe >::const_iterator > const_iterator
Definition: resources.hpp:617
hashmap< Key, Resources > & operator+=(hashmap< Key, Resources > &left, const hashmap< Key, Resources > &right)
Definition: resources.hpp:791
static Resources sum(const hashmap< Key, Resources > &_resources)
Definition: resources.hpp:386
constexpr const char * name
Definition: shell.hpp:43
Try< std::list< std::string > > find(const std::string &directory, const std::string &pattern)
Definition: find.hpp:37
void filter(Filter *filter)
Option< PostValidation > postValidation
Definition: resources.hpp:828