17 #ifndef __MESOS_V1_RESOURCES_HPP__
18 #define __MESOS_V1_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;
502 template <
typename Iterable>
507 foreach (
const auto& t, iterable) {
513 result = converted.
get();
520 template <
typename T>
530 std::set<std::string>
names()
const;
535 std::map<std::string, Value_Type>
types()
const;
555 typedef std::vector<Resource_>::const_iterator
iterator;
560 return static_cast<const std::vector<Resource_>&
>(resources).
begin();
565 return static_cast<const std::vector<Resource_>&
>(resources).
end();
575 operator google::protobuf::RepeatedPtrField<Resource>()
const;
596 std::ostream& stream,
const Resource_& resource_);
606 bool _contains(
const Resource_& that)
const;
618 void add(
const Resource_& r);
619 void subtract(
const Resource_& r);
627 std::vector<Resource_> resources;
632 std::ostream& stream,
633 const Resources::Resource_& resource);
636 std::ostream&
operator<<(std::ostream& stream,
const Resource& resource);
643 std::ostream& stream,
644 const google::protobuf::RepeatedPtrField<Resource>& resources);
648 const google::protobuf::RepeatedPtrField<Resource>& left,
656 const google::protobuf::RepeatedPtrField<Resource>& left,
664 const google::protobuf::RepeatedPtrField<Resource>& left,
671 template <
typename Key>
677 left[key] += resources;
683 template <
typename Key>
721 #endif // __MESOS_V1_RESOURCES_HPP__
Try< Resources > apply(const Resources &resources) const
Resources toUnreserved() const
Resources revocable() const
Resources reserved(const Option< std::string > &role=None()) const
Resources & operator=(const Resources &that)
Definition: resources.hpp:380
static Option< Error > validate(const Resource &resource)
Validates a Resource object.
Definition: errorbase.hpp:35
Resources unreserved() const
const_iterator end()
Definition: resources.hpp:563
static bool isPersistentVolume(const Resource &resource)
Option< Bytes > disk() const
Resources nonRevocable() const
Option< double > cpus() const
Try< Resources > apply(const Iterable &iterable) const
Definition: resources.hpp:503
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:388
Resources(const Resources &that)
Definition: resources.hpp:378
Definition: resources.hpp:79
static bool isAllocatableTo(const Resource &resource, const std::string &role)
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:441
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
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< Key, Resources > & operator+=(hashmap< Key, Resources > &left, const hashmap< Key, Resources > &right)
Definition: resources.hpp:672
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:698
const_iterator begin() const
Definition: resources.hpp:568
Resources createStrippedScalarQuantity() const
size_t size() const
Definition: resources.hpp:390
bool contains(const Resources &that) const
hashmap< std::string, Resources > reservations() const
Resources nonShared() const
static bool isShared(const Resource &resource)
Resources operator-(const Resource &that) const
std::vector< Resource_ >::const_iterator const_iterator
Definition: resources.hpp:556
Resources consumed
Definition: resources.hpp:713
ResourceConversion(const Resources &_consumed, const Resources &_converted, const Option< PostValidation > &_postValidation=None())
Definition: resources.hpp:703
void allocate(const std::string &role)
const_iterator end() const
Definition: resources.hpp:569
Definition: resources.hpp:79
#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:367
friend std::ostream & operator<<(std::ostream &stream, const Resource_ &resource_)
static Try error(const E &e)
Definition: try.hpp:42
lambda::function< Try< Nothing >const Resources &)> PostValidation
Definition: resources.hpp:701
Resources operator-(const google::protobuf::RepeatedPtrField< Resource > &left, const Resources &right)
Definition: resources.hpp:655
const_iterator begin()
Definition: resources.hpp:558
Resources operator+(const google::protobuf::RepeatedPtrField< Resource > &left, const Resources &right)
Definition: resources.hpp:647
size_t count(const Resource &that) const
bool isError() const
Definition: try.hpp:71
Option< Bytes > mem() const
bool operator!=(const Resources &that) const
static bool isRevocable(const Resource &resource)
Type
Definition: capabilities.hpp:79
Resources scalars() const
Resources converted
Definition: resources.hpp:714
Resources allocatableTo(const std::string &role) const
std::vector< Resource_ >::const_iterator iterator
Definition: resources.hpp:555
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.
Resources operator+(const Resource &that) const
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::set< std::string > names() const
static bool shrink(Resource *resource, const Value::Scalar &target)
std::ostream & operator<<(std::ostream &stream, const Attribute &attribute)
static Resources sum(const hashmap< Key, Resources > &_resources)
Definition: resources.hpp:356
const T & get() const
Definition: try.hpp:73
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:715
static bool isEmpty(const Resource &resource)