salsa
0.7.1
|
NodeManager class. More...
#include <NodeManager.hh>
Public Member Functions | |
NodeManager () | |
virtual | ~NodeManager () |
void | print (std::string opt="") const |
void | addConsumer (std::string uuid, std::shared_ptr< Socket > s) |
void | addFeeder (std::string uuid, std::shared_ptr< Socket > s) |
void | addWorker (std::string uuid, std::shared_ptr< Socket > s) |
void | addTask (TaskInfo *taskInfo, std::string cuuid, std::string fuuid, Salsa::Job::EQueueType t=Salsa::Job::pending) |
virtual Socket * | onEnter (std::string self, std::string fromType, Message *msg, std::vector< std::string > &out) |
virtual Socket * | onExit (std::string self, Message *msg, std::vector< std::string > &out) |
virtual Socket * | onWhisper (std::string self, Message *msg, std::vector< std::string > &out) |
std::shared_ptr< Feeder > | feeder (std::string uuid) const |
std::shared_ptr< Consumer > | consumer (std::string uuid) const |
std::shared_ptr< Worker > | worker (std::string uuid) const |
Job * | job (std::string uuid) |
TaskPool * | taskPool () |
Get NM's task pool. More... | |
virtual void | addTaskSlot () |
bool | hasJobs () const |
virtual bool | terminateFinishedJobs () |
uint64_t | finishedJobTimeout () const |
Returns finished job timeout. | |
void | finishedJobTimeout (uint64_t t) |
Sets finished job timeout. | |
int32_t | nSlots (double mult=1.0) const |
void | jobs (std::string clientUUID, std::vector< std::string > &jobs) const |
TaskInfo * | getNextTask () |
virtual void | resultTask (TaskInfo *task) |
virtual void | resultTaskToExternal (Job *, TaskInfo *) |
Handle return of task and send it to external client. | |
virtual void | noMoreTasks (std::string jobUUID) |
virtual bool | haveMoreTasks () |
virtual bool | haveMoreTasks (std::string jobUUID) |
virtual void | runTask (TaskState *ts, std::string wk, std::string upstream)=0 |
Run task interface. | |
virtual void | terminateJob (std::string uuid) |
virtual void | terminateAllJobs (bool finishedonly=false) |
virtual bool | handleTaskPool (void *p) |
virtual bool | sendWhisper (Socket *s, std::string to, std::vector< std::string > &v) |
virtual void | publisher (Publisher *p) |
virtual Publisher * | publisher () const |
virtual bool | publish (std::string id, bool force=false) const |
void | clusterAlias (std::string n) |
Sets Cluster alias. | |
std::string | clusterAlias () |
Returns Cluster alias. | |
Static Public Member Functions | |
static std::shared_ptr< spdlog::logger > | getConsoleOutput () |
Get console output. | |
static void | setConsoleLevel (spdlog::level::level_enum level) |
Sets console log level. | |
Protected Attributes | |
std::string | mClusterAlias {"local"} |
Cluster alias. | |
std::map< std::string, Job * > | mJobs {} |
List of jobs. | |
std::vector< std::string > | mActiveJobs {} |
List of active jobs. | |
std::vector< std::string > | mFinishedJobs {} |
List of finished jobs. | |
uint64_t | mFinishedJobTimeout |
Finished job timeout in seconds. | |
std::map< std::string, std::shared_ptr< Worker > > | mWorkers {} |
List of Workers. | |
std::map< std::string, std::shared_ptr< Consumer > > | mConsumers {} |
List of Consumers. | |
std::map< std::string, std::shared_ptr< Feeder > > | mFeeders {} |
List of Feeders. | |
TaskPool * | mpTaskPool = nullptr |
Task pool. | |
Publisher * | mpPublisher = nullptr |
Publisher. | |
Static Private Attributes | |
static std::shared_ptr< spdlog::logger > | mspConsoleLogger = spdlog::stdout_color_mt("salsa") |
Pointer to spd logger. | |
NodeManager class.
Definition at line 22 of file NodeManager.hh.
Salsa::NodeManager::NodeManager | ( | ) |
Constructor
Definition at line 4 of file NodeManager.cc.
|
virtual |
Destructor
Definition at line 14 of file NodeManager.cc.
References job(), mJobs, mpPublisher, mpTaskPool, and Salsa::TaskPool::terminateJob().
void Salsa::NodeManager::addConsumer | ( | std::string | uuid, |
std::shared_ptr< Socket > | s | ||
) |
Add consumer
Definition at line 57 of file NodeManager.cc.
References mConsumers.
Referenced by Salsa::NodeZyre::init().
void Salsa::NodeManager::addFeeder | ( | std::string | uuid, |
std::shared_ptr< Socket > | s | ||
) |
Add feeder
Definition at line 66 of file NodeManager.cc.
References mFeeders.
Referenced by Salsa::NodeZyre::init().
void Salsa::NodeManager::addTask | ( | TaskInfo * | taskInfo, |
std::string | cuuid, | ||
std::string | fuuid, | ||
Salsa::Job::EQueueType | t = Salsa::Job::pending |
||
) |
Adds task
subscribe to all clients
Definition at line 228 of file NodeManager.cc.
References Salsa::Job::addTask(), Salsa::Job::consumer(), Salsa::Job::feeder(), feeder(), mActiveJobs, mFeeders, and mJobs.
Referenced by Salsa::NodeZyre::handleExternalZmq(), Salsa::Consumer::onWhisper(), and Salsa::Worker::onWhisper().
|
virtual |
Reserve task slot
Reimplemented in Salsa::NodeManagerZyre.
Definition at line 495 of file NodeManager.cc.
References mpTaskPool.
Referenced by Salsa::Worker::Worker().
void Salsa::NodeManager::addWorker | ( | std::string | uuid, |
std::shared_ptr< Socket > | s | ||
) |
Add worker
Definition at line 75 of file NodeManager.cc.
References mWorkers.
Referenced by Salsa::NodeZyre::init().
std::shared_ptr< Consumer > Salsa::NodeManager::consumer | ( | std::string | uuid | ) | const |
Returns consumer /param uuid UUID
Definition at line 457 of file NodeManager.cc.
References mConsumers.
Referenced by onEnter(), Salsa::Feeder::onExit(), onExit(), Salsa::Feeder::onWhisper(), onWhisper(), and resultTask().
std::shared_ptr< Feeder > Salsa::NodeManager::feeder | ( | std::string | uuid | ) | const |
Returns uuid is feeder /param uuid UUID
Definition at line 443 of file NodeManager.cc.
References mFeeders.
Referenced by addTask(), Salsa::NodeZyre::init(), nSlots(), onEnter(), onExit(), onWhisper(), and publish().
TaskInfo * Salsa::NodeManager::getNextTask | ( | ) |
Return Next task from job
Definition at line 260 of file NodeManager.cc.
References mActiveJobs, and mJobs.
Referenced by Salsa::Feeder::onWhisper().
|
virtual |
Handle task pool
Reimplemented in Salsa::NodeManagerZyre.
Definition at line 505 of file NodeManager.cc.
bool Salsa::NodeManager::hasJobs | ( | ) | const |
Returns if jobs are active
Definition at line 521 of file NodeManager.cc.
References mActiveJobs.
Referenced by Salsa::Feeder::onEnter().
|
virtual |
Sets no more tasks to any job
Definition at line 567 of file NodeManager.cc.
References job(), mActiveJobs, and mJobs.
Referenced by Salsa::Feeder::onExit().
|
virtual |
Sets no more tasks to job with jobuuid
Definition at line 595 of file NodeManager.cc.
References mJobs.
Job * Salsa::NodeManager::job | ( | std::string | uuid | ) |
Returns job /param uuid UUID
Definition at line 482 of file NodeManager.cc.
References mJobs.
Referenced by Salsa::NodeZyre::handleExternalZmq(), Salsa::TaskPool::handlePipe(), haveMoreTasks(), Salsa::Feeder::onExit(), Salsa::Feeder::onWhisper(), publish(), resultTask(), Salsa::NodeManagerZyre::resultTaskToExternal(), terminateAllJobs(), terminateFinishedJobs(), Salsa::Feeder::terminateJob(), and ~NodeManager().
void Salsa::NodeManager::jobs | ( | std::string | clientUUID, |
std::vector< std::string > & | jobs | ||
) | const |
Returns list of jobs
Definition at line 529 of file NodeManager.cc.
References mJobs.
Referenced by Salsa::Consumer::onExit().
|
virtual |
Sets no more tasks to job with jobuuid
Definition at line 554 of file NodeManager.cc.
Referenced by Salsa::Consumer::onWhisper().
int32_t Salsa::NodeManager::nSlots | ( | double | mult = 1.0 | ) | const |
Returns numer of slots
Definition at line 541 of file NodeManager.cc.
References feeder(), and mFeeders.
Referenced by Salsa::NodeZyre::handleExternalZmq(), Salsa::Consumer::onWhisper(), and resultTask().
|
virtual |
On ENTER event
Reimplemented in Salsa::NodeManagerZyre.
Definition at line 84 of file NodeManager.cc.
References consumer(), feeder(), Salsa::Message::uuid(), and worker().
Referenced by Salsa::NodeManagerZyre::onEnter().
|
virtual |
On EXIT event
Reimplemented in Salsa::NodeManagerZyre.
Definition at line 149 of file NodeManager.cc.
References consumer(), feeder(), Salsa::Message::uuid(), and worker().
Referenced by Salsa::NodeManagerZyre::onExit().
|
virtual |
On WHISPER event
Reimplemented in Salsa::NodeManagerZyre.
Definition at line 187 of file NodeManager.cc.
References consumer(), feeder(), Salsa::Message::uuid(), and worker().
Referenced by Salsa::NodeManagerZyre::onWhisper().
void Salsa::NodeManager::print | ( | std::string | opt = "" | ) | const |
Prints NodeManager information
Definition at line 32 of file NodeManager.cc.
References mConsumers, mFeeders, mJobs, mpTaskPool, mWorkers, and Salsa::TaskPool::print().
Referenced by Salsa::NodeZyre::handleExternalZmq(), Salsa::Feeder::onExit(), Salsa::Feeder::onWhisper(), resultTask(), and terminateJob().
|
virtual |
Publishes node manager state
Definition at line 625 of file NodeManager.cc.
References Salsa::Job::changed(), feeder(), Salsa::Job::isJustFinished(), job(), Salsa::Job::json(), mClusterAlias, mJobs, mpPublisher, and Salsa::Publisher::publish().
Referenced by Salsa::NodeZyre::exec(), and Salsa::NodeZyre::handleExternalZmq().
|
virtual |
|
virtual |
Sets publisher
Definition at line 609 of file NodeManager.cc.
References mpPublisher.
Referenced by Salsa::NodeZyre::init().
|
virtual |
Handle result of pTask
Moving to finished jobs. They will be removed after some inactivity time
Definition at line 288 of file NodeManager.cc.
References Salsa::Job::consumer(), consumer(), Salsa::Job::feeder(), Salsa::Job::haveMoreTasks(), Salsa::Job::isFinished(), Salsa::Job::isTaskInQueue(), job(), mFinishedJobs, Salsa::Job::moveTask(), nSlots(), print(), Salsa::Job::removeTask(), resultTaskToExternal(), sendWhisper(), Salsa::Job::size(), and Salsa::Job::uuid().
Referenced by Salsa::Feeder::onWhisper().
|
virtual |
Sends message
Reimplemented in Salsa::NodeManagerZyre.
Definition at line 219 of file NodeManager.cc.
Referenced by Salsa::TaskPool::handlePipe(), Salsa::Feeder::onExit(), Salsa::Feeder::onWhisper(), resultTask(), Salsa::Feeder::subscribe(), and Salsa::Feeder::terminateJob().
TaskPool * Salsa::NodeManager::taskPool | ( | ) |
Get NM's task pool.
Returns task pool
Definition at line 513 of file NodeManager.cc.
References mpTaskPool.
Referenced by Salsa::Worker::onWhisper().
|
virtual |
Terminate all jobs
Definition at line 422 of file NodeManager.cc.
References job(), mFinishedJobs, mJobs, and terminateJob().
Referenced by Salsa::NodeZyre::handleExternalZmq().
|
virtual |
Clear finished jobs
Definition at line 391 of file NodeManager.cc.
References job(), mFinishedJobs, mFinishedJobTimeout, and terminateJob().
Referenced by Salsa::NodeZyre::exec().
|
virtual |
Cleans job
Definition at line 362 of file NodeManager.cc.
References mFeeders, mFinishedJobs, mJobs, mpTaskPool, print(), and Salsa::TaskPool::terminateJob().
Referenced by Salsa::NodeZyre::handleExternalZmq(), Salsa::Consumer::onExit(), Salsa::Worker::onWhisper(), terminateAllJobs(), and terminateFinishedJobs().
std::shared_ptr< Worker > Salsa::NodeManager::worker | ( | std::string | uuid | ) | const |
Returns worker /param uuid UUID
Definition at line 469 of file NodeManager.cc.
References mWorkers.
Referenced by Salsa::TaskPool::handlePipe(), Salsa::NodeZyre::init(), onEnter(), onExit(), and onWhisper().