def report_metadata(mode, zk_data, zk_path, version, notification_timestamp, modification_timestamp, retry_count=0): if not zk_path: return if mode == 'SERVERSET': hashsum = zk_util.get_md5_hash_sum(zk_data) try: num_endpoints = len(zk_data.split(',')) except: # A negative value means there are problems getting the count of endpoints num_endpoints = -1 postbody = { 'hashsum': hashsum, 'num_endpoints': num_endpoints, 'zk_path': zk_path, 'notification_timestamp': notification_timestamp, 'modification_timestamp': modification_timestamp, 'mode': mode } else: postbody = { 'version': version, 'zk_path': zk_path, 'notification_timestamp': notification_timestamp, 'modification_timestamp': modification_timestamp, 'mode': mode } try: response = requests.post(_METADATA_REPORT_ENDPOINT, data=postbody) if response.status_code != 200: log.error( "Failed to get response with 200 code posting metadata for %s: %d", zk_path, response.status_code) if retry_count < _METADATA_REPORT_MAX_RETRY_COUNT: report_metadata(mode, zk_data, zk_path, version, notification_timestamp, modification_timestamp, retry_count + 1) else: log.error( "Post metadata of %s retries all used but still fail.", zk_path) except: log.exception("Fail to post metadata to zk_update_monitor for %s", zk_path) if retry_count < _METADATA_REPORT_MAX_RETRY_COUNT: report_metadata(mode, zk_data, zk_path, version, notification_timestamp, modification_timestamp, retry_count + 1)
def update_serverset_metadata(zk_path, notification_timestamp, value): hashsum = zk_util.get_md5_hash_sum(value) try: num_endpoints = len(value.split(',')) except: # A negative value means there are problems getting the count of endpoints num_endpoints = -1 metadata = {"hashsum": hashsum, "num_endpoints": num_endpoints, "notification_timestamp": notification_timestamp} if zk_path in _SERVERSET_METADATA: _SERVERSET_METADATA[zk_path].update(metadata) else: _SERVERSET_METADATA[zk_path] = metadata
def report_metadata(mode, zk_data, zk_path, version, notification_timestamp, modification_timestamp, retry_count=0): if not zk_path: return if mode == 'SERVERSET': hashsum = zk_util.get_md5_hash_sum(zk_data) try: num_endpoints = len(zk_data.split(',')) except: # A negative value means there are problems getting the count of endpoints num_endpoints = -1 postbody = { 'hashsum': hashsum, 'num_endpoints': num_endpoints, 'zk_path': zk_path, 'notification_timestamp': notification_timestamp, 'modification_timestamp': modification_timestamp, 'mode': mode } else: postbody = { 'version': version, 'zk_path': zk_path, 'notification_timestamp': notification_timestamp, 'modification_timestamp': modification_timestamp, 'mode': mode } try: response = requests.post(_METADATA_REPORT_ENDPOINT, data=postbody) if response.status_code != 200: log.error("Failed to get response with 200 code posting metadata for %s: %d", zk_path, response.status_code) if retry_count < _METADATA_REPORT_MAX_RETRY_COUNT: report_metadata( mode, zk_data, zk_path, version, notification_timestamp, modification_timestamp, retry_count+1) else: log.error("Post metadata of %s retries all used but still fail.", zk_path) except: log.exception("Fail to post metadata to zk_update_monitor for %s", zk_path) if retry_count < _METADATA_REPORT_MAX_RETRY_COUNT: report_metadata( mode, zk_data, zk_path, version, notification_timestamp, modification_timestamp, retry_count+1)