Apache Mesos
|
#include <resources.hpp>
Public Types | |
using | Resource_Unsafe = std::shared_ptr< Resource_ > |
typedef boost::indirect_iterator< boost::container::small_vector_base< Resource_Unsafe >::const_iterator > | const_iterator |
Public Member Functions | |
Resources () | |
Resources (const Resource &resource) | |
Resources (Resource &&resource) | |
Resources (const std::vector< Resource > &_resources) | |
Resources (std::vector< Resource > &&_resources) | |
Resources (const google::protobuf::RepeatedPtrField< Resource > &_resources) | |
Resources (google::protobuf::RepeatedPtrField< Resource > &&_resources) | |
Resources (const Resources &that)=default | |
Resources (Resources &&that)=default | |
Resources & | operator= (const Resources &that) |
Resources & | operator= (Resources &&that) |
bool | empty () const |
size_t | size () const |
bool | contains (const Resources &that) const |
bool | contains (const Resource &that) const |
bool | contains (const ResourceQuantities &quantities) const |
size_t | count (const Resource &that) const |
void | allocate (const std::string &role) |
void | unallocate () |
Resources | filter (const lambda::function< bool(const Resource &)> &predicate) const |
hashmap< std::string, Resources > | reservations () const |
Resources | reserved (const Option< std::string > &role=None()) const |
Resources | allocatableTo (const std::string &role) const |
Resources | allocatedToRoleSubtree (const std::string &role) const |
Resources | reservedToRoleSubtree (const std::string &role) const |
Resources | unreserved () const |
Resources | persistentVolumes () const |
Resources | revocable () const |
Resources | nonRevocable () const |
Resources | shared () const |
Resources | nonShared () const |
hashmap< std::string, Resources > | allocations () const |
Resources | pushReservation (const Resource::ReservationInfo &reservation) const |
Resources | popReservation () const |
Resources | toUnreserved () const |
Resources | createStrippedScalarQuantity () const |
Option< Resources > | find (const Resources &targets) const |
Try< Resources > | apply (const ResourceConversion &conversion) const |
Try< Resources > | apply (const Offer::Operation &operation) const |
template<typename Iterable > | |
Try< Resources > | apply (const Iterable &iterable) const |
template<typename T > | |
Option< T > | get (const std::string &name) const |
Resources | get (const std::string &name) const |
Resources | scalars () const |
std::set< std::string > | names () const |
std::map< std::string, Value_Type > | types () const |
Option< double > | cpus () const |
Option< double > | gpus () const |
Option< Bytes > | mem () const |
Option< Bytes > | disk () const |
Option< Value::Ranges > | ports () const |
Option< Value::Ranges > | ephemeral_ports () const |
const_iterator | begin () |
const_iterator | end () |
const_iterator | begin () const |
const_iterator | end () const |
operator google::protobuf::RepeatedPtrField< Resource > () const | |
bool | operator== (const Resources &that) const |
bool | operator!= (const Resources &that) const |
Resources | operator+ (const Resource &that) const & |
Resources | operator+ (const Resource &that)&& |
Resources | operator+ (Resource &&that) const & |
Resources | operator+ (Resource &&that)&& |
Resources & | operator+= (const Resource &that) |
Resources & | operator+= (Resource &&that) |
Resources | operator+ (const Resources &that) const & |
Resources | operator+ (const Resources &that)&& |
Resources | operator+ (Resources &&that) const & |
Resources | operator+ (Resources &&that)&& |
Resources & | operator+= (const Resources &that) |
Resources & | operator+= (Resources &&that) |
Resources | operator- (const Resource &that) const |
Resources | operator- (const Resources &that) const |
Resources & | operator-= (const Resource &that) |
Resources & | operator-= (const Resources &that) |
Static Public Member Functions | |
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. More... | |
static Try< Resources > | parse (const std::string &text, const std::string &defaultRole="*") |
Parses Resources from an input string. More... | |
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. More... | |
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. More... | |
static Try< std::vector< Resource > > | fromString (const std::string &text, const std::string &defaultRole="*") |
Parse an input string into a vector of Resource objects. More... | |
static Option< Error > | validate (const Resource &resource) |
Validates a Resource object. More... | |
static Option< Error > | validate (const google::protobuf::RepeatedPtrField< Resource > &resources) |
Validates the given repeated Resource protobufs. More... | |
static bool | isEmpty (const Resource &resource) |
static bool | isPersistentVolume (const Resource &resource) |
static bool | isDisk (const Resource &resource, const Resource::DiskInfo::Source::Type &type) |
static bool | isReserved (const Resource &resource, const Option< std::string > &role=None()) |
static bool | isAllocatableTo (const Resource &resource, const std::string &role) |
static bool | isUnreserved (const Resource &resource) |
static bool | isDynamicallyReserved (const Resource &resource) |
static bool | isRevocable (const Resource &resource) |
static bool | isShared (const Resource &resource) |
static bool | isAllocatedToRoleSubtree (const Resource &resource, const std::string &role) |
static bool | isReservedToRoleSubtree (const Resource &resource, const std::string &role) |
static bool | hasRefinedReservations (const Resource &resource) |
static bool | hasResourceProvider (const Resource &resource) |
static const std::string & | reservationRole (const Resource &resource) |
static bool | shrink (Resource *resource, const Value::Scalar &target) |
template<typename Key > | |
static Resources | sum (const hashmap< Key, Resources > &_resources) |
Friends | |
std::ostream & | operator<< (std::ostream &stream, const Resource_ &resource_) |
typedef boost::indirect_iterator< boost::container::small_vector_base<Resource_Unsafe>::const_iterator> mesos::v1::Resources::const_iterator |
using mesos::v1::Resources::Resource_Unsafe = std::shared_ptr<Resource_> |
|
inline |
mesos::v1::Resources::Resources | ( | const Resource & | resource | ) |
mesos::v1::Resources::Resources | ( | Resource && | resource | ) |
mesos::v1::Resources::Resources | ( | const std::vector< Resource > & | _resources | ) |
mesos::v1::Resources::Resources | ( | std::vector< Resource > && | _resources | ) |
mesos::v1::Resources::Resources | ( | const google::protobuf::RepeatedPtrField< Resource > & | _resources | ) |
mesos::v1::Resources::Resources | ( | google::protobuf::RepeatedPtrField< Resource > && | _resources | ) |
|
default |
|
default |
Resources mesos::v1::Resources::allocatableTo | ( | const std::string & | role | ) | const |
void mesos::v1::Resources::allocate | ( | const std::string & | role | ) |
Resources mesos::v1::Resources::allocatedToRoleSubtree | ( | const std::string & | role | ) | const |
Try<Resources> mesos::v1::Resources::apply | ( | const ResourceConversion & | conversion | ) | const |
|
inline |
|
inline |
|
inline |
bool mesos::v1::Resources::contains | ( | const Resources & | that | ) | const |
bool mesos::v1::Resources::contains | ( | const Resource & | that | ) | const |
bool mesos::v1::Resources::contains | ( | const ResourceQuantities & | quantities | ) | const |
size_t mesos::v1::Resources::count | ( | const Resource & | that | ) | const |
Option<double> mesos::v1::Resources::cpus | ( | ) | const |
Resources mesos::v1::Resources::createStrippedScalarQuantity | ( | ) | const |
|
inline |
|
inline |
|
inline |
Option<Value::Ranges> mesos::v1::Resources::ephemeral_ports | ( | ) | const |
Resources mesos::v1::Resources::filter | ( | const lambda::function< bool(const Resource &)> & | predicate | ) | const |
|
static |
Parses an input JSON array into a vector of Resource objects.
Parses into a vector of Resource objects from a JSON array. Any resource that doesn't specify a role is assigned to the provided default role. See the Resource
protobuf definition for precise JSON formatting.
Example JSON: [{"name":"cpus","type":"SCALAR","scalar":{"value":8}}]
NOTE: The Resource
objects in the result vector may not be valid semantically (i.e., they may not pass Resources::validate()
). This is to allow additional handling of the parsing results in some cases.
resourcesJSON | The input JSON array. |
defaultRole | The default role. |
|
static |
Parses an input text string into a vector of Resource objects.
Parses into a vector of Resource objects from text. Any resource that doesn't specify a role is assigned to the provided default role.
Example text: name(role):value;name:value;...
NOTE: The Resource
objects in the result vector may not be valid semantically (i.e., they may not pass Resources::validate()
). This is to allow additional handling of the parsing results in some cases.
text | The input text string. |
defaultRole | The default role. |
|
static |
Parse an input string into a vector of Resource objects.
Parses into a vector of Resource objects from either JSON or plain text. If the string is well-formed JSON it is assumed to be JSON, otherwise plain text. Any resource that doesn't specify a role is assigned to the provided default role.
NOTE: The Resource
objects in the result vector may not be valid semantically (i.e., they may not pass Resources::validate()
). This is to allow additional handling of the parsing results in some cases.
Option<T> mesos::v1::Resources::get | ( | const std::string & | name | ) | const |
Resources mesos::v1::Resources::get | ( | const std::string & | name | ) | const |
Option<double> mesos::v1::Resources::gpus | ( | ) | const |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
std::set<std::string> mesos::v1::Resources::names | ( | ) | const |
Resources mesos::v1::Resources::nonRevocable | ( | ) | const |
Resources mesos::v1::Resources::nonShared | ( | ) | const |
mesos::v1::Resources::operator google::protobuf::RepeatedPtrField< Resource > | ( | ) | const |
bool mesos::v1::Resources::operator!= | ( | const Resources & | that | ) | const |
Resources mesos::v1::Resources::operator+ | ( | const Resource & | that | ) | const |
Resources mesos::v1::Resources::operator+ | ( | const Resource & | that | ) |
Resources mesos::v1::Resources::operator+ | ( | Resource && | that | ) | const |
Resources mesos::v1::Resources::operator+ | ( | Resource && | that | ) |
Resources& mesos::v1::Resources::operator+= | ( | const Resource & | that | ) |
Resources& mesos::v1::Resources::operator+= | ( | Resource && | that | ) |
Resources mesos::v1::Resources::operator- | ( | const Resource & | that | ) | const |
Resources& mesos::v1::Resources::operator-= | ( | const Resource & | that | ) |
bool mesos::v1::Resources::operator== | ( | const Resources & | that | ) | const |
|
static |
Returns a Resource with the given name, value, and role.
Parses the text and returns a Resource object with the given name, value, and role. For example, "Resource r = parse("mem", "1024", "*");".
name | The name of the Resource. |
value | The Resource's value. |
role | The role associated with the Resource. |
|
static |
Parses Resources from an input string.
Parses Resources from text in the form of a JSON array or as a simple string in the form of "name(role):value;name:value;...". i.e., this method calls fromJSON()
or fromSimpleString()
and validates the resulting vector<Resource>
before converting it to a Resources
object.
text | The input string. |
defaultRole | The default role. |
Resources mesos::v1::Resources::persistentVolumes | ( | ) | const |
Resources mesos::v1::Resources::popReservation | ( | ) | const |
Option<Value::Ranges> mesos::v1::Resources::ports | ( | ) | const |
Resources mesos::v1::Resources::pushReservation | ( | const Resource::ReservationInfo & | reservation | ) | const |
|
static |
Resources mesos::v1::Resources::reservedToRoleSubtree | ( | const std::string & | role | ) | const |
Resources mesos::v1::Resources::revocable | ( | ) | const |
Resources mesos::v1::Resources::scalars | ( | ) | const |
Resources mesos::v1::Resources::shared | ( | ) | const |
|
static |
|
inline |
|
inlinestatic |
Resources mesos::v1::Resources::toUnreserved | ( | ) | const |
std::map<std::string, Value_Type> mesos::v1::Resources::types | ( | ) | const |
void mesos::v1::Resources::unallocate | ( | ) |
Resources mesos::v1::Resources::unreserved | ( | ) | const |
Validates a Resource object.
Validates the given Resource object. Returns Error if it is not valid. A Resource object is valid if it has a name, a valid type, i.e. scalar, range, or set, has the appropriate value set, and a valid (role, reservation) pair for dynamic reservation.
resource | The input resource to be validated. |
|
static |
Validates the given repeated Resource protobufs.
Validates the given repeated Resource protobufs. Returns Error if an invalid Resource is found. A Resource object is valid if it has a name, a valid type, i.e. scalar, range, or set, has the appropriate value set, and a valid (role, reservation) pair for dynamic reservation.
TODO(jieyu): Right now, it's the same as checking each individual Resource object in the protobufs. In the future, we could add more checks that are not possible if checking each Resource object individually. For example, we could check multiple usage of an item in a set or a range, etc.
resources | The repeated Resource objects to be validated. |
|
friend |