17 #ifndef __MESOS_V1_RESOURCES_HPP__ 18 #define __MESOS_V1_RESOURCES_HPP__ 26 #include <boost/container/small_vector.hpp> 27 #include <boost/iterator/indirect_iterator.hpp> 29 #include <google/protobuf/repeated_field.h> 63 class ResourceConversion;
68 const Resource::ReservationInfo& left,
69 const Resource::ReservationInfo& right);
73 const Resource::ReservationInfo& left,
74 const Resource::ReservationInfo& right);
98 Resource_(
const Resource& _resource)
99 : resource(_resource),
103 if (resource.has_shared()) {
108 Resource_(Resource&& _resource)
109 : resource(std::move(_resource)), sharedCount(
None())
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);
390 template <
typename Key>
409 Resources(
const std::vector<Resource>& _resources);
410 Resources(std::vector<Resource>&& _resources);
413 Resources(
const google::protobuf::RepeatedPtrField<Resource>& _resources);
414 Resources(google::protobuf::RepeatedPtrField<Resource>&& _resources);
422 resourcesNoMutationWithoutExclusiveOwnership =
423 that.resourcesNoMutationWithoutExclusiveOwnership;
431 resourcesNoMutationWithoutExclusiveOwnership =
432 std::move(that.resourcesNoMutationWithoutExclusiveOwnership);
439 return resourcesNoMutationWithoutExclusiveOwnership.size() == 0;
444 return resourcesNoMutationWithoutExclusiveOwnership.size();
451 bool contains(
const Resource& that)
const;
468 size_t count(
const Resource& that)
const;
473 void allocate(
const std::string& role);
480 const lambda::function<
bool(
const Resource&)>& predicate)
const;
571 template <
typename Iterable>
576 foreach (
const auto& t, iterable) {
582 result = converted.
get();
589 template <
typename T>
599 std::set<std::string>
names()
const;
604 std::map<std::string, Value_Type>
types()
const;
628 typedef boost::indirect_iterator<
629 boost::container::small_vector_base<Resource_Unsafe>::const_iterator>
634 const auto&
self = *
this;
640 const auto&
self = *
this;
646 return resourcesNoMutationWithoutExclusiveOwnership.begin();
651 return resourcesNoMutationWithoutExclusiveOwnership.end();
658 operator google::protobuf::RepeatedPtrField<Resource>()
const;
692 std::ostream& stream,
const Resource_& resource_);
702 bool _contains(
const Resource_& that)
const;
714 void add(
const Resource_& r);
715 void add(Resource_&& r);
720 void subtract(
const Resource_& r);
755 boost::container::small_vector<Resource_Unsafe, 15>
756 resourcesNoMutationWithoutExclusiveOwnership;
761 std::ostream& stream,
762 const Resources::Resource_& resource);
765 std::ostream&
operator<<(std::ostream& stream,
const Resource& resource);
772 std::ostream& stream,
773 const google::protobuf::RepeatedPtrField<Resource>& resources);
777 const google::protobuf::RepeatedPtrField<Resource>& left,
785 const google::protobuf::RepeatedPtrField<Resource>& left,
793 const google::protobuf::RepeatedPtrField<Resource>& left,
800 template <
typename Key>
806 left[key] += resources;
812 template <
typename Key>
829 bool contains(
const Resource& left,
const Resource& right);
845 : consumed(_consumed),
846 converted(_converted),
847 postValidation(_postValidation) {}
859 #endif // __MESOS_V1_RESOURCES_HPP__ Resources toUnreserved() const
Resources revocable() const
Resources reserved(const Option< std::string > &role=None()) const
Resources & operator=(const Resources &that)
Definition: resources.hpp:419
static Option< Error > validate(const Resource &resource)
Validates a Resource object.
Definition: errorbase.hpp:36
Resources unreserved() const
T & get()&
Definition: try.hpp:80
const_iterator end()
Definition: resources.hpp:638
static bool isPersistentVolume(const Resource &resource)
Option< Bytes > disk() const
Definition: resource_quantities.hpp:63
Resources nonRevocable() const
Option< double > cpus() const
Try< Resources > apply(const Iterable &iterable) const
Definition: resources.hpp:572
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.
Resources popReservation() const
Resources persistentVolumes() const
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.
bool empty() const
Definition: resources.hpp:437
static bool isAllocatableTo(const Resource &resource, const std::string &role)
boost::indirect_iterator< boost::container::small_vector_base< Resource_Unsafe >::const_iterator > const_iterator
Definition: resources.hpp:630
Resources reservedToRoleSubtree(const std::string &role) const
bool operator==(const Resources &that) const
static const std::string & reservationRole(const Resource &resource)
Resources filter(const lambda::function< bool(const Resource &)> &predicate) const
static bool hasResourceProvider(const Resource &resource)
Operation
Definition: cgroups.hpp:444
Future< Nothing > add(const T &metric)
Definition: metrics.hpp:95
Resources & operator-=(const Resource &that)
static bool isDynamicallyReserved(const Resource &resource)
std::map< std::string, Value_Type > types() const
Resources operator+(const Resource &that) const &
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.
static bool hasRefinedReservations(const Resource &resource)
static bool isReserved(const Resource &resource, const Option< std::string > &role=None())
hashmap< std::string, Resources > allocations() const
Definition: hashmap.hpp:38
Resources pushReservation(const Resource::ReservationInfo &reservation) const
Represents a resource conversion, usually as a result of an offer operation.
Definition: resources.hpp:836
static bool isReservedToRoleSubtree(const Resource &resource, const std::string &role)
const_iterator begin() const
Definition: resources.hpp:644
Resources createStrippedScalarQuantity() const
size_t size() const
Definition: resources.hpp:442
bool contains(const Resources &that) const
hashmap< std::string, Resources > reservations() const
Resources nonShared() const
static bool isAllocatedToRoleSubtree(const Resource &resource, const std::string &role)
static bool isShared(const Resource &resource)
Resources operator-(const Resource &that) const
Resources consumed
Definition: resources.hpp:851
ResourceConversion(const Resources &_consumed, const Resources &_converted, const Option< PostValidation > &_postValidation=None())
Definition: resources.hpp:841
void allocate(const std::string &role)
const_iterator end() const
Definition: resources.hpp:649
Definition: resources.hpp:84
#define foreachpair(KEY, VALUE, ELEMS)
Definition: foreach.hpp:51
bool operator==(const CommandInfo &left, const CommandInfo &right)
#define foreachvalue(VALUE, ELEMS)
Definition: foreach.hpp:77
Option< Value::Ranges > ports() const
Resources()
Definition: resources.hpp:402
friend std::ostream & operator<<(std::ostream &stream, const Resource_ &resource_)
static Try error(const E &e)
Definition: try.hpp:43
Resources & operator=(Resources &&that)
Definition: resources.hpp:428
Resources allocatedToRoleSubtree(const std::string &role) const
lambda::function< Try< Nothing >const Resources &)> PostValidation
Definition: resources.hpp:839
const_iterator begin()
Definition: resources.hpp:632
size_t count(const Resource &that) const
bool isError() const
Definition: try.hpp:78
Option< Bytes > mem() const
bool operator!=(const Resources &that) const
static bool isRevocable(const Resource &resource)
Type
Definition: capabilities.hpp:82
Resources scalars() const
Resources converted
Definition: resources.hpp:852
Resources allocatableTo(const std::string &role) const
static bool isUnreserved(const Resource &resource)
Try< uint32_t > type(const std::string &path)
Option< Value::Ranges > ephemeral_ports() 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.
bool operator!=(const Labels &left, const Labels &right)
Try< Resources > apply(const ResourceConversion &conversion) const
static bool isDisk(const Resource &resource, const Resource::DiskInfo::Source::Type &type)
std::shared_ptr< Resource_ > Resource_Unsafe
Definition: resources.hpp:176
std::set< std::string > names() const
static bool shrink(Resource *resource, const Value::Scalar &target)
static Resources sum(const hashmap< Key, Resources > &_resources)
Definition: resources.hpp:391
constexpr const char * name
Definition: shell.hpp:41
Option< Resources > find(const Resources &targets) const
Resources & operator+=(const Resource &that)
Option< double > gpus() const
Option< PostValidation > postValidation
Definition: resources.hpp:853
static bool isEmpty(const Resource &resource)