Changeset 0196c6 for src


Ignore:
Timestamp:
May 4, 2012, 2:19:07 PM (13 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
dba6d1
Parents:
e70b9d
git-author:
Frederik Heber <heber@…> (12/09/11 20:11:50)
git-committer:
Frederik Heber <heber@…> (05/04/12 14:19:07)
Message:

Added Shutdown as choice to ControllerChoices.

  • new helper app Shutdowner that shuts down Server.
  • TESTFIX: Changed regression test Fragmentation/Automation where now Shutdowner is uses instead of Jobadder with 0 jobs to power down controller socket.
Location:
src/Fragmentation/Automation
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/Automation/ControllerChoices.hpp

    re70b9d r0196c6  
    2020  ReceiveJobs,
    2121  CheckState,
    22   SendResults
     22  SendResults,
     23  Shutdown
    2324};
    2425
  • src/Fragmentation/Automation/FragmentController.cpp

    re70b9d r0196c6  
    157157}
    158158
     159/** Handle completion of a connect operation.
     160 *
     161 * \param e error code if something went wrong
     162 * \param endpoint_iterator endpoint of the connection
     163 */
     164void FragmentController::handle_connect_shutdown(const boost::system::error_code& e,
     165    boost::asio::ip::tcp::resolver::iterator endpoint_iterator)
     166{
     167  Info info(__FUNCTION__);
     168  if (!e)
     169  {
     170    // Successfully established connection. Give choice.
     171    enum ControllerChoices choice = Shutdown;
     172    connection_.async_write(choice,
     173      boost::bind(&FragmentController::handle_FinishOperation, this,
     174      boost::asio::placeholders::error));
     175  } else if (endpoint_iterator != boost::asio::ip::tcp::resolver::iterator()) {
     176    // Try the next endpoint.
     177    connection_.socket().close();
     178    boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator;
     179    connection_.socket().async_connect(endpoint,
     180      boost::bind(&FragmentController::handle_connect_calc, this,
     181      boost::asio::placeholders::error, ++endpoint_iterator));
     182  } else {
     183    // An error occurred. Log it and return. Since we are not starting a new
     184    // operation the io_service will run out of work to do and the client will
     185    // exit.
     186    Exitflag = ErrorFlag;
     187    ELOG(1, e.message());
     188  }
     189}
     190
    159191/** Callback function when operation has been completed.
    160192 *
     
    339371}
    340372
     373/** Internal function to connect to the endpoint of the server asynchronuously.
     374 *
     375 * We require internal connetion_ and host and service to be set up for this.
     376 */
     377void FragmentController::connect_shutdown()
     378{
     379  Info info(__FUNCTION__);
     380  // Resolve the host name into an IP address.
     381  boost::asio::ip::tcp::resolver::iterator endpoint_iterator = getEndpointIterator();
     382  boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator;
     383
     384  // Start an asynchronous connect operation.
     385  std::cout << "Connecting to endpoint " << endpoint << " to get results " << std::endl;
     386  connection_.socket().async_connect(endpoint,
     387    boost::bind(&FragmentController::handle_connect_shutdown, this,
     388      boost::asio::placeholders::error, ++endpoint_iterator));
     389}
     390
    341391/** Internal function to disconnect connection_ correctly.
    342392 *
     
    403453}
    404454
     455/** Function to initiate shutdown of server.
     456 *
     457 */
     458void FragmentController::shutdown()
     459{
     460  // connect
     461  connect_shutdown();
     462  //disconnect
     463  disconnect();
     464}
     465
    405466/** Getter for doneJobs.
    406467 *
  • src/Fragmentation/Automation/FragmentController.hpp

    re70b9d r0196c6  
    4949      boost::asio::ip::tcp::resolver::iterator endpoint_iterator);
    5050
     51  /// Handle completion of a Shutdown operation.
     52  void handle_connect_shutdown(const boost::system::error_code& e,
     53      boost::asio::ip::tcp::resolver::iterator endpoint_iterator);
     54
    5155  /// Handle completion of an operation.
    5256  void handle_FinishOperation(const boost::system::error_code& e);
     
    8488  void obtainResults();
    8589
     90  /// prepares the server's shutdown
     91  void shutdown();
     92
    8693  /// get the results for the current jobs
    8794  std::vector<FragmentResult> getResults();
     
    105112  /// internal function to connect to server and receive calculated results
    106113  void connect_get();
     114
     115  /// internal function to connect to server and receive calculated results
     116  void connect_shutdown();
    107117
    108118  /// internal function to disconnect from server
  • src/Fragmentation/Automation/FragmentScheduler.cpp

    re70b9d r0196c6  
    228228  if (!e)
    229229  {
     230    bool LaunchNewAcceptor = true;
    230231    // switch over the desired choice read previously
    231232    switch(choice) {
     
    254255        boost::bind(&FragmentScheduler::handle_CheckResultState, this,
    255256        boost::asio::placeholders::error, conn));
    256 
    257       initiateControllerSocket();
    258257      break;
    259258    }
     
    266265        boost::bind(&FragmentScheduler::handle_SendResults, this,
    267266        boost::asio::placeholders::error, conn));
    268 
    269       initiateControllerSocket();
     267      break;
     268    }
     269    case Shutdown:
     270    {
     271      LaunchNewAcceptor = false;
    270272      break;
    271273    }
     
    278280    choice = NoOperation;
    279281
     282    if (LaunchNewAcceptor) {
     283      LOG(1, "Launching new acceptor on socket.");
     284      // Start an accept operation for a new Connection.
     285      connection_ptr new_conn(new Connection(controller_acceptor_.get_io_service()));
     286      controller_acceptor_.async_accept(new_conn->socket(),
     287        boost::bind(&FragmentScheduler::handle_AcceptController, this,
     288        boost::asio::placeholders::error, new_conn));
     289    }
    280290  }
    281291  else
     
    310320    if (initiateSocket)
    311321      initiateWorkerSocket();
    312     // launch new acceptor of queue has been filled/is full
    313     initiateControllerSocket();
    314   } else {
    315     LOG(1, "INFO: Shutting down controller socket.");
    316322  }
    317323
  • src/Fragmentation/Automation/Makefile.am

    re70b9d r0196c6  
    4545AM_CPPFLAGS = ${BOOST_CPPFLAGS} ${CodePatterns_CFLAGS}
    4646
    47 bin_PROGRAMS += JobAdder ResultChecker ResultGetter Server Worker
     47bin_PROGRAMS += JobAdder ResultChecker ResultGetter Server Shutdowner Worker
    4848
    4949CONTROLLERSOURCE = \
     
    119119  ${CodePatterns_LIBS}
    120120
     121Shutdowner_SOURCES = $(CONTROLLERSOURCE) $(CONTROLLERHEADER) Shutdowner.cpp
     122Shutdowner_LDFLAGS = $(AM_LDFLAGS) $(BOOST_ASIO_LDFLAGS) $(BOOST_SYSTEM_LDFLAGS) $(BOOST_THREAD_LDFLAGS) $(BOOST_SERIALIZATION_LDFLAGS)
     123Shutdowner_CXXFLAGS = $(AM_CPPFLAGS)
     124Shutdowner_LDADD = \
     125  libMolecuilderFragmentJobs.la \
     126  libMolecuilderFragmentationAutomation.la \
     127  $(BOOST_ASIO_LIBS) \
     128  $(BOOST_SERIALIZATION_LIBS) \
     129  $(BOOST_THREAD_LIBS) \
     130  $(BOOST_SYSTEM_LIBS) \
     131  ${CodePatterns_LIBS}
     132
    121133Worker_SOURCES = $(WORKERSOURCE) $(WORKERHEADER)
    122134Worker_LDFLAGS = $(AM_LDFLAGS) $(BOOST_ASIO_LDFLAGS) $(BOOST_SYSTEM_LDFLAGS) $(BOOST_THREAD_LDFLAGS) $(BOOST_SERIALIZATION_LDFLAGS)
Note: See TracChangeset for help on using the changeset viewer.