Apache Mesos
Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
mesos::v1::Resources Class Reference

#include <resources.hpp>

Public Types

using Resource_Unsafe = std::shared_ptr< Resource_ >
 
typedef boost::indirect_iterator< boost::container::small_vector_base< Resource_Unsafe >::const_iteratorconst_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
 
Resourcesoperator= (const Resources &that)
 
Resourcesoperator= (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, Resourcesreservations () 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, Resourcesallocations () const
 
Resources pushReservation (const Resource::ReservationInfo &reservation) const
 
Resources popReservation () const
 
Resources toUnreserved () const
 
Resources createStrippedScalarQuantity () const
 
Option< Resourcesfind (const Resources &targets) const
 
Try< Resourcesapply (const ResourceConversion &conversion) const
 
Try< Resourcesapply (const Offer::Operation &operation) const
 
template<typename Iterable >
Try< Resourcesapply (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< Bytesmem () const
 
Option< Bytesdisk () 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)&&
 
Resourcesoperator+= (const Resource &that)
 
Resourcesoperator+= (Resource &&that)
 
Resources operator+ (const Resources &that) const &
 
Resources operator+ (const Resources &that)&&
 
Resources operator+ (Resources &&that) const &
 
Resources operator+ (Resources &&that)&&
 
Resourcesoperator+= (const Resources &that)
 
Resourcesoperator+= (Resources &&that)
 
Resources operator- (const Resource &that) const
 
Resources operator- (const Resources &that) const
 
Resourcesoperator-= (const Resource &that)
 
Resourcesoperator-= (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< Resourcesparse (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< Errorvalidate (const Resource &resource)
 Validates a Resource object. More...
 
static Option< Errorvalidate (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_)
 

Member Typedef Documentation

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_>

Constructor & Destructor Documentation

mesos::v1::Resources::Resources ( )
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)
mesos::v1::Resources::Resources ( const Resources that)
default
mesos::v1::Resources::Resources ( Resources &&  that)
default

Member Function Documentation

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
hashmap<std::string, Resources> mesos::v1::Resources::allocations ( ) const
Try<Resources> mesos::v1::Resources::apply ( const ResourceConversion conversion) const
Try<Resources> mesos::v1::Resources::apply ( const Offer::Operation &  operation) const
template<typename Iterable >
Try<Resources> mesos::v1::Resources::apply ( const Iterable &  iterable) const
inline
const_iterator mesos::v1::Resources::begin ( )
inline
const_iterator mesos::v1::Resources::begin ( ) const
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
Option<Bytes> mesos::v1::Resources::disk ( ) const
bool mesos::v1::Resources::empty ( ) const
inline
const_iterator mesos::v1::Resources::end ( )
inline
const_iterator mesos::v1::Resources::end ( ) const
inline
Option<Value::Ranges> mesos::v1::Resources::ephemeral_ports ( ) const
Resources mesos::v1::Resources::filter ( const lambda::function< bool(const Resource &)> &  predicate) const
Option<Resources> mesos::v1::Resources::find ( const Resources targets) const
static Try<std::vector<Resource> > mesos::v1::Resources::fromJSON ( const JSON::Array resourcesJSON,
const std::string &  defaultRole = "*" 
)
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.

Parameters
resourcesJSONThe input JSON array.
defaultRoleThe default role.
Returns
A Try which contains the parsed vector of Resource objects if parsing was successful, or an Error otherwise.
static Try<std::vector<Resource> > mesos::v1::Resources::fromSimpleString ( const std::string &  text,
const std::string &  defaultRole = "*" 
)
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.

Parameters
textThe input text string.
defaultRoleThe default role.
Returns
A Try which contains the parsed vector of Resource objects if parsing was successful, or an Error otherwise.
static Try<std::vector<Resource> > mesos::v1::Resources::fromString ( const std::string &  text,
const std::string &  defaultRole = "*" 
)
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.

template<typename T >
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 bool mesos::v1::Resources::hasRefinedReservations ( const Resource &  resource)
static
static bool mesos::v1::Resources::hasResourceProvider ( const Resource &  resource)
static
static bool mesos::v1::Resources::isAllocatableTo ( const Resource &  resource,
const std::string &  role 
)
static
static bool mesos::v1::Resources::isAllocatedToRoleSubtree ( const Resource &  resource,
const std::string &  role 
)
static
static bool mesos::v1::Resources::isDisk ( const Resource &  resource,
const Resource::DiskInfo::Source::Type &  type 
)
static
static bool mesos::v1::Resources::isDynamicallyReserved ( const Resource &  resource)
static
static bool mesos::v1::Resources::isEmpty ( const Resource &  resource)
static
static bool mesos::v1::Resources::isPersistentVolume ( const Resource &  resource)
static
static bool mesos::v1::Resources::isReserved ( const Resource &  resource,
const Option< std::string > &  role = None() 
)
static
static bool mesos::v1::Resources::isReservedToRoleSubtree ( const Resource &  resource,
const std::string &  role 
)
static
static bool mesos::v1::Resources::isRevocable ( const Resource &  resource)
static
static bool mesos::v1::Resources::isShared ( const Resource &  resource)
static
static bool mesos::v1::Resources::isUnreserved ( const Resource &  resource)
static
Option<Bytes> mesos::v1::Resources::mem ( ) const
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 Resources that) const
Resources mesos::v1::Resources::operator+ ( const Resources that)
Resources mesos::v1::Resources::operator+ ( Resources &&  that) const
Resources mesos::v1::Resources::operator+ ( Resources &&  that)
Resources& mesos::v1::Resources::operator+= ( const Resource &  that)
Resources& mesos::v1::Resources::operator+= ( Resource &&  that)
Resources& mesos::v1::Resources::operator+= ( const Resources that)
Resources& mesos::v1::Resources::operator+= ( Resources &&  that)
Resources mesos::v1::Resources::operator- ( const Resource &  that) const
Resources mesos::v1::Resources::operator- ( const Resources that) const
Resources& mesos::v1::Resources::operator-= ( const Resource &  that)
Resources& mesos::v1::Resources::operator-= ( const Resources that)
Resources& mesos::v1::Resources::operator= ( const Resources that)
inline
Resources& mesos::v1::Resources::operator= ( Resources &&  that)
inline
bool mesos::v1::Resources::operator== ( const Resources that) const
static Try<Resource> mesos::v1::Resources::parse ( const std::string &  name,
const std::string &  value,
const std::string &  role 
)
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", "*");".

Parameters
nameThe name of the Resource.
valueThe Resource's value.
roleThe role associated with the Resource.
Returns
A Try which contains the parsed Resource if parsing was successful, or an Error otherwise.
static Try<Resources> mesos::v1::Resources::parse ( const std::string &  text,
const std::string &  defaultRole = "*" 
)
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.

Parameters
textThe input string.
defaultRoleThe default role.
Returns
A Try which contains the parsed Resources if parsing was successful, or an Error otherwise.
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 const std::string& mesos::v1::Resources::reservationRole ( const Resource &  resource)
static
hashmap<std::string, Resources> mesos::v1::Resources::reservations ( ) const
Resources mesos::v1::Resources::reserved ( const Option< std::string > &  role = None()) const
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 bool mesos::v1::Resources::shrink ( Resource *  resource,
const Value::Scalar &  target 
)
static
size_t mesos::v1::Resources::size ( ) const
inline
template<typename Key >
static Resources mesos::v1::Resources::sum ( const hashmap< Key, Resources > &  _resources)
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
static Option<Error> mesos::v1::Resources::validate ( const Resource &  resource)
static

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.

Parameters
resourceThe input resource to be validated.
Returns
An Option which contains None() if the validation was successful, or an Error if not.
static Option<Error> mesos::v1::Resources::validate ( const google::protobuf::RepeatedPtrField< Resource > &  resources)
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.

Parameters
resourcesThe repeated Resource objects to be validated.
Returns
An Option which contains None() if the validation was successful, or an Error if not.

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  stream,
const Resource_ &  resource_ 
)
friend

The documentation for this class was generated from the following file: