17 #ifndef __RESOURCES_HPP__ 18 #define __RESOURCES_HPP__ 26 #include <boost/container/small_vector.hpp> 27 #include <boost/iterator/indirect_iterator.hpp> 29 #include <google/protobuf/repeated_field.h> 62 class ResourceConversion;
67 const Resource::ReservationInfo& left,
68 const Resource::ReservationInfo& right);
72 const Resource::ReservationInfo& left,
73 const Resource::ReservationInfo& right);
97 Resource_(
const Resource& _resource)
98 : resource(_resource),
102 if (resource.has_shared()) {
107 Resource_(Resource&& _resource)
108 : resource(std::move(_resource)),
112 if (resource.has_shared()) {
117 Resource_(
const Resource_& resource_) =
default;
118 Resource_(Resource_&& resource_) =
default;
120 Resource_&
operator=(
const Resource_&) =
default;
121 Resource_&
operator=(Resource_&&) =
default;
125 operator const Resource&()
const {
return resource; }
128 bool isShared()
const {
return sharedCount.isSome(); }
147 bool contains(
const Resource_& that)
const;
160 std::ostream& stream,
const Resource_& resource_);
191 const std::string&
name,
192 const std::string& value,
193 const std::string& role);
210 const std::string& text,
211 const std::string& defaultRole =
"*");
234 const std::string& defaultRole =
"*");
254 const std::string& text,
255 const std::string& defaultRole =
"*");
270 const std::string& text,
271 const std::string& defaultRole =
"*");
305 const google::protobuf::RepeatedPtrField<Resource>& resources);
315 static bool isEmpty(
const Resource& resource);
322 const Resource& resource,
328 const Resource& resource,
337 const Resource& resource,
338 const std::string& role);
350 static bool isShared(
const Resource& resource);
355 const Resource& resource,
const std::string& role);
360 const Resource& resource,
const std::string& role);
377 static bool shrink(Resource* resource,
const Value::Scalar& target);
404 template <
typename Key>
423 Resources(
const std::vector<Resource>& _resources);
424 Resources(std::vector<Resource>&& _resources);
427 Resources(
const google::protobuf::RepeatedPtrField<Resource>& _resources);
428 Resources(google::protobuf::RepeatedPtrField<Resource>&& _resources);
436 resourcesNoMutationWithoutExclusiveOwnership =
437 that.resourcesNoMutationWithoutExclusiveOwnership;
445 resourcesNoMutationWithoutExclusiveOwnership =
446 std::move(that.resourcesNoMutationWithoutExclusiveOwnership);
453 return resourcesNoMutationWithoutExclusiveOwnership.size() == 0;
458 return resourcesNoMutationWithoutExclusiveOwnership.size();
465 bool contains(
const Resource& that)
const;
482 size_t count(
const Resource& that)
const;
487 void allocate(
const std::string& role);
494 const lambda::function<
bool(
const Resource&)>& predicate)
const;
541 const Resource::ReservationInfo& reservation)
const;
591 template <
typename Iterable>
596 foreach (
const auto& t, iterable) {
602 result = converted.
get();
609 template <
typename T>
619 std::set<std::string>
names()
const;
624 std::map<std::string, Value_Type>
types()
const;
648 typedef boost::indirect_iterator<
649 boost::container::small_vector_base<Resource_Unsafe>::const_iterator>
654 const auto&
self = *
this;
660 const auto&
self = *
this;
666 return resourcesNoMutationWithoutExclusiveOwnership.begin();
671 return resourcesNoMutationWithoutExclusiveOwnership.end();
678 operator google::protobuf::RepeatedPtrField<Resource>()
const;
712 std::ostream& stream,
const Resource_& resource_);
722 bool _contains(
const Resource_& that)
const;
734 void add(
const Resource_& r);
735 void add(Resource_&& r);
740 void subtract(
const Resource_& r);
775 boost::container::small_vector<Resource_Unsafe, 15>
776 resourcesNoMutationWithoutExclusiveOwnership;
781 std::ostream& stream,
782 const Resources::Resource_& resource);
785 std::ostream&
operator<<(std::ostream& stream,
const Resource& resource);
792 std::ostream& stream,
793 const google::protobuf::RepeatedPtrField<Resource>& resources);
797 const google::protobuf::RepeatedPtrField<Resource>& left,
805 const google::protobuf::RepeatedPtrField<Resource>& left,
813 const google::protobuf::RepeatedPtrField<Resource>& left,
820 template <
typename Key>
826 left[key] += resources;
832 template <
typename Key>
849 bool contains(
const Resource& left,
const Resource& right);
865 : consumed(_consumed),
866 converted(_converted),
867 postValidation(_postValidation) {}
878 #endif // __RESOURCES_HPP__ ResourceConversion(const Resources &_consumed, const Resources &_converted, const Option< PostValidation > &_postValidation=None())
Definition: resources.hpp:861
static bool isEmpty(const Resource &resource)
size_t size() const
Definition: resources.hpp:456
std::map< std::string, Value_Type > types() const
Resources consumed
Definition: resources.hpp:871
std::shared_ptr< Resource_ > Resource_Unsafe
Definition: resources.hpp:176
Definition: errorbase.hpp:36
std::set< std::string > names() const
T & get()&
Definition: try.hpp:80
Definition: resource_quantities.hpp:63
const_iterator end()
Definition: resources.hpp:658
static bool isDynamicallyReserved(const Resource &resource)
static bool isAllocatedToRoleSubtree(const Resource &resource, const std::string &role)
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:83
static bool isPersistentVolume(const Resource &resource)
Option< Value::Ranges > ephemeral_ports() const
Option< double > gpus() const
Option< Value::Ranges > ports() const
Try< Resources > apply(const ResourceConversion &conversion) const
Operation
Definition: cgroups.hpp:444
Future< Nothing > add(const T &metric)
Definition: metrics.hpp:95
STOUT_NODISCARD Resources pushReservation(const Resource::ReservationInfo &reservation) const
hashmap< std::string, Resources > reservations() const
static bool isShared(const Resource &resource)
static Resource getReservationAncestor(const Resource &a, const Resource &b)
Resources unreserved() const
Resources & operator=(const Resources &that)
Definition: resources.hpp:433
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:652
bool operator!=(const Resource::ReservationInfo &left, const Resource::ReservationInfo &right)
lambda::function< Try< Nothing >const Resources &)> PostValidation
Definition: resources.hpp:859
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
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 & operator-=(const Resource &that)
Resources createStrippedScalarQuantity() const
const_iterator begin() const
Definition: resources.hpp:664
STOUT_NODISCARD Resources popReservation() const
Resources & operator=(Resources &&that)
Definition: resources.hpp:442
Option< PostValidation > postValidation
Definition: resources.hpp:873
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 STOUT_NODISCARD
Definition: attributes.hpp:41
#define foreachvalue(VALUE, ELEMS)
Definition: foreach.hpp:77
Try< Resources > apply(const Iterable &iterable) const
Definition: resources.hpp:592
Resources reservedToRoleSubtree(const std::string &role) const
static Try error(const E &e)
Definition: try.hpp:43
const_iterator end() const
Definition: resources.hpp:669
static bool hasResourceProvider(const Resource &resource)
Represents a resource conversion, usually as a result of an offer operation.
Definition: resources.hpp:856
Resources scalars() const
Resources revocable() const
Resources persistentVolumes() const
bool empty() const
Definition: resources.hpp:451
bool operator!=(const Resources &that) const
static bool isReservedToRoleSubtree(const Resource &resource, const std::string &role)
bool isError() const
Definition: try.hpp:78
static bool shrink(Resource *resource, const Value::Scalar &target)
Resources nonShared() const
Type
Definition: capabilities.hpp:82
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())
Resources operator+(const Resource &that) const &
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 allocatedToRoleSubtree(const std::string &role) const
Resources()
Definition: resources.hpp:416
static Resources sum(const hashmap< Key, Resources > &_resources)
Definition: resources.hpp:405
bool contains(const Resources &that) const
Resources converted
Definition: resources.hpp:872
static bool isUnreserved(const Resource &resource)
Option< Bytes > disk() const
Resources operator-(const Resource &that) const
boost::indirect_iterator< boost::container::small_vector_base< Resource_Unsafe >::const_iterator > const_iterator
Definition: resources.hpp:650
constexpr const char * name
Definition: shell.hpp:41
static const std::string & reservationRole(const Resource &resource)
hashmap< std::string, Resources > allocations() const