Ignore:
Timestamp:
Apr 5, 2018, 1:19:33 PM (7 years ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
AutomationFragmentation_failures, Candidate_v1.6.1, ChemicalSpaceEvaluator, Enhanced_StructuralOptimization_continued, Exclude_Hydrogens_annealWithBondGraph, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_contraction-expansion, Gui_displays_atomic_force_velocity, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, PythonUI_with_named_parameters, StoppableMakroAction, TremoloParser_IncreasedPrecision
Children:
456f19
Parents:
1181a3
git-author:
Frederik Heber <frederik.heber@…> (04/05/18 12:24:11)
git-committer:
Frederik Heber <frederik.heber@…> (04/05/18 13:19:33)
Message:

Added GetNumberWorkersOperation, Controller returns number of workers.

  • TEST: Added regression test on this new functionality.
Location:
ThirdParty/JobMarket/src/JobMarket
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • ThirdParty/JobMarket/src/JobMarket/Controller/FragmentController.cpp

    r1181a3 r0542e2  
    3131#include "Operations/Controllers/CheckResultsOperation.hpp"
    3232#include "Operations/Controllers/GetNextJobIdOperation.hpp"
     33#include "Operations/Controllers/GetNumberWorkersOperation.hpp"
    3334#include "Operations/Controllers/ReceiveResultsOperation.hpp"
    3435#include "Operations/Controllers/RemoveAllJobsOperation.hpp"
     
    5657  Commands.registerInstance(new CheckResultsOperation(connection_, AsyncOperation::NoOpCallback, failed));
    5758  Commands.registerInstance(new GetNextJobIdOperation(connection_, AsyncOperation::NoOpCallback, failed));
     59  Commands.registerInstance(new GetNumberWorkersOperation(connection_, AsyncOperation::NoOpCallback, failed));
    5860  Commands.registerInstance(new ReceiveResultsOperation(connection_, AsyncOperation::NoOpCallback, failed));
    5961  Commands.registerInstance(new RemoveAllJobsOperation(connection_));
     
    162164}
    163165
     166/** Obtains number of workers enrolled at server
     167 *
     168 * @param host address of server
     169 * @param service port/service of server
     170 */
     171void FragmentController::checkEnrolledWorkers(
     172    const std::string &host,
     173    const std::string &service)
     174{
     175  GetNumberWorkersOperation *checkres = static_cast<GetNumberWorkersOperation *>(
     176      Commands.getByName("numberworkers"));
     177  (*checkres)(host, service);
     178}
     179
    164180/** Return scheduled and done jobs.
    165181 *
     
    173189  const size_t presentJobs = checkres->getPresentJobs();
    174190  return make_pair(presentJobs, doneJobs);
     191}
     192
     193/** Return scheduled and done jobs.
     194 *
     195 * @return number of workers in certain states enrolled in server
     196 */
     197std::vector<size_t> FragmentController::getNumberOfWorkers()
     198{
     199  const GetNumberWorkersOperation * const checkres = static_cast<const GetNumberWorkersOperation *>(
     200      Commands.getByName("numberworkers"));
     201  return checkres->get();
    175202}
    176203
  • ThirdParty/JobMarket/src/JobMarket/Controller/FragmentController.hpp

    r1181a3 r0542e2  
    4949  void checkResults(const std::string &host, const std::string &service);
    5050  std::pair<size_t, size_t> getJobStatus() const;
     51  void checkEnrolledWorkers(const std::string &host, const std::string &service);
     52  std::vector<size_t> getNumberOfWorkers();
    5153  void removeWaitingResults(const std::string &host, const std::string &service);
    5254  void removeWaitingJobs(const std::string &host, const std::string &service);
  • ThirdParty/JobMarket/src/JobMarket/Controller/controller_main.cpp

    r1181a3 r0542e2  
    5757}
    5858
     59/** Print the status of workers
     60 *
     61 * @param number_workers vector of workers in certain states (busy, idle, ...)
     62 */
     63void printNumberWorkers(const std::vector<size_t> &number_workers)
     64{
     65  ASSERT(number_workers.size() == 2,
     66      "printNumberWorkers() - vector of worker numbers is not of size 2.");
     67  LOG(1, "INFO: " << number_workers[0] << " are busy and "
     68      << number_workers[1] << " are idle.");
     69}
     70
    5971inline std::vector<std::string> getListOfCommands(const ControllerCommandRegistry &ControllerCommands)
    6072{
     
    96108        (boost::bind(&printJobStatus,
    97109            boost::bind(&FragmentController::getJobStatus, boost::ref(controller))))
     110      ));
     111  registrator(new ControllerCommand("numberworkers",
     112      boost::assign::list_of< ControllerCommand::commands_t >
     113        (boost::bind(&FragmentController::checkEnrolledWorkers,
     114            boost::ref(controller), boost::cref(ControllerInfo->server), boost::cref(ControllerInfo->serverport)))
     115        (boost::bind(&printNumberWorkers,
     116            boost::bind(&FragmentController::getNumberOfWorkers, boost::ref(controller))))
    98117      ));
    99118  registrator(new ControllerCommand("removeall",
  • ThirdParty/JobMarket/src/JobMarket/ControllerChoices.hpp

    r1181a3 r0542e2  
    2424  EmptyJobQueue,
    2525  RemoveAll,
    26   ShutdownControllerSocket
     26  ShutdownControllerSocket,
     27  NumberOfWorkers
    2728};
    2829
  • ThirdParty/JobMarket/src/JobMarket/FragmentScheduler.hpp

    r1181a3 r0542e2  
    205205    void handle_SendResults(const boost::system::error_code& e, connection_ptr conn);
    206206
     207    /// Controller callback function when result are to be sent.
     208    void handle_SendNumberWorkers(const boost::system::error_code& e, connection_ptr conn);
     209
    207210    /// Controller callback function when results has been sent.
    208211    void handle_finishSendResults(const boost::system::error_code& e, connection_ptr conn);
  • ThirdParty/JobMarket/src/JobMarket/FragmentScheduler_ControllerListener.cpp

    r1181a3 r0542e2  
    2525
    2626#include <algorithm>
     27#include <boost/assign.hpp>
    2728#include <boost/bind.hpp>
    2829#include <sstream>
     
    4344
    4445#include "JobMarket/FragmentScheduler.hpp"
     46
     47using namespace boost::assign;
    4548
    4649/** Handle a new controller connection.
     
    138141    {
    139142      removeallWorkers();
     143      break;
     144    }
     145    case NumberOfWorkers:
     146    {
     147      LOG(1, "INFO: Sending total number of workers to a controller ...");
     148      std::vector<size_t> number_workers;
     149      number_workers += pool.getNoBusyWorkers();
     150      number_workers += pool.getNoIdleWorkers();
     151      conn->async_write(number_workers,
     152        boost::bind(&FragmentScheduler::ControllerListener_t::handle_SendNumberWorkers, this,
     153        boost::asio::placeholders::error, conn));
    140154      break;
    141155    }
     
    346360  LOG(1, "INFO: Results have been sent.");
    347361}
     362
     363/** Controller callback function when number of workers has been sent.
     364 *
     365 * \param e error code if something went wrong
     366 * \param conn reference with the connection
     367 */
     368void FragmentScheduler::ControllerListener_t::handle_SendNumberWorkers(const boost::system::error_code& e, connection_ptr conn)
     369{
     370  DEBUG_FUNCTION_ENTRYEXIT
     371  // do nothing
     372  LOG(1, "INFO: Number of workers have been sent.");
     373}
  • ThirdParty/JobMarket/src/JobMarket/Makefile.am

    r1181a3 r0542e2  
    4040        Operations/Controllers/CheckResultsOperation.cpp \
    4141        Operations/Controllers/GetNextJobIdOperation.cpp \
     42        Operations/Controllers/GetNumberWorkersOperation.cpp \
    4243        Operations/Controllers/ReceiveResultsOperation.cpp \
    4344        Operations/Controllers/RemoveAllJobsOperation.cpp \
     
    6364        Operations/Controllers/CheckResultsOperation.hpp \
    6465        Operations/Controllers/GetNextJobIdOperation.hpp \
     66        Operations/Controllers/GetNumberWorkersOperation.hpp \
    6567        Operations/Controllers/ReceiveResultsOperation.hpp \
    6668        Operations/Controllers/RemoveAllJobsOperation.hpp \
Note: See TracChangeset for help on using the changeset viewer.