def _start(options, config): """Start Fabric server. """ # Remove temporary defaults file, which migh have left behind # by former runs of Fabric. _backup.cleanup_temp_defaults_files() #Configure TTL _setup_ttl(config) # Configure modules that are not dynamic loaded. _server.configure(config) _error_log.configure(config) _failure_detector.configure(config) # Load information on all providers. providers.find_providers() # Load all services into the service manager _services.ServiceManager().load_services(options, config) # Initilize the state store. _persistence.init_thread() # Check the maximum number of threads. _utils.check_number_threads() # Configure Fabric Node. fabric = FabricNode() reported = _utils.get_time() _LOGGER.info("Fabric node version (%s) started. ", fabric.version, extra={ 'subject': str(fabric.uuid), 'category': MySQLHandler.NODE, 'type': MySQLHandler.START, 'reported': reported }) fabric.startup = reported # Start the executor, failure detector and then service manager. In this # scenario, the recovery is sequentially executed after starting the # executor and before starting the service manager. _events.Handler().start() _recovery.recovery() _failure_detector.FailureDetector.register_groups() _services.ServiceManager().start()
def check_number_threads(increasing=0): """Check the number of threads that are running and whether the maximum number of connections in the state store is configured accordingly. :param increasing: Whether you want to increase the number of threads and how many threads. Default is zero. It raises a ConfigurationError exception if the number of connections is too small. """ from mysql.fabric import ( errors as _errors, executor as _executor, persistence as _persistence, services as _services, server as _server, ) n_sessions = _services.ServiceManager().get_number_sessions() n_executors = _executor.Executor().get_number_executors() n_failure_detectors = \ len(_server.Group.groups_by_status(_server.Group.ACTIVE)) n_controls = 1 persister = _persistence.current_persister() max_allowed_connections = persister.max_allowed_connections() if (n_sessions + n_executors + n_controls + n_failure_detectors +\ increasing) > (max_allowed_connections - 1): raise _errors.ConfigurationError( "Too many threads requested. Session threads (%s), Executor " "threads (%s), Control threads (%s) and Failure Detector threads " "(%s). The maximum number of threads allowed is (%s). Increase " "the maximum number of connections in the state store in order " "to increase this limit." % (n_sessions, n_executors, n_controls, n_failure_detectors, max_allowed_connections - 1))
def execute(self, protocol=None): """Return a list with all the available Fabric Servers. :return: List with existing Fabric Servers. :rtype: ["host:port", ...] """ service = _services.ServiceManager() rset = ResultSet(names=('host', 'port'), types=(str, int)) for _, address in service.address(protocol).items(): rset.append_row(address.split(":")) return CommandResult(None, results=rset)
def _shutdown(): """Shutdown Fabric server. """ _failure_detector.FailureDetector.unregister_groups() _services.ServiceManager().shutdown() _events.Handler().shutdown() _events.Handler().wait() _LOGGER.info("Fabric node stopped.", extra={ 'subject': 'Node', 'category': MySQLHandler.NODE, 'type': MySQLHandler.STOP })
def dispatch(self, daemonize=False): """Start the Fabric server. """ # Configure logging. _configure_logging(self.config, daemonize) # Configure connections. _configure_connections(self.config) credentials.check_initial_setup(self.config, _persistence.MySQLPersister(), check_only=True) # Daemonize ourselves. if daemonize: _utils.daemonize() # Start Fabric server. _start(self.options, self.config) _services.ServiceManager().wait()
def dispatch(self, daemonize=False): """Start the Fabric server. """ # Configure logging. _configure_logging(self.config, daemonize) # Configure connections. _configure_connections(self.config) try: credentials.check_initial_setup(self.config, _persistence.MySQLPersister(), check_only=True) except _errors.CredentialError as error: _LOGGER.debug(str(error)) return # Daemonize ourselves. if daemonize: _utils.daemonize() # Start Fabric server. _start(self.options, self.config) _services.ServiceManager().wait()
def _configure_connections(config): """Configure information on database connection and remote servers. """ # Configure the number of concurrent executors. try: number_executors = config.get('executor', "executors") number_executors = int(number_executors) except (_config.NoOptionError, _config.NoSectionError, ValueError): number_executors = DEFAULT_N_EXECUTORS executor = _executor.Executor() executor.set_number_executors(number_executors) services = {} ssl_config = {} # XML-RPC service try: services['protocol.xmlrpc'] = config.get('protocol.xmlrpc', "address") try: number_threads = config.get('protocol.xmlrpc', "threads") number_threads = int(number_threads) except (_config.NoOptionError, ValueError): number_threads = DEFAULT_N_THREADS try: for option in ('ssl_ca', 'ssl_key', 'ssl_cert'): ssl_config[option] = config.get('protocol.xmlrpc', option) except _config.NoOptionError: ssl_config = {} except _config.NoSectionError: raise _errors.ConfigurationError( 'Configuration for protocol.xmlrpc is required') # MySQL-RPC service try: services['protocol.mysql'] = config.get('protocol.mysql', "address") except _config.NoSectionError: # No MySQL-RPC configured pass # Define service configuration _services.ServiceManager(services, number_threads, ssl_config) # Fetch options to configure the state store. address = config.get('storage', 'address') try: host, port = address.split(':') port = int(port) except ValueError: host = address port = _MYSQL_PORT user = config.get('storage', 'user') database = config.get('storage', 'database') try: password = config.get('storage', 'password') except _config.NoOptionError: password = getpass.getpass() try: connection_timeout = config.get("storage", "connection_timeout") connection_timeout = float(connection_timeout) except (_config.NoOptionError, _config.NoSectionError, ValueError): connection_timeout = None try: connection_attempts = config.get("storage", "connection_attempts") connection_attempts = int(connection_attempts) except (_config.NoOptionError, _config.NoSectionError, ValueError): connection_attempts = None try: connection_delay = config.get("storage", "connection_delay") connection_delay = int(connection_delay) except (_config.NoOptionError, _config.NoSectionError, ValueError): connection_delay = None try: auth_plugin = config.get("storage", "auth_plugin") except (_config.NoOptionError, _config.NoSectionError, ValueError): auth_plugin = None # Define state store configuration. _persistence.init(host=host, port=port, user=user, password=password, database=database, connection_timeout=connection_timeout, connection_attempts=connection_attempts, connection_delay=connection_delay, auth_plugin=auth_plugin)