GridComputing
Job Management in Grid Computing
|
GridManager Class. More...
#include <gridmanager.h>
Public Types | |
typedef std::set< User *, IdLess< User > > | UserSet |
typedef std::set< Machine *, IdLess< Machine > > | MachineSet |
typedef std::set < PriorityMachine *, IdLess < PriorityMachine > > | PriorityMachineSet |
Public Member Functions | |
GridManager () | |
Constructor. | |
~GridManager () | |
Destructor. | |
uint | AddUser (User *user) |
Add a User. | |
uint | AddMachine (Machine *machine) |
Add a Machine. | |
uint | AddPriorityMachine (PriorityMachine *pMachine) |
Add a Priority Machine. | |
bool | RemoveUser (const User *user) |
Removes the given user. | |
bool | RemoveUser (uint id) |
Removes the user with the given ID. | |
bool | RemoveMachine (const Machine *machine) |
Removes the given machine. | |
bool | RemoveMachine (uint id) |
Removes the machine with the given ID. | |
bool | RemovePriorityMachine (const PriorityMachine *machine) |
Removes the given priority machine. | |
bool | RemovePriorityMachine (uint id) |
Removes the priority machine with the given ID. | |
User * | GetUser (uint id) const |
Returns the user with the given ID. | |
uint | GetNumberOfUsers () const |
Returns the number of existing users. | |
Machine * | GetMachine (uint id) const |
Returns the machine with the given ID. | |
PriorityMachine * | GetPriorityMachine (uint id) const |
Returns the priority machine with the given ID. | |
uint | GetNumberOfMachines () const |
Returns the number of existing machines. | |
uint | GetNumberOfPriorityMachines () const |
Returns the number of existing priority machines. | |
bool | Save (ByteBuffer &bb) const override |
Saves the information of the instance of the class to the given ByteBuffer. | |
void | Update (uint32 diff) |
Update function that updates all jobs and machine. It removes finished jobs and updates the respective machines. | |
bool | AddJobByUser (int userId, Job *job) |
Adds the given job by the user with the given Id. | |
bool | AddJobByUser (User *user, Job *job) |
Adds the given job to the given user. | |
bool | RemoveMachineJob (Machine *machine, uint jobId) |
Removes the given job from the given machine. | |
uint | GetNumberOfJobs () const |
Returns the number of existing jobs. | |
template<class T > | |
std::vector< const T * > | ApplyPredicate (std::function< bool(const T *)> predicate) const |
Applies the given predicate to the containers of the instance of the class based in the type and returns a vector with the values that meet the requirements. | |
template<class T , class R > | |
std::vector< R > | ApplySelector (std::function< R(const T *)> selector, std::function< bool(const T *)> predicate) const |
Uses ApplyPredicate with the given predicate and then selects a certain element of each object in the vector returned by ApplyPredicate. | |
template<class T , class R > | |
std::vector< R > | ApplySelector (std::function< R(const T *)> selector) const |
Selects a certain element of each object in the vector of T*. | |
const IdleUserContainer & | GetIdleUsers () const |
template<> | |
std::vector< const Job * > | ApplyPredicate (std::function< bool(const Job *)> predicate) const |
template<> | |
std::vector< const User * > | ApplyPredicate (std::function< bool(const User *)> predicate) const |
template<> | |
std::vector< const IdleUser * > | ApplyPredicate (std::function< bool(const IdleUser *)> predicate) const |
template<> | |
std::vector< const Machine * > | ApplyPredicate (std::function< bool(const Machine *)> predicate) const |
template<> | |
std::vector< const PriorityMachine * > | ApplyPredicate (std::function< bool(const PriorityMachine *)> predicate) const |
Static Public Member Functions | |
static GridManager * | Load (ByteBuffer &bb) |
Returns a pointer to a GridManager loaded from the given ByteBuffer. | |
static Menu * | GetMenu () |
Returns the menu for the GridManager class. | |
Private Member Functions | |
bool | AddJob (Job *job) |
Searches for a available machine and adds the given job to it. | |
GridManager (const GridManager &) | |
Copy constructor. Private to avoid copies of a GridManager instance. | |
GridManager & | operator= (GridManager const &) |
Assignment operator. Private to avoid copies of a GridManager instance. | |
Private Attributes | |
UserSet | _users |
Container that saves users. | |
MachineSet | _machines |
Container that saves machines. | |
PriorityMachineSet | _priorityMachines |
Container that saves priority machines. | |
std::queue< Job * > | _waitingJobs |
Container that stores waiting jobs. | |
IdleUserContainer | _idleUsers |
Container used to store users that are removed. | |
Static Private Attributes | |
static uint | _lastUserId = 0 |
Last User Id added. | |
static uint | _lastMachineId = 0 |
Last Machine Id added. | |
static Menu * | _menu = Loader<Menu>("gridManagerMenu.txt").Load() |
Menu associated with the GridManager class. | |
GridManager Class.
The GridManager class has information about users and machines. It enables the user of this class to Add, Remove and Get and Search Users and Machines, and has an interface to add Jobs to a User.
typedef std::set<Machine*, IdLess<Machine> > GridManager::MachineSet |
typedef std::set<PriorityMachine*, IdLess<PriorityMachine> > GridManager::PriorityMachineSet |
typedef std::set<User*, IdLess<User> > GridManager::UserSet |
GridManager::GridManager | ( | ) |
Constructor.
GridManager::~GridManager | ( | ) |
Destructor.
|
private |
Copy constructor. Private to avoid copies of a GridManager instance.
|
private |
Searches for a available machine and adds the given job to it.
job | to be added. |
bool GridManager::AddJobByUser | ( | int | userId, |
Job * | job | ||
) |
Adds the given job by the user with the given Id.
userId | Id of the user that wants to create the job. |
job | to be added. |
Adds the given job to the given user.
user | pointer to the user that created the job. |
job | to be added. |
Add a Machine.
machine | a pointer to the machine to be added. |
uint32 GridManager::AddPriorityMachine | ( | PriorityMachine * | pMachine | ) |
Add a Priority Machine.
pMachine | a pointer to the priority machine to be added. |
std::vector<const T*> GridManager::ApplyPredicate | ( | std::function< bool(const T *)> | predicate | ) | const |
Applies the given predicate to the containers of the instance of the class based in the type and returns a vector with the values that meet the requirements.
predicate | to evaluate the data: unary function that returns a bool and accepts a T* as argument. |
std::vector<const Job*> GridManager::ApplyPredicate | ( | std::function< bool(const Job *)> | predicate | ) | const |
std::vector<const User*> GridManager::ApplyPredicate | ( | std::function< bool(const User *)> | predicate | ) | const |
std::vector<const IdleUser*> GridManager::ApplyPredicate | ( | std::function< bool(const IdleUser *)> | predicate | ) | const |
std::vector<const Machine*> GridManager::ApplyPredicate | ( | std::function< bool(const Machine *)> | predicate | ) | const |
std::vector<const PriorityMachine*> GridManager::ApplyPredicate | ( | std::function< bool(const PriorityMachine *)> | predicate | ) | const |
std::vector< R > GridManager::ApplySelector | ( | std::function< R(const T *)> | selector, |
std::function< bool(const T *)> | predicate | ||
) | const |
Uses ApplyPredicate with the given predicate and then selects a certain element of each object in the vector returned by ApplyPredicate.
selector | to retrieve an element from the data: unary function that returns R and accepts a T* as argument. |
predicate | to evaluate the data: unary function that returns a bool and accepts a T* as argument. Default value applies no restrictions. |
std::vector< R > GridManager::ApplySelector | ( | std::function< R(const T *)> | selector | ) | const |
const IdleUserContainer& GridManager::GetIdleUsers | ( | ) | const |
Returns the machine with the given ID.
id | of the machine. |
|
static |
Returns the menu for the GridManager class.
uint GridManager::GetNumberOfJobs | ( | ) | const |
Returns the number of existing jobs.
uint GridManager::GetNumberOfMachines | ( | ) | const |
Returns the number of existing machines.
uint GridManager::GetNumberOfPriorityMachines | ( | ) | const |
Returns the number of existing priority machines.
uint GridManager::GetNumberOfUsers | ( | ) | const |
Returns the number of existing users.
PriorityMachine * GridManager::GetPriorityMachine | ( | uint | id | ) | const |
Returns the priority machine with the given ID.
id | of the priority machine. |
Returns the user with the given ID.
id | of the user. |
|
static |
Returns a pointer to a GridManager loaded from the given ByteBuffer.
bb | source of the data. |
|
private |
Assignment operator. Private to avoid copies of a GridManager instance.
bool GridManager::RemoveMachine | ( | const Machine * | machine | ) |
Removes the given machine.
machine | a pointer to the machine to be removed. |
bool GridManager::RemoveMachine | ( | uint | id | ) |
Removes the machine with the given ID.
id | of the machine to be removed. |
Removes the given job from the given machine.
machine | pointer to the machine that contains the job. |
jobId | id of the job to be removed. |
bool GridManager::RemovePriorityMachine | ( | const PriorityMachine * | machine | ) |
Removes the given priority machine.
machine | a pointer to the priority machine to be removed. |
bool GridManager::RemovePriorityMachine | ( | uint | id | ) |
Removes the priority machine with the given ID.
id | of the priority machine to be removed. |
bool GridManager::RemoveUser | ( | const User * | user | ) |
Removes the given user.
user | a pointer to the user to be removed. |
bool GridManager::RemoveUser | ( | uint | id | ) |
Removes the user with the given ID.
id | of the user to be removed. |
|
overridevirtual |
Saves the information of the instance of the class to the given ByteBuffer.
bb | destination of the data. |
Implements ISave.
|
virtual |
Update function that updates all jobs and machine. It removes finished jobs and updates the respective machines.
diff | time that has passed since last update. |
Implements IUpdate.
|
private |
Container used to store users that are removed.
|
staticprivate |
Last Machine Id added.
|
private |
Container that saves machines.
Menu associated with the GridManager class.
|
private |
Container that saves priority machines.
|
private |
Container that saves users.
|
private |
Container that stores waiting jobs.