def _strategy(initial_brokers): logger.debug('Failover strategy: searching for a new rabbitmq server') initial_brokers = [broker for broker in initial_brokers if broker] brokers = itertools.cycle(initial_brokers) while True: if cluster.is_cluster_configured(): nodes = cluster.get_cluster_nodes() for node_ip in nodes: _set_master(daemon_name, node_ip) daemon = DaemonFactory().load(daemon_name) broker_url = 'amqp://{0}:{1}@{2}:{3}/{4}'.format( daemon.broker_user, daemon.broker_pass, node_ip, daemon.broker_port, daemon.broker_vhost) logger.debug('Trying broker at {0}'.format(broker_url)) yield broker_url else: logger.debug('cluster config file does not exist') broker_url = next(brokers) if len(initial_brokers) > 1: logger.debug('writing config file') cluster.config_from_broker_urls(broker_url, initial_brokers) _set_master(daemon_name, cluster.get_cluster_active()) logger.debug('Trying broker at {0}'.format(broker_url)) yield broker_url
def get_broker_ssl_cert_path(): """ Returns location of the broker certificate on the agent """ if cluster.is_cluster_configured(): active_node = cluster.get_cluster_active() or {} broker_ssl_cert_path = active_node.get('internal_cert_path') if broker_ssl_cert_path: return broker_ssl_cert_path return os.environ[constants.BROKER_SSL_CERT_PATH]
def get_manager_file_server_url(): """ Returns the manager file server base url. """ if cluster.is_cluster_configured(): active_node_ip = cluster.get_cluster_active() port = get_manager_rest_service_port() if active_node_ip: return 'https://{0}:{1}/resources'.format(active_node_ip, port) return os.environ[constants.MANAGER_FILE_SERVER_URL_KEY]
def get_broker_ssl_cert_path(): """ Returns location of the broker certificate on the agent """ if cluster.is_cluster_configured(): active_node = cluster.get_cluster_active() or {} broker_ssl_cert_path = active_node.get('internal_cert_path') if broker_ssl_cert_path: return broker_ssl_cert_path return os.environ[constants.BROKER_SSL_CERT_PATH]
def get_manager_file_server_url(): """ Returns the manager file server base url. """ if cluster.is_cluster_configured(): active_node_ip = cluster.get_cluster_active() port = get_manager_rest_service_port() if active_node_ip: return 'https://{0}:{1}/resources'.format(active_node_ip, port) return os.environ[constants.MANAGER_FILE_SERVER_URL_KEY]
def get_local_rest_certificate(): """ Returns the path to the local copy of the server's public certificate """ if cluster.is_cluster_configured(): active_node = cluster.get_cluster_active() or {} rest_cert_path = active_node.get('internal_cert_path') if rest_cert_path: return rest_cert_path return os.environ[constants.LOCAL_REST_CERT_FILE_KEY]
def _strategy(initial_brokers): logger.debug('Failover strategy: searching for a new rabbitmq server') initial_brokers = [broker for broker in initial_brokers if broker] brokers = itertools.cycle(initial_brokers) while True: if cluster.is_cluster_configured(): nodes = cluster.get_cluster_nodes() for node in nodes: with _cluster_settings_lock(daemon_name): _set_master(daemon_name, node) ssl_enabled = node.get('broker_ssl_enabled', False) if 'broker_port' in node: port = node['broker_port'] else: port = 5671 if ssl_enabled else 5672 broker_url = 'amqp://{0}:{1}@{2}:{3}//'.format( node['broker_user'], node['broker_pass'], node['broker_ip'], port) if ssl_enabled: # use a different cert for each node in the cluster - # can't pass that in the amqp url broker_ssl_cert_path = node.get('internal_cert_path') if broker_ssl_cert_path: app.conf['BROKER_USE_SSL']['ca_certs'] =\ broker_ssl_cert_path logger.debug('Trying broker at {0}'.format(broker_url)) yield broker_url else: logger.debug('cluster config file does not exist') broker_url = next(brokers) if len(initial_brokers) > 1: logger.debug('writing config file') with _cluster_settings_lock(daemon_name): cluster.config_from_broker_urls( broker_url, initial_brokers) _set_master(daemon_name, cluster.get_cluster_active()) logger.debug('Trying broker at {0}'.format(broker_url)) yield broker_url