def _sync_data_node(self): server_ip = getHostIp() zkOper = Common_ZkOpers() server_ip_list = zkOper.retrieve_data_node_list() if server_ip in server_ip_list: data_node_value = zkOper.retrieve_data_node_info(server_ip) if isinstance(data_node_value, dict): self.config_file_obj.setValue(options.data_node_property, data_node_value) else: logging.error('server %s should be registered first' % str(server_ip))
def sync(self): http_client = AsyncHTTPClient() succ, fail, return_result = [], [], '' key_sets = set() zkOper = Common_ZkOpers() server_list = zkOper.retrieve_data_node_list() try: for server in server_list: requesturi = 'http://%s:%s/inner/server/sync' % (server, options.port) logging.info('server requesturi: %s' % str(requesturi)) callback_key = server key_sets.add(callback_key) http_client.fetch(requesturi, callback=(yield Callback(callback_key))) logging.debug('key_sets:%s' % str(key_sets)) error_record = '' for i in range(len(key_sets)): callback_key = key_sets.pop() response = yield Wait(callback_key) if response.error: message = "remote access, the key:%s,\n error message:\n %s" % ( callback_key, str(response.error)) error_record += message + "|" logging.error(error_record) else: return_result = response.body.strip() if return_result: logging.debug('return_result : %s' % str(return_result)) succ.append(callback_key) else: fail.append(callback_key) finally: http_client.close() logging.debug('succ:%s' % str(succ)) logging.debug('fail:%s' % str(fail))