def start_process(self, strategy, namespec, extra_args='', wait=True): """ Start a process named namespec iaw the strategy and some of the rules file. WARN: the 'wait_exit' rule is not considered here. *@param* ``StartingStrategies strategy``: the strategy used to choose addresses. *@param* ``str namespec``: the process namespec (``name``, ``group:name``, or ``group:*``). *@param* ``str extra_args``: extra arguments to be passed to command line. *@param* ``bool wait``: wait for the process to be fully started. *@throws* ``RPCError``: * with code ``Faults.BAD_SUPVISORS_STATE`` if **Supvisors** is not in state ``OPERATION``, * with code ``Faults.BAD_STRATEGY`` if strategy is unknown to **Supvisors**, * with code ``Faults.BAD_NAME`` if namespec is unknown to **Supvisors**, * with code ``Faults.ALREADY_STARTED`` if process is in a running state, * with code ``Faults.ABNORMAL_TERMINATION`` if process could not be started. *@return* ``bool``: always ``True`` unless error. """ self._check_operating() # check strategy if strategy not in StartingStrategies._values(): raise RPCError(Faults.BAD_STRATEGY, '{}'.format(strategy)) # check names application, process = self._get_application_process(namespec) processes = [process] if process else application.processes.values() # check processes are not already running for process in processes: if process.running(): raise RPCError(Faults.ALREADY_STARTED, process.namespec()) # start all processes done = True for process in processes: done &= self.starter.start_process(strategy, process, extra_args) self.logger.debug('startProcess {} done={}'.format( process.namespec(), done)) # wait until application fully RUNNING or (failed) if wait and not done: def onwait(): # check starter if self.starter.in_progress(): return NOT_DONE_YET for process in processes: if process.stopped(): raise RPCError(Faults.ABNORMAL_TERMINATION, process.namespec()) return True onwait.delay = 0.1 return onwait # deferred return True
def start_process(self, strategy, namespec, extra_args='', wait=True): """ Start a process named namespec iaw the strategy and some of the rules file. WARN: the 'wait_exit' rule is not considered here. *@param* ``StartingStrategies strategy``: the strategy used to choose addresses. *@param* ``str namespec``: the process namespec (``name``, ``group:name``, or ``group:*``). *@param* ``str extra_args``: extra arguments to be passed to command line. *@param* ``bool wait``: wait for the process to be fully started. *@throws* ``RPCError``: * with code ``Faults.BAD_SUPVISORS_STATE`` if **Supvisors** is not in state ``OPERATION``, * with code ``Faults.BAD_STRATEGY`` if strategy is unknown to **Supvisors**, * with code ``Faults.BAD_NAME`` if namespec is unknown to **Supvisors**, * with code ``Faults.ALREADY_STARTED`` if process is in a running state, * with code ``Faults.ABNORMAL_TERMINATION`` if process could not be started. *@return* ``bool``: always ``True`` unless error. """ self._check_operating() # check strategy if strategy not in StartingStrategies._values(): raise RPCError(Faults.BAD_STRATEGY, '{}'.format(strategy)) # check names application, process = self._get_application_process(namespec) processes = [process] if process else application.processes.values() # check processes are not already running for process in processes: if process.running(): raise RPCError(Faults.ALREADY_STARTED, process.namespec()) # start all processes done = True for process in processes: done &= self.starter.start_process(strategy, process, extra_args) self.logger.debug('startProcess {} done={}'.format(process.namespec(), done)) # wait until application fully RUNNING or (failed) if wait and not done: def onwait(): # check starter if self.starter.in_progress(): return NOT_DONE_YET for process in processes: if process.stopped(): raise RPCError(Faults.ABNORMAL_TERMINATION, process.namespec()) return True onwait.delay = 0.1 return onwait # deferred return True
def start_application(self, strategy, application_name, wait=True): """ Start the application named application_name iaw the strategy and the rules file. *@param* ``StartingStrategies strategy``: the strategy used to choose addresses. *@param* ``str application_name``: the name of the application. *@param* ``bool wait``: wait for the application to be fully started. *@throws* ``RPCError``: * with code ``Faults.BAD_SUPVISORS_STATE`` if **Supvisors** is not in state ``OPERATION``, * with code ``Faults.BAD_STRATEGY`` if strategy is unknown to **Supvisors**, * with code ``Faults.BAD_NAME`` if application_name is unknown to **Supvisors**, * with code ``Faults.ALREADY_STARTED`` if application is ``STARTING``, ``STOPPING`` or ``RUNNING``, * with code ``Faults.ABNORMAL_TERMINATION`` if application could not be started. *@return* ``bool``: always ``True`` unless error or nothing to start. """ self._check_operating() # check strategy if strategy not in StartingStrategies._values(): raise RPCError(Faults.BAD_STRATEGY, '{}'.format(strategy)) # check application is known if application_name not in self.context.applications.keys(): raise RPCError(Faults.BAD_NAME, application_name) # check application is not already RUNNING application = self.context.applications[application_name] if application.state != ApplicationStates.STOPPED: raise RPCError(Faults.ALREADY_STARTED, application_name) # TODO: develop a predictive model to check if starting can be achieved # if impossible due to a lack of resources, second try without optionals # return false if still impossible done = self.starter.start_application(strategy, application) self.logger.debug('start_application {} done={}'.format( application_name, done)) # wait until application fully RUNNING or (failed) if wait and not done: def onwait(): # check starter if self.starter.in_progress(): return NOT_DONE_YET if application.state != ApplicationStates.RUNNING: raise RPCError(Faults.ABNORMAL_TERMINATION, application_name) return True onwait.delay = 0.5 return onwait # deferred # if done is True, nothing to do (no starting or impossible to start) return not done
def start_application(self, strategy, application_name, wait=True): """ Start the application named application_name iaw the strategy and the rules file. *@param* ``StartingStrategies strategy``: the strategy used to choose addresses. *@param* ``str application_name``: the name of the application. *@param* ``bool wait``: wait for the application to be fully started. *@throws* ``RPCError``: * with code ``Faults.BAD_SUPVISORS_STATE`` if **Supvisors** is not in state ``OPERATION``, * with code ``Faults.BAD_STRATEGY`` if strategy is unknown to **Supvisors**, * with code ``Faults.BAD_NAME`` if application_name is unknown to **Supvisors**, * with code ``Faults.ALREADY_STARTED`` if application is ``STARTING``, ``STOPPING`` or ``RUNNING``, * with code ``Faults.ABNORMAL_TERMINATION`` if application could not be started. *@return* ``bool``: always ``True`` unless error or nothing to start. """ self._check_operating() # check strategy if strategy not in StartingStrategies._values(): raise RPCError(Faults.BAD_STRATEGY, '{}'.format(strategy)) # check application is known if application_name not in self.context.applications.keys(): raise RPCError(Faults.BAD_NAME, application_name) # check application is not already RUNNING application = self.context.applications[application_name] if application.state != ApplicationStates.STOPPED: raise RPCError(Faults.ALREADY_STARTED, application_name) # TODO: develop a predictive model to check if starting can be achieved # if impossible due to a lack of resources, second try without optionals # return false if still impossible done = self.starter.start_application(strategy, application) self.logger.debug('start_application {} done={}'.format(application_name, done)) # wait until application fully RUNNING or (failed) if wait and not done: def onwait(): # check starter if self.starter.in_progress(): return NOT_DONE_YET if application.state != ApplicationStates.RUNNING: raise RPCError(Faults.ABNORMAL_TERMINATION, application_name) return True onwait.delay = 0.5 return onwait # deferred # if done is True, nothing to do (no starting or impossible to start) return not done