17 #ifndef __RESOURCES_HPP__
18 #define __RESOURCES_HPP__
26 #include <google/protobuf/repeated_field.h>
58 class ResourceConversion;
63 const Resource::ReservationInfo& left,
64 const Resource::ReservationInfo& right);
68 const Resource::ReservationInfo& left,
69 const Resource::ReservationInfo& right);
93 Resource_(
const Resource& _resource)
94 : resource(_resource),
98 if (resource.has_shared()) {
105 operator const Resource&()
const {
return resource; }
108 bool isShared()
const {
return sharedCount.isSome(); }
127 bool contains(
const Resource_& that)
const;
140 std::ostream& stream,
const Resource_& resource_);
166 const std::string&
name,
167 const std::string& value,
168 const std::string& role);
185 const std::string& text,
186 const std::string& defaultRole =
"*");
209 const std::string& defaultRole =
"*");
229 const std::string& text,
230 const std::string& defaultRole =
"*");
245 const std::string& text,
246 const std::string& defaultRole =
"*");
280 const google::protobuf::RepeatedPtrField<Resource>& resources);
290 static bool isEmpty(
const Resource& resource);
297 const Resource& resource,
303 const Resource& resource,
312 const Resource& resource,
313 const std::string& role);
325 static bool isShared(
const Resource& resource);
342 static bool shrink(Resource* resource,
const Value::Scalar& target);
355 template <
typename Key>
373 Resources(
const std::vector<Resource>& _resources);
376 Resources(
const google::protobuf::RepeatedPtrField<Resource>& _resources);
383 resources = that.resources;
388 bool empty()
const {
return resources.size() == 0; }
390 size_t size()
const {
return resources.size(); }
396 bool contains(
const Resource& that)
const;
405 size_t count(
const Resource& that)
const;
410 void allocate(
const std::string& role);
417 const lambda::function<
bool(
const Resource&)>& predicate)
const;
507 template <
typename Iterable>
512 foreach (
const auto& t, iterable) {
518 result = converted.
get();
525 template <
typename T>
535 std::set<std::string>
names()
const;
540 std::map<std::string, Value_Type>
types()
const;
560 typedef std::vector<Resource_>::const_iterator
iterator;
565 return static_cast<const std::vector<Resource_>&
>(resources).
begin();
570 return static_cast<const std::vector<Resource_>&
>(resources).
end();
580 operator google::protobuf::RepeatedPtrField<Resource>()
const;
601 std::ostream& stream,
const Resource_& resource_);
611 bool _contains(
const Resource_& that)
const;
623 void add(
const Resource_& r);
624 void subtract(
const Resource_& r);
632 std::vector<Resource_> resources;
637 std::ostream& stream,
638 const Resources::Resource_& resource);
641 std::ostream&
operator<<(std::ostream& stream,
const Resource& resource);
644 std::ostream&
operator<<(std::ostream& stream,
const Resources& resources);
648 std::ostream& stream,
649 const google::protobuf::RepeatedPtrField<Resource>& resources);
653 const google::protobuf::RepeatedPtrField<Resource>& left,
661 const google::protobuf::RepeatedPtrField<Resource>& left,
669 const google::protobuf::RepeatedPtrField<Resource>& left,
676 template <
typename Key>
682 left[key] += resources;
688 template <
typename Key>
725 #endif // __RESOURCES_HPP__
std::ostream & operator<<(std::ostream &stream, const Attribute &attribute)
ResourceConversion(const Resources &_consumed, const Resources &_converted, const Option< PostValidation > &_postValidation=None())
Definition: resources.hpp:708
std::vector< Resource_ >::const_iterator const_iterator
Definition: resources.hpp:561
Try< Resources > apply(const Resources &resources) const
static bool isEmpty(const Resource &resource)
size_t size() const
Definition: resources.hpp:390
std::map< std::string, Value_Type > types() const
Resources consumed
Definition: resources.hpp:718
Definition: errorbase.hpp:35
std::set< std::string > names() const
const_iterator end()
Definition: resources.hpp:568
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
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
Resources operator-(const google::protobuf::RepeatedPtrField< Resource > &left, const Resources &right)
Definition: resources.hpp:660
hashmap< std::string, Resources > reservations() const
static bool isShared(const Resource &resource)
Resources unreserved() const
Resources & operator=(const Resources &that)
Definition: resources.hpp:380
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:563
bool operator!=(const Resource::ReservationInfo &left, const Resource::ReservationInfo &right)
lambda::function< Try< Nothing >const Resources &)> PostValidation
Definition: resources.hpp:706
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:378
const_iterator begin() const
Definition: resources.hpp:573
Option< PostValidation > postValidation
Definition: resources.hpp:720
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:508
static Try error(const E &e)
Definition: try.hpp:42
const_iterator end() const
Definition: resources.hpp:574
static bool hasResourceProvider(const Resource &resource)
Represents a resource conversion, usually as a result of an offer operation.
Definition: resources.hpp:703
Resources scalars() const
Resources revocable() const
Resources operator+(const google::protobuf::RepeatedPtrField< Resource > &left, const Resources &right)
Definition: resources.hpp:652
Resources persistentVolumes() const
bool empty() const
Definition: resources.hpp:388
bool operator!=(const Resources &that) const
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:367
static Resources sum(const hashmap< Key, Resources > &_resources)
Definition: resources.hpp:356
bool contains(const Resources &that) const
Resources converted
Definition: resources.hpp:719
static bool isUnreserved(const Resource &resource)
Option< Bytes > disk() const
hashmap< Key, Resources > & operator+=(hashmap< Key, Resources > &left, const hashmap< Key, Resources > &right)
Definition: resources.hpp:677
Resources operator-(const Resource &that) const
const T & get() const
Definition: try.hpp:73
constexpr const char * name
Definition: shell.hpp:41
static const std::string & reservationRole(const Resource &resource)
hashmap< std::string, Resources > allocations() const
std::vector< Resource_ >::const_iterator iterator
Definition: resources.hpp:560