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